forked from summerblue/laravel-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters