Examine.php 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 审批流程
  4. // +----------------------------------------------------------------------
  5. // | Author: zjf
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\controller;
  8. use think\Hook;
  9. use think\Request;
  10. use think\Db;
  11. class Examine extends ApiCommon
  12. {
  13. /**
  14. * 用于判断权限
  15. * @permission 无限制
  16. * @allow 登录用户可访问
  17. * @other 其他根据系统设置
  18. **/
  19. public function _initialize()
  20. {
  21. $action = [
  22. 'permission'=>[],
  23. 'allow'=>['index','save','update','read','delete','enables','steplist','userlist','recordlist']
  24. ];
  25. Hook::listen('check_auth',$action);
  26. $request = Request::instance();
  27. $a = strtolower($request->action());
  28. if (!in_array($a, $action['permission'])) {
  29. parent::_initialize();
  30. }
  31. //权限判断
  32. $unAction = ['steplist','userlist','recordlist'];
  33. if (!in_array($a, $unAction) && !checkPerByAction('admin', 'examine_flow', 'index')) {
  34. header('Content-Type:application/json; charset=utf-8');
  35. exit(json_encode(['code'=>102,'error'=>'无权操作']));
  36. }
  37. }
  38. /**
  39. * 审批流程列表
  40. * @author zjf
  41. * @return
  42. */
  43. public function index()
  44. {
  45. $examinewModel = model('Examine');
  46. $param = $this->param;
  47. //过滤审批类型中关联的审批流
  48. // $param['types'] = ['neq','oa_examine'];
  49. $data = $examinewModel->getDataList($param);
  50. return resultArray(['data' => $data]);
  51. }
  52. /**
  53. * 审批流程详情
  54. * @author zjf
  55. * @param
  56. * @return
  57. */
  58. public function read()
  59. {
  60. $examineModel = model('Examine');
  61. $param = $this->param;
  62. $res = $examineModel->getDataById($param['id']);
  63. if (!$res) {
  64. return resultArray(['error' => $examineFlowModel->getError()]);
  65. }
  66. return resultArray(['data' => $res]);
  67. }
  68. /**
  69. * 添加审批流程
  70. *
  71. * @return \think\response\Json
  72. * @throws \think\Exception
  73. * @throws \think\exception\PDOException
  74. */
  75. public function save()
  76. {
  77. $examineModel = model('Examine');
  78. $param = $this->param;
  79. $userInfo = $this->userInfo;
  80. $a = '{"examineName":"合同审批流程","label":1,"recheckType":1,"managerList":[14019],"remarks":"说明","dataList":[{"examineType":1,"name":"审批人0","examineErrorHandling":2,"roleId":null,"type":2,"userList":[32646,14019],"chooseType":null,"rangeType":null,"parentLevel":null},{"examineType":0,"name":"","conditionList":[{"conditionName":"条件1","sort":1,"conditionDataList":[{"name":"发起人","fieldName":"","type":0,"fieldId":0,"conditionType":8,"values":{"deptList":[],"roleList":[173447,173448,173449],"userList":[14019]}},{"name":"合同金额","fieldName":"money","type":6,"fieldId":1055246,"conditionType":6,"values":[1,1,1,2000]}],"examineDataList":[{"examineType":2,"name":"审批人1","examineErrorHandling":2,"roleId":null,"type":1,"userList":[14019],"chooseType":null,"rangeType":null,"parentLevel":3}]},{"conditionName":"条件2","sort":2,"conditionDataList":[{"name":"合同金额","fieldName":"money","type":6,"fieldId":1055246,"conditionType":2,"values":["2000"]}],"examineDataList":[{"examineType":0,"name":"","conditionList":[{"conditionName":"条件2-1","sort":1,"conditionDataList":[{"name":"合同金额","fieldName":"money","type":6,"fieldId":1055246,"conditionType":3,"values":["5000"]}],"examineDataList":[]},{"conditionName":"条件2-2","sort":2,"conditionDataList":[{"name":"合同金额","fieldName":"money","type":6,"fieldId":1055246,"conditionType":2,"values":["5000"]}],"examineDataList":[{"examineType":3,"name":"审批人2-2-1","examineErrorHandling":2,"roleId":173448,"type":2,"userList":[32646],"chooseType":null,"rangeType":null,"parentLevel":null}]}]},{"examineType":2,"name":"审批人2","examineErrorHandling":2,"roleId":null,"type":1,"userList":[14019],"chooseType":null,"rangeType":null,"parentLevel":3}]}]},{"examineType":2,"name":"业务审批1052","examineErrorHandling":2,"roleId":"","type":1,"userList":[],"chooseType":1,"rangeType":null,"parentLevel":3}],"examineId":1378287}';
  81. $param = object_to_array(json_decode($a));
  82. $param['examineId'] = 2;
  83. // 主表 审批表 信息
  84. db('examine')->where(['examine_id' => $param['examineId']])->update(['examine_name'=>$param['examineName'], 'label'=>$param['label'], 'remarks'=>$param['remarks'], 'recheck_type'=>$param['recheckType']]);
  85. // 删除 相关表数据
  86. $flow_ids = db('examine_flow')->where(['examine_id' => $param['examineId']])->column('flow_id');
  87. db('examine_flow')->where(['flow_id' => ['in', $flow_ids]])->delete();
  88. db('examine_condition')->where(['flow_id' => ['in', $flow_ids]])->delete();
  89. db('examine_condition_data')->where(['flow_id' => ['in', $flow_ids]])->delete();
  90. db('examine_flow_continuous_superior')->where(['flow_id' => ['in', $flow_ids]])->delete();
  91. db('examine_flow_member')->where(['flow_id' => ['in', $flow_ids]])->delete();
  92. db('examine_flow_optional')->where(['flow_id' => ['in', $flow_ids]])->delete();
  93. db('examine_flow_role')->where(['flow_id' => ['in', $flow_ids]])->delete();
  94. db('examine_flow_superior')->where(['flow_id' => ['in', $flow_ids]])->delete();
  95. // 审批管理员
  96. db('examine_manager_user')->where(['examine_id' => $param['examineId']])->delete();
  97. $managerUser = [];
  98. foreach ($param['managerList'] as $key => $value) {
  99. $arr['examine_id'] = $param['examineId'];
  100. $arr['user_id'] = $value;
  101. $arr['sort'] = $key;
  102. $managerUser[] = $arr;
  103. }
  104. db('examine_manager_user')->insertAll($managerUser);
  105. $create_time = date('Y-m-d H:i:s');
  106. $userId = $userInfo['id'];
  107. // 审批流程
  108. foreach ($param['dataList'] as $k => $v) {
  109. $condition_id = 0;
  110. // 处理流程 0 条件 1 指定成员 2 主管 3 角色 4 发起人自选 5 连续多级主管 7 发起人
  111. $flow = [];
  112. $flow['name'] = $v['name'];
  113. $flow['examine_id'] = $param['examineId'];
  114. $flow['examine_type'] = $v['examineType'];
  115. $flow['examine_error_handling'] = $v['examineErrorHandling'] ? : 1;
  116. $flow['condition_id'] = $condition_id;
  117. $flow['sort'] = $k;
  118. $flow['create_time'] = $create_time;
  119. $flow['create_user_id'] = $userId;
  120. $flowId = db('examine_flow')->insertGetId($flow);
  121. // 1 指定成员 2 主管 3 角色 4 发起人自选 5 连续多级主管 7 发起人
  122. $examine_flow = [];
  123. switch ($v['examineType']) {
  124. case '1' :
  125. foreach ($v['userList'] as $key => $value) {
  126. $examine_flow[$key]['sort'] = $key;
  127. $examine_flow[$key]['type'] = $v['type'];
  128. $examine_flow[$key]['user_id'] = $value;
  129. $examine_flow[$key]['flow_id'] = $flowId;
  130. }
  131. db('examine_flow_member')->insertAll($examine_flow);
  132. break;
  133. case '2' :
  134. $examine_flow['flow_id'] = $flowId;
  135. $examine_flow['parent_level'] = $v['parentLevel'];
  136. $examine_flow['type'] = $v['type'];
  137. db('examine_flow_superior')->insert($examine_flow);
  138. break;
  139. case '3' :
  140. $examine_flow['flow_id'] = $flowId;
  141. $examine_flow['role_id'] = $v['roleId'];
  142. $examine_flow['type'] = $v['type'];
  143. db('examine_flow_role')->insert($examine_flow);
  144. break;
  145. case '4' :
  146. foreach ($v['userList'] as $key => $value) {
  147. $examine_flow[$key]['sort'] = $key;
  148. $examine_flow[$key]['type'] = $v['type'];
  149. $examine_flow[$key]['user_id'] = $value;
  150. $examine_flow[$key]['flow_id'] = $flowId;
  151. $examine_flow[$key]['role_id'] = $v['roleId'];
  152. $examine_flow[$key]['choose_type'] = $v['chooseType'];
  153. $examine_flow[$key]['range_type'] = $v['rangeType'];
  154. }
  155. db('examine_flow_optional')->insertAll($examine_flow);
  156. break;
  157. case '5' :
  158. $examine_flow['flow_id'] = $flowId;
  159. $examine_flow['role_id'] = $v['roleId'];
  160. $examine_flow['max_level'] = $v['parentLevel'];
  161. $examine_flow['type'] = $v['type'];
  162. db('examine_flow_continuous_superior')->insert($examine_flow);
  163. break;
  164. // case '7' :
  165. // break;
  166. }
  167. foreach ($v['conditionList'] as $k1 => $v1) {
  168. // 处理条件
  169. $condition['condition_name'] = $v1['conditionName'];
  170. $condition['priority'] = $v1['sort'];
  171. $condition['create_time'] = $create_time;
  172. $condition['create_user_id'] = $userId;
  173. $condition['flow_id'] = $flowId;
  174. $condition_id = db('examine_condition')->insertGetId($condition);
  175. // 处理条件 扩展
  176. foreach ($v1['conditionDataList'] as $kc => $vc) {
  177. $conditionDate = [];
  178. $conditionDate['field_id'] = $vc['fieldId'];
  179. $conditionDate['field_name'] = $vc['fieldName'] ? : '';
  180. $conditionDate['condition_type'] = $vc['conditionType'];
  181. $conditionDate['value'] = json_encode($vc['values']);
  182. $conditionDate['name'] = $vc['name'];
  183. $conditionDate['type'] = $vc['type'];
  184. $conditionDate['condition_id'] = $condition_id;
  185. $conditionDate['flow_id'] = $flowId;
  186. $condition_data_id = db('examine_condition_data')->insertGetId($conditionDate);
  187. }
  188. if(!empty($v1['examineDataList'])){
  189. $this->recursion($v1['examineDataList'], $userId, $condition_id, $param['examineId'], $create_time);
  190. }
  191. }
  192. }
  193. return resultArray(['data' => $param]);
  194. }
  195. public function recursion ($conditionList, $userId, $condition_id, $examineId, $create_time)
  196. {
  197. foreach ($conditionList as $k => $v) {
  198. // 处理流程 0 条件 1 指定成员 2 主管 3 角色 4 发起人自选 5 连续多级主管 7 发起人
  199. $flow = [];
  200. $flow['name'] = $v['name'];
  201. $flow['examine_id'] = $examineId;
  202. $flow['examine_type'] = $v['examineType'];
  203. $flow['examine_error_handling'] = $v['examineErrorHandling'] ? : 1;
  204. $flow['condition_id'] = $condition_id;
  205. $flow['sort'] = $k;
  206. $flow['create_time'] = $create_time;
  207. $flow['create_user_id'] = $userId;
  208. $flowId = db('examine_flow')->insertGetId($flow);
  209. // 1 指定成员 2 主管 3 角色 4 发起人自选 5 连续多级主管 7 发起人
  210. $examine_flow = [];
  211. switch ($v['examineType']) {
  212. case '1' :
  213. foreach ($v['userList'] as $key => $value) {
  214. $examine_flow[$key]['sort'] = $key;
  215. $examine_flow[$key]['type'] = $v['type'];
  216. $examine_flow[$key]['user_id'] = $value;
  217. $examine_flow[$key]['flow_id'] = $flowId;
  218. }
  219. db('examine_flow_member')->insertAll($examine_flow);
  220. break;
  221. case '2' :
  222. $examine_flow['flow_id'] = $flowId;
  223. $examine_flow['parent_level'] = $v['parentLevel'];
  224. $examine_flow['type'] = $v['type'];
  225. db('examine_flow_superior')->insert($examine_flow);
  226. break;
  227. case '3' :
  228. $examine_flow['flow_id'] = $flowId;
  229. $examine_flow['role_id'] = $v['roleId'];
  230. $examine_flow['type'] = $v['type'];
  231. db('examine_flow_role')->insert($examine_flow);
  232. break;
  233. case '4' :
  234. foreach ($v['userList'] as $key => $value) {
  235. $examine_flow[$key]['sort'] = $key;
  236. $examine_flow[$key]['type'] = $v['type'];
  237. $examine_flow[$key]['user_id'] = $value;
  238. $examine_flow[$key]['flow_id'] = $flowId;
  239. $examine_flow[$key]['role_id'] = $v['roleId'];
  240. $examine_flow[$key]['choose_type'] = $v['chooseType'];
  241. $examine_flow[$key]['range_type'] = $v['rangeType'];
  242. }
  243. db('examine_flow_optional')->insertAll($examine_flow);
  244. break;
  245. case '5' :
  246. $examine_flow['flow_id'] = $flowId;
  247. $examine_flow['role_id'] = $v['roleId'];
  248. $examine_flow['max_level'] = $v['parentLevel'];
  249. $examine_flow['type'] = $v['type'];
  250. db('examine_flow_continuous_superior')->insert($examine_flow);
  251. break;
  252. // case '7' :
  253. // break;
  254. }
  255. foreach ($v['conditionList'] as $k1 => $v1) {
  256. // 处理条件
  257. $condition['condition_name'] = $v1['conditionName'];
  258. $condition['priority'] = $v1['sort'];
  259. $condition['create_time'] = $create_time;
  260. $condition['create_user_id'] = $userId;
  261. $condition['flow_id'] = $flowId;
  262. $condition_id1 = db('examine_condition')->insertGetId($condition);
  263. // 处理条件 扩展
  264. foreach ($v1['conditionDataList'] as $kc => $vc) {
  265. $conditionDate = [];
  266. $conditionDate['field_id'] = $vc['fieldId'];
  267. $conditionDate['field_name'] = $vc['fieldName'] ? : '';
  268. $conditionDate['condition_type'] = $vc['conditionType'];
  269. $conditionDate['value'] = json_encode($vc['values']);
  270. $conditionDate['name'] = $vc['name'];
  271. $conditionDate['type'] = $vc['type'];
  272. $conditionDate['condition_id'] = $condition_id1;
  273. $conditionDate['flow_id'] = $flowId;
  274. $condition_data_id = db('examine_condition_data')->insertGetId($conditionDate);
  275. }
  276. if(!empty($v1['examineDataList'])){
  277. $this->recursion($v1['examineDataList'], $userId, $condition_id1, $examineId, $create_time);
  278. }
  279. }
  280. }
  281. }
  282. /**
  283. * 预览审批条件
  284. * @return [type] [description]
  285. */
  286. public function previewFiledName()
  287. {
  288. $param = $this->param;
  289. $flow_id = db('examine_flow')
  290. ->where(['examine_id' => $param['id']])
  291. ->where(['examine_type' => 0])
  292. ->where(['condition_id' => 0])
  293. ->min('flow_id');
  294. $condition_data = db('examine_condition_data')->where('flow_id', $flow_id)->where('field_name', 'money')->select();
  295. return resultArray(['data' => $condition_data]);
  296. }
  297. /**
  298. * 预览检查流
  299. * @return [type] [description]
  300. */
  301. public function previewExamineFlow()
  302. {
  303. $userInfo = $this->userInfo;
  304. $param = $this->param;
  305. $param['dataMap']['money'] = 10000;
  306. $examine_flow = db('examine_flow')
  307. ->where(['examine_id' => $param['id']])
  308. ->where(['condition_id' => 0])
  309. ->select();
  310. $data = [];
  311. foreach ($examine_flow as $key => $value) {
  312. if($value['examine_type'] == 0){
  313. $condition = db('examine_condition')
  314. ->where('flow_id', $value['flow_id'])
  315. ->select();
  316. foreach ($condition as $ka => $va) {
  317. // 处理审批条件 是否符合 符合去找流程 不符合 找下一个流程
  318. $condition_data = db('examine_condition_data')->where('condition_id', $va['condition_id'])->select();
  319. foreach ($condition_data as $kb => $vb) {
  320. $jump_out = 1;
  321. // 1 等于 2 大于 3 小于 4 大于等于 5 小于等于 6 两者之间 7 包含 8 员工 9 部门 10 角色',
  322. switch ($vb['condition_type']) {
  323. case '1' :
  324. if($param['dataMap']['money'] != json_decode($vb['value'])[0]){
  325. $jump_out = 2;
  326. }
  327. break;
  328. case '2' :
  329. if($param['dataMap']['money'] <= json_decode($vb['value'])[0]){
  330. $jump_out = 2;
  331. }
  332. break;
  333. case '3' :
  334. if($param['dataMap']['money'] >= json_decode($vb['value'])[0]){
  335. $jump_out = 2;
  336. }
  337. break;
  338. case '4' :
  339. if($param['dataMap']['money'] < json_decode($vb['value'])[0]){
  340. $jump_out = 2;
  341. }
  342. break;
  343. case '5' :
  344. if($param['dataMap']['money'] > json_decode($vb['value'])[0]){
  345. $jump_out = 2;
  346. }
  347. break;
  348. case '6' :
  349. if(json_decode($vb['value'])[1] == 1){
  350. if(json_decode($vb['value'])[0] < $param['dataMap']['money']){
  351. $jump_out = 1;
  352. }else{
  353. $jump_out = 2;
  354. }
  355. }else{
  356. if(json_decode($vb['value'])[0] <= $param['dataMap']['money']){
  357. $jump_out = 1;
  358. }else{
  359. $jump_out = 2;
  360. }
  361. }
  362. if(json_decode($vb['value'])[2] == 1){
  363. if(json_decode($vb['value'])[3] > $param['dataMap']['money']){
  364. $jump_out = 1;
  365. }else{
  366. $jump_out = 2;
  367. }
  368. }else{
  369. if(json_decode($vb['value'])[3] >= $param['dataMap']['money']){
  370. $jump_out = 1;
  371. }else{
  372. $jump_out = 2;
  373. }
  374. }
  375. break;
  376. case '7' :
  377. break;
  378. case '8' :
  379. $group_id = db('admin_access')->where('user_id', $userInfo['id'])->column('group_id');
  380. $userList = json_decode($vb['value'])->userList;
  381. $deptList = json_decode($vb['value'])->deptList;
  382. $roleList = json_decode($vb['value'])->roleList;
  383. if(!is_array($userInfo['id'], $userList) && !in_array($userInfo['structure_id'], $deptList) && count(array_intersect($group_id, $roleList)) <= 0){
  384. $jump_out = 2;
  385. }
  386. }
  387. // 该条件不符合 跳过本条件 继续下一个条件
  388. if($jump_out == 2){
  389. break;
  390. }
  391. }
  392. // 符合条件 不需要继续走下一个条件 开始找流程 并跳出整个循环
  393. if($jump_out == 1){
  394. $flowList = db('examine_flow')
  395. ->where(['examine_id' => $param['id']])
  396. ->where(['condition_id' => $va['condition_id']])
  397. ->select();
  398. $data = $this->conditionalRecursion($flowList, $userInfo, $data, $param);
  399. break;
  400. }
  401. }
  402. }else{
  403. $where = [];
  404. switch ($value['examine_type']) {
  405. case '1' :
  406. $where['a.flow_id'] = $value['flow_id'];
  407. $userList = db('examine_flow_member')
  408. ->alias('a')
  409. ->join('admin_user b','b.id = a.user_id', 'left')
  410. ->where($where)
  411. ->field('b.realname, b.img, a.user_id')
  412. ->select();
  413. break;
  414. case '2' :
  415. $where['flow_id'] = $value['flow_id'];
  416. $superior = db('examine_flow_superior')->where($where)->find();
  417. $owner_user_id = getUserSuperior($userInfo['structure_id'], $superior['parent_level']);
  418. // 找不到主管 先是 上级主管代签 没有上级主管管理员代签(多个管理员 或签)
  419. if(!$owner_user_id){
  420. $owner_user_ids = db('examine_manager_user')->where('examine_id', $param['id'])->column('user_id');
  421. $userList = db('admin_user')->field('realname, img, id as user_id')->where(['id'=>['in', $owner_user_ids]])->select();
  422. }else{
  423. $userList = db('admin_user')->field('realname, img, id as user_id')->where(['id'=>['eq', $owner_user_id]])->select();
  424. }
  425. break;
  426. case '3' :
  427. $where['a.flow_id'] = $value['flow_id'];
  428. $userList = db('examine_flow_role')
  429. ->alias('a')
  430. ->join('admin_access b','b.group_id = a.role_id', 'left')
  431. ->join('admin_user c','b.user_id = c.id', 'left')
  432. ->where($where)
  433. ->field('c.realname, c.img, b.user_id')
  434. ->select();
  435. break;
  436. case '4' :
  437. // db('examine_flow_optional')->insertAll($examine_flow);
  438. break;
  439. case '5' :
  440. // db('examine_flow_continuous_superior')->insert($examine_flow);
  441. break;
  442. // case '7' :
  443. // break;
  444. }
  445. $value['userList'] = $userList;
  446. $data[] = $value;
  447. }
  448. }
  449. return resultArray(['data' => $data]);
  450. }
  451. public function conditionalRecursion ($examine_flow, $userInfo, $data, $param)
  452. {
  453. foreach ($examine_flow as $key => $value) {
  454. if($value['examine_type'] == 0){
  455. $condition = db('examine_condition')
  456. ->where('flow_id', $value['flow_id'])
  457. ->select();
  458. foreach ($condition as $ka => $va) {
  459. // 处理审批条件 是否符合 符合去找流程 不符合 找下一个流程
  460. $condition_data = db('examine_condition_data')->where('condition_id', $va['condition_id'])->select();
  461. foreach ($condition_data as $kb => $vb) {
  462. $jump_out = 1;
  463. // 1 等于 2 大于 3 小于 4 大于等于 5 小于等于 6 两者之间 7 包含 8 员工 9 部门 10 角色',
  464. switch ($vb['condition_type']) {
  465. case '1' :
  466. if($param['dataMap']['money'] != json_decode($vb['value'])[0]){
  467. $jump_out = 2;
  468. }
  469. break;
  470. case '2' :
  471. if($param['dataMap']['money'] <= json_decode($vb['value'])[0]){
  472. $jump_out = 2;
  473. }
  474. break;
  475. case '3' :
  476. if($param['dataMap']['money'] >= json_decode($vb['value'])[0]){
  477. $jump_out = 2;
  478. }
  479. break;
  480. case '4' :
  481. if($param['dataMap']['money'] < json_decode($vb['value'])[0]){
  482. $jump_out = 2;
  483. }
  484. break;
  485. case '5' :
  486. if($param['dataMap']['money'] > json_decode($vb['value'])[0]){
  487. $jump_out = 2;
  488. }
  489. break;
  490. case '6' :
  491. if(json_decode($vb['value'])[1] == 1){
  492. if(json_decode($vb['value'])[0] < $param['dataMap']['money']){
  493. $jump_out = 1;
  494. }else{
  495. $jump_out = 2;
  496. }
  497. }else{
  498. if(json_decode($vb['value'])[0] <= $param['dataMap']['money']){
  499. $jump_out = 1;
  500. }else{
  501. $jump_out = 2;
  502. }
  503. }
  504. if(json_decode($vb['value'])[2] == 1){
  505. if(json_decode($vb['value'])[3] > $param['dataMap']['money']){
  506. $jump_out = 1;
  507. }else{
  508. $jump_out = 2;
  509. }
  510. }else{
  511. if(json_decode($vb['value'])[3] >= $param['dataMap']['money']){
  512. $jump_out = 1;
  513. }else{
  514. $jump_out = 2;
  515. }
  516. }
  517. break;
  518. case '7' :
  519. break;
  520. case '8' :
  521. $group_id = db('admin_access')->where('user_id', $userInfo['id'])->column('group_id');
  522. $userList = json_decode($vb['value'])->userList;
  523. $deptList = json_decode($vb['value'])->deptList;
  524. $roleList = json_decode($vb['value'])->roleList;
  525. if(!is_array($userInfo['id'], $userList) && !in_array($userInfo['structure_id'], $deptList) && count(array_intersect($group_id, $roleList)) <= 0){
  526. $jump_out = 2;
  527. }
  528. }
  529. // 该条件不符合 跳过本条件 继续下一个条件
  530. if($jump_out == 2){
  531. break;
  532. }
  533. }
  534. // 符合条件 不需要继续走下一个条件 开始找流程 并跳出整个循环
  535. if($jump_out == 1){
  536. $flowList = db('examine_flow')
  537. ->where(['examine_id' => $param['id']])
  538. ->where(['condition_id' => $va['condition_id']])
  539. ->select();
  540. $data = $this->conditionalRecursion($flowList, $userInfo, $data, $param);
  541. break;
  542. }
  543. }
  544. }else{
  545. $where = [];
  546. switch ($value['examine_type']) {
  547. case '1' :
  548. $where['a.flow_id'] = $value['flow_id'];
  549. $userList = db('examine_flow_member')
  550. ->alias('a')
  551. ->join('admin_user b','b.id = a.user_id', 'left')
  552. ->where($where)
  553. ->field('b.realname, b.img, a.user_id')
  554. ->select();
  555. break;
  556. case '2' :
  557. $where['flow_id'] = $value['flow_id'];
  558. $superior = db('examine_flow_superior')->where($where)->find();
  559. $owner_user_id = getUserSuperior($userInfo['structure_id'], $superior['parent_level']);
  560. // 找不到主管 先是 上级主管代签 没有上级主管管理员代签(多个管理员 或签)
  561. if(!$owner_user_id){
  562. $owner_user_ids = db('examine_manager_user')->where('examine_id', $param['id'])->column('user_id');
  563. $userList = db('admin_user')->field('realname, img, id as user_id')->where(['id'=>['in', $owner_user_ids]])->select();
  564. }else{
  565. $userList = db('admin_user')->field('realname, img, id as user_id')->where(['id'=>['eq', $owner_user_id]])->select();
  566. }
  567. break;
  568. case '3' :
  569. $where['a.flow_id'] = $value['flow_id'];
  570. $userList = db('examine_flow_role')
  571. ->alias('a')
  572. ->join('admin_access b','b.group_id = a.role_id', 'left')
  573. ->join('admin_user c','b.user_id = c.id', 'left')
  574. ->where($where)
  575. ->field('c.realname, c.img, b.user_id')
  576. ->select();
  577. break;
  578. case '4' :
  579. // db('examine_flow_optional')->insertAll($examine_flow);
  580. break;
  581. case '5' :
  582. // db('examine_flow_continuous_superior')->insert($examine_flow);
  583. break;
  584. // case '7' :
  585. // break;
  586. }
  587. $value['userList'] = $userList;
  588. $data[] = $value;
  589. }
  590. }
  591. return $data;
  592. }
  593. }