WorksController.php 9.2 KB

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