ApproveInfoService.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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\ApproveCopy;
  7. use app\common\model\ApproveApplyGoods;
  8. use app\common\model\ApproveMaintain;
  9. use app\common\model\ApproveMaintainUserLog;
  10. use app\common\model\ApproveStockGoods;
  11. use app\common\model\ApproveEvectionPeerUser;
  12. use app\common\model\ApproveInfo;
  13. use app\common\model\ApproveUseGoods;
  14. use app\common\model\Goods;
  15. use app\common\model\GoodsCategory;
  16. use app\common\model\GoodsStock;
  17. use app\common\model\User;
  18. use think\cache\driver\Redis;
  19. use think\Db;
  20. use think\Exception;
  21. /**
  22. * 审批申请服务类
  23. */
  24. class ApproveInfoService
  25. {
  26. /**
  27. * 申请/重新发起
  28. *
  29. * @param integer $id 申请ID
  30. * @param integer $module 模块类型
  31. * @param array $params
  32. * @param mixed $user 用户信息
  33. * @param string $way 方式:create=申请,update=重新发起
  34. **/
  35. public static function create($id, $module, $params, $user, $way)
  36. {
  37. $userid = $user['userid'];
  38. $apply_user_id = $userid;
  39. $department = $user['department'];
  40. // 5=出差申请,6=请假申请,7=用车申请 申请人信息 提交人和申请人不是同一人
  41. if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
  42. if($userid != $params['apply_user_id']){
  43. $apply_user = User::field('userid,department')
  44. ->where('userid', $params['apply_user_id'])
  45. ->find();
  46. if (!$apply_user) {
  47. except('申请人信息不存在或已删除');
  48. }
  49. $apply_user_id = $apply_user['userid'];
  50. $department = $apply_user['department'];
  51. }
  52. }
  53. // 重新发起
  54. if ($id > 0) {
  55. $info = ApproveInfo::field('is_deleted', true)
  56. ->where('module', $module)
  57. ->where('user_id', $userid)
  58. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  59. ->with([
  60. 'moduleInfo'
  61. ])
  62. ->find($id);
  63. if (!$info) {
  64. except('申请记录不存在或已删除');
  65. }
  66. if (!$info->module_info) {
  67. except(CommonConstant::get_module_list()[$module] . '记录不存在或已删除');
  68. }
  69. if ($info->status != CommonConstant::STATUS_4) {
  70. except('非审批驳回状态无法操作');
  71. }
  72. } else {
  73. // 3=入库申请,9=合同呈批申请
  74. if (in_array($module, [CommonConstant::MODULE_3, CommonConstant::MODULE_9])) {
  75. // 存在申购申请单 判断申购申请单
  76. if ($params['apply_id'] > 0) {
  77. $apply = ApproveInfo::field('id')
  78. ->where('module', CommonConstant::MODULE_1)
  79. ->where('status', CommonConstant::STATUS_3)
  80. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  81. ->find($id);
  82. if (!$apply) {
  83. except('申购申请单不存在或已删除');
  84. }
  85. }
  86. }
  87. }
  88. $order_no = get_order_sn($user['id']);
  89. $approve_user = $params['approve_user'] ? explode(',', $params['approve_user']) : [];
  90. $copy_user = $params['copy_user'] ? explode(',', $params['copy_user']) : [];
  91. $approve_num = $approve_user ? count($approve_user) : 0;
  92. $data = [
  93. 'module' => $module,
  94. 'user_id' => $userid,
  95. 'apply_user_id' => $apply_user_id,
  96. 'department' => $department,
  97. 'status' => CommonConstant::STATUS_2,
  98. 'approve_num' => $approve_num,
  99. 'cur_num' => 0,
  100. 'order_no' => $order_no,
  101. 'apply_date' => date("Y-m-d"),
  102. 'reason' => $params['reason'],
  103. 'type' => $params['type'],
  104. 'desc' => $params['desc'],
  105. 'start_time' => $module == CommonConstant::MODULE_6 ? $params['start_time'] . ' ' . $params['start_am'] : $params['start_time'],
  106. 'end_time' => $module == CommonConstant::MODULE_6 ? $params['end_time'] . ' ' . $params['end_am'] : $params['end_time'],
  107. 'apply_id' => $params['apply_id'],
  108. 'maintain_user_id' => 0,
  109. ];
  110. Db::startTrans();
  111. try {
  112. if ($id > 0) {
  113. // 编辑对应模块
  114. $result = self::create_module($module, $params, $id, $info, 'update');
  115. // 编辑审批抄送
  116. self::create_approve($approve_user, $copy_user, $userid, $id, 'update');
  117. // 编辑审批申请
  118. if ($module == CommonConstant::MODULE_9) {
  119. unset($data['reason']);
  120. }
  121. unset($data['order_no']);
  122. $save_data = [
  123. 'create_at' => date('Y-m-d H:i:s'),
  124. ];
  125. $data = array_merge($data, $save_data);
  126. $info->save($data);
  127. } else {
  128. // 添加审批申请
  129. $info = ApproveInfo::create($data);
  130. $info_id = $info->id;
  131. // 添加对应模块
  132. $result = self::create_module($module, $params, $info_id, [], 'create');
  133. $info->module_id = $result['module_id'];
  134. $info->save();
  135. // 添加审批抄送
  136. self::create_approve($approve_user, $copy_user, $userid, $info_id, 'create');
  137. }
  138. user_log('approve',json_encode($result,JSON_UNESCAPED_UNICODE));
  139. Db::commit();
  140. } catch (Exception $e) {
  141. Db::rollback();
  142. // except('出现错误:' . $e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
  143. except('出现错误:' . $e->getMessage());
  144. }
  145. // 4=领用申请 冻结库存
  146. if ($module == CommonConstant::MODULE_4) {
  147. $goodsStockSave = [];
  148. $redis_stock = [];
  149. foreach ($result['other']['data'] as $key=>$val){
  150. foreach ($val['goods_stock'] as $k => $v) {
  151. $goodsStockSave[] = [
  152. 'id' => $v['id'],
  153. 'stock' => ['dec', $v['stock']],
  154. 'freeze_stock' => ['inc', $v['stock']],
  155. ];
  156. $redis_stock[] = [
  157. 'id'=>'dingtalk_stock_'.$val['info_id'].'_'.$v['goods_id'].'_'.$v['id'],
  158. 'stock'=>$v['stock'],
  159. ];
  160. }
  161. }
  162. if ($goodsStockSave) {
  163. (new GoodsStock)->saveAll($goodsStockSave);
  164. $redis = new Redis(config('redis.'));
  165. foreach ($redis_stock as $key=>$val){
  166. $redis->inc($val['id'], $val['stock']);
  167. }
  168. }
  169. }
  170. if ($way == CommonConstant::create) {
  171. // 9=合同呈批申请 生成合同编号
  172. if ($module == CommonConstant::MODULE_9) {
  173. $contract_no = CommonService::get_contract_no($params['type']);
  174. $info->save(['reason' => $contract_no]);
  175. }
  176. }
  177. return true;
  178. }
  179. /**
  180. * 添加对应模块
  181. *
  182. * @param integer $module 模块类型
  183. * @param array $params
  184. * @param integer $info_id 申请ID
  185. * @param mixed $info 申请信息
  186. * @param string $type 类型:create=申请,update=重新发起
  187. * @return array {"module_id":"3","module_info":{"info_id":"97","reason":"联想显示屏","document":"https:\/\/dingding.hdlkeji.com\/upload\/20240105\/202401051706366597c69c8800d.jpeg","remark":"领用电脑显示屏"},"other":{"total_amount":"0.00","data":[{"info_id":"97","goods_id":50,"goods_category_first":49,"goods_category_id":50,"goods_no":"jx105","goods_name":"联想 S22E","goods_brand":"联想","total_price":"0.00","goods_stock":[{"id":98,"goods_id":50,"name":"S22E","price":0,"stock":"10"}]}]}}
  188. **/
  189. public static function create_module($module, $params, $info_id, $info, $type)
  190. {
  191. $other = [];
  192. switch ($module) {
  193. case CommonConstant::MODULE_1:
  194. // 添加申购物品
  195. $total_amount = 0;
  196. if ($params['type'] == ApplyConstant::TYPE_1) {
  197. $other = self::create_goods($info_id, $module, $params['apply_goods'], $type);
  198. $total_amount = $other['total_amount'];
  199. }
  200. $data['info_id'] = $info_id;
  201. $data['reason'] = $params['reason'];
  202. $data['type'] = $params['type'];
  203. $data['total_amount'] = $params['total_amount']; // $total_amount
  204. $data['start_time'] = $params['start_time'];
  205. $data['document'] = $params['document'];
  206. $data['images'] = $params['images'];
  207. $data['pay_type'] = $params['pay_type'];
  208. break;
  209. case CommonConstant::MODULE_2:
  210. $data['info_id'] = $info_id;
  211. $data['type'] = $params['type'];
  212. $data['word_size'] = $params['word_size'];
  213. $data['desc'] = $params['desc'];
  214. $data['number'] = $params['number'];
  215. $data['reason'] = $params['reason'];
  216. $data['remark'] = $params['remark'];
  217. $data['document'] = $params['document'];
  218. break;
  219. case CommonConstant::MODULE_3:
  220. // 添加入库物品
  221. $other = self::create_goods($info_id, $module, $params['stock_goods'], $type);
  222. $data['info_id'] = $info_id;
  223. $data['total_amount'] = $other['total_amount'];
  224. $data['document'] = $params['document'];
  225. $data['images'] = $params['images'];
  226. $data['remark'] = $params['remark'];
  227. break;
  228. case CommonConstant::MODULE_4:
  229. // 添加领用物品
  230. $other = self::create_goods($info_id, $module, $params['use_goods'], $type);
  231. $data['info_id'] = $info_id;
  232. $data['reason'] = $params['reason'];
  233. $data['document'] = $params['document'];
  234. $data['remark'] = $params['remark'];
  235. break;
  236. case CommonConstant::MODULE_5:
  237. // 添加同行人员
  238. $other = self::create_peer_user($info_id, $params['peer_user'], $type);
  239. $data['info_id'] = $info_id;
  240. $data['reason'] = $params['reason'];
  241. $data['start_time'] = $params['start_time'];
  242. $data['end_time'] = $params['end_time'];
  243. $data['document'] = $params['document'];
  244. $data['images'] = $params['images'];
  245. $data['type'] = $params['type'];
  246. $data['is_who'] = $params['is_who'];
  247. $data['remark'] = $params['remark'];
  248. break;
  249. case CommonConstant::MODULE_6:
  250. $data['info_id'] = $info_id;
  251. $data['type'] = $params['type'];
  252. $data['start_time'] = $params['start_time'];
  253. $data['end_time'] = $params['end_time'];
  254. $data['start_am'] = $params['start_am'];
  255. $data['end_am'] = $params['end_am'];
  256. $data['time'] = $params['time'];
  257. $data['reason'] = $params['reason'];
  258. $data['document'] = $params['document'];
  259. $data['remark'] = $params['remark'];
  260. break;
  261. case CommonConstant::MODULE_7:
  262. $data['info_id'] = $info_id;
  263. $data['reason'] = $params['reason'];
  264. $data['start_time'] = $params['start_time'];
  265. $data['reach_address'] = $params['reach_address'];
  266. $data['end_time'] = $params['end_time'];
  267. $data['end_address'] = $params['end_address'];
  268. $data['document'] = $params['document'];
  269. $data['images'] = $params['images'];
  270. break;
  271. case CommonConstant::MODULE_8:
  272. $data['info_id'] = $info_id;
  273. $data['type'] = $params['type'];
  274. $data['reason'] = $params['reason'];
  275. $data['desc'] = $params['desc'];
  276. $data['images'] = $params['images'];
  277. break;
  278. case CommonConstant::MODULE_9:
  279. $data['info_id'] = $info_id;
  280. $data['reason'] = $params['reason'];
  281. $data['type'] = $params['type'];
  282. $data['desc'] = $params['desc'];
  283. $data['number'] = $params['number'];
  284. $data['scope'] = $params['scope'];
  285. $data['legal_opinion'] = $params['legal_opinion'];
  286. $data['document'] = $params['document'];
  287. $data['remark'] = $params['remark'];
  288. if ($type == 'update') {
  289. unset($data['reason']);
  290. }
  291. break;
  292. case CommonConstant::MODULE_10:
  293. $data['info_id'] = $info_id;
  294. $data['founder'] = $params['founder'];
  295. $data['desc'] = $params['desc'];
  296. $data['serial_number'] = $params['serial_number'];
  297. $data['reason'] = $params['reason'];
  298. $data['start_time'] = $params['start_time'];
  299. $data['remark'] = $params['remark'];
  300. $data['degree'] = $params['degree'];
  301. $data['document'] = $params['document'];
  302. break;
  303. case CommonConstant::MODULE_11:
  304. $data['info_id'] = $info_id;
  305. $data['department'] = $params['department'];
  306. $data['reason'] = $params['reason'];
  307. $data['department_sign'] = $params['department_sign'];
  308. $data['remark'] = $params['remark'];
  309. $data['document'] = $params['document'];
  310. $data['desc'] = $params['desc'];
  311. $data['start_time'] = $params['start_time'];
  312. $data['serial_number'] = $params['serial_number'];
  313. break;
  314. }
  315. if ($type == 'update') {
  316. $info->module_info->save($data);
  317. $module_id = $info->module_info->id;
  318. } else {
  319. $models = CommonConstant::get_module_model_list();
  320. $model = $models[$module];
  321. $module_result = $model::create($data);
  322. $module_id = $module_result->id;
  323. }
  324. $module_info = $data;
  325. return compact("module_id", "module_info", "other");
  326. }
  327. /**
  328. * 添加申购物品/入库物品/领用物品
  329. *
  330. * @param integer $info_id 申请ID
  331. * @param integer $module 模块类型
  332. * @param array $params 数据
  333. * @param string $type 类型:create=申请,update=重新发起
  334. * @return array {"total_amount":"10","data":[{"info_id":"97","goods_id":50,"goods_category_first":49,"goods_category_id":50,"goods_no":"jx105","goods_name":"联想 S22E","goods_brand":"联想","total_price":"0.00","goods_stock":[{"id":98,"goods_id":50,"name":"S22E","price":0,"stock":"10"}]}]}
  335. **/
  336. public static function create_goods($info_id, $module, $params, $type)
  337. {
  338. if (!$params) {
  339. return [];
  340. }
  341. $goods_list_new = [];
  342. $category_first_data = [];
  343. $category_data = [];
  344. $goods_ids = [];
  345. $goods_ids_new = [];
  346. $data = [];
  347. $total_amount = 0;
  348. switch ($module) {
  349. case CommonConstant::MODULE_1:
  350. $model = ApproveApplyGoods::class;
  351. break;
  352. case CommonConstant::MODULE_3:
  353. $model = ApproveStockGoods::class;
  354. break;
  355. case CommonConstant::MODULE_4:
  356. $model = ApproveUseGoods::class;
  357. break;
  358. }
  359. if ($type == 'update') {
  360. $model::where('info_id', $info_id)->delete();
  361. }
  362. foreach ($params as $value) {
  363. if ($value['flag'] == '2') {
  364. // 批量导入
  365. $category_first_data[$value['goods_category_first']][$value['goods_category_id']] = $value['goods_category_id'];
  366. }
  367. if ($value['flag'] == '3') {
  368. // 商品库选择
  369. $goods_ids[$value['goods_id']] = $value;
  370. }
  371. }
  372. // 商品库选择
  373. if ($goods_ids) {
  374. $goods_list = Goods::field('status,is_deleted,create_at', true)
  375. ->where('id', 'in', array_keys($goods_ids))
  376. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  377. ->with([
  378. 'goodsStock',
  379. ])
  380. ->select();
  381. $goods_object = $goods_list ? array_column($goods_list->toArray(), null, 'id') : [];
  382. $goods_name = '';
  383. $goods_stock_name = '';
  384. $apply_goods_data = [];
  385. foreach ($goods_ids as $key => $value) {
  386. if (array_key_exists($value['goods_id'], $goods_object)) {
  387. // 商品库里有该商品
  388. $goods_info = $goods_object[$value['goods_id']];
  389. $goods_stock_info = array_column($goods_info['goods_stock'], null, 'id');
  390. $goods_stock_data = [];
  391. $total_price = 0;
  392. foreach ($value['goods_stock'] as $val) {
  393. if (array_key_exists($val['id'], $goods_stock_info)) {
  394. // 商品库里有该商品规格
  395. $stock = isset($val['stock']) && $val['stock'] > 0 ? $val['stock'] : 0;
  396. $price = isset($val['price']) && $val['price'] > 0 ? $val['price'] : 0;
  397. $total_price = bcadd($total_price, $stock * $price, 2);
  398. $goods_stock_data[] = [
  399. 'id' => $val['id'],
  400. 'goods_id' => $goods_info['id'],
  401. 'name' => $val['name'],
  402. 'price' => $price,
  403. 'stock' => $stock,
  404. ];
  405. } else {
  406. // 商品库里没有该商品规格
  407. $goods_stock_name .= $value['goods_name'] . '-' . $val['name'] . '、';
  408. }
  409. }
  410. $goods_data = [
  411. 'info_id' => $info_id,
  412. 'goods_id' => $goods_info['id'],
  413. 'goods_category_first' => $goods_info['goods_category_first'],
  414. 'goods_category_id' => $goods_info['goods_category_id'],
  415. 'goods_no' => $goods_info['goods_no'],
  416. 'goods_name' => $goods_info['goods_name'],
  417. 'goods_brand' => $goods_info['goods_brand'],
  418. 'total_price' => $total_price,
  419. 'goods_stock' => $goods_stock_data,
  420. ];
  421. $data[] = $goods_data;
  422. $goods_data['goods_stock'] = json_encode($goods_stock_data, JSON_UNESCAPED_UNICODE);
  423. $apply_goods_data[] = $goods_data;
  424. $total_amount = bcadd($total_amount, $total_price, 2);
  425. } else {
  426. // 商品库里没有该商品
  427. $goods_name .= $value['goods_name'] . '、';
  428. }
  429. }
  430. if ($goods_name) {
  431. // 商品库选择的商品 在商品库没有匹配到 返回错误提示
  432. except($goods_name . '等商品在商品库里不存在或已删除');
  433. }
  434. if ($goods_stock_name) {
  435. // 商品库选择的商品的规格 在商品库没有匹配到 返回错误提示
  436. except($goods_stock_name . '等商品规格在商品库里不存在或已删除');
  437. }
  438. $model::insertAll($apply_goods_data);
  439. }
  440. // 批量导入
  441. if ($category_first_data) {
  442. $category_first_list = GoodsCategoryService::get_list([['name', 'in', array_keys($category_first_data)]], 1);
  443. $category_first_object = $category_first_list ? array_column($category_first_list->toArray(), null, 'name') : [];
  444. foreach ($category_first_data as $key => $value) {
  445. if (array_key_exists($key, $category_first_object)) {
  446. // 一级里有该商品分类
  447. $category_first_info = $category_first_object[$key];
  448. $goods_category_first_id = $category_first_info['id'];
  449. $category_second_object = $category_first_info['childlist'] ? array_column($category_first_info['childlist'], null, 'name') : [];
  450. } else {
  451. // 一级里没有该商品分类 创建
  452. $goods_category_first = GoodsCategory::create(['name' => $key]);
  453. $goods_category_first_id = $goods_category_first->id;
  454. $category_second_object = [];
  455. }
  456. $childlist = [];
  457. foreach ($value as $kk => $vv) {
  458. if (array_key_exists($kk, $category_second_object)) {
  459. // 二级里有该商品分类
  460. $category_second_info = $category_second_object[$kk];
  461. $goods_category_id = $category_second_info['id'];
  462. } else {
  463. // 二级里没有该商品分类 创建
  464. $goods_category = GoodsCategory::create(['pid' => $goods_category_first_id, 'name' => $kk]);
  465. $goods_category_id = $goods_category->id;
  466. }
  467. $childlist[] = [
  468. 'id' => $goods_category_id,
  469. 'name' => $kk,
  470. ];
  471. }
  472. $category_data[] = [
  473. 'id' => $goods_category_first_id,
  474. 'name' => $key,
  475. 'childlist' => $childlist
  476. ];
  477. }
  478. }
  479. $category_object = $category_data ? array_column($category_data, null, 'name') : [];
  480. foreach ($params as $key => $value) {
  481. if ($value['flag'] == '1') {
  482. // 添加新商品
  483. $goods_ids_new[$key] = $value;
  484. $goods_info = Goods::field('status,is_deleted,create_at', true)
  485. ->where('goods_category_first', $value['goods_category_first'])
  486. ->where('goods_category_id', $value['goods_category_id'])
  487. ->where('goods_name', $value['goods_name'])
  488. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  489. ->with([
  490. 'goodsStock',
  491. ])
  492. ->find();
  493. if ($goods_info) {
  494. $goods_list_new[] = $goods_info->toArray();
  495. }
  496. }
  497. if ($value['flag'] == '2') {
  498. // 批量导入
  499. if (array_key_exists($value['goods_category_first'], $category_object)) {
  500. $category_first_info = $category_object[$value['goods_category_first']];
  501. $goods_category_first_id = $category_first_info['id'];
  502. $category_second_object = array_column($category_first_info['childlist'], null, 'name');
  503. $category_second_info = $category_second_object[$value['goods_category_id']];
  504. $goods_category_id = $category_second_info['id'];
  505. $goods_ids_new[$key] = $value;
  506. $goods_ids_new[$key]['goods_category_first'] = $goods_category_first_id;
  507. $goods_ids_new[$key]['goods_category_id'] = $goods_category_id;
  508. $goods_info = Goods::field('status,is_deleted,create_at', true)
  509. ->where('goods_category_first', $goods_category_first_id)
  510. ->where('goods_category_id', $goods_category_id)
  511. ->where('goods_name', $value['goods_name'])
  512. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  513. ->with([
  514. 'goodsStock',
  515. ])
  516. ->find();
  517. if ($goods_info) {
  518. $goods_list_new[] = $goods_info->toArray();
  519. }
  520. }
  521. }
  522. }
  523. // 添加新商品
  524. if ($goods_ids_new) {
  525. $goods_object = $goods_list_new ? array_column($goods_list_new, null, 'goods_name') : [];
  526. $apply_goods_data = [];
  527. foreach ($goods_ids_new as $value) {
  528. $goods_data = [
  529. 'goods_category_first' => $value['goods_category_first'],
  530. 'goods_category_id' => $value['goods_category_id'],
  531. 'goods_no' => $value['goods_no'],
  532. 'goods_name' => $value['goods_name'],
  533. 'goods_brand' => isset($value['goods_brand']) ? $value['goods_brand'] : '',
  534. ];
  535. if (array_key_exists($value['goods_name'], $goods_object)) {
  536. // 商品库里有该商品
  537. $goods_info = $goods_object[$value['goods_name']];
  538. $goods_id = $goods_info['id'];
  539. $goods_stock_info = array_column($goods_info['goods_stock'], null, 'name');
  540. } else {
  541. // 商品库里没有该商品 创建
  542. $goods = Goods::create($goods_data);
  543. $goods_id = $goods->id;
  544. $goods_stock_info = [];
  545. }
  546. $goods_stock_data = [];
  547. $total_price = 0;
  548. foreach ($value['goods_stock'] as $val) {
  549. if (array_key_exists($val['name'], $goods_stock_info)) {
  550. // 商品库里有该商品规格
  551. $stock_id = $goods_stock_info[$val['name']]['id'];
  552. } else {
  553. // 商品库里没有该商品规格 创建
  554. $stock_data = [
  555. 'goods_id' => $goods_id,
  556. 'name' => $val['name'],
  557. ];
  558. $stock = GoodsStock::create($stock_data);
  559. $stock_id = $stock->id;
  560. }
  561. $stock = isset($val['stock']) && $val['stock'] > 0 ? $val['stock'] : 0;
  562. $price = isset($val['price']) && $val['price'] > 0 ? $val['price'] : 0;
  563. $total_price = bcadd($total_price, $stock * $price, 2);
  564. $goods_stock_data[] = [
  565. 'id' => $stock_id,
  566. 'goods_id' => $goods_id,
  567. 'name' => $val['name'],
  568. 'price' => $price,
  569. 'stock' => $stock,
  570. ];
  571. }
  572. $goods_data['info_id'] = $info_id;
  573. $goods_data['goods_id'] = $goods_id;
  574. $goods_data['total_price'] = $total_price;
  575. $goods_data['goods_stock'] = $goods_stock_data;
  576. $data[] = $goods_data;
  577. $goods_data['goods_stock'] = json_encode($goods_stock_data, JSON_UNESCAPED_UNICODE);
  578. $apply_goods_data[] = $goods_data;
  579. $total_amount = bcadd($total_amount, $total_price, 2);
  580. }
  581. $model::insertAll($apply_goods_data);
  582. }
  583. return compact("total_amount", "data");
  584. }
  585. /**
  586. * 添加同行人员
  587. *
  588. * @param integer $info_id 申请ID
  589. * @param array $params 同行人员数据
  590. * @param string $type 类型:create=申请,update=重新发起
  591. **/
  592. public static function create_peer_user($info_id, $params, $type)
  593. {
  594. if ($type == 'update') {
  595. ApproveEvectionPeerUser::where('info_id', $info_id)->delete();
  596. }
  597. $data = [];
  598. if (!$params) {
  599. return $data;
  600. }
  601. foreach ($params as $value) {
  602. if (isset($value['name']) && !empty($value['name'])) {
  603. $data[] = [
  604. 'info_id' => $info_id,
  605. 'is_who' => $value['is_who'],
  606. 'user_id' => isset($value['user_id']) ? $value['user_id'] : '',
  607. 'name' => $value['name'],
  608. 'desc' => isset($value['desc']) ? $value['desc'] : '',
  609. ];
  610. }
  611. }
  612. if ($data) {
  613. ApproveEvectionPeerUser::insertAll($data);
  614. }
  615. return $data;
  616. }
  617. /**
  618. * 添加审批抄送
  619. *
  620. * @param array $approve_user 审批ID
  621. * @param array $copy_user 抄送ID
  622. * @param string $userid 发起人ID
  623. * @param integer $info_id 申请ID
  624. * @param string $type 类型:create=申请,update=重新发起
  625. **/
  626. public static function create_approve($approve_user, $copy_user, $userid, $info_id, $type)
  627. {
  628. if ($type == 'update') {
  629. // 审批全部改为历史记录
  630. Approve::where('info_id', $info_id)->where('status','in',[CommonConstant::STATUS_3,CommonConstant::STATUS_4])->update(['state' => CommonConstant::IS_WHO_1]);
  631. Approve::where('info_id', $info_id)->where('status','in',[CommonConstant::STATUS_1,CommonConstant::STATUS_2])->update(['state' => CommonConstant::IS_WHO_0]);
  632. // 删除掉抄送
  633. ApproveCopy::where('info_id', $info_id)->delete();
  634. }
  635. $approve_data = [];
  636. $copy_data = [];
  637. $flow_num = 0;
  638. $copy_num = 0;
  639. // 发起人
  640. $apply_data = [
  641. 'info_id' => $info_id,
  642. 'status' => 0,
  643. 'group' => CommonConstant::IS_WHO_1,
  644. 'approve_user' => $userid,
  645. 'approve_flow' => 1,
  646. ];
  647. // 审批人
  648. foreach ($approve_user as $key => $value) {
  649. $flow_num++;
  650. $approve_data[] = [
  651. 'info_id' => $info_id,
  652. 'status' => $flow_num == 1 ? CommonConstant::STATUS_2 : CommonConstant::STATUS_1,
  653. 'group' => CommonConstant::IS_WHO_0,
  654. 'approve_user' => $value,
  655. 'approve_flow' => $flow_num,
  656. ];
  657. }
  658. // 抄送人
  659. foreach ($copy_user as $key => $value) {
  660. $copy_num++;
  661. $copy_data[] = [
  662. 'info_id' => $info_id,
  663. 'approve_user' => $value,
  664. 'approve_flow' => $copy_num,
  665. ];
  666. }
  667. if ($approve_data) {
  668. // 添加审批
  669. $approve_data = array_merge([$apply_data], $approve_data);
  670. Approve::insertAll($approve_data);
  671. }
  672. if ($copy_data) {
  673. // 添加抄送
  674. ApproveCopy::insertAll($copy_data);
  675. }
  676. }
  677. /**
  678. * 列表
  679. *
  680. * @param integer $group 类别:list=我的申请记录,form=采购审批单
  681. * @param integer $module 模块类型
  682. * @param integer $status 审批状态
  683. * @param string $search 搜索
  684. * @param string $start_time 申请开始时间
  685. * @param string $end_time 申请结束时间
  686. * @param integer $offset 起始位置
  687. * @param integer $length 查询数量
  688. * @param mixed $user 用户信息
  689. **/
  690. public static function get_list($group, $module, $status, $search, $start_time, $end_time,$offset, $length, $user)
  691. {
  692. if ($group == 'list') {
  693. if (!array_key_exists($module, CommonConstant::get_module_list())) {
  694. return [];
  695. }
  696. if (!array_key_exists($status, CommonConstant::get_approve_status_list())) {
  697. return [];
  698. }
  699. $type = 0;
  700. } else {
  701. $module = CommonConstant::MODULE_1;
  702. $status = CommonConstant::STATUS_3;
  703. $type = ApplyConstant::TYPE_1;
  704. }
  705. $userid = $user['userid'];
  706. $list = ApproveInfo::field('module_id,user_id,apply_user_id,department,is_deleted', true)
  707. ->where('module', $module)
  708. ->where(function ($query) use ($module, $userid) {
  709. if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
  710. $query->where('user_id', $userid)->whereOr('apply_user_id', $userid);
  711. } else {
  712. $query->where('user_id', $userid);
  713. }
  714. })
  715. ->where('status', $status)
  716. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  717. ->when(!empty($search), function ($query) use ($search) {
  718. $query->where('order_no|reason', 'like', '%' . $search . '%');
  719. })
  720. ->when(!empty($start_time) && !empty($end_time), function ($query) use ($start_time, $end_time) {
  721. $query->where('create_at', 'BETWEEN', [$start_time, $end_time]);
  722. })
  723. ->when($type > 0, function ($query) use ($type) {
  724. $query->where('type', $type);
  725. });
  726. $list = self::get_with($list, $module, $status);
  727. $list = $list->order('id desc')
  728. ->limit($offset, $length)
  729. ->select();
  730. return $list;
  731. }
  732. /**
  733. * 详情/信息
  734. *
  735. * @param integer $id 申请ID
  736. * @param mixed $user 用户信息
  737. * @param string $group 类别:0=审批人/后台,1=提交人申请人 审批详情,我的申请详情/信息
  738. * @param string $type 类型:detail=详情,info=信息
  739. **/
  740. public static function get_detail($id, $user, $group, $type)
  741. {
  742. $info = ApproveInfo::field('is_deleted', true)
  743. ->where(function ($query) use ($user, $group) {
  744. if ($group == CommonConstant::IS_WHO_1) {
  745. $query->where('user_id', $user['userid'])->whereOr('apply_user_id', $user['userid']);
  746. }
  747. })
  748. ->where('is_deleted', CommonConstant::IS_DELETED_0);
  749. if ($type == 'detail') {
  750. $info->with([
  751. 'moduleInfo',
  752. 'approve' => function ($query) {
  753. $query->field('is_deleted,create_at', true)
  754. ->where('state', 'in', [CommonConstant::IS_WHO_0, CommonConstant::IS_WHO_1])
  755. ->with([
  756. 'user' => function ($query) {
  757. $query->field('userid,name,avatar');
  758. }
  759. ]);
  760. },
  761. 'approveCopy' => function ($query) {
  762. $query->field('is_deleted,create_at', true)
  763. ->with([
  764. 'user' => function ($query) {
  765. $query->field('userid,name,avatar');
  766. }
  767. ]);
  768. }
  769. ]);
  770. $info = $info->find($id);
  771. if ($info) {
  772. // 部门列表
  773. $department_data = UserService::get_user_department_list($info['department']);
  774. $info['department_data'] = $department_data;
  775. }
  776. } else {
  777. // 信息
  778. $info->with([
  779. 'moduleInfo'
  780. ]);
  781. $info = $info->find($id);
  782. }
  783. if ($info) {
  784. $module = $info['module'];
  785. if ($group == CommonConstant::IS_WHO_1) {
  786. // 先默认当前是提交人
  787. $create_user = [
  788. 'id' => $user['id'],
  789. 'userid' => $user['userid'],
  790. 'name' => $user['name'],
  791. 'avatar' => $user['avatar'],
  792. ];
  793. $apply_user = $create_user;
  794. if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
  795. if($user['userid'] == $info['user_id']){
  796. // 当前是提交人
  797. if ($info['user_id'] != $info['apply_user_id']) {
  798. $apply_user_info = User::field('id,userid,name,avatar')
  799. ->where('userid', $info['apply_user_id'])
  800. ->find();
  801. $apply_user = [
  802. 'id' => $apply_user_info['id'],
  803. 'userid' => $apply_user_info['userid'],
  804. 'name' => $apply_user_info['name'],
  805. 'avatar' => $apply_user_info['avatar'],
  806. ];
  807. }
  808. }
  809. if($user['userid'] == $info['apply_user_id']){
  810. // 当前是申请人
  811. if ($info['user_id'] != $info['apply_user_id']) {
  812. $apply_user_info = User::field('id,userid,name,avatar')
  813. ->where('userid', $info['user_id'])
  814. ->find();
  815. $create_user = [
  816. 'id' => $apply_user_info['id'],
  817. 'userid' => $apply_user_info['userid'],
  818. 'name' => $apply_user_info['name'],
  819. 'avatar' => $apply_user_info['avatar'],
  820. ];
  821. }
  822. }
  823. }
  824. }
  825. if ($group == CommonConstant::IS_WHO_0) {
  826. // 审批人
  827. $apply_user = User::field('id,userid,name,avatar')
  828. ->where('userid', $info['apply_user_id'])
  829. ->find();
  830. $create_user = [
  831. 'id' => $apply_user['id'],
  832. 'userid' => $apply_user['userid'],
  833. 'name' => $apply_user['name'],
  834. 'avatar' => $apply_user['avatar'],
  835. ];
  836. $apply_user = $create_user;
  837. if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6, CommonConstant::MODULE_7])) {
  838. if ($info['user_id'] != $info['apply_user_id']) {
  839. $apply_user_info = User::field('id,userid,name,avatar')
  840. ->where('userid', $info['user_id'])
  841. ->find();
  842. $create_user = [
  843. 'id' => $apply_user_info['id'],
  844. 'userid' => $apply_user_info['userid'],
  845. 'name' => $apply_user_info['name'],
  846. 'avatar' => $apply_user_info['avatar'],
  847. ];
  848. }
  849. }
  850. }
  851. $info['create_user'] = $create_user;
  852. $info['apply_user'] = $apply_user;
  853. }
  854. $info = self::get_item($info, $type);
  855. return $info;
  856. }
  857. /**
  858. * 列表-关联数据
  859. *
  860. * @param mixed $list
  861. * @param integer $module 模块类型
  862. * @param integer $status 审批状态
  863. **/
  864. public static function get_with($list, $module, $status)
  865. {
  866. $field = 'id,info_id,status,approve_user';
  867. switch ($module) {
  868. case CommonConstant::MODULE_1:
  869. // 申领商品列表
  870. if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
  871. // 审批中或审批驳回 才关联 审批人信息
  872. $list = $list->with([
  873. 'approveOne' => function ($query) use ($status, $field) {
  874. $query->field($field)
  875. ->where('status', $status)
  876. ->where('group', CommonConstant::IS_WHO_0)
  877. ->where('state', CommonConstant::IS_WHO_0)
  878. ->with([
  879. 'user' => function ($query) {
  880. $query->field('userid,name');
  881. }
  882. ]);
  883. },
  884. 'applyGoods' => function ($query) {
  885. $query->field('create_at', true);
  886. },
  887. ]);
  888. } else {
  889. $list = $list->with([
  890. 'applyGoods' => function ($query) {
  891. $query->field('create_at', true);
  892. },
  893. ]);
  894. }
  895. break;
  896. case CommonConstant::MODULE_2:
  897. if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
  898. // 审批中或审批驳回 才关联 审批人信息
  899. $list = $list->with([
  900. 'approveOne' => function ($query) use ($status, $field) {
  901. $query->field($field)
  902. ->where('status', $status)
  903. ->where('group', CommonConstant::IS_WHO_0)
  904. ->where('state', CommonConstant::IS_WHO_0)
  905. ->with([
  906. 'user' => function ($query) {
  907. $query->field('userid,name');
  908. }
  909. ]);
  910. }
  911. ]);
  912. }
  913. break;
  914. case CommonConstant::MODULE_3:
  915. // 入库商品列表
  916. if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
  917. // 审批中或审批驳回 才关联 审批人信息
  918. $list = $list->with([
  919. 'approveOne' => function ($query) use ($status, $field) {
  920. $query->field($field)
  921. ->where('status', $status)
  922. ->where('group', CommonConstant::IS_WHO_0)
  923. ->where('state', CommonConstant::IS_WHO_0)
  924. ->with([
  925. 'user' => function ($query) {
  926. $query->field('userid,name');
  927. }
  928. ]);
  929. },
  930. 'stockGoods' => function ($query) {
  931. $query->field('id,info_id,goods_name');
  932. },
  933. ]);
  934. } else {
  935. $list = $list->with([
  936. 'stockGoods' => function ($query) {
  937. $query->field('id,info_id,goods_name');
  938. },
  939. ]);
  940. }
  941. break;
  942. case CommonConstant::MODULE_4:
  943. // 领用商品列表
  944. if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
  945. // 审批中或审批驳回 才关联 审批人信息
  946. $list = $list->with([
  947. 'approveOne' => function ($query) use ($status, $field) {
  948. $query->field($field)
  949. ->where('status', $status)
  950. ->where('group', CommonConstant::IS_WHO_0)
  951. ->where('state', CommonConstant::IS_WHO_0)
  952. ->with([
  953. 'user' => function ($query) {
  954. $query->field('userid,name');
  955. }
  956. ]);
  957. },
  958. 'useGoods' => function ($query) {
  959. $query->field('id,info_id,goods_name');
  960. },
  961. ]);
  962. } else {
  963. $list = $list->with([
  964. 'useGoods' => function ($query) {
  965. $query->field('id,info_id,goods_name');
  966. },
  967. ]);
  968. }
  969. break;
  970. case CommonConstant::MODULE_5:
  971. // 出差同行人员列表
  972. if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
  973. // 审批中或审批驳回 才关联 审批人信息
  974. $list = $list->with([
  975. 'approveOne' => function ($query) use ($status, $field) {
  976. $query->field($field)
  977. ->where('status', $status)
  978. ->where('group', CommonConstant::IS_WHO_0)
  979. ->where('state', CommonConstant::IS_WHO_0)
  980. ->with([
  981. 'user' => function ($query) {
  982. $query->field('userid,name');
  983. }
  984. ]);
  985. },
  986. 'peerUser' => function ($query) {
  987. $query->field('id,info_id,name');
  988. },
  989. ]);
  990. } else {
  991. $list = $list->with([
  992. 'peerUser' => function ($query) {
  993. $query->field('id,info_id,name');
  994. },
  995. ]);
  996. }
  997. break;
  998. case CommonConstant::MODULE_6:
  999. case CommonConstant::MODULE_7:
  1000. case CommonConstant::MODULE_8:
  1001. case CommonConstant::MODULE_9:
  1002. case CommonConstant::MODULE_10:
  1003. case CommonConstant::MODULE_11:
  1004. if (in_array($status, [CommonConstant::STATUS_2, CommonConstant::STATUS_4])) {
  1005. // 审批中或审批驳回 才关联 审批人信息
  1006. $list = $list->with([
  1007. 'approveOne' => function ($query) use ($status, $field) {
  1008. $query->field($field)
  1009. ->where('status', $status)
  1010. ->where('group', CommonConstant::IS_WHO_0)
  1011. ->where('state', CommonConstant::IS_WHO_0)
  1012. ->with([
  1013. 'user' => function ($query) {
  1014. $query->field('userid,name');
  1015. }
  1016. ]);
  1017. }
  1018. ]);
  1019. }
  1020. break;
  1021. }
  1022. return $list;
  1023. }
  1024. /**
  1025. * 详情/信息-关联数据
  1026. *
  1027. * @param mixed $info
  1028. * @param string $type 类型:detail=详情,info=信息
  1029. **/
  1030. public static function get_item($info, $type)
  1031. {
  1032. if ($info) {
  1033. $module = $info['module'];
  1034. switch ($module) {
  1035. case CommonConstant::MODULE_1:
  1036. if ($info['type'] == ApplyConstant::TYPE_1) {
  1037. if ($type == 'detail') {
  1038. $info['apply_goods'] = $info->applyGoods()->select();
  1039. } else {
  1040. $info->apply_goods;
  1041. }
  1042. }
  1043. $contract = [];
  1044. if ($type == 'detail') {
  1045. // 关联的合同呈批申请
  1046. $contract = ApproveInfo::field('id,reason')
  1047. ->where('module', CommonConstant::MODULE_9)
  1048. ->where('status', CommonConstant::STATUS_3)
  1049. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  1050. ->where('apply_id', $info['id'])
  1051. ->select();
  1052. }
  1053. $info['contract'] = $contract;
  1054. break;
  1055. case CommonConstant::MODULE_3:
  1056. if ($type == 'detail') {
  1057. $info['stock_goods'] = $info->stockGoods()->select();
  1058. } else {
  1059. $info->stock_goods;
  1060. }
  1061. // 关联的申购申请单
  1062. $apply = null;
  1063. if($info['apply_id'] > 0){
  1064. $apply = ApproveInfo::field('id,order_no')
  1065. ->where('module', CommonConstant::MODULE_1)
  1066. ->where('status', CommonConstant::STATUS_3)
  1067. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  1068. ->find($info['apply_id']);
  1069. }
  1070. $info['apply'] = $apply;
  1071. break;
  1072. case CommonConstant::MODULE_4:
  1073. if ($type == 'detail') {
  1074. $info['use_goods'] = $info->useGoods()->select();
  1075. } else {
  1076. $info->use_goods;
  1077. }
  1078. break;
  1079. case CommonConstant::MODULE_5:
  1080. if ($type == 'detail') {
  1081. $info['peer_user'] = $info->peerUser()->field('id,info_id,name')->select();
  1082. } else {
  1083. $info->peer_user;
  1084. }
  1085. break;
  1086. case CommonConstant::MODULE_9:
  1087. // 关联的申购申请单
  1088. $apply = null;
  1089. if($info['apply_id'] > 0){
  1090. $apply = ApproveInfo::field('id,order_no')
  1091. ->where('module', CommonConstant::MODULE_1)
  1092. ->where('status', CommonConstant::STATUS_3)
  1093. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  1094. ->find($info['apply_id']);
  1095. }
  1096. $info['apply'] = $apply;
  1097. break;
  1098. }
  1099. }
  1100. return $info;
  1101. }
  1102. /**
  1103. * 操作方法
  1104. *
  1105. * @param integer $id 申请ID
  1106. * @param array $params 数组
  1107. * @param mixed $user 用户信息
  1108. * @param string $type 类型:urging=催办,cancel=撤销,comment=评分
  1109. */
  1110. public static function make($id, $params, $user, $type)
  1111. {
  1112. $userid = $user['userid'];
  1113. $info = ApproveInfo::field('id,module,user_id,status,reason,maintain_user_id')
  1114. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  1115. ->find($id);
  1116. if (!$info) {
  1117. except('申请记录不存在或已删除');
  1118. }
  1119. if ($info->user_id != $userid) {
  1120. except('您没有权限操作');
  1121. }
  1122. switch ($type) {
  1123. case 'urging':
  1124. if ($info->status != CommonConstant::STATUS_2) {
  1125. except('其他人已操作');
  1126. }
  1127. // TODO 待对接钉钉接口
  1128. break;
  1129. case 'cancel':
  1130. if ($info->status != CommonConstant::STATUS_4) {
  1131. except('非审批驳回状态无法操作');
  1132. }
  1133. $info->status = CommonConstant::STATUS_5;
  1134. $info->save();
  1135. if ($info->module == CommonConstant::MODULE_9) {
  1136. // 9=合同呈批 释放合同编号
  1137. CommonService::set_contract_no($info->reason);
  1138. }
  1139. break;
  1140. case 'comment':
  1141. if ($info->status != CommonConstant::STATUS_3) {
  1142. except('非审批同意状态无法操作');
  1143. }
  1144. if ($info->module != CommonConstant::MODULE_8) {
  1145. // 8=维修申请
  1146. except(CommonConstant::get_module_list()[CommonConstant::MODULE_8] . '记录不存在或已删除');
  1147. }
  1148. // TODO 没有判断评价状态
  1149. Db::startTrans();
  1150. try {
  1151. // 添加评价记录
  1152. $data = $params;
  1153. $data['info_id'] = $id;
  1154. $data['user_id'] = $info->maintain_user_id;
  1155. ApproveMaintainUserLog::create($data);
  1156. // 更新维修信息
  1157. $params['comment_status'] = CommonConstant::IS_WHO_1;
  1158. ApproveMaintain::where('info_id', $id)->update($params);
  1159. Db::commit();
  1160. } catch (Exception $e) {
  1161. Db::rollback();
  1162. except('出现错误:' . $e->getMessage());
  1163. }
  1164. break;
  1165. }
  1166. return true;
  1167. }
  1168. }