117 lines
3.4 KiB
PHP
117 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Renderable\ShippingRuleTable;
|
|
use App\Admin\Repositories\ShippingTemplate;
|
|
use App\Exceptions\BizException;
|
|
use App\Models\ShippingTemplate as ShippingTemplateModel;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Layout\Content;
|
|
use Dcat\Admin\Show;
|
|
|
|
class ShippingTemplateController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new ShippingTemplate(), function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('name');
|
|
$grid->column('created_at')->sortable();
|
|
|
|
//排序
|
|
$grid->model()->orderBy('created_at', 'desc');
|
|
|
|
/** 操作 **/
|
|
//新增
|
|
if (Admin::user()->can('dcat.admin.shipping_templates.create')) {
|
|
$grid->disableCreateButton(false);
|
|
$grid->enableDialogCreate();
|
|
}
|
|
//修改
|
|
$grid->showQuickEditButton(Admin::user()->can('dcat.admin.shipping_templates.edit'));
|
|
//删除以及自定义操作
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
$actions->disableDelete(Admin::user()->cannot('dcat.admin.shipping_templates.destroy'));
|
|
if (Admin::user()->can('dcat.admin.shipping_templates.rule_list')) {
|
|
$actions->append('<a href="'.admin_route('shipping_templates.rule_list', ['template'=>$actions->row]).'">
|
|
<i class="feather icon-settings grid-action-icon"></i> 运费规则
|
|
</a>');
|
|
}
|
|
});
|
|
|
|
/** 查询 **/
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
$filter->like('name')->width(3);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new ShippingTemplate(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('name');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new ShippingTemplate(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->text('name');
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
//如果有商品选择这个规则
|
|
$template = ShippingTemplateModel::findOrFail($id);
|
|
if ($template->hasSku()) {
|
|
throw new BizException(__('shipping-template.options.deny_message'));
|
|
}
|
|
|
|
return parent::destroy($id);
|
|
}
|
|
|
|
/**
|
|
* 运费模板的规则
|
|
*
|
|
* @param Content $content
|
|
* @param ShippingTemplateModel $coupon
|
|
* @return void
|
|
*/
|
|
public function ruleList(Content $content, ShippingTemplateModel $template)
|
|
{
|
|
return $content->header(__('coupon.labels.coupons'))
|
|
->description($template->name)
|
|
->body(ShippingRuleTable::grid($template->id));
|
|
}
|
|
}
|