- PreCreateAct
This commit is contained in:
@@ -47,6 +47,25 @@ type ActVendorInfo struct {
|
||||
VendorList []*ActMapPureInfo
|
||||
}
|
||||
|
||||
type tPreCreateActVendorInfo struct {
|
||||
VendorID int
|
||||
|
||||
VendorPrice int64 `orm:"" json:"vendorPrice"` // 单品级活动用,创建活动时商品的原始平台价
|
||||
ActualActPrice int64 `orm:"" json:"actualActPrice"` // 单品级活动用,创建活动时商品的活动价格
|
||||
}
|
||||
|
||||
type tPreCreateActStoreSku struct {
|
||||
model.ActStoreSku
|
||||
VendorInfoList []*tPreCreateActVendorInfo `json:"vendorInfoList"`
|
||||
}
|
||||
|
||||
type tPreCreateActInfo struct {
|
||||
model.Act
|
||||
|
||||
ValidVendorIDs []int
|
||||
ActStoreSku []*tPreCreateActStoreSku `json:"actStoreSku"`
|
||||
}
|
||||
|
||||
func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Act, vendorIDs []int, actStoreSku []*ActStoreSkuParam) (validVendorIDs []int, actStoreSkuList []*model.ActStoreSku, actStoreSkuMapList []*model.ActStoreSkuMap, err error) {
|
||||
wholeValidVendorMap := make(map[int]int)
|
||||
if len(actStoreSku) > 0 {
|
||||
@@ -84,7 +103,8 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac
|
||||
SkuID: v.SkuID,
|
||||
VendorID: vendorID,
|
||||
|
||||
SyncStatus: model.SyncFlagNewMask,
|
||||
SyncStatus: model.SyncFlagNewMask,
|
||||
VendorPrice: int64(jxutils.CaculateSkuVendorPrice(storeSkuInfo.Price, int(storeDetail.PricePercentage), 0)),
|
||||
}
|
||||
if v.ActPrice != 0 {
|
||||
actSkuMap.ActualActPrice = v.ActPrice
|
||||
@@ -93,8 +113,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac
|
||||
if v.PricePercentage != 0 {
|
||||
percentage = v.PricePercentage
|
||||
}
|
||||
percentage = percentage * int(storeDetail.PricePercentage) / 100
|
||||
actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(storeSkuInfo.Price, percentage, 0))
|
||||
actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage, 0))
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actSkuMap, ctx.GetUserName())
|
||||
actStoreSkuMapList = append(actStoreSkuMapList, actSkuMap)
|
||||
@@ -245,10 +264,53 @@ func checkActValidation(act *model.Act, vendorIDs []int) (err error) {
|
||||
return fmt.Errorf("%s", strings.Join(strList, ",\n"))
|
||||
}
|
||||
|
||||
func setActDefault(act *model.Act) {
|
||||
if act.LimitCount == 0 {
|
||||
act.LimitCount = 1 // 缺省限购一份,如果确定不限,明确给一个很大的值
|
||||
}
|
||||
act.Status = model.ActStatusCreated
|
||||
}
|
||||
|
||||
func PreCreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (preCreateActInfo *tPreCreateActInfo, err error) {
|
||||
if err = checkActValidation(act, vendorIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
setActDefault(act)
|
||||
|
||||
db := dao.GetDB()
|
||||
validVendorIDs, actStoreSkuList, actStoreSkuMapList, err := ActStoreSkuParam2Model(ctx, db, act, vendorIDs, actStoreSku)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
preCreateActInfo = &tPreCreateActInfo{
|
||||
ValidVendorIDs: validVendorIDs,
|
||||
}
|
||||
storeSkuMap := make(map[int64]*tPreCreateActStoreSku)
|
||||
for _, v := range actStoreSkuList {
|
||||
tmp := &tPreCreateActStoreSku{
|
||||
ActStoreSku: *v,
|
||||
}
|
||||
storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = tmp
|
||||
preCreateActInfo.ActStoreSku = append(preCreateActInfo.ActStoreSku, tmp)
|
||||
}
|
||||
|
||||
for _, v := range actStoreSkuMapList {
|
||||
index := jxutils.Combine2Int(v.StoreID, v.SkuID)
|
||||
storeSkuMap[index].VendorInfoList = append(storeSkuMap[index].VendorInfoList, &tPreCreateActVendorInfo{
|
||||
VendorID: v.VendorID,
|
||||
VendorPrice: v.VendorPrice,
|
||||
ActualActPrice: v.ActualActPrice,
|
||||
})
|
||||
}
|
||||
return preCreateActInfo, nil
|
||||
}
|
||||
|
||||
func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam, isAsync bool) (hint string, err error) {
|
||||
if err = checkActValidation(act, vendorIDs); err != nil {
|
||||
return "", err
|
||||
}
|
||||
setActDefault(act)
|
||||
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
@@ -258,10 +320,6 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if act.LimitCount == 0 {
|
||||
act.LimitCount = 1 // 缺省限购一份,如果确定不限,明确给一个很大的值
|
||||
}
|
||||
act.Status = model.ActStatusCreated
|
||||
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, act)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user