remove banner
parent
38b3e1e1bb
commit
ee02f1b67d
|
|
@ -1,7 +0,0 @@
|
|||
.DS_Store
|
||||
phpunit.phar
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
*.project
|
||||
.idea/
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
# Dact-Admin Extension Banner
|
||||
|
||||
广告管理
|
||||
|
||||
## 权限
|
||||
|
||||
```php
|
||||
$permissions = [
|
||||
'image' => ['name' => '广告管理', 'curd' => false, 'children' => [
|
||||
'banner_ads' => ['name' => '广告位置', 'curd' => true],
|
||||
'banners' => ['name' => '广告内容', 'curd' => true],
|
||||
]],
|
||||
];
|
||||
```
|
||||
|
||||
## 菜单
|
||||
|
||||
```php
|
||||
$menus = [
|
||||
['title' => '广告管理', 'icon' => 'feather icon-image', 'uri' => '', 'permission' => ['banner_ads', 'banners'], 'children' => [
|
||||
['title' => '广告位置', 'icon' => '', 'uri' => '/banner-ads', 'permission' => 'banner_ads'],
|
||||
['title' => '广告内容', 'icon' => '', 'uri' => '/banners', 'permission' => 'banners'],
|
||||
]]
|
||||
];
|
||||
```
|
||||
|
||||
## 接口文档
|
||||
|
||||
[Apifox](https://www.apifox.cn/apidoc/shared-86eb60cb-ba8f-46c6-b718-f33f99de5e7d/api-39896291)
|
||||
|
||||
## 数据表
|
||||
|
||||
### 广告位: banner_ads
|
||||
|
||||
| column | type | nullable | default | comment |
|
||||
| - | - | - | - | - |
|
||||
| id | bigint | not null | - | 主键 |
|
||||
| name | varchar(100) | not null | - | 名称 |
|
||||
| key | varchar(100) | not null | - | 关键字(unique) |
|
||||
| width | integer | null | - | 建议尺寸 |
|
||||
| height | integer | null | - | 建议尺寸 |
|
||||
| is_enable | integer | not null | 1 | 是否可用 |
|
||||
| remarks | varchar(100) | null | - | 备注 |
|
||||
| created_at | timestamp | null | - | 创建时间 |
|
||||
| updated_at | timestamp | null | - | 更新时间 |
|
||||
|
||||
### 广告图: banner
|
||||
|
||||
| column | type | nullable | default | comment |
|
||||
| - | - | - | - | - |
|
||||
| id | bigint | not null | - | 主键 |
|
||||
| ad_id | bigint | not null | - | 位置 id |
|
||||
| path | varchar(191) | not null | - | 图片地址 |
|
||||
| name | varchar(191) | null | - | 名称 |
|
||||
| sort | integer | not null | 1 | 排序(asc) |
|
||||
| is_enable | integer | not null | 1 | 是否可用 |
|
||||
| ext | json | null | - | 其他配置 |
|
||||
| remarks | varchar(191) | null | - | 备注 |
|
||||
| created_at | timestamp | null | - | 创建时间 |
|
||||
| updated_at | timestamp | null | - | 更新时间 |
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
{
|
||||
"name": "peidikeji/banner",
|
||||
"alias": "广告管理",
|
||||
"description": "广告管理",
|
||||
"type": "library",
|
||||
"keywords": ["dcat-admin", "extension"],
|
||||
"homepage": "https://github.com/peidikeji/banner",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "liutk",
|
||||
"email": "961510893@qq.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Peidikeji\\Banner\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"dcat-admin": "Peidikeji\\Banner\\BannerServiceProvider",
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Peidikeji\\Banner\\BannerServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [];
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [];
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'labels' => [
|
||||
'BannerAd' => '广告位管理',
|
||||
'banner-ads'=> '广告位管理',
|
||||
],
|
||||
'fields' => [
|
||||
'name' => '名称',
|
||||
'key' => 'key',
|
||||
'width' => '宽度',
|
||||
'height' => '高度',
|
||||
'is_enable' => '启用',
|
||||
'remarks' => '备注',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
];
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'labels' => [
|
||||
'Banner' => '广告图管理',
|
||||
'banners' => '广告图管理',
|
||||
],
|
||||
'fields' => [
|
||||
'ad_id'=>'广告位',
|
||||
'name'=>'名称',
|
||||
'path'=>'内容',
|
||||
'sort'=>'排序',
|
||||
'is_enable'=>'启用',
|
||||
'remarks'=> '备注',
|
||||
'ext'=>'扩展字段',
|
||||
'ad' => [
|
||||
'name' => '广告位'
|
||||
],
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
];
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner;
|
||||
|
||||
use Dcat\Admin\Extend\ServiceProvider;
|
||||
|
||||
class BannerServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
}
|
||||
|
||||
protected function menu()
|
||||
{
|
||||
if (config('app.debug')) {
|
||||
return [
|
||||
['parent' => '', 'title' => '广告管理', 'icon' => 'feather icon-image', 'uri' => ''],
|
||||
['parent' => '广告管理', 'title' => '广告位置', 'icon' => '', 'uri' => 'banner-ads'],
|
||||
['parent' => '广告管理', 'title' => '广告内容', 'icon' => '', 'uri' => 'banners'],
|
||||
];
|
||||
}
|
||||
return $this->menu;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Http\Admin;
|
||||
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Peidikeji\Banner\Models\Banner;
|
||||
use Peidikeji\Banner\Models\BannerAd;
|
||||
use Dcat\Admin\Grid\Column as GridColumn;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
|
||||
class BannerAdController extends AdminController
|
||||
{
|
||||
protected $translation = 'peidikeji.banner::banner-ad';
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$query = BannerAd::query();
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$query->where('name', 'like', '%'.$request->input('q').'%');
|
||||
}
|
||||
|
||||
if ($request->filled('id')) {
|
||||
$query->where('id',$request->input('id'));
|
||||
}
|
||||
|
||||
$query->select(['id', 'name as text', 'width', 'height']);
|
||||
|
||||
if ($request->filled('_paginate')) {
|
||||
$list = $query->paginate();
|
||||
} else {
|
||||
$list = $query->get();
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
return Grid::make(new BannerAd(), function ($grid) {
|
||||
$grid->disableRowSelector();
|
||||
|
||||
$grid->column('name');
|
||||
$grid->column('key');
|
||||
$grid->column('width');
|
||||
$grid->column('height');
|
||||
$grid->column('is_enable')->if(function(){
|
||||
return !config('admin.permission.enable') || Admin::user()->can('dcat.admin.banner_ads.edit');
|
||||
})->then(function (GridColumn $column) {
|
||||
$column->switch();
|
||||
})->else(function (GridColumn $column) {
|
||||
$column->bool();
|
||||
});
|
||||
$grid->column('remarks');
|
||||
$grid->disableCreateButton(!(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.banner_ads.create')));
|
||||
$grid->enableDialogCreate();
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableView();
|
||||
$actions->disableEdit();
|
||||
$actions->quickEdit(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.banner_ads.edit'));
|
||||
$actions->delete(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.banner_ads.destroy'));
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->expand();
|
||||
$filter->like('name')->width(3);
|
||||
$filter->like('key')->width(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new BannerAd(), function (Form $form) {
|
||||
$form->text('name')->required();
|
||||
$unique = Rule::unique((new BannerAd())->getTable());
|
||||
if ($form->isEditing()) {
|
||||
$unique->ignore($form->getKey());
|
||||
}
|
||||
$form->text('key')->required()->rules([$unique]);
|
||||
$form->number('width')->min(0);
|
||||
$form->number('height')->min(0);
|
||||
$form->switch('is_enable')->default(1);
|
||||
$form->text('remarks');
|
||||
});
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
//如果该广告位下还有内容,则一起删除
|
||||
Banner::where(['ad_id' => $id])->delete();
|
||||
|
||||
return parent::destroy($id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Http\Admin;
|
||||
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Widgets\Card;
|
||||
use Peidikeji\Banner\Models\Banner;
|
||||
use Dcat\Admin\Grid\Column as GridColumn;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Peidikeji\Banner\Models\BannerAd;
|
||||
|
||||
class BannerController extends AdminController
|
||||
{
|
||||
protected $translation = 'peidikeji.banner::banner';
|
||||
|
||||
protected $extDefaults = [];
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
return Grid::make(Banner::with(['ad']), function (Grid $grid) {
|
||||
$grid->model()->sort();
|
||||
|
||||
$grid->disableRowSelector();
|
||||
$grid->column('ad.name');
|
||||
$grid->column('path')->image('', 50);
|
||||
$grid->column('name');
|
||||
$grid->column('sort');
|
||||
$grid->column('is_enable')->if(function () {
|
||||
return !config('admin.permission.enable') || Admin::user()->can('dcat.admin.banners.edit');
|
||||
})->then(function (GridColumn $column) {
|
||||
$column->switch();
|
||||
})->else(function (GridColumn $column) {
|
||||
$column->bool();
|
||||
});
|
||||
$grid->column('ext')
|
||||
->if(function () {
|
||||
return $this->ext;
|
||||
})->then(function (GridColumn $column) {
|
||||
$column->display('展开')->expand(function () {
|
||||
// 返回显示的详情
|
||||
$card = new Card(null, sprintf('<pre class="dump">%s</pre>', json_encode($this->ext, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)));
|
||||
|
||||
return "<div style='padding:10px 10px 0'>$card</div>";
|
||||
});
|
||||
});
|
||||
|
||||
$grid->column('remarks');
|
||||
|
||||
$grid->setDialogFormDimensions('50%', '70%');
|
||||
$grid->disableCreateButton(!(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.banners.create')));
|
||||
$grid->enableDialogCreate();
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableView();
|
||||
$actions->disableEdit();
|
||||
$actions->quickEdit(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.banners.edit'));
|
||||
$actions->delete(!config('admin.permission.enable') || Admin::user()->can('dcat.admin.banners.destroy'));
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->expand();
|
||||
$filter->equal('ad_id')->select(BannerAd::pluck('name', 'id'))->width(3);
|
||||
$filter->like('name')->width(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new Banner(), function (Form $form) {
|
||||
$form->select('ad_id')
|
||||
->options('api/banner-ads')
|
||||
->required();
|
||||
$form->text('name');
|
||||
$form->image('path')
|
||||
->uniqueName()
|
||||
->move('banner')
|
||||
->saveFullUrl()
|
||||
->autoSave(false)
|
||||
->autoUpload()
|
||||
->removable(false) //禁止用户从页面点击删除服务器上的文件,可以实现图片覆盖上传效果
|
||||
->retainable()
|
||||
->required()->help('建议尺寸:');
|
||||
Admin::script(
|
||||
<<<JS
|
||||
$('body').on('select2:select', 'select.field_ad_id', function(e){
|
||||
console.log( e.params.data.id);
|
||||
let url_path = '/admin/api/banner-ads?id=' + e.params.data.id
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
url: url_path,
|
||||
success: function(result){
|
||||
//异步渲染提示尺寸;
|
||||
let cicun = '未设置';
|
||||
if(result[0]){
|
||||
console.log(result[0]);
|
||||
if(result[0].width || result[0].height){
|
||||
console.log(654321)
|
||||
cicun = result[0].width + '*' + result[0].height;
|
||||
}
|
||||
}
|
||||
console.log(cicun);
|
||||
$('input[name=path]').parent().find('span.help-block').html('<i class="fa feather icon-help-circle"></i> 建议尺寸:'+ cicun);
|
||||
}
|
||||
});
|
||||
});
|
||||
JS
|
||||
);
|
||||
$form->number('sort')
|
||||
->min(0)
|
||||
->help('数值越小, 越靠前');
|
||||
$form->keyValue('ext')->default($this->extDefaults)->setKeyLabel('键名')->setValueLabel('键值');
|
||||
$form->switch('is_enable')->default(1);
|
||||
$form->text('remarks');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Http\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Peidikeji\Banner\Models\BannerAd;
|
||||
use Peidikeji\Banner\Http\Resources\BannerResource;
|
||||
|
||||
class BannerController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'key' => 'required'
|
||||
]);
|
||||
$keys = $request->input('key');
|
||||
$keys = is_array($keys) ? $keys : explode(',', $keys);
|
||||
|
||||
$ads = BannerAd::with([
|
||||
'banners' => function ($query) {
|
||||
$query->enable()->sort();
|
||||
},
|
||||
])->enable()->whereIn('key', $keys)->get();
|
||||
|
||||
$data = [];
|
||||
foreach ($keys as $key) {
|
||||
$ad = $ads->where('key', $key)->first();
|
||||
$data[$key] = $ad ? BannerResource::collection($ad->banners) : [];
|
||||
}
|
||||
|
||||
return $this->json($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class BannerResource extends JsonResource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'path' => $this->path,
|
||||
'ext' => $this->ext,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Http\Admin;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
if(! Route::has('dcat.admin.api.banner_ads')){
|
||||
Route::get('api/banner-ads', [BannerAdController::class, 'list'])->name('api.banner_ads');
|
||||
}
|
||||
|
||||
if(! Route::has('dcat.admin.banner_ads.index')){
|
||||
Route::resource('banner-ads', BannerAdController::class)->names('banner_ads');
|
||||
}
|
||||
if(! Route::has('dcat.admin.banners.index')){
|
||||
Route::resource('banners', BannerController::class);
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Http\Api;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group(['middleware' => 'api', 'prefix' => 'api'], function () {
|
||||
Route::get('banner', [BannerController::class, 'index']);
|
||||
});
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Banner extends Model
|
||||
{
|
||||
use HasFactory, HasDateTimeFormatter;
|
||||
|
||||
protected $fillable = ['ad_id', 'path', 'name', 'sort', 'is_enable', 'ext', 'remarks'];
|
||||
|
||||
protected $casts = [
|
||||
'ext' => 'array'
|
||||
];
|
||||
|
||||
public function ad()
|
||||
{
|
||||
return $this->belongsTo(BannerAd::class, 'ad_id');
|
||||
}
|
||||
|
||||
public function scopeEnable($query)
|
||||
{
|
||||
return $query->where('is_enable', 1);
|
||||
}
|
||||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $q->orderBy('sort');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Banner\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class BannerAd extends Model
|
||||
{
|
||||
use HasFactory, HasDateTimeFormatter;
|
||||
|
||||
protected $fillable = ['name', 'key', 'width', 'height', 'is_enable', 'remarks'];
|
||||
|
||||
public function banners()
|
||||
{
|
||||
return $this->hasMany(Banner::class, 'ad_id');
|
||||
}
|
||||
|
||||
public function scopeEnable($query){
|
||||
return $query->where('is_enable', 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateBannerTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Schema::hasTable('banner_ads')) {
|
||||
Schema::create('banner_ads', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->comment('名称');
|
||||
$table->string('key')->unique()->comment('key');
|
||||
$table->unsignedInteger('width')->nullable()->comment('宽');
|
||||
$table->unsignedInteger('height')->nullable()->comment('高');
|
||||
$table->unsignedTinyInteger('is_enable')->default(1)->comment('可用状态');
|
||||
$table->string('remarks')->nullable()->comment('备注');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
if (!Schema::hasTable('banners')) {
|
||||
Schema::create('banners', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('ad_id')->comment('位置ID');
|
||||
$table->string('path')->comment('地址');
|
||||
$table->string('name')->nullable()->comment('名称');
|
||||
$table->unsignedInteger('sort')->default(1)->comment('排序(asc)');
|
||||
$table->unsignedTinyInteger('is_enable')->default(1)->comment('可用状态');
|
||||
$table->text('ext')->nullable()->comment('扩展字段,可用于跳转配置等');
|
||||
$table->string('remarks')->nullable()->comment('备注');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('banners');
|
||||
Schema::dropIfExists('banner_ads');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'1.0.0' => [
|
||||
'CreateBannerTable.php',
|
||||
],
|
||||
];
|
||||
Loading…
Reference in New Issue