Notify.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. print_r($param);
  19. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  20. print_r($param['msg']);
  21. print_r($data);
  22. $orderSn = $data['out_order_no'];
  23. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  24. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  25. $order = (new SaasOrder)->where("out_order_no",$orderSn)->findOrEmpty();
  26. if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
  27. if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
  28. $order->status = 1;
  29. $order->pay_at = getDateFull();
  30. $order->pay_type = $data['pay_channel'];
  31. $order->pay_sn = $data['channel_pay_id'];
  32. $order->pay_money = $data['total_amount'];
  33. $order->save();
  34. return json(['err_no' => 0,'err_tips' => "success"]);
  35. } catch (\Throwable $th) {
  36. return error($th->getMessage());
  37. }
  38. }
  39. #[PostMapping("mini")]
  40. public function getOrderNotifyMini(Request $request): Response
  41. {
  42. try {
  43. $param = $request->all();
  44. echo getDateFull()."===支付返回\n";
  45. print_r($param);
  46. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  47. print_r($param['msg']);
  48. print_r($data);
  49. $orderSn = $data['cp_extra'];
  50. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  51. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  52. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  53. if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
  54. if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
  55. $order->status = 1;
  56. $order->pay_at = getDateFull();
  57. $order->pay_type = $data['way'];
  58. $order->pay_sn = $data['cp_orderno'];
  59. $order->pay_money = $data['total_amount'];
  60. $order->save();
  61. return json(['err_no' => 0,'err_tips' => "success"]);
  62. } catch (\Throwable $th) {
  63. return error($th->getMessage());
  64. }
  65. }
  66. #[PostMapping("refund")]
  67. public function getOrderRefund(Request $request): Response
  68. {
  69. try {
  70. $param = $request->all();
  71. echo getDateFull()."===退款返回\n";
  72. print_r($param);
  73. $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
  74. $orderSn = $data['cp_extra'];
  75. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  76. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  77. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  78. if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
  79. $order->status = 3;
  80. $order->refund_at = getDateFull();
  81. $order->save();
  82. return json(['err_no' => 0,'err_tips' => "success"]);
  83. } catch (\Throwable $throwable) {
  84. return error($throwable->getMessage());
  85. }
  86. }
  87. }