From e6ccd700086ed5123293559e622f2ecde2920804 Mon Sep 17 00:00:00 2001 From: 29071 Date: Fri, 19 Apr 2024 13:36:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BF=AE=E6=94=B9=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/dish_dao.go | 6 ++++ internal/router/admin/setmeal_router.go | 6 ++-- internal/router/service/setmeal_service.go | 35 +++++++++++----------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/internal/db/dish_dao.go b/internal/db/dish_dao.go index 48d0f34..c666af4 100644 --- a/internal/db/dish_dao.go +++ b/internal/db/dish_dao.go @@ -15,6 +15,7 @@ type dishI interface { List(d *model.Dish) (*[]model.Dish, error) GetById(id int64) *model.Dish Save(dish *model.Dish) *model.Dish + GetBySetmealId(id int64) []*model.Dish } type dishDao struct { } @@ -87,3 +88,8 @@ func (*dishDao) GetById(id int64) *model.Dish { DBEngine.Where("id=?", id).First(&dish) return &dish } +func (*dishDao) GetBySetmealId(id int64) []*model.Dish { + var list []*model.Dish + DBEngine.Joins(model.TableNameSetmealDish, DBEngine.Where(&model.SetmealDish{SetmealID: id})).Find(&list) + return list +} diff --git a/internal/router/admin/setmeal_router.go b/internal/router/admin/setmeal_router.go index 65a2100..98fc16e 100644 --- a/internal/router/admin/setmeal_router.go +++ b/internal/router/admin/setmeal_router.go @@ -15,6 +15,8 @@ import ( "strings" ) +// over + // @Summary 套餐管理接机口 func SaveSetMealWithDish(ctx context.Context, c *app.RequestContext) { var setD dto.SetmealDTO @@ -90,12 +92,12 @@ func UpdateMeal(ctx context.Context, c *app.RequestContext) { c.JSON(http.StatusOK, common.Result{1, "", nil}) } -// 待完善 +// @Summary 套餐起售停售 func StartOrStopMeal(ctx context.Context, c *app.RequestContext) { status, id := c.Param("status"), c.Query("id") log.Printf("启用禁用套餐分类:{%s},{%s}", status, id) status_r, _ := strconv.ParseInt(status, 10, 32) id_r, _ := strconv.ParseInt(id, 10, 64) - service.StartOrStopMeal(int32(status_r), id_r, middleware.GetJwtPayload(c)) + service.StartOrStopMeal(int32(status_r), id_r) c.JSON(http.StatusOK, common.Result{1, "", nil}) } diff --git a/internal/router/service/setmeal_service.go b/internal/router/service/setmeal_service.go index ee7bc9a..87bbb1d 100644 --- a/internal/router/service/setmeal_service.go +++ b/internal/router/service/setmeal_service.go @@ -1,9 +1,11 @@ package service import ( + "errors" "github.com/cloudwego/hertz/pkg/common/hlog" "reggie/internal/db" "reggie/internal/models/common" + "reggie/internal/models/constant/message_c" "reggie/internal/models/constant/status_c" "reggie/internal/models/dto" "reggie/internal/models/model" @@ -67,25 +69,22 @@ func UpdateMeal(meal *model.Setmeal, dish *[]model.SetmealDish) { } db.MealDishDao.InsertBatch(dish) } -func StartOrStopMeal(status int32, id int64, update_user int64) { +func StartOrStopMeal(status int32, id int64) error { //起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售" - //if (status == status_c.ENABLE) { - //select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = ? - // List dishList = dishMapper.getBySetmealId(id); - // if (dishList != null && dishList.size() > 0) { - // dishList.forEach(dish -> { - // if (StatusConstant.DISABLE == dish.getStatus()) { - // throw new SetmealEnableFailedException(MessageConstant.SETMEAL_ENABLE_FAILED); - // } - // }); - // } - //} - // - //Setmeal setmeal = Setmeal.builder() - //.id(id) - //.status(status) - //.build(); - //setmealMapper.update(setmeal); + if status == status_c.ENABLE { + //select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = ? + dishList := db.DisDao.GetBySetmealId(id) + if dishList != nil && len(dishList) > 0 { + for _, item := range dishList { + if status_c.DISABLE == item.Status { + return errors.New(message_c.SETMEAL_ENABLE_FAILED) + } + } + } + } + setmeal := model.Setmeal{ID: id, Status: status} + db.MealDao.Update(&setmeal) + return nil } func ListSetmeal(meal *model.Setmeal) *[]model.Setmeal { return db.MealDao.List(meal)