kphcdr 1 rok pred
rodič
commit
02f2349c5a

+ 18 - 0
app/Models/Goods/Category.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Models\Goods;
+
+use App\Base\BaseModel;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class Category extends BaseModel
+{
+    use SoftDeletes;
+
+    protected $table = "category";
+
+    public function format(...$options)
+    {
+
+    }
+}

+ 23 - 0
app/Models/Goods/Goods.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Models\Goods;
+
+use App\Base\BaseModel;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class Goods extends BaseModel
+{
+    use SoftDeletes;
+
+    protected $table = "goods";
+
+    protected $casts = [
+        "image_list" => "array",
+        "spec" => "array",
+    ];
+
+    public function format(...$options)
+    {
+
+    }
+}

+ 16 - 0
app/Models/Goods/GoodsCategoryMap.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Models\Goods;
+
+use App\Base\BaseModel;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class GoodsCategoryMap extends BaseModel
+{
+    protected $table = "goods_category_map";
+
+    public function format(...$options)
+    {
+
+    }
+}

+ 22 - 0
app/Models/Goods/GoodsSku.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models\Goods;
+
+use App\Base\BaseModel;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class GoodsSku extends BaseModel
+{
+    use SoftDeletes;
+
+    protected $table = "goods_sku";
+
+    protected $casts = [
+        "spec_attr_list" => "array",
+    ];
+
+    public function format(...$options)
+    {
+
+    }
+}

+ 2 - 2
app/Modules/Admin/Controllers/Admin/GoodsController.php

@@ -83,8 +83,8 @@ class GoodsController extends BaseController
         return $this->ok([
             "id" => 1,
             "image_list" => [
-                Image::image(),
-                Image::image(),
+                Image::imageUrl(),
+                Image::imageUrl(),
             ],
             "category" => [
                 [

+ 53 - 0
database/migrations/2023_04_28_071852_create_goods_table.php

@@ -30,6 +30,55 @@ return new class extends Migration {
             $t->timestamps();
             $t->softDeletes();
         });
+
+        Schema::create('category', function (Blueprint $table) {
+            $table->id();
+            $table->string("name")->default("");
+            $table->string("thumb")->default("");
+            $table->unsignedTinyInteger("level")->default(0)->comment("层级");
+            $table->unsignedInteger("parent_id")->default(0)->comment("上级分类ID");
+            $table->integer("weight")->default(0)->comment("权重");
+            $table->integer("index_weight")->default(0)->comment("推荐位权重");
+            $table->integer("category_weight")->default(0)->comment("推荐位权重");
+            $table->integer("search_weight")->default(0)->comment("搜索页权重");
+            $table->timestamps();
+            $table->softDeletes();
+        });
+
+        Schema::create('goods', function (Blueprint $table) {
+            $table->id();
+            $table->string("name")->default("");
+            $table->string("image_list", 2000)->default("");
+            $table->string("spec")->default("")->comment("商品的规格");
+            $table->unsignedInteger("weight")->default(0);
+            $table->text("desc_html")->nullable();
+            $table->text("spec_attr_html")->nullable();
+            $table->text("faq_html")->nullable();
+            $table->timestamps();
+            $table->softDeletes();
+        });
+
+        Schema::create('goods_category_map', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedInteger("goods_id")->default(0);
+            $table->unsignedInteger("category_id")->default(0);
+            $table->unsignedTinyInteger("is_public")->default(1)->comment("是否对普通会员展示");
+            $table->timestamps();
+        });
+
+        Schema::create('goods_sku', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedInteger("goods_id")->default(0);
+            $table->string("sn")->default("")->comment("型号");
+            $table->string("3d_url")->default("")->comment("3D的跳转地址");
+            $table->string("spec_attr_list", 2000)->default("")->comment("规格数据");
+            $table->unsignedTinyInteger("is_use")->default(1)->comment("是否使用");
+            $table->timestamps();
+            $table->softDeletes();
+
+            $table->index("goods_id");
+        });
+
     }
 
     /**
@@ -41,5 +90,9 @@ return new class extends Migration {
     {
         Schema::dropIfExists('spec');
         Schema::dropIfExists('spec_attr');
+        Schema::dropIfExists('category');
+        Schema::dropIfExists('goods');
+        Schema::dropIfExists('goods_category_map');
+        Schema::dropIfExists('goods_sku');
     }
 };

+ 36 - 0
database/seeders/DatabaseSeeder.php

@@ -5,9 +5,17 @@ namespace Database\Seeders;
 // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
 use App\Models\Auth\AdminGroup;
 use App\Models\Auth\AdminPermission;
+use App\Models\Goods\Category;
+use App\Models\Goods\Goods;
+use App\Models\Goods\GoodsCategoryMap;
+use App\Models\Goods\GoodsSku;
+use App\Models\Goods\Spec;
+use App\Models\Goods\SpecAttr;
 use App\Models\Setting;
 use App\Models\User\User;
 use App\Models\User\UserCompany;
+use Faker\Provider\Image;
+use Faker\Provider\Text;
 use Illuminate\Database\Seeder;
 use Illuminate\Support\Facades\DB;
 
@@ -52,6 +60,34 @@ class DatabaseSeeder extends Seeder
             "key" => "hot_keyword",
             "value" => ["热搜词1", "热搜词2"],
         ]);
+
+        $this->goods();
+    }
+
+    public function goods()
+    {
+        Spec::truncate();
+        SpecAttr::truncate();
+        Category::truncate();
+        Goods::truncate();
+        GoodsCategoryMap::truncate();
+        GoodsSku::truncate();
+
+        Spec::create(["name" => "颜色"]);
+        Spec::create(["name" => "大小"]);
+        SpecAttr::create(["spec_id" => 1, "name" => "红色"]);
+        SpecAttr::create(["spec_id" => 1, "name" => "白色"]);
+        SpecAttr::create(["spec_id" => 2, "name" => "大号"]);
+        SpecAttr::create(["spec_id" => 2, "name" => "小号"]);
+        Category::create(["name" => "一级分类", "thumb" => Image::imageUrl(300, 300), "level" => 1, "parent_id" => 0]);
+        Category::create(["name" => "一级分类", "thumb" => Image::imageUrl(300, 300), "level" => 2, "parent_id" => 1]);
+        Goods::create(["name" => "测试商品", "image_list" => [Image::imageUrl(), Image::imageUrl()], "spec" => [1, 2]]);
+        GoodsCategoryMap::create(["goods_id" => 1, "category_id" => 2]);
+        GoodsSku::create(["goods_id" => 1, "sn" => substr(md5(microtime()), 0, 6), "spec_attr_list" => [1, 3]]);
+        GoodsSku::create(["goods_id" => 1, "sn" => substr(md5(microtime()), 0, 6), "spec_attr_list" => [1, 4]]);
+        GoodsSku::create(["goods_id" => 1, "sn" => substr(md5(microtime()), 0, 6), "spec_attr_list" => [2, 3]]);
+        GoodsSku::create(["goods_id" => 1, "sn" => substr(md5(microtime()), 0, 6), "spec_attr_list" => [2, 4]]);
+
     }
 
     public function company()