ServiceOrderController.php 10 KB

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