kphcdr 1 year ago
parent
commit
99f2daa48b
2 changed files with 15 additions and 3 deletions
  1. 11 0
      app/Console/Commands/TestCommand.php
  2. 4 3
      app/Modules/Admin/Services/GoodsService.php

+ 11 - 0
app/Console/Commands/TestCommand.php

@@ -2,6 +2,7 @@
 
 namespace App\Console\Commands;
 
+use App\Models\Goods\GoodsSku;
 use Illuminate\Console\Command;
 use Nerd\CartesianProduct\CartesianProduct;
 
@@ -46,4 +47,14 @@ class TestCommand extends Command
         $cartesianProduct->appendSet(["红色", "白色"]);
         dump($cartesianProduct->compute());
     }
+
+    public function fixSku()
+    {
+        GoodsSku::chunkById(10, function ($s) {
+            $s->each(function (GoodsSku $sku) {
+                $sku->spec_attr_list;
+
+            });
+        });
+    }
 }

+ 4 - 3
app/Modules/Admin/Services/GoodsService.php

@@ -144,10 +144,11 @@ class GoodsService extends BaseService
                     "sn" => $sku->sn,
                     "url_3d" => $sku->url_3d,
                     "is_use" => $sku->is_use,
-                    "spec_attr" => array_map(function ($specAttrId) {
+                    "spec_attr" => array_map(function ($specAttr) {
+                        $id = Arr::get($specAttr, "id");
                         return [
-                            "id" => $specAttrId,
-                            "name" => SpecAttr::where("id", $specAttrId)->value("name"),
+                            "id" => $id,
+                            "name" => SpecAttr::where("id", $id)->value("name"),
                         ];
                     }, $sku->spec_attr_list),
                 ];