123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?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\supplier\product;
- use app\controller\supplier\AuthController;
- use app\services\product\brand\StoreBrandServices;
- use think\facade\App;
- /**
- * 商品品牌控制器
- * Class StoreBrand
- * @package app\controller\supplier\product
- */
- class StoreBrand extends AuthController
- {
- /**
- * @var StoreBrandServices
- */
- protected $service;
- /**
- * StoreCategory constructor.
- * @param App $app
- * @param StoreBrandServices $service
- */
- public function __construct(App $app, StoreBrandServices $service)
- {
- parent::__construct($app);
- $this->service = $service;
- }
- /**
- * 品牌列表
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function index()
- {
- $where = $this->request->getMore([
- ['brand_name', ''],
- ['pid', 0]
- ]);
- $where['is_del'] = 0;
- $data = $this->service->getList($where);
- return $this->success($data);
- }
- /**
- * 获取品牌cascader格式数据
- * @param $type
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function cascader_list($type = 1)
- {
- return $this->success($this->service->cascaderList($type));
- }
- /**
- * 修改状态
- * @param string $is_show
- * @param string $id
- */
- public function set_show($is_show = '', $id = '')
- {
- if ($is_show == '' || $id == '') return $this->fail('缺少参数');
- $this->service->setShow($id, $is_show);
- return $this->success($is_show == 1 ? '显示成功' : '隐藏成功');
- }
- /**
- * 保存新增品牌
- * @return mixed
- */
- public function save()
- {
- $data = $this->request->postMore([
- ['fid', []],
- ['brand_name', ''],
- ['sort', 0],
- ['is_show', 0]
- ]);
- if (!$data['brand_name']) {
- return $this->fail('请输入品牌名称');
- }
- if (iconv_strlen($data['brand_name'], 'UTF-8') > 10) {
- return $this->fail('品牌名称过长');
- }
- $this->service->createData($data);
- return $this->success('添加品牌成功!');
- }
- /**
- * 更新品牌
- * @param $id
- * @return mixed
- */
- public function update($id)
- {
- $data = $this->request->postMore([
- ['fid', []],
- ['brand_name', ''],
- ['sort', 0],
- ['is_show', 0]
- ]);
- if (!$data['brand_name']) {
- return $this->fail('请输入品牌名称');
- }
- if (iconv_strlen($data['brand_name'], 'UTF-8') > 10) {
- return $this->fail('品牌名称过长');
- }
- $this->service->editData($id, $data);
- return $this->success('修改成功!');
- }
- /**
- * 删除品牌
- * @param $id
- * @return mixed
- */
- public function delete($id)
- {
- $this->service->del((int)$id);
- return $this->success('删除成功!');
- }
- }
|