Parcourir la source

增加英文支持

kphcdr il y a 1 an
Parent
commit
444b4ba623

+ 1 - 0
app/Models/Cart.php

@@ -30,6 +30,7 @@ use Illuminate\Support\Arr;
  * @property-read mixed                      $goods_name
  * @property-read mixed                      $sn
  * @property-read mixed                      $custom
+ * @property-read mixed                      $sku_id
  */
 class Cart extends BaseModel
 {

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

@@ -45,6 +45,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
  * @property-read int|null                                                                      $child_s_count
  * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Goods\GoodsCategoryMap[] $gcMap
  * @property-read int|null                                                                      $gc_map_count
+ * @property string                                                                             $en_name
+ * @method static \Illuminate\Database\Eloquent\Builder|Category whereEnName($value)
  */
 class Category extends BaseModel
 {
@@ -58,6 +60,7 @@ class Category extends BaseModel
         $return = [
             "id" => $this->id,
             "name" => $this->name,
+            "en_name" => $this->en_name,
             "thumb" => $this->thumb,
             "level" => $this->level,
             "parent_id" => optional($this->parent)->id ?? 0,

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

@@ -55,6 +55,8 @@ use Illuminate\Support\Arr;
  * @property-read int|null                                                                      $spec_map_count
  * @property array                                                                              $custom
  * @method static \Illuminate\Database\Eloquent\Builder|Goods whereCustom($value)
+ * @property string                                                                             $en_name
+ * @method static \Illuminate\Database\Eloquent\Builder|Goods whereEnName($value)
  */
 class Goods extends BaseModel
 {

+ 2 - 0
app/Models/Goods/GoodsCustom.php

@@ -20,6 +20,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
  * @method static \Illuminate\Database\Eloquent\Builder|GoodsCustom whereTitle($value)
  * @method static \Illuminate\Database\Eloquent\Builder|GoodsCustom whereUpdatedAt($value)
  * @mixin \Eloquent
+ * @property string                          $en_title
+ * @method static \Illuminate\Database\Eloquent\Builder|GoodsCustom whereEnTitle($value)
  */
 class GoodsCustom extends BaseModel
 {

+ 3 - 0
app/Models/Goods/Spec.php

@@ -38,6 +38,8 @@ use Illuminate\Support\Arr;
  * @method static \Illuminate\Database\Query\Builder|Spec withTrashed()
  * @method static \Illuminate\Database\Query\Builder|Spec withoutTrashed()
  * @mixin \Eloquent
+ * @property string                                                                     $en_name
+ * @method static \Illuminate\Database\Eloquent\Builder|Spec whereEnName($value)
  */
 class Spec extends BaseModel
 {
@@ -56,6 +58,7 @@ class Spec extends BaseModel
         $return = [
             "id" => $this->id,
             "name" => $this->name,
+            "en_name" => $this->en_name,
             "is_custom" => (bool)$this->is_custom,
             "index_weight" => $this->index_weight,
             "category_weight" => $this->category_weight,

+ 1 - 18
app/Modules/Admin/Controllers/Admin/CategoryController.php

@@ -27,29 +27,12 @@ class CategoryController extends BaseController
         return $this->ok($this->service->paginate($params));
     }
 
-    protected function mockCategory()
-    {
-        return [
-            "id" => 1,
-            "name" => "分类名称",
-            "thumb" => "xx" . Image::imageUrl(),
-            "level" => 1,
-            "parent_id" => 1,
-            "parent_name" => "上级名称",
-            "child_category_count" => 1,
-            "child_goods_count" => 1,
-            "weight" => 1,
-            "index_weight" => 1,
-            "category_weight" => 1,
-            "search_weight" => 1,
-        ];
-    }
-
     public function store()
     {
         $params = $this->valid([
             "id" => "int",
             "name" => "required|max:255",
+            "en_name" => "max:255",
             "thumb" => "url",
             "weight" => "int",
             "parent_id" => "int",

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

@@ -67,6 +67,7 @@ class GoodsController extends BaseController
         $params = $this->valid([
             "id" => "",
             "name" => "required|max:50",
+            "en_name" => "max:255",
             "image_list" => "required|array",
             "category" => "required|array",
             "spec" => 'array',
@@ -98,6 +99,7 @@ class GoodsController extends BaseController
         $params = $this->valid([
             "id" => "",
             "name" => "required",
+            "en_name" => "",
             "attr" => "array",
             "index_weight" => "int",
             "category_weight" => "int",

+ 2 - 0
app/Modules/Admin/Services/CategoryService.php

@@ -29,6 +29,7 @@ class CategoryService extends BaseService
                 return [
                     "id" => $model->id,
                     "name" => $model->name,
+                    "en_name" => $model->en_name,
                     "thumb" => $model->thumb,
                     "level" => $model->level,
                     "parent_id" => optional($model->parent)->id ?? 0,
@@ -54,6 +55,7 @@ class CategoryService extends BaseService
             $model = new Category();
         }
         $model->name = Arr::get($params, 'name');
+        $model->en_name = Arr::get($params, 'en_name');
         $model->thumb = Arr::get($params, 'thumb');
         $model->index_weight = Arr::get($params, 'index_weight');
         $model->category_weight = Arr::get($params, 'category_weight');

+ 5 - 0
app/Modules/Admin/Services/GoodsService.php

@@ -32,6 +32,7 @@ class GoodsService extends BaseService
                 return [
                     "id" => $model->id,
                     "name" => $model->name,
+                    "en_name" => $model->en_name,
                     "thumb" => Arr::first($model->image_list),
                     "weight" => $model->weight,
                     "status" => $model->status,
@@ -57,6 +58,7 @@ class GoodsService extends BaseService
             $goods->url_3d = $params['url_3d'] ?? "";
             $goods->spec = $specIdArr;
             $goods->name = Arr::get($params, "name", []);
+            $goods->en_name = Arr::get($params, "en_name", []);
             $goods->weight = Arr::get($params, "weight", 0);
             $goods->desc_html = Arr::get($params, "desc_html", "");
             $goods->spec_attr_html = Arr::get($params, "spec_attr_html", "");
@@ -108,12 +110,14 @@ class GoodsService extends BaseService
         $return = [
             "id" => $model->id,
             "name" => $model->name,
+            "en_name" => $model->en_name,
             "image_list" => $model->image_list,
             "category" => $model->map->map(function (GoodsCategoryMap $map) {
                 return [
                     "id" => $map->category->id,
                     "is_public" => $map->is_public,
                     "name" => $map->category->name,
+                    "en_name" => $map->category->en_name,
                 ];
             }),
             "spec" => $model->spec,
@@ -130,6 +134,7 @@ class GoodsService extends BaseService
                     "spec_id" => $map->spec_id,
                     "value" => $map->value,
                     "name" => $map->spec->name,
+                    "en_name" => $map->spec->en_name,
                 ];
             }),
             "custom" => $model->custom,

+ 1 - 0
app/Modules/Admin/Services/SpecService.php

@@ -37,6 +37,7 @@ class SpecService extends BaseService
             $spec = new Spec();
         }
         $spec->name = Arr::get($params, 'name');
+        $spec->en_name = Arr::get($params, 'en_name');
         $spec->index_weight = Arr::get($params, 'index_weight');
         $spec->category_weight = Arr::get($params, 'category_weight');
         $spec->search_weight = Arr::get($params, 'search_weight');

+ 49 - 0
database/migrations/2023_05_29_111422_add_en_lng_sup.php

@@ -0,0 +1,49 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table("goods", function (Blueprint $t) {
+            $t->string("en_name")->default("");
+        });
+        Schema::table("goods_custom", function (Blueprint $t) {
+            $t->string("en_title")->default("");
+        });
+        Schema::table("category", function (Blueprint $t) {
+            $t->string("en_name")->default("");
+        });
+        Schema::table("spec", function (Blueprint $t) {
+            $t->string("en_name")->default("");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table("goods", function (Blueprint $t) {
+            $t->dropColumn("en_name");
+        });
+        Schema::table("goods_custom", function (Blueprint $t) {
+            $t->dropColumn("en_title");
+        });
+        Schema::table("category", function (Blueprint $t) {
+            $t->dropColumn("en_name");
+        });
+        Schema::table("spec", function (Blueprint $t) {
+            $t->dropColumn("en_name");
+        });
+    }
+};