show = $show;
$this->controller = $controller;
}
/**
* 基础字段显示
*/
public function field(string $field, string $label): Show\Field
{
return $this->show->field($field, $label);
}
/**
* 用户ID字段,带链接
*/
public function fieldUserId(string $field = 'user_id', string $label = '用户ID'): Show\Field
{
return $this->show->field($field, $label)->link(function ($value) {
return admin_url("users/{$value}");
});
}
/**
* 商品ID字段,带链接
*/
public function fieldItemId(string $field = 'item_id', string $label = '商品ID'): Show\Field
{
return $this->show->field($field, $label)->link(function ($value) {
return admin_url("game-items/{$value}");
});
}
/**
* 订单ID字段,带链接
*/
public function fieldOrderId(string $field, string $label): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
if ($value) {
return "{$value}";
}
return '-';
});
}
/**
* 订单类型字段
*/
public function fieldOrderType(string $field = 'order_type', string $label = '订单类型'): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
return $value instanceof OrderType ? $value->getDescription() : OrderType::from($value)->getDescription();
});
}
/**
* 订单状态字段
*/
public function fieldOrderStatus(string $field = 'status', string $label = '状态'): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
return $value instanceof OrderStatus ? $value->getDescription() : OrderStatus::from($value)->getDescription();
});
}
/**
* 交易类型字段
*/
public function fieldTransactionType(string $field = 'transaction_type', string $label = '交易类型'): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
return TransactionType::from($value)->getDescription();
});
}
/**
* 管理员操作类型字段
*/
public function fieldAdminOperationType(string $field = 'operation_type', string $label = '操作类型'): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
return AdminOperationType::from($value)->getDescription();
});
}
/**
* 价格字段,格式化显示
*/
public function fieldPrice(string $field = 'price', string $label = '价格', int $decimals = 5): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) use ($decimals) {
return number_format($value, $decimals);
});
}
/**
* 金额字段,格式化显示
*/
public function fieldAmount(string $field, string $label, int $decimals = 5): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) use ($decimals) {
return $value ? number_format($value, $decimals) : '-';
});
}
/**
* 数量字段,格式化显示
*/
public function fieldQuantity(string $field = 'quantity', string $label = '数量'): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
return number_format($value);
});
}
/**
* 布尔值字段
*/
public function fieldBoolean(string $field, string $label): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
return $value ? '是' : '否';
});
}
/**
* 启用状态字段
*/
public function fieldEnabled(string $field = 'is_enabled', string $label = '启用状态'): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
return $value ? '启用' : '禁用';
});
}
/**
* JSON字段,格式化显示
*/
public function fieldJson(string $field, string $label): Show\Field
{
return $this->show->field($field, $label)->json();
}
/**
* 时间戳字段
*/
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) : '-';
});
}
/**
* 平均价格计算字段
*/
public function fieldAveragePrice(string $amountField, string $quantityField, string $label): Show\Field
{
return $this->show->field($label)->as(function () use ($amountField, $quantityField) {
$amount = $this->{$amountField};
$quantity = $this->{$quantityField};
if ($quantity > 0) {
$avgPrice = bcdiv($amount, $quantity, 5);
return number_format($avgPrice, 5);
}
return '0.00000';
});
}
/**
* 净值计算字段
*/
public function fieldNetValue(string $positiveField, string $negativeField, string $label, int $decimals = 5): Show\Field
{
return $this->show->field($label)->as(function () use ($positiveField, $negativeField, $decimals) {
$positive = $this->{$positiveField};
$negative = $this->{$negativeField};
if (is_numeric($positive) && is_numeric($negative)) {
$net = bcsub($positive, $negative, $decimals);
return number_format($net, $decimals);
}
return '-';
});
}
/**
* 百分比字段
*/
public function fieldPercentage(string $field, string $label, int $decimals = 2): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) use ($decimals) {
return number_format($value * 100, $decimals) . '%';
});
}
/**
* 管理员ID字段,带链接
*/
public function fieldAdminUserId(string $field = 'admin_user_id', string $label = '管理员ID'): Show\Field
{
return $this->show->field($field, $label)->as(function ($value) {
if ($value) {
return "{$value}";
}
return '-';
});
}
/**
* 分割线
*/
public function divider(string $title = ''): void
{
$this->show->divider($title);
}
/**
* 面板
*/
public function panel(string $title, \Closure $callback): void
{
$this->show->panel($title, $callback);
}
/**
* 表格
*/
public function table(string $title, array $headers, \Closure $callback): void
{
$this->show->table($title, $headers, $callback);
}
/**
* 文本截断显示
*/
public function fieldText(string $field, string $label, int $limit = 100): Show\Field
{
return $this->show->field($field, $label)->limit($limit);
}
/**
* 链接字段
*/
public function fieldLink(string $field, string $label, string $urlTemplate): Show\Field
{
return $this->show->field($field, $label)->link($urlTemplate);
}
}