ServiceWorkLogic.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic\works;
  15. use app\common\enum\ThirdTypeEnum;
  16. use app\common\enum\worker\WorkerAccountLogEnum;
  17. use app\common\logic\ThirdOrderLogic;
  18. use app\common\logic\WorkerAccountLogLogic;
  19. use app\common\model\third\ThirdOrders;
  20. use app\common\model\works\ServiceWorkDeterminedPrice;
  21. use think\Exception;
  22. use think\db\Query;
  23. use think\facade\Db;
  24. use think\facade\Log;
  25. use app\common\logic\BaseLogic;
  26. use app\api\logic\PerformanceLogic;
  27. use app\common\model\dict\DictData;
  28. use app\common\model\coupon\UserCoupon;
  29. use app\common\model\works\ServiceWork;
  30. use app\common\model\recharge\OrderGoods;
  31. use app\common\model\spare_part\SparePart;
  32. use app\common\model\works\ServiceWorkLog;
  33. use app\common\model\coupon\CouponCategory;
  34. use app\common\model\recharge\RechargeOrder;
  35. use app\common\model\works\ServiceWorkSpare;
  36. use app\workerapi\logic\ServiceWorkLogLogic;
  37. use app\common\model\orders\OrderEffectiveLog;
  38. use app\common\model\master_worker\MasterWorker;
  39. use app\common\model\training\TrainingWorkerTask;
  40. use app\common\model\performance\PerformanceRules;
  41. use app\common\model\works\ServiceWorkCustomerLog;
  42. use app\workerapi\logic\ServiceWorkReceiveLogLogic;
  43. use app\common\model\master_worker\MasterWorkerTeam;
  44. use app\common\model\works\ServiceWorkAppointmentLog;
  45. use app\workerapi\logic\ServiceWorkerAllocateWorkerLogic;
  46. use app\common\model\master_worker\MasterWorkerAccountLog;
  47. use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
  48. use app\common\model\master_commission\MasterWorkerCommissionRatio;
  49. use app\common\model\master_commission\MasterWorkerCommissionConfig;
  50. /**
  51. * ServiceWork逻辑
  52. * Class ServiceWorkLogic
  53. * @package app\adminapi\logic\works
  54. */
  55. class ServiceWorkLogic extends BaseLogic
  56. {
  57. /**
  58. * @notes 编辑
  59. * @param array $params
  60. * @return bool
  61. * @author likeadmin
  62. * @date 2024/07/10 18:17
  63. */
  64. public static function edit(array $params): bool
  65. {
  66. Db::startTrans();
  67. try {
  68. ServiceWork::where('id', $params['id'])->update([
  69. 'address' => $params['address'],
  70. 'appointment_time' => strtotime($params['appointment_time']),
  71. 'estimated_finish_time' => $params['estimated_finish_time'],
  72. 'lon' => $params['lon'],
  73. 'lat' => $params['lat'],
  74. ]);
  75. Db::commit();
  76. return true;
  77. } catch (\Exception $e) {
  78. Db::rollback();
  79. self::setError($e->getMessage());
  80. return false;
  81. }
  82. }
  83. /**
  84. *
  85. * @return false|void
  86. */
  87. public static function pickWork($params)
  88. {
  89. Db::startTrans();
  90. try {
  91. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  92. if($work->isEmpty()){
  93. throw new Exception('工单不存在');
  94. }
  95. $receive_time = time();
  96. $work->work_status = 2;//待联系
  97. $work->service_status = 1;//服务中
  98. $work->receive_time = $receive_time;
  99. $work->save();
  100. //添加变更日志
  101. $work_log = [
  102. 'work_id'=>$work->id,
  103. 'master_worker_id'=>$work->master_worker_id,
  104. 'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',$receive_time).'领取了工单',
  105. ];
  106. ServiceWorkLogLogic::add($work_log);
  107. //添加领单日志
  108. ServiceWorkReceiveLogLogic::add($work_log);
  109. Db::commit();
  110. }
  111. catch (\Exception $e) {
  112. Db::rollback();
  113. self::setError($e->getMessage());
  114. return false;
  115. }
  116. }
  117. /**
  118. * 预约成功,等待上门
  119. * @return false|void
  120. */
  121. public static function appointWork($params)
  122. {
  123. Db::startTrans();
  124. try {
  125. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  126. if($work->isEmpty()){
  127. throw new Exception('工单不存在');
  128. }
  129. if($work->work_status != 2){
  130. throw new Exception('请勿重复点击');
  131. }
  132. //验证更改的预约时间必须是在领单时间内的半小内修改,否则不允许修改
  133. if(strtotime($work->appointment_time) != strtotime($params['appointment_time']) && (time()-strtotime($work->receive_time))>1800){
  134. throw new Exception('距离领单时间已超过半小时,无法修改预约时间,请联系客服');
  135. }
  136. $work->work_status = 3;//待上门
  137. $work->appointment_time = strtotime($params['appointment_time']);
  138. $work->save();
  139. //添加变更日志
  140. $work_log = [
  141. 'work_id'=>$work->id,
  142. 'master_worker_id'=>$work->master_worker_id,
  143. 'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'联系了客户,确认了于'.$params['appointment_time'].$params['address'].'预约上门',
  144. ];
  145. ServiceWorkLogLogic::add($work_log);
  146. Db::commit();
  147. }
  148. catch (\Exception $e) {
  149. self::setError($e->getMessage());
  150. return false;
  151. }
  152. }
  153. /**
  154. * 工程师确认上门
  155. * @param $params
  156. * @return false|void
  157. */
  158. public static function confirmDoor($params)
  159. {
  160. Db::startTrans();
  161. try {
  162. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  163. if($work->isEmpty()){
  164. throw new Exception('工单不存在');
  165. }
  166. if($work->work_status != 3){
  167. throw new Exception('请勿重复点击');
  168. }
  169. $work->finally_door_time = time();//最后上门时间
  170. $work->work_status = 4;//已上门
  171. $work->save();
  172. //如果是美团订单,且上门时间小于预约时间,则修改预约时间
  173. if($work->third_type==1 and $work->finally_door_time<$work->appointment_time){
  174. $third_order = ThirdOrders::where('work_id',$work->id)->order('id desc')->findOrEmpty();
  175. if(!$third_order->isEmpty()){
  176. ThirdOrderLogic::merchantmodify([
  177. 'reserveOrderId'=>$third_order['orderId'],
  178. 'reserveUserName'=>$work['real_name'],
  179. "reservePhone"=>$work['mobile'],
  180. "reserveAddress"=>$work['address'],
  181. "bookStartTime"=>$work->finally_door_time*1000,
  182. "bookEndTime"=>($work->finally_door_time+2*3600)*1000,
  183. 'request_msg'=>$third_order['request_msg']
  184. ]);
  185. }
  186. }
  187. //添加变更日志
  188. $work_log = [
  189. 'work_id'=>$work->id,
  190. 'master_worker_id'=>$work->master_worker_id,
  191. 'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'已上门',
  192. ];
  193. ServiceWorkLogLogic::add($work_log);
  194. Db::commit();
  195. }
  196. catch (\Exception $e) {
  197. Db::rollback();
  198. self::setError($e->getMessage());
  199. return false;
  200. }
  201. }
  202. /**
  203. * 工程师确认报价单
  204. * @param $params
  205. * @return false|void
  206. */
  207. public static function confirmPrice($params)
  208. {
  209. Db::startTrans();
  210. try {
  211. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  212. if($work->isEmpty()){
  213. throw new Exception('工单不存在');
  214. }
  215. //搜索待支付订单
  216. $paid_order = RechargeOrder::where(['work_id'=>$work['id'],'pay_status'=>1])->findOrEmpty()->toArray();
  217. if(empty($paid_order)){
  218. throw new Exception('订单错误');
  219. }
  220. if($work->work_status != 4){
  221. throw new Exception('请勿重复操作');
  222. }
  223. // 关联配件信息.计算配件总价 id company_price original_price offering_price number
  224. $spare_total = 0;
  225. isset($params['spare_parts']) && $params['spare_parts'] && $params['spare_parts'] = json_decode($params['spare_parts'], true);
  226. if(isset($params['spare_parts']) && $params['spare_parts']){
  227. $spare_parts = $params['spare_parts'];
  228. foreach ($spare_parts as $spare){
  229. $spare_total += $spare['company_price']*$spare['number'];
  230. }
  231. $work->spare_total = $spare_total;
  232. $service_work_spare = ServiceWorkSpare::where(['service_work_id'=>$work['id']])->findOrEmpty();
  233. if($service_work_spare->isEmpty()){
  234. //新增
  235. $service_work_spare = ServiceWorkSpare::create([
  236. 'service_work_id'=>$work['id'],
  237. 'spare_parts'=>$params['spare_parts'],
  238. 'remark'=>''
  239. ]);
  240. }else{
  241. //修改
  242. $service_work_spare->spare_parts = $params['spare_parts'];
  243. $service_work_spare->save();
  244. }
  245. $work->service_work_spare_id = $service_work_spare->id;
  246. }
  247. // order_amount 原 = $params['amount'] 修改为 = 配件总价 + 服务尾款
  248. $order_amount = $params['amount'] + $spare_total;
  249. //定金存在尾款结算功能,全款直接提交
  250. if($paid_order['payment_type']==1){
  251. $un_order = RechargeOrder::where(['work_id'=>$work['id'],'pay_status'=>0])->findOrEmpty();
  252. if($un_order->isEmpty()){
  253. //新增待支付尾款
  254. $order_data = [
  255. 'order_type'=>$paid_order['order_type'],
  256. 'sn'=>generate_sn(\app\common\model\orders\RechargeOrder::class, 'sn'),
  257. 'work_id'=>$paid_order['work_id'],
  258. 'user_id'=>$paid_order['user_id'],
  259. 'payment_type'=>2,
  260. 'order_total'=>$order_amount,
  261. //'order_amount'=>$params['amount'],
  262. 'order_amount'=>$order_amount,
  263. 'order_terminal'=>$paid_order['order_terminal']
  264. ];
  265. RechargeOrder::create($order_data);
  266. }else{
  267. //修改尾款信息
  268. $un_order->order_total = $order_amount;
  269. //$un_order->order_amount = $params['amount'];
  270. $un_order->order_amount = $order_amount;
  271. $un_order->save();
  272. }
  273. //更新服务费用
  274. $work->service_fee = $paid_order['paid_amount']+$params['amount'];
  275. }
  276. //总工单费用
  277. $work->work_total = $work->service_fee+$spare_total;
  278. $work->work_images = $params['work_images'];
  279. $work->explanation = $params['explanation']??'';
  280. //判断是否是第三个订单,如果是美团订单直接滤过用户确认环节
  281. if($work->third_type==1){
  282. $work->work_status = 5;
  283. $work->user_confirm_status = 2;
  284. }else{
  285. $work->user_confirm_status = 1;//待确认报价
  286. }
  287. if($work->external_platform_id > 0){
  288. $work->work_status = 5;
  289. $work->user_confirm_status = 2;
  290. }
  291. $work->price_approval = 0;
  292. $work->save();
  293. //添加变更日志
  294. $work_log = [
  295. 'work_id'=>$work->id,
  296. 'master_worker_id'=>$work->master_worker_id,
  297. 'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'提交了报价单',
  298. ];
  299. ServiceWorkLogLogic::add($work_log);
  300. // 添加工单尾款报价记录
  301. if(isset($params['price_content'])){
  302. !is_array($params['price_content']) && $params['price_content'] = json_decode($params['price_content'], true);
  303. ServiceWorkDeterminedPrice::where('work_id',$work->id)->delete();
  304. ServiceWorkDeterminedPrice::create([
  305. 'work_id'=>$work->id,
  306. 'content'=>$params['price_content']??[],
  307. ]);
  308. }
  309. Db::commit();
  310. // 外部平台工单 - 通知外边平台
  311. if($work->external_platform_id > 0){
  312. event('ExternalPlatform', [
  313. 'scene' => 'confirm_price',
  314. 'params' => [
  315. 'work_id' => $work->id,
  316. ]
  317. ]);
  318. }
  319. }
  320. catch (\Exception $e) {
  321. Db::rollback();
  322. self::setError($e->getMessage());
  323. return false;
  324. }
  325. }
  326. /**
  327. * 工程师确认服务完成
  328. * @param $params
  329. * @return false|void
  330. */
  331. public static function confirmServiceFinish($params)
  332. {
  333. Db::startTrans();
  334. try {
  335. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  336. if($work->isEmpty()){
  337. throw new Exception('工单不存在');
  338. }
  339. if($work->user_confirm_status !=2){
  340. throw new Exception('请勿重复操作');
  341. }
  342. $work->finished_images = $params['finished_images'];
  343. $work->user_confirm_status = 3;//待确认服务完成
  344. $work->save();
  345. //添加变更日志
  346. $work_log = [
  347. 'work_id'=>$work->id,
  348. 'master_worker_id'=>$work->master_worker_id,
  349. 'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'提交了待用户确认服务完成',
  350. ];
  351. ServiceWorkLogLogic::add($work_log);
  352. Db::commit();
  353. // 外部平台工单 - 通知外边平台
  354. if($work->external_platform_id > 0){
  355. event('ExternalPlatform', [
  356. 'scene' => 'service_finish',
  357. 'params' => [
  358. 'work_id' => $work->id,
  359. ]
  360. ]);
  361. }
  362. } catch (\Exception $e) {
  363. Db::rollback();
  364. self::setError($e->getMessage());
  365. return false;
  366. }
  367. }
  368. public static function allocateWorker($params,$userInfo){
  369. Db::startTrans();
  370. try {
  371. $work = ServiceWork::findOrEmpty($params['id']);
  372. if($work->isEmpty()){
  373. throw new Exception('工单不存在');
  374. }
  375. if($work->work_status >=6 ){
  376. throw new \Exception('工单状态只能修改待结算之前的');
  377. }
  378. if($work->master_worker_id == $params['master_worker_id']){
  379. throw new \Exception('分配的工程师相同');
  380. }
  381. $worker = MasterWorker::where(['id'=>$params['master_worker_id'],'is_disable' =>0])->findOrEmpty();
  382. if($worker->isEmpty()){
  383. throw new \Exception('工程师不存在或被禁用');
  384. }
  385. if($worker->master_worker_id){
  386. MasterWorker::setWorktotal('dec',$worker->master_worker_id);
  387. }
  388. $work->master_worker_id = $params['master_worker_id'];
  389. $work->work_status = 1;
  390. $work->dispatch_time = time();
  391. MasterWorker::setWorktotal('inc',$params['master_worker_id']);
  392. $work->save();
  393. $work_log = [
  394. 'work_id'=>$work->id,
  395. 'master_worker_id'=>$work->master_worker_id,
  396. 'type' => 0,
  397. 'opera_log'=>'后台用户['.$userInfo['admin_id'].']'.$userInfo['name'].'于'.date('Y-m-d H:i:s',time()).'分配了工程师'.'编号['.$worker->worker_number.']'.$worker->real_name
  398. ];
  399. ServiceWorkerAllocateWorkerLogic::add($work_log);
  400. Db::commit();
  401. //美团的订单更新履约状态为已分配
  402. if($work->third_type == 1 || ($work->external_platform_id > 0)){
  403. http_request('https://developer.kyjlkj.com/platf/performanceNotice', http_build_query([
  404. 'external_platform_id'=> $work->external_platform_id,
  405. 'send_code'=>1003,
  406. 'work_sn'=>$work->work_sn,
  407. ]));
  408. ThirdOrderLogic::updateorderfulfillinfo($work,ThirdTypeEnum::MEITUAN_MEITUAN);
  409. }
  410. // 工程师派单通知【给工程师的通知】【公众号通知,不发短信】
  411. $workDetail = ServiceWorkLogic::detail($params);
  412. $res = event('Notice', [
  413. 'scene_id' => 113,
  414. 'params' => [
  415. 'user_id' => $params['master_worker_id'],
  416. 'order_id' => $params['id'],
  417. 'thing9' => $workDetail['title'],
  418. 'time7' => $workDetail['appointment_time'],
  419. 'thing8' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  420. 'phone_number6' => asteriskString($workDetail['mobile']),
  421. ]
  422. ]);
  423. return true;
  424. }catch(\Exception $e){
  425. Db::rollback();
  426. self::setError($e->getMessage());
  427. return false;
  428. }
  429. }
  430. /**
  431. * 工单详情
  432. * @param $params
  433. * @return array|false
  434. */
  435. public static function detail($params){
  436. $work_where = !empty($params['work_sn'])?['work_sn'=>$params['work_sn']]:['id'=>$params['id']];
  437. $result = ServiceWork::with([
  438. 'worker'=> function(Query $query) {
  439. $query->field('id,worker_number,real_name,mobile');
  440. },
  441. 'allocateWorkerLog' =>function(Query $query){
  442. $query->field('id,work_id,opera_log,create_time');
  443. },
  444. 'serviceWorkLog' =>function(Query $query){
  445. $query->field('id,work_id,opera_log,create_time');
  446. }
  447. ])->append(['id','work_status_text','service_status_text'])
  448. ->where($work_where)
  449. ->findOrEmpty()->toArray();
  450. $result['is_operate_prohibit'] = 0;
  451. if(isset($params['user_id']) && $params['user_id'] && ($params['user_id'] != $result['master_worker_id']) ){
  452. // 带徒师傅的工单
  453. $lead_master_worker_id = TrainingWorkerTask::where('master_worker_id',$params['user_id'])->where('training_status',2)
  454. ->where('operate_status',0)->value('lead_master_worker_id');
  455. // 团队负责人编辑 工单池(包括已派队员) 工单
  456. if($params['user_info']['team_role'] == 1 && $params['user_info']['tenant_id'] == $result['tenant_id'] ){
  457. $result['is_operate_prohibit'] = 0;
  458. }elseif(!empty($lead_master_worker_id) && !empty($result['master_worker_id']) && $lead_master_worker_id == $result['master_worker_id']){
  459. // 徒查看师父的工单 不能编辑可查看
  460. $result['is_operate_prohibit'] = 1;
  461. }else{
  462. throw new \Exception('您没有权限操作该工单');
  463. }
  464. }
  465. //工程师工单按钮状态
  466. $work_service_status = 0;
  467. $work_service_status_text = '待派单';
  468. //工单状态
  469. if($result['work_status'] == 1){
  470. $work_service_status = 1;
  471. $work_service_status_text = '待领单';
  472. }
  473. if($result['work_status'] == 2){
  474. $work_service_status = 2;
  475. $work_service_status_text = '预约上门';
  476. }
  477. if($result['work_status'] == 3){
  478. $work_service_status = 3;
  479. $work_service_status_text = '等待上门';
  480. if(date('Y-m-d') === date('Y-m-d',strtotime($result['appointment_time']))){
  481. $work_service_status = 4;
  482. $work_service_status_text = '确认上门';
  483. }
  484. }
  485. if($result['work_status'] == 4 and $result['user_confirm_status']==0){
  486. $work_service_status = 5;
  487. $work_service_status_text = '确认报价';
  488. }
  489. if($result['work_status'] == 4 and $result['user_confirm_status']==1){
  490. $work_service_status = 6;
  491. $work_service_status_text = '用户确认报价中';
  492. }
  493. if($result['work_status'] == 5 and $result['user_confirm_status']==2){
  494. $work_service_status = 7;
  495. $work_service_status_text = '完成服务';
  496. }
  497. if($result['work_status'] == 5 and $result['user_confirm_status']==3){
  498. $work_service_status = 8;
  499. $work_service_status_text = '用户确认完成服务中';
  500. }
  501. if($result['work_status'] ==6){
  502. $work_service_status = 9;
  503. $work_service_status_text = '待结算';
  504. }
  505. if($result['work_status'] ==7){
  506. $work_service_status = 10;
  507. $work_service_status_text = '已完结';
  508. }
  509. if($result['work_status'] ==8){
  510. $work_service_status = 11;
  511. $work_service_status_text = '已评价';
  512. }
  513. if($result['work_status'] ==9){
  514. $work_service_status = 12;
  515. $work_service_status_text = '已退费';
  516. }
  517. $result['work_service_status'] = $work_service_status;
  518. $result['work_service_status_text'] = $work_service_status_text;
  519. //搜索当前工单下的所有订单记录
  520. $result['pay_orders'] = RechargeOrder::with(['orderGoods'=>function(Query $query){
  521. $query->field('id,sn,goods_id,goods_name,goods_image,goods_number,good_unit,goods_size,goods_payment_type,goods_type,goods_brand,base_service_fee,service_total,service_fee')->order(['id'=>'desc']);
  522. }])->where(['work_id'=>$result['id']])->field('id as order_id,sn,order_type,pay_status,payment_type,pay_way,pay_time,order_amount,order_total,coupon_price,create_time')->order('id asc')->select()->toArray();
  523. $pay_status_data = DictData::where('type_value','pay_status')->column('name','value');
  524. $payment_type_data = DictData::where('type_value','payment_type')->column('name','value');
  525. $pay_way_data = DictData::where('type_value','pay_way')->column('name','value');
  526. $order_type_data = DictData::where('type_value','order_type')->column('name','value');
  527. $coupon_price = 0;
  528. foreach ($result['pay_orders'] as $k=>&$v){
  529. $v['pay_status_name'] = $pay_status_data[$v['pay_status']];
  530. $v['payment_type_name'] = $payment_type_data[$v['payment_type']];
  531. $v['pay_way_name'] = $pay_way_data[$v['pay_way']];
  532. $v['order_type_name'] = $order_type_data[$v['order_type']];
  533. $v['pay_time'] = $v['pay_time'] && is_numeric($v['pay_time']) ? date('Y-m-d H:i:s',$v['pay_time']):'';
  534. if($v['payment_type']!=1 and !empty($result['spare_total'])){
  535. $v['order_total'] = $v['order_total'] - $result['spare_total'];
  536. $v['order_amount'] = $v['order_amount'] - $result['spare_total'];
  537. }
  538. $coupon_price += $v['coupon_price'];
  539. //服务支付类别
  540. if(!empty($v['orderGoods'][0]['goods_payment_type'])){
  541. $goods_payment_type = $v['orderGoods'][0]['goods_payment_type'];
  542. }
  543. }
  544. $result['goods_payment_type'] = !empty($goods_payment_type)?$goods_payment_type:1;
  545. //汇总优惠卷额度
  546. $result['coupon_price'] = $coupon_price;
  547. //工单总支付金额
  548. $result['worker_account'] = $result['work_amount'];
  549. // 配件信息
  550. $result['spare_parts'] = [];
  551. if($result['service_work_spare_id']){
  552. $work_spare_parts = json_decode(ServiceWorkSpare::where('id',$result['service_work_spare_id'])->value('spare_parts'),true);
  553. $spare_parts = SparePart::where('id','in',array_column($work_spare_parts,'id'))
  554. ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit','spare_status'])
  555. ->select()
  556. ->toArray();
  557. $spare_parts = array_column($spare_parts,null,'id');
  558. foreach (array_column($work_spare_parts,null,'id') as $k=>&$v){
  559. $spare_parts[$k] = array_merge($spare_parts[$k],$v);
  560. }
  561. $result['spare_parts'] = array_values($spare_parts)??[];
  562. }
  563. // 保修卡信息
  564. $result['order_effectives'] = OrderEffectiveLog::with(['goods'=>function ($query) {
  565. $query->with(['goodsCategory'=>function ($query1) {
  566. $query1->field(['name','picture']);
  567. }]);
  568. }])->where('work_id',$result['id'])
  569. ->field(['id','goods_id','sn','effective_unit','effective_num','remark','end_effective_time'])
  570. ->append(['effective_unit_text'])
  571. ->order('create_time desc')
  572. ->select()
  573. ->toArray();
  574. //查收工程师提成金额
  575. $change_amount = MasterWorkerAccountLog::where(['work_sn'=>$result['work_sn'],'action'=>1])->value('change_amount');
  576. $result['change_amount'] = !empty($change_amount)?$change_amount:0;
  577. //质保金相关金额
  578. $result['retention'] = MasterWorkerRetentionMoneyLog::where('work_id',$result['id'])->visible(['action','amount'])->select()
  579. ->each(function ($item){
  580. $item['amount'] = $item['action'] == 1 ? '+'.$item['amount'] : '-'.$item['amount'];
  581. })->toArray();
  582. //保修工单时的信息
  583. $result['effective_income_amount'] = 0;
  584. if(!empty($result['order_effective_id'])){
  585. $order_effective = OrderEffectiveLog:: findOrEmpty($result['order_effective_id']);
  586. $serviceWork = ServiceWork::findOrEmpty($order_effective->work_id);
  587. if($serviceWork->master_worker_id != $result['master_worker_id']){
  588. $result['effective_income_amount'] = \app\adminapi\logic\effective\OrderEffectiveLogLogic::commissionAndAssuranceDeposit($serviceWork);
  589. }
  590. }
  591. //获取美团订单信息
  592. $result['meituan_order'] = [];
  593. if($result['third_type']==1){
  594. $result['meituan_order'] = ThirdOrders::where(['work_id'=>$result['id']])->order('create_time desc')->findOrEmpty();
  595. }
  596. return $result;
  597. }
  598. public static function getUserCouponDetails($params)
  599. {
  600. try{
  601. $work = ServiceWork::where('id',$params['id'])->findOrEmpty();
  602. if(!$work){
  603. throw new \Exception('工单不存在');
  604. }
  605. $coupon_all_ids =UserCoupon::where('user_id',$work['user_id'])
  606. ->where('voucher_count','>',0)
  607. ->where('voucher_status',0)
  608. ->where('expire_time','>',time())
  609. ->column('coupon_id');
  610. $coupon_ids = CouponCategory::where('goods_category_id',$work['goods_category_id'])->whereIn('coupon_id',$coupon_all_ids)->column('coupon_id');
  611. $data = UserCoupon::where('user_id',$work['user_id'])
  612. ->where('voucher_count','>',0)
  613. ->where('voucher_status',0)
  614. ->whereIn('coupon_id',$coupon_ids)
  615. ->append(['discount_ratio_text'])
  616. ->where('expire_time','>',time())
  617. ->visible(['id','coupon_id','amount','amount_require','begin_use','discount_ratio','event_name','expire_time','max_deductible_price','server_category_name','mold_type'])
  618. ->select()->toArray();
  619. foreach($data as $k => $v){
  620. $data[$k]['begin_use'] = date("Y-m-d H:i:s",$v['begin_use'] );
  621. $data[$k]['expire_time'] = date("Y-m-d H:i:s",$v['expire_time'] );
  622. $data[$k]['amount_require'] = '满'.$v['amount_require'].'可用';
  623. }
  624. return $data;
  625. } catch(\Exception $e){
  626. self::setError($e->getMessage());
  627. return false;
  628. }
  629. }
  630. public static function getDetailWorkServiceStatus($params)
  631. {
  632. $result = ServiceWork::where('id',$params['id'])->field('work_status,user_confirm_status,appointment_time,price_approval,appoint_approval')->findOrEmpty()->toArray();
  633. //工程师工单按钮状态
  634. $work_service_status = 0;
  635. //工单状态
  636. if($result['work_status'] == 1){
  637. $work_service_status = 1;
  638. }
  639. if($result['work_status'] == 2){
  640. $work_service_status = 2;
  641. }
  642. if($result['work_status'] == 3){
  643. $work_service_status = 3;
  644. if(date('Y-m-d') === date('Y-m-d',strtotime($result['appointment_time']))){
  645. $work_service_status = 4;
  646. }
  647. }
  648. if($result['work_status'] == 4 and $result['user_confirm_status']==0){
  649. $work_service_status = 5;
  650. }
  651. if($result['work_status'] == 4 and $result['user_confirm_status']==1){
  652. $work_service_status = 6;
  653. }
  654. if($result['work_status'] == 5 and $result['user_confirm_status']==2){
  655. $work_service_status = 7;
  656. }
  657. if($result['work_status'] == 5 and $result['user_confirm_status']==3){
  658. $work_service_status = 8;
  659. }
  660. if($result['work_status'] ==6){
  661. $work_service_status = 9;
  662. }
  663. if($result['work_status'] ==7){
  664. $work_service_status = 10;
  665. }
  666. if($result['work_status'] ==8){
  667. $work_service_status = 11;
  668. }
  669. if($result['work_status'] ==9){
  670. $work_service_status = 12;
  671. }
  672. return ['work_service_status'=>$work_service_status,'price_approval'=>$result['price_approval'],'appoint_approval'=>$result['appoint_approval']];
  673. }
  674. /**
  675. * @notes 取消操作
  676. * @param array $params
  677. * @return bool
  678. * @author likeadmin
  679. * @date 2024/09/19 10:48
  680. */
  681. public static function cancel(array $params): bool
  682. {
  683. Db::startTrans();
  684. try {
  685. // 04-11-12 不做任何限制强制取消,已支付的费用给工程师余额
  686. $serviceWorkInfo = ServiceWork::find($params['id']);
  687. if((int)$serviceWorkInfo['user_confirm_status'] === 5 || (int)$serviceWorkInfo['service_status'] > 2){
  688. throw new \Exception('用户已完结该工单或已取消,已退款,不可执行取消');
  689. }
  690. //工单如果存在费用情况,不允许取消
  691. $paid_amount = RechargeOrder::where('work_id', $params['id'])->where('pay_status', 1)->value('paid_amount');
  692. if($paid_amount > 0 and $serviceWorkInfo['third_type'] == 0){
  693. // 4=已上门,5=服务中,6=待结算, 即工程师已上门服务过
  694. throw new Exception('工单存在费用情况,不允许取消,请走退费流程');
  695. }
  696. ServiceWork::where('id', $params['id'])->update([
  697. //'work_status' => 9,
  698. 'service_status' => 4,
  699. 'remark' => $params['remark']??''
  700. ]);
  701. ServiceWorkLog::create([
  702. 'work_id' => $params['id'],
  703. 'master_worker_id' => $serviceWorkInfo['master_worker_id'],
  704. 'opera_log' => "工单:{$serviceWorkInfo['work_sn']}已取消"
  705. ]);
  706. Db::commit();
  707. Log::info('取消工单'.json_encode([$serviceWorkInfo]));
  708. return true;
  709. } catch (\Exception $e) {
  710. Db::rollback();
  711. self::setError($e->getMessage());
  712. Log::info('取消工单-Error'.json_encode([$e->getMessage()]));
  713. return false;
  714. }
  715. }
  716. /**
  717. * @notes 工程师结算操作
  718. * @param array $params
  719. * @return bool
  720. * @author likeadmin
  721. * @date 2024/09/19 10:48
  722. */
  723. public static function settlement(array $params): bool
  724. {
  725. Db::startTrans();
  726. try {
  727. $serviceWorkInfo = ServiceWork::find($params['id']);
  728. if((int)$serviceWorkInfo['work_pay_status'] !== 3){
  729. throw new \Exception('该工单非待结算状态');
  730. }
  731. $ratio = 0;
  732. $commissionConfig = MasterWorkerCommissionConfig::where('master_worker_id',$serviceWorkInfo->master_worker_id)->where('voucher_status',2)->findOrEmpty();
  733. !$commissionConfig->isEmpty() && $ratio = MasterWorkerCommissionRatio::where('commission_config_id',$commissionConfig['id'])->where('goods_category_id',$serviceWorkInfo->goods_category_id)->value('ratio')?:0;
  734. if($commissionConfig->isEmpty() || empty($ratio)){
  735. //获取工单对应的商品id
  736. $order_sns = \app\common\model\orders\RechargeOrder::where('work_id',$serviceWorkInfo->id)->column('sn');
  737. $goods_id = OrderGoods::whereIn('sn',$order_sns)->value('goods_id');
  738. $rule = PerformanceRules::whereFindInSet('goods_id',$goods_id)->findOrEmpty();
  739. if($rule->isEmpty()){
  740. throw new \Exception('请配置商品业绩规则');
  741. }
  742. PerformanceLogic::calculatePerformance($serviceWorkInfo);
  743. }else{
  744. // 存在服务分类比例进行结算
  745. PerformanceLogic::calculatePerformanceCommission($serviceWorkInfo);
  746. }
  747. Db::commit();
  748. return true;
  749. } catch (\Exception $e) {
  750. Db::rollback();
  751. self::setError($e->getMessage());
  752. return false;
  753. }
  754. }
  755. /**
  756. * 获取所有改约通知
  757. * @param $userId
  758. * @return array|false
  759. */
  760. public static function getAppointmentNotice($userId)
  761. {
  762. return ServiceWork::where(['master_worker_id'=>$userId,'appoint_approval'=>1])
  763. ->where('work_status','>',1)
  764. ->where('work_status','<',7)
  765. ->field(['id', 'work_sn','real_name','mobile', 'address', 'title', 'appointment_time','work_status'])
  766. ->order(['appointment_time' => 'asc'])//上门时间排序
  767. ->select()->each(function (&$item){
  768. $item['last_appointment_time'] = date('Y-m-d H:i:s',ServiceWorkAppointmentLog::where('work_id',$item['id'])->order('id desc')->value('last_appointment_time'));
  769. })
  770. ->toArray();
  771. }
  772. /**
  773. * @param $params
  774. * @return bool
  775. */
  776. public static function submitAppointment($params)
  777. {
  778. Db::startTrans();
  779. try {
  780. $serviceWork = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  781. if($serviceWork->isEmpty()){
  782. throw new \Exception('工单不存在');
  783. }
  784. $serviceWork->appoint_approval = 2;
  785. $serviceWork->save();
  786. Db::commit();
  787. return true;
  788. } catch (\Exception $e) {
  789. Db::rollback();
  790. self::setError($e->getMessage());
  791. return false;
  792. }
  793. }
  794. /**
  795. * @param $params
  796. * @return bool
  797. */
  798. public static function submitChangePrice($params)
  799. {
  800. Db::startTrans();
  801. try {
  802. $serviceWork = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  803. if($serviceWork->isEmpty()){
  804. throw new \Exception('工单不存在');
  805. }
  806. $serviceWork->work_status = 4;
  807. $serviceWork->user_confirm_status = 0;
  808. $serviceWork->price_approval = 2;
  809. $serviceWork->save();
  810. Db::commit();
  811. return true;
  812. } catch (\Exception $e) {
  813. Db::rollback();
  814. self::setError($e->getMessage());
  815. return false;
  816. }
  817. }
  818. public static function notApproved($params)
  819. {
  820. Db::startTrans();
  821. try {
  822. $serviceWork = ServiceWork::where('id',$params['id'])->findOrEmpty();
  823. if($serviceWork->isEmpty()){
  824. throw new \Exception('工单不存在');
  825. }
  826. $serviceWork->refund_approval = 3;
  827. $serviceWork->save();
  828. Db::commit();
  829. return true;
  830. } catch (\Exception $e) {
  831. Db::rollback();
  832. self::setError($e->getMessage());
  833. return false;
  834. }
  835. }
  836. public static function againDoor($params)
  837. {
  838. Db::startTrans();
  839. try {
  840. $serviceWork = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  841. if($serviceWork->isEmpty()){
  842. throw new \Exception('工单不存在');
  843. }
  844. //更新预约日志
  845. //更新工单未确认上门的状态
  846. $serviceWork->work_status = 3;
  847. $serviceWork->user_confirm_status = 0;
  848. $appoint = ServiceWorkAppointmentLog::where(['work_id'=>$serviceWork->id,'worker_id'=>$params['user_id']])->count();
  849. if($appoint > 2){
  850. throw new Exception('您的修改预约时间次数已到上限,请联系客服处理');
  851. }
  852. ServiceWorkAppointmentLog::create([
  853. 'work_id'=>$serviceWork->id,
  854. 'worker_id'=>$params['user_id'],
  855. 'last_appointment_time'=>strtotime($serviceWork->appointment_time),
  856. 'this_appointment_time'=>strtotime($params['appointment_time']),
  857. ]);
  858. $serviceWork->appointment_time = strtotime($params['appointment_time']);
  859. $serviceWork->save();
  860. Db::commit();
  861. return true;
  862. } catch (\Exception $e) {
  863. Db::rollback();
  864. self::setError($e->getMessage());
  865. return false;
  866. }
  867. }
  868. public static function cancelAllocation($params,$userInfo){
  869. Db::startTrans();
  870. try {
  871. $work = ServiceWork::findOrEmpty($params['id']);
  872. if($work->isEmpty()){
  873. throw new Exception('工单不存在');
  874. }
  875. if($work->work_status >=6 ){
  876. throw new \Exception('工单状态只能修改待结算之前的');
  877. }
  878. $worker = MasterWorker::where(['id'=>$work->master_worker_id])->findOrEmpty();
  879. if($worker->isEmpty()){
  880. throw new \Exception('工程师不存在');
  881. }
  882. if ($work->tenant_id > 0) {
  883. //团队订单取消时,派单数量减1
  884. $updateData = date("H",strtotime($work->appointment_time)) < 12 ? ['am_order' => Db::raw('am_order - 1')] : ['pm_order' => Db::raw('pm_order - 1')];
  885. MasterWorkerTeam::where('master_worker_id',$work->master_worker_id)->where('tenant_id',$work->tenant_id)->update($updateData);
  886. }
  887. $params['master_worker_id'] = (isset($params['master_worker_id']) && !empty($params['master_worker_id']))?$params['master_worker_id']:$work->master_worker_id;
  888. MasterWorker::setWorktotal('dec',$work->master_worker_id);
  889. $work->master_worker_id = 0;
  890. $work->tenant_id = 0;
  891. $work->work_status = 0;
  892. $work->dispatch_time = 0;
  893. $work->first_contact_time = 0;
  894. $work->estimated_finish_time = 0;
  895. $work->exec_time = 0;
  896. $work->save();
  897. $work_log = [
  898. 'work_id'=>$work->id,
  899. 'master_worker_id'=>$params['master_worker_id'],
  900. 'type' => 1,
  901. 'opera_log'=>'后台用户['.$userInfo['admin_id'].']'.$userInfo['name'].'于'.date('Y-m-d H:i:s',time()).'取消了工程师'.'编号['.$worker->worker_number.']'.$worker->real_name
  902. ];
  903. ServiceWorkerAllocateWorkerLogic::add($work_log);
  904. Db::commit();
  905. return true;
  906. }catch(\Exception $e){
  907. Db::rollback();
  908. self::setError($e->getMessage());
  909. return false;
  910. }
  911. }
  912. public static function addCustomerLog($params)
  913. {
  914. Db::startTrans();
  915. try {
  916. $serviceWork = ServiceWork::where('id',$params['id'])->findOrEmpty();
  917. if($serviceWork->isEmpty()){
  918. throw new \Exception('工单不存在');
  919. }
  920. ServiceWorkCustomerLog::create([
  921. 'work_id'=>$serviceWork->id,
  922. 'content'=>$params['content']??'',
  923. 'admin_id'=>$params['admin_id']??0,
  924. 'create_time'=>time(),
  925. ]);
  926. Db::commit();
  927. return true;
  928. } catch (\Exception $e) {
  929. Db::rollback();
  930. self::setError($e->getMessage());
  931. return false;
  932. }
  933. }
  934. public static function distributeTenants($params,$userInfo)
  935. {
  936. Db::startTrans();
  937. try {
  938. if(empty($params['id']) || empty($params['tenant_id'])){
  939. throw new \Exception('参数错误'.json_encode($params));
  940. }
  941. if (is_array($params['id'])) {
  942. $ids = $params['id'];
  943. } else{
  944. $ids = [$params['id']];
  945. }
  946. // 取消工程师分配
  947. foreach ($ids as $id) {
  948. $res = self::cancelAllocation(['id'=>$id,'master_worker_id'=>''],$userInfo);
  949. if($res === false){
  950. Log::info('分配log'.self::getError());
  951. }
  952. }
  953. ServiceWork::whereIn('id',$ids)->update(['tenant_id'=>$params['tenant_id']]);
  954. Db::commit();
  955. return true;
  956. } catch (\Exception $e) {
  957. Db::rollback();
  958. self::setError($e->getMessage());
  959. return false;
  960. }
  961. }
  962. /**
  963. *
  964. * @return false|void
  965. */
  966. public static function contactCustomer($params)
  967. {
  968. try {
  969. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  970. if($work->isEmpty()){
  971. throw new \Exception('工单不存在');
  972. }
  973. if (empty($work->first_contact_time)) {
  974. $work->first_contact_time = time();
  975. $work->save();
  976. }
  977. return true;
  978. }
  979. catch (\Exception $e) {
  980. Db::rollback();
  981. self::setError($e->getMessage());
  982. return false;
  983. }
  984. }
  985. /**
  986. * 添加第三方平台订单
  987. * @return false|void
  988. */
  989. public static function addThirdPlatformsOrders($params)
  990. {
  991. try {
  992. return ThirdOrderLogic::submitOrders($params);
  993. }catch (\Exception $e) {
  994. self::setError($e->getMessage());
  995. return false;
  996. }
  997. }
  998. /**
  999. * 上门码和完成码
  1000. * @param $params
  1001. * @return false|array
  1002. */
  1003. public static function confirmDoorCode($params)
  1004. {
  1005. try {
  1006. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  1007. if($work->isEmpty()){
  1008. throw new Exception('工单不存在');
  1009. }
  1010. $encryptedData = encrypt($params['work_sn'], \think\facade\Config::get('project.work_sn_key'));
  1011. return ['url'=>\think\facade\Config::get('project.user_website').'?code='.$encryptedData];
  1012. }catch (\Exception $e) {
  1013. self::setError($e->getMessage());
  1014. return false;
  1015. }
  1016. }
  1017. /**
  1018. * 终止结束服务操作
  1019. */
  1020. public static function terminateService($params): bool
  1021. {
  1022. Db::startTrans();
  1023. try {
  1024. $serviceWork = ServiceWork::where('work_pay_status',1)
  1025. ->where('master_worker_id','>',0)
  1026. ->whereIn('work_status',[4,5,6])
  1027. ->where('id',$params['id'])->findOrEmpty();
  1028. if($serviceWork->isEmpty()){
  1029. throw new \Exception('该工单状态不可执行结束服务');
  1030. }
  1031. if($params['isearnest'] == 1){
  1032. $serviceWork->work_status = 7;
  1033. $serviceWork->user_confirm_status = 5;
  1034. $serviceWork->service_status = 3;
  1035. $serviceWork->work_pay_status = 1;
  1036. $serviceWork->remark = ($serviceWork->remark?:'')." | 终止结束服务:常规流程";
  1037. $serviceWork->save();
  1038. }else{
  1039. $paid_amount = RechargeOrder::where('work_id', $params['id'])->where('payment_type', 1)->value('paid_amount');
  1040. if($paid_amount > 0){
  1041. // 存在上门费给工程师
  1042. Log::info('终止结束服务工单'.$serviceWork->id.',上门费:'.$paid_amount);
  1043. WorkerAccountLogLogic::addAccountLog($serviceWork,$paid_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);
  1044. }
  1045. ServiceWork::where('id', $params['id'])->update([
  1046. 'work_status' => 7,
  1047. 'user_confirm_status' => 5,
  1048. 'service_status' => 3,
  1049. 'work_pay_status' => 2, // 已结算则不执行 onAfterUpdate
  1050. 'settlement_amount' => $paid_amount??0,
  1051. 'worker_price' => $paid_amount??0,
  1052. 'remark' => ($serviceWork->remark?:'')." | 终止结束服务:上门费-{$paid_amount}"
  1053. ]);
  1054. }
  1055. ServiceWorkLog::create([
  1056. 'work_id' => $params['id'],
  1057. 'master_worker_id' => $serviceWork->master_worker_id,
  1058. 'opera_log' => "工单:{$serviceWork->work_sn} 终止结束服务"
  1059. ]);
  1060. Db::commit();
  1061. Log::info('终止结束服务'.json_encode([$serviceWork]));
  1062. return true;
  1063. } catch (\Exception $e) {
  1064. Db::rollback();
  1065. self::setError($e->getMessage());
  1066. Log::info('终止结束服务-Error'.json_encode([$e->getMessage()]));
  1067. return false;
  1068. }
  1069. }
  1070. }