last_self_order_time ?? null); $userId = is_array($agent) ? ($agent['user_id'] ?? 0) : ($agent->user_id ?? 0); $at = $atTime ?: time(); $start = $this->windowStart($at); if ($last) { return intval($last) >= $start; } if (!$userId) { return false; } return $this->hasQualifiedOrder($userId, $start, $at); } public function hasQualifiedOrder($userId, $start, $end) { $order = OrderModel::where('user_id', $userId) ->where('type', '<>', 'score') ->where('pay_fee', '>', 0) ->paid() ->where('paid_time', '>=', $start) ->where('paid_time', '<=', $end) ->find(); return (bool) $order; } public function activeUserIds($start, $end, $extraWhere = []) { $query = \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); }); foreach ($extraWhere as $field => $value) { $query->where($field, $value); } return $query->column('user_id'); } }