|
|
@@ -16,7 +16,7 @@ class GridHelper extends UGridHelper
|
|
|
/**
|
|
|
* 用户ID列,带链接
|
|
|
*/
|
|
|
- public function columnUserId(string $field = 'user_id', string $label = '用户ID'): Grid\Column
|
|
|
+ public function columnUserId($field = 'user_id', $label = '用户ID')
|
|
|
{
|
|
|
return $this->grid->column($field, $label)->link(function ($value) {
|
|
|
return admin_url("users/{$value}");
|
|
|
@@ -26,7 +26,7 @@ class GridHelper extends UGridHelper
|
|
|
/**
|
|
|
* 商品ID列,带链接
|
|
|
*/
|
|
|
- public function columnItemId(string $field = 'item_id', string $label = '商品ID'): Grid\Column
|
|
|
+ public function columnItemId($field = 'item_id', $label = '商品ID')
|
|
|
{
|
|
|
return $this->grid->column($field, $label)->link(function ($value) {
|
|
|
return admin_url("game-items/{$value}");
|
|
|
@@ -36,7 +36,7 @@ class GridHelper extends UGridHelper
|
|
|
/**
|
|
|
* 订单ID列,带链接
|
|
|
*/
|
|
|
- public function columnOrderId(string $field, string $label): Grid\Column
|
|
|
+ public function columnOrderId($field, $label)
|
|
|
{
|
|
|
return $this->grid->column($field, $label)->link(function ($value) {
|
|
|
return $value ? admin_url("mex-orders/{$value}") : '-';
|
|
|
@@ -46,7 +46,7 @@ class GridHelper extends UGridHelper
|
|
|
/**
|
|
|
* 价格列,格式化显示
|
|
|
*/
|
|
|
- public function columnPrice(string $field = 'price', string $label = '价格', int $decimals = 5): Grid\Column
|
|
|
+ public function columnPrice($field = 'price', $label = '价格', $decimals = 5)
|
|
|
{
|
|
|
return $this->grid->column($field, $label)->display(function ($value) use ($decimals) {
|
|
|
return number_format($value, $decimals);
|
|
|
@@ -56,7 +56,7 @@ class GridHelper extends UGridHelper
|
|
|
/**
|
|
|
* 金额列,格式化显示
|
|
|
*/
|
|
|
- public function columnAmount(string $field, string $label, int $decimals = 5): Grid\Column
|
|
|
+ public function columnAmount($field, $label, $decimals = 5)
|
|
|
{
|
|
|
return $this->grid->column($field, $label)->display(function ($value) use ($decimals) {
|
|
|
return $value ? number_format($value, $decimals) : '-';
|
|
|
@@ -66,99 +66,24 @@ class GridHelper extends UGridHelper
|
|
|
/**
|
|
|
* 数量列,格式化显示
|
|
|
*/
|
|
|
- public function columnQuantity(string $field = 'quantity', string $label = '数量'): Grid\Column
|
|
|
+ public function columnQuantity($field = 'quantity', $label = '数量')
|
|
|
{
|
|
|
return $this->grid->column($field, $label)->display(function ($value) {
|
|
|
return number_format($value);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 百分比列
|
|
|
- */
|
|
|
- public function columnPercentage(string $field, string $label, int $decimals = 2): Grid\Column
|
|
|
- {
|
|
|
- return $this->grid->column($field, $label)->display(function ($value) use ($decimals) {
|
|
|
- return number_format($value * 100, $decimals) . '%';
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 布尔值列,显示为是/否
|
|
|
- */
|
|
|
- public function columnBoolean(string $field, string $label): Grid\Column
|
|
|
- {
|
|
|
- return $this->grid->column($field, $label)->display(function ($value) {
|
|
|
- return $value ? '是' : '否';
|
|
|
- })->label([
|
|
|
- 1 => 'success',
|
|
|
- 0 => 'default',
|
|
|
- ]);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- * 状态列,带颜色标签
|
|
|
+ * 平均价格计算列(根据金额和数量字段计算)
|
|
|
*/
|
|
|
- public function columnStatus(string $field, string $label, array $statusMap, array $colorMap = []): Grid\Column
|
|
|
- {
|
|
|
- $column = $this->grid->column($field, $label)->using($statusMap);
|
|
|
-
|
|
|
- if (!empty($colorMap)) {
|
|
|
- $column->label($colorMap);
|
|
|
- }
|
|
|
-
|
|
|
- return $column;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 时间戳列,格式化显示
|
|
|
- */
|
|
|
- public function columnTimestamp(string $field, string $label, string $format = 'Y-m-d H:i:s'): Grid\Column
|
|
|
- {
|
|
|
- return $this->grid->column($field, $label)->display(function ($value) use ($format) {
|
|
|
- return $value ? date($format, $value) : '-';
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 日期时间列 - 使用UCore的统一时间格式化
|
|
|
- */
|
|
|
- public function columnDatetime(string $field, string $label): Grid\Column
|
|
|
- {
|
|
|
- return $this->columnDateTime($field, $label);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 文本截断列
|
|
|
- */
|
|
|
- public function columnText(string $field, string $label, int $limit = 50): Grid\Column
|
|
|
- {
|
|
|
- return $this->grid->column($field, $label)->limit($limit);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * JSON数据列
|
|
|
- */
|
|
|
- public function columnJson(string $field, string $label): Grid\Column
|
|
|
- {
|
|
|
- return $this->grid->column($field, $label)->display(function ($value) {
|
|
|
- if (is_string($value)) {
|
|
|
- $data = json_decode($value, true);
|
|
|
- return $data ? json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : $value;
|
|
|
- }
|
|
|
- return json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
|
- })->limit(100);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 平均价格计算列
|
|
|
- */
|
|
|
- public function columnAveragePrice(string $amountField, string $quantityField, string $label): Grid\Column
|
|
|
+ public function columnAveragePrice($amountField, $quantityField, $label)
|
|
|
{
|
|
|
return $this->grid->column($label)->display(function () use ($amountField, $quantityField) {
|
|
|
$amount = $this->{$amountField};
|
|
|
$quantity = $this->{$quantityField};
|
|
|
-
|
|
|
+
|
|
|
if ($quantity > 0) {
|
|
|
$avgPrice = bcdiv($amount, $quantity, 5);
|
|
|
return number_format($avgPrice, 5);
|
|
|
@@ -168,14 +93,14 @@ class GridHelper extends UGridHelper
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 净值计算列
|
|
|
+ * 净值计算列(正值减去负值)
|
|
|
*/
|
|
|
- public function columnNetValue(string $positiveField, string $negativeField, string $label, int $decimals = 5): Grid\Column
|
|
|
+ public function columnNetValue($positiveField, $negativeField, $label, $decimals = 5)
|
|
|
{
|
|
|
return $this->grid->column($label)->display(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);
|