WorksController.php 7.6 KB

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