WorksController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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\ServiceWorkLists;
  10. use app\workerapi\lists\ServiceWorkSparePartLists;
  11. use app\workerapi\lists\SparePartLists;
  12. use app\workerapi\validate\ServiceWorkValidate;
  13. /**
  14. * 工单系统
  15. */
  16. class WorksController extends BaseApiController
  17. {
  18. /**
  19. * 首页数量统计
  20. * @return \think\response\Json
  21. * @throws \think\db\exception\DbException
  22. */
  23. public function statistics()
  24. {
  25. $result['service_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId])->whereIn('service_status','0,1,2')->where('work_status','<>',1)->count();
  26. $result['assign_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>1])->count();
  27. $result['pick_work_count'] = 0;
  28. $result['return_work_count'] = ReturnWork::where(['master_worker_id'=>$this->userId])->where('return_work_status','<>',2)->count();
  29. $result['issue_work_count'] = IssueWork::where(['master_worker_id'=>$this->userId])->whereIn('issue_approval','1,2,3')->count();
  30. $result['review_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>7])->count();
  31. return $this->data($result);
  32. }
  33. /**
  34. * 服务工单列表-全部
  35. * @return \think\response\Json
  36. */
  37. public function serviceWorkList()
  38. {
  39. return $this->dataLists(new ServiceWorkLists());
  40. }
  41. /**
  42. * 派单
  43. * @return \think\response\Json
  44. */
  45. public function assignWorkList()
  46. {
  47. return $this->dataLists(new ServiceAssignWorkLists());
  48. }
  49. /**
  50. * 历史工单
  51. * @return \think\response\Json
  52. */
  53. public function historyWorkList()
  54. {
  55. return $this->dataLists(new HistoryWorkLists());
  56. }
  57. /**
  58. * 领取服务单
  59. * @return \think\response\Json
  60. */
  61. public function pickWork()
  62. {
  63. $params = (new ServiceWorkValidate())->post()->goCheck('pick', [
  64. 'user_id' => $this->userId,
  65. 'user_info' => $this->userInfo
  66. ]);
  67. $result = ServiceWorkLogic::pickWork($params);
  68. if (false === $result) {
  69. return $this->fail(ServiceWorkLogic::getError());
  70. }
  71. return $this->success('领取成功', [], 1, 1);
  72. }
  73. /**
  74. * 工单详情
  75. * @return \think\response\Json
  76. */
  77. public function detail()
  78. {
  79. $params = (new ServiceWorkValidate())->goCheck('detail',[
  80. 'user_id' => $this->userId,
  81. ]);
  82. $result = ServiceWorkLogic::detail($params);
  83. if (false === $result) {
  84. return $this->fail(ServiceWorkLogic::getError());
  85. }
  86. return $this->data($result);
  87. }
  88. /**
  89. *
  90. * @return \think\response\Json
  91. */
  92. public function getDetailWorkServiceStatus()
  93. {
  94. $params = (new ServiceWorkValidate())->goCheck('detail',[
  95. 'user_id' => $this->userId,
  96. ]);
  97. $result = ServiceWorkLogic::getDetailWorkServiceStatus($params);
  98. if (false === $result) {
  99. return $this->fail(ServiceWorkLogic::getError());
  100. }
  101. return $this->data($result);
  102. }
  103. /**
  104. * 预约上门
  105. * @return \think\response\Json
  106. */
  107. public function appointWork()
  108. {
  109. $params = (new ServiceWorkValidate())->post()->goCheck('appoint', [
  110. 'user_id' => $this->userId,
  111. 'user_info' => $this->userInfo
  112. ]);
  113. $result = ServiceWorkLogic::appointWork($params);
  114. if (false === $result) {
  115. return $this->fail(ServiceWorkLogic::getError());
  116. }
  117. return $this->success('预约成功,等待上门', [], 1, 1);
  118. }
  119. /**
  120. * 师傅确认上门
  121. * @return \think\response\Json
  122. */
  123. public function confirmDoor()
  124. {
  125. $params = (new ServiceWorkValidate())->post()->goCheck('door', [
  126. 'user_id' => $this->userId,
  127. 'user_info' => $this->userInfo
  128. ]);
  129. $result = ServiceWorkLogic::confirmDoor($params);
  130. if (false === $result) {
  131. return $this->fail(ServiceWorkLogic::getError());
  132. }
  133. return $this->success('操作成功,师傅已上门', [], 1, 1);
  134. }
  135. /**
  136. * 师傅确认报价单
  137. * @return \think\response\Json
  138. */
  139. public function confirmPrice()
  140. {
  141. $params = (new ServiceWorkValidate())->post()->goCheck('price', [
  142. 'user_id' => $this->userId,
  143. 'user_info' => $this->userInfo
  144. ]);
  145. $result = ServiceWorkLogic::confirmPrice($params);
  146. if (false === $result) {
  147. return $this->fail(ServiceWorkLogic::getError());
  148. }
  149. return $this->success('操作成功,师傅已填写报价单,等待用户确认中', [], 1, 1);
  150. }
  151. /**
  152. * 师傅确认服务完成
  153. * @return \think\response\Json
  154. */
  155. public function confirmServiceFinish()
  156. {
  157. $params = (new ServiceWorkValidate())->post()->goCheck('finished', [
  158. 'user_id' => $this->userId,
  159. 'user_info' => $this->userInfo
  160. ]);
  161. $result = ServiceWorkLogic::confirmServiceFinish($params);
  162. if (false === $result) {
  163. return $this->fail(ServiceWorkLogic::getError());
  164. }
  165. return $this->success('操作成功,师傅已确认服务完成,等待用户确认中', [], 1, 1);
  166. }
  167. /**
  168. * 配件列表
  169. * @return \think\response\Json
  170. */
  171. public function spareList()
  172. {
  173. // 查全部可选配件
  174. return $this->dataLists(new SparePartLists());
  175. }
  176. /**
  177. * 工单配件列表
  178. * @return \think\response\Json
  179. */
  180. public function serviceWorkSpareList()
  181. {
  182. // 查该订单的配件
  183. (new ServiceWorkValidate())->get()->goCheck('spare', [
  184. 'user_id' => $this->userId
  185. ]);
  186. return $this->dataLists(new ServiceWorkSparePartLists());
  187. }
  188. }