ExamineStep.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 审批步骤
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\model;
  8. use think\Db;
  9. use app\admin\model\Common;
  10. use think\Request;
  11. use think\Validate;
  12. class ExamineStep extends Common
  13. {
  14. /**
  15. * 为了数据库的整洁,同时又不影响Model和Controller的名称
  16. * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
  17. */
  18. protected $name = 'admin_examine_step';
  19. /**
  20. * 获取有效审批步骤列表
  21. * @param flow_id 审批流程ID
  22. * @param user_id 审批申请人ID
  23. * @return
  24. */
  25. public function getDataList($flow_id)
  26. {
  27. $userModel = new \app\admin\model\User();
  28. $list = $this->where(['flow_id' => $flow_id])->order('order_id asc')->select();
  29. foreach ($list as $k=>$v) {
  30. $list[$k]['user_id_info'] = $userModel->getListByStr($v['user_id']);
  31. }
  32. return $list ? : [];
  33. }
  34. /**
  35. * 审批步骤(创建、编辑)
  36. * @param flow_id 审批流程ID
  37. * @param status 1负责人主管,2指定用户(任意一人),3指定用户(多人会签),4上一级审批人主管
  38. * @return
  39. */
  40. public function createStepData($data, $flow_id)
  41. {
  42. if (!intval($flow_id)) {
  43. $this->error = '审批流程创建失败';
  44. return false;
  45. }
  46. //处理数据
  47. $resSuccess = true;
  48. $dataStep = [];
  49. foreach ($data as $k=>$v) {
  50. if (!intval($v['status']) || (in_array($v['status'],[2,3]) && !$v['user_id'])) {
  51. $resSuccess = false;
  52. }
  53. $dataStep[$k]['relation'] = 1;
  54. if (in_array($v['status'],[2,3])) {
  55. $dataStep[$k]['user_id'] = $v['user_id'] ? arrayToString($v['user_id']) : ''; //处理user_id
  56. $dataStep[$k]['relation'] = ($v['status'] == 3) ? 1 : 2;
  57. }
  58. if ($v['step']) {
  59. $dataStep[$k]['step_id'] = $v['step'];
  60. }
  61. $dataStep[$k]['order_id'] = $k+1;
  62. $dataStep[$k]['flow_id'] = $flow_id;
  63. $dataStep[$k]['status'] = $v['status'];
  64. $dataStep[$k]['create_time'] = time();
  65. }
  66. if ($resSuccess) {
  67. //提交事务
  68. $this->startTrans();
  69. try {
  70. $this->where(['flow_id' => $flow_id])->delete();
  71. $this->saveAll($dataStep);
  72. $this->commit();
  73. return true;
  74. } catch(\Exception $e) {
  75. $this->error = '审批步骤创建失败';
  76. $this->rollback();
  77. return false;
  78. }
  79. } else {
  80. $this->error = '参数错误';
  81. return false;
  82. }
  83. }
  84. /**
  85. * 审批步骤(排序,防止位置情况造成排序错乱)
  86. * @param flow_id 审批流程ID
  87. * @return
  88. */
  89. public function orderData($flow_id)
  90. {
  91. $step_list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id')->select();
  92. foreach ($step_list as $k=>$v) {
  93. $data = [];
  94. $data = ['step_id' => $v['step_id'],'order_id' => $k];
  95. db('admin_examine_step')->update($data);
  96. }
  97. }
  98. /**
  99. * 下一审批人(审批是否结束)
  100. * @param user_id 审批申请人ID
  101. * @param flow_id 审批流ID
  102. * @param types 关联对象
  103. * @param types_id 联对象ID
  104. * @param order_id 审批排序ID
  105. * @param status 1负责人主管,2指定用户(任意一人),3指定用户(多人会签),4上一级审批人主管
  106. * @param check_user_id 当前审核人ID
  107. */
  108. public function nextStepUser($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id)
  109. {
  110. $res = nextCheckData($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id);
  111. return $res ? : [];
  112. }
  113. /**
  114. * 审批步骤权限
  115. * @param step_id 审批步骤ID
  116. * @param user_id 审批人ID(当前登录人)
  117. * @param create_user_id 申请人ID
  118. * @param types 关联对象
  119. * @param types_id 联对象ID
  120. * @param status 1负责人主管,2指定用户(任意一人),3指定用户(多人会签),4上一级审批人主管
  121. * @return
  122. */
  123. public function checkExamine($user_id, $types, $types_id)
  124. {
  125. $data = $this->getDataByTypes($types, $types_id);
  126. $dataInfo = $data['dataInfo']; //审批主体信息
  127. $stepInfo = $data['stepInfo']; //审批步骤信息
  128. if (!$dataInfo) {
  129. $this->error = '参数错误!';
  130. return false;
  131. }
  132. if (in_array($dataInfo['check_status'], ['2','3'])) {
  133. $this->error = '审批已经结束!';
  134. return false;
  135. }
  136. if ($dataInfo['flow_id'] > 0) {
  137. //固定流程
  138. //当前步骤已审批user_id
  139. $check_user_ids = $this->getUserByCheck($types, $types_id, $dataInfo['order_id']);
  140. if (in_array($user_id, $check_user_ids)) {
  141. $this->error = '您已审核,请勿重复操作!';
  142. return false;
  143. }
  144. $examine_user_id_arr = array();
  145. // $examine_user_id_arr = $this->getUserByStep($stepInfo['step_id'], $dataInfo['create_user_id']); //获取审批步骤审批人
  146. $examine_user_id_arr = $dataInfo['check_user_id']; //获取审批步骤审批人
  147. $examine_user_id_arr = stringToArray($examine_user_id_arr);
  148. } else {
  149. $examine_user_id_arr = $this->getUserByPer($types);
  150. }
  151. if (!in_array($user_id, $examine_user_id_arr)) {
  152. $this->error = '没有权限';
  153. return false;
  154. }
  155. return true;
  156. }
  157. /**
  158. * 审批对象获取审批相关信息
  159. * @param types 关联对象
  160. * @param types_id 联对象ID
  161. * @return
  162. */
  163. public function getDataByTypes($types, $types_id)
  164. {
  165. if (empty($types) || empty($types_id)) {
  166. $this->error = '参数错误';
  167. return false;
  168. }
  169. switch (trim($types)) {
  170. case 'oa_examine' : $dataInfo = db('oa_examine')->where(['examine_id' => intval($types_id)])->field('create_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  171. case 'crm_contract' : $dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  172. case 'crm_receivables' : $dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  173. case 'crm_invoice': $dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  174. case 'jxc_purchase': $dataInfo = db('jxc_purchase')->where(['purchase_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  175. case 'jxc_retreat': $dataInfo = db('jxc_retreat')->where(['retreat_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  176. case 'jxc_sale': $dataInfo = db('jxc_sale')->where(['sale_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  177. case 'jxc_salereturn': $dataInfo = db('jxc_salereturn')->where(['salereturn_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  178. case 'jxc_payment': $dataInfo = db('jxc_payment')->where(['payment_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  179. case 'jxc_collection': $dataInfo = db('jxc_collection')->where(['collection_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  180. case 'jxc_inventory': $dataInfo = db('jxc_inventory')->where(['inventory_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  181. case 'jxc_allocation': $dataInfo = db('jxc_allocation')->where(['allocation_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
  182. }
  183. $stepInfo = [];
  184. if ($dataInfo['flow_id'] && !in_array($dataInfo['check_status'],['5'])) {
  185. //固定审批流
  186. $stepInfo = db('admin_examine_step')->where(['flow_id' => $dataInfo['flow_id'],'order_id' => $dataInfo['order_id']])->find();
  187. }
  188. $data = [];
  189. $data['stepInfo'] = $stepInfo;
  190. $data['step_id'] = $stepInfo['step_id'] ? : '';
  191. $data['dataInfo'] = $dataInfo;
  192. return $data;
  193. }
  194. /**
  195. * 获取审批步骤审批人信息
  196. * @param step_id 审批步骤ID
  197. * @param status 1负责人主管,2指定用户(任意一人),3指定用户(多人会签),4上一级审批人主管
  198. * @param user_id 审批主体,申请人user_id
  199. * @return
  200. */
  201. public function getUserByStep($step_id, $user_id)
  202. {
  203. $stepInfo = db('admin_examine_step')->where(['step_id' => $step_id])->find();
  204. $examine_user_id_arr = [];
  205. //固定审批流
  206. switch ($stepInfo['status']) {
  207. case 1 :
  208. $examine_user_id = db('admin_user')->where(['id' => $user_id])->value('parent_id');
  209. if ($examine_user_id) {
  210. $examine_user_id_arr[] = $examine_user_id;
  211. } else {
  212. $examine_user_id_arr[] = 1;
  213. }
  214. break;
  215. case 2 :
  216. case 3 :$examine_user_id_arr = stringToArray($stepInfo['user_id']); break;
  217. case 4 :
  218. $order_id = $stepInfo['order_id'] ? $stepInfo['order_id']-1 : 0;
  219. $last_step_id = db('admin_examine_step')->where(['flow_id' => $stepInfo['flow_id'],'order_id' => $order_id])->value('step_id');
  220. $last_step_info = db('admin_examine_step')->where(['step_id' => $last_step_id])->find();
  221. $last_user_id = $this->getUserByStep($last_step_id, $user_id);
  222. if (count(stringToArray($last_user_id)) !== 1) {
  223. $this->error = '审批流程出错';
  224. return false;
  225. }
  226. $last_user_id_arr = stringToArray($last_user_id);
  227. $examine_user_id = $this->getUserByStep($last_step_id, $last_user_id_arr[0]);
  228. //$examine_user_id = db('admin_user')->where(['id' => $last_step_info['user_id']])->value('parent_id');
  229. $examine_user_id_arr = [];
  230. if ($examine_user_id) {
  231. $examine_user_id_arr = stringToArray($examine_user_id);
  232. }
  233. break;
  234. default : $examine_user_id_arr = [];
  235. }
  236. return array_unique($examine_user_id_arr) ? ','.implode(',',array_filter(array_unique($examine_user_id_arr))).',' : '';
  237. }
  238. /**
  239. * 获取当前步骤已审批的user_id
  240. * @param step_id 审批步骤ID
  241. * @param status 1审核通过0审核失败2撤销
  242. * @return
  243. */
  244. public function getUserByCheck($types, $types_id = 0, $order_id = 0, $status = 1)
  245. {
  246. if ($types_id == 0 && $order_id == 0) {
  247. $check_user_ids = [];
  248. } else {
  249. $check_user_ids = db('admin_examine_record')->where(['types' => $types,'types_id' => $types_id,'order_id' => $order_id,'is_end' => 0,'status' => $status])->column('check_user_id');
  250. }
  251. return $check_user_ids ? : [];
  252. }
  253. /**
  254. * 获取授权审批的user_id
  255. * @param step_id 审批步骤ID
  256. * @param
  257. * @return
  258. */
  259. public function getUserByPer($types)
  260. {
  261. if (!in_array($types,['oa_examine','crm_contract','crm_receivables'])) {
  262. $this->error = '参数错误';
  263. return false;
  264. }
  265. $userModel = new \app\admin\model\User();
  266. $adminUserId = model('User')->getAdminId(); //管理员ID
  267. //获取有审核权限的user_id
  268. switch ($types) {
  269. case 'oa_examine' : $examine_user_id_arr = $userModel->getUserByPer('oa', 'examine', 'check'); break;
  270. case 'crm_contract' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'contract', 'check'); break;
  271. case 'crm_receivables' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'receivables', 'check'); break;
  272. case 'crm_invoice' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'invoice', 'check'); break;
  273. }
  274. $examine_user_id_arr = $examine_user_id_arr ? array_merge($examine_user_id_arr, $adminUserId) : $adminUserId;
  275. return $examine_user_id_arr;
  276. }
  277. /**
  278. * 获取审批步骤相关userId
  279. * @param flow_id 流程ID
  280. * @param order_id 排序ID
  281. * @return
  282. */
  283. public function getStepUserByOrder($flow_id, $order_id, $user_id)
  284. {
  285. $user_ids = [];
  286. if ($flow_id && $order_id) {
  287. $stepInfo = db('admin_examine_step')->where(['flow_id' => $flow_id,'order_id' => $order_id])->find();
  288. $user_ids = $this->getUserByStep($stepInfo['step_id'], $user_id);
  289. }
  290. return $user_ids ? : [];
  291. }
  292. /**
  293. * 获取有效审批步骤列表(固定审批)
  294. * @param flow_id 审批流程ID
  295. * @param user_id 审批申请人ID
  296. * @param check_user_id 当前操作人ID
  297. * @return
  298. */
  299. public function getStepList($flow_id, $user_id, $types, $types_id = 0, $check_user_id = 0, $action = '', $category_id = '')
  300. {
  301. $userModel = new \app\admin\model\User();
  302. $newlist = [];
  303. $dataInfo['order_id'] = 0;
  304. if ($types_id) {
  305. $typesInfo = $this->getDataByTypes($types, $types_id);
  306. $dataInfo = $typesInfo['dataInfo'];
  307. }
  308. $is_check = 0; //审批权限(1有)
  309. $is_recheck = 0; //撤销审批权限(1有)
  310. $admin_user_ids = $userModel->getAdminId();
  311. //创建人或负责人或管理员有撤销权限
  312. //if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id || in_array($check_user_id, $admin_user_ids)) {
  313. if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) {
  314. if (!in_array($dataInfo['check_status'],['2','3','4','6'])) {
  315. $is_recheck = 1;
  316. }
  317. }
  318. if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'],['2','3','4','6'])) {
  319. $is_check = 1;
  320. }
  321. if ($action == 'view') {
  322. $createUserInfo = $userModel->getUserById($dataInfo['create_user_id']);
  323. $createUserInfo['check_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
  324. if ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id']!=trim( $dataInfo['check_status'], ',')) {
  325. $createUserInfo['check_type'] = 2;
  326. $newlist[1]['type'] = '2'; //撤销
  327. $newlist[1]['status'] = '5'; //创建,前端要求给创建人加一个status字段,定义为5
  328. $createUserInfo['check_type'] = 3;
  329. $newlist[0]['type'] = '3'; //创建
  330. $newlist[0]['status'] = '5'; //创建,前端要求给创建人加一个status字段,定义为5
  331. $newlist[0]['user_id_info'] = array($createUserInfo);
  332. $newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
  333. $newlist[1]['user_id_info'] = array($createUserInfo);
  334. $newlist[1]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
  335. } elseif ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id']==trim( $dataInfo['check_status'], ',')){
  336. $createUserInfo['check_type'] = 3;
  337. $newlist[0]['type'] = '3'; //创建
  338. $newlist[0]['status'] = '5'; //创建,前端要求给创建人加一个status字段,定义为5
  339. $createUserInfo['check_type'] = 2;
  340. $newlist[1]['type'] = '2'; //撤销
  341. $newlist[1]['status'] = '5'; //创建,前端要求给创建人加一个status字段,定义为5
  342. $newlist[0]['user_id_info'] = array($createUserInfo);
  343. $newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
  344. $newlist[1]['user_id_info'] = array($createUserInfo);
  345. $newlist[1]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
  346. } else {
  347. $createUserInfo['check_type'] = 3;
  348. $newlist[0]['type'] = '3'; //创建
  349. $newlist[0]['status'] = '5'; //创建,前端要求给创建人加一个status字段,定义为5
  350. $newlist[0]['user_id_info'] = array($createUserInfo);
  351. $newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
  352. }
  353. }
  354. $stepList = [];
  355. if ($dataInfo['check_status'] !== 4 || $action !== 'view') {
  356. $list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id asc')->select();
  357. $is_break = false;
  358. foreach ($list as $k=>$v) {
  359. $type = 4;
  360. $examine_user_ids = '';
  361. //判断步骤审批人是否存在
  362. $examine_user_ids = $this->getUserByStep($v['step_id'], $user_id);
  363. $examine_user_arr = stringToArray($examine_user_ids);
  364. if ($examine_user_arr) {
  365. $newStepInfo = $v;
  366. $user_id_info_arr = [];
  367. foreach ($examine_user_arr as $key=>$val) {
  368. $user_id_info = [];
  369. $user_id_info = $userModel->getUserById($val);
  370. $check_type = 4; //type 0失败,1通过,2撤销,3创建,4待审核,5未提交
  371. //当前步骤已审批user_id
  372. $check_user_ids = [];
  373. $check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 1);
  374. if (in_array($val, $check_user_ids)) {
  375. $check_type = 1;
  376. $type = !empty($dataInfo['check_user_id']) ? 4 : 1;
  377. }
  378. if(in_array($val, $check_user_ids) && $dataInfo['check_status'] == 2){
  379. $check_type = 1;
  380. $type = 1;
  381. }
  382. $re_check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 2); //撤销人员
  383. if ($dataInfo['check_status'] == 4) {
  384. if ($re_check_user_ids) {
  385. $is_break = true;
  386. $check_type = 2;
  387. $type = 2;
  388. }
  389. }
  390. $fail_check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 0); //拒绝人员
  391. if ($dataInfo['check_status'] == 3) {
  392. if (in_array($val,$fail_check_user_ids)) {
  393. $is_break = true;
  394. $check_type = 0;
  395. $type = 0;
  396. }
  397. //if ($action == 'view') break;
  398. }
  399. $user_id_info['check_type'] = $check_type;
  400. $check_time = '';
  401. $check_time = db('admin_examine_record')->where(['types' => $types,'types_id' => $types_id,'flow_id' => $flow_id,'order_id' => $v['order_id'],'check_user_id' => $val,'is_end' =>0])->value('check_time');
  402. $user_id_info['check_time'] = !empty($check_time) ? date('Y-m-d H:i:s', $check_time) : '';
  403. $user_id_info_arr[] = $user_id_info;
  404. }
  405. $newStepInfo['user_id'] = $examine_user_ids;
  406. $newStepInfo['user_id_info'] = $user_id_info_arr;
  407. if ($dataInfo['order_id'] > $v['order_id']) {
  408. $type = 1;
  409. }
  410. //if ($is_break !== false) break;
  411. $newStepInfo['type'] = $type;
  412. $stepList[] = $newStepInfo;
  413. }
  414. }
  415. }
  416. $newStepList = [];
  417. if ($newlist && $stepList) {
  418. $newStepList = array_merge($newlist, $stepList);
  419. } elseif ($stepList) {
  420. $newStepList = $stepList;
  421. } else {
  422. $newStepList = $newlist;
  423. }
  424. $data['steplist'] = $newStepList ? : [];
  425. $data['is_check'] = $is_check;
  426. $data['is_recheck'] = $is_recheck;
  427. return $data ? : [];
  428. }
  429. /**
  430. * 根据order_id获取审批步骤
  431. * @param flow_id 审批流程ID
  432. * @param order_id 审批排序ID
  433. * @return
  434. */
  435. public function getStepByOrder($flow_id, $order_id)
  436. {
  437. $data = db('admin_examine_step')->where(['flow_id' => $flow_id,'order_id' => $order_id])->find();
  438. return $data ? : [];
  439. }
  440. /**
  441. * 获取有效审批步骤列表(自选审批)
  442. * @param types 类型
  443. * @param types_id 类型ID
  444. * @param action 操作类型: view、save
  445. * @return
  446. */
  447. public function getPerStepList($types, $types_id, $user_id, $check_user_id, $action = '')
  448. {
  449. $examineRecordModel = new \app\admin\model\ExamineRecord();
  450. $userModel = new \app\admin\model\User();
  451. $userList = [];
  452. //有效的审批记录
  453. $where = [];
  454. $where['types'] = $types;
  455. $where['types_id'] = $types_id;
  456. $where['is_end'] = 0;
  457. $recordList = $examineRecordModel->getDataList($where);
  458. $typeInfo = $this->getDataByTypes($types, $types_id);
  459. $dataInfo = $typeInfo['dataInfo'];
  460. //type 0失败,1通过,2撤销,3创建,4待审核,5未提交
  461. $i = 0;
  462. if(empty($recordList)){
  463. $createUserInfo = $userModel->getUserById($dataInfo['create_user_id']);
  464. $userList[0]['userInfo'] = $createUserInfo;
  465. $userList[0]['type'] = 3; //创建
  466. $userList[0]['time'] = $dataInfo['update_time'] ? : '';
  467. }else{
  468. foreach ($recordList as $k=>$v) {
  469. $userList[$i]['userInfo'] = $userModel->getUserById($v['check_user_id']);
  470. $userList[$i]['type'] = $v['status'];
  471. $userList[$i]['time'] = $v['check_time'];
  472. $i++;
  473. }
  474. }
  475. if ($dataInfo['check_status'] <= 1 && $dataInfo['check_user_id']) {
  476. $check_user_id_arr = stringToArray($dataInfo['check_user_id']);
  477. $userList[$i]['userInfo'] = $userModel->getUserById($check_user_id_arr[0]);
  478. $userList[$i]['type'] = '4';
  479. }
  480. if ($dataInfo['check_status'] == 5 && $dataInfo['check_user_id']) {
  481. $userList = [];
  482. $check_user_id_arr = stringToArray($dataInfo['check_user_id']);
  483. $userList[0]['userInfo'] = $userModel->getUserById($check_user_id_arr[0]);
  484. $userList[0]['type'] = '5';
  485. }
  486. $is_check = 0; //审批权限(1有)
  487. $is_recheck = 0; //撤销审批权限(1有)
  488. $admin_user_ids = $userModel->getAdminId();
  489. //创建人或负责人或管理员有撤销权限
  490. // if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id || in_array($check_user_id, $admin_user_ids)) {
  491. if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) {
  492. if (!in_array($dataInfo['check_status'],['2','3','4','5','6'])) {
  493. $is_recheck = 1;
  494. }
  495. }
  496. if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'],['2','3','4','5','6'])) {
  497. $is_check = 1;
  498. }
  499. $data['steplist'] = $userList;
  500. $data['is_check'] = $is_check;
  501. $data['is_recheck'] = $is_recheck;
  502. return $data ? : [];
  503. }
  504. }