feat(dashboard): 从专业财富观角度重构升级后台收益与分成统计仪表盘
这个提交包含在:
@@ -50,16 +50,41 @@ class ActiveService
|
||||
|
||||
public function activeUserIds($start, $end, $extraWhere = [])
|
||||
{
|
||||
$query = \think\Db::name('shopro_commission_agent')
|
||||
$baseQuery = \think\Db::name('shopro_commission_agent')
|
||||
->where('status', 'in', ['normal', 'freeze'])
|
||||
->where('level', '>=', 1)
|
||||
->where(function ($q) use ($start, $end) {
|
||||
$q->where('last_self_order_time', '>=', $start)
|
||||
->where('last_self_order_time', '<=', $end);
|
||||
});
|
||||
->where('level', '>=', 1);
|
||||
foreach ($extraWhere as $field => $value) {
|
||||
$query->where($field, $value);
|
||||
$baseQuery->where($field, $value);
|
||||
}
|
||||
return $query->column('user_id');
|
||||
|
||||
// 1. 优先通过 last_self_order_time 索引快速命中
|
||||
$hitUserIds = (clone $baseQuery)->where(function ($q) use ($start, $end) {
|
||||
$q->where('last_self_order_time', '>=', $start)
|
||||
->where('last_self_order_time', '<=', $end);
|
||||
})->column('user_id');
|
||||
|
||||
// 2. 容错:查找 last_self_order_time 为空或为 0 的代理商
|
||||
$nullUserIds = (clone $baseQuery)->where(function ($q) {
|
||||
$q->whereNull('last_self_order_time')->whereOr('last_self_order_time', 0);
|
||||
})->column('user_id');
|
||||
|
||||
if (!empty($nullUserIds)) {
|
||||
$orderHits = \think\Db::name('shopro_order')
|
||||
->whereIn('user_id', $nullUserIds)
|
||||
->where('type', '<>', 'score')
|
||||
->where('pay_fee', '>', 0)
|
||||
->whereIn('status', ['paid', 'completed'])
|
||||
->where('paid_time', '>=', $start)
|
||||
->where('paid_time', '<=', $end)
|
||||
->group('user_id')
|
||||
->column('max(paid_time)', 'user_id');
|
||||
|
||||
foreach ($orderHits as $uId => $lastTime) {
|
||||
\think\Db::name('shopro_commission_agent')->where('user_id', $uId)->update(['last_self_order_time' => $lastTime]);
|
||||
$hitUserIds[] = intval($uId);
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_map('intval', $hitUserIds)));
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户