Преглед изворни кода

修改产品首页展示接口

chenxiqiang пре 6 година
родитељ
комит
b731e6b6f8

+ 6
- 14
manage-server/app/Http/Controllers/ProductController.php Прегледај датотеку

@@ -22,10 +22,11 @@ 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
+        $show = $request->input('show');
26 26
         if ($id) {
27 27
             $product = Product::find($id);
28 28
             $product->status = $status;
29
+            $product->show = 0;
29 30
         } else {
30 31
             $product = new Product;
31 32
             $product->status = 0;
@@ -38,7 +39,7 @@ class ProductController extends Controller
38 39
             $product->color = $color;
39 40
             $product->price = $price;
40 41
             $product->classify = $classify;
41
-            $product->location = $location;
42
+            $product->show = $show;
42 43
             $product->save();
43 44
             return Response()->json([
44 45
                 "status" => 0,
@@ -99,29 +100,20 @@ class ProductController extends Controller
99 100
      */
100 101
     public function home(Request $request)
101 102
     {
102
-        $top = Product::where("location", "top")->limit(3)->get()->toArray();
103
-        $bottom = Product::where("location", "bottom")->first();
103
+        $top = Product::where("show", 1)->orderBy("updated_at", "desc")->limit(3)->get()->toArray();
104 104
 
105 105
         $tops = array_map(function ($t) {
106 106
             return [
107 107
                 "id" => $t["id"],
108 108
                 "name" => $t["name"],
109
-                "info" => $t["info"],
110 109
                 "photo" => $t["photo"],
111 110
                 "location" => $t["location"]
112 111
             ];
113 112
         }, $top);
114 113
 
115 114
         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
-            ]
115
+            "data" => $tops,
116
+            "status" => 0,
125 117
         ]);
126 118
     }
127 119
 

+ 1
- 1
manage-server/app/Models/Product.php Прегледај датотеку

@@ -21,6 +21,6 @@ class Product extends Model
21 21
         'sell_num', // 销量
22 22
 		'status', // 产品状态, 上架/下架
23 23
         'photo', // 产品图片
24
-        'location', // 产品图片
24
+        'show', // 产品轮播首页是否显示,boolean
25 25
 	];
26 26
 }

+ 1
- 1
manage-server/database/migrations/2018_08_10_073946_create_products_table.php Прегледај датотеку

@@ -36,7 +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
+            $table->integer('show');
40 40
         });
41 41
     }
42 42
 

Loading…
Откажи
Сачувај