Notify.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\controller\api;
  3. use app\extra\basic\Base;
  4. use app\model\saas\SaasOrder;
  5. use LinFly\Annotation\Attributes\Route\Controller;
  6. use LinFly\Annotation\Attributes\Route\PostMapping;
  7. use support\Request;
  8. use support\Response;
  9. #[Controller("/notify")]
  10. class Notify extends Base
  11. {
  12. #[PostMapping("douyin")]
  13. public function getOrderNotify(Request $request): Response
  14. {
  15. try {
  16. $param = $request->all();
  17. echo getDateFull()."===支付返回\n";
  18. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  19. print_r($data);
  20. $orderSn = $data['out_order_no'];
  21. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  22. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  23. $order = (new SaasOrder)->where("out_order_no",$orderSn)->findOrEmpty();
  24. if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
  25. if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
  26. $order->status = 1;
  27. $order->pay_at = getDateFull();
  28. $order->pay_type = $data['pay_channel'];
  29. $order->pay_sn = $data['channel_pay_id'];
  30. $order->pay_money = $data['total_amount'];
  31. $order->save();
  32. return json(['err_no' => 0,'err_tips' => "success"]);
  33. } catch (\Throwable $th) {
  34. return error($th->getMessage());
  35. }
  36. }
  37. #[PostMapping("price")]
  38. public function getOrderNotifyPrice(Request $request): Response
  39. {
  40. try {
  41. $param = $request->all();
  42. echo getDateFull()."===支付返回\n";
  43. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  44. print_r($data);
  45. } catch (\Throwable $throwable) {
  46. return error($throwable->getMessage());
  47. }
  48. }
  49. #[PostMapping("mini")]
  50. public function getOrderNotifyMini(Request $request): Response
  51. {
  52. try {
  53. $param = $request->all();
  54. echo getDateFull()."===支付返回\n";
  55. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  56. print_r($data);
  57. $orderSn = $data['cp_extra'];
  58. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  59. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  60. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  61. if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
  62. if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
  63. $order->status = 1;
  64. $order->pay_at = getDateFull();
  65. $order->pay_type = $data['way'];
  66. $order->pay_sn = $data['cp_orderno'];
  67. $order->pay_money = $data['total_amount'];
  68. $order->save();
  69. return json(['err_no' => 0,'err_tips' => "success"]);
  70. } catch (\Throwable $th) {
  71. return error($th->getMessage());
  72. }
  73. }
  74. #[PostMapping("refund")]
  75. public function getOrderRefund(Request $request): Response
  76. {
  77. try {
  78. $param = $request->all();
  79. echo getDateFull()."===退款返回\n";
  80. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  81. print_r($data);
  82. $orderSn = $data['order_id'];
  83. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  84. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  85. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  86. if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
  87. $order->status = 3;
  88. $order->refund_at = getDateFull();
  89. $order->save();
  90. return json(['err_no' => 0,'err_tips' => "success"]);
  91. } catch (\Throwable $throwable) {
  92. return error($throwable->getMessage());
  93. }
  94. }
  95. #[PostMapping("refund/mini")]
  96. public function getOrderRefundMini(Request $request): Response
  97. {
  98. try {
  99. $param = $request->all();
  100. echo getDateFull()."===小程序退款返回\n";
  101. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  102. print_r($data);
  103. $orderSn = $data['cp_extra'];
  104. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  105. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  106. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  107. if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
  108. $order->status = 3;
  109. $order->refund_at = getDateFull();
  110. $order->save();
  111. return json(['err_no' => 0,'err_tips' => "success"]);
  112. } catch (\Throwable $throwable) {
  113. return error($throwable->getMessage());
  114. }
  115. }
  116. }