Notify.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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("mini")]
  38. public function getOrderNotifyMini(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. $orderSn = $data['cp_extra'];
  46. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  47. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  48. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  49. if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
  50. if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
  51. $order->status = 1;
  52. $order->pay_at = getDateFull();
  53. $order->pay_type = $data['way'];
  54. $order->pay_sn = $data['cp_orderno'];
  55. $order->pay_money = $data['total_amount'];
  56. $order->save();
  57. return json(['err_no' => 0,'err_tips' => "success"]);
  58. } catch (\Throwable $th) {
  59. return error($th->getMessage());
  60. }
  61. }
  62. #[PostMapping("refund")]
  63. public function getOrderRefund(Request $request): Response
  64. {
  65. try {
  66. $param = $request->all();
  67. echo getDateFull()."===退款返回\n";
  68. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  69. print_r($data);
  70. $orderSn = $data['order_id'];
  71. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  72. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  73. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  74. if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
  75. $order->status = 3;
  76. $order->refund_at = getDateFull();
  77. $order->save();
  78. return json(['err_no' => 0,'err_tips' => "success"]);
  79. } catch (\Throwable $throwable) {
  80. return error($throwable->getMessage());
  81. }
  82. }
  83. #[PostMapping("refund/mini")]
  84. public function getOrderRefundMini(Request $request): Response
  85. {
  86. try {
  87. $param = $request->all();
  88. echo getDateFull()."===小程序退款返回\n";
  89. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  90. print_r($data);
  91. $orderSn = $data['cp_extra'];
  92. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  93. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  94. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  95. if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
  96. $order->status = 3;
  97. $order->refund_at = getDateFull();
  98. $order->save();
  99. return json(['err_no' => 0,'err_tips' => "success"]);
  100. } catch (\Throwable $throwable) {
  101. return error($throwable->getMessage());
  102. }
  103. }
  104. }