11 changed files with 91 additions and 221 deletions
-
11MySQL_change.sql
-
25app/AdminAgent/Controllers/AdvertisingController.php
-
8app/AdminAgent/Controllers/SpecialController.php
-
130app/AdminAgent/Controllers/WaterfallAdController.php
-
16app/AdminAgent/Repositories/WaterfallAd.php
-
38app/Http/Controllers/Api/AgentProductController.php
-
18app/Http/Controllers/Api/IndexController.php
-
2app/Http/Controllers/Api/SpecialController.php
-
18app/Models/WaterfallAd.php
-
28resources/lang/zh_CN/advertising.php
-
18resources/lang/zh_CN/slide.php
@ -1,130 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\AdminAgent\Controllers; |
|
||||
|
|
||||
use App\AdminAgent\Repositories\WaterfallAd; |
|
||||
use Dcat\Admin\Admin; |
|
||||
use Dcat\Admin\Form; |
|
||||
use Dcat\Admin\Grid; |
|
||||
use Dcat\Admin\Show; |
|
||||
use Dcat\Admin\Http\Controllers\AdminController; |
|
||||
|
|
||||
class WaterfallAdController extends AdminController |
|
||||
{ |
|
||||
/** |
|
||||
* Make a grid builder. |
|
||||
* |
|
||||
* @return Grid |
|
||||
*/ |
|
||||
protected function grid() |
|
||||
{ |
|
||||
return Grid::make(new WaterfallAd('agentProduct.product:id,title'), 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'); |
|
||||
$grid->column('status')->switch(); |
|
||||
$grid->column('sort')->editable()->sortable()->width(120); |
|
||||
|
|
||||
$grid->filter(function (Grid\Filter $filter) { |
|
||||
$filter->panel(); |
|
||||
|
|
||||
$filter->equal('id')->width(2); |
|
||||
$filter->like('title')->width(3); |
|
||||
}); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Make a show builder. |
|
||||
* |
|
||||
* @param mixed $id |
|
||||
* |
|
||||
* @return Show |
|
||||
*/ |
|
||||
protected function detail($id) |
|
||||
{ |
|
||||
return Show::make($id, new WaterfallAd('agentProduct.product:id,title'), function (Show $show) { |
|
||||
//不允许查看非自己的数据
|
|
||||
if ($show->model()->agent_id != Admin::user()->id) { |
|
||||
Admin::exit('数据不存在'); |
|
||||
} |
|
||||
|
|
||||
$show->field('id'); |
|
||||
$show->field('title'); |
|
||||
$show->field('picture')->image('', 80, 80); |
|
||||
$show->field('type')->using(['链接内部页面', '链接网址']); |
|
||||
$show->field('url'); |
|
||||
$show->field('status')->using(['禁用', '启用']); |
|
||||
$show->field('sort'); |
|
||||
$show->field('created_at'); |
|
||||
$show->field('updated_at'); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Make a form builder. |
|
||||
* |
|
||||
* @return Form |
|
||||
*/ |
|
||||
protected function form() |
|
||||
{ |
|
||||
return Form::make(new WaterfallAd(), function (Form $form) { |
|
||||
//不允许查看非自己的数据
|
|
||||
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { |
|
||||
return $form->response()->error('数据不存在'); |
|
||||
} |
|
||||
|
|
||||
$form->display('id'); |
|
||||
$form->text('title')->required(); |
|
||||
$form->image('picture') |
|
||||
->required()->removable(false)->uniqueName(); |
|
||||
$form->radio('type', '链接类型') |
|
||||
->options(['链接到内部页面', '链接到网址']) |
|
||||
->value(0)->default(0) |
|
||||
->when(0, function (Form $form) { |
|
||||
$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', '链接到网址') |
|
||||
->placeholder('如:https://www.baidu.com/') |
|
||||
->customFormat(fn() => $this->type == 1 ? $this->url : ''); |
|
||||
}); |
|
||||
$form->text('sort')->default(255)->required(); |
|
||||
})->saving(function (Form $form) { |
|
||||
//不允许修改非自己的数据
|
|
||||
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { |
|
||||
return $form->response()->error('数据不存在'); |
|
||||
} |
|
||||
|
|
||||
//将null字段设置为空值,防止插入数据库出错
|
|
||||
foreach ($form->input() as $k => $v) { |
|
||||
if (is_null($v)) { |
|
||||
$form->$k = ''; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
//处理特殊字段
|
|
||||
$form->hidden(['agent_id', 'url']); |
|
||||
$form->agent_id = Admin::user()->id; |
|
||||
$form->status = $form->status ? 1 : 0; |
|
||||
$form->url = $form->{'url-' . $form->type}; |
|
||||
$form->deleteInput(['url-0', 'url-1']); |
|
||||
|
|
||||
//不允许编辑的字段
|
|
||||
$form->ignore(['id', 'created_at', 'updated_at']); |
|
||||
})->deleting(function (Form $form) { |
|
||||
//不允许删除非自己的数据
|
|
||||
if (array_filter($form->model()->toArray(), fn($v) => $v['agent_id'] != Admin::user()->id)) { |
|
||||
return $form->response()->error('数据不存在'); |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\AdminAgent\Repositories; |
|
||||
|
|
||||
use App\Models\WaterfallAd as Model; |
|
||||
use Dcat\Admin\Repositories\EloquentRepository; |
|
||||
|
|
||||
class WaterfallAd extends EloquentRepository |
|
||||
{ |
|
||||
/** |
|
||||
* Model. |
|
||||
* |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $eloquentClass = Model::class; |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Models; |
|
||||
|
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|
||||
|
|
||||
use Illuminate\Database\Eloquent\Model; |
|
||||
|
|
||||
class WaterfallAd extends Model |
|
||||
{ |
|
||||
use HasDateTimeFormatter; |
|
||||
protected $table = 'waterfall_ads'; |
|
||||
|
|
||||
public function agentProduct() |
|
||||
{ |
|
||||
return $this->belongsTo(AgentProduct::class); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,28 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'Advertising' => '广告图', |
||||
|
'advertising' => '广告图', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'title' => '标题', |
||||
|
'picture' => '图片地址', |
||||
|
'status' => '状态', |
||||
|
'agent_id' => '代理商ID', |
||||
|
'sort' => '排序', |
||||
|
'type' => '链接类型', |
||||
|
'url' => '链接到', |
||||
|
'display' => '显示位置', |
||||
|
], |
||||
|
'options' => [ |
||||
|
'type' => [ |
||||
|
0 => '内部页面', |
||||
|
1 => '网址', |
||||
|
], |
||||
|
'display' => [ |
||||
|
0 => '轮播图', |
||||
|
1 => '首页横屏广告', |
||||
|
2 => '产品列表内嵌广告', |
||||
|
], |
||||
|
], |
||||
|
]; |
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
return [ |
|
||||
'labels' => [ |
|
||||
'Slide' => '轮播图', |
|
||||
'slide' => '轮播图', |
|
||||
], |
|
||||
'fields' => [ |
|
||||
'title' => '图片说明', |
|
||||
'picture' => '图片地址', |
|
||||
'status' => '状态', |
|
||||
'agent_id' => '代理商ID', |
|
||||
'sort' => '排序', |
|
||||
'type' => '链接类型', |
|
||||
'url' => '链接到', |
|
||||
], |
|
||||
'options' => [ |
|
||||
], |
|
||||
]; |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue