From 3532b1a136bfcd08b4e73305106f38e58cf3fa12 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Thu, 25 Nov 2021 09:48:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=9A=E8=BF=87=E5=B9=BF?= =?UTF-8?q?=E5=91=8A=E4=BD=8D=E8=8E=B7=E5=8F=96=E5=B9=BF=E5=91=8A=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/AdController.php | 6 +-- app/Admin/Controllers/ArticleController.php | 6 +-- app/Admin/bootstrap.php | 2 +- app/Http/Controllers/Api/V1/AdController.php | 26 ++++++++++ app/Http/Resources/AdAddressResource.php | 22 ++++++++ app/Http/Resources/AdResource.php | 23 +++++++++ app/Models/AdAddress.php | 5 ++ app/Providers/AppServiceProvider.php | 2 + .../2021_11_18_135133_create_ads_table.php | 2 +- ...021_11_19_143916_create_articles_table.php | 2 +- ...105141_create_product_categories_table.php | 36 +++++++++++++ ...11_22_110044_create_product_spus_table.php | 44 ++++++++++++++++ ...1_24_110051_create_product_specs_table.php | 33 ++++++++++++ ..._115822_create_product_spu_specs_table.php | 39 +++++++++++++++ ...11_24_120232_create_product_skus_table.php | 50 +++++++++++++++++++ public/{ => dist}/admin/css/app.css | 0 resources/lang/zh_CN/ad.php | 2 +- resources/lang/zh_CN/article.php | 2 +- routes/api/v1/common.php | 2 + 19 files changed, 293 insertions(+), 11 deletions(-) create mode 100644 app/Http/Controllers/Api/V1/AdController.php create mode 100644 app/Http/Resources/AdAddressResource.php create mode 100644 app/Http/Resources/AdResource.php create mode 100644 database/migrations/2021_11_22_105141_create_product_categories_table.php create mode 100644 database/migrations/2021_11_22_110044_create_product_spus_table.php create mode 100644 database/migrations/2021_11_24_110051_create_product_specs_table.php create mode 100644 database/migrations/2021_11_24_115822_create_product_spu_specs_table.php create mode 100644 database/migrations/2021_11_24_120232_create_product_skus_table.php rename public/{ => dist}/admin/css/app.css (100%) diff --git a/app/Admin/Controllers/AdController.php b/app/Admin/Controllers/AdController.php index a27c019f..65ec3e64 100644 --- a/app/Admin/Controllers/AdController.php +++ b/app/Admin/Controllers/AdController.php @@ -25,7 +25,7 @@ class AdController extends AdminController return Grid::make($builder, function (Grid $grid) { $grid->column('id')->sortable(); $grid->column('address.name'); - $grid->column('src_path')->image(50, 100); + $grid->column('image')->image(50, 100); $grid->column('sort'); $grid->column('jump_type')->using([ '0'=>__('admin_message.ad.jump_type.radio.0'), @@ -81,7 +81,7 @@ class AdController extends AdminController return Show::make($id, new Ad(), function (Show $show) { $show->field('id'); $show->field('address_id'); - $show->field('src_path'); + $show->field('image'); $show->field('sort'); $show->field('jump_type'); $show->field('jump_link'); @@ -101,7 +101,7 @@ class AdController extends AdminController 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') + $form->image('image') ->move('ads/'.Carbon::now()->toDateString()) ->saveFullUrl() ->removable(false) diff --git a/app/Admin/Controllers/ArticleController.php b/app/Admin/Controllers/ArticleController.php index 1b5b4b0c..bd55effc 100644 --- a/app/Admin/Controllers/ArticleController.php +++ b/app/Admin/Controllers/ArticleController.php @@ -28,7 +28,7 @@ class ArticleController extends AdminController $grid->column('category.name')->label(); // $grid->column('author_name'); $grid->column('subtitle')->limit(20); - $grid->column('cover_src_path')->images(100, 100); + $grid->column('cover')->images(100, 100); $grid->column('jump_type')->using([ '0'=>__('admin_message.article.jump_type.radio.0'), '1'=>__('admin_message.article.jump_type.radio.1'), @@ -99,7 +99,7 @@ class ArticleController extends AdminController $show->field('title'); $show->field('author_name'); $show->field('subtitle'); - $show->field('cover_src_path'); + $show->field('cover'); $show->field('content'); $show->field('jump_type'); $show->field('jump_link'); @@ -121,7 +121,7 @@ class ArticleController extends AdminController $form->text('title')->required(); // $form->text('author_name'); $form->text('subtitle'); - $form->image('cover_src_path') + $form->image('cover') ->move('articles/'.Carbon::now()->toDateString()) ->saveFullUrl() ->removable(false) diff --git a/app/Admin/bootstrap.php b/app/Admin/bootstrap.php index 4a796fb9..a5f039cf 100644 --- a/app/Admin/bootstrap.php +++ b/app/Admin/bootstrap.php @@ -24,7 +24,7 @@ use Dcat\Admin\Grid; * */ -Admin::css('/admin/css/app.css'); +Admin::css('/dist/admin/css/app.css'); Grid::resolving(function (Grid $grid) { $grid->disableRowSelector(); diff --git a/app/Http/Controllers/Api/V1/AdController.php b/app/Http/Controllers/Api/V1/AdController.php new file mode 100644 index 00000000..fcd4b395 --- /dev/null +++ b/app/Http/Controllers/Api/V1/AdController.php @@ -0,0 +1,26 @@ +input('address_key'); + + $list = AdAddress::with(['ads'=>function ($query) { + $query->where('is_show', 1)->orderBy('sort', 'desc'); + }])->where('is_show', 1)->whereIn('key', $addreseKeys)->get(); + + $data = []; + foreach ($addreseKeys as $key) { + $data[$key] = []; + } + $data = array_merge($data, array_column(AdAddressResource::collection($list)->toArray($request), 'ads', 'key')); + return $data; + } +} diff --git a/app/Http/Resources/AdAddressResource.php b/app/Http/Resources/AdAddressResource.php new file mode 100644 index 00000000..fb5c31d2 --- /dev/null +++ b/app/Http/Resources/AdAddressResource.php @@ -0,0 +1,22 @@ + $this->key, + 'ads' => AdResource::collection($this->ads), + ]; + } +} diff --git a/app/Http/Resources/AdResource.php b/app/Http/Resources/AdResource.php new file mode 100644 index 00000000..5035e57b --- /dev/null +++ b/app/Http/Resources/AdResource.php @@ -0,0 +1,23 @@ +$this->image, + 'jump_type'=>$this->jump_type, + 'jump_link'=>$this->jump_link ?: '', + ]; + } +} diff --git a/app/Models/AdAddress.php b/app/Models/AdAddress.php index c61a3b8e..a4f2317a 100644 --- a/app/Models/AdAddress.php +++ b/app/Models/AdAddress.php @@ -14,4 +14,9 @@ class AdAddress extends Model protected $casts = [ 'is_show' => 'boolean', ]; + + public function ads() + { + return $this->hasMany(Ad::class, 'address_id'); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 86af802a..fabfc2a8 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Http\Request; +use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\ServiceProvider; use Overtrue\EasySms\EasySms; @@ -18,6 +19,7 @@ class AppServiceProvider extends ServiceProvider { $this->registerEasySms(); $this->registerRequestRealIp(); + JsonResource::withoutWrapping(); } /** diff --git a/database/migrations/2021_11_18_135133_create_ads_table.php b/database/migrations/2021_11_18_135133_create_ads_table.php index 9b29eadf..dfb00fc1 100644 --- a/database/migrations/2021_11_18_135133_create_ads_table.php +++ b/database/migrations/2021_11_18_135133_create_ads_table.php @@ -25,7 +25,7 @@ class CreateAdsTable extends Migration Schema::create('ads', function (Blueprint $table) { $table->id(); $table->bigInteger('address_id')->default(0)->comment('广告位ID'); - $table->string('src_path')->nullable()->comment('图片地址'); + $table->string('image')->nullable()->comment('图片地址'); $table->integer('sort')->default(0)->comment('广告排序:逆序'); $table->tinyInteger('jump_type')->default(0)->comment('跳转类型:0不跳转,1跳转应用内页,2H5链接'); $table->string('jump_link')->nullable()->comment('跳转地址'); diff --git a/database/migrations/2021_11_19_143916_create_articles_table.php b/database/migrations/2021_11_19_143916_create_articles_table.php index 806ff377..4ecc4022 100644 --- a/database/migrations/2021_11_19_143916_create_articles_table.php +++ b/database/migrations/2021_11_19_143916_create_articles_table.php @@ -19,7 +19,7 @@ class CreateArticlesTable extends Migration $table->string('title')->comment('文章标题'); $table->string('author_name')->nullable()->comment('作者名称'); $table->string('subtitle')->nullable()->comment('副标题'); - $table->string('cover_src_path')->nullable()->comment('文章封面图'); + $table->string('cover')->nullable()->comment('文章封面图'); $table->text('content')->nullable()->comment('文章内容'); $table->tinyInteger('jump_type')->default(0)->comment('跳转类型:0不跳转,1跳转应用内页,2H5链接'); $table->string('jump_link')->nullable()->comment('跳转地址'); diff --git a/database/migrations/2021_11_22_105141_create_product_categories_table.php b/database/migrations/2021_11_22_105141_create_product_categories_table.php new file mode 100644 index 00000000..d694047d --- /dev/null +++ b/database/migrations/2021_11_22_105141_create_product_categories_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('name')->comment('分类名称'); + $table->string('icon')->nullable()->comment('分类ICON'); + $table->tinyInteger('is_show')->default(0)->comment('是否显示:0不显示,1显示'); + $table->integer('sort')->default(0)->comment('排序'); + $table->nestedSet(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('product_categories'); + } +} diff --git a/database/migrations/2021_11_22_110044_create_product_spus_table.php b/database/migrations/2021_11_22_110044_create_product_spus_table.php new file mode 100644 index 00000000..f9fad1e4 --- /dev/null +++ b/database/migrations/2021_11_22_110044_create_product_spus_table.php @@ -0,0 +1,44 @@ +id(); + $table->string('name')->comment('商品名称'); + $table->string('subtitle')->nullable()->comment('商品副标题'); + $table->string('cover')->nullable()->comment('封面图'); + $table->json('images')->nullable()->comment('商品图片'); + $table->text('description')->nullable()->comment('商品详情'); + $table->bigInteger('sell_price')->unsigned()->default(0)->comment('销售价格:分'); + $table->bigInteger('market_price')->unsigned()->default(0)->comment('市场价格:分'); + $table->bigInteger('cost_price')->unsigned()->default(0)->comment('成本价格:分'); + $table->bigInteger('user_price')->unsigned()->default(0)->comment('会员价格:分'); + $table->string('media')->nullable()->comment('媒体地址'); + $table->integer('weight')->unsigned()->nullable()->comment('重量:g'); + $table->json('attrs')->nullable()->comment('属性文本'); + $table->tinyInteger('is_sell')->unsigned()->default(0)->comment('在售状态'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('product_spus'); + } +} diff --git a/database/migrations/2021_11_24_110051_create_product_specs_table.php b/database/migrations/2021_11_24_110051_create_product_specs_table.php new file mode 100644 index 00000000..07ad84d5 --- /dev/null +++ b/database/migrations/2021_11_24_110051_create_product_specs_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('name')->column('规格名称'); + $table->json('items')->nullable()->comment('规格可选值'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('product_specs'); + } +} diff --git a/database/migrations/2021_11_24_115822_create_product_spu_specs_table.php b/database/migrations/2021_11_24_115822_create_product_spu_specs_table.php new file mode 100644 index 00000000..9e8604d4 --- /dev/null +++ b/database/migrations/2021_11_24_115822_create_product_spu_specs_table.php @@ -0,0 +1,39 @@ +id(); + $table->unsignedBigInteger('product_spu_id')->comment('商品主ID'); + $table->string('name')->column('规格名称'); + /** + * [ + * {"value":"值","price":"10000"} + * ] + */ + $table->json('items')->nullable()->comment('规格值'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('product_spu_specs'); + } +} diff --git a/database/migrations/2021_11_24_120232_create_product_skus_table.php b/database/migrations/2021_11_24_120232_create_product_skus_table.php new file mode 100644 index 00000000..f4b995fe --- /dev/null +++ b/database/migrations/2021_11_24_120232_create_product_skus_table.php @@ -0,0 +1,50 @@ +id(); + $table->unsignedBigInteger('spu_id')->comment('主商品ID'); + $table->string('name')->comment('商品名称'); + $table->string('subtitle')->nullable()->comment('商品副标题'); + $table->string('cover')->nullable()->comment('封面图'); + $table->json('images')->nullable()->comment('商品图片'); + $table->text('description')->nullable()->comment('商品详情'); + $table->bigInteger('sell_price')->unsigned()->default(0)->comment('销售价格:分'); + $table->bigInteger('market_price')->unsigned()->default(0)->comment('市场价格:分'); + $table->bigInteger('cost_price')->unsigned()->default(0)->comment('成本价格:分'); + $table->bigInteger('user_price')->unsigned()->default(0)->comment('会员价格:分'); + $table->string('media')->nullable()->comment('媒体地址'); + $table->integer('weight')->unsigned()->nullable()->comment('重量:g'); + $table->json('attrs')->nullable()->comment('属性文本'); + $table->tinyInteger('is_sell')->unsigned()->default(0)->comment('在售状态'); + $table->json('spec_items')->nullable()->comment('规格属性'); + $table->integer('stock')->unsigned()->default(0)->comment('库存'); + $table->integer('sells')->unsigned()->default(0)->comment('销量'); + $table->timestamps(); + + $table->index('spu_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('product_skus'); + } +} diff --git a/public/admin/css/app.css b/public/dist/admin/css/app.css similarity index 100% rename from public/admin/css/app.css rename to public/dist/admin/css/app.css diff --git a/resources/lang/zh_CN/ad.php b/resources/lang/zh_CN/ad.php index 17fa2c46..c599f118 100644 --- a/resources/lang/zh_CN/ad.php +++ b/resources/lang/zh_CN/ad.php @@ -7,7 +7,7 @@ return [ ], 'fields' => [ 'address_id' => '广告位', - 'src_path' => '图片地址', + 'image' => '图片地址', 'sort' => '广告排序', 'jump_type' => '跳转类型', 'jump_link' => '跳转地址', diff --git a/resources/lang/zh_CN/article.php b/resources/lang/zh_CN/article.php index d45e6b31..15c9ec17 100644 --- a/resources/lang/zh_CN/article.php +++ b/resources/lang/zh_CN/article.php @@ -10,7 +10,7 @@ return [ 'title' => '文章标题', 'author_name' => '作者名称', 'subtitle' => '副标题', - 'cover_src_path' => '文章封面图', + 'cover' => '文章封面图', 'content' => '文章内容', 'jump_type' => '跳转类型', 'jump_link' => '跳转地址', diff --git a/routes/api/v1/common.php b/routes/api/v1/common.php index e1d8ea9a..5e5d30cc 100644 --- a/routes/api/v1/common.php +++ b/routes/api/v1/common.php @@ -1,5 +1,6 @@