1
0

ServiceWorkLogic.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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. http_request(env('internal_api.api_url_host').'platf/performanceNotice',http_build_query([
  320. 'external_platform_id'=> $work->external_platform_id,
  321. 'send_code'=> 1006,
  322. 'work_sn'=> $work->work_sn
  323. ]));
  324. }
  325. }
  326. catch (\Exception $e) {
  327. Db::rollback();
  328. self::setError($e->getMessage());
  329. return false;
  330. }
  331. }
  332. /**
  333. * 工程师确认服务完成
  334. * @param $params
  335. * @return false|void
  336. */
  337. public static function confirmServiceFinish($params)
  338. {
  339. Db::startTrans();
  340. try {
  341. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  342. if($work->isEmpty()){
  343. throw new Exception('工单不存在');
  344. }
  345. if($work->user_confirm_status !=2){
  346. throw new Exception('请勿重复操作');
  347. }
  348. $work->finished_images = $params['finished_images'];
  349. $work->user_confirm_status = 3;//待确认服务完成
  350. $work->save();
  351. //添加变更日志
  352. $work_log = [
  353. 'work_id'=>$work->id,
  354. 'master_worker_id'=>$work->master_worker_id,
  355. '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()).'提交了待用户确认服务完成',
  356. ];
  357. ServiceWorkLogLogic::add($work_log);
  358. Db::commit();
  359. // 外部平台工单 - 通知外边平台
  360. if($work->external_platform_id > 0){
  361. event('ExternalPlatform', [
  362. 'scene' => 'service_finish',
  363. 'params' => [
  364. 'work_id' => $work->id,
  365. ]
  366. ]);
  367. }
  368. } catch (\Exception $e) {
  369. Db::rollback();
  370. self::setError($e->getMessage());
  371. return false;
  372. }
  373. }
  374. public static function allocateWorker($params,$userInfo){
  375. Db::startTrans();
  376. try {
  377. $work = ServiceWork::findOrEmpty($params['id']);
  378. if($work->isEmpty()){
  379. throw new Exception('工单不存在');
  380. }
  381. if($work->work_status >=6 ){
  382. throw new \Exception('工单状态只能修改待结算之前的');
  383. }
  384. if($work->master_worker_id == $params['master_worker_id']){
  385. throw new \Exception('分配的工程师相同');
  386. }
  387. $worker = MasterWorker::where(['id'=>$params['master_worker_id'],'is_disable' =>0])->findOrEmpty();
  388. if($worker->isEmpty()){
  389. throw new \Exception('工程师不存在或被禁用');
  390. }
  391. if($worker->master_worker_id){
  392. MasterWorker::setWorktotal('dec',$worker->master_worker_id);
  393. }
  394. $work->master_worker_id = $params['master_worker_id'];
  395. $work->work_status = 1;
  396. $work->dispatch_time = time();
  397. MasterWorker::setWorktotal('inc',$params['master_worker_id']);
  398. $work->save();
  399. $work_log = [
  400. 'work_id'=>$work->id,
  401. 'master_worker_id'=>$work->master_worker_id,
  402. 'type' => 0,
  403. 'opera_log'=>'后台用户['.$userInfo['admin_id'].']'.$userInfo['name'].'于'.date('Y-m-d H:i:s',time()).'分配了工程师'.'编号['.$worker->worker_number.']'.$worker->real_name
  404. ];
  405. ServiceWorkerAllocateWorkerLogic::add($work_log);
  406. Db::commit();
  407. //美团的订单更新履约状态为已分配
  408. if($work->third_type == 1){
  409. ThirdOrderLogic::updateorderfulfillinfo($work,ThirdTypeEnum::MEITUAN_MEITUAN);
  410. }
  411. // 工程师派单通知【给工程师的通知】【公众号通知,不发短信】
  412. $workDetail = ServiceWorkLogic::detail($params);
  413. $res = event('Notice', [
  414. 'scene_id' => 113,
  415. 'params' => [
  416. 'user_id' => $params['master_worker_id'],
  417. 'order_id' => $params['id'],
  418. 'thing9' => $workDetail['title'],
  419. 'time7' => $workDetail['appointment_time'],
  420. 'thing8' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  421. 'phone_number6' => asteriskString($workDetail['mobile']),
  422. ]
  423. ]);
  424. return true;
  425. }catch(\Exception $e){
  426. Db::rollback();
  427. self::setError($e->getMessage());
  428. return false;
  429. }
  430. }
  431. /**
  432. * 工单详情
  433. * @param $params
  434. * @return array|false
  435. */
  436. public static function detail($params){
  437. $work_where = !empty($params['work_sn'])?['work_sn'=>$params['work_sn']]:['id'=>$params['id']];
  438. $result = ServiceWork::with([
  439. 'worker'=> function(Query $query) {
  440. $query->field('id,worker_number,real_name,mobile');
  441. },
  442. 'allocateWorkerLog' =>function(Query $query){
  443. $query->field('id,work_id,opera_log,create_time');
  444. },
  445. 'serviceWorkLog' =>function(Query $query){
  446. $query->field('id,work_id,opera_log,create_time');
  447. }
  448. ])->append(['id','work_status_text','service_status_text'])
  449. ->where($work_where)
  450. ->findOrEmpty()->toArray();
  451. $result['is_operate_prohibit'] = 0;
  452. if(isset($params['user_id']) && $params['user_id'] && ($params['user_id'] != $result['master_worker_id']) ){
  453. // 带徒师傅的工单
  454. $lead_master_worker_id = TrainingWorkerTask::where('master_worker_id',$params['user_id'])->where('training_status',2)
  455. ->where('operate_status',0)->value('lead_master_worker_id');
  456. // 团队负责人编辑 工单池(包括已派队员) 工单
  457. if($params['user_info']['team_role'] == 1 && $params['user_info']['tenant_id'] == $result['tenant_id'] ){
  458. $result['is_operate_prohibit'] = 0;
  459. }elseif(!empty($lead_master_worker_id) && !empty($result['master_worker_id']) && $lead_master_worker_id == $result['master_worker_id']){
  460. // 徒查看师父的工单 不能编辑可查看
  461. $result['is_operate_prohibit'] = 1;
  462. }else{
  463. throw new \Exception('您没有权限操作该工单');
  464. }
  465. }
  466. //工程师工单按钮状态
  467. $work_service_status = 0;
  468. $work_service_status_text = '待派单';
  469. //工单状态
  470. if($result['work_status'] == 1){
  471. $work_service_status = 1;
  472. $work_service_status_text = '待领单';
  473. }
  474. if($result['work_status'] == 2){
  475. $work_service_status = 2;
  476. $work_service_status_text = '预约上门';
  477. }
  478. if($result['work_status'] == 3){
  479. $work_service_status = 3;
  480. $work_service_status_text = '等待上门';
  481. if(date('Y-m-d') === date('Y-m-d',strtotime($result['appointment_time']))){
  482. $work_service_status = 4;
  483. $work_service_status_text = '确认上门';
  484. }
  485. }
  486. if($result['work_status'] == 4 and $result['user_confirm_status']==0){
  487. $work_service_status = 5;
  488. $work_service_status_text = '确认报价';
  489. }
  490. if($result['work_status'] == 4 and $result['user_confirm_status']==1){
  491. $work_service_status = 6;
  492. $work_service_status_text = '用户确认报价中';
  493. }
  494. if($result['work_status'] == 5 and $result['user_confirm_status']==2){
  495. $work_service_status = 7;
  496. $work_service_status_text = '完成服务';
  497. }
  498. if($result['work_status'] == 5 and $result['user_confirm_status']==3){
  499. $work_service_status = 8;
  500. $work_service_status_text = '用户确认完成服务中';
  501. }
  502. if($result['work_status'] ==6){
  503. $work_service_status = 9;
  504. $work_service_status_text = '待结算';
  505. }
  506. if($result['work_status'] ==7){
  507. $work_service_status = 10;
  508. $work_service_status_text = '已完结';
  509. }
  510. if($result['work_status'] ==8){
  511. $work_service_status = 11;
  512. $work_service_status_text = '已评价';
  513. }
  514. if($result['work_status'] ==9){
  515. $work_service_status = 12;
  516. $work_service_status_text = '已退费';
  517. }
  518. $result['work_service_status'] = $work_service_status;
  519. $result['work_service_status_text'] = $work_service_status_text;
  520. //搜索当前工单下的所有订单记录
  521. $result['pay_orders'] = RechargeOrder::with(['orderGoods'=>function(Query $query){
  522. $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']);
  523. }])->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();
  524. $pay_status_data = DictData::where('type_value','pay_status')->column('name','value');
  525. $payment_type_data = DictData::where('type_value','payment_type')->column('name','value');
  526. $pay_way_data = DictData::where('type_value','pay_way')->column('name','value');
  527. $order_type_data = DictData::where('type_value','order_type')->column('name','value');
  528. $coupon_price = 0;
  529. foreach ($result['pay_orders'] as $k=>&$v){
  530. $v['pay_status_name'] = $pay_status_data[$v['pay_status']];
  531. $v['payment_type_name'] = $payment_type_data[$v['payment_type']];
  532. $v['pay_way_name'] = $pay_way_data[$v['pay_way']];
  533. $v['order_type_name'] = $order_type_data[$v['order_type']];
  534. $v['pay_time'] = $v['pay_time'] && is_numeric($v['pay_time']) ? date('Y-m-d H:i:s',$v['pay_time']):'';
  535. if($v['payment_type']!=1 and !empty($result['spare_total'])){
  536. $v['order_total'] = $v['order_total'] - $result['spare_total'];
  537. $v['order_amount'] = $v['order_amount'] - $result['spare_total'];
  538. }
  539. $coupon_price += $v['coupon_price'];
  540. //服务支付类别
  541. if(!empty($v['orderGoods'][0]['goods_payment_type'])){
  542. $goods_payment_type = $v['orderGoods'][0]['goods_payment_type'];
  543. }
  544. }
  545. $result['goods_payment_type'] = !empty($goods_payment_type)?$goods_payment_type:1;
  546. //汇总优惠卷额度
  547. $result['coupon_price'] = $coupon_price;
  548. //工单总支付金额
  549. $result['worker_account'] = $result['work_amount'];
  550. // 配件信息
  551. $result['spare_parts'] = [];
  552. if($result['service_work_spare_id']){
  553. $work_spare_parts = json_decode(ServiceWorkSpare::where('id',$result['service_work_spare_id'])->value('spare_parts'),true);
  554. $spare_parts = SparePart::where('id','in',array_column($work_spare_parts,'id'))
  555. ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit','spare_status'])
  556. ->select()
  557. ->toArray();
  558. $spare_parts = array_column($spare_parts,null,'id');
  559. foreach (array_column($work_spare_parts,null,'id') as $k=>&$v){
  560. $spare_parts[$k] = array_merge($spare_parts[$k],$v);
  561. }
  562. $result['spare_parts'] = array_values($spare_parts)??[];
  563. }
  564. // 保修卡信息
  565. $result['order_effectives'] = OrderEffectiveLog::with(['goods'=>function ($query) {
  566. $query->with(['goodsCategory'=>function ($query1) {
  567. $query1->field(['name','picture']);
  568. }]);
  569. }])->where('work_id',$result['id'])
  570. ->field(['id','goods_id','sn','effective_unit','effective_num','remark','end_effective_time'])
  571. ->append(['effective_unit_text'])
  572. ->order('create_time desc')
  573. ->select()
  574. ->toArray();
  575. //查收工程师提成金额
  576. $change_amount = MasterWorkerAccountLog::where(['work_sn'=>$result['work_sn'],'action'=>1])->value('change_amount');
  577. $result['change_amount'] = !empty($change_amount)?$change_amount:0;
  578. //质保金相关金额
  579. $result['retention'] = MasterWorkerRetentionMoneyLog::where('work_id',$result['id'])->visible(['action','amount'])->select()
  580. ->each(function ($item){
  581. $item['amount'] = $item['action'] == 1 ? '+'.$item['amount'] : '-'.$item['amount'];
  582. })->toArray();
  583. //保修工单时的信息
  584. $result['effective_income_amount'] = 0;
  585. if(!empty($result['order_effective_id'])){
  586. $order_effective = OrderEffectiveLog:: findOrEmpty($result['order_effective_id']);
  587. $serviceWork = ServiceWork::findOrEmpty($order_effective->work_id);
  588. if($serviceWork->master_worker_id != $result['master_worker_id']){
  589. $result['effective_income_amount'] = \app\adminapi\logic\effective\OrderEffectiveLogLogic::commissionAndAssuranceDeposit($serviceWork);
  590. }
  591. }
  592. //获取美团订单信息
  593. $result['meituan_order'] = [];
  594. if($result['third_type']==1){
  595. $result['meituan_order'] = ThirdOrders::where(['work_id'=>$result['id']])->order('create_time desc')->findOrEmpty();
  596. }
  597. return $result;
  598. }
  599. public static function getUserCouponDetails($params)
  600. {
  601. try{
  602. $work = ServiceWork::where('id',$params['id'])->findOrEmpty();
  603. if(!$work){
  604. throw new \Exception('工单不存在');
  605. }
  606. $coupon_all_ids =UserCoupon::where('user_id',$work['user_id'])
  607. ->where('voucher_count','>',0)
  608. ->where('voucher_status',0)
  609. ->where('expire_time','>',time())
  610. ->column('coupon_id');
  611. $coupon_ids = CouponCategory::where('goods_category_id',$work['goods_category_id'])->whereIn('coupon_id',$coupon_all_ids)->column('coupon_id');
  612. $data = UserCoupon::where('user_id',$work['user_id'])
  613. ->where('voucher_count','>',0)
  614. ->where('voucher_status',0)
  615. ->whereIn('coupon_id',$coupon_ids)
  616. ->append(['discount_ratio_text'])
  617. ->where('expire_time','>',time())
  618. ->visible(['id','coupon_id','amount','amount_require','begin_use','discount_ratio','event_name','expire_time','max_deductible_price','server_category_name','mold_type'])
  619. ->select()->toArray();
  620. foreach($data as $k => $v){
  621. $data[$k]['begin_use'] = date("Y-m-d H:i:s",$v['begin_use'] );
  622. $data[$k]['expire_time'] = date("Y-m-d H:i:s",$v['expire_time'] );
  623. $data[$k]['amount_require'] = '满'.$v['amount_require'].'可用';
  624. }
  625. return $data;
  626. } catch(\Exception $e){
  627. self::setError($e->getMessage());
  628. return false;
  629. }
  630. }
  631. public static function getDetailWorkServiceStatus($params)
  632. {
  633. $result = ServiceWork::where('id',$params['id'])->field('work_status,user_confirm_status,appointment_time,price_approval,appoint_approval')->findOrEmpty()->toArray();
  634. //工程师工单按钮状态
  635. $work_service_status = 0;
  636. //工单状态
  637. if($result['work_status'] == 1){
  638. $work_service_status = 1;
  639. }
  640. if($result['work_status'] == 2){
  641. $work_service_status = 2;
  642. }
  643. if($result['work_status'] == 3){
  644. $work_service_status = 3;
  645. if(date('Y-m-d') === date('Y-m-d',strtotime($result['appointment_time']))){
  646. $work_service_status = 4;
  647. }
  648. }
  649. if($result['work_status'] == 4 and $result['user_confirm_status']==0){
  650. $work_service_status = 5;
  651. }
  652. if($result['work_status'] == 4 and $result['user_confirm_status']==1){
  653. $work_service_status = 6;
  654. }
  655. if($result['work_status'] == 5 and $result['user_confirm_status']==2){
  656. $work_service_status = 7;
  657. }
  658. if($result['work_status'] == 5 and $result['user_confirm_status']==3){
  659. $work_service_status = 8;
  660. }
  661. if($result['work_status'] ==6){
  662. $work_service_status = 9;
  663. }
  664. if($result['work_status'] ==7){
  665. $work_service_status = 10;
  666. }
  667. if($result['work_status'] ==8){
  668. $work_service_status = 11;
  669. }
  670. if($result['work_status'] ==9){
  671. $work_service_status = 12;
  672. }
  673. return ['work_service_status'=>$work_service_status,'price_approval'=>$result['price_approval'],'appoint_approval'=>$result['appoint_approval']];
  674. }
  675. /**
  676. * @notes 取消操作
  677. * @param array $params
  678. * @return bool
  679. * @author likeadmin
  680. * @date 2024/09/19 10:48
  681. */
  682. public static function cancel(array $params): bool
  683. {
  684. Db::startTrans();
  685. try {
  686. // 04-11-12 不做任何限制强制取消,已支付的费用给工程师余额
  687. $serviceWorkInfo = ServiceWork::find($params['id']);
  688. if((int)$serviceWorkInfo['user_confirm_status'] === 5 || (int)$serviceWorkInfo['service_status'] > 2){
  689. throw new \Exception('用户已完结该工单或已取消,已退款,不可执行取消');
  690. }
  691. //工单如果存在费用情况,不允许取消
  692. $paid_amount = RechargeOrder::where('work_id', $params['id'])->where('pay_status', 1)->value('paid_amount');
  693. if($paid_amount > 0 and ($serviceWorkInfo['third_type'] == 0 && $serviceWorkInfo['external_platform_id'] == 0)){
  694. // 4=已上门,5=服务中,6=待结算, 即工程师已上门服务过
  695. throw new Exception('工单存在费用情况,不允许取消,请走退费流程');
  696. }
  697. ServiceWork::where('id', $params['id'])->update([
  698. //'work_status' => 9,
  699. 'service_status' => 4,
  700. 'remark' => $params['remark']??''
  701. ]);
  702. ServiceWorkLog::create([
  703. 'work_id' => $params['id'],
  704. 'master_worker_id' => $serviceWorkInfo['master_worker_id'],
  705. 'opera_log' => "工单:{$serviceWorkInfo['work_sn']}已取消"
  706. ]);
  707. Db::commit();
  708. Log::info('取消工单'.json_encode([$serviceWorkInfo]));
  709. return true;
  710. } catch (\Exception $e) {
  711. Db::rollback();
  712. self::setError($e->getMessage());
  713. Log::info('取消工单-Error'.json_encode([$e->getMessage()]));
  714. return false;
  715. }
  716. }
  717. /**
  718. * @notes 工程师结算操作
  719. * @param array $params
  720. * @return bool
  721. * @author likeadmin
  722. * @date 2024/09/19 10:48
  723. */
  724. public static function settlement(array $params): bool
  725. {
  726. Db::startTrans();
  727. try {
  728. $serviceWorkInfo = ServiceWork::find($params['id']);
  729. if((int)$serviceWorkInfo['work_pay_status'] !== 3){
  730. throw new \Exception('该工单非待结算状态');
  731. }
  732. $ratio = 0;
  733. $commissionConfig = MasterWorkerCommissionConfig::where('master_worker_id',$serviceWorkInfo->master_worker_id)->where('voucher_status',2)->findOrEmpty();
  734. !$commissionConfig->isEmpty() && $ratio = MasterWorkerCommissionRatio::where('commission_config_id',$commissionConfig['id'])->where('goods_category_id',$serviceWorkInfo->goods_category_id)->value('ratio')?:0;
  735. if($commissionConfig->isEmpty() || empty($ratio)){
  736. //获取工单对应的商品id
  737. $order_sns = \app\common\model\orders\RechargeOrder::where('work_id',$serviceWorkInfo->id)->column('sn');
  738. $goods_id = OrderGoods::whereIn('sn',$order_sns)->value('goods_id');
  739. $rule = PerformanceRules::whereFindInSet('goods_id',$goods_id)->findOrEmpty();
  740. if($rule->isEmpty()){
  741. throw new \Exception('请配置商品业绩规则');
  742. }
  743. PerformanceLogic::calculatePerformance($serviceWorkInfo);
  744. }else{
  745. // 存在服务分类比例进行结算
  746. PerformanceLogic::calculatePerformanceCommission($serviceWorkInfo);
  747. }
  748. Db::commit();
  749. return true;
  750. } catch (\Exception $e) {
  751. Db::rollback();
  752. self::setError($e->getMessage());
  753. return false;
  754. }
  755. }
  756. /**
  757. * 获取所有改约通知
  758. * @param $userId
  759. * @return array|false
  760. */
  761. public static function getAppointmentNotice($userId)
  762. {
  763. return ServiceWork::where(['master_worker_id'=>$userId,'appoint_approval'=>1])
  764. ->where('work_status','>',1)
  765. ->where('work_status','<',7)
  766. ->field(['id', 'work_sn','real_name','mobile', 'address', 'title', 'appointment_time','work_status'])
  767. ->order(['appointment_time' => 'asc'])//上门时间排序
  768. ->select()->each(function (&$item){
  769. $item['last_appointment_time'] = date('Y-m-d H:i:s',ServiceWorkAppointmentLog::where('work_id',$item['id'])->order('id desc')->value('last_appointment_time'));
  770. })
  771. ->toArray();
  772. }
  773. /**
  774. * @param $params
  775. * @return bool
  776. */
  777. public static function submitAppointment($params)
  778. {
  779. Db::startTrans();
  780. try {
  781. $serviceWork = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  782. if($serviceWork->isEmpty()){
  783. throw new \Exception('工单不存在');
  784. }
  785. $serviceWork->appoint_approval = 2;
  786. $serviceWork->save();
  787. Db::commit();
  788. return true;
  789. } catch (\Exception $e) {
  790. Db::rollback();
  791. self::setError($e->getMessage());
  792. return false;
  793. }
  794. }
  795. /**
  796. * @param $params
  797. * @return bool
  798. */
  799. public static function submitChangePrice($params)
  800. {
  801. Db::startTrans();
  802. try {
  803. $serviceWork = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  804. if($serviceWork->isEmpty()){
  805. throw new \Exception('工单不存在');
  806. }
  807. $serviceWork->work_status = 4;
  808. $serviceWork->user_confirm_status = 0;
  809. $serviceWork->price_approval = 2;
  810. $serviceWork->save();
  811. Db::commit();
  812. return true;
  813. } catch (\Exception $e) {
  814. Db::rollback();
  815. self::setError($e->getMessage());
  816. return false;
  817. }
  818. }
  819. public static function notApproved($params)
  820. {
  821. Db::startTrans();
  822. try {
  823. $serviceWork = ServiceWork::where('id',$params['id'])->findOrEmpty();
  824. if($serviceWork->isEmpty()){
  825. throw new \Exception('工单不存在');
  826. }
  827. $serviceWork->refund_approval = 3;
  828. $serviceWork->save();
  829. Db::commit();
  830. return true;
  831. } catch (\Exception $e) {
  832. Db::rollback();
  833. self::setError($e->getMessage());
  834. return false;
  835. }
  836. }
  837. public static function againDoor($params)
  838. {
  839. Db::startTrans();
  840. try {
  841. $serviceWork = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  842. if($serviceWork->isEmpty()){
  843. throw new \Exception('工单不存在');
  844. }
  845. //更新预约日志
  846. //更新工单未确认上门的状态
  847. $serviceWork->work_status = 3;
  848. $serviceWork->user_confirm_status = 0;
  849. $appoint = ServiceWorkAppointmentLog::where(['work_id'=>$serviceWork->id,'worker_id'=>$params['user_id']])->count();
  850. if($appoint > 2){
  851. throw new Exception('您的修改预约时间次数已到上限,请联系客服处理');
  852. }
  853. ServiceWorkAppointmentLog::create([
  854. 'work_id'=>$serviceWork->id,
  855. 'worker_id'=>$params['user_id'],
  856. 'last_appointment_time'=>strtotime($serviceWork->appointment_time),
  857. 'this_appointment_time'=>strtotime($params['appointment_time']),
  858. ]);
  859. $serviceWork->appointment_time = strtotime($params['appointment_time']);
  860. $serviceWork->save();
  861. Db::commit();
  862. return true;
  863. } catch (\Exception $e) {
  864. Db::rollback();
  865. self::setError($e->getMessage());
  866. return false;
  867. }
  868. }
  869. public static function cancelAllocation($params,$userInfo){
  870. Db::startTrans();
  871. try {
  872. $work = ServiceWork::findOrEmpty($params['id']);
  873. if($work->isEmpty()){
  874. throw new Exception('工单不存在');
  875. }
  876. if($work->work_status >=6 ){
  877. throw new \Exception('工单状态只能修改待结算之前的');
  878. }
  879. $worker = MasterWorker::where(['id'=>$work->master_worker_id])->findOrEmpty();
  880. if($worker->isEmpty()){
  881. throw new \Exception('工程师不存在');
  882. }
  883. if ($work->tenant_id > 0) {
  884. //团队订单取消时,派单数量减1
  885. $updateData = date("H",strtotime($work->appointment_time)) < 12 ? ['am_order' => Db::raw('am_order - 1')] : ['pm_order' => Db::raw('pm_order - 1')];
  886. MasterWorkerTeam::where('master_worker_id',$work->master_worker_id)->where('tenant_id',$work->tenant_id)->update($updateData);
  887. }
  888. $params['master_worker_id'] = (isset($params['master_worker_id']) && !empty($params['master_worker_id']))?$params['master_worker_id']:$work->master_worker_id;
  889. MasterWorker::setWorktotal('dec',$work->master_worker_id);
  890. $work->master_worker_id = 0;
  891. $work->tenant_id = 0;
  892. $work->work_status = 0;
  893. $work->dispatch_time = 0;
  894. $work->first_contact_time = 0;
  895. $work->estimated_finish_time = 0;
  896. $work->exec_time = 0;
  897. $work->save();
  898. $work_log = [
  899. 'work_id'=>$work->id,
  900. 'master_worker_id'=>$params['master_worker_id'],
  901. 'type' => 1,
  902. 'opera_log'=>'后台用户['.$userInfo['admin_id'].']'.$userInfo['name'].'于'.date('Y-m-d H:i:s',time()).'取消了工程师'.'编号['.$worker->worker_number.']'.$worker->real_name
  903. ];
  904. ServiceWorkerAllocateWorkerLogic::add($work_log);
  905. Db::commit();
  906. return true;
  907. }catch(\Exception $e){
  908. Db::rollback();
  909. self::setError($e->getMessage());
  910. return false;
  911. }
  912. }
  913. public static function addCustomerLog($params)
  914. {
  915. Db::startTrans();
  916. try {
  917. $serviceWork = ServiceWork::where('id',$params['id'])->findOrEmpty();
  918. if($serviceWork->isEmpty()){
  919. throw new \Exception('工单不存在');
  920. }
  921. ServiceWorkCustomerLog::create([
  922. 'work_id'=>$serviceWork->id,
  923. 'content'=>$params['content']??'',
  924. 'admin_id'=>$params['admin_id']??0,
  925. 'create_time'=>time(),
  926. ]);
  927. Db::commit();
  928. return true;
  929. } catch (\Exception $e) {
  930. Db::rollback();
  931. self::setError($e->getMessage());
  932. return false;
  933. }
  934. }
  935. public static function distributeTenants($params,$userInfo)
  936. {
  937. Db::startTrans();
  938. try {
  939. if(empty($params['id']) || empty($params['tenant_id'])){
  940. throw new \Exception('参数错误'.json_encode($params));
  941. }
  942. if (is_array($params['id'])) {
  943. $ids = $params['id'];
  944. } else{
  945. $ids = [$params['id']];
  946. }
  947. // 取消工程师分配
  948. foreach ($ids as $id) {
  949. $res = self::cancelAllocation(['id'=>$id,'master_worker_id'=>''],$userInfo);
  950. if($res === false){
  951. Log::info('分配log'.self::getError());
  952. }
  953. }
  954. ServiceWork::whereIn('id',$ids)->update(['tenant_id'=>$params['tenant_id']]);
  955. Db::commit();
  956. return true;
  957. } catch (\Exception $e) {
  958. Db::rollback();
  959. self::setError($e->getMessage());
  960. return false;
  961. }
  962. }
  963. /**
  964. *
  965. * @return false|void
  966. */
  967. public static function contactCustomer($params)
  968. {
  969. try {
  970. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  971. if($work->isEmpty()){
  972. throw new \Exception('工单不存在');
  973. }
  974. if (empty($work->first_contact_time)) {
  975. $work->first_contact_time = time();
  976. $work->save();
  977. }
  978. return true;
  979. }
  980. catch (\Exception $e) {
  981. Db::rollback();
  982. self::setError($e->getMessage());
  983. return false;
  984. }
  985. }
  986. /**
  987. * 添加第三方平台订单
  988. * @return false|void
  989. */
  990. public static function addThirdPlatformsOrders($params)
  991. {
  992. try {
  993. return ThirdOrderLogic::submitOrders($params);
  994. }catch (\Exception $e) {
  995. self::setError($e->getMessage());
  996. return false;
  997. }
  998. }
  999. /**
  1000. * 上门码和完成码
  1001. * @param $params
  1002. * @return false|array
  1003. */
  1004. public static function confirmDoorCode($params)
  1005. {
  1006. try {
  1007. $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
  1008. if($work->isEmpty()){
  1009. throw new Exception('工单不存在');
  1010. }
  1011. $encryptedData = encrypt($params['work_sn'], \think\facade\Config::get('project.work_sn_key'));
  1012. return ['url'=>\think\facade\Config::get('project.user_website').'?code='.$encryptedData];
  1013. }catch (\Exception $e) {
  1014. self::setError($e->getMessage());
  1015. return false;
  1016. }
  1017. }
  1018. /**
  1019. * 终止结束服务操作
  1020. */
  1021. public static function terminateService($params): bool
  1022. {
  1023. Db::startTrans();
  1024. try {
  1025. $serviceWork = ServiceWork::where('work_pay_status',1)
  1026. ->where('master_worker_id','>',0)
  1027. ->whereIn('work_status',[4,5,6])
  1028. ->where('id',$params['id'])->findOrEmpty();
  1029. if($serviceWork->isEmpty()){
  1030. throw new \Exception('该工单状态不可执行结束服务');
  1031. }
  1032. if($params['isearnest'] == 1){
  1033. $serviceWork->work_status = 7;
  1034. $serviceWork->user_confirm_status = 5;
  1035. $serviceWork->service_status = 3;
  1036. $serviceWork->work_pay_status = 1;
  1037. $serviceWork->remark = ($serviceWork->remark?:'')." | 终止结束服务:常规流程";
  1038. $serviceWork->save();
  1039. }else{
  1040. $paid_amount = RechargeOrder::where('work_id', $params['id'])->where('payment_type', 1)->value('paid_amount');
  1041. if($paid_amount > 0){
  1042. // 存在上门费给工程师
  1043. Log::info('终止结束服务工单'.$serviceWork->id.',上门费:'.$paid_amount);
  1044. WorkerAccountLogLogic::addAccountLog($serviceWork,$paid_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);
  1045. }
  1046. ServiceWork::where('id', $params['id'])->update([
  1047. 'work_status' => 7,
  1048. 'user_confirm_status' => 5,
  1049. 'service_status' => 3,
  1050. 'work_pay_status' => 2, // 已结算则不执行 onAfterUpdate
  1051. 'settlement_amount' => $paid_amount??0,
  1052. 'worker_price' => $paid_amount??0,
  1053. 'remark' => ($serviceWork->remark?:'')." | 终止结束服务:上门费-{$paid_amount}"
  1054. ]);
  1055. }
  1056. ServiceWorkLog::create([
  1057. 'work_id' => $params['id'],
  1058. 'master_worker_id' => $serviceWork->master_worker_id,
  1059. 'opera_log' => "工单:{$serviceWork->work_sn} 终止结束服务"
  1060. ]);
  1061. Db::commit();
  1062. Log::info('终止结束服务'.json_encode([$serviceWork]));
  1063. return true;
  1064. } catch (\Exception $e) {
  1065. Db::rollback();
  1066. self::setError($e->getMessage());
  1067. Log::info('终止结束服务-Error'.json_encode([$e->getMessage()]));
  1068. return false;
  1069. }
  1070. }
  1071. }