1
0

ServiceOrderController.php 10 KB

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