1
0

WorksController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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\ServiceWorkLists;
  13. use app\workerapi\lists\ServiceWorkSparePartLists;
  14. use app\workerapi\lists\SparePartLists;
  15. use app\workerapi\validate\ServiceWorkValidate;
  16. use app\workerapi\validate\GoodsFeeStandardsValidate;
  17. use Exception;
  18. /**
  19. * 工单系统
  20. */
  21. class WorksController extends BaseApiController
  22. {
  23. /**
  24. * 首页数量统计
  25. * @return \think\response\Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function statistics()
  29. {
  30. $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();
  31. $result['assign_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>1])->where('work_pay_status','>',0)->count();
  32. $result['pick_work_count'] = 0;
  33. $result['return_work_count'] = ReturnWork::where(['master_worker_id'=>$this->userId])->where('return_work_status','<>',4)->count();
  34. $result['issue_work_count'] = IssueWork::where(['master_worker_id'=>$this->userId])->whereIn('issue_approval','1,2,3')->count();
  35. $result['review_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>7])->count();
  36. return $this->data($result);
  37. }
  38. /**
  39. * 服务工单列表-全部
  40. * @return \think\response\Json
  41. */
  42. public function serviceWorkList()
  43. {
  44. return $this->dataLists(new ServiceWorkLists());
  45. }
  46. /**
  47. * 派单
  48. * @return \think\response\Json
  49. */
  50. public function assignWorkList()
  51. {
  52. return $this->dataLists(new ServiceAssignWorkLists());
  53. }
  54. /**
  55. * 历史工单
  56. * @return \think\response\Json
  57. */
  58. public function historyWorkList()
  59. {
  60. return $this->dataLists(new HistoryWorkLists());
  61. }
  62. /**
  63. * 领取服务单
  64. * @return \think\response\Json
  65. */
  66. public function pickWork()
  67. {
  68. $params = (new ServiceWorkValidate())->post()->goCheck('pick', [
  69. 'user_id' => $this->userId,
  70. 'user_info' => $this->userInfo
  71. ]);
  72. $result = ServiceWorkLogic::pickWork($params);
  73. if (false === $result) {
  74. return $this->fail(ServiceWorkLogic::getError());
  75. }
  76. // 用户订单被领单通知【给用户的通知】
  77. $workDetail = ServiceWorkLogic::detail($params);
  78. event('Notice', [
  79. 'scene_id' => 114,
  80. 'params' => [
  81. 'user_id' => $workDetail['user_id'],
  82. ]
  83. ]);
  84. return $this->success('领取成功', [], 1, 1);
  85. }
  86. /**
  87. * 工单详情
  88. * @return \think\response\Json
  89. */
  90. public function detail()
  91. {
  92. try {
  93. $params = (new ServiceWorkValidate())->goCheck('detail',[
  94. 'user_id' => $this->userId,
  95. ]);
  96. if(empty($params['id']) && empty($params['work_sn'])){
  97. $this->fail('参数错误');
  98. }
  99. $result = ServiceWorkLogic::detail($params);
  100. if (false === $result) {
  101. return $this->fail(ServiceWorkLogic::getError());
  102. }
  103. return $this->data($result);
  104. } catch (Exception $e) {
  105. return $this->fail($e->getMessage());
  106. }
  107. }
  108. /**
  109. * 获取用户优惠券
  110. * @return \think\response\Json
  111. */
  112. public function getUserCoupons()
  113. {
  114. try {
  115. $params = (new ServiceWorkValidate())->goCheck('detail',[
  116. 'user_id' => $this->userId,
  117. ]);
  118. if(empty($params['id'])){
  119. $this->fail('参数错误');
  120. }
  121. $result = ServiceWorkLogic::getUserCouponDetails($params);
  122. if (false === $result) {
  123. return $this->fail(ServiceWorkLogic::getError());
  124. }
  125. return $this->data($result);
  126. } catch (Exception $e) {
  127. return $this->fail($e->getMessage());
  128. }
  129. }
  130. /**
  131. *
  132. * @return \think\response\Json
  133. */
  134. public function getDetailWorkServiceStatus()
  135. {
  136. $params = (new ServiceWorkValidate())->goCheck('detail',[
  137. 'user_id' => $this->userId,
  138. ]);
  139. $result = ServiceWorkLogic::getDetailWorkServiceStatus($params);
  140. if (false === $result) {
  141. return $this->fail(ServiceWorkLogic::getError());
  142. }
  143. return $this->data($result);
  144. }
  145. /**
  146. * 预约上门
  147. * @return \think\response\Json
  148. */
  149. public function appointWork()
  150. {
  151. $params = (new ServiceWorkValidate())->post()->goCheck('appoint', [
  152. 'user_id' => $this->userId,
  153. 'user_info' => $this->userInfo
  154. ]);
  155. $result = ServiceWorkLogic::appointWork($params);
  156. if (false === $result) {
  157. return $this->fail(ServiceWorkLogic::getError());
  158. }
  159. // 工程师预约上门通知【给用户的通知】
  160. $workDetail = ServiceWorkLogic::detail($params);
  161. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  162. event('Notice', [
  163. 'scene_id' => 115,
  164. 'params' => [
  165. 'user_id' => $workDetail['user_id'],
  166. 'date' => $workDetail['appointment_time'],
  167. 'tel' => asteriskString($masterDetail['mobile'])
  168. ]
  169. ]);
  170. // 工程师预约上门通知【给工程师的通知,仅限公众号】
  171. event('Notice', [
  172. 'scene_id' => 116,
  173. 'params' => [
  174. 'user_id' => $workDetail['master_worker_id'],
  175. 'order_id' => $workDetail['id'],
  176. 'thing5' => $workDetail['title'],
  177. 'time10' => $workDetail['appointment_time'],
  178. 'thing3' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  179. ]
  180. ]);
  181. return $this->success('预约成功,等待上门', [], 1, 1);
  182. }
  183. /**
  184. * 工程师确认上门
  185. * @return \think\response\Json
  186. */
  187. public function confirmDoor()
  188. {
  189. $params = (new ServiceWorkValidate())->post()->goCheck('door', [
  190. 'user_id' => $this->userId,
  191. 'user_info' => $this->userInfo
  192. ]);
  193. $result = ServiceWorkLogic::confirmDoor($params);
  194. if (false === $result) {
  195. return $this->fail(ServiceWorkLogic::getError());
  196. }
  197. return $this->success('操作成功,工程师已上门', [], 1, 1);
  198. }
  199. /**
  200. * 工程师确认报价单
  201. * @return \think\response\Json
  202. */
  203. public function confirmPrice()
  204. {
  205. $params = (new ServiceWorkValidate())->post()->goCheck('price', [
  206. 'user_id' => $this->userId,
  207. 'user_info' => $this->userInfo
  208. ]);
  209. $result = ServiceWorkLogic::confirmPrice($params);
  210. if (false === $result) {
  211. return $this->fail(ServiceWorkLogic::getError());
  212. }
  213. return $this->success('操作成功,工程师已填写报价单,等待用户确认中', [], 1, 1);
  214. }
  215. /**
  216. * 工程师确认服务完成
  217. * @return \think\response\Json
  218. */
  219. public function confirmServiceFinish()
  220. {
  221. $params = (new ServiceWorkValidate())->post()->goCheck('finished', [
  222. 'user_id' => $this->userId,
  223. 'user_info' => $this->userInfo
  224. ]);
  225. $result = ServiceWorkLogic::confirmServiceFinish($params);
  226. if (false === $result) {
  227. return $this->fail(ServiceWorkLogic::getError());
  228. }
  229. return $this->success('操作成功,工程师已确认服务完成,等待用户确认中', [], 1, 1);
  230. }
  231. /**
  232. * 配件列表
  233. * @return \think\response\Json
  234. */
  235. public function spareList()
  236. {
  237. // 查全部可选配件
  238. return $this->dataLists(new SparePartLists());
  239. }
  240. /**
  241. * 工单配件列表
  242. * @return \think\response\Json
  243. */
  244. public function serviceWorkSpareList()
  245. {
  246. // 查该订单的配件
  247. (new ServiceWorkValidate())->get()->goCheck('spare', [
  248. 'user_id' => $this->userId
  249. ]);
  250. return $this->dataLists(new ServiceWorkSparePartLists());
  251. }
  252. /**
  253. * 工单收费标准列表
  254. * @return \think\response\Json
  255. */
  256. public function serviceFeeStandards()
  257. {
  258. // 查该订单的配件
  259. (new GoodsFeeStandardsValidate())->get()->goCheck('standards', [
  260. 'user_id' => $this->userId
  261. ]);
  262. return $this->dataLists(new GoodsFeeStandardsLists());
  263. }
  264. /**
  265. * 预约通知确认
  266. * @return \think\response\Json
  267. */
  268. public function appointmentSubmitNotice()
  269. {
  270. $params = (new ServiceWorkValidate())->post()->goCheck('submitAppointment', [
  271. 'user_id' => $this->userId,
  272. 'user_info' => $this->userInfo
  273. ]);
  274. $result = ServiceWorkLogic::submitAppointment($params);
  275. if (false === $result) {
  276. return $this->fail(ServiceWorkLogic::getError());
  277. }
  278. // 工程师再次上门通知【给用户的通知】
  279. $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
  280. event('Notice', [
  281. 'scene_id' => 119,
  282. 'params' => [
  283. 'user_id' => $workDetail['user_id'],
  284. ]
  285. ]);
  286. return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
  287. }
  288. /**
  289. * 再次上门
  290. * @return \think\response\Json
  291. */
  292. public function againDoor()
  293. {
  294. $params = (new ServiceWorkValidate())->post()->goCheck('againDoor', [
  295. 'user_id' => $this->userId,
  296. 'user_info' => $this->userInfo
  297. ]);
  298. $result = ServiceWorkLogic::againDoor($params);
  299. if (false === $result) {
  300. return $this->fail(ServiceWorkLogic::getError());
  301. }
  302. // 工程师再次上门通知【给用户的通知】
  303. $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
  304. event('Notice', [
  305. 'scene_id' => 119,
  306. 'params' => [
  307. 'user_id' => $workDetail['user_id'],
  308. ]
  309. ]);
  310. return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
  311. }
  312. /**
  313. * 第一次电话联系客户
  314. * @return \think\response\Json
  315. */
  316. public function contactCustomer()
  317. {
  318. $params = (new ServiceWorkValidate())->post()->goCheck('contact', [
  319. 'user_id' => $this->userId,
  320. 'user_info' => $this->userInfo
  321. ]);
  322. $result = ServiceWorkLogic::contactCustomer($params);
  323. if (false === $result) {
  324. return $this->fail(ServiceWorkLogic::getError());
  325. }
  326. return $this->success('成功', [], 1, 1);
  327. }
  328. }