- up
This commit is contained in:
@@ -257,9 +257,7 @@ func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
isStoreSkuAllDeleted := true
|
||||
for _, actStoreSku := range actStoreSkuMap[actStore.StoreID] {
|
||||
if actStoreSku == nil || actStoreSkuParamMap[jxutils.Combine2Int(actStoreSku.StoreID, actStoreSku.SkuID)] != nil {
|
||||
objActStoreSkuMap := &model.ActStoreSkuMap{}
|
||||
objActStoreSkuMap.ID = actStoreSku.MapID
|
||||
if _, err = dao.UpdateEntityLogically(db, objActStoreSkuMap, map[string]interface{}{
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.ActStoreSku2ActStoreSkuMap(actStoreSku), map[string]interface{}{
|
||||
model.FieldSyncStatus: actStoreSku.SyncStatus | model.SyncFlagDeletedMask,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
return err
|
||||
@@ -269,7 +267,7 @@ func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
}
|
||||
}
|
||||
if isStoreSkuAllDeleted {
|
||||
if _, err = dao.UpdateEntityLogically(db, &actStore.ActStoreMap, map[string]interface{}{
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.ActStore2ActStoreMap(actStore), map[string]interface{}{
|
||||
model.FieldSyncStatus: actStore.SyncStatus | model.SyncFlagDeletedMask,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
return err
|
||||
@@ -281,9 +279,7 @@ func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
}
|
||||
|
||||
if isStoreAllDeleted {
|
||||
objActMap := &model.ActMap{}
|
||||
objActMap.ID = act.MapID
|
||||
if _, err = dao.UpdateEntityLogically(db, objActMap, map[string]interface{}{
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.Act2ActMap(act), map[string]interface{}{
|
||||
model.FieldSyncStatus: act.SyncStatus | model.SyncFlagDeletedMask,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
return err
|
||||
|
||||
@@ -30,3 +30,19 @@ func SplitActStoreSku(actStoreSkuList []*model.ActStoreSku2) (actStoreSkuMap map
|
||||
}
|
||||
return actStoreSkuMap
|
||||
}
|
||||
|
||||
func Act2ActMap(act *model.Act2) (actMap *model.ActMap) {
|
||||
actMap = &model.ActMap{}
|
||||
actMap.ID = act.MapID
|
||||
return actMap
|
||||
}
|
||||
|
||||
func ActStore2ActStoreMap(actStore *model.ActStore2) (actStoreMap *model.ActStoreMap) {
|
||||
return &actStore.ActStoreMap
|
||||
}
|
||||
|
||||
func ActStoreSku2ActStoreSkuMap(actStoreSku *model.ActStoreSku2) (actStoreSkuMap *model.ActStoreSkuMap) {
|
||||
actStoreSkuMap = &model.ActStoreSkuMap{}
|
||||
actStoreSkuMap.ID = actStoreSku.MapID
|
||||
return actStoreSkuMap
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package jd
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -15,6 +17,12 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type LogicUpdateInfo struct {
|
||||
Item interface{}
|
||||
KVs map[string]interface{}
|
||||
Condition map[string]interface{}
|
||||
}
|
||||
|
||||
func CreatePromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
@@ -125,51 +133,40 @@ func storeSku2Jd(actStoreSku []*model.ActStoreSku2, handler func(syncStatus int)
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
if act.Type < model.ActOrderBegin {
|
||||
outInfoID := utils.Int2Str(act.ID)
|
||||
infoID, err2 := CreatePromotionInfos(act.Type, act.Name, act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceID)
|
||||
if err = err2; err == nil {
|
||||
act.VendorActID = utils.Int64ToStr(infoID)
|
||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitDevice, act.LimitPin, act.LimitCount, act.LimitDaily, traceID); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceID); err == nil {
|
||||
err = ConfirmPromotion(act.Type, infoID, "", traceID)
|
||||
}
|
||||
}
|
||||
}
|
||||
act.VendorActID, err = createSkuAct(ctx, act, actStoreSku)
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.ActStoreSku2) (vendorActID string, err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
if act.Type < model.ActOrderBegin {
|
||||
outInfoID := utils.Int2Str(act.ID)
|
||||
if !utils.IsTimeZero(act.EndAt) {
|
||||
if err = AdjustPromotionTime(act.Type, 0, outInfoID, act.EndAt, traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if toBeDeleted := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(toBeDeleted) > 0 {
|
||||
if err = CancelPromotionSku(act.Type, 0, outInfoID, toBeDeleted, traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// if toBeAdded := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(toBeAdded) > 0 {
|
||||
// if _, err = CreatePromotionSku(act.Type, 0, outInfoID, toBeAdded, traceID); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// if toBeUpdated := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(toBeUpdated) > 0 {
|
||||
// if _, err = AdjustPromotionSku(act.Type, 0, outInfoID, toBeUpdated, traceID); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
|
||||
outInfoID := ""
|
||||
if act.VendorActID == "" {
|
||||
outInfoID = utils.Int2Str(act.ID)
|
||||
}
|
||||
infoID, err2 := CreatePromotionInfos(act.Type, act.Name, act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceID)
|
||||
if err = err2; err == nil {
|
||||
vendorActID = utils.Int64ToStr(infoID)
|
||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitDevice, act.LimitPin, act.LimitCount, act.LimitDaily, traceID); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceID); err == nil {
|
||||
err = ConfirmPromotion(act.Type, infoID, "", traceID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return vendorActID, err
|
||||
}
|
||||
|
||||
func cancelSkuActSkus(ctx *jxcontext.Context, actType int, vendorActID string, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if skuList := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(skuList) > 0 {
|
||||
err = CancelPromotionSku(actType, utils.Str2Int64(vendorActID), "", skuList, getTraceID(ctx))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -181,3 +178,102 @@ func (c *PurchaseHandler) CancelAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreList []*model.ActStore2, actStoreSkuList []*model.ActStoreSku2) (err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
|
||||
actStoreMap := partner.SplitActStore(actStoreList)
|
||||
actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuList)
|
||||
var actStoreSkuList4Create, actStoreSkuList4Delete []*model.ActStoreSku2
|
||||
var okList []*LogicUpdateInfo
|
||||
for _, actStore := range actStoreMap {
|
||||
for _, actStoreSku := range actStoreSkuMap[actStore.StoreID] {
|
||||
if model.IsSyncStatusNeedCreate(actStoreSku.SyncStatus) {
|
||||
if actStore.VendorActID == "" {
|
||||
actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku)
|
||||
} else {
|
||||
if actStoreSku.VendorActID, err = createSkuAct(ctx, act, []*model.ActStoreSku2{actStoreSku}); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(actStoreSku),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldVendorActID: actStoreSku.VendorActID,
|
||||
},
|
||||
})
|
||||
}
|
||||
} else if model.IsSyncStatusNeedDelete(actStoreSku.SyncStatus) {
|
||||
if actStoreSku.VendorActID == "" {
|
||||
actStoreSkuList4Delete = append(actStoreSkuList4Delete, actStoreSku)
|
||||
} else {
|
||||
if err = CancelPromotion(act.Type, utils.Str2Int64(actStoreSku.VendorActID), "", traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(actStoreSku),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldDeletedAt: time.Now(),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if actStore.VendorActID != "" {
|
||||
if model.IsSyncStatusDelete(actStore.SyncStatus) {
|
||||
if err = CancelPromotion(act.Type, utils.Str2Int64(actStore.VendorActID), "", traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStore2ActStoreMap(actStore),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldDeletedAt: time.Now(),
|
||||
},
|
||||
})
|
||||
|
||||
} else if len(actStoreSkuList4Delete) > 0 {
|
||||
if err = cancelSkuActSkus(ctx, act.Type, actStore.VendorActID, actStoreSkuList4Delete); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, v := range actStoreSkuList4Delete {
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(v),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldDeletedAt: time.Now(),
|
||||
},
|
||||
})
|
||||
}
|
||||
actStoreSkuList4Delete = nil
|
||||
}
|
||||
|
||||
if act.VendorActID != "" {
|
||||
if len(actStoreSkuList4Create) > 0 {
|
||||
if actStore.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
|
||||
return err
|
||||
}
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStore2ActStoreMap(actStore),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
},
|
||||
})
|
||||
for _, v := range actStoreSkuList4Create {
|
||||
okList = append(okList, &LogicUpdateInfo{
|
||||
Item: partner.ActStoreSku2ActStoreSkuMap(v),
|
||||
KVs: map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
actStoreSkuList4Create = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
// db := dao.GetDB()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user