ServiceOrderController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 Exception;
  11. use think\facade\Log;
  12. /**
  13. * 订单类
  14. */
  15. class ServiceOrderController extends BaseApiController
  16. {
  17. /**
  18. * 订单列表
  19. * @return \think\response\Json
  20. */
  21. public function lists()
  22. {
  23. return $this->dataLists(new ServiceOrderLists());
  24. }
  25. /**
  26. * 订单详情
  27. * @return \think\response\Json
  28. */
  29. public function detail()
  30. {
  31. $params = (new ServiceOrderValidate())->goCheck('detail',[
  32. 'user_id' => $this->userId,
  33. 'user_info' => $this->userInfo,
  34. 'domain'=>$this->request->domain()
  35. ]);
  36. $result = ServiceOrderLogic::detail($params);
  37. if (false === $result) {
  38. return $this->fail(ServiceOrderLogic::getError());
  39. }
  40. return $this->data($result);
  41. }
  42. public function getDetailStatus()
  43. {
  44. $params = (new ServiceOrderValidate())->goCheck('detail',[
  45. 'user_id' => $this->userId,
  46. ]);
  47. $result = ServiceOrderLogic::getDetailStatus($params);
  48. if (false === $result) {
  49. return $this->fail(ServiceOrderLogic::getError());
  50. }
  51. return $this->data($result);
  52. }
  53. /**
  54. * 订单支付详情
  55. * @return \think\response\Json
  56. */
  57. public function orderPayInfo()
  58. {
  59. $params = (new ServiceOrderValidate())->goCheck('detail',[
  60. 'user_id' => $this->userId,
  61. ]);
  62. $result = ServiceOrderLogic::orderPayInfo($params);
  63. if (false === $result) {
  64. return $this->fail(ServiceOrderLogic::getError());
  65. }
  66. return $this->data($result);
  67. }
  68. public function getMasterWorker()
  69. {
  70. $params = (new ServiceOrderValidate())->goCheck('worker',[
  71. 'user_id' => $this->userId,
  72. ]);
  73. $result = ServiceOrderLogic::getMasterWorker($params);
  74. if (false === $result) {
  75. return $this->fail(ServiceOrderLogic::getError());
  76. }
  77. return $this->data($result);
  78. }
  79. /**
  80. * 提交订单
  81. * @return \think\response\Json
  82. */
  83. public function submitOrder()
  84. {
  85. $params = (new ServiceOrderValidate())->post()->goCheck('add', [
  86. 'user_id' => $this->userId,
  87. 'terminal' => $this->userInfo['terminal'],
  88. 'user_info' => $this->userInfo
  89. ]);
  90. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  91. $result = ServiceOrderLogic::submitOrder($params);
  92. if (false === $result) {
  93. return $this->fail(ServiceOrderLogic::getError());
  94. }
  95. ActivityLogic::createPropertyOrder($params,$result);
  96. return $this->data($result);
  97. }
  98. /**
  99. * 取消订单
  100. * @return \think\response\Json
  101. */
  102. public function cancelOrder()
  103. {
  104. $params = (new ServiceOrderValidate())->post()->goCheck('cancel', [
  105. 'user_id' => $this->userId,
  106. 'terminal' => $this->userInfo['terminal'],
  107. 'user_info' => $this->userInfo
  108. ]);
  109. $result = ServiceOrderLogic::cancelOrder($params);
  110. if (false === $result) {
  111. return $this->fail(ServiceOrderLogic::getError());
  112. }
  113. return $this->success('取消成功', [], 1, 1);
  114. }
  115. /**
  116. * 确认报价订单
  117. * @return \think\response\Json
  118. */
  119. public function confirmOrder()
  120. {
  121. $params = (new ServiceOrderValidate())->post()->goCheck('price', [
  122. 'user_id' => $this->userId,
  123. 'user_info' => $this->userInfo
  124. ]);
  125. /*$result = ServiceOrderLogic::confirmOrder($params);
  126. if (false === $result) {
  127. return $this->fail(ServiceOrderLogic::getError());
  128. }*/
  129. return $this->success('已确认报价,工程师即将开始服务', [], 1, 1);
  130. }
  131. /**
  132. * 用户确认服务完成
  133. * @return \think\response\Json
  134. */
  135. public function confirmServiceFinish()
  136. {
  137. $params = (new ServiceOrderValidate())->post()->goCheck('finished', [
  138. 'user_id' => $this->userId,
  139. 'user_info' => $this->userInfo
  140. ]);
  141. $result = ServiceOrderLogic::confirmServiceFinish($params);
  142. if (false === $result) {
  143. return $this->fail(ServiceOrderLogic::getError());
  144. }
  145. // 订单完成通知【给用户】 - 全款 -通知
  146. ServiceOrderLogic::serviceFinishNotice($params);
  147. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  148. ServiceOrderLogic::orderQuantityRule($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. return $this->success('已提交改约', [], 1, 1);
  232. }
  233. /**
  234. * 提交退款申请
  235. * @return \think\response\Json
  236. */
  237. public function approvalRefund()
  238. {
  239. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  240. 'user_id' => $this->userId,
  241. 'user_info' => $this->userInfo
  242. ]);
  243. $result = ServiceOrderLogic::approvalRefund($params);
  244. if (false === $result) {
  245. return $this->fail(ServiceOrderLogic::getError());
  246. }
  247. return $this->success('已提交申请,等待客服确认中', [], 1, 1);
  248. }
  249. public function firmOrderLists()
  250. {
  251. return $this->dataLists(new ServiceOrderLists());
  252. }
  253. public function firmOrderSave()
  254. {
  255. $params = (new ServiceOrderValidate())->post()->goCheck('firmOrderSave', [
  256. 'user_id' => $this->userId,
  257. 'terminal' => $this->userInfo['terminal'],
  258. 'user_info' => $this->userInfo
  259. ]);
  260. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  261. if(count($params['order_goods']) == 0){
  262. return $this->fail('请选择商品');
  263. }else{
  264. $params['goods_id'] = $params['order_goods'][0]['id'];
  265. }
  266. $result = ServiceOrderLogic::firmSubmitOrder($params);
  267. if (false === $result) {
  268. return $this->fail(ServiceOrderLogic::getError());
  269. }
  270. return $this->data($result);
  271. }
  272. /**
  273. * 绑定工程师-设置为加单
  274. * @return \think\response\Json
  275. */
  276. public function bindWorkerAndWork()
  277. {
  278. $params = (new ServiceOrderValidate())->post()->goCheck('bindWorkerAndWork', [
  279. 'user_id' => $this->userId,
  280. 'user_info' => $this->userInfo
  281. ]);
  282. $result = ServiceOrderLogic::bindWorkerAndWork($params);
  283. if (false === $result) {
  284. return $this->fail(ServiceOrderLogic::getError());
  285. }
  286. return $this->success('绑定成功', [], 1, 1);
  287. }
  288. /**
  289. * 终止结束服务 - 上门费直接给工程师
  290. * @return \think\response\Json
  291. * @author liugc <466014217@qq.com>
  292. * @date 2025/5/5 19:03
  293. */
  294. public function terminateService()
  295. {
  296. $params = (new ServiceOrderValidate())->post()->goCheck('terminateService', [
  297. 'user_id' => $this->userId,
  298. 'user_info' => $this->userInfo
  299. ]);
  300. $params['isearnest'] = 0;
  301. $result = ServiceWorkLogic::terminateService($params);
  302. if (false === $result) {
  303. return $this->fail(ServiceWorkLogic::getError());
  304. }
  305. return $this->success('终止服务成功', [], 1, 1);
  306. }
  307. /**
  308. * 获取工单需支付信息
  309. * @return \think\response\Json
  310. * @author liugc <466014217@qq.com>
  311. * @date 2025/5/7 15:08
  312. */
  313. public function shareFixedAmountToNative()
  314. {
  315. try {
  316. $params = request()->post();
  317. $result = ServiceWorkLogic::shareFixedAmountToNative($params);
  318. if (false === $result) {
  319. return $this->fail(ServiceWorkLogic::getError());
  320. }
  321. return $this->success('', $result, 1, 1);
  322. } catch (Exception $e) {
  323. return $this->fail($e->getMessage());
  324. }
  325. }
  326. /**
  327. * 扫码分享的工单 - 获取工单信息
  328. * @return \think\response\Json
  329. * @author liugc <466014217@qq.com>
  330. * @date 2025/5/7 15:08
  331. */
  332. public function shareServiceWorkDetail()
  333. {
  334. try {
  335. $params = request()->post();
  336. $result = ServiceWorkLogic::shareServiceWorkDetail($params);
  337. return $this->data($result);
  338. } catch (Exception $e) {
  339. return $this->fail($e->getMessage());
  340. }
  341. }
  342. }