ServiceOrderController.php 9.4 KB

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