MeiTuanNotifyController.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <?php
  2. namespace app\api\controller\notify;
  3. use app\api\controller\BaseApiController;
  4. use app\common\enum\PayEnum;
  5. use app\common\enum\ThirdTypeEnum;
  6. use app\common\enum\WorkEnum;
  7. use app\common\logic\ThirdOrderLogic;
  8. use app\common\model\equity\UserEquity;
  9. use app\common\model\orders\RechargeOrder;
  10. use app\common\model\recharge\OrderGoods;
  11. use app\common\model\third\ThirdOrders;
  12. use app\common\model\works\ServiceWork;
  13. use think\facade\Db;
  14. use think\facade\Log;
  15. /**
  16. *
  17. * Class MeiTuanNotifyController
  18. * @package app\api\controller\notify
  19. */
  20. class MeiTuanNotifyController extends BaseApiController
  21. {
  22. public array $notNeedLogin = ['changeresultcallback','finishedWork','bookresultcallback','notify5810099','notify5810005','notify5810007','notify5810009','notify5810013','notify5810023','notify5810027','notify5810029','notify5810031','notifyMapping','submitOrder','notifyAuth','notifyReviewAuth','get_sign','test','cancellation','bookingResults','booking','changeBooking','cancellation5910003','bookingResults5910005','booking5910011','booking5910015','booking5910017'];
  23. public function notifyAuth(): void
  24. {
  25. Log::write('店铺权限授权CODE:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  26. }
  27. public function notifyReviewAuth()
  28. {
  29. Log::write('店铺权限解约授权CODE:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  30. }
  31. /**
  32. * 门店映射
  33. * @return void
  34. */
  35. public function notifyMapping()
  36. {
  37. Log::write('门店映射:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  38. }
  39. public function test()
  40. {
  41. $data = array("businessId"=>"58","charset" => "utf-8","code"=>"7355f0a0d01f31e7963f23f6e20519f5", "developerId" => "114657","grantType"=>"authorization_code", "timestamp" => "1744107897");
  42. // $data = array("businessId"=>"58","charset" => "utf-8","appAuthToken"=>"V2-26f91ef8b515c59b97b9b4404e77dc2b2fc14b9715e3be7edb9f3f86178e193ec380e1ef5a9ab7a877120a94bcae4586707c51ab5e56cfeb4cd91d4fb2983babbbfd2fda0f77353eb21b105fd14299aea392a706589a422baec961b6cc255191", "developerId" => "114657","version"=>"2", "timestamp" => "1741663560",'biz'=>'{ "orderId": "61427436", "bookStatus": 2, "code": 200,"type":2}');
  43. echo $this->get_sign("8471lgvnv0qcjpx6", $data);
  44. }
  45. public static function get_sign($sign_key, $data)
  46. {
  47. if ($data == null) {
  48. return null;
  49. }
  50. ksort($data);
  51. $result_str = "";
  52. foreach ($data as $key => $val) {
  53. if ($key != "sign" && $val != null && $val != "") {
  54. $result_str = $result_str . $key . $val;
  55. }
  56. }
  57. $result_str = $sign_key . $result_str;
  58. $ret = bin2hex(sha1($result_str, true));
  59. return $ret;
  60. }
  61. //到店综合
  62. /**
  63. * 取消预订
  64. * @return \think\response\Json
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\DbException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. */
  69. public function cancellation()
  70. {
  71. return '';
  72. http_request('https://developer.kyjlkj.com/platf/kaidianbao/cancellationByUser',http_build_query($this->request->param()));
  73. Log::write('取消预订:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  74. $order = $this->request->param();
  75. ThirdOrderLogic::cancelOrderHandle($order);
  76. return $this->success('取消预订成功');
  77. }
  78. /**
  79. * 预订结果同步
  80. * @return void
  81. */
  82. public function bookingResults()
  83. {
  84. return '';
  85. http_request('https://developer.kyjlkj.com/platf/kaidianbao/reservationResults',http_build_query($this->request->param()));
  86. Log::write('预订结果同步:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  87. }
  88. /**
  89. * 开始预约
  90. * @return \think\response\Json
  91. */
  92. public function booking()
  93. {
  94. return '';
  95. http_request('https://developer.kyjlkj.com/platf/kaidianbao/reservation',http_build_query($this->request->param()));
  96. $order = $this->request->param();
  97. Log::write('开始预约:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  98. //手动处理未配置的工单
  99. // $request_msg = ThirdOrders::where('id',51)->findOrEmpty()['request_msg'];
  100. // $order = json_decode($request_msg,true);
  101. ThirdOrderLogic::orderhandle($order);
  102. return $this->success('开始预约');
  103. }
  104. /**
  105. * 改约提交
  106. * @return \think\response\Json
  107. */
  108. public function changeBooking()
  109. {
  110. return '';
  111. http_request('https://developer.kyjlkj.com/platf/kaidianbao/reschedulingByUser',http_build_query($this->request->param()));
  112. $order = $this->request->param();
  113. Log::write('改约提交:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  114. ThirdOrderLogic::updateOrderHandle($order);
  115. return $this->success('改约提交成功');
  116. }
  117. //到店综合(客服)-回调通知
  118. /**
  119. * 商品状态变更
  120. * @return void
  121. */
  122. public function cancellation5910003()
  123. {
  124. Log::write('商品状态变更:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  125. }
  126. /**
  127. * 改约结果同步三方
  128. * @return void
  129. */
  130. public function bookingResults5910005()
  131. {
  132. Log::write('改约结果同步三方:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  133. }
  134. /**
  135. * 取消同步三方接口
  136. * @return void
  137. */
  138. public function booking5910011()
  139. {
  140. Log::write('取消同步三方接口:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  141. }
  142. /**
  143. * 创单同步三方接口
  144. * @return void
  145. */
  146. public function booking5910015()
  147. {
  148. Log::write('创单同步三方接口:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  149. }
  150. /**
  151. * 用户改约
  152. * @return void
  153. */
  154. public function booking5910017()
  155. {
  156. Log::write('用户改约:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  157. }
  158. /**
  159. * 手动提交美团订单
  160. * @return \think\response\Json
  161. */
  162. public function submitOrder()
  163. {
  164. $request = $this->request->param();
  165. if(empty($request['userName']) || empty($request['mobile']) || empty($request['userAddress']) || empty($request['appointment_time']) || empty($request['goods_id']) || empty($request['amount'])){
  166. return $this->fail('参数错误');
  167. }
  168. ThirdOrderLogic::submitOrders($request);
  169. return $this->success('下单成功');
  170. }
  171. /**
  172. * 用户撤销退款通知
  173. * @return void
  174. */
  175. public function notify5810005()
  176. {
  177. Log::write('用户撤销退款通知:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  178. }
  179. /**
  180. * 改约结果通知三方
  181. * @return void
  182. */
  183. public function notify5810007()
  184. {
  185. return '';
  186. http_request('https://developer.kyjlkj.com/platf/kaidianbao/reschedulingResults',http_build_query($this->request->param()));
  187. Log::write('改约结果通知三方:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  188. }
  189. public function notify5810009()
  190. {
  191. return '';
  192. http_request('https://developer.kyjlkj.com/platf/Kaidianbao/inventory',http_build_query($this->request->param()));
  193. Log::write('到家行业库存查询:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  194. }
  195. public function notify5810013()
  196. {
  197. Log::write('取消预订审核:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  198. }
  199. public function notify5810023()
  200. {
  201. return '';
  202. http_request('https://developer.kyjlkj.com/platf/Kaidianbao/completedDetails',http_build_query($this->request->param()));
  203. Log::write('核销状态查询:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  204. }
  205. public function notify5810027()
  206. {
  207. return '';
  208. Log::write('通知三方核销:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  209. }
  210. public function notify5810029()
  211. {
  212. return '';
  213. http_request('https://developer.kyjlkj.com/platf/Kaidianbao/completedByArrears',http_build_query($this->request->param()));
  214. //尾款结算2--维修的尾款订单信息增加
  215. //获取工单信息
  216. $request = $this->request->param();
  217. // $request = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810029","developerId":"114657","businessId":"58","sign":"7f936c6c65ee05fa50a105fdc7bbb2652ccfe9b6","msgId":"2993785907604100573","message":"{\"orderId\":\"62737288\",\"addPriceStatus\":\"0\",\"serialNumber\":\"5962563697\",\"amount\":\"9.90\"}","timestamp":"1742907755"}',true);
  218. Log::write('补价支付结果:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  219. if(!empty($request['message'])){
  220. Db::startTrans();
  221. try {
  222. $message = json_decode($request['message'], true);
  223. $orderId = $message['orderId'];
  224. $amount = $message['amount'];
  225. $order = ThirdOrders::where('orderId',$orderId)->order('create_time desc')->findOrEmpty();
  226. if(!$order->isEmpty() && $order['verifyStatus'] != 2){
  227. $un_pay = RechargeOrder::where(['work_id'=>$order['work_id'],'pay_status'=>0])->findOrEmpty();
  228. if(!$un_pay->isEmpty()){
  229. $un_pay->pay_way = 4;//美团支付
  230. $un_pay->pay_status = PayEnum::ISPAID;
  231. $un_pay->pay_time = time();
  232. $un_pay->order_amount = $amount;
  233. $un_pay->paid_amount = $amount;
  234. $un_pay->save();
  235. }else{
  236. $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
  237. if(count($orders)==1){
  238. //判断是否是一口价预支付订单,支付成功后生成尾款订单,针对工程师未报价的订单
  239. $good_order = $orders[0];
  240. $order_goods = OrderGoods::where('sn',$good_order['sn'])->findOrEmpty();
  241. if(!$order_goods->isEmpty()){
  242. //新增待支付尾款
  243. $order_data = [
  244. 'order_type'=>$good_order['order_type'],
  245. 'sn'=>generate_sn(\app\common\model\orders\RechargeOrder::class, 'sn'),
  246. 'work_id'=>$good_order['work_id'],
  247. 'user_id'=>$good_order['user_id'],
  248. 'payment_type'=>2,
  249. 'order_total'=>$amount,
  250. 'order_amount'=>$amount,
  251. 'order_terminal'=>$good_order['order_terminal'],
  252. 'pay_status'=>PayEnum::ISPAID,
  253. 'pay_time'=>time(),
  254. 'paid_amount'=>$amount,
  255. 'pay_way'=>4//美团支付
  256. ];
  257. \app\common\model\recharge\RechargeOrder::create($order_data);
  258. }
  259. }
  260. }
  261. //结算工单
  262. $work = ServiceWork::where('id',$order['work_id'])->findOrEmpty();
  263. if(!$work->isEmpty()){
  264. $order->verifyStatus = 2;
  265. $order->save();
  266. $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
  267. $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order['work_id']])->select()->toArray();
  268. $order_total = 0;
  269. $order_amount = 0;
  270. foreach ($orders as $k=>$v){
  271. $order_total += $v['order_total'];
  272. $order_amount += $v['order_amount'];
  273. }
  274. $work->work_total = $order_total;
  275. $work->work_amount = $order_amount;
  276. $work->work_status = 7;
  277. $work->user_confirm_status = 5;
  278. $work->service_status = 3;
  279. $work->work_pay_status = 1;
  280. $work->finished_time = time();
  281. $work->save();
  282. ThirdOrderLogic::updateorderfulfillinfo($work,ThirdTypeEnum::MEITUAN_COMPLETION);
  283. }
  284. }
  285. Db::commit();
  286. }catch(\Exception $e){
  287. Db::rollback();
  288. return $this->fail('尾款支付失败');
  289. }
  290. }
  291. return $this->success('尾款支付成功');
  292. }
  293. public function notify5810031()
  294. {
  295. return '';
  296. http_request('https://developer.kyjlkj.com/platf/Kaidianbao/completedByUser',http_build_query($this->request->param()));
  297. //尾款结算1 //尾款结算3
  298. //获取工单信息
  299. $request = $this->request->param();
  300. // $request = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810031","developerId":"114657","businessId":"58","sign":"70e9ab334024101d8601276e5e3a24f459005a1e","msgId":"8401776939815074952","message":"{\"orderId\":\"63702731\",\"verifyStatus\":\"2\",\"verifyChannel\":\"1\",\"type\":\"2\",\"serialNumber\":\"4078677902\"}","timestamp":"1743944824"}',true);
  301. Log::write('预订核销同步:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  302. if(!empty($request['message'])){
  303. Db::startTrans();
  304. try {
  305. $message = json_decode($request['message'], true);
  306. $orderId = $message['orderId'];
  307. $order = ThirdOrders::where('orderId',$orderId)->order('create_time desc')->findOrEmpty();
  308. if(!$order->isEmpty() && $order['verifyStatus'] != 2 && $message['verifyStatus'] == 2){
  309. //判断工单是否存在未结算的尾款订单,如果存在,等待结算后再核销
  310. $un_pay = RechargeOrder::where(['work_id'=>$order['work_id'],'pay_status'=>0])->findOrEmpty();
  311. $workOrder = RechargeOrder::where('work_id',$order['work_id'])->order('id desc')->findOrEmpty();
  312. if($un_pay->isEmpty() && ($workOrder['payment_type'] == 0 || $workOrder['payment_type'] == 2)){
  313. $work = ServiceWork::where('id',$order['work_id'])->findOrEmpty();
  314. $order->verifyStatus = 2;
  315. $order->save();
  316. if(!$work->isEmpty()){
  317. $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
  318. $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
  319. $order_total = 0;
  320. $order_amount = 0;
  321. foreach ($orders as $k=>$v){
  322. $order_total += $v['order_total'];
  323. $order_amount += $v['order_amount'];
  324. }
  325. $work->work_total = $order_total;
  326. $work->work_amount = $order_amount;
  327. $work->work_status = 7;
  328. $work->user_confirm_status = 5;
  329. $work->service_status = 3;
  330. $work->work_pay_status = 1;
  331. $work->finished_time = time();
  332. $work->save();
  333. ThirdOrderLogic::updateorderfulfillinfo($work,ThirdTypeEnum::MEITUAN_COMPLETION);
  334. }
  335. }
  336. }
  337. Db::commit();
  338. }catch(\Exception $e){
  339. Db::rollback();
  340. return $this->fail('订单核销失败');
  341. }
  342. return $this->success('订单核销成功');
  343. }
  344. }
  345. /**
  346. * 手动完结订单
  347. * @return \think\response\Json
  348. */
  349. public function finishedWork()
  350. {
  351. $work = ServiceWork::where('id',324)->findOrEmpty();
  352. if(!$work->isEmpty()){
  353. $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
  354. $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>324])->select()->toArray();
  355. $order_total = 0;
  356. $order_amount = 0;
  357. foreach ($orders as $k=>$v){
  358. $order_total += $v['order_total'];
  359. $order_amount += $v['order_amount'];
  360. }
  361. $work->work_total = $order_total;
  362. $work->work_amount = $order_amount;
  363. $work->work_status = 7;
  364. $work->user_confirm_status = 5;
  365. $work->service_status = 3;
  366. $work->work_pay_status = 1;
  367. $work->finished_time = time();
  368. $work->save();
  369. }
  370. return $this->success('订单核销成功');
  371. }
  372. public function notify5810099()
  373. {
  374. return '';
  375. //尾款结算4
  376. // {"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810099","developerId":"114657","businessId":"58","sign":"a726ef82351172679a8faf83e1c687e23930f3e9","msgId":"-8772277532478005199","message":"{\"phone\":\"13545228441\",\"dealGroupId\":\"1287039501\",\"dealName\":\"【燃气灶维修】不打火维修电话安装上门维修优惠卷\",\"amount\":\"31.00\",\"firstOrderId\":\"4981005619907623352\",\"firstOrderCode\":\"5831711557\",\"firstOrderActualPrice\":\"30.00\",\"finalOrderId\":\"4981005652342579640\",\"finalOrderCode\":\"8283252725\",\"finalOrderActualPrice\":\"1.00\",\"firstOrderDiscountAmount\":\"0.00\",\"finalOrderDiscountAmount\":\"0.00\",\"dealUnitAmount\":\"30.00\",\"firstOrderPrice\":\"30.00\",\"finalOrderPrice\":\"1.00\"}","timestamp":"1741600287"}
  377. Log::write('加价尾单核销通知:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  378. }
  379. //商家操作接口
  380. public function bookresultcallback()
  381. {
  382. return '';
  383. $a = ThirdOrderLogic::bookresultcallback('AE7MKOJAV67338LIC3UD0K5TGIO','63950625',2);
  384. dd($a);
  385. }
  386. /**
  387. * 商家确认改约接口
  388. * @return void
  389. */
  390. public function changeresultcallback()
  391. {
  392. return '';
  393. //changeresultcallback-$shop_token2
  394. $a = ThirdOrderLogic::changeresultcallback('64201808');
  395. dd($a);
  396. }
  397. }