Notify.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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['cp_extra'];
  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("order_sn",$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['way'];
  31. $order->pay_sn = $data['cp_orderno'];
  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("refund")]
  40. public function getOrderRefund(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. $orderSn = $data['cp_extra'];
  48. if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
  49. if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
  50. $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
  51. if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
  52. $order->status = 3;
  53. $order->refund_at = getDateFull();
  54. $order->save();
  55. return json(['err_no' => 0,'err_tips' => "success"]);
  56. } catch (\Throwable $throwable) {
  57. return error($throwable->getMessage());
  58. }
  59. }
  60. }