ServiceOrderController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. ServiceOrderLogic::serviceFinishNotice($params);
  149. return $this->success('已确认服务完成', [], 1, 1);
  150. }
  151. /**
  152. * 提交尾款订单
  153. * @return \think\response\Json
  154. */
  155. public function submitFinalOrder()
  156. {
  157. $params = (new ServiceOrderValidate())->post()->goCheck('final', [
  158. 'user_id' => $this->userId,
  159. 'terminal' => $this->userInfo['terminal'],
  160. 'user_info' => $this->userInfo
  161. ]);
  162. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  163. $result = ServiceOrderLogic::submitFinalOrder($params);
  164. if (false === $result) {
  165. return $this->fail(ServiceOrderLogic::getError());
  166. }
  167. return $this->data($result);
  168. }
  169. /**
  170. * 重置订单优惠券
  171. * @return \think\response\Json
  172. */
  173. public function cancelOrderCoupon()
  174. {
  175. $params = (new ServiceOrderValidate())->post()->goCheck('cancelOrderCoupon', [
  176. 'user_id' => $this->userId,
  177. 'user_info' => $this->userInfo
  178. ]);
  179. $result = ServiceOrderLogic::cancelOrderCoupon($params);
  180. if (false === $result) {
  181. return $this->fail(ServiceOrderLogic::getError());
  182. }
  183. return $this->success('保存成功', [], 1, 1);
  184. }
  185. /**
  186. * 查询是否在服务区内
  187. * @return \think\response\Json
  188. */
  189. public function isServiceWithin()
  190. {
  191. $params = (new ServiceOrderValidate())->get()->goCheck('LonLat', [
  192. 'user_id' => $this->userId,
  193. 'user_info' => $this->userInfo
  194. ]);
  195. $result = ServiceOrderLogic::isService($params);
  196. if (false === $result) {
  197. return $this->fail(ServiceOrderLogic::getError(),['is_service'=>0]);
  198. }
  199. return $this->success('服务区域内', ['is_service'=>1], 1, 1);
  200. }
  201. /**
  202. * 申请改价
  203. * @return \think\response\Json
  204. */
  205. public function approvalChangePrice()
  206. {
  207. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  208. 'user_id' => $this->userId,
  209. 'user_info' => $this->userInfo
  210. ]);
  211. $result = ServiceOrderLogic::approvalChangePrice($params);
  212. if (false === $result) {
  213. return $this->fail(ServiceOrderLogic::getError());
  214. }
  215. return $this->success('已提交改价申请,等待工程师确认', [], 1, 1);
  216. }
  217. /**
  218. * 申请改约
  219. * @return \think\response\Json
  220. */
  221. public function approvalChangeAppointment()
  222. {
  223. $params = (new ServiceOrderValidate())->post()->goCheck('changeAppointment', [
  224. 'user_id' => $this->userId,
  225. 'user_info' => $this->userInfo
  226. ]);
  227. $result = ServiceOrderLogic::approvalChangeAppointment($params);
  228. if (false === $result) {
  229. return $this->fail(ServiceOrderLogic::getError());
  230. }
  231. $order = ServiceOrderLogic::orderPayInfo($params);
  232. $workDetail = ServiceWorkAppointmentLog::where(['work_id'=>$order['work_id']])->order('id desc')->findOrEmpty();
  233. $masterDetail = MasterWorkerLogic::detail(['id'=>$result['master_worker_id']]);
  234. // 修改预约时间通知【给用户的通知】
  235. $res = event('Notice', [
  236. 'scene_id' => 117,
  237. 'params' => [
  238. 'user_id' => $result['user_id'],
  239. 'date' => $params['appointment_time'],
  240. 'tel' => $masterDetail['mobile'],
  241. ]
  242. ]);
  243. // 修改预约时间通知【给工程师的通知,仅限公众号】
  244. $res = event('Notice', [
  245. 'scene_id' => 118,
  246. 'params' => [
  247. 'user_id' => $result['master_worker_id'],
  248. 'order_id' => $order['work_id'],
  249. 'thing4' => $result['title'],
  250. 'time5' => date('Y-m-d H:i:s',$workDetail['last_appointment_time']),
  251. 'time6' => date('Y-m-d H:i:s',$workDetail['this_appointment_time']),
  252. 'thing11' => (iconv_strlen($result['address'])>15)?(mb_substr($result['address'],0,15,'UTF-8').'...'):$result['address'],
  253. 'phone_number8' => $result['mobile'],
  254. ]
  255. ]);
  256. return $this->success('已提交改约', [], 1, 1);
  257. }
  258. /**
  259. * 提交退款申请
  260. * @return \think\response\Json
  261. */
  262. public function approvalRefund()
  263. {
  264. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  265. 'user_id' => $this->userId,
  266. 'user_info' => $this->userInfo
  267. ]);
  268. $result = ServiceOrderLogic::approvalRefund($params);
  269. if (false === $result) {
  270. return $this->fail(ServiceOrderLogic::getError());
  271. }
  272. return $this->success('已提交申请,等待客服确认中', [], 1, 1);
  273. }
  274. public function firmOrderLists()
  275. {
  276. return $this->dataLists(new ServiceOrderLists());
  277. }
  278. public function firmOrderSave()
  279. {
  280. $params = (new ServiceOrderValidate())->post()->goCheck('firmOrderSave', [
  281. 'user_id' => $this->userId,
  282. 'terminal' => $this->userInfo['terminal'],
  283. 'user_info' => $this->userInfo
  284. ]);
  285. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  286. if(count($params['order_goods']) == 0){
  287. return $this->fail('请选择商品');
  288. }else{
  289. $params['goods_id'] = $params['order_goods'][0]['id'];
  290. }
  291. $result = ServiceOrderLogic::firmSubmitOrder($params);
  292. if (false === $result) {
  293. return $this->fail(ServiceOrderLogic::getError());
  294. }
  295. return $this->data($result);
  296. }
  297. }