6 changed files with 154 additions and 0 deletions
-
16MySQL_change.sql
-
93app/AdminAgent/Controllers/WaterfallAdController.php
-
16app/AdminAgent/Repositories/WaterfallAd.php
-
1app/AdminAgent/routes.php
-
14app/Models/WaterfallAd.php
-
14resources/lang/zh_CN/waterfall-ad.php
@ -0,0 +1,93 @@ |
|||
<?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(), function (Grid $grid) { |
|||
$grid->disableFilterButton(); |
|||
|
|||
$grid->model()->where('agent_id', Admin::user()->id); |
|||
|
|||
$grid->column('id')->sortable(); |
|||
$grid->column('picture'); |
|||
$grid->column('agent_product_id'); |
|||
$grid->column('created_at'); |
|||
$grid->column('updated_at')->sortable(); |
|||
|
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->panel(); |
|||
|
|||
$filter->equal('id'); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a show builder. |
|||
* |
|||
* @param mixed $id |
|||
* |
|||
* @return Show |
|||
*/ |
|||
protected function detail($id) |
|||
{ |
|||
return Show::make($id, new WaterfallAd(), function (Show $show) { |
|||
//不允许查看非自己的数据
|
|||
if ($show->model()->agent_id != Admin::user()->id) { |
|||
Admin::exit('数据不存在'); |
|||
} |
|||
|
|||
$show->field('id'); |
|||
$show->field('picture'); |
|||
$show->field('agent_product_id'); |
|||
$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('picture'); |
|||
$form->text('agent_product_id'); |
|||
})->saving(function (Form $form) { |
|||
//不允许修改非自己的数据
|
|||
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { |
|||
return $form->response()->error('数据不存在'); |
|||
} |
|||
|
|||
|
|||
})->deleting(function (Form $form) { |
|||
//不允许删除非自己的数据
|
|||
if ($form->model()[0]['agent_id'] != Admin::user()->id) { |
|||
return $form->response()->error('数据不存在'); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?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; |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|||
|
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class WaterfallAd extends Model |
|||
{ |
|||
use HasDateTimeFormatter; |
|||
protected $table = 'waterfall_ads'; |
|||
|
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'WaterfallAd' => '产品列表内嵌广告', |
|||
'waterfall-ad' => '产品列表内嵌广告', |
|||
], |
|||
'fields' => [ |
|||
'agent_id' => '代理商ID', |
|||
'picture' => '广告图片', |
|||
'agent_product_id' => '链接到产品', |
|||
], |
|||
'options' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue