Service.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\controller;
  12. use app\wap\model\store\StoreService;
  13. use service\SystemConfigService;
  14. use app\wap\model\user\User;
  15. use service\JsonService;
  16. use service\UtilService;
  17. use think\Request;
  18. /**客服控制器
  19. * Class Service
  20. * @package app\wap\controller
  21. */
  22. class Service extends AuthController
  23. {
  24. /**微信客服列表
  25. * @param Request $request
  26. * @return mixed
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. * @throws \think\exception\DbException
  30. */
  31. public function service_list()
  32. {
  33. $customer_service_configuration = SystemConfigService::get('customer_service_configuration');
  34. $service_url = SystemConfigService::get('service_url');
  35. $this->assign([
  36. 'service_configuration' => $customer_service_configuration,
  37. 'service_url' => $service_url,
  38. 'userInfo' => json_encode($this->userInfo)
  39. ]);
  40. return $this->fetch();
  41. }
  42. /**
  43. * 获取微信客服
  44. */
  45. public function get_service_list()
  46. {
  47. $where = UtilService::getMore([
  48. ['page', 1],
  49. ['limit', 10]
  50. ]);
  51. $list = StoreService::field('uid,avatar,nickname')->where('status', 1)->page($where['page'], $where['limit'])->order('id desc')->select();
  52. $list = count($list) > 0 ? $list->toArray() : [];
  53. return JsonService::successful($list);
  54. }
  55. /**
  56. * crmeb客服token
  57. */
  58. public function get_kefu_token()
  59. {
  60. $kefu_token = SystemConfigService::get('kefu_token');
  61. $data['kefu_token'] = $kefu_token;
  62. return JsonService::successful($data);
  63. }
  64. /**聊天
  65. * @param Request $request
  66. * @return mixed
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. */
  71. public function service_ing(Request $request)
  72. {
  73. $params = Request::instance()->param();
  74. $to_uid = $params['to_uid'];
  75. if (!isset($to_uid) || empty($to_uid)) $this->failed('未获取到接收用户信息!');
  76. if ($this->uid == $to_uid) $this->failed('您不能进行自言自语!');
  77. //发送用户信息
  78. $now_user = StoreService::where(['uid' => $this->uid])->find();
  79. if (!$now_user) $now_user = $this->userInfo;
  80. $this->assign('user', $now_user);
  81. //接收用户信息
  82. $to_user = StoreService::where(['uid' => $to_uid])->find();
  83. if (!$to_user) $to_user = User::getUserData($to_uid);
  84. if(!$to_user) $this->failed('未获取到接收用户信息!');
  85. $this->assign(['to_user' => $to_user]);
  86. return $this->fetch();
  87. }
  88. /**聊天记录
  89. * @return mixed
  90. */
  91. public function service_new()
  92. {
  93. return $this->fetch();
  94. }
  95. }