Sfoglia il codice sorgente

添加产品分类接口

chenxiqiang 6 anni fa
parent
commit
7f100ff9c4

+ 39
- 0
manage-server/app/Http/Controllers/ProductClassifyController.php Vedi File

@@ -0,0 +1,39 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use App\Models\ProductClassify;
6
+use Illuminate\Http\Request;
7
+
8
+class ProductClassifyController extends Controller
9
+{
10
+
11
+    public function store(Request $request) {
12
+        $classify = $request->input("classify");
13
+        if($classify) {
14
+            $record = ProductClassify::find(1);
15
+            $record->classify = $classify;
16
+            $record->save();
17
+            return response()->json([
18
+                "status" => 0,
19
+                "message" => '修改成功'
20
+            ]);
21
+        } else {
22
+            return Response()->json([
23
+                "status" => -1,
24
+                "message" => "信息不能为空!"
25
+            ]);
26
+        }
27
+    }
28
+
29
+    public function get(Request $request) {
30
+        $record = ProductClassify::find(1);
31
+        $classify = $record->classify;
32
+        $classify = str_replace(" ", "", $classify);
33
+        $arrays = preg_split("/,/", $classify);
34
+        return response()->json([
35
+            "status" => 0,
36
+            "data" => $arrays
37
+        ]);
38
+    }
39
+}

+ 12
- 0
manage-server/app/Models/ProductClassify.php Vedi File

@@ -0,0 +1,12 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class ProductClassify extends Model
8
+{
9
+    protected $fillable = [
10
+        'classify', // 产品分类
11
+    ];
12
+}

+ 32
- 0
manage-server/database/migrations/2018_09_24_085158_create_product_classifies_table.php Vedi File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+use Illuminate\Support\Facades\Schema;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Database\Migrations\Migration;
6
+
7
+class CreateProductClassifiesTable extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('product_classifies', function (Blueprint $table) {
17
+            $table->increments('id');
18
+            $table->string('classify');
19
+            $table->timestamps();
20
+        });
21
+    }
22
+
23
+    /**
24
+     * Reverse the migrations.
25
+     *
26
+     * @return void
27
+     */
28
+    public function down()
29
+    {
30
+        Schema::dropIfExists('product_classifies');
31
+    }
32
+}

+ 3
- 0
manage-server/routes/web.php Vedi File

@@ -30,6 +30,9 @@ Route::middleware(['manage.token'])->group(function () {
30 30
     Route::get('/reward/price', 'RewardController@getPrice');
31 31
     Route::get('/classify/parent', 'ClassifyController@parent');
32 32
 
33
+    Route::post('/product_classify/store', 'ProductClassifyController@store');
34
+    Route::get('/product_classify', 'ProductClassifyController@get');
35
+
33 36
     Route::get('/product/home', 'ProductController@home');
34 37
     Route::post('/product/home', 'ProductController@setHome');
35 38
     Route::post('/classify/home', 'ClassifyController@setHome');

Loading…
Annulla
Salva