Client.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\work;
  12. use app\controller\admin\AuthController;
  13. use app\services\user\UserServices;
  14. use app\services\work\WorkClientServices;
  15. use crmeb\services\wechat\config\WorkConfig;
  16. use think\facade\App;
  17. /**
  18. * 客户管理
  19. * Class Client
  20. * @package app\controller\admin\v1\work
  21. */
  22. class Client extends AuthController
  23. {
  24. /**
  25. * Client constructor.
  26. * @param App $app
  27. * @param WorkClientServices $services
  28. */
  29. public function __construct(App $app, WorkClientServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 企微客户列表
  36. * @param WorkConfig $config
  37. * @return mixed
  38. */
  39. public function index(WorkConfig $config)
  40. {
  41. $where = $this->request->getMore([
  42. ['time', ''],//添加时间
  43. ['userid', []],//所属客服
  44. ['label', []],//客户标签
  45. ['name', ''],
  46. ['field_key', ''],//客户搜索
  47. ['gender', 0],//性别
  48. ['status', 0],//客户状态
  49. ['state', 0],//0=扫码,1=自行添加
  50. ]);
  51. $where['corp_id'] = $config->get('corpId');
  52. $where['timeKey'] = 'create_time';
  53. return $this->success($this->services->getList($where));
  54. }
  55. /**
  56. * 非企微客户列表
  57. * @param UserServices $services
  58. * @return mixed
  59. */
  60. public function userList(UserServices $services)
  61. {
  62. $where = $this->request->getMore([
  63. ['time', '', '', 'user_time'],//添加时间
  64. ['name', '', '', 'nickname'],
  65. ['field_key', ''],//客户搜索
  66. ['gender', 0, '', 'sex'],//性别
  67. ]);
  68. return $this->success($services->index($where));
  69. }
  70. /**
  71. * 同步客户
  72. * @return mixed
  73. */
  74. public function synch()
  75. {
  76. $this->services->authGetExternalcontact();
  77. return $this->success('已加入消息队列,请稍后查看');
  78. }
  79. /**
  80. * 修改客户
  81. * @param $id
  82. * @return mixed
  83. */
  84. public function update($id)
  85. {
  86. $data = $this->request->postMore([
  87. ['remark', '']
  88. ]);
  89. if (!$id) {
  90. return $this->fail('缺少参数');
  91. }
  92. $this->services->update($id, $data);
  93. return $this->success('修改成功');
  94. }
  95. /**
  96. * 批量设置标签
  97. * @return mixed
  98. */
  99. public function batchLabel()
  100. {
  101. [$labelId, $removeTag, $userId, $isAll] = $this->request->postMore([
  102. ['add_tag', []],
  103. ['removeTag', []],
  104. ['userid', []],
  105. ['is_all', 0]
  106. ], true);
  107. if (!$labelId) {
  108. return $this->fail('请选择标签');
  109. }
  110. if (!$isAll && !$userId) {
  111. return $this->fail('请选择客户');
  112. }
  113. $where = $this->request->getMore([
  114. ['time', ''],//添加时间
  115. ['userid', []],//所属客服
  116. ['label', []],//客户标签
  117. ['name', ''],
  118. ['field_key', ''],//客户搜索
  119. ['gender', 0],//性别
  120. ['status', 0],//客户状态
  121. ['state', 0],//0=扫码,1=自行添加
  122. ]);
  123. $this->services->synchBatchLabel($labelId, $removeTag, $userId, $where, (int)$isAll);
  124. return $this->success('已加入消息队列');
  125. }
  126. /**
  127. * @return mixed
  128. */
  129. public function count()
  130. {
  131. $where = $this->request->postMore([
  132. ['userid', []],
  133. ['time', ''],
  134. ['label', []],
  135. ['notLabel', []],
  136. ['is_all', 0]
  137. ]);
  138. return $this->success(['sum_count' => $this->services->getUserIdsByCount($where)]);
  139. }
  140. }