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