- 重构新京西活动,平台接口定为笼统的SyncAct,京平台支持添加,删除商品,暂不支持修改
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
package act
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
@@ -33,7 +31,8 @@ type ActDetail struct {
|
||||
model.Act2
|
||||
}
|
||||
|
||||
func ActStoreSkuParam2Model(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actStoreSku []*ActStoreSkuParam) (actMapList []*model.ActMap, actStoreMapList []*model.ActStoreMap, actStoreSkuList []*model.ActStoreSku, actStoreSkuMapList []*model.ActStoreSkuMap, err error) {
|
||||
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 {
|
||||
storeIDMap := make(map[int]int)
|
||||
skuIDMap := make(map[int]int)
|
||||
@@ -43,18 +42,16 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, act *model.Act, vendorIDs []
|
||||
skuIDMap[v.SkuID] = 1
|
||||
storeSkuParamMap[v.StoreID] = append(storeSkuParamMap[v.StoreID], v)
|
||||
}
|
||||
db := dao.GetDB()
|
||||
|
||||
storeSkuList, err2 := dao.GetStoresSkusInfo(db, jxutils.IntMap2List(storeIDMap), jxutils.IntMap2List(skuIDMap))
|
||||
if err = err2; err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
storeSkuMap := make(map[int64]*model.StoreSkuBind)
|
||||
for _, v := range storeSkuList {
|
||||
storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = v
|
||||
}
|
||||
|
||||
wholeValidVendorMap := make(map[int]int)
|
||||
for storeID, oneStoreSkuParam := range storeSkuParamMap {
|
||||
validVendorMap := make(map[int]int)
|
||||
validSkuMap := make(map[int]int)
|
||||
@@ -87,15 +84,16 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, act *model.Act, vendorIDs []
|
||||
actStoreSkuMapList = append(actStoreSkuMapList, actSkuMap)
|
||||
}
|
||||
}
|
||||
wholeValidVendorMap[vendorID] = 1
|
||||
} else if !dao.IsNoRowsError(err) {
|
||||
return nil, nil, nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range oneStoreSkuParam {
|
||||
if validSkuMap[v.SkuID] == 1 {
|
||||
if validSkuMap[v.SkuID] == 1 { // todo 这里是否需要判断
|
||||
if storeSkuInfo := storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)]; storeSkuInfo != nil {
|
||||
storeSku := &v.ActStoreSku
|
||||
storeSku.ActID = act.ID
|
||||
@@ -105,40 +103,12 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, act *model.Act, vendorIDs []
|
||||
}
|
||||
}
|
||||
}
|
||||
for vendorID := range validVendorMap {
|
||||
wholeValidVendorMap[vendorID] = 1
|
||||
actStoreMap := &model.ActStoreMap{
|
||||
ActID: act.ID,
|
||||
StoreID: storeID,
|
||||
VendorID: vendorID,
|
||||
|
||||
SyncStatus: model.SyncFlagNewMask,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actStoreMap, ctx.GetUserName())
|
||||
actStoreMapList = append(actStoreMapList, actStoreMap)
|
||||
}
|
||||
}
|
||||
for vendorID := range wholeValidVendorMap {
|
||||
actMap := &model.ActMap{
|
||||
ActID: act.ID,
|
||||
VendorID: vendorID,
|
||||
|
||||
SyncStatus: model.SyncFlagNewMask,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actMap, ctx.GetUserName())
|
||||
actMapList = append(actMapList, actMap)
|
||||
}
|
||||
}
|
||||
return actMapList, actStoreMapList, actStoreSkuList, actStoreSkuMapList, err
|
||||
return jxutils.IntMap2List(wholeValidVendorMap), actStoreSkuList, actStoreSkuMapList, err
|
||||
}
|
||||
|
||||
func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (actID int, err error) {
|
||||
vendorIDMap := make(map[int]bool)
|
||||
for _, v := range vendorIDs {
|
||||
vendorIDMap[v] = true
|
||||
}
|
||||
db := dao.GetDB()
|
||||
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
||||
func addActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actStoreSkuList []*model.ActStoreSku, actStoreSkuMapList []*model.ActStoreSkuMap) (err error) {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -146,32 +116,108 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
err = dao.CreateEntity(db, act)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
storeSkuMap := make(map[int64]int)
|
||||
for _, v := range actStoreSkuList {
|
||||
err = dao.CreateEntity(db, v)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = v.ID
|
||||
}
|
||||
actMapList, actStoreMapList, actStoreSkuList, actStoreSkuMapList, err := ActStoreSkuParam2Model(ctx, act, vendorIDs, actStoreSku)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, v := range actStoreSkuMapList {
|
||||
v.BindID = storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)]
|
||||
}
|
||||
isEmptyAct := true
|
||||
for _, list := range []interface{}{
|
||||
actMapList, actStoreMapList, actStoreSkuList, actStoreSkuMapList,
|
||||
} {
|
||||
if len(utils.Interface2Slice(list)) > 0 {
|
||||
err = dao.CreateMultiEntities(db, list)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
isEmptyAct = false
|
||||
|
||||
if len(actStoreSkuMapList) > 0 {
|
||||
err = dao.CreateMultiEntities(db, actStoreSkuMapList)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if isEmptyAct {
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
|
||||
func AddActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreSkuParam) (err error) {
|
||||
db := dao.GetDB()
|
||||
var vendorIDs []int
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for vendorID := range actMap {
|
||||
vendorIDs = append(vendorIDs, vendorID)
|
||||
}
|
||||
var act *model.Act
|
||||
if len(vendorIDs) > 0 {
|
||||
act = &actMap[vendorIDs[0]].Act
|
||||
} else {
|
||||
act = &model.Act{}
|
||||
act.ID = actID
|
||||
if err = dao.GetEntity(db, act); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, actStoreSkuList, actStoreSkuMapList, err := ActStoreSkuParam2Model(ctx, db, act, vendorIDs, actStoreSku)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = addActStoreBind(ctx, db, actStoreSkuList, actStoreSkuMapList)
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (actID int, err error) {
|
||||
db := dao.GetDB()
|
||||
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, act)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, fmt.Errorf("没有门店及SKU满足需求,空操作")
|
||||
return 0, err
|
||||
}
|
||||
|
||||
validVendorIDs, actStoreSkuList, actStoreSkuMapList, err := ActStoreSkuParam2Model(ctx, db, act, vendorIDs, actStoreSku)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var actMapList []*model.ActMap
|
||||
for vendorID := range validVendorIDs {
|
||||
actMap := &model.ActMap{
|
||||
ActID: act.ID,
|
||||
VendorID: vendorID,
|
||||
|
||||
SyncStatus: model.SyncFlagNewMask,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actMap, ctx.GetUserName())
|
||||
actMapList = append(actMapList, actMap)
|
||||
}
|
||||
if len(actMapList) > 0 {
|
||||
err = dao.CreateMultiEntities(db, actMapList)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
if err = addActStoreBind(ctx, db, actStoreSkuList, actStoreSkuMapList); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
dao.Commit(db)
|
||||
|
||||
actID = act.ID
|
||||
err = SyncAct(ctx, actID, nil, nil, nil)
|
||||
return actID, err
|
||||
@@ -185,18 +231,6 @@ func GetActDetail(ctx *jxcontext.Context, actID int) (actDetail *ActDetail, err
|
||||
return actDetail, err
|
||||
}
|
||||
|
||||
// func GetAcVendorInfo(ctx *jxcontext.Context, actID int) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func GetAcStoresVendorInfo(ctx *jxcontext.Context, actID int, storeIDs []int) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func GetAcStoresSkusVendorInfo(ctx *jxcontext.Context, actID int, storeIDs, skuIDs []int) (err error) {
|
||||
// return err
|
||||
// }
|
||||
|
||||
func UpdateAct(ctx *jxcontext.Context, act *model.Act, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (err error) {
|
||||
return err
|
||||
}
|
||||
@@ -214,27 +248,13 @@ func DeleteActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActSto
|
||||
return deleteActStoreBind(ctx, dao.GetDB(), actID, actStoreSku)
|
||||
}
|
||||
|
||||
func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, 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
|
||||
}
|
||||
storeIDs := jxutils.IntMap2List(storeIDMap)
|
||||
skuIDs := jxutils.IntMap2List(skuIDMap)
|
||||
|
||||
func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actStoreSkuParam []*ActStoreSkuParam) (err error) {
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
actStoreMap, err := dao.GetActStoreVendorInfo(db, actID, nil, storeIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, storeIDs, skuIDs)
|
||||
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -248,50 +268,66 @@ func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
}
|
||||
}()
|
||||
|
||||
actStoreSkuParamMap := make(map[int64]*ActStoreSkuParam)
|
||||
for _, v := range actStoreSkuParam {
|
||||
actStoreSkuParamMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = v
|
||||
if _, err = dao.DeleteEntityLogically(db, &model.ActStoreSku{}, nil, ctx.GetUserName(),
|
||||
map[string]interface{}{
|
||||
model.FieldActID: actID,
|
||||
model.FieldStoreID: v.StoreID,
|
||||
model.FieldSkuID: v.SkuID,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
isNeedCancelAct := true
|
||||
for vendorID, act := range actMap {
|
||||
actStoreMap := partner.SplitActStore(actStoreMap[vendorID])
|
||||
isDeleteAll := true
|
||||
isDeleteAtLeastOne := false
|
||||
actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuMap[vendorID])
|
||||
isStoreAllDeleted := true
|
||||
for _, actStore := range actStoreMap {
|
||||
isStoreSkuAllDeleted := true
|
||||
for _, actStoreSku := range actStoreSkuMap[actStore.StoreID] {
|
||||
if actStoreSku == nil || actStoreSkuParamMap[jxutils.Combine2Int(actStoreSku.StoreID, actStoreSku.SkuID)] != nil {
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.ActStoreSku2ActStoreSkuMap(actStoreSku), map[string]interface{}{
|
||||
model.FieldSyncStatus: actStoreSku.SyncStatus | model.SyncFlagDeletedMask,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
for storeID := range actStoreSkuMap {
|
||||
for _, actStoreSku := range actStoreSkuMap[storeID] {
|
||||
if actStoreSkuParam == nil || actStoreSkuParamMap[jxutils.Combine2Int(actStoreSku.StoreID, actStoreSku.SkuID)] != nil {
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.ActStoreSku2ActStoreSkuMap(actStoreSku),
|
||||
map[string]interface{}{
|
||||
model.FieldSyncStatus: actStoreSku.SyncStatus | model.SyncFlagDeletedMask,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
isDeleteAtLeastOne = true
|
||||
} else {
|
||||
isStoreSkuAllDeleted = false
|
||||
isNeedCancelAct = false
|
||||
isDeleteAll = false
|
||||
}
|
||||
}
|
||||
if isStoreSkuAllDeleted {
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.ActStore2ActStoreMap(actStore), map[string]interface{}{
|
||||
model.FieldSyncStatus: actStore.SyncStatus | model.SyncFlagDeletedMask,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
isStoreAllDeleted = false
|
||||
isNeedCancelAct = false
|
||||
}
|
||||
}
|
||||
|
||||
if isStoreAllDeleted {
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.Act2ActMap(act), map[string]interface{}{
|
||||
model.FieldSyncStatus: act.SyncStatus | model.SyncFlagDeletedMask,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
if isDeleteAll || isDeleteAtLeastOne {
|
||||
// globals.SugarLogger.Debugf("isDeleteAll:%t", isDeleteAll)
|
||||
syncStatus := model.SyncFlagModifiedMask
|
||||
if isDeleteAll {
|
||||
syncStatus = model.SyncFlagDeletedMask
|
||||
}
|
||||
syncStatus |= act.SyncStatus
|
||||
if _, err = dao.UpdateEntityLogically(db, partner.Act2ActMap(act),
|
||||
map[string]interface{}{
|
||||
model.FieldSyncStatus: syncStatus,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if isDeleteAll != isNeedCancelAct {
|
||||
globals.SugarLogger.Warnf("deleteActStoreBind, actID:%d isDeleteAll:%t != isNeedCancelAct:%t", act.ID, isDeleteAll, isNeedCancelAct)
|
||||
}
|
||||
}
|
||||
|
||||
if isNeedCancelAct {
|
||||
act := &model.Act{}
|
||||
act.ID = actID
|
||||
if _, err = dao.UpdateEntityLogically(db, act, map[string]interface{}{
|
||||
model.FieldStatus: model.ActStatusCanceled,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
if _, err = dao.UpdateEntityLogically(db, act,
|
||||
map[string]interface{}{
|
||||
model.FieldStatus: model.ActStatusCanceled,
|
||||
}, ctx.GetUserName(), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -300,93 +336,110 @@ func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
}
|
||||
|
||||
func SyncAct(ctx *jxcontext.Context, actID int, vendorIDs, storeIDs, skuIDs []int) (err error) {
|
||||
var actOrderRules []*model.ActOrderRule
|
||||
db := dao.GetDB()
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, vendorIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
actStoreMap, err := dao.GetActStoreVendorInfo(db, actID, vendorIDs, storeIDs)
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, storeIDs, skuIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, vendorIDs, storeIDs, skuIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var realVendorIDs []int
|
||||
for vendorID := range actMap {
|
||||
realVendorIDs = append(realVendorIDs, vendorID)
|
||||
}
|
||||
|
||||
task := tasksch.NewParallelTask("SyncAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := batchItemList[0].(int)
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
if handler == nil {
|
||||
err = fmt.Errorf("不被支持的vendorID:%d", vendorID)
|
||||
} else {
|
||||
act := actMap[vendorID]
|
||||
actStore := actStoreMap[vendorID]
|
||||
actStoreSku := actStoreSkuMap[vendorID]
|
||||
// globals.SugarLogger.Debugf("%s", utils.Format4Output(act, false))
|
||||
// globals.SugarLogger.Debugf("%s", utils.Format4Output(actStore, false))
|
||||
// globals.SugarLogger.Debugf("%s", utils.Format4Output(actStoreSku, false))
|
||||
if act != nil && actStore != nil && actStoreSku != nil {
|
||||
if model.IsSyncStatusNeedCreate(act.SyncStatus) {
|
||||
err = handler.CreateAct(ctx, task, act, actOrderRules, actStore, actStoreSku)
|
||||
} else if model.IsSyncStatusNeedUpdate(act.SyncStatus) {
|
||||
if act.Status == model.ActStatusCanceled {
|
||||
err = handler.CancelAct(ctx, task, act, actStore, actStoreSku)
|
||||
} else {
|
||||
// actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update := splitActStore(actStore)
|
||||
// err = handler.UpdateAct(ctx, task, act, actOrderRules, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update, actStoreSku)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
actMap := &model.ActMap{}
|
||||
actMap.ID = act.MapID
|
||||
dao.UpdateEntityLogically(db, actMap, map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldVendorActID: act.VendorActID,
|
||||
}, ctx.GetUserName(), nil)
|
||||
for _, v := range actStore {
|
||||
storeMap := model.ActStoreMap{}
|
||||
storeMap.ID = v.MapID
|
||||
dao.UpdateEntityLogically(db, storeMap, map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldVendorActID: v.VendorActID,
|
||||
}, ctx.GetUserName(), nil)
|
||||
}
|
||||
for _, v := range actStoreSku {
|
||||
storeSkuMap := model.ActStoreSkuMap{}
|
||||
storeSkuMap.ID = v.MapID
|
||||
dao.UpdateEntityLogically(db, storeSkuMap, map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldVendorActID: v.VendorActID,
|
||||
}, ctx.GetUserName(), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformActHandler); handler != nil {
|
||||
if err = handler.SyncAct(ctx, nil, actMap[vendorID], nil, actStoreSkuMap[vendorID]); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil, err
|
||||
}, realVendorIDs)
|
||||
tasksch.ManageTask(task).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
}
|
||||
return err
|
||||
// var actOrderRules []*model.ActOrderRule
|
||||
// db := dao.GetDB()
|
||||
// actMap, err := dao.GetActVendorInfo(db, actID, vendorIDs)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// actStoreMap, err := dao.GetActStoreVendorInfo(db, actID, vendorIDs, storeIDs)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, vendorIDs, storeIDs, skuIDs)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// var realVendorIDs []int
|
||||
// for vendorID := range actMap {
|
||||
// realVendorIDs = append(realVendorIDs, vendorID)
|
||||
// }
|
||||
|
||||
// task := tasksch.NewParallelTask("SyncAct", nil, ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// vendorID := batchItemList[0].(int)
|
||||
// handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||||
// if handler == nil {
|
||||
// err = fmt.Errorf("不被支持的vendorID:%d", vendorID)
|
||||
// } else {
|
||||
// act := actMap[vendorID]
|
||||
// actStore := actStoreMap[vendorID]
|
||||
// actStoreSku := actStoreSkuMap[vendorID]
|
||||
// // globals.SugarLogger.Debugf("%s", utils.Format4Output(act, false))
|
||||
// // globals.SugarLogger.Debugf("%s", utils.Format4Output(actStore, false))
|
||||
// // globals.SugarLogger.Debugf("%s", utils.Format4Output(actStoreSku, false))
|
||||
// if act != nil && actStore != nil && actStoreSku != nil {
|
||||
// if model.IsSyncStatusNeedCreate(act.SyncStatus) {
|
||||
// err = handler.CreateAct(ctx, task, act, actOrderRules, actStore, actStoreSku)
|
||||
// } else if model.IsSyncStatusNeedUpdate(act.SyncStatus) {
|
||||
// if act.Status == model.ActStatusCanceled {
|
||||
// err = handler.CancelAct(ctx, task, act, actStore, actStoreSku)
|
||||
// } else {
|
||||
// // actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update := splitActStore(actStore)
|
||||
// // err = handler.UpdateAct(ctx, task, act, actOrderRules, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update, actStoreSku)
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// actMap := &model.ActMap{}
|
||||
// actMap.ID = act.MapID
|
||||
// dao.UpdateEntityLogically(db, actMap, map[string]interface{}{
|
||||
// model.FieldSyncStatus: 0,
|
||||
// model.FieldVendorActID: act.VendorActID,
|
||||
// }, ctx.GetUserName(), nil)
|
||||
// for _, v := range actStore {
|
||||
// storeMap := model.ActStoreMap{}
|
||||
// storeMap.ID = v.MapID
|
||||
// dao.UpdateEntityLogically(db, storeMap, map[string]interface{}{
|
||||
// model.FieldSyncStatus: 0,
|
||||
// model.FieldVendorActID: v.VendorActID,
|
||||
// }, ctx.GetUserName(), nil)
|
||||
// }
|
||||
// for _, v := range actStoreSku {
|
||||
// storeSkuMap := model.ActStoreSkuMap{}
|
||||
// storeSkuMap.ID = v.MapID
|
||||
// dao.UpdateEntityLogically(db, storeSkuMap, map[string]interface{}{
|
||||
// model.FieldSyncStatus: 0,
|
||||
// model.FieldVendorActID: v.VendorActID,
|
||||
// }, ctx.GetUserName(), nil)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return nil, err
|
||||
// }, realVendorIDs)
|
||||
// tasksch.ManageTask(task).Run()
|
||||
// _, err = task.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func splitActStore(actStore []*model.ActStore2) (actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2) {
|
||||
for _, v := range actStore {
|
||||
if model.IsSyncStatusNeedDelete(v.SyncStatus) {
|
||||
if !dao.IsVendorThingIDEmpty(v.VendorActID) {
|
||||
actStoreMap2Remove = append(actStoreMap2Remove, v)
|
||||
}
|
||||
} else if model.IsSyncStatusNeedCreate(v.SyncStatus) {
|
||||
actStoreMap2Add = append(actStoreMap2Add, v)
|
||||
} else if model.IsSyncStatusNeedUpdate(v.SyncStatus) {
|
||||
actStoreMap2Update = append(actStoreMap2Update, v)
|
||||
}
|
||||
}
|
||||
return actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update
|
||||
}
|
||||
// func splitActStore(actStore []*model.ActStore2) (actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2) {
|
||||
// for _, v := range actStore {
|
||||
// if model.IsSyncStatusNeedDelete(v.SyncStatus) {
|
||||
// if !dao.IsVendorThingIDEmpty(v.VendorActID) {
|
||||
// actStoreMap2Remove = append(actStoreMap2Remove, v)
|
||||
// }
|
||||
// } else if model.IsSyncStatusNeedCreate(v.SyncStatus) {
|
||||
// actStoreMap2Add = append(actStoreMap2Add, v)
|
||||
// } else if model.IsSyncStatusNeedUpdate(v.SyncStatus) {
|
||||
// actStoreMap2Update = append(actStoreMap2Update, v)
|
||||
// }
|
||||
// }
|
||||
// return actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update
|
||||
// }
|
||||
|
||||
@@ -21,15 +21,15 @@ func init() {
|
||||
|
||||
func TestInitDb(t *testing.T) {
|
||||
dao.ExecuteSQL(dao.GetDB(), `
|
||||
DROP TABLE IF EXISTS act,act_map, act_order_rule, act_store_map, act_store_sku, act_store_sku_map;
|
||||
DROP TABLE IF EXISTS act, act_map, act_order_rule, act_store_sku, act_store_sku_map;
|
||||
`)
|
||||
}
|
||||
|
||||
func TestCreateAct(t *testing.T) {
|
||||
actID, err := CreateAct(jxcontext.AdminCtx, &model.Act{
|
||||
Name: "测试活动2",
|
||||
Name: "测试活动",
|
||||
PricePercentage: 80,
|
||||
}, []int{0, 1, 3}, nil, []*ActStoreSkuParam{
|
||||
}, []int{0}, nil, []*ActStoreSkuParam{
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100119,
|
||||
@@ -68,6 +68,70 @@ func TestCancelAct(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteActStoreBind(t *testing.T) {
|
||||
err := DeleteActStoreBind(jxcontext.AdminCtx, 1, []*ActStoreSkuParam{
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100119,
|
||||
// SkuID: 30828,
|
||||
// },
|
||||
// },
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100119,
|
||||
// SkuID: 30827,
|
||||
// },
|
||||
// },
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100118,
|
||||
SkuID: 30592,
|
||||
},
|
||||
},
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100118,
|
||||
SkuID: 30565,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddActStoreBind(t *testing.T) {
|
||||
err := AddActStoreBind(jxcontext.AdminCtx, 1, []*ActStoreSkuParam{
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100119,
|
||||
// SkuID: 30828,
|
||||
// },
|
||||
// },
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100119,
|
||||
// SkuID: 30827,
|
||||
// },
|
||||
// },
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100118,
|
||||
SkuID: 30592,
|
||||
},
|
||||
},
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100118,
|
||||
SkuID: 30565,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncAct(t *testing.T) {
|
||||
err := SyncAct(jxcontext.AdminCtx, 1, nil, nil, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user