ChannelCode.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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\Request;
  14. use app\services\work\WorkChannelCategoryServices;
  15. use app\services\work\WorkChannelCodeServices;
  16. use app\services\work\WorkClientFollowServices;
  17. use app\validate\admin\work\WechatWorkChannelCodeValidate;
  18. use think\facade\App;
  19. /**
  20. * 渠道码
  21. * Class ClientCode
  22. * @package app\controller\admin\v1\work
  23. */
  24. class ChannelCode extends AuthController
  25. {
  26. /**
  27. * ClientCode constructor.
  28. * @param App $app
  29. * @param WorkChannelCodeServices $services
  30. */
  31. public function __construct(App $app, WorkChannelCodeServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * 获取渠道码列表
  38. * @return mixed
  39. */
  40. public function index()
  41. {
  42. $where = $this->request->getMore([
  43. ['name', ''],
  44. ['type', ''],
  45. ['cate_id', '']
  46. ]);
  47. //顶部搜索全部分类
  48. if ($where['name'] !== '' || $where['type'] !== '') {
  49. $where['cate_id'] = '';
  50. }
  51. return $this->success($this->services->getList($where));
  52. }
  53. /**
  54. * 获取渠道码详情
  55. * @param $id
  56. * @return mixed
  57. */
  58. public function read($id)
  59. {
  60. if (!$id) {
  61. return $this->fail('缺少参数');
  62. }
  63. return $this->success($this->services->getChannelInfo((int)$id));
  64. }
  65. /**
  66. * 保存渠道码
  67. * @param Request $request
  68. * @return mixed
  69. */
  70. public function save(Request $request)
  71. {
  72. $data = $request->postMore([
  73. ['type', 0],
  74. ['name', ''],
  75. ['cate_id', 0],
  76. ['label_id', []],
  77. ['reserve_userid', []],
  78. ['userids', []],
  79. ['skip_verify', 0],//自动加好友
  80. ['add_upper_limit', 0],//员工添加上限
  81. ['welcome_words', []],
  82. ['status', 0],
  83. ['welcome_type', 0],
  84. ['cycle', []],
  85. ['useridLimit', []],
  86. ]);
  87. $this->validate($data, WechatWorkChannelCodeValidate::class);
  88. if ($data['type'] && !count($data['cycle'])) {
  89. return $this->fail('至少设置一个周期规则');
  90. }
  91. if ($data['add_upper_limit'] && !$data['useridLimit']) {
  92. return $this->fail('请设置添加上限');
  93. }
  94. if ($this->services->saveChanne($data)) {
  95. return $this->success('保存成功');
  96. } else {
  97. return $this->fail('保存失败');
  98. }
  99. }
  100. /**
  101. * 修改渠道码
  102. * @param Request $request
  103. * @param $id
  104. * @return mixed
  105. */
  106. public function update(Request $request, $id)
  107. {
  108. if (!$id) {
  109. return $this->fail('缺少参数');
  110. }
  111. $data = $request->postMore([
  112. ['type', 0],
  113. ['name', ''],
  114. ['cate_id', 0],
  115. ['label_id', []],
  116. ['reserve_userid', []],
  117. ['userids', []],
  118. ['skip_verify', 0],//自动加好友
  119. ['add_upper_limit', 0],//员工添加上限
  120. ['welcome_words', []],
  121. ['status', 0],
  122. ['cycle', []],
  123. ['welcome_type', 0],
  124. ['useridLimit', []],
  125. ]);
  126. $this->validate($data, WechatWorkChannelCodeValidate::class);
  127. if ($data['type'] && !count($data['cycle'])) {
  128. return $this->fail('至少设置一个周期规则');
  129. }
  130. if ($data['add_upper_limit'] && !$data['useridLimit']) {
  131. return $this->fail('请设置添加上限');
  132. }
  133. if ($this->services->saveChanne($data, $id)) {
  134. return $this->success('修改成功');
  135. } else {
  136. return $this->fail('修改失败');
  137. }
  138. }
  139. /**
  140. * 修改状态
  141. * @param $id
  142. * @param $status
  143. * @return mixed
  144. */
  145. public function status($id, $status)
  146. {
  147. if (!$id) {
  148. return $this->fail('缺少参数');
  149. }
  150. if ($this->services->update($id, ['status' => $status])) {
  151. return $this->success('修改成功');
  152. } else {
  153. return $this->fail('修改失败');
  154. }
  155. }
  156. /**
  157. * 删除
  158. * @param $id
  159. * @return mixed
  160. */
  161. public function delete($id)
  162. {
  163. if (!$id) {
  164. return $this->fail('缺少参数');
  165. }
  166. if ($this->services->deleteChannel((int)$id)) {
  167. return $this->success('删除成功');
  168. } else {
  169. return $this->fail('删除失败');
  170. }
  171. }
  172. /**
  173. * 获取扫描渠道码添加的客户列表
  174. * @param WorkClientFollowServices $services
  175. * @param $id
  176. * @return mixed
  177. */
  178. public function getClientList(WorkClientFollowServices $services, $id)
  179. {
  180. if (!$id) {
  181. return $this->fail('缺少参数');
  182. }
  183. $name = $this->request->get('name', '');
  184. return $this->success($services->getChannelCodeClientList((int)$id, $name));
  185. }
  186. /**
  187. * 批量移动分类
  188. * @return mixed
  189. */
  190. public function bactchMoveCate()
  191. {
  192. [$ids, $cateId] = $this->request->postMore([
  193. ['ids', []],
  194. ['cate_id', 0]
  195. ], true);
  196. if (!$ids) {
  197. return $this->fail('请选择需要移动的渠道码');
  198. }
  199. if (!$cateId) {
  200. return $this->fail('请选择分类');
  201. }
  202. if ($this->services->update(['id' => $ids], ['cate_id' => $cateId])) {
  203. return $this->success('移动成功');
  204. } else {
  205. return $this->fail('移动失败');
  206. }
  207. }
  208. }