优化:Give_Gift 表查询处理

This commit is contained in:
2026-01-12 21:21:11 +08:00
parent 8d995cb5b4
commit ce2bf4c7ce

View File

@@ -313,7 +313,7 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
return ['code' => 0, 'msg' => '盲盒ID不能为空', 'data' => null];
}
// 检查用户金币
$user_waller = db::name('user_wallet')
$user_waller = db::name('user_wallet_coin')
->where(['user_id' => $user_id])
->find();
if (!$user_waller) {
@@ -718,20 +718,13 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
private function deductUserCoins($user_id, $bagGiftPrice, $room_id , $bag_data=[])
{
// 使用悲观锁查询用户钱包
$userWallet = db::name('user_wallet')
$userWallet = db::name('user_wallet_coin')
->where(['user_id' => $user_id])
->find();
if (!$userWallet || $userWallet['coin'] < $bagGiftPrice) {
throw new \Exception('用户金币不足');
}
$walletUpdate = model('GiveGift')->change_user_cion_or_earnings_log(
$user_id,
$bagGiftPrice,
$room_id,
1,
10,
$bag_data['gift_bag_name'] .'抽奖消耗'
);
$walletUpdate = model('api/UserWallet')->change_user_cion_log($user_id, $bagGiftPrice, $room_id, 10, $bag_data['gift_bag_name'] .'抽奖消耗');
if (!$walletUpdate) {
throw new \Exception('扣除用户金币失败');
}
@@ -1084,18 +1077,11 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
$current_batch = min($batch_size, $num - $total_processed); // 当前批次处理数量
// 批量扣除金币(只在第一次事务中处理)
if ($total_processed == 0) {
$user_waller = db::name('user_wallet')->where(['user_id' => $user_id])->find();
$user_waller = db::name('user_wallet_coin')->where(['user_id' => $user_id])->find();
if (!$user_waller || $user_waller['coin'] < $bag_gift_price) {
return ['code' => 0, 'msg' => '用户金币不足', 'data' => null];
}
$wallet_update = model('GiveGift')->change_user_cion_or_earnings_log(
$user_id,
$bag_gift_price,
$room_id,
1,
10,
$ext['gift_bag_name'].'抽奖消耗'
);
$wallet_update = model('api/UserWallet')->change_user_cion_log($user_id, $bag_gift_price, $room_id, 10, $ext['gift_bag_name'].'抽奖消耗');
if (!$wallet_update) {
throw new \Exception('扣除用户金币失败');
}
@@ -1480,7 +1466,7 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
// 获取转盘信息和用户钱包
$bag_data = $this->getCachedGiftBag($gift_bag_id);
$user_wallet = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
$user_wallet = Db::name('user_wallet_coin')->where(['user_id' => $user_id])->find();
if (!$user_wallet) {
return ['code' => 0, 'msg' => '用户钱包不存在', 'data' => null];