From df9f8680aaecfbc0a848901fe6b54a16f2a00df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=92=8A?= Date: Tue, 16 Sep 2025 23:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E7=BA=BF=20=E8=B4=A2=E5=AF=8C?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=EF=BC=8C=E5=B7=A5=E4=BC=9A=E6=88=90=E5=91=98?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=B5=81=E6=B0=B4=E6=98=BE=E7=A4=BA=20bug?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/adminapi/controller/Level.php | 2 + application/api/model/Guild.php | 54 +++++++++++++---------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/application/adminapi/controller/Level.php b/application/adminapi/controller/Level.php index 360af23..f743902 100644 --- a/application/adminapi/controller/Level.php +++ b/application/adminapi/controller/Level.php @@ -163,6 +163,8 @@ class Level extends adminApi } } + }else{ + db::name('vs_wealth_level_rights')->where(['level_id'=>$id])->delete(); } $result = db::name($this->table_wealth_level)->where(['id'=>$id])->update($level_data); if(!$result){ diff --git a/application/api/model/Guild.php b/application/api/model/Guild.php index 65eabad..8e80281 100644 --- a/application/api/model/Guild.php +++ b/application/api/model/Guild.php @@ -651,62 +651,68 @@ class Guild extends Model $coin_consumption_type_array = model('common/UserWallet')->coin_consumption_type_array; $coin_consumption_type_array = array_diff($coin_consumption_type_array, [model('common/UserWallet')::OPERATION_CONSUME]); -// // 获取所有工会成员的 user_id -// $all_guild_users = Db::name('vs_guild_user') -// ->where(['guild_id' => $guild_id, 'status' => 1, 'delete_time' => 0]) -// ->column('user_id'); -// -// // 批量查询总消费 -// $total_consumption = Db::name('vs_user_money_log') -// ->whereIn('change_type', $coin_consumption_type_array) -// ->where(['money_type' => 1, 'createtime' => ['between', [$start_time, $end_time]]]) -// ->whereIn('user_id', $all_guild_users) -// ->sum('change_value'); - //总消费 - //所有工会成员 + // 总消费 - 需要按时间限制并只统计加入工会后的消费 + if (!$start_time || !$end_time) { + // 如果没有指定时间范围,则查询所有记录 + $start_time_filter = 0; + $end_time_filter = time(); + } else { + $start_time_filter = strtotime($start_time." 00:00:00"); + $end_time_filter = strtotime($end_time." 23:59:59"); + } + + // 所有工会成员 $all_guild_user = db::name('vs_guild_user')->where(['guild_id' => $guild_id,'status'=>1,"delete_time"=>0])->select(); $total_consumption = 0; foreach ($all_guild_user as $key => $value) { - if(!$start_time){ - $start_time_all = $value['createtime']; - $end_time_all = time(); - }else{ - $start_time_all = strtotime($start_time." 00:00:00"); - $end_time_all = strtotime($end_time." 23:59:59"); + // 计算时间范围:取工会加入时间和指定时间范围的较大值作为开始时间 + $actual_start_time = max($value['createtime'], $start_time_filter); + $actual_end_time = $end_time_filter; + + // 如果开始时间大于结束时间,则跳过该用户 + if ($actual_start_time > $actual_end_time) { + continue; } + $consumption = db::name('vs_user_money_log') ->whereIn('change_type',$coin_consumption_type_array) - ->where(['money_type'=>1,'user_id' => $value['user_id'],'createtime' => ['between', [$start_time_all, $end_time_all]]]) + ->where(['money_type'=>1,'user_id' => $value['user_id']]) + ->where('createtime', '>=', $actual_start_time) + ->where('createtime', '<=', $actual_end_time) ->sum('change_value'); - $total_consumption = $total_consumption+$consumption; + $total_consumption = $total_consumption + ($consumption ?: 0); } if (!$start_time || !$end_time) { - $start_time = strtotime('-1 month'); // 默认最近一个月 + // 如果没有指定时间范围,则查询所有记录 + $start_time = 0; $end_time = time(); }else{ $start_time = strtotime($start_time." 00:00:00"); $end_time = strtotime($end_time." 23:59:59"); } + // 查询成员列表及各自消费 $list = Db::name('vs_guild_user') ->alias('a') ->join('user b', 'a.user_id = b.id') - ->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime BETWEEN ' . $start_time . ' AND ' . $end_time, 'LEFT') + ->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime >= a.createtime' . ($start_time ? ' AND c.createtime >= ' . $start_time : '') . ($end_time ? ' AND c.createtime <= ' . $end_time : ''), 'LEFT') ->field('a.id, a.user_id, a.guild_id, a.room_id, a.status, a.is_deacon, b.nickname, b.avatar, b.user_code, a.createtime, a.apply_time, SUM(c.change_value) AS total_consumption') ->where(['a.guild_id' => $guild_id, 'a.status' => 1,'a.delete_time' => 0]) ->group('a.user_id') ->order('a.id asc') ->page($page, $page_limit) ->select(); + $count = Db::name('vs_guild_user') ->alias('a') ->join('user b', 'a.user_id = b.id') - ->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime BETWEEN ' . $start_time . ' AND ' . $end_time, 'LEFT') + ->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime >= a.createtime' . ($start_time ? ' AND c.createtime >= ' . $start_time : '') . ($end_time ? ' AND c.createtime <= ' . $end_time : ''), 'LEFT') ->field('a.id, a.user_id, a.guild_id, a.room_id, a.status, a.is_deacon, b.nickname, b.avatar, b.user_code, a.createtime, a.apply_time, SUM(c.change_value) AS total_consumption') ->where(['a.guild_id' => $guild_id, 'a.status' => 1,'a.delete_time' => 0]) ->group('a.user_id') ->count(); + $data = []; foreach ($list as $k => $v) { $data[$k]['id'] = $v['id'];