From cf384e724e1eead005cf9013ad6672d694a57510 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Wed, 5 Jun 2024 12:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/PayController.php | 3 -- app/api/controller/order/OrderController.php | 2 +- app/common/enum/OrderEnum.php | 8 ++++ app/common/logic/PayNotifyLogic.php | 49 +++++++++++++++++++- app/common/model/pay/PayNotify.php | 10 ++++ 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 app/common/model/pay/PayNotify.php diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php index 8bbf48f8..ded81e91 100644 --- a/app/api/controller/PayController.php +++ b/app/api/controller/PayController.php @@ -28,12 +28,9 @@ class PayController extends BaseApiController { $app = new PayService(1); $result = $app->wechat->callback(Request()->post()); - Cache::set('log'.time(),$result); - Cache::set('logJ'.time(),json_encode($result)); if ($result && $result->event_type == 'TRANSACTION.SUCCESS') { $ciphertext = $result->resource['ciphertext']; if ($ciphertext['trade_state'] === 'SUCCESS') { - $extra['transaction_id'] = $ciphertext['transaction_id']; $attach = $ciphertext['attach']; switch ($attach) { case 'wechat_common': diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 5d918bc4..bee4effe 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -130,7 +130,7 @@ class OrderController extends BaseApiController case PayEnum::WECHAT_PAY: //微信支付 $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; - $result = PaymentLogic::pay($pay_type, 'StoreOrder', $order, $this->userInfo['terminal'], $redirectUrl); + $result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'], $redirectUrl); if (PaymentLogic::hasError()) { return $this->fail(PaymentLogic::getError(), $params); } diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 43dceeed..6fa8fc99 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -53,6 +53,14 @@ class OrderEnum */ const IS_OK = 1; + /** + * 回调订单相关 + * @PAY 支付 + * @IBACK 退款 + */ + const PAY = 1; + const BACK = 0; + /** * 账户类型 * @USER 用户 diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 24653c9c..96458d2a 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -4,6 +4,7 @@ namespace app\common\logic; use app\common\enum\OrderEnum; use app\common\enum\PayEnum; +use app\common\model\pay\PayNotify; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; use app\common\model\user\User; @@ -97,7 +98,7 @@ class PayNotifyLogic extends BaseLogic } else { PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); Redis::send('push-platform-print', ['order_id' => $order['id']], 60); - Db::name('order_middle')->insert(['c_order_id' => $order['id']]); +// Db::name('order_middle')->insert(['c_order_id' => $order['id']]); } if (!empty($extra['payer']['openid']) && $order->pay_type != 9) { Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5); @@ -105,6 +106,31 @@ class PayNotifyLogic extends BaseLogic return true; } + + public static function store_order($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + return true; + } + if ($order->pay_type != 10) { + $order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2); + $order->paid = 1; + $order->pay_time = time(); + $order->status = 1; + $order->save(); + } else { + $extra['transaction_id'] = time(); + } + if ($order->pay_type == 9) { + $order->status = 2; + } + self::afterPay($order); + + return true; + + } + /** * 现金支付 */ @@ -179,4 +205,25 @@ class PayNotifyLogic extends BaseLogic $financeLogic->save(); } + + /** + * 回调日志 + * @param $order + * @param $extra + * @return void + */ + public static function notifyLog($order,$extra) + { + $data = [ + 'pay_type'=>'wechat', + 'type'=>OrderEnum::PAY, + 'amount'=>$extra['amount']['payer_total'],//分 + 'order_sn'=>$order, + 'out_trade_no'=>$extra['transaction_id'], + 'attach'=>$extra['attach'], + 'create_time'=>date('Y-m-d H:i:s',time()), + ]; + PayNotify::create($data); + } + } diff --git a/app/common/model/pay/PayNotify.php b/app/common/model/pay/PayNotify.php new file mode 100644 index 00000000..44d3c4e3 --- /dev/null +++ b/app/common/model/pay/PayNotify.php @@ -0,0 +1,10 @@ +