Skip to content

Commit

Permalink
管理后台 - 订单列表
Browse files Browse the repository at this point in the history
  • Loading branch information
leo108 committed Dec 23, 2018
1 parent 8f7393c commit f7fc748
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
56 changes: 56 additions & 0 deletions app/Admin/Controllers/OrdersController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Admin\Controllers;

use App\Models\Order;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class OrdersController extends Controller
{
use HasResourceActions;

public function index(Content $content)
{
return $content
->header('订单列表')
->body($this->grid());
}

protected function grid()
{
$grid = new Grid(new Order);

// 只展示已支付的订单,并且默认按支付时间倒序排序
$grid->model()->whereNotNull('paid_at')->orderBy('paid_at', 'desc');

$grid->no('订单流水号');
// 展示关联关系的字段时,使用 column 方法
$grid->column('user.name', '买家');
$grid->total_amount('总金额')->sortable();
$grid->paid_at('支付时间')->sortable();
$grid->ship_status('物流')->display(function($value) {
return Order::$shipStatusMap[$value];
});
$grid->refund_status('退款状态')->display(function($value) {
return Order::$refundStatusMap[$value];
});
// 禁用创建按钮,后台不需要创建订单
$grid->disableCreateButton();
$grid->actions(function ($actions) {
// 禁用删除和编辑按钮
$actions->disableDelete();
$actions->disableEdit();
});
$grid->tools(function ($tools) {
// 禁用批量删除按钮
$tools->batch(function ($batch) {
$batch->disableDelete();
});
});

return $grid;
}
}
2 changes: 2 additions & 0 deletions app/Admin/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
$router->post('products', 'ProductsController@store');
$router->get('products/{id}/edit', 'ProductsController@edit');
$router->put('products/{id}', 'ProductsController@update');

$router->get('orders', 'OrdersController@index')->name('admin.orders.index');
});

0 comments on commit f7fc748

Please sign in to comment.