添加:购买会员卡赠送额度

This commit is contained in:
wuhui_zzw 2024-01-17 18:48:29 +08:00
parent 80d54c0680
commit 78a995c467
3 changed files with 71 additions and 1 deletions

View File

@ -132,12 +132,16 @@ class UserOrderRepository extends BaseRepository
$type = explode('-',$res['order_type'])[0].'-';
// 付费会员充值
if ($type == self::TYPE_SVIP) {
return Db::transaction(function () use($data, $res) {
$result = Db::transaction(function () use($data, $res) {
$res->paid = 1;
$res->pay_time = date('y_m-d H:i:s', time());
$res->save();
return $this->payAfter($res, $res);
});
event('user.vipPay', [$res]);
return $result;
}
}

View File

@ -73,6 +73,11 @@ return [
// 酒卡额度相关处理
'app\listener\exchangeQuota\OrderAgreeRefundEvent'
],
// 会员卡开通 支付成功
'user.vipPay' => [
// 酒卡额度相关处理
'app\listener\exchangeQuota\OrderVipPayEvent'
],
],
'subscribe' => [],

View File

@ -0,0 +1,61 @@
<?php
namespace app\listener\exchangeQuota;
use app\common\model\user\ExchangeQuota;
use app\common\model\user\ExchangeQuotaRecord;
use think\facade\Log;
class OrderVipPayEvent{
public $groupOrder;
public function handle($data){
try{
$order = $data[0] ?? [];
// Log::info('会员卡开通成功 - 酒卡额度相关处理 - 开始: '.var_export([
// 'order_id' => $order->order_id ?? '',
// 'uid' => $order->uid ?? '',
// 'order_info' => $order->order_info ?? ''
// ],1));
// 获取用户当前持有
$userHoldInfo = ExchangeQuota::where('uid',$order->uid )->findOrEmpty();
if((int)$userHoldInfo->uid <= 0) $userHoldInfo->uid = $order->uid;
// 赠送数量
$vipInfo = json_decode($order->order_info,TRUE);
$giveNum = (float)$vipInfo['quota'] ?? 0;
// Log::info('会员卡开通成功 - 酒卡额度相关处理 - 开始1111111111111 '.var_export([
// '$giveNum' => $giveNum ?? '',
// '$vipInfo' => $vipInfo ?? ''
// ],1));
if((float)$giveNum > 0){
// 赠送
$changeFront = (float)$userHoldInfo->surplus_quota;
$userHoldInfo->total_quota += (float)$giveNum;// 总额度
$userHoldInfo->surplus_quota += (float)$giveNum;// 剩余额度
$userHoldInfo->save();
// 记录
$insertData[] = [
'uid' => $order->uid,
'product_id' => 0,
'order_id' => $order->order_id,
'order_product_id' => 0,
'change_type' => 1,
'change_quantity' => (float)$giveNum,
'change_front' => $changeFront,
'change_after' => (float)$userHoldInfo->surplus_quota,
'remark' => "购买会员卡赠送",
'source' => 3,
];
ExchangeQuotaRecord::insertAll($insertData);
}
}catch(\Exception $e){
Log::info('会员卡开通成功 - 酒卡额度相关处理 - 错误: '.$e->getMessage());
}
}
}