ProductCategory.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 产品类别
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\crm\controller;
  8. use app\admin\controller\ApiCommon;
  9. use think\Hook;
  10. use think\Request;
  11. class ProductCategory extends ApiCommon
  12. {
  13. /**
  14. * 用于判断权限
  15. * @permission 无限制
  16. * @allow 登录用户可访问
  17. * @other 其他根据系统设置
  18. **/
  19. public function _initialize()
  20. {
  21. $action = [
  22. 'permission'=>[''],
  23. 'allow'=>['index','save','update','delete']
  24. ];
  25. Hook::listen('check_auth',$action);
  26. $request = Request::instance();
  27. $a = strtolower($request->action());
  28. if (!in_array($a, $action['permission'])) {
  29. parent::_initialize();
  30. }
  31. $userInfo = $this->userInfo;
  32. //权限判断
  33. $unAction = ['index'];
  34. if (!in_array($a, $unAction) && !checkPerByAction('admin', 'crm', 'setting')) {
  35. header('Content-Type:application/json; charset=utf-8');
  36. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  37. }
  38. }
  39. /**
  40. * 产品分类列表
  41. * @author Michael_xu
  42. * @return
  43. */
  44. public function index()
  45. {
  46. $categoryModel = model('ProductCategory');
  47. $param = $this->param;
  48. $data = $categoryModel->getDataList($param['type']);
  49. return resultArray(['data' => $data]);
  50. }
  51. /**
  52. * 添加产品分类
  53. * @author Michael_xu
  54. * @param
  55. * @return
  56. */
  57. public function save()
  58. {
  59. $categoryModel = model('ProductCategory');
  60. $param = $this->param;
  61. $userInfo = $this->userInfo;
  62. $param['create_user_id'] = $userInfo['id'];
  63. $res = $categoryModel->createData($param);
  64. if ($res) {
  65. return resultArray(['data' => '添加成功']);
  66. } else {
  67. return resultArray(['error' => $categoryModel->getError()]);
  68. }
  69. }
  70. /**
  71. * 编辑产品分类
  72. * @author Michael_xu
  73. * @param
  74. * @return
  75. */
  76. public function update()
  77. {
  78. $categoryModel = model('ProductCategory');
  79. $param = $this->param;
  80. $userInfo = $this->userInfo;
  81. $res = $categoryModel->updateDataById($param, $param['id']);
  82. if ($res) {
  83. return resultArray(['data' => '编辑成功']);
  84. } else {
  85. return resultArray(['error' => $categoryModel->getError()]);
  86. }
  87. }
  88. /**
  89. * 删除产品分类
  90. * @author Michael_xu
  91. * @param
  92. * @return
  93. */
  94. public function delete()
  95. {
  96. $categoryModel = model('ProductCategory');
  97. $param = $this->param;
  98. $data = $categoryModel->delDataById($param['id'], true);
  99. if (!$data) {
  100. return resultArray(['error' => $categoryModel->getError()]);
  101. }
  102. return resultArray(['data' => '删除成功']);
  103. }
  104. }