Achievement.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. // return resultArray(['data' => $data]);
  64. if (empty($this->param['year'])) return resultArray(['error' => '请选择年份!']);
  65. if (empty($this->param['type'])) return resultArray(['error' => '请选择业绩类型']);
  66. if (empty($this->param['structure_id']) && empty($this->param['user_id'])) {
  67. return resultArray(['error' => '请选择部门或员工!']);
  68. }
  69. $data = $achievementLogic->getEmployeeList($this->param);
  70. return resultArray(['data' => $data]);
  71. }
  72. /**
  73. * 添加
  74. * @author yykun
  75. * @param
  76. * @return
  77. */
  78. public function save()
  79. {
  80. $model = model('Achievement');
  81. $param = $this->param;
  82. $userInfo = $this->userInfo;
  83. if ($model->createData($param)) {
  84. return resultArray(['data' => '添加成功']);
  85. } else {
  86. return resultArray(['error' => $model->getError()]);
  87. }
  88. }
  89. /**
  90. * 详情
  91. * @author yykun
  92. * @param
  93. * @return
  94. */
  95. public function read()
  96. {
  97. $model = model('Achievement');
  98. $param = $this->param;
  99. $data = $model->getDataById($param['id']);
  100. if (!$data) {
  101. return resultArray(['error' => $model->getError()]);
  102. } else {
  103. return resultArray(['data' => $data]);
  104. }
  105. }
  106. /**
  107. * 编辑信息
  108. * @author yykun
  109. * @param
  110. * @return
  111. */
  112. public function update()
  113. {
  114. $model = model('Achievement');
  115. $param = $this->param;
  116. if ($model->updateData($param)) {
  117. return resultArray(['data' => '编辑成功']);
  118. } else {
  119. return resultArray(['error' => $model->getError()]);
  120. }
  121. }
  122. /**
  123. * 删除
  124. *
  125. * @return \think\response\Json
  126. * @throws \think\Exception
  127. * @throws \think\exception\PDOException
  128. */
  129. public function delete()
  130. {
  131. if (empty($this->param['achievement_id'])) return resultArray(['error' => '参数错误!']);
  132. $model = new \app\crm\model\Achievement();
  133. if (!$model->delete($this->param['achievement_id'])) return resultArray(['error' => '操作失败!']);
  134. return resultArray(['data' => '操作成功!']);
  135. }
  136. }