| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- // +----------------------------------------------------------------------
- // | Description: 产品类别
- // +----------------------------------------------------------------------
- // | Author: Michael_xu | gengxiaoxu@5kcrm.com
- // +----------------------------------------------------------------------
-
- namespace app\crm\controller;
-
- use app\admin\controller\ApiCommon;
- use think\Hook;
- use think\Request;
-
- class ProductCategory extends ApiCommon
- {
- /**
- * 用于判断权限
- * @permission 无限制
- * @allow 登录用户可访问
- * @other 其他根据系统设置
- **/
- public function _initialize()
- {
- $action = [
- 'permission'=>[''],
- 'allow'=>['index','save','update','delete']
- ];
- Hook::listen('check_auth',$action);
- $request = Request::instance();
- $a = strtolower($request->action());
- if (!in_array($a, $action['permission'])) {
- parent::_initialize();
- }
-
- $userInfo = $this->userInfo;
- //权限判断
- $unAction = ['index'];
- if (!in_array($a, $unAction) && !checkPerByAction('admin', 'crm', 'setting')) {
- header('Content-Type:application/json; charset=utf-8');
- exit(json_encode(['code'=>102,'error'=>'无权操作']));
- }
- }
-
- /**
- * 产品分类列表
- * @author Michael_xu
- * @return
- */
- public function index()
- {
- $categoryModel = model('ProductCategory');
- $param = $this->param;
- $data = $categoryModel->getDataList($param['type']);
- return resultArray(['data' => $data]);
- }
-
- /**
- * 添加产品分类
- * @author Michael_xu
- * @param
- * @return
- */
- public function save()
- {
- $categoryModel = model('ProductCategory');
- $param = $this->param;
- $userInfo = $this->userInfo;
- $param['create_user_id'] = $userInfo['id'];
-
- $res = $categoryModel->createData($param);
- if ($res) {
- return resultArray(['data' => '添加成功']);
- } else {
- return resultArray(['error' => $categoryModel->getError()]);
- }
- }
-
- /**
- * 编辑产品分类
- * @author Michael_xu
- * @param
- * @return
- */
- public function update()
- {
- $categoryModel = model('ProductCategory');
- $param = $this->param;
- $userInfo = $this->userInfo;
-
- $res = $categoryModel->updateDataById($param, $param['id']);
- if ($res) {
- return resultArray(['data' => '编辑成功']);
- } else {
- return resultArray(['error' => $categoryModel->getError()]);
- }
- }
-
- /**
- * 删除产品分类
- * @author Michael_xu
- * @param
- * @return
- */
- public function delete()
- {
- $categoryModel = model('ProductCategory');
- $param = $this->param;
- $data = $categoryModel->delDataById($param['id'], true);
- if (!$data) {
- return resultArray(['error' => $categoryModel->getError()]);
- }
- return resultArray(['data' => '删除成功']);
- }
- }
|