1
0

ServiceOrderController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. public array $notNeedLogin = ['shareServiceWorkDetail'];
  18. /**
  19. * 订单列表
  20. * @return \think\response\Json
  21. */
  22. public function lists()
  23. {
  24. return $this->dataLists(new ServiceOrderLists());
  25. }
  26. /**
  27. * 订单详情
  28. * @return \think\response\Json
  29. */
  30. public function detail()
  31. {
  32. $params = (new ServiceOrderValidate())->goCheck('detail',[
  33. 'user_id' => $this->userId,
  34. 'user_info' => $this->userInfo,
  35. 'domain'=>$this->request->domain()
  36. ]);
  37. $result = ServiceOrderLogic::detail($params);
  38. if (false === $result) {
  39. return $this->fail(ServiceOrderLogic::getError());
  40. }
  41. return $this->data($result);
  42. }
  43. public function getDetailStatus()
  44. {
  45. $params = (new ServiceOrderValidate())->goCheck('detail',[
  46. 'user_id' => $this->userId,
  47. ]);
  48. $result = ServiceOrderLogic::getDetailStatus($params);
  49. if (false === $result) {
  50. return $this->fail(ServiceOrderLogic::getError());
  51. }
  52. return $this->data($result);
  53. }
  54. /**
  55. * 订单支付详情
  56. * @return \think\response\Json
  57. */
  58. public function orderPayInfo()
  59. {
  60. $params = (new ServiceOrderValidate())->goCheck('detail',[
  61. 'user_id' => $this->userId,
  62. ]);
  63. $result = ServiceOrderLogic::orderPayInfo($params);
  64. if (false === $result) {
  65. return $this->fail(ServiceOrderLogic::getError());
  66. }
  67. return $this->data($result);
  68. }
  69. public function getMasterWorker()
  70. {
  71. $params = (new ServiceOrderValidate())->goCheck('worker',[
  72. 'user_id' => $this->userId,
  73. ]);
  74. $result = ServiceOrderLogic::getMasterWorker($params);
  75. if (false === $result) {
  76. return $this->fail(ServiceOrderLogic::getError());
  77. }
  78. return $this->data($result);
  79. }
  80. /**
  81. * 提交订单
  82. * @return \think\response\Json
  83. */
  84. public function submitOrder()
  85. {
  86. $params = (new ServiceOrderValidate())->post()->goCheck('add', [
  87. 'user_id' => $this->userId,
  88. 'terminal' => $this->userInfo['terminal'],
  89. 'user_info' => $this->userInfo
  90. ]);
  91. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  92. $result = ServiceOrderLogic::submitOrder($params);
  93. if (false === $result) {
  94. return $this->fail(ServiceOrderLogic::getError());
  95. }
  96. ActivityLogic::createPropertyOrder($params,$result);
  97. return $this->data($result);
  98. }
  99. /**
  100. * 取消订单
  101. * @return \think\response\Json
  102. */
  103. public function cancelOrder()
  104. {
  105. $params = (new ServiceOrderValidate())->post()->goCheck('cancel', [
  106. 'user_id' => $this->userId,
  107. 'terminal' => $this->userInfo['terminal'],
  108. 'user_info' => $this->userInfo
  109. ]);
  110. $result = ServiceOrderLogic::cancelOrder($params);
  111. if (false === $result) {
  112. return $this->fail(ServiceOrderLogic::getError());
  113. }
  114. return $this->success('取消成功', [], 1, 1);
  115. }
  116. /**
  117. * 确认报价订单
  118. * @return \think\response\Json
  119. */
  120. public function confirmOrder()
  121. {
  122. $params = (new ServiceOrderValidate())->post()->goCheck('price', [
  123. 'user_id' => $this->userId,
  124. 'user_info' => $this->userInfo
  125. ]);
  126. /*$result = ServiceOrderLogic::confirmOrder($params);
  127. if (false === $result) {
  128. return $this->fail(ServiceOrderLogic::getError());
  129. }*/
  130. return $this->success('已确认报价,工程师即将开始服务', [], 1, 1);
  131. }
  132. /**
  133. * 用户确认服务完成
  134. * @return \think\response\Json
  135. */
  136. public function confirmServiceFinish()
  137. {
  138. $params = (new ServiceOrderValidate())->post()->goCheck('finished', [
  139. 'user_id' => $this->userId,
  140. 'user_info' => $this->userInfo
  141. ]);
  142. $result = ServiceOrderLogic::confirmServiceFinish($params);
  143. if (false === $result) {
  144. return $this->fail(ServiceOrderLogic::getError());
  145. }
  146. // 订单完成通知【给用户】 - 全款 -通知
  147. ServiceOrderLogic::serviceFinishNotice($params);
  148. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  149. ServiceOrderLogic::orderQuantityRule($params);
  150. return $this->success('已确认服务完成', [], 1, 1);
  151. }
  152. /**
  153. * 提交尾款订单
  154. * @return \think\response\Json
  155. */
  156. public function submitFinalOrder()
  157. {
  158. $params = (new ServiceOrderValidate())->post()->goCheck('final', [
  159. 'user_id' => $this->userId,
  160. 'terminal' => $this->userInfo['terminal'],
  161. 'user_info' => $this->userInfo
  162. ]);
  163. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  164. $result = ServiceOrderLogic::submitFinalOrder($params);
  165. if (false === $result) {
  166. return $this->fail(ServiceOrderLogic::getError());
  167. }
  168. return $this->data($result);
  169. }
  170. /**
  171. * 重置订单优惠券
  172. * @return \think\response\Json
  173. */
  174. public function cancelOrderCoupon()
  175. {
  176. $params = (new ServiceOrderValidate())->post()->goCheck('cancelOrderCoupon', [
  177. 'user_id' => $this->userId,
  178. 'user_info' => $this->userInfo
  179. ]);
  180. $result = ServiceOrderLogic::cancelOrderCoupon($params);
  181. if (false === $result) {
  182. return $this->fail(ServiceOrderLogic::getError());
  183. }
  184. return $this->success('保存成功', [], 1, 1);
  185. }
  186. /**
  187. * 查询是否在服务区内
  188. * @return \think\response\Json
  189. */
  190. public function isServiceWithin()
  191. {
  192. $params = (new ServiceOrderValidate())->get()->goCheck('LonLat', [
  193. 'user_id' => $this->userId,
  194. 'user_info' => $this->userInfo
  195. ]);
  196. $result = ServiceOrderLogic::isService($params);
  197. if (false === $result) {
  198. return $this->fail(ServiceOrderLogic::getError(),['is_service'=>0]);
  199. }
  200. return $this->success('服务区域内', ['is_service'=>1], 1, 1);
  201. }
  202. /**
  203. * 申请改价
  204. * @return \think\response\Json
  205. */
  206. public function approvalChangePrice()
  207. {
  208. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  209. 'user_id' => $this->userId,
  210. 'user_info' => $this->userInfo
  211. ]);
  212. $result = ServiceOrderLogic::approvalChangePrice($params);
  213. if (false === $result) {
  214. return $this->fail(ServiceOrderLogic::getError());
  215. }
  216. return $this->success('已提交改价申请,等待工程师确认', [], 1, 1);
  217. }
  218. /**
  219. * 申请改约
  220. * @return \think\response\Json
  221. */
  222. public function approvalChangeAppointment()
  223. {
  224. $params = (new ServiceOrderValidate())->post()->goCheck('changeAppointment', [
  225. 'user_id' => $this->userId,
  226. 'user_info' => $this->userInfo
  227. ]);
  228. $result = ServiceOrderLogic::approvalChangeAppointment($params);
  229. if (false === $result) {
  230. return $this->fail(ServiceOrderLogic::getError());
  231. }
  232. return $this->success('已提交改约', [], 1, 1);
  233. }
  234. /**
  235. * 提交退款申请
  236. * @return \think\response\Json
  237. */
  238. public function approvalRefund()
  239. {
  240. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  241. 'user_id' => $this->userId,
  242. 'user_info' => $this->userInfo
  243. ]);
  244. $result = ServiceOrderLogic::approvalRefund($params);
  245. if (false === $result) {
  246. return $this->fail(ServiceOrderLogic::getError());
  247. }
  248. return $this->success('已提交申请,等待客服确认中', [], 1, 1);
  249. }
  250. public function firmOrderLists()
  251. {
  252. return $this->dataLists(new ServiceOrderLists());
  253. }
  254. public function firmOrderSave()
  255. {
  256. $params = (new ServiceOrderValidate())->post()->goCheck('firmOrderSave', [
  257. 'user_id' => $this->userId,
  258. 'terminal' => $this->userInfo['terminal'],
  259. 'user_info' => $this->userInfo
  260. ]);
  261. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  262. if(count($params['order_goods']) == 0){
  263. return $this->fail('请选择商品');
  264. }else{
  265. $params['goods_id'] = $params['order_goods'][0]['id'];
  266. }
  267. $result = ServiceOrderLogic::firmSubmitOrder($params);
  268. if (false === $result) {
  269. return $this->fail(ServiceOrderLogic::getError());
  270. }
  271. return $this->data($result);
  272. }
  273. /**
  274. * 绑定工程师-设置为加单
  275. * @return \think\response\Json
  276. */
  277. public function bindWorkerAndWork()
  278. {
  279. $params = (new ServiceOrderValidate())->post()->goCheck('bindWorkerAndWork', [
  280. 'user_id' => $this->userId,
  281. 'user_info' => $this->userInfo
  282. ]);
  283. $result = ServiceOrderLogic::bindWorkerAndWork($params);
  284. if (false === $result) {
  285. return $this->fail(ServiceOrderLogic::getError());
  286. }
  287. return $this->success('绑定成功', [], 1, 1);
  288. }
  289. /**
  290. * 终止结束服务 - 上门费直接给工程师
  291. * @return \think\response\Json
  292. * @author liugc <466014217@qq.com>
  293. * @date 2025/5/5 19:03
  294. */
  295. public function terminateService()
  296. {
  297. $params = (new ServiceOrderValidate())->post()->goCheck('terminateService', [
  298. 'user_id' => $this->userId,
  299. 'user_info' => $this->userInfo
  300. ]);
  301. $params['isearnest'] = 0;
  302. $result = ServiceWorkLogic::terminateService($params);
  303. if (false === $result) {
  304. return $this->fail(ServiceWorkLogic::getError());
  305. }
  306. return $this->success('终止服务成功', [], 1, 1);
  307. }
  308. /**
  309. * 获取工单需支付信息
  310. * @return \think\response\Json
  311. * @author liugc <466014217@qq.com>
  312. * @date 2025/5/7 15:08
  313. */
  314. public function shareFixedAmountToNative()
  315. {
  316. try {
  317. $params = request()->post();
  318. $result = ServiceWorkLogic::shareFixedAmountToNative($params);
  319. if (false === $result) {
  320. return $this->fail(ServiceWorkLogic::getError());
  321. }
  322. return $this->success('', $result, 1, 1);
  323. } catch (Exception $e) {
  324. return $this->fail($e->getMessage());
  325. }
  326. }
  327. /**
  328. * 扫码分享的工单 - 获取工单信息
  329. * @return \think\response\Json
  330. * @author liugc <466014217@qq.com>
  331. * @date 2025/5/7 15:08
  332. */
  333. public function shareServiceWorkDetail()
  334. {
  335. try {
  336. $params = request()->post();
  337. $result = ServiceWorkLogic::shareServiceWorkDetail($params);
  338. return $this->data($result);
  339. } catch (Exception $e) {
  340. return $this->fail($e->getMessage());
  341. }
  342. }
  343. }