WorksController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. if(empty($params['id']) && empty($params['work_sn'])){
  83. $this->fail('参数错误');
  84. }
  85. $result = ServiceWorkLogic::detail($params);
  86. if (false === $result) {
  87. return $this->fail(ServiceWorkLogic::getError());
  88. }
  89. return $this->data($result);
  90. }
  91. /**
  92. *
  93. * @return \think\response\Json
  94. */
  95. public function getDetailWorkServiceStatus()
  96. {
  97. $params = (new ServiceWorkValidate())->goCheck('detail',[
  98. 'user_id' => $this->userId,
  99. ]);
  100. $result = ServiceWorkLogic::getDetailWorkServiceStatus($params);
  101. if (false === $result) {
  102. return $this->fail(ServiceWorkLogic::getError());
  103. }
  104. return $this->data($result);
  105. }
  106. /**
  107. * 预约上门
  108. * @return \think\response\Json
  109. */
  110. public function appointWork()
  111. {
  112. $params = (new ServiceWorkValidate())->post()->goCheck('appoint', [
  113. 'user_id' => $this->userId,
  114. 'user_info' => $this->userInfo
  115. ]);
  116. $result = ServiceWorkLogic::appointWork($params);
  117. if (false === $result) {
  118. return $this->fail(ServiceWorkLogic::getError());
  119. }
  120. return $this->success('预约成功,等待上门', [], 1, 1);
  121. }
  122. /**
  123. * 师傅确认上门
  124. * @return \think\response\Json
  125. */
  126. public function confirmDoor()
  127. {
  128. $params = (new ServiceWorkValidate())->post()->goCheck('door', [
  129. 'user_id' => $this->userId,
  130. 'user_info' => $this->userInfo
  131. ]);
  132. $result = ServiceWorkLogic::confirmDoor($params);
  133. if (false === $result) {
  134. return $this->fail(ServiceWorkLogic::getError());
  135. }
  136. return $this->success('操作成功,师傅已上门', [], 1, 1);
  137. }
  138. /**
  139. * 师傅确认报价单
  140. * @return \think\response\Json
  141. */
  142. public function confirmPrice()
  143. {
  144. $params = (new ServiceWorkValidate())->post()->goCheck('price', [
  145. 'user_id' => $this->userId,
  146. 'user_info' => $this->userInfo
  147. ]);
  148. $result = ServiceWorkLogic::confirmPrice($params);
  149. if (false === $result) {
  150. return $this->fail(ServiceWorkLogic::getError());
  151. }
  152. return $this->success('操作成功,师傅已填写报价单,等待用户确认中', [], 1, 1);
  153. }
  154. /**
  155. * 师傅确认服务完成
  156. * @return \think\response\Json
  157. */
  158. public function confirmServiceFinish()
  159. {
  160. $params = (new ServiceWorkValidate())->post()->goCheck('finished', [
  161. 'user_id' => $this->userId,
  162. 'user_info' => $this->userInfo
  163. ]);
  164. $result = ServiceWorkLogic::confirmServiceFinish($params);
  165. if (false === $result) {
  166. return $this->fail(ServiceWorkLogic::getError());
  167. }
  168. return $this->success('操作成功,师傅已确认服务完成,等待用户确认中', [], 1, 1);
  169. }
  170. /**
  171. * 配件列表
  172. * @return \think\response\Json
  173. */
  174. public function spareList()
  175. {
  176. // 查全部可选配件
  177. return $this->dataLists(new SparePartLists());
  178. }
  179. /**
  180. * 工单配件列表
  181. * @return \think\response\Json
  182. */
  183. public function serviceWorkSpareList()
  184. {
  185. // 查该订单的配件
  186. (new ServiceWorkValidate())->get()->goCheck('spare', [
  187. 'user_id' => $this->userId
  188. ]);
  189. return $this->dataLists(new ServiceWorkSparePartLists());
  190. }
  191. }