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\wechat\V3 as WechatPaymentV3;
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) {
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->setOrderNo($tradeInfo['order_no'])
->setMethod($tradeInfo['pay_method'])

@ -127,16 +127,12 @@ class PaySuccess extends BaseService
*/
public function handle(): bool
{
Db::table('yoshop_wx_server')->insertGetId(['content' => '开始处理业务', 'created_at' => date('Y-m-d H:i:s')]);
// 验证当前参数是否合法
$this->verifyParameters();
Db::table('yoshop_wx_server')->insertGetId(['content' => '数据合法', 'created_at' => date('Y-m-d H:i:s')]);
// 当前订单开启并发锁
$this->lockUp();
Db::table('yoshop_wx_server')->insertGetId(['content' => '准备修改订单', 'created_at' => date('Y-m-d H:i:s')]);
// 验证当前订单是否允许支付
if ($this->checkOrderStatusOnPay()) {
Db::table('yoshop_wx_server')->insertGetId(['content' => '修改订单开始', 'created_at' => date('Y-m-d H:i:s')]);
// 更新订单状态为已付款
$this->updatePayStatus();
}
@ -189,22 +185,25 @@ class PaySuccess extends BaseService
Log::append('PaySuccess --updatePayStatus', ['title' => '订单已付款事件']);
// 当前订单信息
$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();
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']);
Db::table('yoshop_wx_server')->insertGetId(['content' => '设置消费金额', 'created_at' => date('Y-m-d H:i:s')]);
// 记录订单支付信息
$this->updatePayInfo();
Db::table('yoshop_wx_server')->insertGetId(['content' => '修改第三方订单信息', 'created_at' => date('Y-m-d H:i:s')]);
//更改会员角色
$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])) {
Db::table('yoshop_wx_server')->insertGetId(['content' => '微信支付开始', 'created_at' => date('Y-m-d H:i:s')]);
$this->updateTradeRecord();
}
}
@ -242,7 +240,6 @@ class PaySuccess extends BaseService
*/
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)) {
PaymentTradeModel::updateToPaySuccess($this->tradeId, $this->paymentData['tradeNo']);
}
@ -365,6 +362,7 @@ class PaySuccess extends BaseService
private function activate(): void
{
Db::table('yoshop_wx_server')->insertGetId(['content' => '修改会员信息开始', 'created_at' => date('Y-m-d H:i:s')]);
$orderInfo = $this->orderInfo;
$userInfo = $this->userInfo;
//判断当前用户角色
@ -378,6 +376,7 @@ class PaySuccess extends BaseService
$time = date('Y-m-d');
//已经是会员或者未开通会员
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;
//已经是会员
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)));
}
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);
}
}
Loading…
Cancel
Save