123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. $userId=$userInfo['id'];
  265. if (!$param['work_id'] || !$param['owner_user_id']) {
  266. return resultArray(['error'=>'参数错误']);
  267. }
  268. $workModel = model('Work');
  269. # 权限判断
  270. if (!$this->checkWorkOperationAuth('setWork', $param['work_id'], $userInfo['id'])) {
  271. header('Content-Type:application/json; charset=utf-8');
  272. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  273. }
  274. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  275. // header('Content-Type:application/json; charset=utf-8');
  276. // exit(json_encode(['code'=>102,'error'=>'无权操作']));
  277. // }
  278. $res = $workModel->delOwner($param,$userId);
  279. if ($res) {
  280. return resultArray(['data'=>'操作成功']);
  281. } else {
  282. return resultArray(['error'=>$workModel->getError()]);
  283. }
  284. }
  285. /**
  286. * 参与人列表
  287. * @author yykun
  288. * @return
  289. */
  290. public function ownerList()
  291. {
  292. $param = $this->param;
  293. $workModel = model('Work');
  294. $list = $workModel->ownerList($param);
  295. return resultArray(['data'=>$list]);
  296. }
  297. /**
  298. * 退出项目
  299. * @author yykun
  300. * @return
  301. */
  302. public function leave()
  303. {
  304. $param = $this->param;
  305. $userInfo = $this->userInfo;
  306. $workModel = model('Work');
  307. if (!$param['work_id']) {
  308. return resultArray(['error'=>'参数错误']);
  309. }
  310. $ret = $workModel->leaveById($param['work_id'],$userInfo['id']);
  311. if ($ret) {
  312. return resultArray(['data'=>'操作成功']);
  313. } else {
  314. return resultArray(['error'=>$workModel->getError()]);
  315. }
  316. }
  317. /**
  318. * 归档项目列表
  319. * @author yykun
  320. * @return
  321. */
  322. public function archiveList()
  323. {
  324. $param = $this->param;
  325. $userInfo = $this->userInfo;
  326. $param['user_id'] = $userInfo['id'];
  327. $workModel = model('Work');
  328. $list = $workModel->archiveList($param);
  329. return resultArray(['data'=>$list]);
  330. }
  331. /**
  332. * 恢复归档项目
  333. * @author yykun
  334. * @return
  335. */
  336. public function arRecover()
  337. {
  338. $param = $this->param;
  339. $userInfo = $this->userInfo;
  340. if (!$param['work_id']) {
  341. return resultArray(['error'=>'参数错误']);
  342. }
  343. $workModel = Model('Work');
  344. # 权限判断
  345. if (!$this->checkWorkOperationAuth('setWork', $param['work_id'], $userInfo['id'])) {
  346. header('Content-Type:application/json; charset=utf-8');
  347. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  348. }
  349. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  350. // header('Content-Type:application/json; charset=utf-8');
  351. // exit(json_encode(['code'=>102,'error'=>'无权操作']));
  352. // }
  353. $ret = $workModel->arRecover($param['work_id'],$userInfo['id']);
  354. if ($ret) {
  355. return resultArray(['data'=>'操作成功']);
  356. } else {
  357. return resultArray(['error'=>$workModel->getError()]);
  358. }
  359. }
  360. /**
  361. * 项目任务统计
  362. *
  363. * @return \think\response\Json
  364. * @throws \think\db\exception\DataNotFoundException
  365. * @throws \think\db\exception\ModelNotFoundException
  366. * @throws \think\exception\DbException
  367. */
  368. public function statistic()
  369. {
  370. if (empty($this->param['work_id'])) return resultArray(['error'=>'参数错误']);
  371. $userModel = new \app\admin\model\User();
  372. $workModel = model('work');
  373. $param = $this->param;
  374. $work_id = $param['work_id'];
  375. $userInfo = $this->userInfo;
  376. $dataCount = [];
  377. if ($work_id !== 'all') $workInfo = Db::name('Work')->where(['work_id' => $work_id])->find();
  378. $lableary = []; # 标签
  379. $main_user_arr = []; # 成员
  380. $allNum = 0; # 总任务数
  381. $undoneNum = 0; # 总未完成数
  382. $doneNum = 0; # 总完成数
  383. $overtimeNum = 0; # 总延期数
  384. $archiveNum = 0; # 总归档数
  385. $completionRate = 0; # 总完成率
  386. $delayRate = 0; # 总延期率
  387. $workIds = [];
  388. $groupIds = db('admin_access')->where('user_id', $userInfo['id'])->column('group_id');
  389. $isSuperAdmin = $userInfo['id'] == 1 || in_array(1, (array)$groupIds); # 是否是超管
  390. if (empty($isSuperAdmin)) $workIds = db('work_user')->where('user_id', $userInfo['id'])->column('work_id');
  391. //公开项目
  392. if ($work_id !== 'all') {
  393. $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();
  394. } else {
  395. $where['work_id'] = !empty($isSuperAdmin) ? ['gt', 0] : ['in', $workIds];
  396. $where['ishidden'] = 0;
  397. $where['pid'] = 0;
  398. $taskList = Db::name('Task')->where($where)->field('task_id,main_user_id,lable_id,status,owner_user_id,stop_time,is_archive')->select();
  399. }
  400. foreach ($taskList as $key => $value) {
  401. if (empty($value['is_archive'])) {
  402. $allNum += 1;
  403. if ($value['status'] == 1) {
  404. $undoneNum += 1;
  405. }
  406. if ($value['status'] == 1 && $value['stop_time'] && ($value['stop_time'] < time())) {
  407. $overtimeNum += 1;
  408. }
  409. }
  410. if ($value['is_archive'] == 1) $archiveNum += 1;
  411. if ($value['status'] == 5) $doneNum += 1;
  412. //获取项目下成员ID
  413. // if ($value['owner_user_id'] && $workInfo['is_open'] == 1) $main_user_arr[] = $value['main_user_id']; //负责人
  414. // if ($work_id == 'all') $main_user_arr[] = $value['main_user_id']; //负责人
  415. $main_user_arr[] = $value['main_user_id'];
  416. $lableArray = [];
  417. $lableArray = $value['lable_id'] ? stringToArray($value['lable_id']) : []; //标签
  418. $lableary = $lableArray ? array_merge($lableary,$lableArray) : $lableary;
  419. }
  420. $main_user_arr = $main_user_arr ? array_filter(array_unique($main_user_arr)) : [];
  421. $lableary = array_filter(array_unique($lableary));
  422. $completionRate = $allNum ? round(($doneNum / $allNum) * 100,2) : 0;
  423. $delayRate = $allNum ? round(($overtimeNum / $allNum) * 100,2) : 0;
  424. $dataCount['allNum'] = !empty($allNum) ? $allNum : 0;
  425. $dataCount['undoneNum'] = !empty($undoneNum) ? $undoneNum : 0;
  426. $dataCount['doneNum'] = !empty($doneNum) ? $doneNum : 0;
  427. $dataCount['overtimeNum'] = !empty($overtimeNum) ? $overtimeNum : 0;
  428. $dataCount['archiveNum'] = !empty($archiveNum) ? $archiveNum : 0;
  429. $dataCount['completionRate'] = !empty($completionRate) ? round($completionRate) : 0;
  430. $dataCount['delayRate'] = !empty($delayRate) ? $delayRate : 0;
  431. //项目负责人
  432. $ownerArr = [];
  433. if ($workInfo && $workInfo['is_open'] == 0) {
  434. //私有项目
  435. // $main_user_arr = db('work_user')->where(['work_id' => $work_id])->column('user_id');
  436. $ownerArr = db('work_user')->where(['work_id' => $work_id,'types' => 1])->column('user_id');
  437. } elseif ($work_id !== 'all') {
  438. $ownerArr[] = $workInfo['create_user_id'];
  439. }
  440. $ownerList = [];
  441. foreach ($ownerArr as $k3=>$v3) {
  442. $ownerList[] = $userModel->getUserById($v3);
  443. }
  444. $dataAry['ownerList'] = $ownerList ? : [];
  445. // $dataAry['workInfo'] = $workInfo ? : [];
  446. //成员统计
  447. $list = [];
  448. $i = 0;
  449. $main_user_arr = $main_user_arr ? array_merge($main_user_arr) : [];
  450. foreach ($main_user_arr as $key => $value) {
  451. //参与项目数量
  452. $userInfo = [];
  453. $userInfo = $userModel->getUserById($value);
  454. if (!$userInfo) continue;
  455. $list[$i]['userInfo'] = $userInfo ? : [];
  456. // $workCount = 0; //项目总数
  457. $allCount = 0; //任务总数
  458. $undoneCount = 0; //待完成任务总数
  459. $doneCount = 0; //已完成任务总数
  460. $overtimeCount = 0; //延期任务总数
  461. $archiveCount = 0; //归档任务总数
  462. $completionRate = 0; //完成率
  463. $taskArr = [];
  464. if ($work_id == 'all') {
  465. $taskWhere['work_id'] = !empty($isSuperAdmin) ? ['gt', 0] : ['in', $workIds];
  466. $taskWhere['main_user_id'] = $value;
  467. $taskWhere['ishidden'] = 0;
  468. $taskWhere['pid'] = 0;
  469. $taskArr = db('task')->where($taskWhere)->field('status,stop_time,is_archive,task_id')->select();
  470. } else {
  471. $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();
  472. }
  473. foreach ($taskArr as $v) {
  474. $allCount += 1;
  475. if ($v['status'] == 1 && empty($v['is_archive'])) $undoneCount += 1;
  476. if (($v['status'] == 1 && empty($v['is_archive'])) && $v['stop_time'] && ($v['stop_time'] < time())) $overtimeCount += 1;
  477. if ($v['is_archive'] == 1) $archiveCount += 1;
  478. if ($v['status'] == 5) $doneCount += 1;
  479. }
  480. $completionRate = $allCount ? round(($doneCount/$allCount),2)*100 : 0;
  481. $list[$i]['allCount'] = $allCount ? : 0;
  482. $list[$i]['undoneCount'] = $undoneCount ? : 0;
  483. $list[$i]['doneCount'] = $doneCount ? : 0;
  484. $list[$i]['overtimeCount'] = $overtimeCount ? : 0;
  485. $list[$i]['archiveCount'] = $archiveCount ? : 0;
  486. $list[$i]['completionRate'] = $completionRate ? : 0;
  487. $list[$i]['realname'] = !empty($userInfo) ? $userInfo['realname'] : '';
  488. $i++;
  489. }
  490. $dataAry['dataCount'] = $dataCount;
  491. $dataAry['userList'] = $list;
  492. if ($work_id !== 'all') {
  493. //任务列表统计
  494. $dataAry['classList'] = $workModel->classList($work_id);
  495. //标签统计
  496. $dataAry['labelList'] = $workModel->labelList($work_id,$lableary);
  497. }
  498. return resultArray(['data'=>$dataAry]);
  499. }
  500. /**
  501. * 参与人角色添加
  502. *
  503. * @return \think\response\Json
  504. * @throws \think\Exception
  505. * @throws \think\db\exception\DataNotFoundException
  506. * @throws \think\db\exception\ModelNotFoundException
  507. * @throws \think\exception\DbException
  508. * @throws \think\exception\PDOException
  509. */
  510. public function addUserGroup()
  511. {
  512. $param = $this->param;
  513. $userInfo = $this->userInfo;
  514. $workModel = model('Work');
  515. $list = $param['list'] ? : [];
  516. $work_id = $param['work_id'] ? : [];
  517. if (!is_array($list) || !$work_id) {
  518. return resultArray(['error'=>'参数错误']);
  519. }
  520. # 权限判断
  521. if (!$this->checkWorkOperationAuth('setWork', $work_id, $userInfo['id'])) {
  522. header('Content-Type:application/json; charset=utf-8');
  523. exit(json_encode(['code' => 102, 'error' => '无权操作!']));
  524. }
  525. // if (!$workModel->isCheck('work','work','update',$param['work_id'],$userInfo['id'])) {
  526. // header('Content-Type:application/json; charset=utf-8');
  527. // exit(json_encode(['code'=>102,'error'=>'无权操作1']));
  528. // }
  529. foreach ($list as $value) {
  530. $data = array();
  531. $types = 0;
  532. $data['work_id'] = $work_id;
  533. $data['user_id'] = $value['user_id'];
  534. $flag = db('work_user')->where($data)->find();
  535. $data['group_id'] = $value['group_id'];
  536. if ($value['group_id'] == 1) $types = 1; //项目管理员,不能删除
  537. $data['types'] = $types;
  538. if (!$flag) {
  539. db('work_user')->insert($data);
  540. } else {
  541. db('work_user')->where(['work_id' => $work_id,'user_id' => $value['user_id']])->update($data);
  542. }
  543. }
  544. $dataList = db('work_user')->where(['work_id' => $work_id])->select();
  545. return resultArray(['data'=>$dataList]);
  546. }
  547. /**
  548. * 项目下附件列表
  549. *
  550. * @param
  551. * @return
  552. */
  553. public function fileList()
  554. {
  555. $param = $this->param;
  556. $userInfo = $this->userInfo;
  557. $workModel = model('Work');
  558. $work_id = $param['work_id'];
  559. if (!$work_id) {
  560. return resultArray(['error'=>'参数错误']);
  561. }
  562. //判断权限
  563. $checkRes = $workModel->checkWork($work_id, $userInfo['id']);
  564. if ($checkRes !== true) {
  565. return resultArray(['error' => $workModel->getError()]);
  566. }
  567. $task_ids = db('task')->where(['work_id' => $work_id])->column('task_id');
  568. $request = [];
  569. $request['module'] = 'work_task';
  570. $request['module_id'] = $task_ids;
  571. $fileModel = new \app\admin\model\File();
  572. $data = $fileModel->getDataList($request, $param['by']);
  573. return resultArray(['data' => $data]);
  574. }
  575. /**
  576. * 项目角色列表
  577. *
  578. * @return \think\response\Json
  579. * @throws \think\db\exception\DataNotFoundException
  580. * @throws \think\db\exception\ModelNotFoundException
  581. * @throws \think\exception\DbException
  582. */
  583. public function groupList()
  584. {
  585. $list[] = ['id' => 1,'title' => '管理', 'remark' => '系统默认权限,包含项目所有权限,不可修改/删除'];
  586. $groupList = db('admin_group')->where(['pid' => 5, 'types' => 7, 'type' => 0])->order('system desc')->field('id, title, remark,rules')->select();
  587. $listArr = array_merge($list, $groupList) ? : [];
  588. return resultArray(['data' => $listArr]);
  589. }
  590. /**
  591. * 项目关注
  592. *
  593. * @return \think\response\Json
  594. * @throws \think\Exception
  595. * @throws \think\exception\PDOException
  596. */
  597. public function follow()
  598. {
  599. if (!isset($this->param['follow']) || empty($this->param['work_id'])) return resultArray(['error' => '参数错误!']);
  600. $this->param['follow'] = !empty($this->param['follow']) ? $this->param['follow'] : 0;
  601. if (!Db::name('work')->where('work_id', $this->param['work_id'])->update(['is_follow' => $this->param['follow']])) {
  602. return resultArray(['error' => '操作失败!']);
  603. }
  604. return resultArray(['data' => '操作成功!']);
  605. }
  606. /**
  607. * 项目列表排序
  608. *
  609. * @author fanqi
  610. * @date 2021-03-11
  611. * @param WorkLogic $workLogic
  612. */
  613. public function updateWorkOrder(WorkLogic $workLogic)
  614. {
  615. $workIds = $this->param['workIds'];
  616. $userInfo = $this->userInfo;
  617. $workLogic->setWorkOrder($workIds, $userInfo['id']);
  618. return resultArray(['data' => '操作成功!']);
  619. }
  620. }