ソースを参照

Fix #27 修复商家删除商品后,用户端让然可以看到该商品的问题

microapp 3 年 前
コミット
7793bcba7e

+ 13 - 1
flash-waimai-api/src/main/java/cn/enilu/flash/api/controller/business/FoodController.java

@@ -170,7 +170,19 @@ public class FoodController extends BaseController {
      */
     @RequestMapping(value = "/v2/food/{id}", method = RequestMethod.DELETE)
     public Object delete(@PathVariable("id") Long id) {
-        mongoRepository.delete("foods", Maps.newHashMap("item_id", id));
+        //下架食品
+        Food food =mongoRepository.findOne(Food.class, Maps.newHashMap("item_id",id));
+        food.setState(Food.STATE_DEL);
+        mongoRepository.update(food);
+        //从菜单中移除当前食品
+        Long restaurantId = food.getRestaurant_id();
+        Menu menu = mongoRepository.findOne(Menu.class,Maps.newHashMap("restaurant_id",restaurantId));
+        List<Food> foods = menu.getFoods();
+
+        foods.removeIf(s-> s.getItem_id().intValue() == id.intValue());
+
+        mongoRepository.update(menu);
+
         return Rets.success();
     }
 

+ 7 - 0
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Food.java

@@ -25,6 +25,10 @@ public class Food extends BaseMongoEntity{
      * 审核状态:审核拒绝
      */
     public static  final String STATE_NO = "-1";
+    /**
+     * 已删除
+     */
+    public static  final String STATE_DEL = "-2";
     @Id
     private String _id;
     /**
@@ -332,6 +336,9 @@ public class Food extends BaseMongoEntity{
         if(STATE_NO.equals(state)){
             return "审核失败";
         }
+        if(STATE_DEL.equals(state)){
+            return "已删除";
+        }
         return "";
     }
 }

+ 5 - 0
flash-waimai-manage/src/views/business/food/index.vue

@@ -80,6 +80,10 @@
           label="评分"
           prop="rating">
         </el-table-column>
+        <el-table-column
+          label="状态"
+          prop="stateStr">
+        </el-table-column>
         <el-table-column label="操作" width="250">
           <template slot-scope="scope">
             <el-button
@@ -94,6 +98,7 @@
               v-permission="['/business/food/edit']"
               @click="handleEdit(scope.row)">编辑</el-button>
             <el-button
+              v-if="scope.row.stateStr!=='已删除'"
               size="small"
               type="danger"
               v-permission="['/business/food/delete']"

+ 4 - 2
flash-waimai-mobile/src/config/fetch.js

@@ -14,8 +14,10 @@ export default async(url = '', data = {}, type = 'GET', method = 'fetch') => {
 
 		if (dataStr !== '') {
 			dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'));
-			url = url + '?' + dataStr;
-		}
+			url = url + '?' + dataStr+'&t='+new Date().getTime();
+		}else{
+		  url = url+'?t='+new Date().getTime()
+    }
 	}
 
 	if (window.fetch && method == 'fetch') {