show->field($field, $label)->as(function ($value) { $fundsDesc = AccountService::getFundsDesc(); return $fundsDesc[$value] ?? $value; }); } /** * 显示资金余额 * * 复用价值:高 - 统一处理余额的格式化显示,包括单位转换 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldBalance(string $field = 'balance', string $label = '余额'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return number_format($value / 1000, 3); }); } public function fieldBalance1000(string $field = 'balance', string $label = '余额'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { return number_format($value / 1000, 3); }); } /** * 显示操作金额 * * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldAmount(string $field = 'amount', string $label = '操作金额'): Show\Field { return $this->show->field($field, $label)->unescape()->as(function ($value) { if ($value > 0) { return "+{$value}"; } elseif ($value < 0) { return "{$value}"; } else { return "{$value}"; } }); } /** * @param string $field * @param string $label * @return Show\Field */ public function fieldAmount1000(string $field = 'amount', string $label = '操作金额'): Show\Field { return $this->show->field($field, $label)->unescape()->as(function ($value) { $formattedValue = number_format($value / 1000, 3); if ($value > 0) { return "+{$formattedValue}"; } elseif ($value < 0) { return "{$formattedValue}"; } else { return "{$formattedValue}"; } }); } /** * 显示操作类型 * * 复用价值:高 - 统一处理操作类型的显示,使用枚举类型 * * @param string $field 字段名 * @param string $label 标签名 * @return Show\Field */ public function fieldOperateType(string $field = 'operate_type', string $label = '操作类型'): Show\Field { return $this->show->field($field, $label)->as(function ($value) { try { // 使用 from() 方法获取枚举实例,然后获取描述 return LOG_TYPE::from($value)->getDesc(); } catch (\ValueError $e) { // 如果值不存在,返回原值 return $value; } }); } /** * 显示时间戳 * * 复用价值:高 - 统一处理时间戳的格式化显示 * * @param string $field 字段名 * @param string $label 标签名 * @param string $format 日期格式 * @return Show\Field */ public function fieldTimestamp(string $field, string $label, string $format = 'Y-m-d H:i:s'): Show\Field { return $this->show->field($field, $label)->as(function ($value) use ($format) { return $value ? date($format, $value) : ''; }); } /** * 显示金额(毫转元) * * 复用价值:高 - 统一处理金额的格式化显示,包括单位转换 * * @param string $field 字段名 * @param string $label 标签名 * @param int $decimals 小数位数 * @return Show\Field */ public function fieldMoney(string $field, string $label, int $decimals = 3): Show\Field { return $this->show->field($field, $label)->as(function ($value) use ($decimals) { return number_format($value / 1000, $decimals); }); } }