123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- namespace app\controller\admin\v1\work;
- use app\controller\admin\AuthController;
- use app\Request;
- use app\services\work\WorkChannelCategoryServices;
- use app\services\work\WorkChannelCodeServices;
- use app\services\work\WorkClientFollowServices;
- use app\validate\admin\work\WechatWorkChannelCodeValidate;
- use think\facade\App;
- class ChannelCode extends AuthController
- {
-
- public function __construct(App $app, WorkChannelCodeServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
-
- public function index()
- {
- $where = $this->request->getMore([
- ['name', ''],
- ['type', ''],
- ['cate_id', '']
- ]);
-
- if ($where['name'] !== '' || $where['type'] !== '') {
- $where['cate_id'] = '';
- }
- return $this->success($this->services->getList($where));
- }
-
- public function read($id)
- {
- if (!$id) {
- return $this->fail('缺少参数');
- }
- return $this->success($this->services->getChannelInfo((int)$id));
- }
-
- public function save(Request $request)
- {
- $data = $request->postMore([
- ['type', 0],
- ['name', ''],
- ['cate_id', 0],
- ['label_id', []],
- ['reserve_userid', []],
- ['userids', []],
- ['skip_verify', 0],
- ['add_upper_limit', 0],
- ['welcome_words', []],
- ['status', 0],
- ['welcome_type', 0],
- ['cycle', []],
- ['useridLimit', []],
- ]);
- $this->validate($data, WechatWorkChannelCodeValidate::class);
- if ($data['type'] && !count($data['cycle'])) {
- return $this->fail('至少设置一个周期规则');
- }
- if ($data['add_upper_limit'] && !$data['useridLimit']) {
- return $this->fail('请设置添加上限');
- }
- if ($this->services->saveChanne($data)) {
- return $this->success('保存成功');
- } else {
- return $this->fail('保存失败');
- }
- }
-
- public function update(Request $request, $id)
- {
- if (!$id) {
- return $this->fail('缺少参数');
- }
- $data = $request->postMore([
- ['type', 0],
- ['name', ''],
- ['cate_id', 0],
- ['label_id', []],
- ['reserve_userid', []],
- ['userids', []],
- ['skip_verify', 0],
- ['add_upper_limit', 0],
- ['welcome_words', []],
- ['status', 0],
- ['cycle', []],
- ['welcome_type', 0],
- ['useridLimit', []],
- ]);
- $this->validate($data, WechatWorkChannelCodeValidate::class);
- if ($data['type'] && !count($data['cycle'])) {
- return $this->fail('至少设置一个周期规则');
- }
- if ($data['add_upper_limit'] && !$data['useridLimit']) {
- return $this->fail('请设置添加上限');
- }
- if ($this->services->saveChanne($data, $id)) {
- return $this->success('修改成功');
- } else {
- return $this->fail('修改失败');
- }
- }
-
- public function status($id, $status)
- {
- if (!$id) {
- return $this->fail('缺少参数');
- }
- if ($this->services->update($id, ['status' => $status])) {
- return $this->success('修改成功');
- } else {
- return $this->fail('修改失败');
- }
- }
-
- public function delete($id)
- {
- if (!$id) {
- return $this->fail('缺少参数');
- }
- if ($this->services->deleteChannel((int)$id)) {
- return $this->success('删除成功');
- } else {
- return $this->fail('删除失败');
- }
- }
-
- public function getClientList(WorkClientFollowServices $services, $id)
- {
- if (!$id) {
- return $this->fail('缺少参数');
- }
- $name = $this->request->get('name', '');
- return $this->success($services->getChannelCodeClientList((int)$id, $name));
- }
-
- public function bactchMoveCate()
- {
- [$ids, $cateId] = $this->request->postMore([
- ['ids', []],
- ['cate_id', 0]
- ], true);
- if (!$ids) {
- return $this->fail('请选择需要移动的渠道码');
- }
- if (!$cateId) {
- return $this->fail('请选择分类');
- }
- if ($this->services->update(['id' => $ids], ['cate_id' => $cateId])) {
- return $this->success('移动成功');
- } else {
- return $this->fail('移动失败');
- }
- }
- }
|