Tasklable.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 任务标签及基础
  4. // +----------------------------------------------------------------------
  5. // | Author: yykun
  6. // +----------------------------------------------------------------------
  7. namespace app\oa\controller;
  8. use think\Request;
  9. use think\Session;
  10. use think\Hook;
  11. use think\Db;
  12. use app\admin\controller\ApiCommon;
  13. class Tasklable extends ApiCommon
  14. {
  15. /**
  16. * 用于判断权限
  17. * @permission 无限制
  18. * @allow 登录用户可访问
  19. * @other 其他根据系统设置
  20. **/
  21. public function _initialize()
  22. {
  23. $action = [
  24. 'permission'=>[''], //不登录可访问
  25. 'allow'=>['index','getwoklist','grouplist','update','delete','save'] //需要登录才能访问
  26. ];
  27. Hook::listen('check_auth',$action);
  28. $request = Request::instance();
  29. $a = strtolower($request->action());
  30. if (!in_array($a, $action['permission'])) {
  31. parent::_initialize();
  32. }
  33. }
  34. /*
  35. * 添加新标签
  36. */
  37. public function save()
  38. {
  39. $param = $this->param;
  40. $userInfo = $this->userInfo;
  41. $lableModel = new \app\work\model\WorkLable();
  42. if (!$param) {
  43. return resultArray(['error'=>'参数错误']);
  44. }
  45. $param['create_user_id'] = $userInfo['id'];
  46. if (!$lableModel->createData($param)) {
  47. return resultArray(['error'=>$lableModel->getError()]);
  48. }
  49. return resultArray(['data'=>'添加成功']);
  50. }
  51. /*
  52. * 返回标签列表
  53. */
  54. public function index()
  55. {
  56. $lableModel = new \app\work\model\WorkLable();
  57. $list = $lableModel->getDataList();
  58. return resultArray(['data'=>$list]);
  59. }
  60. /**
  61. * 根据标签获取项目及任务
  62. * @return
  63. */
  64. public function getWokList()
  65. {
  66. $param = $this->param;
  67. $userModel = new \app\admin\model\User();
  68. $lable_id = $param['lable_id'];
  69. if (!$lable_id) {
  70. return resultArray(['error'=>'参数错误']);
  71. }
  72. $taskList = Db::name('Task')
  73. ->field('task_id,name,work_id,lable_id,main_user_id,priority,stop_time')
  74. ->where('FIND_IN_SET("'.$lable_id.'", lable_id)')
  75. ->order('work_id desc')->select();
  76. $lableModel = model('WorkLable');
  77. foreach ($taskList as $k => $v) {
  78. $taskList[$k]['lableList'] = $v['lable_id'] ? $lableModel->getDataByStr($v['lable_id']) : [];
  79. $userDet = [];
  80. $userDet = isset($v['main_user_id']) ? $userModel->getUserById($v['main_user_id']) : [];
  81. $taskList[$k]['main_user_name'] = $userDet ? $userDet['realname'] : '';
  82. $taskList[$k]['main_user_img'] = $userDet ? $userDet['thumb_img'] : '';
  83. $taskList[$k]['stop_time'] = $v['stop_time'] ? : '';
  84. }
  85. $workArr = [];
  86. $workGroup = $this->group_same_key($taskList);
  87. $newWorkArr = [];
  88. $i = 0;
  89. foreach ($workGroup as $key => $value) {
  90. $workDet = Db::name('Work')->where(['work_id' => $key])->find();
  91. $newWorkArr[$i]['work_name'] = $workDet['name'];
  92. $newWorkArr[$i]['work_id'] = $key;
  93. $newWorkArr[$i]['list'] = $value;
  94. $i++;
  95. }
  96. return resultArray(['data'=>$newWorkArr]);
  97. }
  98. public function group_same_key( $arr ) {
  99. $new_arr = array();
  100. foreach ($arr as $k => $v) {
  101. $new_arr[$v['work_id']][] = $v;
  102. }
  103. return $new_arr;
  104. }
  105. //分组列表
  106. public function groupList()
  107. {
  108. $lableModel = new \app\work\model\WorkLable();
  109. $workList = Db::name('Work')->field('name,work_id')->select();
  110. $temp = array();
  111. foreach ($workList as $key => $value) {
  112. $temp = array();
  113. $taskList = Db::name('Task')->field('task_id,lable_id')->where(['work_id' => $value['work_id']])->select();
  114. foreach ($taskList as $k => $v) {
  115. $temp_temp = $lableModel->getDataByStr($v['lable_id']);
  116. $temp = array_merge($temp,$temp_temp);
  117. }
  118. $temp = array_filter(array_unique($temp));
  119. $workList[$key]['taskList'] = $temp;
  120. }
  121. return resultArray(['data' => $workList]);
  122. }
  123. /*
  124. *编辑标签
  125. */
  126. public function update()
  127. {
  128. $param = $this->param;
  129. $lableModel = new \app\work\model\WorkLable();
  130. if (!$param['lable_id']) {
  131. return resultArray(['error'=>'参数错误']);
  132. }
  133. $userInfo = $this->userInfo;
  134. $param['create_user_id'] = $userInfo['id'];
  135. if ($lableModel->updateDataById($param)) {
  136. return resultArray(['data'=>'编辑成功']);
  137. } else {
  138. return resultArray(['error'=>$lableModel->getError()]);
  139. }
  140. }
  141. /*
  142. *删除标签
  143. */
  144. public function delete()
  145. {
  146. $param = $this->param;
  147. $lableModel = new \app\work\model\WorkLable();
  148. if (!$param['lable_id']) {
  149. return resultArray(['error'=>'参数错误']);
  150. }
  151. $userInfo = $this->userInfo;
  152. $param['create_user_id'] = $userInfo['id'];
  153. if ($lableModel->delDataById($param)) {
  154. return resultArray(['data'=>'删除成功']);
  155. } else {
  156. return resultArray(['error'=>$lableModel->getError()]);
  157. }
  158. }
  159. }