ApplyRecord-old.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class ApplyRecord extends Model
  8. {
  9. public function add($data,$orgId,$title){
  10. try{
  11. $recordId = Db::name('apply_record')->insertGetId($data);
  12. if(!$recordId){
  13. \exception('数据保存失败');
  14. }
  15. // 生成消息及推送提醒
  16. if($data['type'] == 3){
  17. $context = $title.',抄送给您,请知晓。';
  18. } else if($data['type'] == 9){
  19. $context = $title.',需要您去执行,请知晓。';
  20. } else {
  21. $context = $title.'需要您审批。';
  22. }
  23. $res = model('Message')->add(2,$recordId,2,$data['user_id'],$orgId,$context);
  24. if(!$res){
  25. \exception('消息生成失败');
  26. }
  27. return true;
  28. }catch (Exception $e){
  29. $this->error = $e->getMessage();
  30. return false;
  31. }
  32. }
  33. // 审批单生成时审批记录生成
  34. public function createRecord($applyId,$data){
  35. // flowJson排序
  36. $flowJson = sort_flow_json(json_decode($data['flow_json'],true));
  37. $curTime = date('Y-m-d H:i:s');
  38. $nodeid = '';
  39. $status = 1;
  40. $users = [];
  41. foreach ($flowJson as $k=>$v){
  42. $nodeid = $v['id'];
  43. if($v['type'] == 9||$v['type'] == 3){ // 节点是执行人或审批人时
  44. foreach ($v['userList'] as $kk=>$vv){
  45. $users[] = [
  46. 'user_id' => $vv['userId'],
  47. 'nodeid' => $v['id'],
  48. 'type' => $v['type']
  49. ];
  50. }
  51. } else if($v['type'] == 2||$v['type'] == 8){ // 审批人
  52. foreach ($v['userList'] as $kk=>$vv){
  53. $users[] = [
  54. 'user_id' => $vv['userId'],
  55. 'nodeid' => $v['id'],
  56. 'type' => $v['type']
  57. ];
  58. }
  59. break;
  60. } else if($v['type'] == 5){ // 流程结束
  61. $status = 2;
  62. }
  63. }
  64. try{
  65. if($status == 2){ // 流程结束
  66. $ret = Db::name('apply')->where('id',$applyId)->update([
  67. 'status' => 2,
  68. 'finish_time' => $curTime,
  69. 'update_time' => $curTime,
  70. 'nodeid' => $nodeid
  71. ]);
  72. if(!$ret){
  73. \exception('流程状态修改失败1');
  74. }
  75. // 生成消息记录
  76. $context = "温馨提醒,".$data['title']."(编号:".$data['apply_sn'].")已通过。";
  77. $mres = model('Message')->add(3,$applyId,4,$data['user_id'],$data['org_id'],$context);
  78. if(!$mres){
  79. \exception('消息生成失败');
  80. }
  81. if($data['advanced'] > 0){ // 流程结束高级组件执行逻辑
  82. $aret = $this->advancedEndAction($applyId,$data['org_id'],$data['user_id'],$data['form_json'],$data['advanced']);
  83. if(!$aret){
  84. \exception('操作失败');
  85. }
  86. }
  87. } else { // 审批中
  88. $ret = Db::name('apply')->where('id',$applyId)->update([
  89. 'status' => 1,
  90. 'update_time' => $curTime,
  91. 'nodeid' => $nodeid
  92. ]);
  93. if(!$ret){
  94. \exception('流程状态修改失败2'.$ret);
  95. }
  96. }
  97. if($users){
  98. foreach ($users as $k=>$v){
  99. $v['apply_id'] = $applyId;
  100. $v['status'] = 0;
  101. $v['create_time'] = $curTime;
  102. $res = model('ApplyRecord')->add($v,$data['org_id'],$data['title']);
  103. if(!$res){
  104. \exception('流程记录生成失败');
  105. }
  106. }
  107. }
  108. return true;
  109. }catch (Exception $e){
  110. $this->error = $e->getMessage();
  111. return false;
  112. }
  113. }
  114. // 记录修改为已阅
  115. public function updateStatus($id,$userId){
  116. $info = Db::name('apply_record')->where('id',$id)->where('user_id',$userId)->find();
  117. if($info && $info['status'] == 0){
  118. Db::name('apply_record')
  119. ->where('id',$id)
  120. ->update(['status' => 1,'finish_time' => date('Y-m-d H:i:s')]);
  121. }
  122. }
  123. // 转交
  124. public function transferApply($id,$userId,$transferUserId){
  125. if($userId == $transferUserId){
  126. HelpHander::error('被转交人不能是自己');
  127. }
  128. $info = Db::name('apply_record')
  129. ->alias('ar')
  130. ->join('apply a','a.id = ar.apply_id')
  131. ->where('ar.id',$id)
  132. ->where('ar.del',0)
  133. ->where('ar.user_id',$userId)
  134. ->field('ar.*,a.title,a.org_id')
  135. ->find();
  136. if(!$info){
  137. HelpHander::error('数据不存在');
  138. }
  139. if($info['type'] == 3||$info['type'] == 9){
  140. HelpHander::error('无法转交');
  141. }
  142. if($info['status'] != 0){
  143. HelpHander::error('已处理,无法转交');
  144. }
  145. $transfer = Db::name('apply_record')->where('del',0)->where('apply_id',$info['apply_id'])->where('user_id',$transferUserId)->find();
  146. if($transfer){
  147. HelpHander::error('被转交人已参与审批,无法再次转交');
  148. }
  149. Db::startTrans();
  150. try{
  151. $ret = Db::name('apply_record')->where('id',$id)->setField('status',3);
  152. if(!$ret){
  153. \exception('转交失败');
  154. }
  155. $data = [
  156. 'user_id' => $transferUserId,
  157. 'apply_id' => $info['apply_id'],
  158. 'status' => 0,
  159. 'nodeid' => $info['nodeid'],
  160. 'type' => 2,
  161. 'transfer' => 1,
  162. 'create_time' => date('Y-m-d H:i:s')
  163. ];
  164. $res = $this->add($data,$info['org_id'],$info['title']);
  165. if(!$res){
  166. \exception('转交失败');
  167. }
  168. Db::commit();
  169. }catch (Exception $e){
  170. Db::rollback();
  171. HelpHander::error('转交失败');
  172. }
  173. return true;
  174. }
  175. // 会签
  176. public function aggregationApproval($id,$userId,$userIds){
  177. $userIds = explode(',',$userIds);
  178. $info = Db::name('apply_record')
  179. ->alias('ar')
  180. ->join('apply a','a.id = ar.apply_id')
  181. ->where('ar.id',$id)
  182. ->where('ar.del',0)
  183. ->where('ar.user_id',$userId)
  184. ->field('ar.*,a.title,a.org_id,a.flow_json')
  185. ->find();
  186. if(!$info){
  187. HelpHander::error('数据不存在');
  188. }
  189. if($info['type'] == 3||$info['type'] == 9){
  190. HelpHander::error('无法会签');
  191. }
  192. if($info['status'] != 0){
  193. HelpHander::error('已处理,无法会签');
  194. }
  195. // 检查当前节点是会签还是或签,或签无法加人会签
  196. $flowJson = json_decode($info['flow_json'],true);
  197. foreach ($flowJson as $k=>$v){
  198. if($v['id'] == $info['nodeid'] && $v['mode'] == 2){
  199. HelpHander::error('该节点为或签,无法添加会签');
  200. }
  201. }
  202. $oldusers = Db::name('apply_record')
  203. ->where('nodeid',$info['nodeid'])
  204. ->where('apply_id',$id)
  205. ->where('del',0)
  206. ->column('user_id');
  207. $jjuser = array_intersect($userIds, $oldusers);
  208. if($jjuser){
  209. HelpHander::error('存在用户已是会签人员');
  210. }
  211. Db::startTrans();
  212. try{
  213. foreach ($userIds as $k=>$v){
  214. $data = [
  215. 'user_id' => $v,
  216. 'apply_id' => $info['apply_id'],
  217. 'status' => 0,
  218. 'nodeid' => $info['nodeid'],
  219. 'type' => 2,
  220. 'countersign' => 1,
  221. 'create_time' => date('Y-m-d H:i:s')
  222. ];
  223. $res = $this->add($data,$info['org_id'],$info['title']);
  224. if(!$res){
  225. \exception('会签失败');
  226. }
  227. }
  228. Db::commit();
  229. }catch (Exception $e){
  230. Db::rollback();
  231. HelpHander::error('会签失败');
  232. }
  233. return true;
  234. }
  235. // 加签
  236. public function addSign($id,$userId,$addUserId,$type=0){
  237. $info = Db::name('apply_record')
  238. ->alias('ar')
  239. ->join('apply a','a.id = ar.apply_id')
  240. ->where('ar.id',$id)
  241. ->where('ar.del',0)
  242. ->where('ar.user_id',$userId)
  243. ->field('ar.*,a.title,a.org_id,a.flow_json')
  244. ->find();
  245. if(!$info){
  246. HelpHander::error('数据不存在');
  247. }
  248. if($info['type'] == 3||$info['type'] == 9){
  249. HelpHander::error('无法加签');
  250. }
  251. if($info['status'] != 0){
  252. HelpHander::error('已处理,无法加签');
  253. }
  254. $lastNode = ''; // 最后一个审批节点
  255. $node = [];
  256. // 检查当前节点是会签还是或签,或签无法加签
  257. $flowJson = sort_flow_json(json_decode($info['flow_json'],true));
  258. foreach ($flowJson as $k=>$v){
  259. if($v['id'] == $info['nodeid'] && $v['mode'] == 2){
  260. HelpHander::error('该节点为或签,无法加签');
  261. }
  262. if($v['type'] == 2||$v['type'] == 8){
  263. $lastNode = $v['id'];
  264. }
  265. if($v['id'] == $info['nodeid']){
  266. $node = $v;
  267. }
  268. }
  269. // 检查是否多人会签,多人会签无法加签
  270. $oldusers = Db::name('apply_record')
  271. ->where('nodeid',$info['nodeid'])
  272. ->where('apply_id',$id)
  273. ->where('del',0)
  274. ->column('user_id');
  275. if(count($oldusers) > 1 || in_array($addUserId,$oldusers)){
  276. HelpHander::error('无权限加签');
  277. }
  278. if($type == 1 && $lastNode != $info['nodeid']){ // 往后加签,检查是否是最后一个审批节点
  279. HelpHander::error('无权限加签');
  280. }
  281. $user = Db::name('user_info')
  282. ->where('user_id',$addUserId)
  283. ->field('user_id,name')
  284. ->find();
  285. Db::startTrans();
  286. try{
  287. $node = [];
  288. foreach ($flowJson as $k=>$v){
  289. if($v['id'] == $info['nodeid']){
  290. $node = $v;
  291. }
  292. }
  293. $addnode = $node;
  294. $addnode['id'] = 'addnode'.time().rand(1000,9999);
  295. $addnode['nextId'] = $node['id'];
  296. $addnode['type'] = 8;
  297. $addnode['name'] = '加签';
  298. $addnode['userList'] = [[
  299. "userName" => $user['name'],
  300. "shortName" => mb_strlen($user['name']) > 2?mb_substr($user['name'], 0, -2):$user['name'],
  301. "userId" => $user['user_id']
  302. ]];
  303. foreach ($flowJson as $k=>$v){
  304. if($v['nextId'] == $info['nodeid']){
  305. $flowJson[$k]['nextId'] = $addnode['id'];
  306. }
  307. }
  308. $flowJson[] = $addnode;
  309. // 修改审批单信息
  310. $ret = Db::name('apply')->where('id',$info['apply_id'])->update([
  311. 'nodeid' => $addnode['id'],
  312. 'flow_json' => json_encode($flowJson,JSON_UNESCAPED_UNICODE),
  313. 'update_time' => date('Y-m-d H:i:s')
  314. ]);
  315. if(!$ret){
  316. \exception('加签失败');
  317. }
  318. // 删除原来节点记录及消息
  319. $ids = Db::name('apply_record')
  320. ->where('apply_id',$info['apply_id'])
  321. ->where('nodeid',$info['nodeid'])
  322. ->where('del',0)
  323. ->column('id');
  324. Db::name('apply_record')->where('id','in',$ids)->setField('del',1);
  325. Db::name('message')
  326. ->where('type',2)
  327. ->where('bus_type',2)
  328. ->where('org_id',$info['org_id'])
  329. ->where('bus_id','in',$ids)
  330. ->delete();
  331. $data = [
  332. 'user_id' => $addUserId,
  333. 'apply_id' => $info['apply_id'],
  334. 'status' => 0,
  335. 'nodeid' => $addnode['id'],
  336. 'type' => 8,
  337. 'create_time' => date('Y-m-d H:i:s')
  338. ];
  339. $res = $this->add($data,$info['org_id'],$info['title']);
  340. if(!$res){
  341. \exception('加签失败');
  342. }
  343. Db::commit();
  344. }catch (Exception $e){
  345. Db::rollback();
  346. HelpHander::error('加签失败'.$e->getMessage());
  347. }
  348. return true;
  349. }
  350. // 同意
  351. public function audit($id,$userId,$content,$formJson,$userList){
  352. $info = Db::name('apply_record')
  353. ->where('id',$id)
  354. ->where('user_id',$userId)
  355. ->find();
  356. if(!$info){
  357. HelpHander::error('数据不存在');
  358. }
  359. if($info['type'] == 3||$info['type'] == 9){
  360. HelpHander::error('无法执行此操作');
  361. }
  362. if($info['status'] != 0){
  363. HelpHander::error('已处理');
  364. }
  365. $apply = Db::name('apply')->where('id',$info['apply_id'])->find();
  366. $flowJson = sort_flow_json(json_decode($apply['flow_json'],true));
  367. $curNode = $this->getNodeFlowJson($flowJson,$info['nodeid']);
  368. $next = 0; // 是否走到下一流程
  369. if($curNode['mode'] == '1'){ // 会签
  370. // 检查是否该到下一流程
  371. $count = Db::name('apply_record')
  372. ->where('apply_id',$info['apply_id'])
  373. ->where('nodeid',$info['nodeid'])
  374. ->where('status',0)
  375. ->count();
  376. if($count == 1){ // 下一流程
  377. $next = 1;
  378. }
  379. } else { // 或签
  380. $next = 1;
  381. }
  382. $isexecutor = 0;
  383. foreach ($flowJson as $k=>$v){
  384. if($v['type'] == 9){
  385. $isexecutor = 1;
  386. break;
  387. }
  388. }
  389. $curTime = date('Y-m-d H:i:s');
  390. $duration = round((strtotime($curTime) - strtotime($info['create_time']))/3600,2); // 时长
  391. $applyduration = round((strtotime($curTime) - strtotime($apply['create_time']))/3600,2); // 时长
  392. Db::startTrans();
  393. try{
  394. $ret = Db::name('apply_record')
  395. ->where('id',$id)
  396. ->update([
  397. 'status' => 1,
  398. 'finish_time'=>$curTime,
  399. 'content' => $content,
  400. 'duration' => $duration
  401. ]);
  402. if(!$ret){
  403. \exception('操作失败');
  404. }
  405. if($formJson || $userList){ // formJson或$userList有变化
  406. if($formJson){
  407. $ad['form_json'] = $formJson;
  408. // formJson日志记录
  409. $res = Db::name('apply_form_log')->insert([
  410. 'apply_id' => $info['apply_id'],
  411. 'user_id' => $userId,
  412. 'form_json' => $formJson,
  413. 'create_time' => $curTime
  414. ]);
  415. if(!$res){
  416. \exception('数据保存失败');
  417. }
  418. }
  419. if($isexecutor == 1){
  420. foreach ($flowJson as $k=>$v){
  421. if($v['type'] == 9){
  422. $flowJson[$k]['userList'] = json_decode($userList,true);
  423. break;
  424. }
  425. }
  426. $ad['flow_json'] = json_encode($flowJson,JSON_UNESCAPED_UNICODE);
  427. }
  428. $ad['update_time'] = $curTime;
  429. $ret = Db::name('apply')->where('id',$info['apply_id'])->update($ad);
  430. if(!$ret){
  431. \exception('数据修改失败');
  432. }
  433. }
  434. if($next == 1){ // 流转到下一节点
  435. Db::name('apply_record')
  436. ->where('id','<>',$id)
  437. ->where('apply_id',$info['apply_id'])
  438. ->where('status',0)
  439. ->where('nodeid',$info['nodeid'])
  440. ->setField('status',4);
  441. $nodeid = $curNode['nextId'];
  442. $status = 1;
  443. $users = [];
  444. while (true){
  445. $nextNode = $this->getNodeFlowJson($flowJson,$nodeid);
  446. if($nextNode['type'] == 9||$nextNode['type'] == 3){ // 节点是执行人或审批人时
  447. foreach ($nextNode['userList'] as $kk=>$vv){
  448. $users[] = [
  449. 'user_id' => $vv['userId'],
  450. 'nodeid' => $nextNode['id'],
  451. 'type' => $nextNode['type']
  452. ];
  453. }
  454. $nodeid = $nextNode['nextId'];
  455. } else if($nextNode['type'] == 2||$nextNode['type'] == 8){ // 审批人
  456. foreach ($nextNode['userList'] as $kk=>$vv){
  457. $users[] = [
  458. 'user_id' => $vv['userId'],
  459. 'nodeid' => $nextNode['id'],
  460. 'type' => $nextNode['type']
  461. ];
  462. }
  463. break;
  464. } else if($nextNode['type'] == 5){ // 流程结束
  465. $status = 2;
  466. break;
  467. }
  468. }
  469. if($status == 2){ // 流程结束
  470. $ret = Db::name('apply')->where('id',$info['apply_id'])->update([
  471. 'status' => 2,
  472. 'finish_time' => $curTime,
  473. 'update_time' => $curTime,
  474. 'nodeid' => $nodeid,
  475. 'duration' => $applyduration
  476. ]);
  477. if(!$ret){
  478. \exception('信息修改失败');
  479. }
  480. // 生成消息记录
  481. $context = "温馨提醒,".$apply['title']."(编号:".$apply['apply_sn'].")已通过。";
  482. $mres = model('Message')->add(3,$info['apply_id'],4,$apply['user_id'],$apply['org_id'],$context);
  483. if(!$mres){
  484. \exception('消息生成失败');
  485. }
  486. if($apply['advanced'] > 0){ // 流程结束高级组件执行逻辑
  487. $aret = $this->advancedEndAction($apply['id'],$apply['org_id'],$apply['user_id'],$apply['form_json'],$apply['advanced']);
  488. if(!$aret){
  489. \exception('操作失败');
  490. }
  491. }
  492. } else { // 审批中
  493. $ret = Db::name('apply')->where('id',$info['apply_id'])->update([
  494. 'status' => 1,
  495. 'update_time' => $curTime,
  496. 'nodeid' => $nodeid
  497. ]);
  498. if(!$ret){
  499. \exception('信息修改失败');
  500. }
  501. }
  502. if($users){
  503. foreach ($users as $k=>$v){
  504. $v['apply_id'] = $info['apply_id'];
  505. $v['status'] = 0;
  506. $v['create_time'] = $curTime;
  507. $res = $this->add($v,$apply['org_id'],$apply['title']);
  508. if(!$res){
  509. \exception('流程记录生成失败');
  510. }
  511. }
  512. }
  513. }
  514. Db::commit();
  515. }catch (Exception $e){
  516. Db::rollback();
  517. HelpHander::error('操作失败'.$e->getMessage());
  518. }
  519. return true;
  520. }
  521. // 打回/拒绝
  522. public function toBack($applyId,$userId,$content){
  523. $info = Db::name('apply_record')
  524. ->alias('ar')
  525. ->join('apply a','a.id = ar.apply_id')
  526. ->where('a.id',$applyId)
  527. ->where('ar.user_id',$userId)
  528. ->where('ar.status',0)
  529. ->field('ar.*')
  530. ->find();
  531. if(!$info){
  532. HelpHander::error('数据不存在');
  533. }
  534. if($info['type'] == 3||$info['type'] == 9){
  535. HelpHander::error('无法操作');
  536. }
  537. if($info['status'] != 0){
  538. HelpHander::error('已处理');
  539. }
  540. $apply = Db::name('apply')->where('id',$info['apply_id'])->find();
  541. $curTime = date('Y-m-d H:i:s');
  542. $duration = round((strtotime($curTime) - strtotime($info['create_time']))/3600,2); // 时长
  543. $applyduration = round((strtotime($curTime) - strtotime($apply['create_time']))/3600,2); // 时长
  544. Db::startTrans();
  545. try{
  546. $ret = Db::name('apply_record')->where('id',$info['id'])->update([
  547. 'status' => 2,
  548. 'content' => $content,
  549. 'finish_time' => $curTime,
  550. 'duration' => $duration
  551. ]);
  552. if(!$ret){
  553. \exception('操作失败');
  554. }
  555. Db::name('apply_record')
  556. ->where('id','<>',$info['id'])
  557. ->where('status',0)
  558. ->where('apply_id',$info['apply_id'])
  559. ->where('nodeid',$info['nodeid'])
  560. ->setField('status',4);
  561. $res = Db::name('apply')->where('id',$applyId)->update([
  562. 'status' => 5,
  563. 'finish_time' => $curTime,
  564. 'duration' => $applyduration
  565. ]);
  566. if(!$res){
  567. \exception('操作失败');
  568. }
  569. $result = $this->advancedDisagreeAction($applyId,$apply['advanced']);
  570. if(!$result){
  571. \exception('操作失败');
  572. }
  573. Db::commit();
  574. }catch (Exception $e){
  575. Db::rollback();
  576. HelpHander::error('会签失败');
  577. }
  578. return true;
  579. }
  580. // 获取node信息
  581. public function getNodeFlowJson($flowJson,$nodeId){
  582. $curNode = [];
  583. foreach ($flowJson as $k=>$v){
  584. if($v['id'] == $nodeId){
  585. $curNode = $v;
  586. break;
  587. }
  588. }
  589. return $curNode;
  590. }
  591. // 高级组件执行操作 -- 流程申请时
  592. public function advancedStartAction($id,$orgId,$userId,$formJson,$advanced,$extra=[]){
  593. switch ($advanced){
  594. case '1': // 请假
  595. $ret = model('AttendanceLeave')->advancedStartLeave($id,$orgId,$userId,$formJson);
  596. break;
  597. case '3': // 合同
  598. $ret = model('Contract')->advancedStartContract($id,$orgId,$userId,$formJson);
  599. break;
  600. case '4': // 追加合同
  601. $ret = model('Contract')->advancedStartAddContract($id,$orgId,$userId,$formJson);
  602. break;
  603. case '5': // 合同付款
  604. $ret = model('ContractPay')->advancedStartContractPay($id,$orgId,$userId,$formJson);
  605. break;
  606. case '6': // 会议室预定
  607. $ret = model('MeetingRoom')->advancedStartMeetingRoom($id,$orgId,$userId,$formJson,$extra);
  608. break;
  609. case '7': // 合同收款
  610. $ret = model('ContractPay')->advancedStartContractGet($id,$orgId,$userId,$formJson);
  611. break;
  612. case '8': // 销假
  613. $ret = model('AttendanceLeaveTerminate')->advancedStartLeaveTerminate($id,$orgId,$userId,$formJson);
  614. break;
  615. case '9': // 离京报告
  616. $ret = model('LeaveBj')->advancedStartLeaveBj($id,$orgId,$userId,$formJson);
  617. break;
  618. case '10': // 办公物品
  619. $ret = model('OfficeReceive')->advancedStartOfficeReceive($id,$orgId,$userId,$formJson,$extra);
  620. break;
  621. case '11': // 用车
  622. $ret = model('CarRecord')->advancedStartCarRecord($id,$orgId,$userId,$formJson,$extra);
  623. break;
  624. case '13': // 资产领取
  625. $ret = model('AssetReceive')->advancedStartAssetReceive($id,$orgId,$userId,$formJson,$extra);
  626. break;
  627. case '14': // 资产退库
  628. $ret = model('AssetWithdraw')->advancedStartAssetWithdraw($id,$orgId,$userId,$formJson,$extra);
  629. break;
  630. case '15': // 资产维修
  631. $ret = model('AssetRepair')->advancedStartAssetRepair($id,$orgId,$userId,$formJson,$extra);
  632. break;
  633. case '16': // 资产处置
  634. $ret = model('AssetDisposal')->advancedStartAssetDisposal($id,$orgId,$userId,$formJson,$extra);
  635. break;
  636. case '17': // 预算
  637. $ret = model('BudgetApply')->advancedStartBudgetApply($id,$orgId,$userId,$formJson,$extra);
  638. break;
  639. case '18': // 用印
  640. $ret = model('OfficialSealApply')->advancedStartSealApply($id,$orgId,$userId,$formJson,$extra);
  641. break;
  642. case '19': // 中心发文
  643. $ret = model('PostApply')->advancedStartPostApply($id,$orgId,$userId,$formJson,$extra);
  644. break;
  645. default:
  646. $ret = true;
  647. break;
  648. }
  649. return $ret;
  650. }
  651. // 高级组件执行操作 -- 流程结束时
  652. public function advancedEndAction($id,$orgId,$userId,$formJson,$advanced){
  653. switch ($advanced){
  654. case '1': // 请假
  655. $ret = model('AttendanceLeave')->advancedEndLeave($id,$orgId,$userId,$formJson);
  656. break;
  657. case '3': // 合同
  658. $ret = model('Contract')->advancedEndContract($id,$orgId,$userId,$formJson);
  659. break;
  660. case '4': // 追加合同
  661. $ret = model('Contract')->advancedEndAddContract($id,$orgId,$userId,$formJson);
  662. break;
  663. case '5': // 合同支付
  664. $ret = model('ContractPay')->advancedEndContractPay($id,$orgId,$userId,$formJson);
  665. break;
  666. case '6': // 会议室预定
  667. $ret = model('MeetingRoom')->advancedEndMeetingRoom($id,$orgId,$userId,$formJson);
  668. break;
  669. case '7': // 合同收款
  670. $ret = model('ContractPay')->advancedEndContractGet($id,$orgId,$userId,$formJson);
  671. break;
  672. case '8': // 销假
  673. $ret = model('AttendanceLeaveTerminate')->advancedEndLeaveTerminate($id,$orgId,$userId,$formJson);
  674. break;
  675. case '9': // 离京报告
  676. $ret = model('LeaveBj')->advancedEndLeaveBj($id,$orgId,$userId,$formJson);
  677. break;
  678. case '10': // 办公物品
  679. $ret = model('OfficeReceive')->advancedEndOfficeReceive($id,$orgId,$userId,$formJson);
  680. break;
  681. case '11': // 用车
  682. $ret = model('CarRecord')->advancedEndCarRecord($id,$orgId,$userId,$formJson);
  683. break;
  684. case '12': // 离职或退休
  685. $ret = model('UserInfo')->advancedEndUserInfo($id,$orgId,$userId,$formJson);
  686. break;
  687. case '13': // 资产领取
  688. $ret = model('AssetReceive')->advancedEndAssetReceive($id,$orgId,$userId,$formJson);
  689. break;
  690. case '14': // 资产退库
  691. $ret = model('AssetWithdraw')->advancedEndAssetWithdraw($id,$orgId,$userId,$formJson);
  692. break;
  693. case '15': // 资产维修
  694. $ret = model('AssetRepair')->advancedEndAssetRepair($id,$orgId,$userId,$formJson);
  695. break;
  696. case '16': // 资产处置
  697. $ret = model('AssetDisposal')->advancedEndAssetDisposal($id,$orgId,$userId,$formJson);
  698. break;
  699. case '17': // 预算
  700. $ret = model('BudgetApply')->advancedEndBudgetApply($id,$orgId,$userId,$formJson);
  701. break;
  702. case '18': // 用印
  703. $ret = model('OfficialSealApply')->advancedEndSealApply($id,$orgId,$userId,$formJson);
  704. break;
  705. case '19': // 中心发文
  706. $ret = model('PostApply')->advancedEndPostApply($id,$orgId,$userId,$formJson);
  707. break;
  708. default:
  709. $ret = true;
  710. break;
  711. }
  712. return $ret;
  713. }
  714. public function advancedDisagreeAction($applyId,$advanced){
  715. switch ($advanced){
  716. case '1': // 请假
  717. $ret = model('AttendanceLeave')->advancedDisagreeLeave($applyId);
  718. break;
  719. case '3': // 合同
  720. $ret = model('Contract')->advancedDisagreeContract($applyId);
  721. break;
  722. case '4': // 追加合同
  723. $ret = model('Contract')->advancedDisagreeAddContract($applyId);
  724. break;
  725. case '5': // 合同支付
  726. $ret = model('ContractPay')->advancedDisagreeContractPay($applyId);
  727. break;
  728. case '6': // 会议室预定
  729. $ret = model('MeetingRoom')->advancedDisagreeMeetingRoom($applyId);
  730. break;
  731. case '7': // 合同收款
  732. $ret = model('ContractPay')->advancedDisagreeContractGet($applyId);
  733. break;
  734. case '8': // 销假
  735. $ret = model('AttendanceLeaveTerminate')->advancedDisagreeLeaveTerminate($applyId);
  736. break;
  737. case '9': // 离京报告
  738. $ret = model('LeaveBj')->advancedDisagreeLeaveBj($applyId);
  739. break;
  740. case '10': // 办公物品
  741. $ret = model('OfficeReceive')->advancedDisagreeOfficeReceive($applyId);
  742. break;
  743. case '11': // 用车
  744. $ret = model('CarRecord')->advancedDisagreeCarRecord($applyId);
  745. break;
  746. case '13': // 资产领取
  747. $ret = model('AssetReceive')->advancedDisagreeAssetReceive($applyId);
  748. break;
  749. case '14': // 资产退库
  750. $ret = model('AssetWithdraw')->advancedDisagreeAssetWithdraw($applyId);
  751. break;
  752. case '15': // 资产维修
  753. $ret = model('AssetRepair')->advancedDisagreeAssetRepair($applyId);
  754. break;
  755. case '16': // 资产处置
  756. $ret = model('AssetDisposal')->advancedDisagreeAssetDisposal($applyId);
  757. break;
  758. case '17': // 预算
  759. $ret = model('BudgetApply')->advancedDisagreeBudgetApply($applyId);
  760. break;
  761. case '18': // 用印
  762. $ret = model('OfficialSealApply')->advancedDisagreeSealApply($applyId);
  763. break;
  764. case '19': // 中心发文
  765. $ret = model('PostApply')->advancedDisagreePostApply($applyId);
  766. break;
  767. default:
  768. $ret = true;
  769. break;
  770. }
  771. return $ret;
  772. }
  773. // 获取未审批数量
  774. public function unApplyNums($userId,$orgId){
  775. $count = Db::name('apply_record')
  776. ->alias('ar')
  777. ->join('apply a','a.id = ar.apply_id')
  778. ->where('ar.status',0)
  779. ->where('ar.type','in',[2,8])
  780. ->where('ar.user_id',$userId)
  781. ->where('a.org_id',$orgId)
  782. ->count();
  783. return $count;
  784. }
  785. }