1
0

ServiceOrderController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. namespace app\api\controller;
  3. use app\adminapi\logic\master_worker\MasterWorkerLogic;
  4. use app\adminapi\logic\works\ServiceWorkLogic;
  5. use app\api\lists\recharge\ServiceOrderLists;
  6. use app\api\logic\ServiceOrderLogic;
  7. use app\api\validate\ServiceOrderValidate;
  8. use think\facade\Log;
  9. /**
  10. * 订单类
  11. */
  12. class ServiceOrderController extends BaseApiController
  13. {
  14. /**
  15. * 订单列表
  16. * @return \think\response\Json
  17. */
  18. public function lists()
  19. {
  20. return $this->dataLists(new ServiceOrderLists());
  21. }
  22. /**
  23. * 订单详情
  24. * @return \think\response\Json
  25. */
  26. public function detail()
  27. {
  28. $params = (new ServiceOrderValidate())->goCheck('detail',[
  29. 'user_id' => $this->userId,
  30. ]);
  31. $result = ServiceOrderLogic::detail($params);
  32. if (false === $result) {
  33. return $this->fail(ServiceOrderLogic::getError());
  34. }
  35. return $this->data($result);
  36. }
  37. /**
  38. * 订单支付详情
  39. * @return \think\response\Json
  40. */
  41. public function orderPayInfo()
  42. {
  43. $params = (new ServiceOrderValidate())->goCheck('detail',[
  44. 'user_id' => $this->userId,
  45. ]);
  46. $result = ServiceOrderLogic::orderPayInfo($params);
  47. if (false === $result) {
  48. return $this->fail(ServiceOrderLogic::getError());
  49. }
  50. return $this->data($result);
  51. }
  52. public function getMasterWorker()
  53. {
  54. $params = (new ServiceOrderValidate())->goCheck('worker',[
  55. 'user_id' => $this->userId,
  56. ]);
  57. $result = ServiceOrderLogic::getMasterWorker($params);
  58. if (false === $result) {
  59. return $this->fail(ServiceOrderLogic::getError());
  60. }
  61. return $this->data($result);
  62. }
  63. /**
  64. * 提交订单
  65. * @return \think\response\Json
  66. */
  67. public function submitOrder()
  68. {
  69. $params = (new ServiceOrderValidate())->post()->goCheck('add', [
  70. 'user_id' => $this->userId,
  71. 'terminal' => $this->userInfo['terminal'],
  72. 'user_info' => $this->userInfo
  73. ]);
  74. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  75. $result = ServiceOrderLogic::submitOrder($params);
  76. if (false === $result) {
  77. return $this->fail(ServiceOrderLogic::getError());
  78. }
  79. return $this->data($result);
  80. }
  81. /**
  82. * 取消订单
  83. * @return \think\response\Json
  84. */
  85. public function cancelOrder()
  86. {
  87. $params = (new ServiceOrderValidate())->post()->goCheck('cancel', [
  88. 'user_id' => $this->userId,
  89. 'terminal' => $this->userInfo['terminal'],
  90. 'user_info' => $this->userInfo
  91. ]);
  92. $result = ServiceOrderLogic::cancelOrder($params);
  93. if (false === $result) {
  94. return $this->fail(ServiceOrderLogic::getError());
  95. }
  96. // 订单取消通知【给用户】
  97. $res = event('Notice', [
  98. 'scene_id' => 122,
  99. 'params' => [
  100. 'user_id' => $params['user_id']
  101. ]
  102. ]);
  103. return $this->success('取消成功', [], 1, 1);
  104. }
  105. /**
  106. * 确认报价订单
  107. * @return \think\response\Json
  108. */
  109. public function confirmOrder()
  110. {
  111. $params = (new ServiceOrderValidate())->post()->goCheck('price', [
  112. 'user_id' => $this->userId,
  113. 'user_info' => $this->userInfo
  114. ]);
  115. $result = ServiceOrderLogic::confirmOrder($params);
  116. if (false === $result) {
  117. return $this->fail(ServiceOrderLogic::getError());
  118. }
  119. return $this->success('已确认报价,工程师即将开始服务', [], 1, 1);
  120. }
  121. /**
  122. * 用户确认服务完成
  123. * @return \think\response\Json
  124. */
  125. public function confirmServiceFinish()
  126. {
  127. $params = (new ServiceOrderValidate())->post()->goCheck('finished', [
  128. 'user_id' => $this->userId,
  129. 'user_info' => $this->userInfo
  130. ]);
  131. $result = ServiceOrderLogic::confirmServiceFinish($params);
  132. if (false === $result) {
  133. return $this->fail(ServiceOrderLogic::getError());
  134. }
  135. // 订单完成通知【给用户】
  136. $res = event('Notice', [
  137. 'scene_id' => 120,
  138. 'params' => [
  139. 'user_id' => $params['user_id']
  140. ]
  141. ]);
  142. return $this->success('已确认服务完成', [], 1, 1);
  143. }
  144. /**
  145. * 提交尾款订单
  146. * @return \think\response\Json
  147. */
  148. public function submitFinalOrder()
  149. {
  150. $params = (new ServiceOrderValidate())->post()->goCheck('final', [
  151. 'user_id' => $this->userId,
  152. 'terminal' => $this->userInfo['terminal'],
  153. 'user_info' => $this->userInfo
  154. ]);
  155. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  156. $result = ServiceOrderLogic::submitFinalOrder($params);
  157. if (false === $result) {
  158. return $this->fail(ServiceOrderLogic::getError());
  159. }
  160. return $this->data($result);
  161. }
  162. /**
  163. * 重置订单优惠券
  164. * @return \think\response\Json
  165. */
  166. public function cancelOrderCoupon()
  167. {
  168. $params = (new ServiceOrderValidate())->post()->goCheck('cancelOrderCoupon', [
  169. 'user_id' => $this->userId,
  170. 'user_info' => $this->userInfo
  171. ]);
  172. $result = ServiceOrderLogic::cancelOrderCoupon($params);
  173. if (false === $result) {
  174. return $this->fail(ServiceOrderLogic::getError());
  175. }
  176. return $this->success('保存成功', [], 1, 1);
  177. }
  178. /**
  179. * 查询是否在服务区内
  180. * @return \think\response\Json
  181. */
  182. public function isServiceWithin()
  183. {
  184. $params = (new ServiceOrderValidate())->get()->goCheck('LonLat', [
  185. 'user_id' => $this->userId,
  186. 'user_info' => $this->userInfo
  187. ]);
  188. $result = ServiceOrderLogic::isService($params);
  189. if (false === $result) {
  190. return $this->fail(ServiceOrderLogic::getError(),['is_service'=>0]);
  191. }
  192. return $this->success('服务区域内', ['is_service'=>1], 1, 1);
  193. }
  194. /**
  195. * 申请改价
  196. * @return \think\response\Json
  197. */
  198. public function approvalChangePrice()
  199. {
  200. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  201. 'user_id' => $this->userId,
  202. 'user_info' => $this->userInfo
  203. ]);
  204. $result = ServiceOrderLogic::approvalChangePrice($params);
  205. if (false === $result) {
  206. return $this->fail(ServiceOrderLogic::getError());
  207. }
  208. return $this->success('已提交改价申请,等待工程师确认', [], 1, 1);
  209. }
  210. /**
  211. * 申请改约
  212. * @return \think\response\Json
  213. */
  214. public function approvalChangeAppointment()
  215. {
  216. $params = (new ServiceOrderValidate())->post()->goCheck('changeAppointment', [
  217. 'user_id' => $this->userId,
  218. 'user_info' => $this->userInfo
  219. ]);
  220. $result = ServiceOrderLogic::approvalChangeAppointment($params);
  221. if (false === $result) {
  222. return $this->fail(ServiceOrderLogic::getError());
  223. }
  224. $order = ServiceOrderLogic::orderPayInfo($params);
  225. $workDetail = ServiceWorkLogic::detail(['id'=>$order['work_id']]);
  226. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  227. // 修改预约时间通知【给用户的通知】
  228. $res = event('Notice', [
  229. 'scene_id' => 117,
  230. 'params' => [
  231. 'user_id' => $workDetail['user_id'],
  232. 'date' => $params['appointment_time'],
  233. 'tel' => $masterDetail['mobile'],
  234. ]
  235. ]);
  236. // 修改预约时间通知【给工程师的通知,仅限公众号】
  237. $res = event('Notice', [
  238. 'scene_id' => 118,
  239. 'params' => [
  240. 'user_id' => $workDetail['master_worker_id'],
  241. 'thing4' => $workDetail['title'],
  242. 'time5' => $workDetail['appointment_time'],
  243. 'time6' => $params['appointment_time'],
  244. 'thing11' => $workDetail['address'],
  245. 'phone_number8' => $workDetail['mobile'],
  246. ]
  247. ]);
  248. return $this->success('已提交改约', [], 1, 1);
  249. }
  250. }