grid->column($field, $label); } /** * 添加用户信息组合列 * * 复用价值:高 - 将用户ID、用户名和头像组合显示,提高信息密度 * * @param string $idField 用户ID字段名 * @param string $usernameField 用户名字段名 * @param string $avatarField 头像字段名 * @param string $label 标签名 * @return Column */ public function columnUserInfo(string $idField = 'id', string $usernameField = 'username', string $avatarField = 'avatar', string $label = '用户信息'): Column { return $this->grid->column($idField, $label)->display(function ($userId) use ($usernameField, $avatarField) { $username = $this->{$usernameField} ?? ''; $avatar = $this->{$avatarField} ?? ''; $avatarHtml = $avatar ? "" : ''; return << {$avatarHtml}
ID: {$userId}
{$username}
HTML; }); } /** * 添加用户联系信息组合列 * * 复用价值:高 - 将用户手机号、邮箱和微信号组合显示,提高信息密度 * * @param string $phoneField 手机号字段名 * @param string $emailField 邮箱字段名 * @param string $wxIdField 微信号字段名 * @param string $label 标签名 * @return Column */ public function columnUserContact(string $phoneField = 'phone', string $emailField = 'email', string $wxIdField = 'wx_id', string $label = '联系方式'): Column { return $this->grid->column($phoneField, $label)->display(function ($phone) use ($emailField, $wxIdField) { $email = $this->{$emailField} ?? ''; $wxId = $this->{$wxIdField} ?? ''; $phoneHtml = $phone ? "
手机: {$phone}
" : ''; $emailHtml = $email ? "
邮箱: {$email}
" : ''; $wxIdHtml = $wxId ? "
微信: {$wxId}
" : ''; return $phoneHtml . $emailHtml . $wxIdHtml; }); } /** * 添加用户安全信息组合列 * * 复用价值:高 - 将用户安全相关信息组合显示,提高信息密度 * * @param string $secretPasswordField 安全密码字段名 * @param string $lastCheckAtField 最后验证时间字段名 * @param string $label 标签名 * @return Column */ public function columnUserSecurity(string $secretPasswordField = 'secret_password', string $lastCheckAtField = 'last_check_at', string $label = '安全信息'): Column { return $this->grid->column($secretPasswordField, $label)->display(function ($secretPassword) use ($lastCheckAtField) { $lastCheckAt = $this->{$lastCheckAtField} ?? ''; $secretPasswordHtml = "
安全密码: " . ($secretPassword ? '已设置' : '未设置') . "
"; $lastCheckAtHtml = $lastCheckAt ? "
最后验证: {$lastCheckAt}
" : ''; return $secretPasswordHtml . $lastCheckAtHtml; }); } /** * 添加时间信息组合列 * * 复用价值:高 - 将创建时间和更新时间组合显示,提高信息密度 * * @param string $createdAtField 创建时间字段名 * @param string $updatedAtField 更新时间字段名 * @param string $label 标签名 * @return Column */ public function columnTimes(string $createdAtField = 'created_at', string $updatedAtField = 'updated_at', string $label = '时间信息'): Column { return $this->grid->column($createdAtField, $label)->display(function ($createdAt) use ($updatedAtField) { $updatedAt = $this->{$updatedAtField} ?? ''; $createdAtHtml = "
创建: {$createdAt}
"; $updatedAtHtml = $updatedAt ? "
更新: {$updatedAt}
" : ''; return $createdAtHtml . $updatedAtHtml; }); } /** * 添加用户资金账户信息列 * * 复用价值:高 - 显示用户的资金账户信息 * * @param string $idField 用户ID字段名 * @param string $label 标签名 * @return Column */ public function columnUserFunds(string $idField = 'id', string $label = '资金账户'): Column { return $this->grid->column($idField, $label)->display(function ($userId) { // 获取用户的资金账户 $funds = \App\Module\Fund\Models\FundModel::where('user_id', $userId)->get(); if ($funds->isEmpty()) { return '无资金账户'; } $fundNames = \App\Module\Fund\Services\AccountService::getFundsDesc(); $html = '
'; foreach ($funds as $fund) { $fundName = $fundNames[$fund->fund_id] ?? "未知类型({$fund->fund_id})"; $balance = number_format($fund->balance / 100, 2); $html .= "
{$fundName}: {$balance}
"; } $html .= '
'; $html .= "
查看详情
"; return $html; }); } /** * 添加用户物品信息列 * * 复用价值:高 - 显示用户的物品信息 * * @param string $idField 用户ID字段名 * @param string $label 标签名 * @return Column */ public function columnUserItems(string $idField = 'id', string $label = '物品背包'): Column { return $this->grid->column($idField, $label)->display(function ($userId) { // 获取用户的物品(限制最多显示5个) $items = \App\Module\GameItems\Models\ItemUser::with('item') ->where('user_id', $userId) ->orderBy('quantity', 'desc') ->limit(5) ->get(); if ($items->isEmpty()) { return '无物品'; } $html = '
'; foreach ($items as $userItem) { $itemName = $userItem->item->name ?? "物品 {$userItem->item_id}"; $quantity = $userItem->quantity; $html .= "
{$itemName} x {$quantity}
"; } // 获取用户物品总数 $totalCount = \App\Module\GameItems\Models\ItemUser::where('user_id', $userId)->count(); if ($totalCount > 5) { $html .= "
... 共 {$totalCount} 种物品
"; } $html .= '
'; $html .= "
查看详情
"; return $html; }); } /** * 添加用户土地信息列 * * 复用价值:高 - 显示用户的土地信息 * * @param string $idField 用户ID字段名 * @param string $label 标签名 * @return Column */ public function columnUserLands(string $idField = 'id', string $label = '土地信息'): Column { return $this->grid->column($idField, $label)->display(function ($userId) { // 获取用户的土地 $lands = \App\Module\Farm\Models\FarmLand::where('user_id', $userId)->get(); if ($lands->isEmpty()) { return '无土地'; } // 获取土地状态统计 $statusCounts = $lands->groupBy('status')->map->count(); $statusMap = [ \App\Module\Farm\Enums\LAND_STATUS::IDLE->value => '空闲', \App\Module\Farm\Enums\LAND_STATUS::PLANTING->value => '种植中', \App\Module\Farm\Enums\LAND_STATUS::DISASTER->value => '灾害', \App\Module\Farm\Enums\LAND_STATUS::HARVESTABLE->value => '可收获', \App\Module\Farm\Enums\LAND_STATUS::WITHERED->value => '枯萎' ]; $html = '
'; $html .= "
总数: {$lands->count()} 块
"; foreach ($statusCounts as $status => $count) { $statusName = $statusMap[$status] ?? "未知状态({$status})"; $badgeClass = match($status) { \App\Module\Farm\Enums\LAND_STATUS::IDLE->value => 'secondary', \App\Module\Farm\Enums\LAND_STATUS::PLANTING->value => 'primary', \App\Module\Farm\Enums\LAND_STATUS::DISASTER->value => 'warning', \App\Module\Farm\Enums\LAND_STATUS::HARVESTABLE->value => 'success', \App\Module\Farm\Enums\LAND_STATUS::WITHERED->value => 'danger', default => 'info' }; $html .= "
{$statusName}: {$count} 块
"; } $html .= '
'; $html .= "
查看详情
"; return $html; }); } /** * 添加用户神像buff信息列 * * 复用价值:高 - 显示用户的神像buff信息 * * @param string $idField 用户ID字段名 * @param string $label 标签名 * @return Column */ public function columnUserBuffs(string $idField = 'id', string $label = '神像加持'): Column { return $this->grid->column($idField, $label)->display(function ($userId) { // 获取用户的神像buff $buffs = \App\Module\Farm\Models\FarmGodBuff::where('user_id', $userId) ->where('expire_time', '>', now()) ->get(); if ($buffs->isEmpty()) { return '无有效神像加持'; } $buffTypes = [ \App\Module\Farm\Enums\BUFF_TYPE::HARVEST_GOD->value => '丰收之神', \App\Module\Farm\Enums\BUFF_TYPE::RAIN_GOD->value => '雨露之神', \App\Module\Farm\Enums\BUFF_TYPE::WEED_KILLER_GOD->value => '屠草之神', \App\Module\Farm\Enums\BUFF_TYPE::PEST_CLEANER_GOD->value => '拭虫之神' ]; $html = '
'; foreach ($buffs as $buff) { $buffName = $buffTypes[$buff->buff_type] ?? "未知神像({$buff->buff_type})"; $expireTime = $buff->expire_time->format('Y-m-d H:i:s'); $html .= "
{$buffName} 到期: {$expireTime}
"; } $html .= '
'; $html .= "
查看详情
"; return $html; }); } /** * 添加用户种植作物信息列 * * 复用价值:高 - 显示用户的种植作物信息 * * @param string $idField 用户ID字段名 * @param string $label 标签名 * @return Column */ public function columnUserCrops(string $idField = 'id', string $label = '种植作物'): Column { return $this->grid->column($idField, $label)->display(function ($userId) { // 获取用户的作物 $crops = \App\Module\Farm\Models\FarmCrop::with(['seed', 'land']) ->where('user_id', $userId) ->get(); if ($crops->isEmpty()) { return '无种植作物'; } // 获取作物生长阶段统计 $stageCounts = $crops->groupBy('growth_stage')->map->count(); $stageMap = [ \App\Module\Farm\Enums\GROWTH_STAGE::SEED->value => '种子期', \App\Module\Farm\Enums\GROWTH_STAGE::SPROUT->value => '发芽期', \App\Module\Farm\Enums\GROWTH_STAGE::GROWTH->value => '生长期', \App\Module\Farm\Enums\GROWTH_STAGE::MATURE->value => '成熟期', \App\Module\Farm\Enums\GROWTH_STAGE::WITHERED->value => '枯萎期' ]; $html = '
'; $html .= "
总数: {$crops->count()} 株
"; foreach ($stageCounts as $stage => $count) { $stageName = $stageMap[$stage] ?? "未知阶段({$stage})"; $badgeClass = match($stage) { \App\Module\Farm\Enums\GROWTH_STAGE::SEED->value => 'secondary', \App\Module\Farm\Enums\GROWTH_STAGE::SPROUT->value => 'info', \App\Module\Farm\Enums\GROWTH_STAGE::GROWTH->value => 'primary', \App\Module\Farm\Enums\GROWTH_STAGE::MATURE->value => 'success', \App\Module\Farm\Enums\GROWTH_STAGE::WITHERED->value => 'danger', default => 'dark' }; $html .= "
{$stageName}: {$count} 株
"; } $html .= '
'; $html .= "
查看详情
"; return $html; }); } }