ApproveService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <?php
  2. namespace app\common\service;
  3. use app\common\constant\ApplyConstant;
  4. use app\common\constant\CommonConstant;
  5. use app\common\model\Approve;
  6. use app\common\model\ApproveApplyGoods;
  7. use app\common\model\ApproveCopy;
  8. use app\common\model\ApproveEvectionPeerUser;
  9. use app\common\model\ApproveInfo;
  10. use app\common\model\ApproveInfoLog;
  11. use app\common\model\ApproveMaintain;
  12. use app\common\model\ApproveStockGoods;
  13. use app\common\model\ApproveUseGoods;
  14. use app\common\model\GoodsStock;
  15. use app\common\model\GoodsStockLog;
  16. use app\common\model\User;
  17. use think\cache\driver\Redis;
  18. use think\Db;
  19. use think\Exception;
  20. /**
  21. * 审批服务类
  22. */
  23. class ApproveService
  24. {
  25. /**
  26. * 审批待处理统计
  27. *
  28. * @param mixed $user 用户信息
  29. **/
  30. public static function get_count(User $user)
  31. {
  32. $get_module_list = CommonConstant::get_module_list();
  33. $modules = array_keys($get_module_list);
  34. $userid = $user['userid'];
  35. $ids = Approve::where('status', CommonConstant::STATUS_2)
  36. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  37. ->where('approve_user', $userid)
  38. ->column('info_id');
  39. $key = [];
  40. if ($ids) {
  41. $list = ApproveInfo::field('module,count(id) as number')
  42. ->where('id', 'in', $ids)
  43. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  44. ->where('module', 'in', $modules)
  45. ->where('status', CommonConstant::STATUS_2)
  46. ->group('module')
  47. ->select()
  48. ->toArray();
  49. $key = $list ? array_column($list, null, 'module') : [];
  50. }
  51. $data = [];
  52. foreach ($get_module_list as $module => $value) {
  53. $module_text = $value;
  54. $number = 0;
  55. if (array_key_exists($module, $key)) {
  56. $number = $key[$module]['number'];
  57. }
  58. $params = compact('module', "module_text", 'number');
  59. $data[] = $params;
  60. }
  61. return $data;
  62. }
  63. /**
  64. * 审批列表
  65. *
  66. * @param integer $status 处理状态
  67. * @param integer $module 模块类型
  68. * @param string $start_time 申请开始时间
  69. * @param string $end_time 申请结束时间
  70. * @param string $search 搜索
  71. * @param integer $offset 起始位置
  72. * @param integer $length 查询数量
  73. * @param mixed $user 用户信息
  74. **/
  75. public static function get_list($status, $module, $start_time, $end_time, $search, $offset, $length, $user)
  76. {
  77. if (!in_array($status, [1, 2, 3])) {
  78. return [];
  79. }
  80. if ($module && !array_key_exists($module, CommonConstant::get_module_list())) {
  81. return [];
  82. }
  83. $userids = $search && !is_numeric($search) ? User::where('name', 'like', '%' . $search . '%')->column('userid') : [];
  84. $userid = $user['userid'];
  85. $group = $status == 3 ? 'approve_copy' : 'approve';
  86. if ($group == 'approve') {
  87. $model = Approve::class;
  88. $field = 'id as approve_id,info_id,status,create_at';
  89. } else {
  90. $model = ApproveCopy::class;
  91. $field = 'id as approve_id,info_id,create_at';
  92. }
  93. $aliasName = 'approve.';
  94. $jobName = 'approveInfo.';
  95. $joinField = 'module,user_id,apply_user_id,order_no,apply_date,reason,type,desc,start_time,end_time';
  96. $field = CommonService::getAliasField($field, $aliasName);
  97. $joinField = CommonService::getAliasField($joinField, $jobName);
  98. $field = implode(',', array_merge($field, $joinField));
  99. $list = $model::alias('approve')
  100. ->field($field)
  101. ->when($status, function ($query) use ($aliasName, $status) {
  102. if ($status == 1) {
  103. $query->where($aliasName . 'status', CommonConstant::STATUS_2);
  104. // $query->where($aliasName . 'status', 'in', [CommonConstant::STATUS_1, CommonConstant::STATUS_2]);
  105. }
  106. if ($status == 2) {
  107. $query->where($aliasName . 'status', 'in', [CommonConstant::STATUS_3, CommonConstant::STATUS_4]);
  108. }
  109. })
  110. ->where($aliasName . 'is_deleted', CommonConstant::IS_DELETED_0)
  111. ->when($group, function ($query) use ($aliasName, $group) {
  112. if ($group == 'approve') {
  113. $query->where($aliasName . 'group', CommonConstant::IS_WHO_0);
  114. }
  115. })
  116. ->when($group, function ($query) use ($aliasName, $group) {
  117. if ($group == 'approve') {
  118. $query->where($aliasName . 'state', CommonConstant::IS_WHO_0);
  119. }
  120. })
  121. ->where($aliasName . 'approve_user', $userid)
  122. ->where($jobName . 'is_deleted', CommonConstant::IS_DELETED_0)
  123. ->when($module, function ($query) use ($jobName, $module) {
  124. $query->where($jobName . 'module', 'in', $module);
  125. })
  126. ->when(!empty($start_time) && !empty($end_time), function ($query) use ($aliasName, $start_time, $end_time) {
  127. $query->where($aliasName . 'create_at', 'BETWEEN', [$start_time, $end_time]);
  128. })
  129. ->when($userids, function ($query) use ($jobName, $userids) {
  130. $query->where($jobName . 'user_id', 'in', $userids);
  131. })
  132. ->when($search, function ($query) use ($search, $userids) {
  133. if (!$userids) {
  134. if (!is_numeric($search)) {
  135. $query->where('order_no|reason', 'like', '%' . $search . '%');
  136. } else {
  137. $query->where('order_no', 'like', '%' . $search . '%');
  138. }
  139. }
  140. })
  141. ->join('__APPROVE_INFO__ approveInfo', 'approve.info_id = approveInfo.id', 'INNER');
  142. if ($status == 1) {
  143. // 待处理(待审批 审批中) 才关联 审批人信息
  144. $list->with([
  145. 'approveInfoUser' => function ($query) {
  146. $query->field('userid,name');
  147. },
  148. 'approveOne' => function ($query) {
  149. $query->field('id,info_id,status,approve_user')
  150. ->where('status', CommonConstant::STATUS_2)
  151. ->where('group', CommonConstant::IS_WHO_0)
  152. ->where('state', CommonConstant::IS_WHO_0)
  153. ->with([
  154. 'user' => function ($query) {
  155. $query->field('userid,name');
  156. }
  157. ]);
  158. }
  159. ]);
  160. } else {
  161. $list->with([
  162. 'approveInfoUser' => function ($query) {
  163. $query->field('userid,name');
  164. }
  165. ]);
  166. }
  167. $list = $list->order('approve_id desc')
  168. ->limit($offset, $length)
  169. ->select();
  170. return self::get_array($list);
  171. }
  172. public static function get_array($list)
  173. {
  174. $apply_goods_info_ids = [];
  175. $stock_goods_info_ids = [];
  176. $use_goods_info_ids = [];
  177. $peer_user_info_ids = [];
  178. $apply_goods_list = [];
  179. $stock_goods_list = [];
  180. $use_goods_list = [];
  181. $peer_user_list = [];
  182. foreach ($list as $value) {
  183. $module = $value['module'];
  184. switch ($module) {
  185. case CommonConstant::MODULE_1:
  186. if ($value['type'] == ApplyConstant::TYPE_1) {
  187. $apply_goods_info_ids[] = $value['info_id'];
  188. }
  189. break;
  190. case CommonConstant::MODULE_3:
  191. $stock_goods_info_ids[] = $value['info_id'];
  192. break;
  193. case CommonConstant::MODULE_4:
  194. $use_goods_info_ids[] = $value['info_id'];
  195. break;
  196. case CommonConstant::MODULE_5:
  197. $peer_user_info_ids[] = $value['info_id'];
  198. break;
  199. }
  200. }
  201. if ($apply_goods_info_ids) {
  202. $apply_goods_list = ApproveApplyGoods::field('id,info_id,goods_name')
  203. ->where('info_id', 'in', $apply_goods_info_ids)
  204. ->select()
  205. ->toArray();
  206. }
  207. if ($stock_goods_info_ids) {
  208. $stock_goods_list = ApproveStockGoods::field('id,info_id,goods_name')
  209. ->where('info_id', 'in', $stock_goods_info_ids)
  210. ->select()
  211. ->toArray();
  212. }
  213. if ($use_goods_info_ids) {
  214. $use_goods_list = ApproveUseGoods::field('id,info_id,goods_name')
  215. ->where('info_id', 'in', $use_goods_info_ids)
  216. ->select()
  217. ->toArray();
  218. }
  219. if ($peer_user_info_ids) {
  220. $peer_user_list = ApproveEvectionPeerUser::field('id,info_id,name')
  221. ->where('info_id', 'in', $peer_user_info_ids)
  222. ->select()
  223. ->toArray();
  224. }
  225. foreach ($list as $value) {
  226. $module = $value['module'];
  227. $apply_goods = [];
  228. $stock_goods = [];
  229. $use_goods = [];
  230. $peer_user = [];
  231. switch ($module) {
  232. case CommonConstant::MODULE_1:
  233. if ($value['type'] == ApplyConstant::TYPE_1) {
  234. foreach ($apply_goods_list as $val) {
  235. if ($value['info_id'] == $val['info_id']) {
  236. $apply_goods[] = $val;
  237. }
  238. }
  239. }
  240. break;
  241. case CommonConstant::MODULE_3:
  242. foreach ($stock_goods_list as $val) {
  243. if ($value['info_id'] == $val['info_id']) {
  244. $stock_goods[] = $val;
  245. }
  246. }
  247. break;
  248. case CommonConstant::MODULE_4:
  249. foreach ($use_goods_list as $val) {
  250. if ($value['info_id'] == $val['info_id']) {
  251. $use_goods[] = $val;
  252. }
  253. }
  254. break;
  255. case CommonConstant::MODULE_5:
  256. foreach ($peer_user_list as $val) {
  257. if ($value['info_id'] == $val['info_id']) {
  258. $peer_user[] = $val;
  259. }
  260. }
  261. break;
  262. }
  263. $value['apply_goods'] = $apply_goods;
  264. $value['stock_goods'] = $stock_goods;
  265. $value['use_goods'] = $use_goods;
  266. $value['peer_user'] = $peer_user;
  267. }
  268. return $list;
  269. // $info_ids = [];
  270. // foreach ($list as $value){
  271. // if($value['status'] == CommonConstant::STATUS_1) {
  272. // $info_ids[] = $value['info_id'];
  273. // }
  274. // }
  275. // if($info_ids){
  276. // $approve_one_list = Approve::field('id,info_id,status,approve_user')
  277. // ->where('info_id','in',$info_ids)
  278. // ->where('status',CommonConstant::STATUS_2)
  279. // ->where('is_deleted', CommonConstant::IS_DELETED_0)
  280. // ->with(['user' => function ($query) {
  281. // $query->field('userid,name');
  282. // }])
  283. // ->select();
  284. // $approve_one_data = array_column($approve_one_list, null, 'info_id');
  285. // foreach ($list as $val){
  286. // if(array_key_exists($val['info_id'],$approve_one_data)){
  287. // $val['approve_one'] = $approve_one_data[$val['info_id']];
  288. // }
  289. // }
  290. // }
  291. }
  292. /**
  293. * 详情
  294. *
  295. * @param integer $id 审批ID
  296. * @param mixed $user 用户信息
  297. * @param string $group 类别:approve=审批,approve_copy=审批抄送
  298. * @param string $type 类型:detail=详情,info=信息
  299. **/
  300. public static function get_detail($id, $user, $group, $type)
  301. {
  302. $userid = $user['userid'];
  303. if ($group == 'approve') {
  304. $model = Approve::class;
  305. $field = 'id,info_id,status';
  306. } else {
  307. $model = ApproveCopy::class;
  308. $field = 'id,info_id';
  309. }
  310. $info = $model::field($field)
  311. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  312. ->when($group, function ($query) use ($group) {
  313. if ($group == 'approve') {
  314. $query->where('group', CommonConstant::IS_WHO_0);
  315. }
  316. })
  317. ->when($group, function ($query) use ($group) {
  318. if ($group == 'approve') {
  319. $query->where('state', CommonConstant::IS_WHO_0);
  320. }
  321. })
  322. ->where('approve_user', $userid)
  323. ->find($id);
  324. $data = [];
  325. $is_maintain = false;
  326. $is_feedback = false;
  327. if ($info) {
  328. $data = ApproveInfoService::get_detail($info['info_id'], $user, CommonConstant::IS_WHO_0, $type);
  329. if ($data) {
  330. $data['approve_id'] = $id;
  331. $data['approve_status'] = isset($info['status']) ? $info['status'] : CommonConstant::STATUS_1;
  332. if ($group == 'approve') {
  333. // 条件:维修模块 审批的审批状态是审批中 用户是物业主管或信息负责人 是否显示维修人员:false=不显示,true=显示 目的:审批
  334. // 条件:维修模块 审批申请的审批状态是审批同意 用户是物业主管或信息负责人 反馈状态 是否显示上传反馈结果:false=不显示,true=显示 目的:上传反馈结果
  335. if ($data['module'] == CommonConstant::MODULE_8) {
  336. if ($data['approve_status'] == CommonConstant::STATUS_2) {
  337. $is_maintain = CommonService::isMaintain($user);
  338. }
  339. if ($data['status'] == CommonConstant::STATUS_3) {
  340. // if (CommonService::isMaintain($user) && $data['maintain_user_id'] > 0 && $data['module_info']['feedback_status'] == CommonConstant::IS_WHO_0) {
  341. if (CommonService::isMaintain($user) && $data['module_info']['feedback_status'] == CommonConstant::IS_WHO_0) {
  342. $is_feedback = true;
  343. }
  344. }
  345. }
  346. }
  347. $data['is_maintain'] = $is_maintain;
  348. $data['is_feedback'] = $is_feedback;
  349. }
  350. }
  351. return $data;
  352. }
  353. /**
  354. * 操作方法
  355. *
  356. * @param integer $id 审批ID
  357. * @param array $params 数组
  358. * @param mixed $user 用户信息
  359. * @param string $type 类型:audit=审批,edit=修改,feedback=上传反馈结果
  360. **/
  361. public static function make($id, $params, $user, $type)
  362. {
  363. $userid = $user['userid'];
  364. $approve = Approve::field('id,info_id,status,approve_user,approve_flow,approve_time')
  365. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  366. ->where('group', CommonConstant::IS_WHO_0)
  367. ->where('state', CommonConstant::IS_WHO_0)
  368. ->where('approve_user', $userid)
  369. ->with([
  370. 'approveInfo' => function ($query) {
  371. $query->field('is_deleted', true);
  372. }
  373. ])
  374. ->find($id);
  375. switch ($type) {
  376. case 'audit':
  377. if (!$approve) {
  378. except('审批记录不存在或已删除');
  379. }
  380. if ($approve->status != CommonConstant::STATUS_2) {
  381. except('非待处理状态无法操作');
  382. }
  383. $info = $approve->approve_info;
  384. if (!$info) {
  385. except('申请记录不存在或已删除');
  386. }
  387. if ($info->status != CommonConstant::STATUS_2) {
  388. except('非待处理状态无法操作!');
  389. }
  390. self::audit($approve, $info, $params, $user);
  391. break;
  392. case 'edit':
  393. if (!$approve) {
  394. except('审批记录不存在或已删除');
  395. }
  396. if ($approve->status != CommonConstant::STATUS_2) {
  397. except('非待处理状态无法操作');
  398. }
  399. $info = $approve->approve_info;
  400. if (!$info) {
  401. except('申请记录不存在或已删除');
  402. }
  403. if ($info->status != CommonConstant::STATUS_2) {
  404. except('非待处理状态无法操作!');
  405. }
  406. $info->module_info;
  407. if (!$info->module_info) {
  408. except(CommonConstant::get_module_list()[$params['module']] . '记录不存在或已删除');
  409. }
  410. self::edit($approve, $info, $params);
  411. break;
  412. case 'feedback':
  413. if (!$approve) {
  414. except('审批记录不存在或已删除');
  415. }
  416. if ($approve->status != CommonConstant::STATUS_3) {
  417. except('非审批同意状态无法操作');
  418. }
  419. $info = $approve->approve_info;
  420. if (!$info) {
  421. except('申请记录不存在或已删除');
  422. }
  423. if ($info->status != CommonConstant::STATUS_3) {
  424. except('非审批同意状态无法操作!');
  425. }
  426. if ($info->module != CommonConstant::MODULE_8) {
  427. except(CommonConstant::get_module_list()[CommonConstant::MODULE_8] . '记录不存在或已删除');
  428. }
  429. $is_maintain = CommonService::isMaintain($user);
  430. if (!$is_maintain) {
  431. except('您没有权限操作');
  432. }
  433. // TODO 没有判断反馈状态
  434. try {
  435. // 更新维修信息
  436. $params['maintain_user_id'] = $info->maintain_user_id;
  437. $params['feedback_status'] = CommonConstant::IS_WHO_1;
  438. ApproveMaintain::where('info_id', $info->id)->update($params);
  439. } catch (Exception $e) {
  440. except('出现错误:' . $e->getMessage());
  441. }
  442. break;
  443. }
  444. return true;
  445. }
  446. /**
  447. * 审批
  448. *
  449. * @param mixed $approve 审批信息
  450. * @param mixed $info 申请信息
  451. * @param array $params 数组
  452. * @param mixed $user 用户信息
  453. **/
  454. public static function audit($approve, $info, $params, $user)
  455. {
  456. $status = $params['status'];
  457. $remark = $params['remark'];
  458. $maintain_user_id = $params['maintain_user_id'];
  459. $approve_time = date('Y-m-d H:i:s');
  460. $duration = time() - strtotime($approve['approve_time']);
  461. $module = $info->module;
  462. $goodsStockSave = [];
  463. $goodsStockLog = [];
  464. $redisStock = [];
  465. if ($module == CommonConstant::MODULE_4) {
  466. // 4=领用申请
  467. $goods = $info->use_goods;
  468. if (!$goods->toArray()) {
  469. except('领用商品不存在');
  470. }
  471. if ($status == CommonConstant::STATUS_3) {
  472. if ($approve['approve_flow'] < $info['approve_num']) {
  473. } else {
  474. list($goodsStockSave,$goodsStockLog,$redisStock) = ApproveInfoService::composition_data($goods->toArray(),CommonConstant::MODULE_4,CommonConstant::STATUS_3);
  475. }
  476. }
  477. if ($status == CommonConstant::STATUS_4) {
  478. list($goodsStockSave,$goodsStockLog,$redisStock) = ApproveInfoService::composition_data($goods->toArray(),CommonConstant::MODULE_4,CommonConstant::STATUS_4);
  479. }
  480. }
  481. if ($module == CommonConstant::MODULE_3 && $status == CommonConstant::STATUS_3) {
  482. // 3=入库申请
  483. $goods = $info->stock_goods;
  484. if (!$goods->toArray()) {
  485. except('入库商品不存在');
  486. }
  487. if ($approve['approve_flow'] < $info['approve_num']) {
  488. } else{
  489. list($goodsStockSave,$goodsStockLog,$redisStock) = ApproveInfoService::composition_data($goods->toArray(),CommonConstant::MODULE_3,CommonConstant::STATUS_3);
  490. }
  491. }
  492. if ($module == CommonConstant::MODULE_8 && $status == CommonConstant::STATUS_3) {
  493. // 8=维修申请
  494. $is_maintain = CommonService::isMaintain($user);
  495. if ($is_maintain && !$maintain_user_id) {
  496. except('请选择维修人员');
  497. }
  498. // 维修人员ID
  499. if ($maintain_user_id > 0) {
  500. $info->maintain_user_id = $maintain_user_id;
  501. }
  502. }
  503. Db::startTrans();
  504. try {
  505. if ($goodsStockSave) {
  506. // 批量更新商品库存
  507. (new GoodsStock)->saveAll($goodsStockSave);
  508. }
  509. if ($goodsStockLog) {
  510. // 批量添加商品入库出库记录
  511. GoodsStockLog::insertAll($goodsStockLog);
  512. }
  513. // 更新审批申请
  514. if ($status == CommonConstant::STATUS_3) {
  515. // 审批流程批次小于审批次数 更新下一级审批状态
  516. if ($approve['approve_flow'] < $info['approve_num']) {
  517. Approve::where(['info_id' => $approve['info_id'], 'approve_flow' => $approve['approve_flow'] + 1])->update(['status' => CommonConstant::STATUS_2, 'approve_time' => $approve_time]);
  518. } else {
  519. // 审批通过
  520. $info->status = $status;
  521. }
  522. }
  523. if ($status == CommonConstant::STATUS_4) {
  524. // 审批驳回
  525. $info->status = $status;
  526. }
  527. $info->cur_num = $info['cur_num'] + 1;
  528. $info->save();
  529. // 更新审批
  530. $approve->status = $status;
  531. $approve->approve_time = $approve_time;
  532. $approve->remark = $remark;
  533. $approve->time = $duration;
  534. $approve->time_text = get_stay_time($duration);
  535. $approve->save();
  536. Db::commit();
  537. } catch (Exception $e) {
  538. except('出现错误:' . $e->getMessage(), 2, $e);
  539. }
  540. // 4=领用申请 扣除冻结库存
  541. if ($module == CommonConstant::MODULE_4) {
  542. if($redisStock){
  543. // 库存缓存记录
  544. $redis = new Redis(config('redis.'));
  545. foreach ($redisStock as $key=>$val){
  546. $redis->dec($val['id'], $val['stock']);
  547. }
  548. }
  549. }
  550. return true;
  551. }
  552. /**
  553. * 修改
  554. *
  555. * @param mixed $approve 审批信息
  556. * @param mixed $info 申请信息
  557. * @param array $params 数组
  558. **/
  559. public static function edit($approve, $info, $params)
  560. {
  561. $copy_user = $params['copy_user'] ? explode(',', $params['copy_user']) : [];
  562. $data = [
  563. 'reason' => $params['reason'],
  564. 'type' => $params['type'],
  565. 'desc' => $params['desc'],
  566. 'start_time' => $params['module'] == CommonConstant::MODULE_6 ? $params['start_time'] . ' ' . $params['start_am'] : $params['start_time'],
  567. 'end_time' => $params['module'] == CommonConstant::MODULE_6 ? $params['end_time'] . ' ' . $params['end_am'] : $params['end_time'],
  568. 'apply_id' => $params['apply_id'],
  569. ];
  570. Db::startTrans();
  571. try {
  572. // 编辑对应模块
  573. $module = $params['module'];
  574. $result = ApproveInfoService::create_module($module, $params, $info->id, $info, 'update');
  575. // 编辑抄送人
  576. ApproveInfoService::create_approve_copy($copy_user, $info->id, 'update');
  577. // 编辑审批申请
  578. if ($module == CommonConstant::MODULE_9) {
  579. // 9=合同呈批 不编辑合同编号
  580. unset($data['reason']);
  581. }
  582. $info->save($data);
  583. // 保存修改记录
  584. self::create_approve_info_log($approve, $info, $result);
  585. Db::commit();
  586. } catch (Exception $e) {
  587. except('出现错误:' . $e->getMessage(), 2, $e);
  588. }
  589. return true;
  590. }
  591. /**
  592. * 保存修改记录
  593. *
  594. * @param mixed $approve 审批信息
  595. * @param mixed $info 申请信息
  596. * @param array $params 数组
  597. **/
  598. public static function create_approve_info_log($approve, $info, $params)
  599. {
  600. $info['module_info'] = $params['module_info'];
  601. $info['other'] = $params['other'] ? $params['other']['data'] : [];
  602. $data = [
  603. 'info_id' => $info->id,
  604. 'user_id' => $approve->approve_user,
  605. 'data' => json_encode($info, JSON_UNESCAPED_UNICODE),
  606. ];
  607. ApproveInfoLog::create($data);
  608. return true;
  609. }
  610. }