Skip to content

Commit

Permalink
完成修改状态
Browse files Browse the repository at this point in the history
  • Loading branch information
onenewcode committed Apr 19, 2024
1 parent f8ececa commit e6ccd70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
6 changes: 6 additions & 0 deletions internal/db/dish_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand Down Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions internal/router/admin/setmeal_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"strings"
)

// over

// @Summary 套餐管理接机口
func SaveSetMealWithDish(ctx context.Context, c *app.RequestContext) {
var setD dto.SetmealDTO
Expand Down Expand Up @@ -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})
}
35 changes: 17 additions & 18 deletions internal/router/service/setmeal_service.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<Dish> 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)
Expand Down

0 comments on commit e6ccd70

Please sign in to comment.