From 7b0d1d396f14a24557e11d0e890a3c1ba7cd355d Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 16:57:46 +0800 Subject: [PATCH 01/12] - up --- business/userstore/food_recipe.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/business/userstore/food_recipe.go b/business/userstore/food_recipe.go index c1639cf96..6db1ce593 100644 --- a/business/userstore/food_recipe.go +++ b/business/userstore/food_recipe.go @@ -48,7 +48,7 @@ func updateFoodRecipeItemAndStep(ctx *jxcontext.Context, db *dao.DaoDB, recipeID Index: int8(k + 1), Name: v.Name, } - dao.WrapAddIDCULEntity(item, ctx.GetUserName()) + dao.WrapAddIDCULDEntity(item, ctx.GetUserName()) if err = dao.CreateEntity(db, item); err != nil { return err } @@ -60,7 +60,7 @@ func updateFoodRecipeItemAndStep(ctx *jxcontext.Context, db *dao.DaoDB, recipeID ChoiceIndex: int8(k2 + 1), } - dao.WrapAddIDCULEntity(choice, ctx.GetUserName()) + dao.WrapAddIDCULDEntity(choice, ctx.GetUserName()) if err = dao.CreateEntity(db, choice); err != nil { return err } @@ -73,7 +73,7 @@ func updateFoodRecipeItemAndStep(ctx *jxcontext.Context, db *dao.DaoDB, recipeID Index: int8(k + 1), Name: v.Name, } - dao.WrapAddIDCULEntity(step, ctx.GetUserName()) + dao.WrapAddIDCULDEntity(step, ctx.GetUserName()) if err = dao.CreateEntity(db, step); err != nil { return err } @@ -101,7 +101,7 @@ func CreateFoodRecipe(ctx *jxcontext.Context, foodRecipe *model.FoodRecipe, item }() _, foodRecipe.AuthorID = ctx.GetMobileAndUserID() - dao.WrapAddIDCULEntity(foodRecipe, ctx.GetUserName()) + dao.WrapAddIDCULDEntity(foodRecipe, ctx.GetUserName()) if err = dao.CreateEntity(db, foodRecipe); err != nil { return err } From 61c52330fddba45549862edf28b2480a24b795eb Mon Sep 17 00:00:00 2001 From: zhudan Date: Tue, 17 Sep 2019 17:03:10 +0800 Subject: [PATCH 02/12] =?UTF-8?q?Accept=20Merge=20Request=20#4:=20(don=20-?= =?UTF-8?q?>=20mark)=20Merge=20Request:=20=E9=97=A8=E5=BA=97=E8=AF=84?= =?UTF-8?q?=E5=88=86-=E4=BF=AE=E6=94=B9BUG=20Created=20By:=20@zhudan=20Acc?= =?UTF-8?q?epted=20By:=20@zhudan=20URL:=20https://rosydev.coding.net/p/jx-?= =?UTF-8?q?callback/d/jx-callback/git/merge/4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/store_score.go | 44 ++++++++++++++++++++-------- business/model/dao/dao_order.go | 2 +- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/business/jxstore/misc/store_score.go b/business/jxstore/misc/store_score.go index e4949b1aa..e52e0c4e9 100644 --- a/business/jxstore/misc/store_score.go +++ b/business/jxstore/misc/store_score.go @@ -591,17 +591,35 @@ func ScoreStore(ctx *jxcontext.Context, storeIDList []int) (retVal interface{}, GetAllStoreSkus(ctx, task, storeList) baseapi.SugarLogger.Debugf("ScoreStore step1 end") case 2: - db := dao.GetDB() - storeCountList, _ := dao.GetDailyBadCommentOrderCount(db, scoreDate) - storeScoreDataWrapper.SetDailyBadCommentOrderCount(storeCountList) - storeCountList, _ = dao.GetDailyUnFinishOrderCount(db, scoreDate) - storeScoreDataWrapper.SetDailyUnFinishOrderCount(storeCountList) - storeCountList, _ = dao.GetDailyFinishOrderCount(db, scoreDate) - storeScoreDataWrapper.SetDailyFinishOrderCount(storeCountList) - storeCountList, _ = dao.GetDailyAbsentGoodsOrderCount(db, scoreDate) - storeScoreDataWrapper.SetDailyAbsentGoodsOrderCount(storeCountList) - case 3: baseapi.SugarLogger.Debugf("ScoreStore step2 begin") + db := dao.GetDB() + storeCountList, err := dao.GetDailyBadCommentOrderCount(db, scoreDate) + if err == nil { + storeScoreDataWrapper.SetDailyBadCommentOrderCount(storeCountList) + } else { + baseapi.SugarLogger.Debugf("ScoreStore GetDailyBadCommentOrderCount %v", err) + } + storeCountList, err = dao.GetDailyUnFinishOrderCount(db, scoreDate) + if err == nil { + storeScoreDataWrapper.SetDailyUnFinishOrderCount(storeCountList) + } else { + baseapi.SugarLogger.Debugf("ScoreStore GetDailyUnFinishOrderCount %v", err) + } + storeCountList, err = dao.GetDailyFinishOrderCount(db, scoreDate) + if err == nil { + storeScoreDataWrapper.SetDailyFinishOrderCount(storeCountList) + } else { + baseapi.SugarLogger.Debugf("ScoreStore GetDailyFinishOrderCount %v", err) + } + storeCountList, err = dao.GetDailyAbsentGoodsOrderCount(db, scoreDate) + if err == nil { + storeScoreDataWrapper.SetDailyAbsentGoodsOrderCount(storeCountList) + } else { + baseapi.SugarLogger.Debugf("ScoreStore GetDailyAbsentGoodsOrderCount %v", err) + } + baseapi.SugarLogger.Debugf("ScoreStore step2 end") + case 3: + baseapi.SugarLogger.Debugf("ScoreStore step3 begin") taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { storeInfo := batchItemList[0].(*cms.StoreExt) storeID := storeInfo.ID @@ -626,13 +644,13 @@ func ScoreStore(ctx *jxcontext.Context, storeIDList []int) (retVal interface{}, if err != nil { baseapi.SugarLogger.Debugf("ScoreStore taskParallel error:%v", err) } - baseapi.SugarLogger.Debugf("ScoreStore step2 end") + baseapi.SugarLogger.Debugf("ScoreStore step3 end") case 4: - baseapi.SugarLogger.Debugf("ScoreStore step3 begin") + baseapi.SugarLogger.Debugf("ScoreStore step4 begin") storeScoreDataWrapper.InsertStoreScore() storeScoreDataWrapper.ClearData() allStoreSkusWrapper.ClearData() - baseapi.SugarLogger.Debugf("ScoreStore step3 end") + baseapi.SugarLogger.Debugf("ScoreStore step4 end") isScoring = false } return result, err diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index a365377ed..bbb20e382 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -354,7 +354,7 @@ func GetDailyEndOrderCount(db *DaoDB, statusList []int, isAbsentOrder bool, date } sql += ` GROUP BY jx_store_id` - err = GetRow(db, &storeCountList, sql, sqlParams) + err = GetRows(db, &storeCountList, sql, sqlParams) return storeCountList, err } From d8f684f7201a69b9529f978bdbf891adde7b64cc Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 17:06:08 +0800 Subject: [PATCH 03/12] - up --- business/model/food_recipe.go | 4 ++-- business/userstore/food_recipe.go | 2 +- controllers/{cmd_food_recipe.go => cms_food_recipe.go} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename controllers/{cmd_food_recipe.go => cms_food_recipe.go} (100%) diff --git a/business/model/food_recipe.go b/business/model/food_recipe.go index 05fe82cb2..6c75cb419 100644 --- a/business/model/food_recipe.go +++ b/business/model/food_recipe.go @@ -13,7 +13,7 @@ type FoodRecipe struct { AuthorID string `orm:"size(48);column(author_id);index" json:"authorID"` Description string `orm:"size(4096)" json:"description"` - Img string `orm:"size(48)" json:"img"` + Img string `orm:"size(1024)" json:"img"` TimeInMinute int `json:"timeInMinute"` // 大约时间(分钟) UpvoteCount int `json:"upvoteCount"` DownvoteCount int `json:"downvoteCount"` @@ -39,7 +39,7 @@ type FoodRecipeStep struct { Name string `orm:"size(48)" json:"name"` Description string `orm:"size(4096)" json:"description"` - Img string `orm:"size(48)" json:"img"` + Img string `orm:"size(1024)" json:"img"` } func (*FoodRecipeStep) TableUnique() [][]string { diff --git a/business/userstore/food_recipe.go b/business/userstore/food_recipe.go index 6db1ce593..99e7e02e0 100644 --- a/business/userstore/food_recipe.go +++ b/business/userstore/food_recipe.go @@ -255,7 +255,7 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error) UserID: userID, } if err = dao.GetEntity(db, recipeUser); err != nil { - if dao.IsNoRowsError(err) { + if !dao.IsNoRowsError(err) { return err } } diff --git a/controllers/cmd_food_recipe.go b/controllers/cms_food_recipe.go similarity index 100% rename from controllers/cmd_food_recipe.go rename to controllers/cms_food_recipe.go From 8dbb872f4cf21c89997ee7d5518c921c0a7e36f7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 17:25:24 +0800 Subject: [PATCH 04/12] =?UTF-8?q?-=20=E4=BF=AE=E6=94=B9=E8=8F=9C=E8=B0=B1?= =?UTF-8?q?=E7=9A=84=E5=87=A0=E4=B8=AAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/food_recipe.go | 28 ++++++++++++++++++++-------- business/userstore/food_recipe.go | 30 +++++++++++++++++++++--------- controllers/cms_food_recipe.go | 10 +++++++--- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/business/model/dao/food_recipe.go b/business/model/dao/food_recipe.go index bac34ad31..a18a7d843 100644 --- a/business/model/dao/food_recipe.go +++ b/business/model/dao/food_recipe.go @@ -10,12 +10,12 @@ type FoodRecipeWithAction struct { ActionType int8 `json:"actionType"` } -func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string) (recipeList []*FoodRecipeWithAction, err error) { +func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string, offset, pageSize int) (recipeList []*FoodRecipeWithAction, totalCount int, err error) { var sql string var sqlParams []interface{} if userID != "" { sql = ` - SELECT t1.*, t2.action_type + SELECT SQL_CALC_FOUND_ROWS t1.*, t2.action_type FROM food_recipe t1 LEFT JOIN food_recipe_user t2 ON t2.recipe_id = t1.id AND t2.user_id = ? AND t2.deleted_at = ? WHERE t1.deleted_at = ?` @@ -26,7 +26,7 @@ func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID } } else { sql = ` - SELECT t1.* + SELECT SQL_CALC_FOUND_ROWS t1.* FROM food_recipe t1 WHERE t1.deleted_at = ?` sqlParams = []interface{}{ @@ -47,15 +47,27 @@ func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID sql += " AND t1.author_id = ?" sqlParams = append(sqlParams, authorID) } - err = GetRows(db, &recipeList, sql, sqlParams...) - return recipeList, err + offset = FormalizePageOffset(offset) + pageSize = FormalizePageSize(pageSize) + sql += ` + ORDER BY t1.created_at DESC + LIMIT ? OFFSET ?` + sqlParams = append(sqlParams, pageSize, offset) + + Begin(db) + defer Rollback(db) + if err = GetRows(db, &recipeList, sql, sqlParams...); err == nil { + totalCount = GetLastTotalRowCount(db) + } + return recipeList, totalCount, err } -func GetRecommendFoodRecipes(db *DaoDB, keyword, userID string) (recipeList []*model.FoodRecipe, err error) { - if list, err := QueryFoodRecipes(db, keyword, 0, userID, ""); err == nil { +func GetRecommendFoodRecipes(db *DaoDB, keyword, userID string, offset, pageSize int) (recipeList []*model.FoodRecipe, totalCount int, err error) { + list, totalCount, err := QueryFoodRecipes(db, keyword, 0, userID, "", offset, pageSize) + if err == nil { recipeList = FoodRecipeWithActionList2Recipe(list) } - return recipeList, err + return recipeList, totalCount, err } func FoodRecipeWithActionList2Recipe(recipeList []*FoodRecipeWithAction) (outRecipeList []*model.FoodRecipe) { diff --git a/business/userstore/food_recipe.go b/business/userstore/food_recipe.go index 99e7e02e0..18352903c 100644 --- a/business/userstore/food_recipe.go +++ b/business/userstore/food_recipe.go @@ -169,22 +169,34 @@ func UpdateFoodRecipe(ctx *jxcontext.Context, recipeID int, mapData map[string]i return err } -func QueryFoodRecipes(ctx *jxcontext.Context, keyword, authorID string) (recipeList []*dao.FoodRecipeWithAction, err error) { +func QueryFoodRecipes(ctx *jxcontext.Context, keyword, authorID string, offset, pageSize int) (recipeInfo *model.PagedInfo, err error) { _, userID := ctx.GetMobileAndUserID() - recipeList, err = dao.QueryFoodRecipes(dao.GetDB(), keyword, 0, authorID, userID) - return recipeList, err + recipeList, totalCount, err := dao.QueryFoodRecipes(dao.GetDB(), keyword, 0, authorID, userID, offset, pageSize) + if err == nil { + recipeInfo = &model.PagedInfo{ + TotalCount: totalCount, + Data: recipeList, + } + } + return recipeInfo, err } -func GetRecommendFoodRecipes(ctx *jxcontext.Context, keyword string) (recipeList []*model.FoodRecipe, err error) { +func GetRecommendFoodRecipes(ctx *jxcontext.Context, keyword string, offset, pageSize int) (recipeInfo *model.PagedInfo, err error) { _, userID := ctx.GetMobileAndUserID() - recipeList, err = dao.GetRecommendFoodRecipes(dao.GetDB(), keyword, userID) - return recipeList, err + recipeList, totalCount, err := dao.GetRecommendFoodRecipes(dao.GetDB(), keyword, userID, offset, pageSize) + if err == nil { + recipeInfo = &model.PagedInfo{ + TotalCount: totalCount, + Data: recipeList, + } + } + return recipeInfo, err } func GetRecipeDetail(ctx *jxcontext.Context, recipeID int) (recipeDetail *FoodRecipeDetail, err error) { _, userID := ctx.GetMobileAndUserID() db := dao.GetDB() - recipeList, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID) + recipeList, _, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID, 0, 0) if err != nil { return nil, err } @@ -231,7 +243,7 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error) } db := dao.GetDB() - recipeList, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID) + recipeList, _, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID, 0, 0) if err != nil { return err } @@ -274,7 +286,7 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error) recipe.DownvoteCount-- } - if recipeUser.ActionType&actionMask != 0 || recipeUser.ActionType&(model.RecipeActionUpvote|model.RecipeActionDownvote) == 0 { + if recipeUser.ActionType&actionMask != 0 || (recipeUser.ActionType&(model.RecipeActionUpvote|model.RecipeActionDownvote) == 0 && voteType == 0) { return fmt.Errorf("已经做过此操作了") } diff --git a/controllers/cms_food_recipe.go b/controllers/cms_food_recipe.go index 95637cbb5..dd1f47273 100644 --- a/controllers/cms_food_recipe.go +++ b/controllers/cms_food_recipe.go @@ -72,13 +72,15 @@ func (c *FoodRecipeController) UpdateFoodRecipe() { // @Description 查询菜谱列表 // @Param token header string true "认证token" // @Param keyword query string false "关键字" -// @Param userID query string false "厂商ID" +// @Param authorID query string false "创建者ID" +// @Param offset query int false "菜谱列表起始序号(以0开始,缺省为0)" +// @Param pageSize query int false "菜谱列表页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /QueryFoodRecipes [get] func (c *FoodRecipeController) QueryFoodRecipes() { c.callQueryFoodRecipes(func(params *tFoodrecipeQueryFoodRecipesParams) (retVal interface{}, errCode string, err error) { - retVal, err = userstore.QueryFoodRecipes(params.Ctx, params.Keyword, params.UserID) + retVal, err = userstore.QueryFoodRecipes(params.Ctx, params.Keyword, params.AuthorID, params.Offset, params.PageSize) return retVal, "", err }) } @@ -87,12 +89,14 @@ func (c *FoodRecipeController) QueryFoodRecipes() { // @Description 得到我的推荐菜谱列表 // @Param token header string true "认证token" // @Param keyword query string false "关键字" +// @Param offset query int false "菜谱列表起始序号(以0开始,缺省为0)" +// @Param pageSize query int false "菜谱列表页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /GetRecommendFoodRecipes [get] func (c *FoodRecipeController) GetRecommendFoodRecipes() { c.callGetRecommendFoodRecipes(func(params *tFoodrecipeGetRecommendFoodRecipesParams) (retVal interface{}, errCode string, err error) { - retVal, err = userstore.GetRecommendFoodRecipes(params.Ctx, params.Keyword) + retVal, err = userstore.GetRecommendFoodRecipes(params.Ctx, params.Keyword, params.Offset, params.PageSize) return retVal, "", err }) } From c4c5afb6f91b18b01124aedc39547040835ac1a0 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 17:46:56 +0800 Subject: [PATCH 05/12] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E8=8F=9C=E8=B0=B1B?= =?UTF-8?q?UG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/userstore/food_recipe.go | 4 ++-- controllers/cms_food_recipe.go | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/business/userstore/food_recipe.go b/business/userstore/food_recipe.go index 18352903c..70e9c733f 100644 --- a/business/userstore/food_recipe.go +++ b/business/userstore/food_recipe.go @@ -266,7 +266,7 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error) RecipeID: recipeID, UserID: userID, } - if err = dao.GetEntity(db, recipeUser); err != nil { + if err = dao.GetEntity(db, recipeUser, "RecipeID", "UserID"); err != nil { if !dao.IsNoRowsError(err) { return err } @@ -290,7 +290,7 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error) return fmt.Errorf("已经做过此操作了") } - recipeUser.ActionType &= actionMask | ^(model.RecipeActionUpvote | model.RecipeActionDownvote) + recipeUser.ActionType = (recipeUser.ActionType & ^(model.RecipeActionUpvote | model.RecipeActionDownvote)) | actionMask if recipeUser.ID == 0 { dao.WrapAddIDCULDEntity(recipeUser, ctx.GetUserName()) err = dao.CreateEntity(db, recipeUser) diff --git a/controllers/cms_food_recipe.go b/controllers/cms_food_recipe.go index dd1f47273..09d697211 100644 --- a/controllers/cms_food_recipe.go +++ b/controllers/cms_food_recipe.go @@ -17,7 +17,7 @@ type FoodRecipeController struct { // @Param name formData string true "菜谱名" // @Param description formData string true "菜谱描述" // @Param img formData string true "图片"" -// @Param timeInMinute formData string true "大约需要时间(分钟)" +// @Param timeInMinute formData int true "大约需要时间(分钟)" // @Param recipeItems formData string true "菜谱配料" // @Param recipeSteps formData string true "菜谱步骤" // @Success 200 {object} controllers.CallResult @@ -32,9 +32,10 @@ func (c *FoodRecipeController) CreateFoodRecipe() { ) if err = jxutils.Strings2Objs(params.RecipeItems, &itemList, params.RecipeSteps, &stepList); err == nil { foodRecipe = &model.FoodRecipe{ - Name: params.Name, - Description: params.Description, - Img: params.Img, + Name: params.Name, + Description: params.Description, + Img: params.Img, + TimeInMinute: params.TimeInMinute, } err = userstore.CreateFoodRecipe(params.Ctx, foodRecipe, itemList, stepList) } @@ -49,7 +50,7 @@ func (c *FoodRecipeController) CreateFoodRecipe() { // @Param name formData string false "菜谱名" // @Param description formData string false "菜谱描述" // @Param img formData string false "图片"" -// @Param timeInMinute formData string false "大约需要时间(分钟)" +// @Param timeInMinute formData int false "大约需要时间(分钟)" // @Param recipeItems formData string false "菜谱配料" // @Param recipeSteps formData string false "菜谱步骤" // @Success 200 {object} controllers.CallResult From b140091b3368e42ac7b608c075ab59c1450b1640 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 17:57:54 +0800 Subject: [PATCH 06/12] =?UTF-8?q?-=20=E8=8F=9C=E8=B0=B1=E9=85=8D=E6=96=99?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=AD=EF=BC=8C=E8=BF=94=E5=9B=9Esku?= =?UTF-8?q?=E7=9A=84=E5=90=8D=E5=AD=97=E4=B8=8E=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/food_recipe.go | 22 ++++++++++++++++++++-- business/userstore/food_recipe.go | 11 +++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/business/model/dao/food_recipe.go b/business/model/dao/food_recipe.go index a18a7d843..7d4e9f184 100644 --- a/business/model/dao/food_recipe.go +++ b/business/model/dao/food_recipe.go @@ -10,6 +10,20 @@ type FoodRecipeWithAction struct { ActionType int8 `json:"actionType"` } +type FoodRecipeItemChoiceExt struct { + model.FoodRecipeItemChoice + + Img string `orm:"size(255)" json:"img"` + SkuName string `json:"skuName"` + + Prefix string `json:"-"` + SkuNameName string `orm:"column(sku_name_name)" json:"-"` + Unit string `orm:"size(8)" json:"-"` + SpecQuality float32 `json:"-"` + SpecUnit string `json:"-"` + Comment string `json:"-"` +} + func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string, offset, pageSize int) (recipeList []*FoodRecipeWithAction, totalCount int, err error) { var sql string var sqlParams []interface{} @@ -91,10 +105,14 @@ func QueryFoodRecipesItems(db *DaoDB, recipeID int) (recipeItemList []*model.Foo return recipeItemList, err } -func QueryFoodRecipesItemChoices(db *DaoDB, recipeID int) (recipeItemChoiceList []*model.FoodRecipeItemChoice, err error) { +func QueryFoodRecipesItemChoices(db *DaoDB, recipeID int) (recipeItemChoiceList []*FoodRecipeItemChoiceExt, err error) { sql := ` - SELECT t1.* + SELECT t1.*, + t2.spec_quality, t2.spec_unit, t2.comment, + t3.img, t3.prefix, t3.name sku_name_name, t3.unit FROM food_recipe_item_choice t1 + LEFT JOIN sku t2 ON t2.id = t1.sku_id + LEFT JOIN sku_name t3 ON t3.id = t2.name_id WHERE t1.deleted_at = ? AND t1.recipe_id = ?` sqlParams := []interface{}{ utils.DefaultTimeValue, diff --git a/business/userstore/food_recipe.go b/business/userstore/food_recipe.go index 70e9c733f..91de214e6 100644 --- a/business/userstore/food_recipe.go +++ b/business/userstore/food_recipe.go @@ -3,6 +3,8 @@ package userstore import ( "fmt" + "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" @@ -21,13 +23,13 @@ type FoodRecipeStepParam struct { type FoodRecipeItem struct { model.FoodRecipeItem - ItemChoiceList []*model.FoodRecipeItemChoice + ItemChoiceList []*dao.FoodRecipeItemChoiceExt `json:"itemChoiceList"` } type FoodRecipeDetail struct { model.FoodRecipe - ItemList []*FoodRecipeItem - StepList []*model.FoodRecipeStep + ItemList []*FoodRecipeItem `json:"itemList"` + StepList []*model.FoodRecipeStep `json:"stepList"` } func updateFoodRecipeItemAndStep(ctx *jxcontext.Context, db *dao.DaoDB, recipeID int, itemList []*FoodRecipeItemParam, stepList []*FoodRecipeStepParam) (err error) { @@ -213,8 +215,9 @@ func GetRecipeDetail(ctx *jxcontext.Context, recipeID int) (recipeDetail *FoodRe if err != nil { return nil, err } - choiceMap := make(map[int8][]*model.FoodRecipeItemChoice) + choiceMap := make(map[int8][]*dao.FoodRecipeItemChoiceExt) for _, v := range itemChoiceList { + v.SkuName = jxutils.ComposeSkuName(v.Prefix, v.SkuNameName, v.Comment, v.Unit, v.SpecQuality, v.SpecUnit, 0) choiceMap[v.Index] = append(choiceMap[v.Index], v) } From 9a7ab6425f6a62db565e4badd7e2428bebc30a42 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 18:15:55 +0800 Subject: [PATCH 07/12] =?UTF-8?q?-=20=E6=B4=BB=E5=8A=A8=E5=87=BA=E9=94=99?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=BF=94=E5=9B=9E=E6=9C=80=E7=BB=88=E7=9A=84?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index bb0b24dcd..a680bc4ec 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -32,7 +32,9 @@ type ActOrderRuleParam struct { type ActStoreSkuParam struct { model.ActStoreSku - ErrMsg string `json:"errMsg"` + + ActualActPrice int64 `json:"actualActPrice,omitempty"` // 单品级活动用,创建活动时商品的活动价格 + ErrMsg string `json:"errMsg,omitempty"` } type ActDetail struct { @@ -153,6 +155,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac } if err2 := checkDiscountValidation(act.Type, int(actSkuMap.ActualActPrice*100/actSkuMap.VendorPrice)); err2 != nil { v.ErrMsg = err2.Error() + v.ActualActPrice = actSkuMap.ActualActPrice wrongSkuList = append(wrongSkuList, v) } else { dao.WrapAddIDCULDEntity(actSkuMap, ctx.GetUserName()) @@ -275,7 +278,11 @@ func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto func checkDiscountValidation(actType int, pricePercentage int) (err error) { if actType == model.ActSkuDirectDown && (pricePercentage < minDiscount4SkuDirectDown || pricePercentage > 99) { - err = fmt.Errorf("%s活动折扣必须大于:%d, 且必须有折扣", model.ActTypeName[actType], minDiscount4SkuDirectDown) + if pricePercentage < minDiscount4SkuDirectDown { + err = fmt.Errorf("%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDown) + } else if pricePercentage > 99 { + err = fmt.Errorf("%s活动必须有折扣", model.ActTypeName[actType]) + } } else if actType == model.ActSkuSecKill && pricePercentage > maxDiscount4SkuSecKill { err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill) } From 025b2b0cfd27d81138567d8cfc7cc4d6c94d3342 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 18:22:06 +0800 Subject: [PATCH 08/12] + DeleteRecipes --- business/userstore/food_recipe.go | 24 ++++++++++++++++++++++++ controllers/cms_food_recipe.go | 17 +++++++++++++++++ routers/commentsRouter_controllers.go | 9 +++++++++ 3 files changed, 50 insertions(+) diff --git a/business/userstore/food_recipe.go b/business/userstore/food_recipe.go index 91de214e6..ab3d074e8 100644 --- a/business/userstore/food_recipe.go +++ b/business/userstore/food_recipe.go @@ -312,3 +312,27 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error) dao.Commit(db) return err } + +func DeleteRecipes(ctx *jxcontext.Context, recipeIDs []int) (num int64, err error) { + db := dao.GetDB() + dao.Begin(db) + defer func() { + if r := recover(); r != nil || err != nil { + dao.Rollback(db) + if r != nil { + panic(r) + } + } + }() + for _, recipeID := range recipeIDs { + recipe := &model.FoodRecipe{} + recipe.ID = recipeID + num2, err2 := dao.DeleteEntityLogically(db, recipe, nil, ctx.GetUserName(), nil) + if err = err2; err != nil { + return 0, err + } + num += num2 + } + dao.Commit(db) + return 0, err +} diff --git a/controllers/cms_food_recipe.go b/controllers/cms_food_recipe.go index 09d697211..932b06d8c 100644 --- a/controllers/cms_food_recipe.go +++ b/controllers/cms_food_recipe.go @@ -130,3 +130,20 @@ func (c *FoodRecipeController) VoteFoodRecipe() { return retVal, "", err }) } + +// @Title 删除菜谱 +// @Description 删除菜谱 +// @Param token header string true "认证token" +// @Param recipeIDs query string true "菜谱ID列表" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /DeleteRecipes [delete] +func (c *FoodRecipeController) DeleteRecipes() { + c.callDeleteRecipes(func(params *tFoodrecipeDeleteRecipesParams) (retVal interface{}, errCode string, err error) { + var recipeIDs []int + if err = jxutils.Strings2Objs(params.RecipeIDs, &recipeIDs); err == nil { + retVal, err = userstore.DeleteRecipes(params.Ctx, recipeIDs) + } + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 0ae93a495..5baa4b15a 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -493,6 +493,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"], + beego.ControllerComments{ + Method: "DeleteRecipes", + Router: `/DeleteRecipes`, + AllowHTTPMethods: []string{"delete"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"], beego.ControllerComments{ Method: "GetRecipeDetail", From d5b31014cafbea3fa5f138fd1e4479fa9567faba Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 21:16:30 +0800 Subject: [PATCH 09/12] =?UTF-8?q?-=20=E4=B8=B4=E6=97=B6=E7=A6=81=E6=AD=A2?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=97=B6=E5=B9=B3=E5=8F=B0=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E7=9A=84=E6=8A=A5=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index dcee5ff63..76551f092 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -356,7 +356,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo isAdded2Update := false // 修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改 if (model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) || (model.IsSyncStatusSeq(sku.StoreSkuSyncStatus) && reorderHandler == nil)) && singleStoreHandler != nil { - if dao.IsVendorThingIDEmpty(sku.VendorCatID) { + if false { //dao.IsVendorThingIDEmpty(sku.VendorCatID) { globals.SugarLogger.Warnf("syncStoreSkuNew 修改门店:%d商品:%d,但没有平台分类ID", sku.StoreID, sku.SkuID) } else { isAdded2Update = true From 26221afaef9cf208277040c21d95a311eadd0882 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 21:44:04 +0800 Subject: [PATCH 10/12] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8Ddao.GetSkusCategori?= =?UTF-8?q?es=E6=B2=A1=E6=9C=89=E5=8F=96=E5=85=A8=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/store_sku.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index b456a3aad..2d4e56575 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -111,8 +111,8 @@ func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int t4p.name parent_cat_name, t5p.id parent_map_id, t5p.%s_id parent_vendor_cat_id, t5p.%s_sync_status parent_cat_sync_status FROM store_sku_bind t1 - JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ? AND t2.status = ? - JOIN sku_name t3 ON t2.name_id = t3.id AND t3.deleted_at = ? AND t3.status = ? + JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ? + JOIN sku_name t3 ON t2.name_id = t3.id AND t3.deleted_at = ? ` if level == 2 { sql += ` @@ -128,26 +128,27 @@ func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int LEFT JOIN store_sku_category_map t5 ON t4.id = t5.category_id AND t5.store_id = t1.store_id AND t5.deleted_at = ? LEFT JOIN sku_category t4p ON t4.parent_id = t4p.id LEFT JOIN store_sku_category_map t5p ON t4p.id = t5p.category_id AND t5p.store_id = t1.store_id AND t5p.deleted_at = ? - WHERE t1.deleted_at = ? AND t1.store_id = ? AND t1.status = ? + WHERE t1.deleted_at = ? AND t1.store_id = ? AND ((t1.status = ? AND t2.status = ? AND t3.status = ?) OR (t1.%s_sync_status & ? = 0)) ` sqlParams := []interface{}{ utils.DefaultTimeValue, - model.SkuStatusNormal, utils.DefaultTimeValue, - model.SkuStatusNormal, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, storeID, model.SkuStatusNormal, + model.SkuStatusNormal, + model.SkuStatusNormal, + model.SyncFlagNewMask | model.SyncFlagDeletedMask, } if len(skuIDs) > 0 { sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")" sqlParams = append(sqlParams, skuIDs) } fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID]) - sql = fmt.Sprintf(sql, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix) + sql = fmt.Sprintf(sql, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix) if err = GetRows(db, &cats, sql, sqlParams...); err != nil { return nil, err } From d919b5d9f145a7a7755a340abe38282d32ed5699 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 17 Sep 2019 21:48:24 +0800 Subject: [PATCH 11/12] - up --- business/model/dao/store_sku.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 2d4e56575..c90b7f118 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -102,6 +102,7 @@ type StoreSkuNameInfo struct { UnitPrice int64 } +// todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑 // 单门店模式厂商适用 // 从store_sku_bind中,得到所有依赖的商家分类信息 func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int) (cats []*SkuStoreCatInfo, err error) { From 96bb72f87a76809c4e0b716f1ff978c327cec77a Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 18 Sep 2019 08:23:40 +0800 Subject: [PATCH 12/12] - dao.GetSkusCategories --- business/model/dao/store_sku.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index c90b7f118..78e31a26f 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -129,7 +129,7 @@ func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int LEFT JOIN store_sku_category_map t5 ON t4.id = t5.category_id AND t5.store_id = t1.store_id AND t5.deleted_at = ? LEFT JOIN sku_category t4p ON t4.parent_id = t4p.id LEFT JOIN store_sku_category_map t5p ON t4p.id = t5p.category_id AND t5p.store_id = t1.store_id AND t5p.deleted_at = ? - WHERE t1.deleted_at = ? AND t1.store_id = ? AND ((t1.status = ? AND t2.status = ? AND t3.status = ?) OR (t1.%s_sync_status & ? = 0)) + WHERE t1.deleted_at = ? AND t1.%s_sync_status & ? = 0 AND t1.store_id = ? AND ((t1.status = ? AND t2.status = ? AND t3.status = ?) OR (t1.%s_sync_status & ? = 0)) ` sqlParams := []interface{}{ utils.DefaultTimeValue, @@ -138,18 +138,19 @@ func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, + model.SyncFlagDeletedMask, storeID, model.SkuStatusNormal, model.SkuStatusNormal, model.SkuStatusNormal, - model.SyncFlagNewMask | model.SyncFlagDeletedMask, + model.SyncFlagNewMask, } if len(skuIDs) > 0 { sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")" sqlParams = append(sqlParams, skuIDs) } fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID]) - sql = fmt.Sprintf(sql, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix) + sql = fmt.Sprintf(sql, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix, fieldPrefix) if err = GetRows(db, &cats, sql, sqlParams...); err != nil { return nil, err }