WorksController.php 9.8 KB

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