| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?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";
- $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
- print_r($data);
- $orderSn = $data['out_order_no'];
- 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("out_order_no",$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['pay_channel'];
- $order->pay_sn = $data['channel_pay_id'];
- $order->pay_money = $data['total_amount'];
- $order->save();
- return json(['err_no' => 0,'err_tips' => "success"]);
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- #[PostMapping("mini")]
- public function getOrderNotifyMini(Request $request): Response
- {
- try {
- $param = $request->all();
- echo getDateFull()."===支付返回\n";
- $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
- 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";
- $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
- print_r($data);
- $orderSn = $data['order_id'];
- 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());
- }
- }
- #[PostMapping("refund/mini")]
- public function getOrderRefundMini(Request $request): Response
- {
- try {
- $param = $request->all();
- echo getDateFull()."===小程序退款返回\n";
- $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
- 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['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());
- }
- }
- }
|