WorksController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. namespace app\workerapi\controller;
  3. use app\adminapi\logic\master_worker\MasterWorkerLogic;
  4. use app\adminapi\logic\works\ServiceWorkLogic;
  5. use app\api\logic\UserCouponLogic;
  6. use app\common\model\works\IssueWork;
  7. use app\common\model\works\ReturnWork;
  8. use app\common\model\works\ServiceWork;
  9. use app\workerapi\lists\HistoryWorkLists;
  10. use app\workerapi\lists\ServiceAssignWorkLists;
  11. use app\workerapi\lists\GoodsFeeStandardsLists;
  12. use app\workerapi\lists\ServiceWorkGrabOrderLists;
  13. use app\workerapi\lists\ServiceWorkGrabOrderLogLists;
  14. use app\workerapi\lists\ServiceWorkLists;
  15. use app\workerapi\lists\ServiceWorkSparePartLists;
  16. use app\workerapi\lists\SparePartLists;
  17. use app\workerapi\validate\ServiceWorkValidate;
  18. use app\workerapi\validate\GoodsFeeStandardsValidate;
  19. use Exception;
  20. /**
  21. * 工单系统
  22. */
  23. class WorksController extends BaseApiController
  24. {
  25. public array $notNeedLogin = ['grabOrder','shareServiceWorkDetail'];
  26. /**
  27. * 首页数量统计
  28. * @return \think\response\Json
  29. * @throws \think\db\exception\DbException
  30. */
  31. public function statistics()
  32. {
  33. $result['service_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId])->whereIn('service_status','0,1,2')->where('work_status','<>',1)->where('work_pay_status','>',0)->count();
  34. $result['assign_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>1])->where('work_pay_status','>',0)->count();
  35. $result['pick_work_count'] = 0;
  36. $result['return_work_count'] = ReturnWork::where(['master_worker_id'=>$this->userId])->where('return_work_status','<>',4)->count();
  37. $result['issue_work_count'] = IssueWork::where(['master_worker_id'=>$this->userId])->whereIn('issue_approval','1,2,3')->count();
  38. $result['review_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>7])->count();
  39. return $this->data($result);
  40. }
  41. /**
  42. * 服务工单列表-全部
  43. * @return \think\response\Json
  44. */
  45. public function serviceWorkList()
  46. {
  47. return $this->dataLists(new ServiceWorkLists());
  48. }
  49. /**
  50. * 派单
  51. * @return \think\response\Json
  52. */
  53. public function assignWorkList()
  54. {
  55. return $this->dataLists(new ServiceAssignWorkLists());
  56. }
  57. /**
  58. * 历史工单
  59. * @return \think\response\Json
  60. */
  61. public function historyWorkList()
  62. {
  63. return $this->dataLists(new HistoryWorkLists());
  64. }
  65. /**
  66. * 领取服务单
  67. * @return \think\response\Json
  68. */
  69. public function pickWork()
  70. {
  71. $params = (new ServiceWorkValidate())->post()->goCheck('pick', [
  72. 'user_id' => $this->userId,
  73. 'user_info' => $this->userInfo
  74. ]);
  75. $result = ServiceWorkLogic::pickWork($params);
  76. if (false === $result) {
  77. return $this->fail(ServiceWorkLogic::getError());
  78. }
  79. // 用户订单被领单通知【给用户的通知】
  80. $workDetail = ServiceWorkLogic::detail($params);
  81. event('Notice', [
  82. 'scene_id' => 114,
  83. 'params' => [
  84. 'user_id' => $workDetail['user_id'],
  85. ]
  86. ]);
  87. return $this->success('领取成功', [], 1, 1);
  88. }
  89. /**
  90. * 工单详情
  91. * @return \think\response\Json
  92. */
  93. public function detail()
  94. {
  95. try {
  96. $params = (new ServiceWorkValidate())->goCheck('detail',[
  97. 'user_id' => $this->userId,
  98. 'user_info' => $this->userInfo,
  99. ]);
  100. if(empty($params['id']) && empty($params['work_sn'])){
  101. $this->fail('参数错误');
  102. }
  103. $result = ServiceWorkLogic::detail($params);
  104. if (false === $result) {
  105. return $this->fail(ServiceWorkLogic::getError());
  106. }
  107. return $this->data($result);
  108. } catch (Exception $e) {
  109. return $this->fail($e->getMessage());
  110. }
  111. }
  112. /**
  113. * 获取用户优惠券
  114. * @return \think\response\Json
  115. */
  116. public function getUserCoupons()
  117. {
  118. try {
  119. $params = (new ServiceWorkValidate())->goCheck('detail',[
  120. 'user_id' => $this->userId,
  121. ]);
  122. if(empty($params['id'])){
  123. $this->fail('参数错误');
  124. }
  125. $result = ServiceWorkLogic::getUserCouponDetails($params);
  126. if (false === $result) {
  127. return $this->fail(ServiceWorkLogic::getError());
  128. }
  129. return $this->data($result);
  130. } catch (Exception $e) {
  131. return $this->fail($e->getMessage());
  132. }
  133. }
  134. /**
  135. *
  136. * @return \think\response\Json
  137. */
  138. public function getDetailWorkServiceStatus()
  139. {
  140. $params = (new ServiceWorkValidate())->goCheck('detail',[
  141. 'user_id' => $this->userId,
  142. ]);
  143. $result = ServiceWorkLogic::getDetailWorkServiceStatus($params);
  144. if (false === $result) {
  145. return $this->fail(ServiceWorkLogic::getError());
  146. }
  147. return $this->data($result);
  148. }
  149. /**
  150. * 预约上门
  151. * @return \think\response\Json
  152. */
  153. public function appointWork()
  154. {
  155. $params = (new ServiceWorkValidate())->post()->goCheck('appoint', [
  156. 'user_id' => $this->userId,
  157. 'user_info' => $this->userInfo
  158. ]);
  159. $result = ServiceWorkLogic::appointWork($params);
  160. if (false === $result) {
  161. return $this->fail(ServiceWorkLogic::getError());
  162. }
  163. // 工程师预约上门通知【给用户的通知】
  164. $workDetail = ServiceWorkLogic::detail($params);
  165. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  166. event('Notice', [
  167. 'scene_id' => 115,
  168. 'params' => [
  169. 'user_id' => $workDetail['user_id'],
  170. 'date' => $workDetail['appointment_time'],
  171. 'tel' => asteriskString($masterDetail['mobile'])
  172. ]
  173. ]);
  174. // 工程师预约上门通知【给工程师的通知,仅限公众号】
  175. event('Notice', [
  176. 'scene_id' => 116,
  177. 'params' => [
  178. 'user_id' => $workDetail['master_worker_id'],
  179. 'order_id' => $workDetail['id'],
  180. 'thing5' => $workDetail['title'],
  181. 'time10' => $workDetail['appointment_time'],
  182. 'thing3' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  183. ]
  184. ]);
  185. return $this->success('预约成功,等待上门', [], 1, 1);
  186. }
  187. /**
  188. * 工程师确认上门
  189. * @return \think\response\Json
  190. */
  191. public function confirmDoor()
  192. {
  193. $params = (new ServiceWorkValidate())->post()->goCheck('door', [
  194. 'user_id' => $this->userId,
  195. 'user_info' => $this->userInfo
  196. ]);
  197. $result = ServiceWorkLogic::confirmDoor($params);
  198. if (false === $result) {
  199. return $this->fail(ServiceWorkLogic::getError());
  200. }
  201. return $this->success('操作成功,工程师已上门', [], 1, 1);
  202. }
  203. /**
  204. * 工程师确认报价单
  205. * @return \think\response\Json
  206. */
  207. public function confirmPrice()
  208. {
  209. $params = (new ServiceWorkValidate())->post()->goCheck('price', [
  210. 'user_id' => $this->userId,
  211. 'user_info' => $this->userInfo
  212. ]);
  213. $result = ServiceWorkLogic::confirmPrice($params);
  214. if (false === $result) {
  215. return $this->fail(ServiceWorkLogic::getError());
  216. }
  217. return $this->success('操作成功,工程师已填写报价单,等待用户确认中', [], 1, 1);
  218. }
  219. /**
  220. * 工程师确认服务完成
  221. * @return \think\response\Json
  222. */
  223. public function confirmServiceFinish()
  224. {
  225. $params = (new ServiceWorkValidate())->post()->goCheck('finished', [
  226. 'user_id' => $this->userId,
  227. 'user_info' => $this->userInfo
  228. ]);
  229. $result = ServiceWorkLogic::confirmServiceFinish($params);
  230. if (false === $result) {
  231. return $this->fail(ServiceWorkLogic::getError());
  232. }
  233. return $this->success('操作成功,工程师已确认服务完成,等待用户确认中', [], 1, 1);
  234. }
  235. /**
  236. * 配件列表
  237. * @return \think\response\Json
  238. */
  239. public function spareList()
  240. {
  241. // 查全部可选配件
  242. return $this->dataLists(new SparePartLists());
  243. }
  244. /**
  245. * 工单配件列表
  246. * @return \think\response\Json
  247. */
  248. public function serviceWorkSpareList()
  249. {
  250. // 查该订单的配件
  251. (new ServiceWorkValidate())->get()->goCheck('spare', [
  252. 'user_id' => $this->userId
  253. ]);
  254. return $this->dataLists(new ServiceWorkSparePartLists());
  255. }
  256. /**
  257. * 工单收费标准列表
  258. * @return \think\response\Json
  259. */
  260. public function serviceFeeStandards()
  261. {
  262. // 查该订单的配件
  263. (new GoodsFeeStandardsValidate())->get()->goCheck('standards', [
  264. 'user_id' => $this->userId
  265. ]);
  266. return $this->dataLists(new GoodsFeeStandardsLists());
  267. }
  268. /**
  269. * 预约通知确认
  270. * @return \think\response\Json
  271. */
  272. public function appointmentSubmitNotice()
  273. {
  274. $params = (new ServiceWorkValidate())->post()->goCheck('submitAppointment', [
  275. 'user_id' => $this->userId,
  276. 'user_info' => $this->userInfo
  277. ]);
  278. $result = ServiceWorkLogic::submitAppointment($params);
  279. if (false === $result) {
  280. return $this->fail(ServiceWorkLogic::getError());
  281. }
  282. // 工程师再次上门通知【给用户的通知】
  283. $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
  284. event('Notice', [
  285. 'scene_id' => 119,
  286. 'params' => [
  287. 'user_id' => $workDetail['user_id'],
  288. ]
  289. ]);
  290. return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
  291. }
  292. /**
  293. * 再次上门
  294. * @return \think\response\Json
  295. */
  296. public function againDoor()
  297. {
  298. $params = (new ServiceWorkValidate())->post()->goCheck('againDoor', [
  299. 'user_id' => $this->userId,
  300. 'user_info' => $this->userInfo
  301. ]);
  302. $result = ServiceWorkLogic::againDoor($params);
  303. if (false === $result) {
  304. return $this->fail(ServiceWorkLogic::getError());
  305. }
  306. // 工程师再次上门通知【给用户的通知】
  307. $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
  308. event('Notice', [
  309. 'scene_id' => 119,
  310. 'params' => [
  311. 'user_id' => $workDetail['user_id'],
  312. ]
  313. ]);
  314. return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
  315. }
  316. /**
  317. * 电话联系客户(虚拟拨号)
  318. * @return \think\response\Json
  319. */
  320. public function contactCustomer()
  321. {
  322. $params = (new ServiceWorkValidate())->post()->goCheck('contact', [
  323. 'user_id' => $this->userId,
  324. 'user_info' => $this->userInfo
  325. ]);
  326. $result = ServiceWorkLogic::contactCustomer($params);
  327. if (false === $result) {
  328. return $this->fail(ServiceWorkLogic::getError());
  329. }
  330. return $this->data($result);
  331. }
  332. /**
  333. * 上门码和完成码
  334. * @return \think\response\Json
  335. */
  336. public function showDoorCode(): \think\response\Json
  337. {
  338. $params = (new ServiceWorkValidate())->get()->goCheck('door', [
  339. 'user_id' => $this->userId,
  340. 'user_info' => $this->userInfo
  341. ]);
  342. $result = ServiceWorkLogic::confirmDoorCode($params);
  343. if (false === $result) {
  344. return $this->fail(ServiceWorkLogic::getError());
  345. }
  346. return $this->success('操作成功,工程师已上门,请用户扫码确认', $result, 1, 1);
  347. }
  348. /**
  349. * 工程师取消自己的分配
  350. * @return \think\response\Json
  351. * @author liugc <466014217@qq.com>
  352. * @date 2025/4/28 15:08
  353. */
  354. public function cancelMasterWorker()
  355. {
  356. $params = (new ServiceWorkValidate())->post()->goCheck('cancel', [
  357. 'user_id' => $this->userId,
  358. 'user_info' => $this->userInfo
  359. ]);
  360. $result = ServiceWorkLogic::cancelAllocation(['id'=>$params['id'],'master_worker_id'=>$this->userId],['admin_id'=>$this->userId,'name'=>'工程师-'.$this->userInfo['mobile']], 2);
  361. if (false === $result) {
  362. return $this->fail(ServiceWorkLogic::getError());
  363. }
  364. return $this->success('成功', [], 1, 1);
  365. }
  366. /**
  367. * 工程师抢单池
  368. * @return \think\response\Json
  369. * @author liugc <466014217@qq.com>
  370. * @date 2025/5/7 15:08
  371. */
  372. public function grabOrderList()
  373. {
  374. return $this->dataLists(new ServiceWorkGrabOrderLists());
  375. }
  376. /**
  377. * 工程师抢单记录列表
  378. * @return \think\response\Json
  379. * @author liugc <466014217@qq.com>
  380. * @date 2025/5/7 15:08
  381. */
  382. public function grabOrderLog()
  383. {
  384. return $this->dataLists(new ServiceWorkGrabOrderLogLists());
  385. }
  386. /**
  387. * 工程师抢单
  388. * @return \think\response\Json
  389. * @author liugc <466014217@qq.com>
  390. * @date 2025/5/7 15:08
  391. */
  392. public function grabOrder()
  393. {
  394. $params = (new ServiceWorkValidate())->post()->goCheck('cancel');
  395. $result = ServiceWorkLogic::grabOrder(['id'=>$params['id'],'master_worker_id'=>$this->userId]);
  396. if (false === $result) {
  397. return $this->fail(ServiceWorkLogic::getError());
  398. }
  399. return $this->success('抢单成功', [], 1, 1);
  400. }
  401. /**
  402. * 工程师修改自选配件信息
  403. * @return \think\response\Json
  404. * @author liugc <466014217@qq.com>
  405. * @date 2025/5/7 15:08
  406. */
  407. public function selfSparePart()
  408. {
  409. $params = (new ServiceWorkValidate())->post()->goCheck('sparepart', [
  410. 'user_id' => $this->userId,
  411. ]);
  412. $result = ServiceWorkLogic::selfSparePart($params);
  413. if (false === $result) {
  414. return $this->fail(ServiceWorkLogic::getError());
  415. }
  416. return $this->success('修改成功', [], 1, 1);
  417. }
  418. /**
  419. * 扫码分享的工单 - 获取工单信息
  420. * @return \think\response\Json
  421. * @author liugc <466014217@qq.com>
  422. * @date 2025/5/7 15:08
  423. */
  424. public function shareServiceWorkDetail()
  425. {
  426. try {
  427. $params = request()->post();
  428. $result = ServiceWorkLogic::shareServiceWorkDetail($params);
  429. return $this->data($result);
  430. } catch (Exception $e) {
  431. return $this->fail($e->getMessage());
  432. }
  433. }
  434. }