ServiceOrderController.php 9.0 KB

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