ServiceOrderController.php 7.6 KB

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