ServiceWorkLogic.php 47 KB

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