1
0

ServiceOrderController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. $res = event('Notice', [
  80. 'scene_id' => 100,
  81. 'params' => [
  82. 'user_id' => 0,
  83. /*'thing4' => xxxx,
  84. 'phone_number8' => xxxx,*/
  85. ]
  86. ]);
  87. return $this->data($result);
  88. }
  89. /**
  90. * 取消订单
  91. * @return \think\response\Json
  92. */
  93. public function cancelOrder()
  94. {
  95. $params = (new ServiceOrderValidate())->post()->goCheck('cancel', [
  96. 'user_id' => $this->userId,
  97. 'terminal' => $this->userInfo['terminal'],
  98. 'user_info' => $this->userInfo
  99. ]);
  100. $result = ServiceOrderLogic::cancelOrder($params);
  101. if (false === $result) {
  102. return $this->fail(ServiceOrderLogic::getError());
  103. }
  104. // 订单取消通知【给用户】
  105. $res = event('Notice', [
  106. 'scene_id' => 122,
  107. 'params' => [
  108. 'user_id' => $params['user_id']
  109. ]
  110. ]);
  111. return $this->success('取消成功', [], 1, 1);
  112. }
  113. /**
  114. * 确认报价订单
  115. * @return \think\response\Json
  116. */
  117. public function confirmOrder()
  118. {
  119. $params = (new ServiceOrderValidate())->post()->goCheck('price', [
  120. 'user_id' => $this->userId,
  121. 'user_info' => $this->userInfo
  122. ]);
  123. $result = ServiceOrderLogic::confirmOrder($params);
  124. if (false === $result) {
  125. return $this->fail(ServiceOrderLogic::getError());
  126. }
  127. return $this->success('已确认报价,工程师即将开始服务', [], 1, 1);
  128. }
  129. /**
  130. * 用户确认服务完成
  131. * @return \think\response\Json
  132. */
  133. public function confirmServiceFinish()
  134. {
  135. $params = (new ServiceOrderValidate())->post()->goCheck('finished', [
  136. 'user_id' => $this->userId,
  137. 'user_info' => $this->userInfo
  138. ]);
  139. $result = ServiceOrderLogic::confirmServiceFinish($params);
  140. if (false === $result) {
  141. return $this->fail(ServiceOrderLogic::getError());
  142. }
  143. // 订单完成通知【给用户】
  144. $res = event('Notice', [
  145. 'scene_id' => 120,
  146. 'params' => [
  147. 'user_id' => $params['user_id']
  148. ]
  149. ]);
  150. return $this->success('已确认服务完成', [], 1, 1);
  151. }
  152. /**
  153. * 提交尾款订单
  154. * @return \think\response\Json
  155. */
  156. public function submitFinalOrder()
  157. {
  158. $params = (new ServiceOrderValidate())->post()->goCheck('final', [
  159. 'user_id' => $this->userId,
  160. 'terminal' => $this->userInfo['terminal'],
  161. 'user_info' => $this->userInfo
  162. ]);
  163. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  164. $result = ServiceOrderLogic::submitFinalOrder($params);
  165. if (false === $result) {
  166. return $this->fail(ServiceOrderLogic::getError());
  167. }
  168. return $this->data($result);
  169. }
  170. /**
  171. * 重置订单优惠券
  172. * @return \think\response\Json
  173. */
  174. public function cancelOrderCoupon()
  175. {
  176. $params = (new ServiceOrderValidate())->post()->goCheck('cancelOrderCoupon', [
  177. 'user_id' => $this->userId,
  178. 'user_info' => $this->userInfo
  179. ]);
  180. $result = ServiceOrderLogic::cancelOrderCoupon($params);
  181. if (false === $result) {
  182. return $this->fail(ServiceOrderLogic::getError());
  183. }
  184. return $this->success('保存成功', [], 1, 1);
  185. }
  186. public function firmOrderLists()
  187. {
  188. return $this->dataLists(new ServiceOrderLists());
  189. }
  190. public function firmOrderSave()
  191. {
  192. $params = (new ServiceOrderValidate())->post()->goCheck('firmOrderSave', [
  193. 'user_id' => $this->userId,
  194. 'user_info' => $this->userInfo
  195. ]);
  196. $result = ServiceOrderLogic::firmOrderSave($params);
  197. if (false === $result) {
  198. return $this->fail(ServiceOrderLogic::getError());
  199. }
  200. return $this->success('保存成功', [], 1, 1);
  201. }
  202. public function isServiceWithin()
  203. {
  204. $params = (new ServiceOrderValidate())->get()->goCheck('LonLat', [
  205. 'user_id' => $this->userId,
  206. 'user_info' => $this->userInfo
  207. ]);
  208. $result = ServiceOrderLogic::isService($params);
  209. if (false === $result) {
  210. return $this->fail(ServiceOrderLogic::getError(),['is_service'=>0]);
  211. }
  212. return $this->success('服务区域内', ['is_service'=>1], 1, 1);
  213. }
  214. }