123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 业绩目标设置及完成情况统计
  4. // +----------------------------------------------------------------------
  5. // | Author: yykun
  6. // +----------------------------------------------------------------------
  7. namespace app\crm\controller;
  8. use app\admin\controller\ApiCommon;
  9. use app\crm\logic\AchievementLogic;
  10. use think\Hook;
  11. use think\Request;
  12. class Achievement extends ApiCommon
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission'=>[''],
  24. 'allow'=>['index','indexforuser','save','read','update','delete']
  25. ];
  26. Hook::listen('check_auth',$action);
  27. $request = Request::instance();
  28. $a = strtolower($request->action());
  29. if (!in_array($a, $action['permission'])) {
  30. parent::_initialize();
  31. }
  32. $userInfo = $this->userInfo;
  33. //权限判断
  34. $unAction = [''];
  35. if (!in_array($a, $unAction) && !checkPerByAction('admin', 'crm', 'achievement')) {
  36. header('Content-Type:application/json; charset=utf-8');
  37. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  38. }
  39. }
  40. /**
  41. * 业绩目标列表
  42. * @author yykun
  43. * @return
  44. */
  45. public function index(AchievementLogic $achievementLogic)
  46. {
  47. // $model = model('Achievement');
  48. // $param = $this->param;
  49. // $data = $model->getDataList($param);
  50. // return resultArray(['data' => $data]);
  51. if (empty($this->param['year'])) return resultArray(['error' => '请选择年份!']);
  52. if (empty($this->param['type'])) return resultArray(['error' => '请选择业绩类型']);
  53. if (empty($this->param['structure_id'])) return resultArray(['error' => '请选择部门或员工!']);
  54. $data = $achievementLogic->getDepartmentList($this->param);
  55. return resultArray(['data' => $data]);
  56. }
  57. //员工业绩目标列表
  58. public function indexForuser(AchievementLogic $achievementLogic)
  59. {
  60. $model = model('Achievement');
  61. $param = $this->param;
  62. $data = $model->getDataListForUser($param);
  63. # 剔除没有业绩目标的员工
  64. foreach ($data AS $key => $value) {
  65. if (empty((int)$value['yeartarget'])) unset($data[(int)$key]);
  66. }
  67. return resultArray(['data' => array_values($data)]);
  68. // if (empty($this->param['year'])) return resultArray(['error' => '请选择年份!']);
  69. // if (empty($this->param['type'])) return resultArray(['error' => '请选择业绩类型']);
  70. // if (empty($this->param['structure_id']) && empty($this->param['user_id'])) {
  71. // return resultArray(['error' => '请选择部门或员工!']);
  72. // }
  73. //
  74. // $data = $achievementLogic->getEmployeeList($this->param);
  75. //
  76. // return resultArray(['data' => $data]);
  77. }
  78. /**
  79. * 添加
  80. * @author yykun
  81. * @param
  82. * @return
  83. */
  84. public function save()
  85. {
  86. $model = model('Achievement');
  87. $param = $this->param;
  88. $userInfo = $this->userInfo;
  89. if ($model->createData($param)) {
  90. # 系统操作日志
  91. SystemActionLog($userInfo['id'], 'crm_number_sequence','customer', 1, 'save','业绩目标设置' , '', '','添加了业绩目标');
  92. return resultArray(['data' => '添加成功']);
  93. } else {
  94. return resultArray(['error' => $model->getError()]);
  95. }
  96. }
  97. /**
  98. * 详情
  99. * @author yykun
  100. * @param
  101. * @return
  102. */
  103. public function read()
  104. {
  105. $model = model('Achievement');
  106. $param = $this->param;
  107. $data = $model->getDataById($param['id']);
  108. if (!$data) {
  109. return resultArray(['error' => $model->getError()]);
  110. } else {
  111. return resultArray(['data' => $data]);
  112. }
  113. }
  114. /**
  115. * 编辑信息
  116. * @author yykun
  117. * @param
  118. * @return
  119. */
  120. public function update()
  121. {
  122. $model = model('Achievement');
  123. $userInfo = $this->userInfo;
  124. $param = $this->param;
  125. if ($model->updateData($param)) {
  126. # 系统操作日志
  127. SystemActionLog($userInfo['id'], 'crm_number_sequence','customer', 1, 'update','业绩目标设置' , '', '','设置了业绩目标');
  128. return resultArray(['data' => '编辑成功']);
  129. } else {
  130. return resultArray(['error' => $model->getError()]);
  131. }
  132. }
  133. /**
  134. * 删除
  135. *
  136. * @return \think\response\Json
  137. * @throws \think\Exception
  138. * @throws \think\exception\PDOException
  139. */
  140. public function delete()
  141. {
  142. if (empty($this->param['achievement_id'])) return resultArray(['error' => '参数错误!']);
  143. $model = new \app\crm\model\Achievement();
  144. $userInfo = $this->userInfo;
  145. if (!$model->delete($this->param['achievement_id'])) return resultArray(['error' => '操作失败!']);
  146. # 系统操作日志
  147. SystemActionLog($userInfo['id'], 'crm_number_sequence','customer', 1, 'update','业绩目标设置' , '', '','删除了业绩目标');
  148. return resultArray(['data' => '操作成功!']);
  149. }
  150. }