|
|
|
@ -2,11 +2,7 @@ |
|
|
|
|
|
|
|
namespace App\AdminAgent\Controllers; |
|
|
|
|
|
|
|
use App\AdminAgent\Renderable\SelectAgentProduct; |
|
|
|
use App\AdminAgent\Renderable\SelectProduct; |
|
|
|
use App\AdminAgent\Repositories\Slide; |
|
|
|
use App\Models\AgentProduct; |
|
|
|
use App\Models\Product; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
use Dcat\Admin\Grid; |
|
|
|
@ -22,23 +18,22 @@ class SlideController extends AdminController |
|
|
|
*/ |
|
|
|
protected function grid() |
|
|
|
{ |
|
|
|
return Grid::make(new Slide(['agentProduct.product:id,title,pictures']), function (Grid $grid) { |
|
|
|
$grid->model()->where('agent_id', Admin::user()->id)->orderBy('sort'); |
|
|
|
return Grid::make(new Slide(), function (Grid $grid) { |
|
|
|
$grid->model()->where('agent_id', Admin::user()->id)->orderBy('sort')->orderBy('id', 'DESC'); |
|
|
|
|
|
|
|
$grid->column('id')->sortable(); |
|
|
|
$grid->column('title'); |
|
|
|
$grid->column('picture')->image('', 60, 60); |
|
|
|
$grid->column('type')->using(['链接产品', '链接网址']); |
|
|
|
$grid->column('url') |
|
|
|
->if(fn($column) => $this->type == 0) |
|
|
|
->then(fn($column) => $column->display($this->agentProduct->product->title ?? '')) |
|
|
|
->else(fn($column) => $column->display($this->url ?? '')); |
|
|
|
$grid->column('type')->using(['链接内部页面', '链接网址']); |
|
|
|
$grid->column('url'); |
|
|
|
$grid->column('status')->switch(); |
|
|
|
$grid->column('sort')->editable()->sortable()->width(120); |
|
|
|
|
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
|
|
$filter->equal('id'); |
|
|
|
$filter->panel(); |
|
|
|
|
|
|
|
$filter->equal('id'); |
|
|
|
$filter->like('title'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -52,7 +47,7 @@ class SlideController extends AdminController |
|
|
|
*/ |
|
|
|
protected function detail($id) |
|
|
|
{ |
|
|
|
return Show::make($id, new Slide(['agentProduct.product:id,title,pictures']), function (Show $show) { |
|
|
|
return Show::make($id, new Slide(), function (Show $show) { |
|
|
|
//不允许查看非自己的数据
|
|
|
|
if ($show->model()->agent_id != Admin::user()->id) { |
|
|
|
Admin::exit('数据不存在'); |
|
|
|
@ -61,14 +56,8 @@ class SlideController extends AdminController |
|
|
|
$show->field('id'); |
|
|
|
$show->field('title'); |
|
|
|
$show->field('picture')->image('', 80, 80); |
|
|
|
$show->field('type')->using(['链接到产品详情', '链接到网址']); |
|
|
|
$show->field('url') |
|
|
|
->as(function ($v) { |
|
|
|
if($this->type == 0) { |
|
|
|
return $this->agentProduct->product->title; |
|
|
|
} |
|
|
|
return $v; |
|
|
|
}); |
|
|
|
$show->field('type')->using(['链接内部页面', '链接网址']); |
|
|
|
$show->field('url'); |
|
|
|
$show->field('status')->using(['禁用', '启用']); |
|
|
|
$show->field('sort'); |
|
|
|
$show->field('created_at'); |
|
|
|
@ -98,24 +87,14 @@ class SlideController extends AdminController |
|
|
|
->help('图片大小:750*360'); |
|
|
|
$form->select('status')->options(['禁用', '启用'])->default(1)->required(); |
|
|
|
$form->radio('type', '链接类型') |
|
|
|
->options(['链接到产品详情', '链接到网址']) |
|
|
|
->options(['链接到内部页面', '链接到网址']) |
|
|
|
->value(0)->default(0) |
|
|
|
->when(0, function (Form $form) { |
|
|
|
$form->selectTable('url-0', '链接到产品') |
|
|
|
->help('请选择要链接到的产品') |
|
|
|
->title('选择在售产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectAgentProduct::make(['id' => $form->url])) |
|
|
|
->options(function ($v) { |
|
|
|
if (!$v || $this->type != 0) return []; |
|
|
|
$agent_product = AgentProduct::with('product:id,title') |
|
|
|
->select(['id', 'product_id']) |
|
|
|
->firstWhere(['id' => $v]); |
|
|
|
if (!$agent_product) return []; |
|
|
|
return [$agent_product->id => $agent_product->product->title]; |
|
|
|
}) |
|
|
|
->pluck('product.title') |
|
|
|
->value($form->model()->url); |
|
|
|
$form->text('url-0', '内部页面地址') |
|
|
|
->customFormat(fn() => $this->type == 0 ? $this->url : '') |
|
|
|
->help('格式如下:<br>产品详情页:/pages/goodsDetail/index?goods_id=产品ID |
|
|
|
<br>文章详情页:/pages/notice/article?article_id=文章ID |
|
|
|
<br>公告详情页:/pages/notice/notice?notice_id=公告ID'); |
|
|
|
}) |
|
|
|
->when(1, function (Form $form) { |
|
|
|
$form->url('url-1', '链接到网址') |
|
|
|
|