| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace app\controller\api;
- use app\extra\basic\Base;
- use app\model\saas\SaasOrder;
- use app\model\saas\SaasOrderItem;
- 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"]);
- (new SaasOrderItem)->where("order_sn",$order['order_sn'])->update(['status' => 1]);
- $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("price")]
- public function getOrderNotifyPrice(Request $request): Response
- {
- try {
- $param = $request->all();
- echo getDateFull()."===支付返回\n";
- $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
- print_r($data);
- } catch (\Throwable $throwable) {
- return error($throwable->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"]);
- $itemNum = (new SaasOrderItem)->where(["order_sn" => $order['order_sn'],'status' => 2])->count();
- $trueNum = count($data['refund_item_detail']['item_order_detail']);
- if (($trueNum+$itemNum) <> $order['number']) { // 部分退款
- $order->status = 6;
- } else { // 全部退款
- $order->status = 3;
- }
- if (!empty($data['refund_item_detail']['item_order_detail']))
- {
- foreach ($data['refund_item_detail']['item_order_detail'] as $val) {
- (new SaasOrderItem)->where("item_order_id",$val['item_order_id'])->update(['status' => 2]);
- }
- }
- $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());
- }
- }
- }
|