用户收益 金币扣除
This commit is contained in:
@@ -471,60 +471,45 @@ class User extends Model
|
||||
public function get_user_gift_wall_info($uid)
|
||||
{
|
||||
//查询用户礼物墙 以gift_id,send_user_id分组 同一用户送的同一礼物相加
|
||||
$result = db::name('vs_give_gift')->alias('a')
|
||||
$result = db::name('user_gift_wall')->alias('a')
|
||||
->join('vs_gift g', 'a.gift_id = g.gid')
|
||||
->where(['a.gift_user' => $uid,'g.label'=>['<>',2]])
|
||||
->field('a.gift_id,a.user_id,sum(a.number) as total')
|
||||
->group('a.gift_id,a.user_id')
|
||||
->order('total desc')
|
||||
->where(['a.user_id' => $uid, 'g.label' => ['not in', [2, 16]],'a.gift_id' => ['<>', 0]])
|
||||
->field('a.gift_id,a.user_id,a.count,a.give_user_ids,g.gift_name,g.gift_price,g.base_image')
|
||||
->order('count desc')
|
||||
->select();
|
||||
// var_dump($result);exit;
|
||||
// 根据礼物二次分组 获取礼物的总数和送的数量最多的三用户
|
||||
$data = [];
|
||||
// 按 gift_id 聚合数据
|
||||
foreach ($result as $item) {
|
||||
$giftId = $item['gift_id'];
|
||||
$sendUserId = $item['user_id'];
|
||||
$sendUserNickname = db::name('user')->where(['id' => $sendUserId])->value('nickname');
|
||||
$sendUserAvatar = db::name('user')->where(['id' => $sendUserId])->value('avatar');
|
||||
$total = $item['total'];
|
||||
|
||||
if (!isset($data[$giftId])) {
|
||||
$data[$giftId] = [
|
||||
'gift_id' => $giftId,
|
||||
'gift_price' => model('Gift')->where(['gid' => $giftId])->value('gift_price'),
|
||||
'gift_name' => model('Gift')->where(['gid' => $giftId])->value('gift_name'),
|
||||
'base_image' => model('Gift')->where(['gid' => $giftId])->value('base_image'),
|
||||
'total_count' => 0,
|
||||
'top_users' => []
|
||||
$data = [];
|
||||
|
||||
if($result){
|
||||
//获取数组中的礼物ID集合
|
||||
// $giftIds = array_column($result, 'gift_id');
|
||||
$userInfo = [];
|
||||
foreach ($result as &$item){
|
||||
$users = explode(',', $item['give_user_ids']);
|
||||
foreach ($users as $userId){
|
||||
$user = db::name('user')->where(['id' => $userId])->field('id user_id,nickname,avatar')->find();
|
||||
if($user){
|
||||
$userInfo[] = $user;
|
||||
}
|
||||
}
|
||||
$data[] = [
|
||||
'top_users_count' => count($users),
|
||||
'gift_id' => $item['gift_id'],
|
||||
'gift_name' => $item['gift_name'],
|
||||
'gift_price' => $item['gift_price'],
|
||||
'base_image' => $item['base_image'],
|
||||
'total_count' => $item['count'],
|
||||
'top_users' => $userInfo
|
||||
];
|
||||
}
|
||||
|
||||
// 累加总数量
|
||||
$data[$giftId]['total_count'] += $total;
|
||||
|
||||
// 存储用户赠送记录
|
||||
$data[$giftId]['top_users'][] = [
|
||||
'user_id' => $sendUserId,
|
||||
'nickname' => $sendUserNickname,
|
||||
'avatar' => $sendUserAvatar,
|
||||
'count' => $total
|
||||
];
|
||||
}
|
||||
|
||||
// 对每个礼物的 top_users 排序并取前三名
|
||||
foreach ($data as &$giftData) {
|
||||
// 按 count 降序排序
|
||||
usort($giftData['top_users'], function ($a, $b) {
|
||||
return $b['count'] <=> $a['count'];
|
||||
});
|
||||
$giftData['top_users_count'] = count($giftData['top_users']);
|
||||
// 取前3位
|
||||
$giftData['top_users'] = array_slice($giftData['top_users'], 0, 3);
|
||||
}
|
||||
$data = array_values($data);
|
||||
|
||||
//查询所有的礼物
|
||||
$gift_list = db::name('vs_gift')->field('gid as gift_id,gift_name,base_image,gift_price')->where(['delete_time' => 0,'label'=>['<>',2]])->select();
|
||||
$gift_list = db::name('vs_gift')
|
||||
->field('gid as gift_id,gift_name,base_image,gift_price')
|
||||
->where(['delete_time' => 0,'label'=>['not in', [2, 16]]])
|
||||
->select();
|
||||
//对比去除$data 里面的礼物
|
||||
$gift_list = array_filter((array)$gift_list, function ($item) use ($data) {
|
||||
return !in_array($item['gift_id'], array_column($data, 'gift_id'));
|
||||
|
||||
@@ -237,7 +237,7 @@ class UserWallet extends Model
|
||||
//减少用户金币类型
|
||||
$out_types = [4,7,10,17,20,24,25,32,42,50,56,59];
|
||||
|
||||
$user_wallet = Db::name('user_wallet_coin')->where(['user_id' => $user_id])->lock(true)->value('coin');
|
||||
$user_wallet = Db::name('user_wallet_coin')->where(['user_id' => $user_id])->lock(true)->find();
|
||||
if (!$user_wallet) {
|
||||
return false;
|
||||
}
|
||||
@@ -306,7 +306,12 @@ class UserWallet extends Model
|
||||
|
||||
//减少用户钻石类型
|
||||
$out_types = [3,14,29,43];
|
||||
$user_earnings = Db::name('user_wallet_earnings')->where(['user_id' => $user_id])->value('earnings');
|
||||
$user_wallet = Db::name('user_wallet_earnings')->where(['user_id' => $user_id])->lock(true)->find();
|
||||
if(!$user_wallet){
|
||||
return false;
|
||||
}
|
||||
$user_earnings = $user_wallet['earnings'];
|
||||
$original_coin = $user_earnings; // 保存原始值用于日志
|
||||
|
||||
if(in_array($change_type,$in_types)){
|
||||
$update_coin = bcadd($user_earnings , $money,4);
|
||||
@@ -327,7 +332,7 @@ class UserWallet extends Model
|
||||
'user_id' => $user_id,
|
||||
'room_id' => $room_id,
|
||||
'earnings' => $money,
|
||||
'before' => $user_earnings,
|
||||
'before' => $original_coin,
|
||||
'after' => $update_coin,
|
||||
'change_type' => $change_type,
|
||||
'remarks' => $remarks,
|
||||
|
||||
Reference in New Issue
Block a user