From 62f497fcaaa4723aa4d2d80efaff49620f89073e Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 20 Jun 2019 16:08:26 +0800 Subject: [PATCH] - up --- business/jxstore/act/act.go | 60 ++++++++++++++++++++++++++----------- business/model/act.go | 8 +++++ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index e97ed4a05..25e7a3be7 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -25,15 +25,9 @@ type ActOrderRuleParam struct { } type ActStoreSkuParam struct { + model.ActStoreSku + Action int // -1删除,1修改,2新增 - - StoreID int `orm:"column(store_id)" json:"storeID"` - SkuID int `orm:"column(sku_id)" json:"skuID"` - - PricePercentage int `orm:"" json:"pricePercentage"` // 单品级活动用,SKU级的价格比例,非0覆盖Act中的PricePercentage - ActPrice int64 `orm:"" json:"actPrice"` // 单品级活动用,SKU级指定的价格,非0覆盖CustomPricePercentage与Act中的PricePercentage - - Stock int `orm:"" json:"stock"` // 订单级活动用 } type ActDetail struct { @@ -117,15 +111,9 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, act *model.Act, vendorIDs [] for _, v := range oneStoreSkuParam { if validSkuMap[v.SkuID] == 1 { if storeSkuInfo := storeSkuMap[genStoreSkuMapKey(v.StoreID, v.SkuID)]; storeSkuInfo != nil { - storeSku := &model.ActStoreSku{ - ActID: act.ID, - StoreID: v.StoreID, - SkuID: v.SkuID, - OriginalPrice: int64(storeSkuInfo.Price), - PricePercentage: v.PricePercentage, - ActPrice: v.ActPrice, - Stock: v.Stock, - } + storeSku := &v.ActStoreSku + storeSku.ActID = act.ID + storeSku.OriginalPrice = int64(storeSkuInfo.Price) dao.WrapAddIDCULDEntity(storeSku, ctx.GetUserName()) actStoreSkuList = append(actStoreSkuList, storeSku) } @@ -262,6 +250,44 @@ func CancelAct(ctx *jxcontext.Context, actID int) (err error) { return err } +func DeleteActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreSkuParam) (err error) { + storeIDMap := make(map[int]int) + skuIDMap := make(map[int]int) + actStoreSkuParamMap := make(map[int64]*ActStoreSkuParam) + for _, v := range actStoreSku { + storeIDMap[v.StoreID] = 1 + skuIDMap[v.SkuID] = 1 + actStoreSkuParamMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = v + } + + db := dao.GetDB() + actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, jxutils.IntMap2List(storeIDMap), jxutils.IntMap2List(skuIDMap)) + if err != nil { + return err + } + dao.Begin(db) + defer func() { + if r := recover(); r != nil || err != nil { + dao.Rollback(db) + if r != nil { + panic(r) + } + } + }() + for _, v := range actStoreSkuMap { + for _, storeSku := range v { + storeSku.SyncStatus |= model.SyncFlagDeletedMask + if param := actStoreSkuParamMap[jxutils.Combine2Int(storeSku.StoreID, storeSku.SkuID)]; param != nil { + if _, err = dao.UpdateEntity(db, storeSku); err != nil { + return err + } + } + } + } + dao.Commit(db) + return err +} + func SyncAct(ctx *jxcontext.Context, actID int, vendorIDs, storeIDs, skuIDs []int) (err error) { var actOrderRules []*model.ActOrderRule db := dao.GetDB() diff --git a/business/model/act.go b/business/model/act.go index 188729be6..f42d7df44 100644 --- a/business/model/act.go +++ b/business/model/act.go @@ -3,6 +3,7 @@ package model import "time" const ( + ActSkuFake = 0 // 假活动,只用于存储活动结算信息 ActSkuDirectDown = 1 ActSkuSecKill = 2 @@ -103,10 +104,17 @@ type ActStoreSku struct { OriginalPrice int64 `orm:"" json:"originalPrice"` // 单品级活动用,创建活动时商品的原始京西价 PricePercentage int `orm:"" json:"pricePercentage"` // 单品级活动用,SKU级的价格比例,非0覆盖Act中的PricePercentage ActPrice int64 `orm:"" json:"actPrice"` // 单品级活动用,SKU级指定的价格,非0覆盖CustomPricePercentage与Act中的PricePercentage + EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱 Stock int `orm:"" json:"stock"` // 订单级活动用 } +func (*ActStoreSku) TableUnique() [][]string { + return [][]string{ + []string{"ActID", "SkuID", "StoreID", "DeletedAt"}, + } +} + type ActStoreSkuMap struct { ModelIDCULD