ServiceOrderController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. 'user_info' => $this->userInfo,
  33. 'domain'=>$this->request->domain()
  34. ]);
  35. $result = ServiceOrderLogic::detail($params);
  36. if (false === $result) {
  37. return $this->fail(ServiceOrderLogic::getError());
  38. }
  39. return $this->data($result);
  40. }
  41. public function getDetailStatus()
  42. {
  43. $params = (new ServiceOrderValidate())->goCheck('detail',[
  44. 'user_id' => $this->userId,
  45. ]);
  46. $result = ServiceOrderLogic::getDetailStatus($params);
  47. if (false === $result) {
  48. return $this->fail(ServiceOrderLogic::getError());
  49. }
  50. return $this->data($result);
  51. }
  52. /**
  53. * 订单支付详情
  54. * @return \think\response\Json
  55. */
  56. public function orderPayInfo()
  57. {
  58. $params = (new ServiceOrderValidate())->goCheck('detail',[
  59. 'user_id' => $this->userId,
  60. ]);
  61. $result = ServiceOrderLogic::orderPayInfo($params);
  62. if (false === $result) {
  63. return $this->fail(ServiceOrderLogic::getError());
  64. }
  65. return $this->data($result);
  66. }
  67. public function getMasterWorker()
  68. {
  69. $params = (new ServiceOrderValidate())->goCheck('worker',[
  70. 'user_id' => $this->userId,
  71. ]);
  72. $result = ServiceOrderLogic::getMasterWorker($params);
  73. if (false === $result) {
  74. return $this->fail(ServiceOrderLogic::getError());
  75. }
  76. return $this->data($result);
  77. }
  78. /**
  79. * 提交订单
  80. * @return \think\response\Json
  81. */
  82. public function submitOrder()
  83. {
  84. $params = (new ServiceOrderValidate())->post()->goCheck('add', [
  85. 'user_id' => $this->userId,
  86. 'terminal' => $this->userInfo['terminal'],
  87. 'user_info' => $this->userInfo
  88. ]);
  89. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  90. $result = ServiceOrderLogic::submitOrder($params);
  91. if (false === $result) {
  92. return $this->fail(ServiceOrderLogic::getError());
  93. }
  94. ActivityLogic::createPropertyOrder($params,$result);
  95. return $this->data($result);
  96. }
  97. /**
  98. * 取消订单
  99. * @return \think\response\Json
  100. */
  101. public function cancelOrder()
  102. {
  103. $params = (new ServiceOrderValidate())->post()->goCheck('cancel', [
  104. 'user_id' => $this->userId,
  105. 'terminal' => $this->userInfo['terminal'],
  106. 'user_info' => $this->userInfo
  107. ]);
  108. $result = ServiceOrderLogic::cancelOrder($params);
  109. if (false === $result) {
  110. return $this->fail(ServiceOrderLogic::getError());
  111. }
  112. return $this->success('取消成功', [], 1, 1);
  113. }
  114. /**
  115. * 确认报价订单
  116. * @return \think\response\Json
  117. */
  118. public function confirmOrder()
  119. {
  120. $params = (new ServiceOrderValidate())->post()->goCheck('price', [
  121. 'user_id' => $this->userId,
  122. 'user_info' => $this->userInfo
  123. ]);
  124. $result = ServiceOrderLogic::confirmOrder($params);
  125. if (false === $result) {
  126. return $this->fail(ServiceOrderLogic::getError());
  127. }
  128. return $this->success('已确认报价,工程师即将开始服务', [], 1, 1);
  129. }
  130. /**
  131. * 用户确认服务完成
  132. * @return \think\response\Json
  133. */
  134. public function confirmServiceFinish()
  135. {
  136. $params = (new ServiceOrderValidate())->post()->goCheck('finished', [
  137. 'user_id' => $this->userId,
  138. 'user_info' => $this->userInfo
  139. ]);
  140. $result = ServiceOrderLogic::confirmServiceFinish($params);
  141. if (false === $result) {
  142. return $this->fail(ServiceOrderLogic::getError());
  143. }
  144. // 订单完成通知【给用户】 - 全款 -通知
  145. ServiceOrderLogic::serviceFinishNotice($params);
  146. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  147. ServiceOrderLogic::orderQuantityRule($params);
  148. return $this->success('已确认服务完成', [], 1, 1);
  149. }
  150. /**
  151. * 提交尾款订单
  152. * @return \think\response\Json
  153. */
  154. public function submitFinalOrder()
  155. {
  156. $params = (new ServiceOrderValidate())->post()->goCheck('final', [
  157. 'user_id' => $this->userId,
  158. 'terminal' => $this->userInfo['terminal'],
  159. 'user_info' => $this->userInfo
  160. ]);
  161. Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
  162. $result = ServiceOrderLogic::submitFinalOrder($params);
  163. if (false === $result) {
  164. return $this->fail(ServiceOrderLogic::getError());
  165. }
  166. return $this->data($result);
  167. }
  168. /**
  169. * 重置订单优惠券
  170. * @return \think\response\Json
  171. */
  172. public function cancelOrderCoupon()
  173. {
  174. $params = (new ServiceOrderValidate())->post()->goCheck('cancelOrderCoupon', [
  175. 'user_id' => $this->userId,
  176. 'user_info' => $this->userInfo
  177. ]);
  178. $result = ServiceOrderLogic::cancelOrderCoupon($params);
  179. if (false === $result) {
  180. return $this->fail(ServiceOrderLogic::getError());
  181. }
  182. return $this->success('保存成功', [], 1, 1);
  183. }
  184. /**
  185. * 查询是否在服务区内
  186. * @return \think\response\Json
  187. */
  188. public function isServiceWithin()
  189. {
  190. $params = (new ServiceOrderValidate())->get()->goCheck('LonLat', [
  191. 'user_id' => $this->userId,
  192. 'user_info' => $this->userInfo
  193. ]);
  194. $result = ServiceOrderLogic::isService($params);
  195. if (false === $result) {
  196. return $this->fail(ServiceOrderLogic::getError(),['is_service'=>0]);
  197. }
  198. return $this->success('服务区域内', ['is_service'=>1], 1, 1);
  199. }
  200. /**
  201. * 申请改价
  202. * @return \think\response\Json
  203. */
  204. public function approvalChangePrice()
  205. {
  206. $params = (new ServiceOrderValidate())->post()->goCheck('changePrice', [
  207. 'user_id' => $this->userId,
  208. 'user_info' => $this->userInfo
  209. ]);
  210. $result = ServiceOrderLogic::approvalChangePrice($params);
  211. if (false === $result) {
  212. return $this->fail(ServiceOrderLogic::getError());
  213. }
  214. return $this->success('已提交改价申请,等待工程师确认', [], 1, 1);
  215. }
  216. /**
  217. * 申请改约
  218. * @return \think\response\Json
  219. */
  220. public function approvalChangeAppointment()
  221. {
  222. $params = (new ServiceOrderValidate())->post()->goCheck('changeAppointment', [
  223. 'user_id' => $this->userId,
  224. 'user_info' => $this->userInfo
  225. ]);
  226. $result = ServiceOrderLogic::approvalChangeAppointment($params);
  227. if (false === $result) {
  228. return $this->fail(ServiceOrderLogic::getError());
  229. }
  230. if($result->master_worker_id!=0){
  231. $workDetail = ServiceWorkAppointmentLog::where(['work_id'=>$result['id']])->order('id desc')->findOrEmpty();
  232. $masterDetail = MasterWorkerLogic::detail(['id'=>$result['master_worker_id']]);
  233. // 修改预约时间通知【给用户的通知】
  234. $res = event('Notice', [
  235. 'scene_id' => 117,
  236. 'params' => [
  237. 'user_id' => $result['user_id'],
  238. 'date' => $params['appointment_time'],
  239. 'tel' => asteriskString($masterDetail['mobile']),
  240. ]
  241. ]);
  242. // 修改预约时间通知【给工程师的通知,仅限公众号】
  243. $res = event('Notice', [
  244. 'scene_id' => 118,
  245. 'params' => [
  246. 'user_id' => $result['master_worker_id'],
  247. 'order_id' => $result['id'],
  248. 'thing4' => $result['title'],
  249. 'time5' => date('Y-m-d H:i:s',$workDetail['last_appointment_time']),
  250. 'time6' => date('Y-m-d H:i:s',$workDetail['this_appointment_time']),
  251. 'thing11' => (iconv_strlen($result['address'])>15)?(mb_substr($result['address'],0,15,'UTF-8').'...'):$result['address'],
  252. 'phone_number8' => asteriskString($result['mobile']),
  253. ]
  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. /**
  298. * 绑定工程师-设置为加单
  299. * @return \think\response\Json
  300. */
  301. public function bindWorkerAndWork()
  302. {
  303. $params = (new ServiceOrderValidate())->post()->goCheck('bindWorkerAndWork', [
  304. 'user_id' => $this->userId,
  305. 'user_info' => $this->userInfo
  306. ]);
  307. $result = ServiceOrderLogic::bindWorkerAndWork($params);
  308. if (false === $result) {
  309. return $this->fail(ServiceOrderLogic::getError());
  310. }
  311. return $this->success('绑定成功', [], 1, 1);
  312. }
  313. }