WorksController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. 'user_info' => $this->userInfo,
  96. ]);
  97. if(empty($params['id']) && empty($params['work_sn'])){
  98. $this->fail('参数错误');
  99. }
  100. $result = ServiceWorkLogic::detail($params);
  101. if (false === $result) {
  102. return $this->fail(ServiceWorkLogic::getError());
  103. }
  104. return $this->data($result);
  105. } catch (Exception $e) {
  106. return $this->fail($e->getMessage());
  107. }
  108. }
  109. /**
  110. * 获取用户优惠券
  111. * @return \think\response\Json
  112. */
  113. public function getUserCoupons()
  114. {
  115. try {
  116. $params = (new ServiceWorkValidate())->goCheck('detail',[
  117. 'user_id' => $this->userId,
  118. ]);
  119. if(empty($params['id'])){
  120. $this->fail('参数错误');
  121. }
  122. $result = ServiceWorkLogic::getUserCouponDetails($params);
  123. if (false === $result) {
  124. return $this->fail(ServiceWorkLogic::getError());
  125. }
  126. return $this->data($result);
  127. } catch (Exception $e) {
  128. return $this->fail($e->getMessage());
  129. }
  130. }
  131. /**
  132. *
  133. * @return \think\response\Json
  134. */
  135. public function getDetailWorkServiceStatus()
  136. {
  137. $params = (new ServiceWorkValidate())->goCheck('detail',[
  138. 'user_id' => $this->userId,
  139. ]);
  140. $result = ServiceWorkLogic::getDetailWorkServiceStatus($params);
  141. if (false === $result) {
  142. return $this->fail(ServiceWorkLogic::getError());
  143. }
  144. return $this->data($result);
  145. }
  146. /**
  147. * 预约上门
  148. * @return \think\response\Json
  149. */
  150. public function appointWork()
  151. {
  152. $params = (new ServiceWorkValidate())->post()->goCheck('appoint', [
  153. 'user_id' => $this->userId,
  154. 'user_info' => $this->userInfo
  155. ]);
  156. $result = ServiceWorkLogic::appointWork($params);
  157. if (false === $result) {
  158. return $this->fail(ServiceWorkLogic::getError());
  159. }
  160. // 工程师预约上门通知【给用户的通知】
  161. $workDetail = ServiceWorkLogic::detail($params);
  162. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  163. event('Notice', [
  164. 'scene_id' => 115,
  165. 'params' => [
  166. 'user_id' => $workDetail['user_id'],
  167. 'date' => $workDetail['appointment_time'],
  168. 'tel' => asteriskString($masterDetail['mobile'])
  169. ]
  170. ]);
  171. // 工程师预约上门通知【给工程师的通知,仅限公众号】
  172. event('Notice', [
  173. 'scene_id' => 116,
  174. 'params' => [
  175. 'user_id' => $workDetail['master_worker_id'],
  176. 'order_id' => $workDetail['id'],
  177. 'thing5' => $workDetail['title'],
  178. 'time10' => $workDetail['appointment_time'],
  179. 'thing3' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  180. ]
  181. ]);
  182. return $this->success('预约成功,等待上门', [], 1, 1);
  183. }
  184. /**
  185. * 工程师确认上门
  186. * @return \think\response\Json
  187. */
  188. public function confirmDoor()
  189. {
  190. $params = (new ServiceWorkValidate())->post()->goCheck('door', [
  191. 'user_id' => $this->userId,
  192. 'user_info' => $this->userInfo
  193. ]);
  194. $result = ServiceWorkLogic::confirmDoor($params);
  195. if (false === $result) {
  196. return $this->fail(ServiceWorkLogic::getError());
  197. }
  198. return $this->success('操作成功,工程师已上门', [], 1, 1);
  199. }
  200. /**
  201. * 工程师确认报价单
  202. * @return \think\response\Json
  203. */
  204. public function confirmPrice()
  205. {
  206. $params = (new ServiceWorkValidate())->post()->goCheck('price', [
  207. 'user_id' => $this->userId,
  208. 'user_info' => $this->userInfo
  209. ]);
  210. $result = ServiceWorkLogic::confirmPrice($params);
  211. if (false === $result) {
  212. return $this->fail(ServiceWorkLogic::getError());
  213. }
  214. return $this->success('操作成功,工程师已填写报价单,等待用户确认中', [], 1, 1);
  215. }
  216. /**
  217. * 工程师确认服务完成
  218. * @return \think\response\Json
  219. */
  220. public function confirmServiceFinish()
  221. {
  222. $params = (new ServiceWorkValidate())->post()->goCheck('finished', [
  223. 'user_id' => $this->userId,
  224. 'user_info' => $this->userInfo
  225. ]);
  226. $result = ServiceWorkLogic::confirmServiceFinish($params);
  227. if (false === $result) {
  228. return $this->fail(ServiceWorkLogic::getError());
  229. }
  230. return $this->success('操作成功,工程师已确认服务完成,等待用户确认中', [], 1, 1);
  231. }
  232. /**
  233. * 配件列表
  234. * @return \think\response\Json
  235. */
  236. public function spareList()
  237. {
  238. // 查全部可选配件
  239. return $this->dataLists(new SparePartLists());
  240. }
  241. /**
  242. * 工单配件列表
  243. * @return \think\response\Json
  244. */
  245. public function serviceWorkSpareList()
  246. {
  247. // 查该订单的配件
  248. (new ServiceWorkValidate())->get()->goCheck('spare', [
  249. 'user_id' => $this->userId
  250. ]);
  251. return $this->dataLists(new ServiceWorkSparePartLists());
  252. }
  253. /**
  254. * 工单收费标准列表
  255. * @return \think\response\Json
  256. */
  257. public function serviceFeeStandards()
  258. {
  259. // 查该订单的配件
  260. (new GoodsFeeStandardsValidate())->get()->goCheck('standards', [
  261. 'user_id' => $this->userId
  262. ]);
  263. return $this->dataLists(new GoodsFeeStandardsLists());
  264. }
  265. /**
  266. * 预约通知确认
  267. * @return \think\response\Json
  268. */
  269. public function appointmentSubmitNotice()
  270. {
  271. $params = (new ServiceWorkValidate())->post()->goCheck('submitAppointment', [
  272. 'user_id' => $this->userId,
  273. 'user_info' => $this->userInfo
  274. ]);
  275. $result = ServiceWorkLogic::submitAppointment($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. /**
  290. * 再次上门
  291. * @return \think\response\Json
  292. */
  293. public function againDoor()
  294. {
  295. $params = (new ServiceWorkValidate())->post()->goCheck('againDoor', [
  296. 'user_id' => $this->userId,
  297. 'user_info' => $this->userInfo
  298. ]);
  299. $result = ServiceWorkLogic::againDoor($params);
  300. if (false === $result) {
  301. return $this->fail(ServiceWorkLogic::getError());
  302. }
  303. // 工程师再次上门通知【给用户的通知】
  304. $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
  305. event('Notice', [
  306. 'scene_id' => 119,
  307. 'params' => [
  308. 'user_id' => $workDetail['user_id'],
  309. ]
  310. ]);
  311. return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
  312. }
  313. /**
  314. * 第一次电话联系客户
  315. * @return \think\response\Json
  316. */
  317. public function contactCustomer()
  318. {
  319. $params = (new ServiceWorkValidate())->post()->goCheck('contact', [
  320. 'user_id' => $this->userId,
  321. 'user_info' => $this->userInfo
  322. ]);
  323. $result = ServiceWorkLogic::contactCustomer($params);
  324. if (false === $result) {
  325. return $this->fail(ServiceWorkLogic::getError());
  326. }
  327. return $this->success('成功', [], 1, 1);
  328. }
  329. }