WorksController.php 6.6 KB

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