WorksController.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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','<>',4)->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. 'order_id' => $workDetail['id'],
  148. 'thing5' => $workDetail['title'],
  149. 'time10' => $workDetail['appointment_time'],
  150. 'thing3' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  151. ]
  152. ]);
  153. return $this->success('预约成功,等待上门', [], 1, 1);
  154. }
  155. /**
  156. * 工程师确认上门
  157. * @return \think\response\Json
  158. */
  159. public function confirmDoor()
  160. {
  161. $params = (new ServiceWorkValidate())->post()->goCheck('door', [
  162. 'user_id' => $this->userId,
  163. 'user_info' => $this->userInfo
  164. ]);
  165. $result = ServiceWorkLogic::confirmDoor($params);
  166. if (false === $result) {
  167. return $this->fail(ServiceWorkLogic::getError());
  168. }
  169. return $this->success('操作成功,工程师已上门', [], 1, 1);
  170. }
  171. /**
  172. * 工程师确认报价单
  173. * @return \think\response\Json
  174. */
  175. public function confirmPrice()
  176. {
  177. $params = (new ServiceWorkValidate())->post()->goCheck('price', [
  178. 'user_id' => $this->userId,
  179. 'user_info' => $this->userInfo
  180. ]);
  181. $result = ServiceWorkLogic::confirmPrice($params);
  182. if (false === $result) {
  183. return $this->fail(ServiceWorkLogic::getError());
  184. }
  185. return $this->success('操作成功,工程师已填写报价单,等待用户确认中', [], 1, 1);
  186. }
  187. /**
  188. * 工程师确认服务完成
  189. * @return \think\response\Json
  190. */
  191. public function confirmServiceFinish()
  192. {
  193. $params = (new ServiceWorkValidate())->post()->goCheck('finished', [
  194. 'user_id' => $this->userId,
  195. 'user_info' => $this->userInfo
  196. ]);
  197. $result = ServiceWorkLogic::confirmServiceFinish($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 spareList()
  208. {
  209. // 查全部可选配件
  210. return $this->dataLists(new SparePartLists());
  211. }
  212. /**
  213. * 工单配件列表
  214. * @return \think\response\Json
  215. */
  216. public function serviceWorkSpareList()
  217. {
  218. // 查该订单的配件
  219. (new ServiceWorkValidate())->get()->goCheck('spare', [
  220. 'user_id' => $this->userId
  221. ]);
  222. return $this->dataLists(new ServiceWorkSparePartLists());
  223. }
  224. /**
  225. * 工单收费标准列表
  226. * @return \think\response\Json
  227. */
  228. public function serviceFeeStandards()
  229. {
  230. // 查该订单的配件
  231. (new GoodsFeeStandardsValidate())->get()->goCheck('standards', [
  232. 'user_id' => $this->userId
  233. ]);
  234. return $this->dataLists(new GoodsFeeStandardsLists());
  235. }
  236. /**
  237. * 预约通知确认
  238. * @return \think\response\Json
  239. */
  240. public function appointmentSubmitNotice()
  241. {
  242. $params = (new ServiceWorkValidate())->post()->goCheck('submitAppointment', [
  243. 'user_id' => $this->userId,
  244. 'user_info' => $this->userInfo
  245. ]);
  246. $result = ServiceWorkLogic::submitAppointment($params);
  247. if (false === $result) {
  248. return $this->fail(ServiceWorkLogic::getError());
  249. }
  250. // 工程师再次上门通知【给用户的通知】
  251. $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
  252. event('Notice', [
  253. 'scene_id' => 119,
  254. 'params' => [
  255. 'user_id' => $workDetail['user_id'],
  256. ]
  257. ]);
  258. return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
  259. }
  260. /**
  261. * 再次上门
  262. * @return \think\response\Json
  263. */
  264. public function againDoor()
  265. {
  266. $params = (new ServiceWorkValidate())->post()->goCheck('againDoor', [
  267. 'user_id' => $this->userId,
  268. 'user_info' => $this->userInfo
  269. ]);
  270. $result = ServiceWorkLogic::againDoor($params);
  271. if (false === $result) {
  272. return $this->fail(ServiceWorkLogic::getError());
  273. }
  274. // 工程师再次上门通知【给用户的通知】
  275. $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
  276. event('Notice', [
  277. 'scene_id' => 119,
  278. 'params' => [
  279. 'user_id' => $workDetail['user_id'],
  280. ]
  281. ]);
  282. return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
  283. }
  284. }