Examine.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 审批
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\oa\controller;
  8. use app\admin\controller\ApiCommon;
  9. use app\admin\model\Message;
  10. use app\admin\model\User;
  11. use think\Hook;
  12. use app\oa\logic\ExamineLogic;
  13. use think\Request;
  14. use think\Db;
  15. class Examine extends ApiCommon
  16. {
  17. /**
  18. * 用于判断权限
  19. * @permission 无限制
  20. * @allow 登录用户可访问
  21. * @other 其他根据系统设置
  22. **/
  23. public function _initialize()
  24. {
  25. $action = [
  26. 'permission'=>[''],
  27. 'allow'=>['index','save','read','update','delete','categorylist','check','revokecheck','category','categorysave','categoryupdate','categorydelete','categoryenables','excelexport','myexamine','examinesort']
  28. ];
  29. Hook::listen('check_auth',$action);
  30. $request = Request::instance();
  31. $a = strtolower($request->action());
  32. if (!in_array($a, $action['permission'])) {
  33. parent::_initialize();
  34. }
  35. //权限判断
  36. // $unAction = ['index','save','read','update','delete','categorylist','check','revokecheck','excelexport',];
  37. $unAction = ['index','save','read','update','delete','categorylist','check','revokecheck','category','categorysave','categoryupdate','categorydelete','categoryenables','excelexport','myexamine','examinesort'];
  38. if (!in_array($a, $unAction) && !checkPerByAction('admin', 'oa', 'examine')) {
  39. header('Content-Type:application/json; charset=utf-8');
  40. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  41. }
  42. }
  43. /**
  44. * 审批列表
  45. * @author Michael_xu
  46. * @return
  47. */
  48. public function index()
  49. {
  50. $examineModel = model('Examine');
  51. $param = $this->param;
  52. $userInfo = $this->userInfo;
  53. $param['user_id'] = $userInfo['id'];
  54. $data = $examineModel->getDataList($param);
  55. return resultArray(['data' => $data]);
  56. }
  57. /**
  58. * 审核列表导出
  59. * @return \think\response\Json|void
  60. */
  61. public function excelExport(){
  62. $param = $this->param;
  63. $userInfo = $this->userInfo;
  64. $param['user_id'] = $userInfo['id'];
  65. $ExamineLogic = new ExamineLogic();
  66. $data = $ExamineLogic->excelExport($param);
  67. return $data;
  68. }
  69. /**
  70. * 添加审批
  71. * @author Michael_xu
  72. * @param
  73. * @return
  74. */
  75. public function save()
  76. {
  77. $examineModel = model('Examine');
  78. $param = $this->param;
  79. $userInfo = $this->userInfo;
  80. $param['create_user_id'] = $userInfo['id'];
  81. $category_id = $param['category_id'];
  82. //审核判断(是否有符合条件的审批流)
  83. $examineFlowModel = new \app\admin\model\ExamineFlow();
  84. $examineStepModel = new \app\admin\model\ExamineStep();
  85. if (!$examineFlowModel->checkExamine($param['create_user_id'], 'oa_examine', $category_id)) {
  86. return resultArray(['error' => '暂无审批人,无法创建']);
  87. }
  88. //获取审批相关信息
  89. $examineFlowData = $examineFlowModel->getFlowByTypes($param['create_user_id'], 'oa_examine', $category_id);
  90. if (!$examineFlowData) {
  91. return resultArray(['error' => '无可用审批流,请联系管理员']);
  92. }
  93. $param['flow_id'] = $examineFlowData['flow_id'];
  94. //获取审批人信息
  95. if ($examineFlowData['config'] == 1) {
  96. //固定审批流
  97. $nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
  98. $check_user_id = $nextStepData['next_user_ids'] ? : '';
  99. $param['order_id'] = 1;
  100. } else {
  101. $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
  102. }
  103. if (!$check_user_id) {
  104. return resultArray(['error' => '无可用审批人,请联系管理员']);
  105. }
  106. $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
  107. //流程审批人
  108. // $flow_user_id = $examineFlowModel->getUserByFlow($examineFlowData['flow_id'], $userInfo['id']);
  109. // $param['flow_user_id'] = $flow_user_id ? arrayToString($flow_user_id) : '';
  110. $res = $examineModel->createData($param);
  111. if ($res) {
  112. $categoryModel = new \app\oa\model\ExamineCategory();
  113. $categoryInfo = $categoryModel->getDataById($category_id);
  114. actionLog($res['examine_id'], '', '', '创建了审批');
  115. return resultArray(['data' => '添加成功']);
  116. } else {
  117. return resultArray(['error' => $examineModel->getError()]);
  118. }
  119. }
  120. /**
  121. * 审批详情
  122. * @author Michael_xu
  123. * @param
  124. * @return
  125. */
  126. public function read()
  127. {
  128. $examineModel = model('Examine');
  129. $userModel = new \app\admin\model\User();
  130. $examineFlowModel = new \app\admin\model\ExamineFlow();
  131. $param = $this->param;
  132. $userInfo = $this->userInfo;
  133. $data = $examineModel->getDataById($param['id']);
  134. //权限判断(创建人、审批人、管理员)
  135. $adminIds = $userModel->getAdminId(); //管理员
  136. $checkUserIds = $examineFlowModel->getUserByFlow($data['flow_id'], $data['create_user_id'], $data['check_user_id']);
  137. if (($userInfo['id'] != $data['create_user_id']) && !in_array($userInfo['id'],$adminIds) && !in_array($userInfo['id'],$checkUserIds)) {
  138. return resultArray(['error' => '没有权限']);
  139. }
  140. if (!$data) {
  141. return resultArray(['error' => $examineModel->getError()]);
  142. }
  143. return resultArray(['data' => $data]);
  144. }
  145. /**
  146. * 编辑审批
  147. * @author Michael_xu
  148. * @param
  149. * @return
  150. */
  151. public function update()
  152. {
  153. $examineModel = model('Examine');
  154. $param = $this->param;
  155. $userInfo = $this->userInfo;
  156. $param['create_user_id'] = $userInfo['id'];
  157. $param['user_id'] = $userInfo['id'];
  158. $dataInfo = db('oa_examine')->where(['examine_id' => $param['id']])->find();
  159. if (!$dataInfo) {
  160. return resultArray(['error' => '数据不存在或已删除']);
  161. }
  162. //权限判断
  163. if ($userInfo['id'] != $dataInfo['create_user_id']) {
  164. return resultArray(['error' => '没有权限']);
  165. }
  166. if (!in_array($dataInfo['check_status'],['3','4'])) {
  167. return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
  168. }
  169. //审核判断(是否有符合条件的审批流)
  170. $examineFlowModel = new \app\admin\model\ExamineFlow();
  171. $examineStepModel = new \app\admin\model\ExamineStep();
  172. if (!$examineFlowModel->checkExamine($dataInfo['create_user_id'], 'oa_examine', $dataInfo['category_id'])) {
  173. return resultArray(['error' => '暂无审批人,无法创建']);
  174. }
  175. //获取审批相关信息
  176. $examineFlowData = $examineFlowModel->getFlowByTypes($dataInfo['create_user_id'], 'oa_examine', $dataInfo['category_id']);
  177. if (!$examineFlowData) {
  178. return resultArray(['error' => '无可用审批流,请联系管理员']);
  179. }
  180. $param['flow_id'] = $examineFlowData['flow_id'];
  181. //获取审批人信息
  182. if ($examineFlowData['config'] == 1) {
  183. //固定审批流
  184. $nextStepData = $examineStepModel->nextStepUser($dataInfo['create_user_id'], $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
  185. $next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
  186. $check_user_id = $next_user_ids ? : '';
  187. $param['order_id'] = 1;
  188. } else {
  189. $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
  190. }
  191. if (!$check_user_id) {
  192. return resultArray(['error' => '无可用审批人,请联系管理员']);
  193. }
  194. $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
  195. $param['check_status'] = 0;
  196. //流程审批人
  197. // $flow_user_id = $examineFlowModel->getUserByFlow($examineFlowData['flow_id'], $dataInfo['create_user_id']);
  198. // $param['flow_user_id'] = $flow_user_id ? arrayToString($flow_user_id) : '';
  199. $param['flow_user_id'] = '';
  200. $res = $examineModel->updateDataById($param, $param['id']);
  201. if ($res) {
  202. //将审批记录至为无效
  203. $examineRecordModel = new \app\admin\model\ExamineRecord();
  204. $examineRecordModel->setEnd(['types' => 'oa_examine','types_id' => $param['id']]);
  205. $categoryModel = new \app\oa\model\ExamineCategory();
  206. $categoryInfo = $categoryModel->getDataById($dataInfo['category_id']);
  207. actionLog($param['id'], '', '', '新建了审批');
  208. return resultArray(['data' => '编辑成功']);
  209. } else {
  210. return resultArray(['error' => $examineModel->getError()]);
  211. }
  212. }
  213. /**
  214. * 删除审批(逻辑删)
  215. * @author Michael_xu
  216. * @param
  217. * @return
  218. */
  219. public function delete()
  220. {
  221. $examineModel = model('Examine');
  222. $param = $this->param;
  223. $userInfo = $this->userInfo;
  224. $dataInfo = db('oa_examine')->where(['examine_id' => $param['id']])->find();
  225. if (!$dataInfo) {
  226. return resultArray(['error' => '数据不存在或已删除']);
  227. }
  228. $adminTypes = adminGroupTypes($userInfo['id']);
  229. if (in_array($dataInfo['check_status'], [2,3])) {
  230. return resultArray(['error' => '已审批,不可删除']);
  231. }
  232. if (!in_array($dataInfo['check_status'],['4']) && !in_array(1,$adminTypes)) {
  233. return resultArray(['error' => '不可删除,请先撤销审核']);
  234. }
  235. //权限判断
  236. if ($userInfo['id'] != $dataInfo['create_user_id']) {
  237. return resultArray(['error' => '无权操作']);
  238. }
  239. $data = $examineModel->delDataById($param['id']);
  240. if (!$data) {
  241. return resultArray(['error' => $examineModel->getError()]);
  242. }
  243. $fileModel = new \app\admin\model\File();
  244. // 删除自定义字段数据
  245. db('oa_examine_data')->where('examine_id', $param['id'])->delete();
  246. //删除关联附件
  247. $fileModel->delRFileByModule('oa_examine',$param['id']);
  248. # 删除记录
  249. actionLog($param['id'], '', '', '删除了审批');
  250. # 删除活动记录
  251. Db::name('crm_activity')->where(['activity_type' => 9, 'activity_type_id' => $param['id']])->delete();
  252. return resultArray(['data' => '删除成功']);
  253. }
  254. /**
  255. * 审批类型(列表)
  256. * @author Michael_xu
  257. * @param
  258. * @return
  259. */
  260. public function category()
  261. {
  262. $categoryModel = model('ExamineCategory');
  263. $param = $this->param;
  264. $data = $categoryModel->getDataList($param);
  265. return resultArray(['data' => $data]);
  266. }
  267. /**
  268. * 审批类型(创建)
  269. * @author Michael_xu
  270. * @param
  271. * @return
  272. */
  273. public function categorySave()
  274. {
  275. $categoryModel = model('ExamineCategory');
  276. $param = $this->param;
  277. $userInfo = $this->userInfo;
  278. $param['create_user_id'] = $userInfo['id'];
  279. $res = $categoryModel->createData($param);
  280. if ($res) {
  281. #添加系统操作日志
  282. $userInfo=$this->userInfo;
  283. SystemActionLog($userInfo['id'], 'admin_examine','approval', $res['category_id'], 'save', $param['title'], '', '','添加了办公审批流:'.$param['title']);
  284. return resultArray(['data' => $res]);
  285. } else {
  286. return resultArray(['error' => $categoryModel->getError()]);
  287. }
  288. }
  289. /**
  290. * 审批类型(编辑)
  291. * @author Michael_xu
  292. * @param
  293. * @return
  294. */
  295. public function categoryUpdate()
  296. {
  297. $categoryModel = model('ExamineCategory');
  298. $examineFlowModel = new \app\admin\model\ExamineFlow();
  299. $examineStepModel = new \app\admin\model\ExamineStep();
  300. $param = $this->param;
  301. $userInfo = $this->userInfo;
  302. $category_id = $param['id'];
  303. $dataInfo = $categoryModel->getDataById($category_id);
  304. if (!$dataInfo) {
  305. return resultArray(['error' => '数据不存在或已删除']);
  306. }
  307. //将当前审批流标记为已删除,重新创建审批流(目的:保留审批流程记录)
  308. // $newData = db('admin_examine_flow')->where(['flow_id' => $dataInfo['flow_id']])->find();
  309. $param['name'] = $param['title'].'流程';
  310. $param['types'] = 'oa_examine';
  311. $param['types_id'] = $category_id;
  312. $param['user_ids'] = arrayToString($param['user_ids']);
  313. $param['structure_ids'] = arrayToString($param['structure_ids']);
  314. $param['update_user_id'] = $userInfo['id'];
  315. $param['create_time'] = time();
  316. // $param['update_time'] = time();
  317. $param['status'] = 1;
  318. $resUpdate = $examineFlowModel->createData($param);
  319. if ($resUpdate) {
  320. if ($param['config'] == 1) {
  321. $resStep = $examineStepModel->createStepData($param['step'], $resUpdate['flow_id']);
  322. if (!$resStep) {
  323. return resultArray(['error' => $examineStepModel->getError()]);
  324. }
  325. }
  326. if ($dataInfo['flow_id']) {
  327. $upData = [];
  328. $upData['is_deleted'] = 1;
  329. $upData['delete_time'] = time();
  330. $upData['delete_user_id'] = $userInfo['id'];
  331. $upData['status'] = 0;
  332. $resFlow = db('admin_examine_flow')->where(['flow_id' => $dataInfo['flow_id']])->update($upData);
  333. if (!$resFlow) {
  334. return resultArray(['error' => '编辑失败']);
  335. }
  336. }
  337. $param['flow_id'] = $resUpdate['flow_id'];
  338. $res = $categoryModel->updateDataById($param, $param['id']);
  339. if (!$res) {
  340. return resultArray(['error' => $categoryModel->getError()]);
  341. }
  342. # 系统操作记录
  343. $userInfo=$this->userInfo;
  344. SystemActionLog($userInfo['id'], 'oa_examine','approval', $category_id, 'save', '办公审批' , '', '编辑了办公审批流:办公审批');
  345. return resultArray(['data' => '编辑成功']);
  346. } else {
  347. return resultArray(['error' => $examineFlowModel->getError()]);
  348. }
  349. }
  350. /**
  351. * 审批类型(逻辑删)
  352. * @author Michael_xu
  353. * @param
  354. * @return
  355. */
  356. public function categoryDelete()
  357. {
  358. $categoryModel = model('ExamineCategory');
  359. $param = $this->param;
  360. $userInfo = $this->userInfo;
  361. $data = $categoryModel->signDelById($param['id'], $userInfo['id']);
  362. if (!$data) {
  363. return resultArray(['error' => $categoryModel->getError()]);
  364. }
  365. return resultArray(['data' => '删除成功']);
  366. }
  367. /**
  368. * 审批类型状态(启用、停用)
  369. * @author Michael_xu
  370. * @param ids array
  371. * @param status 1启用,0禁用
  372. * @return
  373. */
  374. public function categoryEnables()
  375. {
  376. $categoryModel = model('ExamineCategory');
  377. $param = $this->param;
  378. $userInfo = $this->userInfo;
  379. $id = [$param['id']];
  380. $data = $categoryModel->enableDatas($id, $param['status']);
  381. if (!$data) {
  382. return resultArray(['error' => $categoryModel->getError()]);
  383. }
  384. $info=db('oa_examine_category')->where('category_id',$param['id'])->find();
  385. # 系统操作记录
  386. if($param['status']==0){
  387. $content='停用了:'.$info['title'];
  388. }else{
  389. $content='启用了:'.$info['title'];
  390. }
  391. SystemActionLog($userInfo['id'], 'oa_examine','approval', $param['id'], 'delete',$info['title'] , '', '',$content);
  392. return resultArray(['data' => '操作成功']);
  393. }
  394. /**
  395. * 审批类型列表(创建时)
  396. * @author Michael_xu
  397. * @return
  398. */
  399. public function categoryList()
  400. {
  401. $param = $this->param;
  402. $userInfo = $this->userInfo;
  403. $where = [];
  404. $where['c.is_deleted'] = ['neq',1];
  405. $where['c.status'] = ['eq',1];
  406. $examineCategory=db('oa_examine_order')->where('user_id',$userInfo['id'])->column('work_id');
  407. $category_id=db('oa_examine_category')->where(['create_user_id'=>$userInfo['id'],'is_deleted'=>['neq',1],'status'=>1])->column('category_id');
  408. if($examineCategory && count($examineCategory)==count($category_id)){
  409. $orderField = 'o.order';
  410. $orderSort = 'asc';
  411. $join=[['__OA_EXAMINE_ORDER__ o','o.work_id=c.category_id','LEFT']];
  412. $where['o.user_id'] = ['eq',$userInfo['id']];
  413. }else{
  414. $orderField = 'c.category_id';
  415. $orderSort = 'asc';
  416. $join='';
  417. }
  418. $list = db('oa_examine_category')
  419. ->alias('c')
  420. ->join($join)
  421. ->where($where)
  422. ->where(function ($query) use ($userInfo){
  423. $query->where('c.`user_ids` = "" AND c.`structure_ids` = ""')
  424. ->whereOr(function($query) use ($userInfo){
  425. $query->where('c.structure_ids','like','%,'.$userInfo['structure_id'].',%')
  426. ->whereOr('c.user_ids','like','%,'.$userInfo['id'].',%');
  427. });
  428. })->order($orderField,$orderSort)->select();
  429. foreach ($list AS $key => $value) {
  430. $list[$key]['category_name'] = $value['title'];
  431. }
  432. return resultArray(['data' => $list]);
  433. }
  434. /**
  435. * 审批审核
  436. * @author Michael_xu
  437. * @param
  438. * @return
  439. */
  440. public function check()
  441. {
  442. $param = $this->param;
  443. $userInfo = $this->userInfo;
  444. $user_id = $userInfo['id'];
  445. $examineModel = model('Examine');
  446. $examineStepModel = new \app\admin\model\ExamineStep();
  447. $examineRecordModel = new \app\admin\model\ExamineRecord();
  448. $examineFlowModel = new \app\admin\model\ExamineFlow();
  449. $examineData = [];
  450. $examineData['update_time'] = time();
  451. $examineData['check_status'] = 1; //0待审核,1审核通中,2审核通过,3审核未通过
  452. //权限判断
  453. if (!$examineStepModel->checkExamine($user_id, 'oa_examine', $param['id'])) {
  454. return resultArray(['error' => $examineStepModel->getError()]);
  455. };
  456. //审批主体详情
  457. $dataInfo = $examineModel->getDataById($param['id']);
  458. $flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
  459. $is_end = 0; // 1审批结束
  460. $status = $param['status'] ? 1 : 0; //1通过,0驳回
  461. $checkData = [];
  462. $checkData['check_user_id'] = $user_id;
  463. $checkData['types'] = 'oa_examine';
  464. $checkData['types_id'] = $param['id'];
  465. $checkData['check_time'] = time();
  466. $checkData['content'] = $param['content'];
  467. $checkData['flow_id'] = $dataInfo['flow_id'];
  468. $checkData['order_id'] = $dataInfo['order_id'] ? : 1;
  469. $checkData['status'] = $status;
  470. if ($status == 1) {
  471. if ($flowInfo['config'] == 1) {
  472. //固定流程
  473. //获取下一审批信息
  474. $nextStepData = $examineStepModel->nextStepUser($dataInfo['create_user_id'], $dataInfo['flow_id'], 'oa_examine', $param['id'], $dataInfo['order_id'], $user_id);
  475. $next_user_ids = $nextStepData['next_user_ids'] ? : [];
  476. $examineData['order_id'] = $nextStepData['order_id'] ? : '';
  477. if (!$next_user_ids) {
  478. $is_end = 1;
  479. //审批结束
  480. $checkData['check_status'] = !empty($status) ? 2 : 3;
  481. // $examineData['check_user_id'] = '';
  482. } else {
  483. //修改主体相关审批信息
  484. $examineData['check_user_id'] = arrayToString($next_user_ids);
  485. }
  486. } else {
  487. //自选流程
  488. $is_end = $param['is_end'] ? 1 : '';
  489. $check_user_id = $param['check_user_id'] ? : '';
  490. if ($is_end !== 1 && empty($check_user_id)) {
  491. return resultArray(['error' => '请选择下一审批人']);
  492. }
  493. $examineData['check_user_id'] = arrayToString($param['check_user_id']);
  494. }
  495. if ($is_end == 1) {
  496. $checkData['check_status'] = !empty($status) ? 2 : 3;
  497. // $examineData['check_user_id'] = '';
  498. $examineData['check_status'] = 2;
  499. }
  500. } else {
  501. //审批驳回
  502. $is_end = 1;
  503. $examineData['check_status'] = 3;
  504. //将审批记录至为无效
  505. // $examineRecordModel->setEnd(['types' => 'oa_examine','types_id' => $param['id']]);
  506. }
  507. //已审批人ID
  508. $examineData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]);
  509. $resExamine = db('oa_examine')->where(['examine_id' => $param['id']])->update($examineData);
  510. if ($resExamine) {
  511. $lastExamine = db('oa_examine')->where(['examine_id' => $param['id']])->update(['last_user_id'=> $examineData['flow_user_id']]);
  512. //审批记录
  513. $resRecord = $examineRecordModel->createData($checkData);
  514. //审核通过
  515. if ($is_end == 1 && !empty($status)) {
  516. // 审批通过消息告知审批提交人
  517. (new Message())->send(
  518. Message::EXAMINE_PASS,
  519. [
  520. 'title' => $dataInfo['category_name'],
  521. 'action_id' => $param['id']
  522. ],
  523. $dataInfo['create_user_id']
  524. );
  525. } else {
  526. if ($status) {
  527. // 通过后发送消息给下一审批人
  528. (new Message())->send(
  529. Message::EXAMINE_TO_DO,
  530. [
  531. 'from_user' => User::where(['id' => $dataInfo['create_user_id']])->value('realname'),
  532. 'title' => $dataInfo['category_name'],
  533. 'action_id' => $param['id']
  534. ],
  535. stringToArray($examineData['check_user_id'])
  536. );
  537. } else {
  538. // 审批驳回消息告知审批提交人
  539. (new Message())->send(
  540. Message::EXAMINE_REJECT,
  541. [
  542. 'title' => $dataInfo['category_name'],
  543. 'action_id' => $param['id']
  544. ],
  545. $dataInfo['create_user_id']
  546. );
  547. }
  548. }
  549. return resultArray(['data' => '审批成功']);
  550. } else {
  551. return resultArray(['error' => '审批失败,请重试!']);
  552. }
  553. }
  554. /**
  555. * 审批撤销审核
  556. * @author Michael_xu
  557. * @param
  558. * @return
  559. */
  560. public function revokeCheck()
  561. {
  562. $param = $this->param;
  563. $userInfo = $this->userInfo;
  564. $user_id = $userInfo['id'];
  565. $examine_id = $param['id'];
  566. $examineModel = model('Examine');
  567. $examineRecordModel = new \app\admin\model\ExamineRecord();
  568. $userModel = new \app\admin\model\User();
  569. $examineData = [];
  570. $examineData['update_time'] = time();
  571. $examineData['check_status'] = 0; //0待审核,1审核通中,2审核通过,3审核未通过
  572. //审批主体详情
  573. $dataInfo = db('oa_examine')->where(['examine_id' => $examine_id])->find();
  574. //权限判断(创建人或管理员)
  575. if ($dataInfo['check_status'] == 2) {
  576. return resultArray(['error' => '已审批结束,不能撤销']);
  577. }
  578. if ($dataInfo['check_status'] == 4) {
  579. return resultArray(['error' => '无需撤销']);
  580. }
  581. $admin_user_ids = $userModel->getAdminId();
  582. if ($dataInfo['create_user_id'] !== $user_id && !in_array($user_id, $admin_user_ids)) {
  583. return resultArray(['error' => '没有权限']);
  584. }
  585. $is_end = 0; // 1审批结束
  586. $status = 2; //1通过,0驳回, 2撤销
  587. $checkData = [];
  588. $checkData['check_user_id'] = $user_id;
  589. $checkData['types'] = 'oa_examine';
  590. $checkData['types_id'] = $param['id'];
  591. $checkData['check_time'] = time();
  592. $checkData['content'] = $param['content'];
  593. $checkData['flow_id'] = $dataInfo['flow_id'];
  594. $checkData['order_id'] = $dataInfo['order_id'];
  595. $checkData['status'] = $status;
  596. $examineData['check_status'] = 4;
  597. # 如果将审批人置空,会导致普通员工在右上角消息中无法查看审批
  598. $examineData['check_user_id'] = $dataInfo['check_user_id'];
  599. $examineData['flow_user_id'] = '';
  600. $resExamine = db('oa_examine')->where(['examine_id' => $examine_id])->update($examineData);
  601. if ($resExamine) {
  602. //将审批记录至为无效
  603. $examineRecordModel->setEnd(['types' => 'oa_examine','types_id' => $examine_id]);
  604. //审批记录
  605. $resRecord = $examineRecordModel->createData($checkData);
  606. return resultArray(['data' => '撤销成功']);
  607. } else {
  608. return resultArray(['error' => '撤销失败,请重试!']);
  609. }
  610. }
  611. /**
  612. * 我的审批
  613. * @return mixed
  614. */
  615. public function myExamine(){
  616. $param = $this->param;
  617. $userInfo = $this->userInfo;
  618. $param['user_id'] = $userInfo['id'];
  619. $ExamineLogic = new ExamineLogic();
  620. $data = $ExamineLogic->myExamine($param);
  621. return resultArray(['data' => $data]);
  622. }
  623. /**
  624. * 办公审批类型排序
  625. *
  626. * @author alvin guogaobo
  627. * @version 1.0 版本号
  628. * @since 2021/4/16 0016 14:02
  629. */
  630. public function examineSort(){
  631. $examineIds = $this->param['examineIds'];
  632. $userInfo = $this->userInfo;
  633. $examineCategory=new ExamineLogic();
  634. $examineCategory->setWorkOrder($examineIds, $userInfo['id']);
  635. return resultArray(['data' => '操作成功!']);
  636. }
  637. }