123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\store\product\label;
- use app\controller\store\AuthController;
- use app\services\product\label\StoreProductLabelCateServices;
- use app\services\product\label\StoreProductLabelServices;
- use think\facade\App;
- use app\Request;
- /**
- * 商品标签
- * Class StoreProductLabel
- * @package app\controller\store\product\label
- */
- class StoreProductLabel extends AuthController
- {
- /**
- * StoreProductLabel constructor.
- * @param App $app
- * @param StoreProductLabelServices $services
- */
- public function __construct(App $app, StoreProductLabelServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 带标签的标签组树形结构
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function tree_list()
- {
- return $this->success($this->services->getProductLabelTreeList());
- }
- /**
- * 获取商品标签列表
- * @return mixed
- */
- public function allLabel()
- {
- return $this->success($this->services->getAllLabel(1, (int)$this->storeId));
- }
- /**
- * 添加、编辑商品标签
- * @param Request $request
- * @param $id
- * @return mixed
- */
- public function save(Request $request, $id)
- {
- $data = $request->postMore([
- ['label_cate', 0],
- ['label_name', ''],
- ]);
- if (!$data['label_cate']) {
- return $this->fail('请选择标签组');
- }
- if (!trim($data['label_name'])) {
- return $this->fail('请输入标签名称');
- }
- $label = $this->services->getOne(['label_cate' => $data['label_cate'], 'label_name' => $data['label_name'], 'type' => 1, 'relation_id' => $this->storeId]);
- if ($id) {
- if ($label && $id != $label['id']) {
- return $this->fail('标签已经存在');
- }
- if ($this->services->update($id, $data)) {
- return $this->success('编辑成功');
- } else {
- return $this->fail('编辑失败');
- }
- } else {
- if ($label) {
- return $this->fail('标签已经存在');
- }
- $data['type'] = 1;
- $data['relation_id'] = $this->storeId;
- $data['add_time'] = time();
- if ($this->services->save($data)) {
- return $this->success('保存成功');
- } else {
- return $this->fail('保存失败');
- }
- }
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- if (!$id || !$this->services->count(['id' => $id])) {
- return $this->fail('删除的数据不存在');
- }
- $this->services->delete($id);
- return $this->success('删除成功');
- }
- /**
- * 获取表单
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getLabelForm()
- {
- return $this->success($this->services->getLabelForm());
- }
- }
|