Browse Source

支持attr

kphcdr 1 year ago
parent
commit
8686a487b4
3 changed files with 65 additions and 0 deletions
  1. 50 0
      app/Console/Commands/ExportCommand.php
  2. 13 0
      app/Http/Controllers/Controller.php
  3. 2 0
      routes/api.php

+ 50 - 0
app/Console/Commands/ExportCommand.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Goods\GoodsSku;
+use Illuminate\Console\Command;
+use Nerd\CartesianProduct\CartesianProduct;
+
+class ExportCommand extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'export {cmd?}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    public function handle()
+    {
+        $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()
+    {
+        $cartesianProduct = new CartesianProduct();
+        $cartesianProduct->appendSet(["红色", "白色"]);
+        dump($cartesianProduct->compute());
+    }
+}

+ 13 - 0
app/Http/Controllers/Controller.php

@@ -15,4 +15,17 @@ class Controller extends BaseController
     {
         return "pong";
     }
+
+    public function upload()
+    {
+        $file = request()->file("file");
+        $category = request()->input("category", "default");
+        $path = $file->store("public/{$category}");
+        return [
+            "code" => 200,
+            "data" => [
+                "upload_url" => config("app.url") . str_replace("public", "/storage", $path),
+            ],
+        ];
+    }
 }

+ 2 - 0
routes/api.php

@@ -4,3 +4,5 @@ use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Route;
 
 Route::get('/', [\App\Http\Controllers\Controller::class, "ping"]);
+
+Route::post("/api/common/upload", [App\Http\Controllers\Controller::class, "upload"]);