header(function () {
$matchTimes = MexTransactionService::getLastMatchTimes();
$lastSellTime = $matchTimes['last_sell_match_time']
? $matchTimes['last_sell_match_time']->format('Y-m-d H:i:s')
: '暂无记录';
$lastBuyTime = $matchTimes['last_buy_match_time']
? $matchTimes['last_buy_match_time']->format('Y-m-d H:i:s')
: '暂无记录';
return '
最后卖出撮合时间: ' . $lastSellTime . '
最后买入撮合时间: ' . $lastBuyTime . '
';
});
$grid->column('id', 'ID')->sortable();
$helper->columnUserId();
$helper->columnItemId();
$grid->column('item.name', '商品名称')->display(function ($value) {
return $value ?: '未知商品';
});
$grid->column('order_type', '订单类型')->display(function ($value) {
return $value instanceof OrderType ? $value->getDescription() : OrderType::from($value)->getDescription();
})->label([
'BUY' => 'primary',
'SELL' => 'success',
]);
$helper->columnQuantity();
$helper->columnPrice();
$helper->columnAmount('total_amount', '总金额');
$grid->column('status', '状态')->display(function ($value) {
return $value instanceof OrderStatus ? $value->getDescription() : OrderStatus::from($value)->getDescription();
})->label([
'PENDING' => 'warning',
'COMPLETED' => 'success',
'CANCELLED' => 'default',
'FAILED' => 'danger',
]);
$helper->columnQuantity('completed_quantity', '已成交数量');
$helper->columnAmount('completed_amount', '已成交金额');
$helper->columnDatetime('created_at', '创建时间');
$helper->columnDatetime('completed_at', '完成时间');
// 禁用新增和删除
$grid->disableCreateButton();
$grid->disableDeleteButton();
// 筛选器
$grid->filter(function (Grid\Filter $filter) {
$filterHelper = new FilterHelper($filter, $this);
$filterHelper->equalId();
$filterHelper->equalUserId();
$filterHelper->equalItemId();
$filterHelper->equalOrderType();
$filterHelper->equalOrderStatus();
$filterHelper->betweenPrice();
$filterHelper->betweenAmount('total_amount', '总金额范围');
$filterHelper->betweenCreatedAt();
});
// 默认排序
$grid->model()->orderBy('created_at', 'desc');
});
}
/**
* 详情页面
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new MexOrderRepository(['item']), function (Show $show) {
$show->field('id', 'ID');
$show->field('user_id', '用户ID');
$show->field('item_id', '商品ID');
$show->field('item.name', '商品名称')->as(function ($value) {
return $value ?: '未知商品';
});
$show->field('order_type', '订单类型')->as(function ($value) {
return $value instanceof OrderType ? $value->getDescription() : OrderType::from($value)->getDescription();
});
$show->field('quantity', '数量');
$show->field('price', '价格');
$show->field('total_amount', '总金额');
$show->field('status', '状态')->as(function ($value) {
return $value instanceof OrderStatus ? $value->getDescription() : OrderStatus::from($value)->getDescription();
});
$show->field('frozen_amount', '冻结金额');
$show->field('completed_quantity', '已成交数量');
$show->field('completed_amount', '已成交金额');
$show->field('failed_reason', '失败原因');
$show->field('created_at', '创建时间');
$show->field('updated_at', '更新时间');
$show->field('completed_at', '完成时间');
// 禁用编辑和删除
$show->disableEditButton();
$show->disableDeleteButton();
});
}
/**
* 表单页面(仅用于查看,不允许编辑)
*
* @return Form
*/
protected function form()
{
return Form::make(new MexOrderRepository(['item']), function (Form $form) {
$helper = new FormHelper($form, $this);
$helper->display('id', 'ID');
$helper->display('user_id', '用户ID');
$helper->display('item_id', '商品ID');
$form->display('item.name', '商品名称')->with(function ($value) {
return $value ?: '未知商品';
});
$form->display('order_type', '订单类型')->with(function ($value) {
return OrderType::from($value)->getDescription();
});
$helper->display('quantity', '数量');
$helper->display('price', '单价');
$helper->display('total_amount', '总金额');
$form->display('status', '状态')->with(function ($value) {
return OrderStatus::from($value)->getDescription();
});
$helper->display('frozen_amount', '冻结金额');
$helper->display('completed_quantity', '已成交数量');
$helper->display('completed_amount', '已成交金额');
$helper->display('failed_reason', '失败原因');
$helper->display('created_at', '创建时间');
$helper->display('updated_at', '更新时间');
$helper->display('completed_at', '完成时间');
// 禁用保存按钮
$form->disableSubmitButton();
$form->disableResetButton();
});
}
}