123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 项目控制器
  4. // +----------------------------------------------------------------------
  5. // | Author: yykun
  6. // +----------------------------------------------------------------------
  7. namespace app\work\controller;
  8. use app\crm\model\Activity;
  9. use app\work\logic\WorkLogic;
  10. use app\work\traits\WorkAuthTrait;
  11. use think\Request;
  12. use think\Hook;
  13. use app\admin\controller\ApiCommon;
  14. use think\Db;
  15. class work extends ApiCommon
  16. {
  17. # 项目权限
  18. use WorkAuthTrait;
  19. /**
  20. * 用于判断权限
  21. * @permission 无限制
  22. * @allow 登录用户可访问
  23. * @other 其他根据系统设置
  24. **/
  25. public function _initialize()
  26. {
  27. $action = [
  28. 'permission'=>[''],
  29. 'allow'=>[
  30. 'index',
  31. 'filelist',
  32. 'delete',
  33. 'read',
  34. 'archive',
  35. 'owneradd',
  36. 'ownerdel',
  37. 'ownerlist',
  38. 'leave',
  39. 'archivelist',
  40. 'arrecover',
  41. 'statistic',
  42. 'grouplist',
  43. 'addusergroup',
  44. 'update',
  45. 'follow',
  46. 'updateWorkOrder'
  47. ]
  48. ];
  49. Hook::listen('check_auth',$action);
  50. $request = Request::instance();
  51. $a = strtolower($request->action());
  52. if (!in_array($a, $action['permission'])) {
  53. parent::_initialize();
  54. }
  55. }
  56. /**
  57. * 项目列表
  58. *
  59. * @param WorkLogic $workLogic
  60. * @return \think\response\Json
  61. */
  62. public function index(WorkLogic $workLogic)
  63. {
  64. $this->param['user_id'] = $this->userInfo['id'];
  65. $data = $workLogic->index($this->param);
  66. return resultArray(['data' => $data]);
  67. }
  68. /**
  69. * 创建项目
  70. *
  71. * @return \think\response\Json
  72. */
  73. public function save()
  74. {
  75. $userId = $this->userInfo['id'];
  76. $param = $this->param;
  77. $workModel = model('Work');
  78. if (empty($param['name'])) return resultArray(['error' => '项目名称不能为空']);
  79. if (empty($param['cover_url'])) return resultArray(['error' => '请选择项目封面!']);
  80. # 设置项目创建人和成员
  81. $param['create_user_id'] = $userId;
  82. $ownerUserId = !empty($param['owner_user_id']) ? $param['owner_user_id'] : [$userId];
  83. if (!in_array($userId, $ownerUserId)) $owner_user_id[] = $userId;
  84. $param['owner_user_id'] = $ownerUserId;
  85. if (!$workModel->createData($param)) {
  86. return resultArray(['error' => $workModel->getError()]);
  87. }
  88. return resultArray(['data' => '操作成功!']);
  89. }
  90. /**
  91. * 编辑项目
  92. *
  93. * @return \think\response\Json
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. */
  98. public function update()
  99. {
  100. if (empty($this->param['work_id'])) return resultArray(['error' => '缺少项目ID!']);
  101. if (empty($this->param['name'])) return resultArray(['error' => '项目名称不能为空']);
  102. if (!empty($this->param['is_open']) && empty($this->param['group_id'])) {
  103. return resultArray(['error' => '请选择公开项目成员权限!']);
  104. }
  105. // if (empty($this->param['cover_url'])) return resultArray(['error' => '请选择项目封面!']);
  106. $workModel = model('Work');
  107. $userId = $this->userInfo['id'];
  108. # 权限判断
  109. if (!$this->checkWorkOperationAuth('setWork', $this->param['work_id'], $userId)) {
  110. header('Content-Type:application/json; charset=utf-8');
  111. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  112. }
  113. $this->param['user_id'] = $userId;
  114. if (!$workModel->updateDataById($this->param)) return resultArray(['error' => $workModel->getError()]);
  115. return resultArray(['data' => '操作成功!']);
  116. }
  117. /**
  118. * 项目详情
  119. *
  120. * @return \think\response\Json
  121. * @throws \think\db\exception\DataNotFoundException
  122. * @throws \think\db\exception\ModelNotFoundException
  123. * @throws \think\exception\DbException
  124. */
  125. public function read()
  126. {
  127. if (empty($this->param['work_id'])) return resultArray(['error' => '请选择要查看的项目!']);
  128. $workModel = model('Work');
  129. $workInfo = $workModel->getDataById($this->param['work_id']);
  130. # 是否是公开项目
  131. $userId = $this->userInfo['id'];
  132. $groupId = !empty($workInfo['is_open']) ? $workInfo['group_id'] : 0;
  133. # 项目成员
  134. $workInfo['ownerUser'] = db('admin_user')->field(['id', 'realname'])->whereIn('id', trim($workInfo['owner_user_id'], ','))->select();
  135. $workInfo['auth'] = $this->getRuleList($this->param['work_id'], $userId, $groupId);
  136. return resultArray(['data' => $workInfo]);
  137. }
  138. /**
  139. * 删除项目
  140. *
  141. * @return \think\response\Json
  142. * @throws \think\Exception
  143. * @throws \think\exception\PDOException
  144. */
  145. public function delete()
  146. {
  147. $param = $this->param;
  148. $userInfo = $this->userInfo;
  149. $workModel = model('Work');
  150. if (empty($param['work_id'])) return resultArray(['error' => '请选择要删除的项目!']);
  151. # 权限判断
  152. if (!$this->checkWorkOperationAuth('setWork', $param['work_id'], $userInfo['id'])) {
  153. header('Content-Type:application/json; charset=utf-8');
  154. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  155. }
  156. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  157. // header('Content-Type:application/json; charset=utf-8');
  158. // exit(json_encode(['code'=>102,'error'=>'无权操作']));
  159. // }
  160. $param['create_user_id'] = $userInfo['id'];
  161. $resWork = $workModel->delWorkById($param);
  162. if ($resWork) {
  163. //删除项目下所有任务
  164. $resTask = db('task')->where(['work_id' => $param['work_id']])->delete();
  165. return resultArray(['data'=>'删除成功']);
  166. } else {
  167. return resultArray(['error'=>$workModel->getError()]);
  168. }
  169. }
  170. /**
  171. * 归档项目
  172. * @author yykun
  173. * @return
  174. */
  175. public function archive()
  176. {
  177. $param = $this->param;
  178. $userInfo = $this->userInfo;
  179. $workModel = model('Work');
  180. if (!$param['work_id']) {
  181. return resultArray(['error'=>'参数错误']);
  182. }
  183. # 权限判断
  184. if (!$this->checkWorkOperationAuth('setWork', $param['work_id'], $userInfo['id'])) {
  185. header('Content-Type:application/json; charset=utf-8');
  186. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  187. }
  188. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  189. // header('Content-Type:application/json; charset=utf-8');
  190. // exit(json_encode(['code'=>102,'error'=>'无权操作']));
  191. // }
  192. $param['create_user_id'] = $userInfo['id'];
  193. $flag = $workModel->archiveData($param);
  194. if ($flag) {
  195. return resultArray(['data'=>'归档成功']);
  196. } else {
  197. return resultArray(['error'=>$workModel->getError()]);
  198. }
  199. }
  200. /**
  201. * 参与人添加
  202. *
  203. * @return \think\response\Json
  204. * @throws \think\db\exception\DataNotFoundException
  205. * @throws \think\db\exception\ModelNotFoundException
  206. * @throws \think\exception\DbException
  207. */
  208. public function ownerAdd()
  209. {
  210. $param = $this->param;
  211. $userInfo = $this->userInfo;
  212. if (!$param['work_id'] || !$param['owner_user_id']) {
  213. return resultArray(['error'=>'参数错误']);
  214. }
  215. $workModel = model('Work');
  216. # 权限判断
  217. if (!$this->checkWorkOperationAuth('setWork', $param['work_id'], $userInfo['id'])) {
  218. header('Content-Type:application/json; charset=utf-8');
  219. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  220. }
  221. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  222. // header('Content-Type:application/json; charset=utf-8');
  223. // exit(json_encode(['code'=>102,'error'=>'无权操作']));
  224. // }
  225. $res = $workModel->addOwner($param);
  226. if ($res) {
  227. $temp['work_id'] = $param['work_id'];
  228. $list = $workModel->ownerList($temp); //获取参与人列表
  229. return resultArray(['data'=>$list]);
  230. } else {
  231. return resultArray(['error'=>'操作失败']);
  232. }
  233. }
  234. /**
  235. * 参与人删除
  236. * @author yykun
  237. * @return
  238. */
  239. public function ownerDel()
  240. {
  241. $param = $this->param;
  242. $userInfo = $this->userInfo;
  243. if (!$param['work_id'] || !$param['owner_user_id']) {
  244. return resultArray(['error'=>'参数错误']);
  245. }
  246. $workModel = model('Work');
  247. # 权限判断
  248. if (!$this->checkWorkOperationAuth('setWork', $param['work_id'], $userInfo['id'])) {
  249. header('Content-Type:application/json; charset=utf-8');
  250. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  251. }
  252. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  253. // header('Content-Type:application/json; charset=utf-8');
  254. // exit(json_encode(['code'=>102,'error'=>'无权操作']));
  255. // }
  256. $res = $workModel->delOwner($param);
  257. if ($res) {
  258. return resultArray(['data'=>'操作成功']);
  259. } else {
  260. return resultArray(['error'=>$workModel->getError()]);
  261. }
  262. }
  263. /**
  264. * 参与人列表
  265. * @author yykun
  266. * @return
  267. */
  268. public function ownerList()
  269. {
  270. $param = $this->param;
  271. $workModel = model('Work');
  272. $list = $workModel->ownerList($param);
  273. return resultArray(['data'=>$list]);
  274. }
  275. /**
  276. * 退出项目
  277. * @author yykun
  278. * @return
  279. */
  280. public function leave()
  281. {
  282. $param = $this->param;
  283. $userInfo = $this->userInfo;
  284. $workModel = model('Work');
  285. if (!$param['work_id']) {
  286. return resultArray(['error'=>'参数错误']);
  287. }
  288. $ret = $workModel->leaveById($param['work_id'],$userInfo['id']);
  289. if ($ret) {
  290. return resultArray(['data'=>'操作成功']);
  291. } else {
  292. return resultArray(['error'=>$workModel->getError()]);
  293. }
  294. }
  295. /**
  296. * 归档项目列表
  297. * @author yykun
  298. * @return
  299. */
  300. public function archiveList()
  301. {
  302. $param = $this->param;
  303. $userInfo = $this->userInfo;
  304. $param['user_id'] = $userInfo['id'];
  305. $workModel = model('Work');
  306. $list = $workModel->archiveList($param);
  307. return resultArray(['data'=>$list]);
  308. }
  309. /**
  310. * 恢复归档项目
  311. * @author yykun
  312. * @return
  313. */
  314. public function arRecover()
  315. {
  316. $param = $this->param;
  317. $userInfo = $this->userInfo;
  318. if (!$param['work_id']) {
  319. return resultArray(['error'=>'参数错误']);
  320. }
  321. $workModel = Model('Work');
  322. # 权限判断
  323. if (!$this->checkWorkOperationAuth('setWork', $param['work_id'], $userInfo['id'])) {
  324. header('Content-Type:application/json; charset=utf-8');
  325. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  326. }
  327. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  328. // header('Content-Type:application/json; charset=utf-8');
  329. // exit(json_encode(['code'=>102,'error'=>'无权操作']));
  330. // }
  331. $ret = $workModel->arRecover($param['work_id']);
  332. if ($ret) {
  333. return resultArray(['data'=>'操作成功']);
  334. } else {
  335. return resultArray(['error'=>$workModel->getError()]);
  336. }
  337. }
  338. /**
  339. * 项目任务统计
  340. *
  341. * @return \think\response\Json
  342. * @throws \think\db\exception\DataNotFoundException
  343. * @throws \think\db\exception\ModelNotFoundException
  344. * @throws \think\exception\DbException
  345. */
  346. public function statistic()
  347. {
  348. if (empty($this->param['work_id'])) return resultArray(['error'=>'参数错误']);
  349. $userModel = new \app\admin\model\User();
  350. $workModel = model('work');
  351. $param = $this->param;
  352. $work_id = $param['work_id'];
  353. $userInfo = $this->userInfo;
  354. $dataCount = [];
  355. if ($work_id !== 'all') $workInfo = Db::name('Work')->where(['work_id' => $work_id])->find();
  356. $lableary = []; # 标签
  357. $main_user_arr = []; # 成员
  358. $allNum = 0; # 总任务数
  359. $undoneNum = 0; # 总未完成数
  360. $doneNum = 0; # 总完成数
  361. $overtimeNum = 0; # 总延期数
  362. $archiveNum = 0; # 总归档数
  363. $completionRate = 0; # 总完成率
  364. $delayRate = 0; # 总延期率
  365. $workIds = [];
  366. $groupIds = db('admin_access')->where('user_id', $userInfo['id'])->column('group_id');
  367. $isSuperAdmin = $userInfo['id'] == 1 || in_array(1, (array)$groupIds); # 是否是超管
  368. if (empty($isSuperAdmin)) $workIds = db('work_user')->where('user_id', $userInfo['id'])->column('work_id');
  369. //公开项目
  370. if ($work_id !== 'all') {
  371. $taskList = Db::name('Task')->where(['work_id' => $work_id, 'ishidden' => 0, 'pid' => 0])->field('task_id,main_user_id,lable_id,status,owner_user_id,stop_time,is_archive')->select();
  372. } else {
  373. $where['work_id'] = !empty($isSuperAdmin) ? ['gt', 0] : ['in', $workIds];
  374. $where['ishidden'] = 0;
  375. $where['pid'] = 0;
  376. $taskList = Db::name('Task')->where($where)->field('task_id,main_user_id,lable_id,status,owner_user_id,stop_time,is_archive')->select();
  377. }
  378. foreach ($taskList as $key => $value) {
  379. if (empty($value['is_archive'])) {
  380. $allNum += 1;
  381. if ($value['status'] == 1) {
  382. $undoneNum += 1;
  383. }
  384. if ($value['status'] == 1 && $value['stop_time'] && ($value['stop_time'] < time())) {
  385. $overtimeNum += 1;
  386. }
  387. }
  388. if ($value['is_archive'] == 1) $archiveNum += 1;
  389. if ($value['status'] == 5) $doneNum += 1;
  390. //获取项目下成员ID
  391. // if ($value['owner_user_id'] && $workInfo['is_open'] == 1) $main_user_arr[] = $value['main_user_id']; //负责人
  392. // if ($work_id == 'all') $main_user_arr[] = $value['main_user_id']; //负责人
  393. $main_user_arr[] = $value['main_user_id'];
  394. $lableArray = [];
  395. $lableArray = $value['lable_id'] ? stringToArray($value['lable_id']) : []; //标签
  396. $lableary = $lableArray ? array_merge($lableary,$lableArray) : $lableary;
  397. }
  398. $main_user_arr = $main_user_arr ? array_filter(array_unique($main_user_arr)) : [];
  399. $lableary = array_filter(array_unique($lableary));
  400. $completionRate = $allNum ? round(($doneNum / $allNum) * 100,2) : 0;
  401. $delayRate = $allNum ? round(($overtimeNum / $allNum) * 100,2) : 0;
  402. $dataCount['allNum'] = !empty($allNum) ? $allNum : 0;
  403. $dataCount['undoneNum'] = !empty($undoneNum) ? $undoneNum : 0;
  404. $dataCount['doneNum'] = !empty($doneNum) ? $doneNum : 0;
  405. $dataCount['overtimeNum'] = !empty($overtimeNum) ? $overtimeNum : 0;
  406. $dataCount['archiveNum'] = !empty($archiveNum) ? $archiveNum : 0;
  407. $dataCount['completionRate'] = !empty($completionRate) ? round($completionRate) : 0;
  408. $dataCount['delayRate'] = !empty($delayRate) ? $delayRate : 0;
  409. //项目负责人
  410. $ownerArr = [];
  411. if ($workInfo && $workInfo['is_open'] == 0) {
  412. //私有项目
  413. // $main_user_arr = db('work_user')->where(['work_id' => $work_id])->column('user_id');
  414. $ownerArr = db('work_user')->where(['work_id' => $work_id,'types' => 1])->column('user_id');
  415. } elseif ($work_id !== 'all') {
  416. $ownerArr[] = $workInfo['create_user_id'];
  417. }
  418. $ownerList = [];
  419. foreach ($ownerArr as $k3=>$v3) {
  420. $ownerList[] = $userModel->getUserById($v3);
  421. }
  422. $dataAry['ownerList'] = $ownerList ? : [];
  423. // $dataAry['workInfo'] = $workInfo ? : [];
  424. //成员统计
  425. $list = [];
  426. $i = 0;
  427. $main_user_arr = $main_user_arr ? array_merge($main_user_arr) : [];
  428. foreach ($main_user_arr as $key => $value) {
  429. //参与项目数量
  430. $userInfo = [];
  431. $userInfo = $userModel->getUserById($value);
  432. if (!$userInfo) continue;
  433. $list[$i]['userInfo'] = $userInfo ? : [];
  434. // $workCount = 0; //项目总数
  435. $allCount = 0; //任务总数
  436. $undoneCount = 0; //待完成任务总数
  437. $doneCount = 0; //已完成任务总数
  438. $overtimeCount = 0; //延期任务总数
  439. $archiveCount = 0; //归档任务总数
  440. $completionRate = 0; //完成率
  441. $taskArr = [];
  442. if ($work_id == 'all') {
  443. $taskWhere['work_id'] = !empty($isSuperAdmin) ? ['gt', 0] : ['in', $workIds];
  444. $taskWhere['main_user_id'] = $value;
  445. $taskWhere['ishidden'] = 0;
  446. $taskWhere['pid'] = 0;
  447. $taskArr = db('task')->where($taskWhere)->field('status,stop_time,is_archive,task_id')->select();
  448. } else {
  449. $taskArr = db('task')->where(['work_id' => $work_id, 'main_user_id' => $value, 'ishidden' => 0, 'pid' => 0])->field('status,stop_time,is_archive,task_id')->select();
  450. }
  451. foreach ($taskArr as $v) {
  452. $allCount += 1;
  453. if ($v['status'] == 1 && empty($v['is_archive'])) $undoneCount += 1;
  454. if (($v['status'] == 1 && empty($v['is_archive'])) && $v['stop_time'] && ($v['stop_time'] < time())) $overtimeCount += 1;
  455. if ($v['is_archive'] == 1) $archiveCount += 1;
  456. if ($v['status'] == 5) $doneCount += 1;
  457. }
  458. $completionRate = $allCount ? round(($doneCount/$allCount),2)*100 : 0;
  459. $list[$i]['allCount'] = $allCount ? : 0;
  460. $list[$i]['undoneCount'] = $undoneCount ? : 0;
  461. $list[$i]['doneCount'] = $doneCount ? : 0;
  462. $list[$i]['overtimeCount'] = $overtimeCount ? : 0;
  463. $list[$i]['archiveCount'] = $archiveCount ? : 0;
  464. $list[$i]['completionRate'] = $completionRate ? : 0;
  465. $list[$i]['realname'] = !empty($userInfo) ? $userInfo['realname'] : '';
  466. $i++;
  467. }
  468. $dataAry['dataCount'] = $dataCount;
  469. $dataAry['userList'] = $list;
  470. if ($work_id !== 'all') {
  471. //任务列表统计
  472. $dataAry['classList'] = $workModel->classList($work_id);
  473. //标签统计
  474. $dataAry['labelList'] = $workModel->labelList($work_id,$lableary);
  475. }
  476. return resultArray(['data'=>$dataAry]);
  477. }
  478. /**
  479. * 参与人角色添加
  480. *
  481. * @return \think\response\Json
  482. * @throws \think\Exception
  483. * @throws \think\db\exception\DataNotFoundException
  484. * @throws \think\db\exception\ModelNotFoundException
  485. * @throws \think\exception\DbException
  486. * @throws \think\exception\PDOException
  487. */
  488. public function addUserGroup()
  489. {
  490. $param = $this->param;
  491. $userInfo = $this->userInfo;
  492. $workModel = model('Work');
  493. $list = $param['list'] ? : [];
  494. $work_id = $param['work_id'] ? : [];
  495. if (!is_array($list) || !$work_id) {
  496. return resultArray(['error'=>'参数错误']);
  497. }
  498. # 权限判断
  499. if (!$this->checkWorkOperationAuth('setWork', $work_id, $userInfo['id'])) {
  500. header('Content-Type:application/json; charset=utf-8');
  501. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  502. }
  503. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  504. // header('Content-Type:application/json; charset=utf-8');
  505. // exit(json_encode(['code'=>102,'error'=>'无权操作1']));
  506. // }
  507. foreach ($list as $value) {
  508. $data = array();
  509. $types = 0;
  510. $data['work_id'] = $work_id;
  511. $data['user_id'] = $value['user_id'];
  512. $flag = db('work_user')->where($data)->find();
  513. $data['group_id'] = $value['group_id'];
  514. if ($value['group_id'] == 1) $types = 1; //项目管理员,不能删除
  515. $data['types'] = $types;
  516. if (!$flag) {
  517. db('work_user')->insert($data);
  518. } else {
  519. db('work_user')->where(['work_id' => $work_id,'user_id' => $value['user_id']])->update($data);
  520. }
  521. }
  522. $dataList = db('work_user')->where(['work_id' => $work_id])->select();
  523. return resultArray(['data'=>$dataList]);
  524. }
  525. /**
  526. * 项目下附件列表
  527. *
  528. * @param
  529. * @return
  530. */
  531. public function fileList()
  532. {
  533. $param = $this->param;
  534. $userInfo = $this->userInfo;
  535. $workModel = model('Work');
  536. $work_id = $param['work_id'];
  537. if (!$work_id) {
  538. return resultArray(['error'=>'参数错误']);
  539. }
  540. //判断权限
  541. $checkRes = $workModel->checkWork($work_id, $userInfo['id']);
  542. if ($checkRes !== true) {
  543. return resultArray(['error' => $workModel->getError()]);
  544. }
  545. $task_ids = db('task')->where(['work_id' => $work_id])->column('task_id');
  546. $request = [];
  547. $request['module'] = 'work_task';
  548. $request['module_id'] = $task_ids;
  549. $fileModel = new \app\admin\model\File();
  550. $data = $fileModel->getDataList($request, $param['by']);
  551. return resultArray(['data' => $data]);
  552. }
  553. /**
  554. * 项目角色列表
  555. *
  556. * @return \think\response\Json
  557. * @throws \think\db\exception\DataNotFoundException
  558. * @throws \think\db\exception\ModelNotFoundException
  559. * @throws \think\exception\DbException
  560. */
  561. public function groupList()
  562. {
  563. $list[] = ['id' => 1,'title' => '管理', 'remark' => '系统默认权限,包含项目所有权限,不可修改/删除'];
  564. $groupList = db('admin_group')->where(['pid' => 5, 'types' => 7, 'type' => 0])->order('system desc')->field('id, title, remark')->select();
  565. $listArr = array_merge($list, $groupList) ? : [];
  566. return resultArray(['data' => $listArr]);
  567. }
  568. /**
  569. * 项目关注
  570. *
  571. * @return \think\response\Json
  572. * @throws \think\Exception
  573. * @throws \think\exception\PDOException
  574. */
  575. public function follow()
  576. {
  577. if (!isset($this->param['follow']) || empty($this->param['work_id'])) return resultArray(['error' => '参数错误!']);
  578. $this->param['follow'] = !empty($this->param['follow']) ? $this->param['follow'] : 0;
  579. if (!Db::name('work')->where('work_id', $this->param['work_id'])->update(['is_follow' => $this->param['follow']])) {
  580. return resultArray(['error' => '操作失败!']);
  581. }
  582. return resultArray(['data' => '操作成功!']);
  583. }
  584. /**
  585. * 项目列表排序
  586. *
  587. * @author fanqi
  588. * @date 2021-03-11
  589. * @param WorkLogic $workLogic
  590. */
  591. public function updateWorkOrder(WorkLogic $workLogic)
  592. {
  593. $workIds = $this->param['workIds'];
  594. $userInfo = $this->userInfo;
  595. $workLogic->setWorkOrder($workIds, $userInfo['id']);
  596. return resultArray(['data' => '操作成功!']);
  597. }
  598. }