diff --git a/app/Admin/Controllers/AdAddressController.php b/app/Admin/Controllers/AdAddressController.php new file mode 100644 index 00000000..45620df1 --- /dev/null +++ b/app/Admin/Controllers/AdAddressController.php @@ -0,0 +1,102 @@ +column('id')->sortable(); + $grid->column('key'); + $grid->column('name'); + $grid->column('dimensions'); + $grid->column('is_show') + ->if(function () { + return Admin::user()->can('dcat.admin.ad-addresses.edit'); + }) + ->then(function (Column $column) { + $column->switch(); + }) + ->else(function (Column $column) { + $column->bool(); + }); + $grid->column('created_at')->sortable(); + //排序 + $grid->model()->orderBy('created_at', 'desc'); + + /** 操作 **/ + //新增 + if (Admin::user()->can('dcat.admin.ad-addresses.create')) { + $grid->disableCreateButton(false); + $grid->enableDialogCreate(); + } + //修改 + $grid->showQuickEditButton(Admin::user()->can('dcat.admin.ad_addresses.edit')); + //删除以及自定义操作 + $grid->actions(function (Grid\Displayers\Actions $actions) { + $actions->disableDelete(Admin::user()->cannot('dcat.admin.ad_addresses.destroy')); + }); + + /** 查询 **/ + $grid->filter(function (Grid\Filter $filter) { + $filter->panel(); + $filter->equal('key')->width(3); + $filter->equal('name')->width(3); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new AdAddress(), function (Show $show) { + $show->field('id'); + $show->field('key'); + $show->field('name'); + $show->field('dimensions'); + $show->field('is_show'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new AdAddress(), function (Form $form) { + $form->display('id'); + + $form->text('key')->required(); + $form->text('name'); + $form->text('dimensions')->help(__('admin_message.ad-address.dimensions.help')); + $form->switch('is_show'); + + $form->display('created_at'); + $form->display('updated_at'); + }); + } +} diff --git a/app/Admin/Controllers/AdController.php b/app/Admin/Controllers/AdController.php new file mode 100644 index 00000000..4b6af391 --- /dev/null +++ b/app/Admin/Controllers/AdController.php @@ -0,0 +1,122 @@ +column('id')->sortable(); + $grid->column('address.name'); + $grid->column('src_path')->image(50, 100); + $grid->column('sort'); + $grid->column('jump_type')->using([ + '0'=>__('admin_message.ad.jump_type.radio.0'), + '1'=>__('admin_message.ad.jump_type.radio.1'), + '2'=>__('admin_message.ad.jump_type.radio.2'), + ])->label(); + $grid->column('jump_link'); + $grid->column('is_show') + ->if(function () { + return Admin::user()->can('dcat.admin.ads.edit'); + }) + ->then(function (Column $column) { + $column->switch(); + }) + ->else(function (Column $column) { + $column->bool(); + }); + $grid->column('created_at')->sortable(); + //排序 + $grid->model()->orderBy('created_at', 'desc'); + $grid->model()->orderBy('address_id', 'desc'); + + /** 操作 **/ + //新增 + if (Admin::user()->can('dcat.admin.ad-addresses.create')) { + $grid->disableCreateButton(false); + $grid->enableDialogCreate(); + } + //修改 + $grid->showQuickEditButton(Admin::user()->can('dcat.admin.ad_addresses.edit')); + //删除以及自定义操作 + $grid->actions(function (Grid\Displayers\Actions $actions) { + $actions->disableDelete(Admin::user()->cannot('dcat.admin.ad_addresses.destroy')); + }); + + /** 查询 **/ + $grid->filter(function (Grid\Filter $filter) { + $filter->panel(); + $filter->equal('address_id')->select(AdAddress::all()->pluck('name', 'id'))->width(3); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new Ad(), function (Show $show) { + $show->field('id'); + $show->field('address_id'); + $show->field('src_path'); + $show->field('sort'); + $show->field('jump_type'); + $show->field('jump_link'); + $show->field('is_show'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new Ad(), function (Form $form) { + $form->display('id'); + $form->select('address_id')->options(AdAddress::all()->pluck('name', 'id')); + $form->image('src_path') + ->move('ads/'.Carbon::now()->toDateString()) + ->saveFullUrl() + ->removable(false) + ->autoUpload(); + $form->radio('jump_type')->options([ + '0'=>__('admin_message.ad.jump_type.radio.0'), + '1'=>__('admin_message.ad.jump_type.radio.1'), + '2'=>__('admin_message.ad.jump_type.radio.2'), + ])->default(0); + $form->text('jump_link'); + $form->switch('is_show'); + $form->number('sort')->default(0); + + $form->display('created_at'); + $form->display('updated_at'); + }); + } +} diff --git a/app/Admin/Repositories/Ad.php b/app/Admin/Repositories/Ad.php new file mode 100644 index 00000000..28e9e5c4 --- /dev/null +++ b/app/Admin/Repositories/Ad.php @@ -0,0 +1,16 @@ + 'boolean', + ]; + + public function address() + { + return $this->belongsTo(AdAddress::class, 'address_id'); + } +} diff --git a/app/Models/AdAddress.php b/app/Models/AdAddress.php new file mode 100644 index 00000000..c61a3b8e --- /dev/null +++ b/app/Models/AdAddress.php @@ -0,0 +1,17 @@ + 'boolean', + ]; +} diff --git a/database/migrations/2021_11_18_135133_create_ads_table.php b/database/migrations/2021_11_18_135133_create_ads_table.php new file mode 100644 index 00000000..9b29eadf --- /dev/null +++ b/database/migrations/2021_11_18_135133_create_ads_table.php @@ -0,0 +1,48 @@ +id(); + $table->string('key')->unique()->comment('广告位KEY'); + $table->string('name')->nullable()->comment('广告位名称'); + $table->string('dimensions')->nullable()->comment('广告位宽高'); + $table->tinyInteger('is_show')->default(0)->comment('是否显示:0不显示,1显示'); + $table->timestamps(); + }); + + Schema::create('ads', function (Blueprint $table) { + $table->id(); + $table->bigInteger('address_id')->default(0)->comment('广告位ID'); + $table->string('src_path')->nullable()->comment('图片地址'); + $table->integer('sort')->default(0)->comment('广告排序:逆序'); + $table->tinyInteger('jump_type')->default(0)->comment('跳转类型:0不跳转,1跳转应用内页,2H5链接'); + $table->string('jump_link')->nullable()->comment('跳转地址'); + $table->tinyInteger('is_show')->default(0)->comment('是否显示:0不显示,1显示'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('ads'); + Schema::dropIfExists('ad_addresses'); + } +} diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php new file mode 100644 index 00000000..e4cb4968 --- /dev/null +++ b/dcat_admin_ide_helper.php @@ -0,0 +1,205 @@ + + */ +namespace Dcat\Admin { + use Illuminate\Support\Collection; + + /** + * @property Grid\Column|Collection created_at + * @property Grid\Column|Collection dimensions + * @property Grid\Column|Collection id + * @property Grid\Column|Collection is_show + * @property Grid\Column|Collection key + * @property Grid\Column|Collection updated_at + * @property Grid\Column|Collection detail + * @property Grid\Column|Collection name + * @property Grid\Column|Collection type + * @property Grid\Column|Collection version + * @property Grid\Column|Collection is_enabled + * @property Grid\Column|Collection extension + * @property Grid\Column|Collection icon + * @property Grid\Column|Collection order + * @property Grid\Column|Collection parent_id + * @property Grid\Column|Collection uri + * @property Grid\Column|Collection menu_id + * @property Grid\Column|Collection permission_id + * @property Grid\Column|Collection http_method + * @property Grid\Column|Collection http_path + * @property Grid\Column|Collection slug + * @property Grid\Column|Collection role_id + * @property Grid\Column|Collection user_id + * @property Grid\Column|Collection value + * @property Grid\Column|Collection avatar + * @property Grid\Column|Collection password + * @property Grid\Column|Collection remember_token + * @property Grid\Column|Collection username + * @property Grid\Column|Collection address_id + * @property Grid\Column|Collection jump_link + * @property Grid\Column|Collection jump_type + * @property Grid\Column|Collection sort + * @property Grid\Column|Collection src_path + * @property Grid\Column|Collection connection + * @property Grid\Column|Collection exception + * @property Grid\Column|Collection failed_at + * @property Grid\Column|Collection payload + * @property Grid\Column|Collection queue + * @property Grid\Column|Collection uuid + * + * @method Grid\Column|Collection created_at(string $label = null) + * @method Grid\Column|Collection dimensions(string $label = null) + * @method Grid\Column|Collection id(string $label = null) + * @method Grid\Column|Collection is_show(string $label = null) + * @method Grid\Column|Collection key(string $label = null) + * @method Grid\Column|Collection updated_at(string $label = null) + * @method Grid\Column|Collection detail(string $label = null) + * @method Grid\Column|Collection name(string $label = null) + * @method Grid\Column|Collection type(string $label = null) + * @method Grid\Column|Collection version(string $label = null) + * @method Grid\Column|Collection is_enabled(string $label = null) + * @method Grid\Column|Collection extension(string $label = null) + * @method Grid\Column|Collection icon(string $label = null) + * @method Grid\Column|Collection order(string $label = null) + * @method Grid\Column|Collection parent_id(string $label = null) + * @method Grid\Column|Collection uri(string $label = null) + * @method Grid\Column|Collection menu_id(string $label = null) + * @method Grid\Column|Collection permission_id(string $label = null) + * @method Grid\Column|Collection http_method(string $label = null) + * @method Grid\Column|Collection http_path(string $label = null) + * @method Grid\Column|Collection slug(string $label = null) + * @method Grid\Column|Collection role_id(string $label = null) + * @method Grid\Column|Collection user_id(string $label = null) + * @method Grid\Column|Collection value(string $label = null) + * @method Grid\Column|Collection avatar(string $label = null) + * @method Grid\Column|Collection password(string $label = null) + * @method Grid\Column|Collection remember_token(string $label = null) + * @method Grid\Column|Collection username(string $label = null) + * @method Grid\Column|Collection address_id(string $label = null) + * @method Grid\Column|Collection jump_link(string $label = null) + * @method Grid\Column|Collection jump_type(string $label = null) + * @method Grid\Column|Collection sort(string $label = null) + * @method Grid\Column|Collection src_path(string $label = null) + * @method Grid\Column|Collection connection(string $label = null) + * @method Grid\Column|Collection exception(string $label = null) + * @method Grid\Column|Collection failed_at(string $label = null) + * @method Grid\Column|Collection payload(string $label = null) + * @method Grid\Column|Collection queue(string $label = null) + * @method Grid\Column|Collection uuid(string $label = null) + */ + class Grid {} + + class MiniGrid extends Grid {} + + /** + * @property Show\Field|Collection created_at + * @property Show\Field|Collection dimensions + * @property Show\Field|Collection id + * @property Show\Field|Collection is_show + * @property Show\Field|Collection key + * @property Show\Field|Collection updated_at + * @property Show\Field|Collection detail + * @property Show\Field|Collection name + * @property Show\Field|Collection type + * @property Show\Field|Collection version + * @property Show\Field|Collection is_enabled + * @property Show\Field|Collection extension + * @property Show\Field|Collection icon + * @property Show\Field|Collection order + * @property Show\Field|Collection parent_id + * @property Show\Field|Collection uri + * @property Show\Field|Collection menu_id + * @property Show\Field|Collection permission_id + * @property Show\Field|Collection http_method + * @property Show\Field|Collection http_path + * @property Show\Field|Collection slug + * @property Show\Field|Collection role_id + * @property Show\Field|Collection user_id + * @property Show\Field|Collection value + * @property Show\Field|Collection avatar + * @property Show\Field|Collection password + * @property Show\Field|Collection remember_token + * @property Show\Field|Collection username + * @property Show\Field|Collection address_id + * @property Show\Field|Collection jump_link + * @property Show\Field|Collection jump_type + * @property Show\Field|Collection sort + * @property Show\Field|Collection src_path + * @property Show\Field|Collection connection + * @property Show\Field|Collection exception + * @property Show\Field|Collection failed_at + * @property Show\Field|Collection payload + * @property Show\Field|Collection queue + * @property Show\Field|Collection uuid + * + * @method Show\Field|Collection created_at(string $label = null) + * @method Show\Field|Collection dimensions(string $label = null) + * @method Show\Field|Collection id(string $label = null) + * @method Show\Field|Collection is_show(string $label = null) + * @method Show\Field|Collection key(string $label = null) + * @method Show\Field|Collection updated_at(string $label = null) + * @method Show\Field|Collection detail(string $label = null) + * @method Show\Field|Collection name(string $label = null) + * @method Show\Field|Collection type(string $label = null) + * @method Show\Field|Collection version(string $label = null) + * @method Show\Field|Collection is_enabled(string $label = null) + * @method Show\Field|Collection extension(string $label = null) + * @method Show\Field|Collection icon(string $label = null) + * @method Show\Field|Collection order(string $label = null) + * @method Show\Field|Collection parent_id(string $label = null) + * @method Show\Field|Collection uri(string $label = null) + * @method Show\Field|Collection menu_id(string $label = null) + * @method Show\Field|Collection permission_id(string $label = null) + * @method Show\Field|Collection http_method(string $label = null) + * @method Show\Field|Collection http_path(string $label = null) + * @method Show\Field|Collection slug(string $label = null) + * @method Show\Field|Collection role_id(string $label = null) + * @method Show\Field|Collection user_id(string $label = null) + * @method Show\Field|Collection value(string $label = null) + * @method Show\Field|Collection avatar(string $label = null) + * @method Show\Field|Collection password(string $label = null) + * @method Show\Field|Collection remember_token(string $label = null) + * @method Show\Field|Collection username(string $label = null) + * @method Show\Field|Collection address_id(string $label = null) + * @method Show\Field|Collection jump_link(string $label = null) + * @method Show\Field|Collection jump_type(string $label = null) + * @method Show\Field|Collection sort(string $label = null) + * @method Show\Field|Collection src_path(string $label = null) + * @method Show\Field|Collection connection(string $label = null) + * @method Show\Field|Collection exception(string $label = null) + * @method Show\Field|Collection failed_at(string $label = null) + * @method Show\Field|Collection payload(string $label = null) + * @method Show\Field|Collection queue(string $label = null) + * @method Show\Field|Collection uuid(string $label = null) + */ + class Show {} + + /** + + */ + class Form {} + +} + +namespace Dcat\Admin\Grid { + /** + + */ + class Column {} + + /** + + */ + class Filter {} +} + +namespace Dcat\Admin\Show { + /** + + */ + class Field {} +} diff --git a/resources/lang/zh_CN/ad-address.php b/resources/lang/zh_CN/ad-address.php new file mode 100644 index 00000000..af383811 --- /dev/null +++ b/resources/lang/zh_CN/ad-address.php @@ -0,0 +1,18 @@ + [ + 'AdAddress' => '广告位', + 'ad-addresses' => '广告位', + ], + 'fields' => [ + 'key' => 'KEY', + 'name' => '名称', + 'dimensions' => '宽高', + 'width'=>'宽', + 'hight'=>'高', + 'is_show' => '显示', + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh_CN/ad.php b/resources/lang/zh_CN/ad.php new file mode 100644 index 00000000..17fa2c46 --- /dev/null +++ b/resources/lang/zh_CN/ad.php @@ -0,0 +1,21 @@ + [ + 'Ad' => '广告', + 'ad' => '广告', + ], + 'fields' => [ + 'address_id' => '广告位', + 'src_path' => '图片地址', + 'sort' => '广告排序', + 'jump_type' => '跳转类型', + 'jump_link' => '跳转地址', + 'is_show' => '显示', + 'address'=>[ + 'name'=>'广告位', + ], + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh_CN/admin_message.php b/resources/lang/zh_CN/admin_message.php new file mode 100644 index 00000000..1a2a5295 --- /dev/null +++ b/resources/lang/zh_CN/admin_message.php @@ -0,0 +1,18 @@ +[ + 'dimensions'=>[ + 'help'=>'请输入:宽*高', + ], + ], + 'ad'=>[ + 'jump_type'=>[ + 'radio'=>[ + '0'=>'无跳转', + '1'=>'跳转应用内页', + '2'=>'跳转外部网页', + ], + ], + ], +];