chenxiqiang 6 роки тому
джерело
коміт
88f3ec7ac9

+ 35
- 0
manage-server/app/Http/Controllers/ProductController.php Переглянути файл

22
         $color = $request->input('color');
22
         $color = $request->input('color');
23
         $price = $request->input('price');
23
         $price = $request->input('price');
24
         $status = $request->input('status');
24
         $status = $request->input('status');
25
+        $location = $request->input('location');
25
         if ($id) {
26
         if ($id) {
26
             $product = Product::find($id);
27
             $product = Product::find($id);
27
             $product->status = $status;
28
             $product->status = $status;
37
             $product->color = $color;
38
             $product->color = $color;
38
             $product->price = $price;
39
             $product->price = $price;
39
             $product->classify = $classify;
40
             $product->classify = $classify;
41
+            $product->location = $location;
40
             $product->save();
42
             $product->save();
41
             return Response()->json([
43
             return Response()->json([
42
                 "status" => 0,
44
                 "status" => 0,
90
         ]);
92
         ]);
91
     }
93
     }
92
 
94
 
95
+    /**
96
+     * 每页20进行分页
97
+     * @param Request $request
98
+     * @return mixed
99
+     */
100
+    public function home(Request $request)
101
+    {
102
+        $top = Product::where("location", "top")->limit(3)->get()->toArray();
103
+        $bottom = Product::where("location", "bottom")->first();
104
+
105
+        $tops = array_map(function ($t) {
106
+            return [
107
+                "id" => $t["id"],
108
+                "name" => $t["name"],
109
+                "info" => $t["info"],
110
+                "photo" => $t["photo"],
111
+                "location" => $t["location"]
112
+            ];
113
+        }, $top);
114
+
115
+        return Response()->json([
116
+            "top" => $tops,
117
+            "introduce" => "产品介绍",
118
+            "bottom" => [
119
+                "id" => $bottom["id"],
120
+                "name" => $bottom["name"],
121
+                "info" => $bottom["info"],
122
+                "photo" => $bottom["photo"],
123
+                "location" => $bottom["location"]
124
+            ]
125
+        ]);
126
+    }
127
+
93
 }
128
 }

+ 1
- 0
manage-server/app/Models/Product.php Переглянути файл

21
         'sell_num', // 销量
21
         'sell_num', // 销量
22
 		'status', // 产品状态, 上架/下架
22
 		'status', // 产品状态, 上架/下架
23
         'photo', // 产品图片
23
         'photo', // 产品图片
24
+        'location', // 产品图片
24
 	];
25
 	];
25
 }
26
 }

+ 1
- 0
manage-server/database/migrations/2018_08_10_073946_create_products_table.php Переглянути файл

36
             $table->integer('collect_num');
36
             $table->integer('collect_num');
37
             $table->integer('sell_num');
37
             $table->integer('sell_num');
38
             $table->string('photo');
38
             $table->string('photo');
39
+            $table->string('location');
39
         });
40
         });
40
     }
41
     }
41
 
42
 

+ 1
- 0
manage-server/routes/api.php Переглянути файл

46
 
46
 
47
 Route::post('/campaign/store', 'CampaignController@store');
47
 Route::post('/campaign/store', 'CampaignController@store');
48
 Route::post('/product/store', 'ProductController@store');
48
 Route::post('/product/store', 'ProductController@store');
49
+Route::get('/product/home', 'ProductController@home');
49
 
50
 
50
 
51
 
51
 Route::post('/payments/wechat-notify', 'PaymentController@notify');
52
 Route::post('/payments/wechat-notify', 'PaymentController@notify');

Loading…
Відмінити
Зберегти