BusinessStatus.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. $res = $businessStatusModel->updateDataById($param, $param['type_id']);
  100. if ($res) {
  101. $key = 'BI_queryCache_StatusList_Data';
  102. cache($key, null, true);
  103. return resultArray(['data' => '编辑成功']);
  104. } else {
  105. return resultArray(['error' => $businessStatusModel->getError()]);
  106. }
  107. }
  108. /**
  109. * 商机组(停用)
  110. * @author Michael_xu
  111. * @param status 1启用, 0停用
  112. * @return
  113. */
  114. public function enables()
  115. {
  116. $businessStatusModel = model('BusinessStatus');
  117. $param = $this->param;
  118. $userInfo=$this->userInfo;
  119. if ($param['id'] == 1) {
  120. return resultArray(['error' => '系统数据,不能操作']);
  121. }
  122. $status = $param['status'] ? : '0';
  123. if (db('crm_business_type')->where(['type_id' => $param['id']])->setField('status', $status)) {
  124. $data=db('crm_business_type')->where(['type_id' => $param['id']])->find();
  125. if($status==0){
  126. $status='停用了商机组:'.$data['name'];
  127. }else{
  128. $status='启用了商机组:'.$data['name'];
  129. }
  130. # 系统操作日志
  131. SystemActionLog($userInfo['id'], 'crm_business_type','customer', $param['id'], 'update',$data['name'] , '', '',$status);
  132. return resultArray(['data' => '操作成功']);
  133. } else {
  134. return resultArray(['error' => $businessStatusModel->getError()]);
  135. }
  136. }
  137. /**
  138. * 删除商机组
  139. * @author Michael_xu
  140. * @param status 1启用, 0停用
  141. * @return
  142. */
  143. public function delete()
  144. {
  145. $businessStatusModel = model('BusinessStatus');
  146. $param = $this->param;
  147. $data = $businessStatusModel->delDataById($param['id'], true);
  148. if (!$data) {
  149. return resultArray(['error' => $businessStatusModel->getError()]);
  150. }
  151. return resultArray(['data' => '删除成功']);
  152. }
  153. }