StoreService.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\models\store\StoreServiceLog;
  4. use app\models\store\StoreService as StoreServiceModel;
  5. use app\Request;
  6. use crmeb\services\UtilService;
  7. /**
  8. * 客服类
  9. * Class StoreService
  10. * @package app\api\controller\user
  11. */
  12. class StoreService
  13. {
  14. /**
  15. * @api {get} user/service/list 获取客服列表
  16. * @apiName GetUserServiceList
  17. * @apiGroup User
  18. *
  19. * @apiQuery {int} page 分页
  20. * @apiQuery {int} limit
  21. *
  22. * @apiSuccessExample Succeed
  23. * {
  24. * "data": [{
  25. * "id": 1,
  26. * "uid": 123,
  27. * "avatar": "http://icon.png",
  28. * "nickname": "john",
  29. * "customer": 0
  30. * }]
  31. * }
  32. * // 失败返回空数组
  33. *
  34. */
  35. public function lst(Request $request)
  36. {
  37. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 0]], $request, true);
  38. if (!$page || !$limit) {
  39. return app('json')->successful([]);
  40. }
  41. $serviceInfoList = StoreServiceModel::lst($page, $limit);
  42. if (!count($serviceInfoList)) {
  43. return app('json')->successful([]);
  44. }
  45. return app('json')->successful($serviceInfoList->hidden(['notify', 'status', 'mer_id', 'add_time'])->toArray());
  46. }
  47. /**
  48. * @api {get} user/service/record/:toUid 获取客服聊天记录
  49. * @apiName GetUserServiceRecord
  50. * @apiGroup User
  51. *
  52. * @apiParam {int} toUid 聊天对象
  53. * @apiQuery {int} page 分页
  54. * @apiQuery {int} limit
  55. *
  56. * @apiSuccessExample Succeed
  57. * {
  58. *
  59. * }
  60. */
  61. public function record(Request $request, $toUid)
  62. {
  63. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 0]], $request, true);
  64. if (!$toUid) {
  65. return app('json')->fail('参数错误');
  66. }
  67. $uid = $request->uid();
  68. if (!$limit || !$page) {
  69. return app('json')->successful([]);
  70. }
  71. $serviceLogList = StoreServiceLog::lst($uid, $toUid, $page, $limit);
  72. if (!$serviceLogList) {
  73. return app('json')->successful([]);
  74. }
  75. $serviceLogList = $serviceLogList->hidden(['mer_id'])->toArray();
  76. $idArr = array_column($serviceLogList, 'id');
  77. array_multisort($idArr, SORT_ASC, $serviceLogList);
  78. return app('json')->successful($serviceLogList);
  79. }
  80. }