wang hou sheng 7 months ago
parent 50d5518f5d
commit c71f49d2fd
  1. 3
      app/api/service/Notify.php
  2. 28
      app/api/service/identity/PaySuccess.php

@ -26,7 +26,6 @@ use app\common\library\payment\Facade as PaymentFacade;
use app\common\library\payment\gateway\Driver; use app\common\library\payment\gateway\Driver;
use app\common\library\payment\gateway\driver\wechat\V3 as WechatPaymentV3; use app\common\library\payment\gateway\driver\wechat\V3 as WechatPaymentV3;
use cores\exception\BaseException; use cores\exception\BaseException;
use think\facade\Db;
/** /**
* 服务类:第三方支付异步通知 * 服务类:第三方支付异步通知
@ -167,8 +166,6 @@ class Notify
} }
// 订单支付成功业务处理 (开通会员、分销商) // 订单支付成功业务处理 (开通会员、分销商)
if ($tradeInfo['order_type'] == OrderTypeEnum::MEMBER || $tradeInfo['order_type'] == OrderTypeEnum::DEALER) { if ($tradeInfo['order_type'] == OrderTypeEnum::MEMBER || $tradeInfo['order_type'] == OrderTypeEnum::DEALER) {
Db::table('yoshop_wx_server')->insertGetId(['content' => '进入异步通知开始处理会员分销业务', 'created_at' => date('Y-m-d H:i:s')]);
Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($tradeInfo), 'created_at' => date('Y-m-d H:i:s')]);
$service = new identity\PaySuccess(); $service = new identity\PaySuccess();
$service->setOrderNo($tradeInfo['order_no']) $service->setOrderNo($tradeInfo['order_no'])
->setMethod($tradeInfo['pay_method']) ->setMethod($tradeInfo['pay_method'])

@ -127,16 +127,12 @@ class PaySuccess extends BaseService
*/ */
public function handle(): bool public function handle(): bool
{ {
Db::table('yoshop_wx_server')->insertGetId(['content' => '开始处理业务', 'created_at' => date('Y-m-d H:i:s')]);
// 验证当前参数是否合法 // 验证当前参数是否合法
$this->verifyParameters(); $this->verifyParameters();
Db::table('yoshop_wx_server')->insertGetId(['content' => '数据合法', 'created_at' => date('Y-m-d H:i:s')]);
// 当前订单开启并发锁 // 当前订单开启并发锁
$this->lockUp(); $this->lockUp();
Db::table('yoshop_wx_server')->insertGetId(['content' => '准备修改订单', 'created_at' => date('Y-m-d H:i:s')]);
// 验证当前订单是否允许支付 // 验证当前订单是否允许支付
if ($this->checkOrderStatusOnPay()) { if ($this->checkOrderStatusOnPay()) {
Db::table('yoshop_wx_server')->insertGetId(['content' => '修改订单开始', 'created_at' => date('Y-m-d H:i:s')]);
// 更新订单状态为已付款 // 更新订单状态为已付款
$this->updatePayStatus(); $this->updatePayStatus();
} }
@ -189,22 +185,25 @@ class PaySuccess extends BaseService
Log::append('PaySuccess --updatePayStatus', ['title' => '订单已付款事件']); Log::append('PaySuccess --updatePayStatus', ['title' => '订单已付款事件']);
// 当前订单信息 // 当前订单信息
$orderInfo = $this->getOrderInfo(); $orderInfo = $this->getOrderInfo();
Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($orderInfo), 'created_at' => date('Y-m-d H:i:s')]); // 事务处理
// $this->orderModel()->transaction(function () use ($orderInfo) {
// // 更新订单状态
// $this->updateOrderStatus();
// // 累积用户总消费金额
// UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']);
// // 记录订单支付信息
// $this->updatePayInfo();
// //更改会员角色
// $this->activate();
// });
// 更新订单状态 // 更新订单状态
$this->updateOrderStatus(); $this->updateOrderStatus();
Db::table('yoshop_wx_server')->insertGetId(['content' => '修改订单开始11111', 'created_at' => date('Y-m-d H:i:s')]);
// 累积用户总消费金额 // 累积用户总消费金额
UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']); UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']);
Db::table('yoshop_wx_server')->insertGetId(['content' => '设置消费金额', 'created_at' => date('Y-m-d H:i:s')]);
// 记录订单支付信息 // 记录订单支付信息
$this->updatePayInfo(); $this->updatePayInfo();
Db::table('yoshop_wx_server')->insertGetId(['content' => '修改第三方订单信息', 'created_at' => date('Y-m-d H:i:s')]);
//更改会员角色 //更改会员角色
$this->activate(); $this->activate();
// 事务处理
// $this->orderModel()->transaction(function () use ($orderInfo) {
//
// });
} }
@ -232,7 +231,6 @@ class PaySuccess extends BaseService
} }
// 将第三方交易记录更新为已支付状态 // 将第三方交易记录更新为已支付状态
if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) { if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
Db::table('yoshop_wx_server')->insertGetId(['content' => '微信支付开始', 'created_at' => date('Y-m-d H:i:s')]);
$this->updateTradeRecord(); $this->updateTradeRecord();
} }
} }
@ -242,7 +240,6 @@ class PaySuccess extends BaseService
*/ */
private function updateTradeRecord() private function updateTradeRecord()
{ {
Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($this->paymentData), 'created_at' => date('Y-m-d H:i:s')]);
if ($this->tradeId && !empty($this->paymentData)) { if ($this->tradeId && !empty($this->paymentData)) {
PaymentTradeModel::updateToPaySuccess($this->tradeId, $this->paymentData['tradeNo']); PaymentTradeModel::updateToPaySuccess($this->tradeId, $this->paymentData['tradeNo']);
} }
@ -365,6 +362,7 @@ class PaySuccess extends BaseService
private function activate(): void private function activate(): void
{ {
Db::table('yoshop_wx_server')->insertGetId(['content' => '修改会员信息开始', 'created_at' => date('Y-m-d H:i:s')]);
$orderInfo = $this->orderInfo; $orderInfo = $this->orderInfo;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
//判断当前用户角色 //判断当前用户角色
@ -378,6 +376,7 @@ class PaySuccess extends BaseService
$time = date('Y-m-d'); $time = date('Y-m-d');
//已经是会员或者未开通会员 //已经是会员或者未开通会员
if ($orderType == IdentityEnum::MEMBER && $userType != UserTypeEnum::DEALER) { if ($orderType == IdentityEnum::MEMBER && $userType != UserTypeEnum::DEALER) {
Db::table('yoshop_wx_server')->insertGetId(['content' => '不是会员', 'created_at' => date('Y-m-d H:i:s')]);
$up['user_type'] = UserTypeEnum::MEMBER; $up['user_type'] = UserTypeEnum::MEMBER;
//已经是会员 //已经是会员
if ($userType == UserTypeEnum::MEMBER) { if ($userType == UserTypeEnum::MEMBER) {
@ -410,6 +409,7 @@ class PaySuccess extends BaseService
} }
$up['fx_effective_time'] = date("Y-m-d", strtotime("+{$orderInfo['month']} months", strtotime($time))); $up['fx_effective_time'] = date("Y-m-d", strtotime("+{$orderInfo['month']} months", strtotime($time)));
} }
Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($up), 'created_at' => date('Y-m-d H:i:s')]);
$userModel->where(['user_id' => $userInfo['user_id']])->save($up); $userModel->where(['user_id' => $userInfo['user_id']])->save($up);
} }
} }
Loading…
Cancel
Save