123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. $dataInfo = db('oa_examine')->where(['examine_id' => $param['id']])->find();
  158. if (!$dataInfo) {
  159. return resultArray(['error' => '数据不存在或已删除']);
  160. }
  161. //权限判断
  162. if ($userInfo['id'] != $dataInfo['create_user_id']) {
  163. return resultArray(['error' => '没有权限']);
  164. }
  165. if (!in_array($dataInfo['check_status'],['3','4'])) {
  166. return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
  167. }
  168. //审核判断(是否有符合条件的审批流)
  169. $examineFlowModel = new \app\admin\model\ExamineFlow();
  170. $examineStepModel = new \app\admin\model\ExamineStep();
  171. if (!$examineFlowModel->checkExamine($dataInfo['create_user_id'], 'oa_examine', $dataInfo['category_id'])) {
  172. return resultArray(['error' => '暂无审批人,无法创建']);
  173. }
  174. //获取审批相关信息
  175. $examineFlowData = $examineFlowModel->getFlowByTypes($dataInfo['create_user_id'], 'oa_examine', $dataInfo['category_id']);
  176. if (!$examineFlowData) {
  177. return resultArray(['error' => '无可用审批流,请联系管理员']);
  178. }
  179. $param['flow_id'] = $examineFlowData['flow_id'];
  180. //获取审批人信息
  181. if ($examineFlowData['config'] == 1) {
  182. //固定审批流
  183. $nextStepData = $examineStepModel->nextStepUser($dataInfo['create_user_id'], $examineFlowData['flow_id'], 'oa_examine', 0, 0, 0);
  184. $next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
  185. $check_user_id = $next_user_ids ? : '';
  186. $param['order_id'] = 1;
  187. } else {
  188. $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
  189. }
  190. if (!$check_user_id) {
  191. return resultArray(['error' => '无可用审批人,请联系管理员']);
  192. }
  193. $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
  194. $param['check_status'] = 0;
  195. //流程审批人
  196. // $flow_user_id = $examineFlowModel->getUserByFlow($examineFlowData['flow_id'], $dataInfo['create_user_id']);
  197. // $param['flow_user_id'] = $flow_user_id ? arrayToString($flow_user_id) : '';
  198. $param['flow_user_id'] = '';
  199. $res = $examineModel->updateDataById($param, $param['id']);
  200. if ($res) {
  201. //将审批记录至为无效
  202. $examineRecordModel = new \app\admin\model\ExamineRecord();
  203. $examineRecordModel->setEnd(['types' => 'oa_examine','types_id' => $param['id']]);
  204. $categoryModel = new \app\oa\model\ExamineCategory();
  205. $categoryInfo = $categoryModel->getDataById($dataInfo['category_id']);
  206. actionLog($param['id'], '', '', '新建了审批');
  207. return resultArray(['data' => '编辑成功']);
  208. } else {
  209. return resultArray(['error' => $examineModel->getError()]);
  210. }
  211. }
  212. /**
  213. * 删除审批(逻辑删)
  214. * @author Michael_xu
  215. * @param
  216. * @return
  217. */
  218. public function delete()
  219. {
  220. $examineModel = model('Examine');
  221. $param = $this->param;
  222. $userInfo = $this->userInfo;
  223. $dataInfo = db('oa_examine')->where(['examine_id' => $param['id']])->find();
  224. if (!$dataInfo) {
  225. return resultArray(['error' => '数据不存在或已删除']);
  226. }
  227. $adminTypes = adminGroupTypes($userInfo['id']);
  228. if (in_array($dataInfo['check_status'], [2,3])) {
  229. return resultArray(['error' => '已审批,不可删除']);
  230. }
  231. if (!in_array($dataInfo['check_status'],['4']) && !in_array(1,$adminTypes)) {
  232. return resultArray(['error' => '不可删除,请先撤销审核']);
  233. }
  234. //权限判断
  235. if ($userInfo['id'] != $dataInfo['create_user_id']) {
  236. return resultArray(['error' => '无权操作']);
  237. }
  238. $data = $examineModel->delDataById($param['id']);
  239. if (!$data) {
  240. return resultArray(['error' => $examineModel->getError()]);
  241. }
  242. $fileModel = new \app\admin\model\File();
  243. //删除关联附件
  244. $fileModel->delRFileByModule('oa_examine',$param['id']);
  245. # 删除记录
  246. actionLog($param['id'], '', '', '删除了审批');
  247. # 删除活动记录
  248. Db::name('crm_activity')->where(['activity_type' => 9, 'activity_type_id' => $param['id']])->delete();
  249. return resultArray(['data' => '删除成功']);
  250. }
  251. /**
  252. * 审批类型(列表)
  253. * @author Michael_xu
  254. * @param
  255. * @return
  256. */
  257. public function category()
  258. {
  259. $categoryModel = model('ExamineCategory');
  260. $param = $this->param;
  261. $data = $categoryModel->getDataList($param);
  262. return resultArray(['data' => $data]);
  263. }
  264. /**
  265. * 审批类型(创建)
  266. * @author Michael_xu
  267. * @param
  268. * @return
  269. */
  270. public function categorySave()
  271. {
  272. $categoryModel = model('ExamineCategory');
  273. $param = $this->param;
  274. $userInfo = $this->userInfo;
  275. $param['create_user_id'] = $userInfo['id'];
  276. $res = $categoryModel->createData($param);
  277. if ($res) {
  278. #添加系统操作日志
  279. $userInfo=$this->userInfo;
  280. SystemActionLog($userInfo['id'], 'admin_examine','approval', $res['category_id'], 'save', $param['title'], '', '','添加了办公审批流:'.$param['title']);
  281. return resultArray(['data' => $res]);
  282. } else {
  283. return resultArray(['error' => $categoryModel->getError()]);
  284. }
  285. }
  286. /**
  287. * 审批类型(编辑)
  288. * @author Michael_xu
  289. * @param
  290. * @return
  291. */
  292. public function categoryUpdate()
  293. {
  294. $categoryModel = model('ExamineCategory');
  295. $examineFlowModel = new \app\admin\model\ExamineFlow();
  296. $examineStepModel = new \app\admin\model\ExamineStep();
  297. $param = $this->param;
  298. $userInfo = $this->userInfo;
  299. $category_id = $param['id'];
  300. $dataInfo = $categoryModel->getDataById($category_id);
  301. if (!$dataInfo) {
  302. return resultArray(['error' => '数据不存在或已删除']);
  303. }
  304. //将当前审批流标记为已删除,重新创建审批流(目的:保留审批流程记录)
  305. // $newData = db('admin_examine_flow')->where(['flow_id' => $dataInfo['flow_id']])->find();
  306. $param['name'] = $param['title'].'流程';
  307. $param['types'] = 'oa_examine';
  308. $param['types_id'] = $category_id;
  309. $param['user_ids'] = arrayToString($param['user_ids']);
  310. $param['structure_ids'] = arrayToString($param['structure_ids']);
  311. $param['update_user_id'] = $userInfo['id'];
  312. $param['create_time'] = time();
  313. // $param['update_time'] = time();
  314. $param['status'] = 1;
  315. $resUpdate = $examineFlowModel->createData($param);
  316. if ($resUpdate) {
  317. if ($param['config'] == 1) {
  318. $resStep = $examineStepModel->createStepData($param['step'], $resUpdate['flow_id']);
  319. if (!$resStep) {
  320. return resultArray(['error' => $examineStepModel->getError()]);
  321. }
  322. }
  323. if ($dataInfo['flow_id']) {
  324. $upData = [];
  325. $upData['is_deleted'] = 1;
  326. $upData['delete_time'] = time();
  327. $upData['delete_user_id'] = $userInfo['id'];
  328. $upData['status'] = 0;
  329. $resFlow = db('admin_examine_flow')->where(['flow_id' => $dataInfo['flow_id']])->update($upData);
  330. if (!$resFlow) {
  331. return resultArray(['error' => '编辑失败']);
  332. }
  333. }
  334. $param['flow_id'] = $resUpdate['flow_id'];
  335. $res = $categoryModel->updateDataById($param, $param['id']);
  336. if (!$res) {
  337. return resultArray(['error' => $categoryModel->getError()]);
  338. }
  339. # 系统操作记录
  340. $userInfo=$this->userInfo;
  341. SystemActionLog($userInfo['id'], 'oa_examine','approval', $category_id, 'save', '办公审批' , '', '编辑了办公审批流:办公审批');
  342. return resultArray(['data' => '编辑成功']);
  343. } else {
  344. return resultArray(['error' => $examineFlowModel->getError()]);
  345. }
  346. }
  347. /**
  348. * 审批类型(逻辑删)
  349. * @author Michael_xu
  350. * @param
  351. * @return
  352. */
  353. public function categoryDelete()
  354. {
  355. $categoryModel = model('ExamineCategory');
  356. $param = $this->param;
  357. $userInfo = $this->userInfo;
  358. $data = $categoryModel->signDelById($param['id'], $userInfo['id']);
  359. if (!$data) {
  360. return resultArray(['error' => $categoryModel->getError()]);
  361. }
  362. return resultArray(['data' => '删除成功']);
  363. }
  364. /**
  365. * 审批类型状态(启用、停用)
  366. * @author Michael_xu
  367. * @param ids array
  368. * @param status 1启用,0禁用
  369. * @return
  370. */
  371. public function categoryEnables()
  372. {
  373. $categoryModel = model('ExamineCategory');
  374. $param = $this->param;
  375. $userInfo = $this->userInfo;
  376. $id = [$param['id']];
  377. $data = $categoryModel->enableDatas($id, $param['status']);
  378. if (!$data) {
  379. return resultArray(['error' => $categoryModel->getError()]);
  380. }
  381. $info=db('oa_examine_category')->where('category_id',$param['id'])->find();
  382. # 系统操作记录
  383. if($param['status']==0){
  384. $content='停用了:'.$info['title'];
  385. }else{
  386. $content='启用了:'.$info['title'];
  387. }
  388. SystemActionLog($userInfo['id'], 'oa_examine','approval', $param['id'], 'delete',$info['title'] , '', '',$content);
  389. return resultArray(['data' => '操作成功']);
  390. }
  391. /**
  392. * 审批类型列表(创建时)
  393. * @author Michael_xu
  394. * @return
  395. */
  396. public function categoryList()
  397. {
  398. $param = $this->param;
  399. $userInfo = $this->userInfo;
  400. $where = [];
  401. $where['c.is_deleted'] = ['neq',1];
  402. $where['c.status'] = ['eq',1];
  403. $examineCategory=db('oa_examine_order')->where('user_id',$userInfo['id'])->column('work_id');
  404. $category_id=db('oa_examine_category')->where(['create_user_id'=>$userInfo['id'],'is_deleted'=>['neq',1],'status'=>1])->column('category_id');
  405. if($examineCategory && count($examineCategory)==count($category_id)){
  406. $orderField = 'o.order';
  407. $orderSort = 'asc';
  408. $join=[['__OA_EXAMINE_ORDER__ o','o.work_id=c.category_id','LEFT']];
  409. $where['o.user_id'] = ['eq',$userInfo['id']];
  410. }else{
  411. $orderField = 'c.category_id';
  412. $orderSort = 'asc';
  413. $join='';
  414. }
  415. $list = db('oa_examine_category')
  416. ->alias('c')
  417. ->join($join)
  418. ->where($where)
  419. ->where(function ($query) use ($userInfo){
  420. $query->where('c.`user_ids` = "" AND c.`structure_ids` = ""')
  421. ->whereOr(function($query) use ($userInfo){
  422. $query->where('c.structure_ids','like','%,'.$userInfo['structure_id'].',%')
  423. ->whereOr('c.user_ids','like','%,'.$userInfo['id'].',%');
  424. });
  425. })->order($orderField,$orderSort)->select();
  426. return resultArray(['data' => $list]);
  427. }
  428. /**
  429. * 审批审核
  430. * @author Michael_xu
  431. * @param
  432. * @return
  433. */
  434. public function check()
  435. {
  436. $param = $this->param;
  437. $userInfo = $this->userInfo;
  438. $user_id = $userInfo['id'];
  439. $examineModel = model('Examine');
  440. $examineStepModel = new \app\admin\model\ExamineStep();
  441. $examineRecordModel = new \app\admin\model\ExamineRecord();
  442. $examineFlowModel = new \app\admin\model\ExamineFlow();
  443. $examineData = [];
  444. $examineData['update_time'] = time();
  445. $examineData['check_status'] = 1; //0待审核,1审核通中,2审核通过,3审核未通过
  446. //权限判断
  447. if (!$examineStepModel->checkExamine($user_id, 'oa_examine', $param['id'])) {
  448. return resultArray(['error' => $examineStepModel->getError()]);
  449. };
  450. //审批主体详情
  451. $dataInfo = $examineModel->getDataById($param['id']);
  452. $flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
  453. $is_end = 0; // 1审批结束
  454. $status = $param['status'] ? 1 : 0; //1通过,0驳回
  455. $checkData = [];
  456. $checkData['check_user_id'] = $user_id;
  457. $checkData['types'] = 'oa_examine';
  458. $checkData['types_id'] = $param['id'];
  459. $checkData['check_time'] = time();
  460. $checkData['content'] = $param['content'];
  461. $checkData['flow_id'] = $dataInfo['flow_id'];
  462. $checkData['order_id'] = $dataInfo['order_id'] ? : 1;
  463. $checkData['status'] = $status;
  464. if ($status == 1) {
  465. if ($flowInfo['config'] == 1) {
  466. //固定流程
  467. //获取下一审批信息
  468. $nextStepData = $examineStepModel->nextStepUser($dataInfo['create_user_id'], $dataInfo['flow_id'], 'oa_examine', $param['id'], $dataInfo['order_id'], $user_id);
  469. $next_user_ids = $nextStepData['next_user_ids'] ? : [];
  470. $examineData['order_id'] = $nextStepData['order_id'] ? : '';
  471. if (!$next_user_ids) {
  472. $is_end = 1;
  473. //审批结束
  474. $checkData['check_status'] = !empty($status) ? 2 : 3;
  475. // $examineData['check_user_id'] = '';
  476. } else {
  477. //修改主体相关审批信息
  478. $examineData['check_user_id'] = arrayToString($next_user_ids);
  479. }
  480. } else {
  481. //自选流程
  482. $is_end = $param['is_end'] ? 1 : '';
  483. $check_user_id = $param['check_user_id'] ? : '';
  484. if ($is_end !== 1 && empty($check_user_id)) {
  485. return resultArray(['error' => '请选择下一审批人']);
  486. }
  487. $examineData['check_user_id'] = arrayToString($param['check_user_id']);
  488. }
  489. if ($is_end == 1) {
  490. $checkData['check_status'] = !empty($status) ? 2 : 3;
  491. // $examineData['check_user_id'] = '';
  492. $examineData['check_status'] = 2;
  493. }
  494. } else {
  495. //审批驳回
  496. $is_end = 1;
  497. $examineData['check_status'] = 3;
  498. //将审批记录至为无效
  499. // $examineRecordModel->setEnd(['types' => 'oa_examine','types_id' => $param['id']]);
  500. }
  501. //已审批人ID
  502. $examineData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]);
  503. $resExamine = db('oa_examine')->where(['examine_id' => $param['id']])->update($examineData);
  504. if ($resExamine) {
  505. $lastExamine = db('oa_examine')->where(['examine_id' => $param['id']])->update(['last_user_id'=> $examineData['flow_user_id']]);
  506. //审批记录
  507. $resRecord = $examineRecordModel->createData($checkData);
  508. //审核通过
  509. if ($is_end == 1 && !empty($status)) {
  510. // 审批通过消息告知审批提交人
  511. (new Message())->send(
  512. Message::EXAMINE_PASS,
  513. [
  514. 'title' => $dataInfo['category_name'],
  515. 'action_id' => $param['id']
  516. ],
  517. $dataInfo['create_user_id']
  518. );
  519. } else {
  520. if ($status) {
  521. // 通过后发送消息给下一审批人
  522. (new Message())->send(
  523. Message::EXAMINE_TO_DO,
  524. [
  525. 'from_user' => User::where(['id' => $dataInfo['create_user_id']])->value('realname'),
  526. 'title' => $dataInfo['category_name'],
  527. 'action_id' => $param['id']
  528. ],
  529. stringToArray($examineData['check_user_id'])
  530. );
  531. } else {
  532. // 审批驳回消息告知审批提交人
  533. (new Message())->send(
  534. Message::EXAMINE_REJECT,
  535. [
  536. 'title' => $dataInfo['category_name'],
  537. 'action_id' => $param['id']
  538. ],
  539. $dataInfo['create_user_id']
  540. );
  541. }
  542. }
  543. return resultArray(['data' => '审批成功']);
  544. } else {
  545. return resultArray(['error' => '审批失败,请重试!']);
  546. }
  547. }
  548. /**
  549. * 审批撤销审核
  550. * @author Michael_xu
  551. * @param
  552. * @return
  553. */
  554. public function revokeCheck()
  555. {
  556. $param = $this->param;
  557. $userInfo = $this->userInfo;
  558. $user_id = $userInfo['id'];
  559. $examine_id = $param['id'];
  560. $examineModel = model('Examine');
  561. $examineRecordModel = new \app\admin\model\ExamineRecord();
  562. $userModel = new \app\admin\model\User();
  563. $examineData = [];
  564. $examineData['update_time'] = time();
  565. $examineData['check_status'] = 0; //0待审核,1审核通中,2审核通过,3审核未通过
  566. //审批主体详情
  567. $dataInfo = db('oa_examine')->where(['examine_id' => $examine_id])->find();
  568. //权限判断(创建人或管理员)
  569. if ($dataInfo['check_status'] == 2) {
  570. return resultArray(['error' => '已审批结束,不能撤销']);
  571. }
  572. if ($dataInfo['check_status'] == 4) {
  573. return resultArray(['error' => '无需撤销']);
  574. }
  575. $admin_user_ids = $userModel->getAdminId();
  576. if ($dataInfo['create_user_id'] !== $user_id && !in_array($user_id, $admin_user_ids)) {
  577. return resultArray(['error' => '没有权限']);
  578. }
  579. $is_end = 0; // 1审批结束
  580. $status = 2; //1通过,0驳回, 2撤销
  581. $checkData = [];
  582. $checkData['check_user_id'] = $user_id;
  583. $checkData['types'] = 'oa_examine';
  584. $checkData['types_id'] = $param['id'];
  585. $checkData['check_time'] = time();
  586. $checkData['content'] = $param['content'];
  587. $checkData['flow_id'] = $dataInfo['flow_id'];
  588. $checkData['order_id'] = $dataInfo['order_id'];
  589. $checkData['status'] = $status;
  590. $examineData['check_status'] = 4;
  591. # 如果将审批人置空,会导致普通员工在右上角消息中无法查看审批
  592. $examineData['check_user_id'] = $dataInfo['check_user_id'];
  593. $examineData['flow_user_id'] = '';
  594. $resExamine = db('oa_examine')->where(['examine_id' => $examine_id])->update($examineData);
  595. if ($resExamine) {
  596. //将审批记录至为无效
  597. $examineRecordModel->setEnd(['types' => 'oa_examine','types_id' => $examine_id]);
  598. //审批记录
  599. $resRecord = $examineRecordModel->createData($checkData);
  600. return resultArray(['data' => '撤销成功']);
  601. } else {
  602. return resultArray(['error' => '撤销失败,请重试!']);
  603. }
  604. }
  605. /**
  606. * 我的审批
  607. * @return mixed
  608. */
  609. public function myExamine(){
  610. $param = $this->param;
  611. $userInfo = $this->userInfo;
  612. $param['user_id'] = $userInfo['id'];
  613. $ExamineLogic = new ExamineLogic();
  614. $data = $ExamineLogic->myExamine($param);
  615. return resultArray(['data' => $data]);
  616. }
  617. /**
  618. * 办公审批类型排序
  619. *
  620. * @author alvin guogaobo
  621. * @version 1.0 版本号
  622. * @since 2021/4/16 0016 14:02
  623. */
  624. public function examineSort(){
  625. $examineIds = $this->param['examineIds'];
  626. $userInfo = $this->userInfo;
  627. $examineCategory=new ExamineLogic();
  628. $examineCategory->setWorkOrder($examineIds, $userInfo['id']);
  629. return resultArray(['data' => '操作成功!']);
  630. }
  631. }