浏览代码

添加产品首页接口

chenxiqiang 6 年前
父节点
当前提交
88f3ec7ac9

+ 35
- 0
manage-server/app/Http/Controllers/ProductController.php 查看文件

@@ -22,6 +22,7 @@ class ProductController extends Controller
22 22
         $color = $request->input('color');
23 23
         $price = $request->input('price');
24 24
         $status = $request->input('status');
25
+        $location = $request->input('location');
25 26
         if ($id) {
26 27
             $product = Product::find($id);
27 28
             $product->status = $status;
@@ -37,6 +38,7 @@ class ProductController extends Controller
37 38
             $product->color = $color;
38 39
             $product->price = $price;
39 40
             $product->classify = $classify;
41
+            $product->location = $location;
40 42
             $product->save();
41 43
             return Response()->json([
42 44
                 "status" => 0,
@@ -90,4 +92,37 @@ class ProductController extends Controller
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,5 +21,6 @@ class Product extends Model
21 21
         'sell_num', // 销量
22 22
 		'status', // 产品状态, 上架/下架
23 23
         'photo', // 产品图片
24
+        'location', // 产品图片
24 25
 	];
25 26
 }

+ 1
- 0
manage-server/database/migrations/2018_08_10_073946_create_products_table.php 查看文件

@@ -36,6 +36,7 @@ class CreateProductsTable extends Migration
36 36
             $table->integer('collect_num');
37 37
             $table->integer('sell_num');
38 38
             $table->string('photo');
39
+            $table->string('location');
39 40
         });
40 41
     }
41 42
 

+ 1
- 0
manage-server/routes/api.php 查看文件

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

Loading…
取消
保存