show->field($field, $label)->as(function ($value) { return BUFF_TYPE::getName($value); }); } /** * 显示灾害类型 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldDisasterType(string $field = 'disaster_type', string $label = '灾害类型'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return DISASTER_TYPE::getName($value); }); } /** * 显示生长阶段 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldGrowthStage(string $field = 'growth_stage', string $label = '生长阶段'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return GROWTH_STAGE::getName($value); }); } /** * 显示土地状态 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldLandStatus(string $field = 'status', string $label = '土地状态'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return LAND_STATUS::getName($value); }); } /** * 显示土地类型 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldLandType(string $field = 'land_type', string $label = '土地类型'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return LAND_TYPE::getName($value); }); } /** * 显示种子类型 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldSeedType(string $field = 'type', string $label = '种子类型'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return SEED_TYPE::getName($value); }); } /** * 显示升级类型 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldUpgradeType(string $field = 'upgrade_type', string $label = '升级类型'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return UPGRADE_TYPE::getName($value); }); } /** * 显示灾害情况 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldDisasters(string $field = 'disasters', string $label = '灾害情况'): Show\Field { return $this->show->field($field, $label)->json(); } /** * 显示是否施肥 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldFertilized(string $field = 'fertilized', string $label = '已施肥'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return $value ? '是' : '否'; }); } /** * 显示产量加成 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldOutputBonus(string $field = 'output_bonus', string $label = '产量加成'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return ($value * 100) . '%'; }); } /** * 显示灾害抵抗 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldDisasterResistance(string $field = 'disaster_resistance', string $label = '灾害抵抗'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return ($value * 100) . '%'; }); } /** * 显示是否特殊土地 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldIsSpecial(string $field = 'is_special', string $label = '特殊土地'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return $value ? '是' : '否'; }); } /** * 显示种子信息 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldSeed(string $field = 'seed_id', string $label = '种子'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { if (empty($value)) { return '-'; } // 尝试获取种子名称 $seed = \App\Module\Farm\Models\FarmSeed::find($value); if ($seed) { $html = "
"; $html .= "{$seed->name} "; $html .= "ID: {$seed->id} "; $typeName = \App\Module\Farm\Enums\SEED_TYPE::getName($seed->type); $html .= "{$typeName}"; // 显示种子属性 $html .= "
"; $html .= "种子期: {$seed->seed_time}秒 | "; $html .= "发芽期: {$seed->sprout_time}秒 | "; $html .= "生长期: {$seed->growth_time}秒"; $html .= "
"; // 如果有关联的物品ID,尝试获取物品名称 if ($seed->item_id) { try { $item = \App\Module\GameItems\Models\Item::find($seed->item_id); if ($item) { $html .= "
"; $html .= "产出物品: {$item->name} "; $html .= "ID: {$item->id}"; $html .= "
"; } } catch (\Exception $e) { // 忽略异常,只是不显示物品信息 } } $html .= "
"; return $html; } return $value; }); } /** * 显示物品信息 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldItem(string $field = 'item_id', string $label = '物品'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { if (empty($value)) { return '-'; } // 尝试获取物品名称 try { $item = \App\Module\GameItems\Models\Item::find($value); if ($item) { $html = "
"; $html .= "{$item->name} "; $html .= "ID: {$item->id} "; // 尝试显示物品类型 if (isset($item->type)) { try { $typeName = \App\Module\GameItems\Enums\ITEM_TYPE::getName($item->type); $html .= "{$typeName}"; } catch (\Exception $e) { // 忽略异常,只是不显示类型信息 } } // 显示物品属性 if (isset($item->numeric_attributes)) { $html .= "
"; $attrs = json_decode($item->numeric_attributes, true); if (is_array($attrs)) { $attrStrings = []; foreach ($attrs as $key => $value) { $attrStrings[] = "{$key}: {$value}"; } $html .= implode(' | ', $attrStrings); } $html .= "
"; } $html .= "
"; return $html; } } catch (\Exception $e) { // 忽略异常,只是不显示物品信息 } return $value; }); } /** * 显示模型Cast JSON字段 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldModelCatsJson2(string $field, string $label): Show\Field { return $this->show->field($field, $label)->as(function ($value) { if (empty($value)) { return '-'; } if (is_string($value)) { $value = json_decode($value, true); } elseif (is_object($value)) { $value = (array)$value; } if (!is_array($value)) { return '-'; } $html = '
'; $html .= ''; $html .= ''; foreach ($value as $key => $val) { if (is_array($val) || is_object($val)) { $val = json_encode($val, JSON_UNESCAPED_UNICODE); } $html .= ""; } $html .= '
属性
{$key}{$val}
'; return $html; }); } }