ServiceOrderController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. // 用户下单后,给订单运营专员(配置固定ID)发送公众号提醒(订单信息)
  80. $workDetail = ServiceWorkLogic::detail(['id'=>$result['work_id']]);
  81. $res = event('Notice', [
  82. 'scene_id' => 100,
  83. 'params' => [
  84. 'user_id' => 0,
  85. 'thing3' => $workDetail['title'],
  86. 'time6' => $workDetail['appointment_time'],
  87. 'phone_number8' => $workDetail['mobile'],
  88. ]
  89. ]);
  90. return $this->data($result);
  91. }
  92. /**
  93. * 取消订单
  94. * @return \think\response\Json
  95. */
  96. public function cancelOrder()
  97. {
  98. $params = (new ServiceOrderValidate())->post()->goCheck('cancel', [
  99. 'user_id' => $this->userId,
  100. 'terminal' => $this->userInfo['terminal'],
  101. 'user_info' => $this->userInfo
  102. ]);
  103. $result = ServiceOrderLogic::cancelOrder($params);
  104. if (false === $result) {
  105. return $this->fail(ServiceOrderLogic::getError());
  106. }
  107. // 订单取消通知【给用户】
  108. $res = event('Notice', [
  109. 'scene_id' => 122,
  110. 'params' => [
  111. 'user_id' => $params['user_id']
  112. ]
  113. ]);
  114. return $this->success('取消成功', [], 1, 1);
  115. }
  116. /**
  117. * 确认报价订单
  118. * @return \think\response\Json
  119. */
  120. public function confirmOrder()
  121. {
  122. $params = (new ServiceOrderValidate())->post()->goCheck('price', [
  123. 'user_id' => $this->userId,
  124. 'user_info' => $this->userInfo
  125. ]);
  126. $result = ServiceOrderLogic::confirmOrder($params);
  127. if (false === $result) {
  128. return $this->fail(ServiceOrderLogic::getError());
  129. }
  130. return $this->success('已确认报价,工程师即将开始服务', [], 1, 1);
  131. }
  132. /**
  133. * 用户确认服务完成
  134. * @return \think\response\Json
  135. */
  136. public function confirmServiceFinish()
  137. {
  138. $params = (new ServiceOrderValidate())->post()->goCheck('finished', [
  139. 'user_id' => $this->userId,
  140. 'user_info' => $this->userInfo
  141. ]);
  142. $result = ServiceOrderLogic::confirmServiceFinish($params);
  143. if (false === $result) {
  144. return $this->fail(ServiceOrderLogic::getError());
  145. }
  146. // 订单完成通知【给用户】
  147. $res = event('Notice', [
  148. 'scene_id' => 120,
  149. 'params' => [
  150. 'user_id' => $params['user_id']
  151. ]
  152. ]);
  153. return $this->success('已确认服务完成', [], 1, 1);
  154. }
  155. /**
  156. * 提交尾款订单
  157. * @return \think\response\Json
  158. */
  159. public function submitFinalOrder()
  160. {
  161. $params = (new ServiceOrderValidate())->post()->goCheck('final', [
  162. 'user_id' => $this->userId,
  163. 'terminal' => $this->userInfo['terminal'],
  164. 'user_info' => $this->userInfo
  165. ]);
  166. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  167. $result = ServiceOrderLogic::submitFinalOrder($params);
  168. if (false === $result) {
  169. return $this->fail(ServiceOrderLogic::getError());
  170. }
  171. return $this->data($result);
  172. }
  173. /**
  174. * 重置订单优惠券
  175. * @return \think\response\Json
  176. */
  177. public function cancelOrderCoupon()
  178. {
  179. $params = (new ServiceOrderValidate())->post()->goCheck('cancelOrderCoupon', [
  180. 'user_id' => $this->userId,
  181. 'user_info' => $this->userInfo
  182. ]);
  183. $result = ServiceOrderLogic::cancelOrderCoupon($params);
  184. if (false === $result) {
  185. return $this->fail(ServiceOrderLogic::getError());
  186. }
  187. return $this->success('保存成功', [], 1, 1);
  188. }
  189. /**
  190. * 查询是否在服务区内
  191. * @return \think\response\Json
  192. */
  193. public function isServiceWithin()
  194. {
  195. $params = (new ServiceOrderValidate())->get()->goCheck('LonLat', [
  196. 'user_id' => $this->userId,
  197. 'user_info' => $this->userInfo
  198. ]);
  199. $result = ServiceOrderLogic::isService($params);
  200. if (false === $result) {
  201. return $this->fail(ServiceOrderLogic::getError(),['is_service'=>0]);
  202. }
  203. return $this->success('服务区域内', ['is_service'=>1], 1, 1);
  204. }
  205. /**
  206. * 申请改价
  207. * @return \think\response\Json
  208. */
  209. public function approvalChangePrice()
  210. {
  211. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  212. 'user_id' => $this->userId,
  213. 'user_info' => $this->userInfo
  214. ]);
  215. $result = ServiceOrderLogic::approvalChangePrice($params);
  216. if (false === $result) {
  217. return $this->fail(ServiceOrderLogic::getError());
  218. }
  219. return $this->success('已提交改价申请,等待工程师确认', [], 1, 1);
  220. }
  221. /**
  222. * 申请改约
  223. * @return \think\response\Json
  224. */
  225. public function approvalChangeAppointment()
  226. {
  227. $params = (new ServiceOrderValidate())->post()->goCheck('changeAppointment', [
  228. 'user_id' => $this->userId,
  229. 'user_info' => $this->userInfo
  230. ]);
  231. $result = ServiceOrderLogic::approvalChangeAppointment($params);
  232. if (false === $result) {
  233. return $this->fail(ServiceOrderLogic::getError());
  234. }
  235. $order = ServiceOrderLogic::orderPayInfo($params);
  236. $workDetail = ServiceWorkLogic::detail(['id'=>$order['work_id']]);
  237. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  238. // 修改预约时间通知【给用户的通知】
  239. $res = event('Notice', [
  240. 'scene_id' => 117,
  241. 'params' => [
  242. 'user_id' => $workDetail['user_id'],
  243. 'date' => $params['appointment_time'],
  244. 'tel' => $masterDetail['mobile'],
  245. ]
  246. ]);
  247. // 修改预约时间通知【给工程师的通知,仅限公众号】
  248. $res = event('Notice', [
  249. 'scene_id' => 118,
  250. 'params' => [
  251. 'user_id' => $workDetail['master_worker_id'],
  252. 'thing4' => $workDetail['title'],
  253. 'time5' => $workDetail['appointment_time'],
  254. 'time6' => $params['appointment_time'],
  255. 'thing11' => $workDetail['address'],
  256. 'phone_number8' => $workDetail['mobile'],
  257. ]
  258. ]);
  259. return $this->success('已提交改约', [], 1, 1);
  260. }
  261. }