From db38799bf8b2a7d6933e5956538d5e3f4a962a8a Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Wed, 9 Jun 2021 15:14:04 +0800 Subject: [PATCH] aa --- business/jxstore/act/act.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 6ae86d5b5..0b6b335ae 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -644,6 +644,10 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, vendorOr } func CreateActForMtByOrder(ctx *jxcontext.Context, act *model.Act, vendorID int, vendorOrgCode string, actStoreSku []*ActStoreSkuParam) (err error) { + var ( + db = dao.GetDB() + actStoreSkuMap = make(map[int][]*model.StoreSkuBind) + ) if vendorID != model.VendorIDMTWM { return fmt.Errorf("此接口只支持美团使用!") } @@ -651,7 +655,29 @@ func CreateActForMtByOrder(ctx *jxcontext.Context, act *model.Act, vendorID int, return fmt.Errorf("此接口只支持创建直降!") } setActDefault(act) - db := dao.GetDB() + //处理actStoreSku + //参数有可能传多个店多个商品,先分好组:map = [门店ID][]{商品ID1,商品ID2},[门店ID][]{商品ID1,商品ID3,商品ID4} + for _, v := range actStoreSku { + if resultList, _ := dao.GetStoresSkusInfo(db, []int{v.StoreID}, []int{v.SkuID}); len(resultList) > 0 { + actStoreSkuMap[v.StoreID] = append(actStoreSkuMap[v.StoreID], &model.StoreSkuBind{ + SkuID: v.SkuID, + MtwmPrice: resultList[0].MtwmPrice, + }) + } + } + //根据平台价排序 + for _, storeSkus := range actStoreSkuMap { + for i := 0; i < len(storeSkus)-1; i++ { + for j := 0; j < len(storeSkus)-i-1; j++ { + if storeSkus[j].MtwmPrice < storeSkus[j+1].MtwmPrice { + temp := storeSkus[j].MtwmPrice + storeSkus[j].MtwmPrice = storeSkus[j+1].MtwmPrice + storeSkus[j+1].MtwmPrice = temp + } + } + } + } + fmt.Println("1111111111111111111111111111", utils.Format4Output(actStoreSkuMap, true)) txDB, _ := dao.Begin(db) defer func() { if r := recover(); r != nil { @@ -676,6 +702,7 @@ func CreateActForMtByOrder(ctx *jxcontext.Context, act *model.Act, vendorID int, dao.Rollback(db, txDB) return err } + dao.Commit(db, txDB) return err }