123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace app\controller\store\user;
- use app\controller\store\AuthController;
- use app\services\user\label\UserLabelCateServices;
- use app\services\user\label\UserLabelRelationServices;
- use app\services\user\label\UserLabelServices;
- use think\facade\App;
- class UserLabel extends AuthController
- {
-
- public function __construct(App $app, UserLabelServices $service)
- {
- parent::__construct($app);
- $this->service = $service;
- }
-
- public function index($label_cate = 0)
- {
- return app('json')->success($this->service->getList(['label_cate' => $label_cate, 'type' => 1, 'relation_id' => $this->storeId]));
- }
-
- public function create()
- {
- return app('json')->success($this->service->add(0, 1, (int)$this->storeId));
- }
-
- public function edit()
- {
- [$id] = $this->request->getMore([
- ['id', 0],
- ], true);
- return app('json')->success($this->service->add((int)$id, 1, (int)$this->storeId));
- }
-
- public function save()
- {
- $data = $this->request->postMore([
- ['id', 0],
- ['label_cate', 0],
- ['label_name', ''],
- ]);
- if (!$data['label_name'] = trim($data['label_name'])) return app('json')->fail('会员标签不能为空!');
- $this->service->save((int)$data['id'], $data, 1, (int)$this->storeId);
- return app('json')->success('保存成功');
- }
-
- public function delete()
- {
- [$id] = $this->request->getMore([
- ['id', 0],
- ], true);
- if (!$id) return app('json')->fail('数据不存在');
- $this->service->delLabel((int)$id);
- return app('json')->success('刪除成功!');
- }
-
- public function getUserLabel(UserLabelCateServices $services, $uid)
- {
- return app('json')->success($services->getUserLabel((int)$uid, 1, (int)$this->storeId));
- }
-
- public function setUserLabel(UserLabelRelationServices $services, $uid)
- {
- [$labels, $unLabelIds] = $this->request->postMore([
- ['label_ids', []],
- ['un_label_ids', []]
- ], true);
- if (!count($labels) && !count($unLabelIds)) {
- return app('json')->fail('请先添加标签');
- }
- if ($services->setUserLable($uid, $labels, 1, (int)$this->storeId) && $services->unUserLabel($uid, $unLabelIds, 1, (int)$this->storeId)) {
- return app('json')->success('设置成功');
- } else {
- return app('json')->fail('设置失败');
- }
- }
- }
|