| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\controller\api;
- use app\extra\basic\Base;
- use app\model\saas\SaasOrder;
- use LinFly\Annotation\Attributes\Route\Controller;
- use LinFly\Annotation\Attributes\Route\PostMapping;
- use support\Request;
- use support\Response;
- #[Controller("/notify")]
- class Notify extends Base
- {
- #[PostMapping("douyin")]
- public function getOrderNotify(Request $request): Response
- {
- try {
- $param = $request->all();
- echo getDateFull()."===支付返回\n";
- print_r($param);
- $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
- print_r($param['msg']);
- print_r($data);
- $orderSn = $data['cp_extra'];
- if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
- if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
- $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
- if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
- if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
- $order->status = 1;
- $order->pay_at = getDateFull();
- $order->pay_type = $data['way'];
- $order->pay_sn = $data['cp_orderno'];
- $order->pay_money = $data['total_amount'];
- $order->save();
- return json(['err_no' => 0,'err_tips' => "success"]);
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- #[PostMapping("refund")]
- public function getOrderRefund(Request $request): Response
- {
- try {
- $param = $request->all();
- echo getDateFull()."===退款返回\n";
- print_r($param);
- $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
- $orderSn = $data['cp_extra'];
- if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
- if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
- $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
- if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
- $order->status = 3;
- $order->refund_at = getDateFull();
- $order->save();
- return json(['err_no' => 0,'err_tips' => "success"]);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|