MeiTuanNotifyController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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\WorkEnum;
  6. use app\common\logic\ThirdOrderLogic;
  7. use app\common\model\equity\UserEquity;
  8. use app\common\model\orders\RechargeOrder;
  9. use app\common\model\recharge\OrderGoods;
  10. use app\common\model\third\ThirdOrders;
  11. use app\common\model\works\ServiceWork;
  12. use think\facade\Db;
  13. use think\facade\Log;
  14. /**
  15. *
  16. * Class MeiTuanNotifyController
  17. * @package app\api\controller\notify
  18. */
  19. class MeiTuanNotifyController extends BaseApiController
  20. {
  21. public array $notNeedLogin = ['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'];
  22. public function notifyAuth(): void
  23. {
  24. Log::write('店铺权限授权CODE:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  25. }
  26. public function notifyReviewAuth()
  27. {
  28. Log::write('店铺权限解约授权CODE:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  29. }
  30. /**
  31. * 门店映射
  32. * @return void
  33. */
  34. public function notifyMapping()
  35. {
  36. Log::write('门店映射:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  37. }
  38. // public function test()
  39. // {
  40. //// $data = array("businessId"=>"58","charset" => "utf-8","code"=>"828227b6489b14300c682e7b787d9afc", "developerId" => "114657","grantType"=>"authorization_code", "timestamp" => "1741664392");
  41. // $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}');
  42. // echo $this->get_sign("8471lgvnv0qcjpx6", $data);
  43. // }
  44. //到店综合
  45. /**
  46. * 取消预订
  47. * @return \think\response\Json
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function cancellation()
  53. {
  54. Log::write('取消预订:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  55. $order = $this->request->param();
  56. $order = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810001","developerId":"114657","businessId":"58","sign":"82db3112e2603fc65c9165c8c6f63ef2ff9d8f70","msgId":"4531348325686354394","message":"{\"cancelType\":\"1\",\"orderId\":\"61702316\",\"auditChannel\":\"2\",\"type\":\"2\"}","timestamp":"1741940681"}',true);
  57. ThirdOrderLogic::cancelOrderHandle($order);
  58. return $this->success('取消预订成功');
  59. }
  60. /**
  61. * 预订结果同步
  62. * @return void
  63. */
  64. public function bookingResults()
  65. {
  66. Log::write('预订结果同步:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  67. }
  68. /**
  69. * 开始预约
  70. * @return \think\response\Json
  71. */
  72. public function booking()
  73. {
  74. $order = $this->request->param();
  75. Log::write('开始预约:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  76. ThirdOrderLogic::orderhandle($order);
  77. return $this->success('开始预约');
  78. }
  79. /**
  80. * 改约提交
  81. * @return void
  82. */
  83. public function changeBooking()
  84. {
  85. $order = $this->request->param();
  86. Log::write('改约提交:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  87. }
  88. //到店综合(客服)-回调通知
  89. /**
  90. * 商品状态变更
  91. * @return void
  92. */
  93. public function cancellation5910003()
  94. {
  95. Log::write('商品状态变更:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  96. }
  97. /**
  98. * 改约结果同步三方
  99. * @return void
  100. */
  101. public function bookingResults5910005()
  102. {
  103. Log::write('改约结果同步三方:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  104. }
  105. /**
  106. * 取消同步三方接口
  107. * @return void
  108. */
  109. public function booking5910011()
  110. {
  111. Log::write('取消同步三方接口:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  112. }
  113. /**
  114. * 创单同步三方接口
  115. * @return void
  116. */
  117. public function booking5910015()
  118. {
  119. Log::write('创单同步三方接口:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  120. }
  121. /**
  122. * 用户改约
  123. * @return void
  124. */
  125. public function booking5910017()
  126. {
  127. Log::write('用户改约:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  128. }
  129. /**
  130. * 手动提交美团订单
  131. * @return \think\response\Json
  132. */
  133. public function submitOrder()
  134. {
  135. $request = $this->request->param();
  136. if(empty($request['userName']) || empty($request['mobile']) || empty($request['userAddress']) || empty($request['appointment_time']) || empty($request['goods_id']) || empty($request['amount'])){
  137. return $this->fail('参数错误');
  138. }
  139. ThirdOrderLogic::submitOrders($request);
  140. return $this->success('下单成功');
  141. }
  142. /**
  143. * 用户撤销退款通知
  144. * @return void
  145. */
  146. public function notify5810005()
  147. {
  148. Log::write('用户撤销退款通知:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  149. }
  150. /**
  151. * 改约结果通知三方
  152. * @return void
  153. */
  154. public function notify5810007()
  155. {
  156. Log::write('改约结果通知三方:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  157. }
  158. public function notify5810009()
  159. {
  160. Log::write('到家行业库存查询:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  161. }
  162. public function notify5810013()
  163. {
  164. Log::write('取消预订审核:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  165. }
  166. public function notify5810023()
  167. {
  168. Log::write('核销状态查询:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  169. }
  170. public function notify5810027()
  171. {
  172. Log::write('通知三方核销:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  173. }
  174. public function notify5810029()
  175. {
  176. //尾款结算2--维修的尾款订单信息增加
  177. //获取工单信息
  178. $request = $this->request->param();
  179. // $request = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810029","developerId":"114657","businessId":"58","sign":"01b0ddb70d91a22d7e22f04935e938413142e16e","msgId":"7475175529296583912","message":"{\"orderId\":\"61374467\",\"addPriceStatus\":\"0\",\"serialNumber\":\"8283252725\",\"amount\":\"1.00\"}","timestamp":"1741600285"}',true);
  180. Log::write('补价支付结果:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  181. if(!empty($request['message'])){
  182. Db::startTrans();
  183. try {
  184. $message = json_decode($request['message'], true);
  185. $orderId = $message['orderId'];
  186. $amount = $message['amount'];
  187. $order = ThirdOrders::where('orderId',$orderId)->order('create_time desc')->findOrEmpty();
  188. if(!$order->isEmpty() && $order['verifyStatus'] != 2){
  189. $un_pay = RechargeOrder::where(['work_id'=>$order['work_id'],'pay_status'=>0])->findOrEmpty();
  190. if(!$un_pay->isEmpty()){
  191. $un_pay->pay_status = PayEnum::ISPAID;
  192. $un_pay->pay_time = time();
  193. $un_pay->order_amount = $amount;
  194. $un_pay->paid_amount = $amount;
  195. $un_pay->save();
  196. }else{
  197. $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
  198. if(count($orders)==1){
  199. //判断是否是一口价预支付订单,支付成功后生成尾款订单,针对工程师未报价的订单
  200. $good_order = $orders[0];
  201. $order_goods = OrderGoods::where('sn',$good_order->sn)->findOrEmpty();
  202. if(!$order_goods->isEmpty()){
  203. //新增待支付尾款
  204. $order_data = [
  205. 'order_type'=>$good_order['order_type'],
  206. 'sn'=>generate_sn(\app\common\model\orders\RechargeOrder::class, 'sn'),
  207. 'work_id'=>$good_order['work_id'],
  208. 'user_id'=>$good_order['user_id'],
  209. 'payment_type'=>2,
  210. 'order_total'=>$amount,
  211. 'order_amount'=>$amount,
  212. 'order_terminal'=>$good_order['order_terminal'],
  213. 'pay_status'=>PayEnum::ISPAID,
  214. 'pay_time'=>time(),
  215. 'paid_amount'=>$amount
  216. ];
  217. \app\common\model\recharge\RechargeOrder::create($order_data);
  218. }
  219. }
  220. }
  221. }
  222. Db::commit();
  223. }catch(\Exception $e){
  224. Db::rollback();
  225. return $this->fail('尾款支付失败');
  226. }
  227. }
  228. return $this->success('尾款支付成功');
  229. }
  230. public function notify5810031()
  231. {
  232. //尾款结算1 //尾款结算3
  233. //获取工单信息
  234. $request = $this->request->param();
  235. // $request = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810031","developerId":"114657","businessId":"58","sign":"d43ab164d41859ce7df2894e3e8f086d0c3182cb","msgId":"-1355174693375827369","message":"{\"orderId\":\"61659141\",\"verifyStatus\":\"2\",\"verifyChannel\":\"1\",\"type\":\"2\",\"serialNumber\":\"7843863751\"}","timestamp":"1741927727"}',true);
  236. Log::write('预订核销同步:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  237. if(!empty($request['message'])){
  238. Db::startTrans();
  239. try {
  240. $message = json_decode($request['message'], true);
  241. $orderId = $message['orderId'];
  242. $order = ThirdOrders::where('orderId',$orderId)->order('create_time desc')->findOrEmpty();
  243. if(!$order->isEmpty() && $order['verifyStatus'] != 2 && $message['verifyStatus'] == 2){
  244. //判断工单是否存在未结算的尾款订单,如果存在,等待结算后再核销
  245. $un_pay = RechargeOrder::where(['work_id'=>$order['work_id'],'pay_status'=>0])->findOrEmpty();
  246. $workOrder = RechargeOrder::where('work_id',$order['work_id'])->order('id desc')->findOrEmpty();
  247. if($un_pay->isEmpty() && ($workOrder['payment_type'] == 0 || $workOrder['payment_type'] == 2)){
  248. $work = ServiceWork::where('id',$order['work_id'])->findOrEmpty();
  249. $order->verifyStatus = 2;
  250. $order->save();
  251. if(!$work->isEmpty()){
  252. $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
  253. $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
  254. $order_total = 0;
  255. $order_amount = 0;
  256. foreach ($orders as $k=>$v){
  257. $order_total += $v['order_total'];
  258. $order_amount += $v['order_amount'];
  259. }
  260. $work->work_total = $order_total;
  261. $work->work_amount = $order_amount;
  262. $work->work_status = 7;
  263. $work->user_confirm_status = 5;
  264. $work->service_status = 3;
  265. $work->work_pay_status = 1;
  266. $work->save();
  267. }
  268. }
  269. }
  270. Db::commit();
  271. }catch(\Exception $e){
  272. Db::rollback();
  273. return $this->fail('订单核销失败');
  274. }
  275. return $this->success('订单核销成功');
  276. }
  277. }
  278. public function notify5810099()
  279. {
  280. //尾款结算4
  281. // {"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"}
  282. Log::write('加价尾单核销通知:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
  283. }
  284. //商家操作接口
  285. public function bookresultcallback()
  286. {
  287. ThirdOrderLogic::bookresultcallback('61427436',2);
  288. }
  289. /**
  290. * 商家确认改约接口
  291. * @return void
  292. */
  293. public function changeresultcallback()
  294. {
  295. //changeresultcallback-$shop_token2
  296. }
  297. }