BusinessStatus.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 BusinessStatus extends ApiCommon
  12. {
  13. /**
  14. * 用于判断权限
  15. * @permission 无限制
  16. * @allow 登录用户可访问
  17. * @other 其他根据系统设置
  18. **/
  19. public function _initialize()
  20. {
  21. $action = [
  22. 'permission'=>[''],
  23. 'allow'=>['type','save','update','read','enables','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 = ['type'];
  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 type()
  45. {
  46. $businessStatusModel = model('BusinessStatus');
  47. $param = $this->param;
  48. $data = $businessStatusModel->getTypeList($param);
  49. return resultArray(['data' => $data]);
  50. }
  51. /**
  52. * 添加商机组
  53. * @author Michael_xu
  54. * @param
  55. * @return
  56. */
  57. public function save()
  58. {
  59. $businessStatusModel = model('BusinessStatus');
  60. $param = $this->param;
  61. $userInfo = $this->userInfo;
  62. $param['create_user_id'] = $userInfo['id'];
  63. $res = $businessStatusModel->createData($param);
  64. if ($res) {
  65. $key = 'BI_queryCache_StatusList_Data';
  66. cache($key, null, true);
  67. return resultArray(['data' => '添加成功']);
  68. } else {
  69. return resultArray(['error' => $businessStatusModel->getError()]);
  70. }
  71. }
  72. /**
  73. * 商机组详情
  74. * @author Michael_xu
  75. * @param
  76. * @return
  77. */
  78. public function read()
  79. {
  80. $businessStatusModel = model('BusinessStatus');
  81. $param = $this->param;
  82. $data = $businessStatusModel->getDataById($param['id']);
  83. if (!$data) {
  84. return resultArray(['error' => $businessStatusModel->getError()]);
  85. }
  86. return resultArray(['data' => $data]);
  87. }
  88. /**
  89. * 编辑商机组
  90. * @author Michael_xu
  91. * @param
  92. * @return
  93. */
  94. public function update()
  95. {
  96. $businessStatusModel = model('BusinessStatus');
  97. $param = $this->param;
  98. $userInfo = $this->userInfo;
  99. $param['user_id']=$userInfo['id'];
  100. $res = $businessStatusModel->updateDataById($param, $param['type_id']);
  101. if ($res) {
  102. $key = 'BI_queryCache_StatusList_Data';
  103. cache($key, null, true);
  104. return resultArray(['data' => '编辑成功']);
  105. } else {
  106. return resultArray(['error' => $businessStatusModel->getError()]);
  107. }
  108. }
  109. /**
  110. * 商机组(停用)
  111. * @author Michael_xu
  112. * @param status 1启用, 0停用
  113. * @return
  114. */
  115. public function enables()
  116. {
  117. $businessStatusModel = model('BusinessStatus');
  118. $param = $this->param;
  119. $userInfo=$this->userInfo;
  120. if ($param['id'] == 1) {
  121. return resultArray(['error' => '系统数据,不能操作']);
  122. }
  123. $status = $param['status'] ? : '0';
  124. if (db('crm_business_type')->where(['type_id' => $param['id']])->setField('status', $status)) {
  125. $data=db('crm_business_type')->where(['type_id' => $param['id']])->find();
  126. if($status==0){
  127. $status='停用了商机组:'.$data['name'];
  128. }else{
  129. $status='启用了商机组:'.$data['name'];
  130. }
  131. # 系统操作日志
  132. SystemActionLog($userInfo['id'], 'crm_business_type','customer', $param['id'], 'update',$data['name'] , '', '',$status);
  133. return resultArray(['data' => '操作成功']);
  134. } else {
  135. return resultArray(['error' => $businessStatusModel->getError()]);
  136. }
  137. }
  138. /**
  139. * 删除商机组
  140. * @author Michael_xu
  141. * @param status 1启用, 0停用
  142. * @return
  143. */
  144. public function delete()
  145. {
  146. $businessStatusModel = model('BusinessStatus');
  147. $param = $this->param;
  148. $userInfo=$this->userInfo;
  149. $param['user_id']=$userInfo['id'];
  150. $data = $businessStatusModel->delDataById($param, true);
  151. if (!$data) {
  152. return resultArray(['error' => $businessStatusModel->getError()]);
  153. }
  154. return resultArray(['data' => '删除成功']);
  155. }
  156. }