kphcdr 1 vuosi sitten
vanhempi
commit
9d14c0e434
3 muutettua tiedostoa jossa 32 lisäystä ja 16 poistoa
  1. 21 13
      app/Console/Commands/TestCommand.php
  2. 10 2
      app/Modules/Admin/Services/GoodsService.php
  3. 1 1
      config/app.php

+ 21 - 13
app/Console/Commands/TestCommand.php

@@ -12,7 +12,7 @@ class TestCommand extends Command
      *
      * @var string
      */
-    protected $signature = 'test';
+    protected $signature = 'test {cmd?}';
 
     /**
      * The console command description.
@@ -21,19 +21,27 @@ class TestCommand extends Command
      */
     protected $description = 'Command description';
 
-    /**
-     * Execute the console command.
-     *
-     * @return int
-     */
     public function handle()
     {
-        $cartesianProduct = new CartesianProduct();
-        $cartesianProduct->appendSet(["a"]);
-        dump($cartesianProduct->compute());
-        $cartesianProduct = new CartesianProduct();
-        $cartesianProduct->appendSet(["a"]);
-        $cartesianProduct->appendSet(["b"]);
-        dump($cartesianProduct->compute());
+        $cmd = $this->argument('cmd');
+        $args = $this->arguments();
+        unset($args['command'], $args['cmd']);
+        $params = array_values($args);
+
+        if (empty($cmd)) {
+            echo 'Nothing to do...';
+        } else {
+            if (method_exists($this, $cmd)) {
+                call_user_func_array([$this, $cmd], $params);
+            } else {
+                echo 'cmd not exists';
+            }
+        }
+        return;
+    }
+
+    public function time()
+    {
+        dump(date('Y-m-d H:i:s'));
     }
 }

+ 10 - 2
app/Modules/Admin/Services/GoodsService.php

@@ -3,9 +3,11 @@
 namespace App\Modules\Admin\Services;
 
 use App\Base\BaseService;
+use App\Exceptions\ClientException;
 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 Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Arr;
@@ -46,10 +48,16 @@ class GoodsService extends BaseService
             $goods = new Goods();
         }
 
-        DB::transaction(function () use ($params, $goods) {
+        $specIdArr = Arr::get($params, "spec", []);
+        $notCustomSpecS = Spec::whereIn("id", $specIdArr)->where("is_custom", 0)->get();
+        if ($notCustomSpecS->isEmpty()) {
+            throw new ClientException("必须要存在一个非自定义的规格");
+        }
+
+        DB::transaction(function () use ($params, $goods, $specIdArr) {
 
             $goods->image_list = Arr::get($params, "image_list", []);
-            $goods->spec = Arr::get($params, "spec", []);
+            $goods->spec = $specIdArr;
             $goods->name = Arr::get($params, "name", []);
             $goods->weight = Arr::get($params, "weight", 0);
             $goods->desc_html = Arr::get($params, "desc_html", "");

+ 1 - 1
config/app.php

@@ -69,7 +69,7 @@ return [
     |
     */
 
-    'timezone' => 'UTC',
+    'timezone' => 'Asia/Shanghai',
 
     /*
     |--------------------------------------------------------------------------