Work.php 24KB

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