Bladeren bron

修改产品首页接口,小程序首页轮训接口

chenxiqiang 7 jaren geleden
bovenliggende
commit
3a215f527e

+ 16
- 35
manage-server/app/Http/Controllers/ClassifyController.php Bestand weergeven

@@ -15,18 +15,10 @@ class ClassifyController extends Controller
15 15
     }
16 16
 
17 17
     public function setHome(Request $request) {
18
-        $top1 = $request->input("top1");
19
-        $top2 = $request->input("top2");
20
-        $top3 = $request->input("top3");
21
-        $bottom = $request->input("bottom");
22 18
         $introduce = $request->input("introduce");
23 19
 
24
-        if($top1 && $top2 && $top3 && $bottom && $introduce) {
20
+        if($introduce) {
25 21
             $homePage = HomePage::find(1);
26
-            $homePage->top1 = $top1;
27
-            $homePage->top2 = $top2;
28
-            $homePage->top3 = $top3;
29
-            $homePage->bottom = $bottom;
30 22
             $homePage->introduce = $introduce;
31 23
             $homePage->save();
32 24
 
@@ -49,39 +41,28 @@ class ClassifyController extends Controller
49 41
      */
50 42
     public function home(Request $request)
51 43
     {
44
+        $top = Classify::where("location", "top")->orderBy("updated_at", "desc")->limit(3)->get()->toArray();
45
+        $bottom = Classify::where("location", "bottom")->orderBy("updated_at", "desc")->first();
52 46
         $homePage = HomePage::find(1);
53
-        $top1 = Classify::find($homePage->top1);
54
-        $top2 = Classify::find($homePage->top2);
55
-        $top3 = Classify::find($homePage->top3);
56
-        $bottom = Classify::find($homePage->bottom);
57
-        $introduce = $homePage->introduce;
47
+        $tops = array_map(function ($t) {
48
+            return [
49
+                "id" => $t["id"],
50
+                "server" => $t["server"],
51
+                "content" => $t["content"],
52
+                "photo" => $t["photo"],
53
+                "location" => $t["location"]
54
+            ];
55
+        }, $top);
56
+
58 57
         return Response()->json([
59
-            "top" => [
60
-                [
61
-                    "id" => $top1["id"],
62
-                    "server" => $top1["server"],
63
-                    "content" => $top1["content"],
64
-                    "photo" => $top1["photo"],
65
-                ],
66
-                [
67
-                    "id" => $top2["id"],
68
-                    "server" => $top2["server"],
69
-                    "content" => $top2["content"],
70
-                    "photo" => $top2["photo"],
71
-                ],
72
-                [
73
-                    "id" => $top3["id"],
74
-                    "server" => $top3["server"],
75
-                    "content" => $top3["content"],
76
-                    "photo" => $top3["photo"],
77
-                ]
78
-            ],
79
-            "introduce" => $introduce,
58
+            "top" => $tops,
59
+            "introduce" => $homePage->introduce,
80 60
             "bottom" => [
81 61
                 "id" => $bottom["id"],
82 62
                 "server" => $bottom["server"],
83 63
                 "content" => $bottom["content"],
84 64
                 "photo" => $bottom["photo"],
65
+                "location" => $bottom["location"]
85 66
             ]
86 67
         ]);
87 68
     }

+ 1
- 0
manage-server/app/Http/Controllers/CommonController.php Bestand weergeven

@@ -308,6 +308,7 @@ class CommonController extends Controller
308 308
             $record = $this->getRecord($order_type, $id);
309 309
             if ($record) {
310 310
                 $record->price = $price;
311
+                $record->status = 1;
311 312
                 $record->save();
312 313
                 return Response()->json([
313 314
                     "status" => 0,

+ 47
- 0
manage-server/app/Http/Controllers/OptionController.php Bestand weergeven

@@ -0,0 +1,47 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use App\Models\OptionValue;
6
+use Illuminate\Http\Request;
7
+use App\Models\OptionKey;
8
+
9
+class OptionController extends Controller
10
+{
11
+
12
+    public function option_keys(Request $request,$classify_id) {
13
+        $classify_id = $request->route("classify_id");
14
+        if($classify_id) {
15
+            $options = OptionKey::with("optionValues")->where("classify_id", $classify_id)->get()->toArray();
16
+            return Response()->json([
17
+                "status" => 0,
18
+                "data" => $options
19
+            ]);
20
+
21
+        }
22
+    }
23
+
24
+    public function option_key(Request $request, $id) {
25
+
26
+        $option_key_id = $request->route("id");
27
+        if($option_key_id) {
28
+            $option_value = OptionKey::with("optionValues")->find($option_key_id);
29
+            return Response()->json([
30
+                "status" => 0,
31
+                "data" => $option_value
32
+            ]);
33
+        }
34
+    }
35
+
36
+    public function option_value(Request $request, $id) {
37
+
38
+        $option_value_id = $request->route("id");
39
+        if($option_value_id) {
40
+            $option_value = OptionValue::with("optionKey")->find($option_value_id);
41
+            return Response()->json([
42
+                "status" => 0,
43
+                "data" => $option_value
44
+            ]);
45
+        }
46
+    }
47
+}

+ 11
- 21
manage-server/app/Http/Controllers/ProductController.php Bestand weergeven

@@ -101,28 +101,18 @@ class ProductController extends Controller
101 101
      */
102 102
     public function home(Request $request)
103 103
     {
104
-        $homePage = ProductPage::find(1);
105
-        $top1 = Product::find($homePage->top1);
106
-        $top2 = Product::find($homePage->top2);
107
-        $top3 = Product::find($homePage->top3);
104
+        $top = Product::where("show", 1)->orderBy("updated_at", "desc")->limit(3)->get()->toArray();
105
+
106
+        $tops = array_map(function ($t) {
107
+            return [
108
+                "id" => $t["id"],
109
+                "name" => $t["name"],
110
+                "photo" => $t["photo"]
111
+            ];
112
+        }, $top);
113
+
108 114
         return Response()->json([
109
-            "data" => [
110
-                [
111
-                    "id" => $top1["id"],
112
-                    "name" => $top1["name"],
113
-                    "photo" => $top1["photo"]
114
-                ],
115
-                [
116
-                    "id" => $top2["id"],
117
-                    "name" => $top2["name"],
118
-                    "photo" => $top2["photo"]
119
-                ],
120
-                [
121
-                    "id" => $top3["id"],
122
-                    "name" => $top3["name"],
123
-                    "photo" => $top3["photo"]
124
-                ],
125
-            ],
115
+            "data" => $tops,
126 116
             "status" => 0,
127 117
         ]);
128 118
     }

+ 5
- 0
manage-server/app/Models/Classify.php Bestand weergeven

@@ -23,4 +23,9 @@ class Classify extends Model
23 23
         $this->children[$key] = $value;
24 24
         return;
25 25
     }
26
+
27
+
28
+    public function options() {
29
+        return $this->hasMany('App\Models\OptionKey', 'classify_id')->withDefault();
30
+    }
26 31
 }

+ 2
- 4
manage-server/app/Models/HomePage.php Bestand weergeven

@@ -6,11 +6,9 @@ use Illuminate\Database\Eloquent\Model;
6 6
 
7 7
 class HomePage extends Model
8 8
 {
9
+    public $timestamps = false;
10
+
9 11
     protected $fillable = [
10
-        'top1',
11
-        'top2',
12
-        'top3',
13 12
         'introduce',
14
-        'bottom'
15 13
     ];
16 14
 }

+ 21
- 0
manage-server/app/Models/OptionKey.php Bestand weergeven

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class OptionKey extends Model
8
+{
9
+    public $timestamps = false;
10
+
11
+    protected $fillable = [
12
+        'key',
13
+        'classify_id',
14
+        'type'
15
+    ];
16
+
17
+
18
+    public function optionValues() {
19
+        return $this->hasMany('App\Models\OptionValue', 'option_key_id', 'id');
20
+    }
21
+}

+ 20
- 0
manage-server/app/Models/OptionValue.php Bestand weergeven

@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class OptionValue extends Model
8
+{
9
+    public $timestamps = false;
10
+
11
+    protected $fillable = [
12
+        'value',
13
+        'option_key_id'
14
+    ];
15
+
16
+    public function optionKey () {
17
+
18
+        return $this->belongsTo('App\Models\OptionKey', 'option_key_id')->withDefault();
19
+    }
20
+}

+ 31
- 0
manage-server/database/migrations/2018_09_23_070729_create_option_keys_table.php Bestand weergeven

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

+ 31
- 0
manage-server/database/migrations/2018_09_23_070740_create_option_values_table.php Bestand weergeven

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

+ 15
- 10
manage-server/routes/api.php Bestand weergeven

@@ -20,15 +20,6 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
20 20
 
21 21
 Route::post('/login', 'CommonController@login');
22 22
 
23
-Route::get('/server_info/{id}', 'ClassifyController@server_content');
24
-Route::get('/classify/{id}', 'ClassifyController@get');
25
-Route::post('/upload', 'CommonController@upload');
26
-Route::post('/server/store', 'ServerInfoController@store');
27
-Route::get('/{order_type}/{order_id}/comments', 'CommonController@comments');
28
-Route::post('/{order_type}/status', 'CommonController@status');
29
-Route::get('/{order_type}/{id}', 'CommonController@get')->where('id', '[0-9]+');
30
-Route::delete('/{order_type}/{id}', 'CommonController@delete')->where('id', '[0-9]+');
31
-
32 23
 Route::get('/classify', 'ClassifyController@list');
33 24
 
34 25
 Route::get('/campaigns', 'CampaignController@list');
@@ -48,10 +39,24 @@ Route::post('/campaign/store', 'CampaignController@store');
48 39
 Route::post('/product/store', 'ProductController@store');
49 40
 Route::get('/product/home', 'ProductController@home');
50 41
 
51
-
52 42
 Route::post('/payments/wechat-notify', 'PaymentController@notify');
53 43
 
54 44
 
45
+Route::get('/classify/{classify_id}/options', 'OptionController@option_keys');
46
+Route::get('/option/key/{id}', 'OptionController@option_key');
47
+Route::get('/option/value/{id}', 'OptionController@option_value');
48
+
49
+
50
+Route::get('/server_info/{id}', 'ClassifyController@server_content');
51
+Route::get('/classify/{id}', 'ClassifyController@get');
52
+Route::post('/upload', 'CommonController@upload');
53
+Route::post('/server/store', 'ServerInfoController@store');
54
+Route::get('/{order_type}/{order_id}/comments', 'CommonController@comments');
55
+Route::post('/{order_type}/status', 'CommonController@status');
56
+Route::get('/{order_type}/{id}', 'CommonController@get')->where('id', '[0-9]+');
57
+Route::delete('/{order_type}/{id}', 'CommonController@delete')->where('id', '[0-9]+');
58
+
59
+
55 60
 Route::middleware(['token'])->group(function () {
56 61
 
57 62
     Route::get('/my/orders', 'CommonController@orders');

Loading…
Annuleren
Opslaan