实验StoreSkuAct
This commit is contained in:
@@ -33,6 +33,8 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
batchSize = 1
|
||||
case partner.FuncGetStoreSkusFullInfo:
|
||||
batchSize = 1
|
||||
case partner.FuncCreateActs, partner.FuncCancelActs:
|
||||
batchSize = 1
|
||||
}
|
||||
return batchSize
|
||||
}
|
||||
@@ -460,3 +462,33 @@ func SelectStoreSkuListByOpResult(storeSkuList []*partner.StoreSkuInfo, opResult
|
||||
}
|
||||
return selectedStoreSkuList
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreSkusAct(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
for _, v := range storeSkuList {
|
||||
if vendorActID, err2 := createOneShopAct(putils.GetFixDirectDownAct(storeID, v.SkuID), utils.Int2Str(storeID), putils.StoreSku2ActStoreSku([]*partner.StoreSkuInfo{v})); err2 != nil {
|
||||
failedList = append(failedList, &partner.StoreSkuInfoWithErr{
|
||||
StoreSkuInfo: v,
|
||||
VendoreID: model.VendorIDJD,
|
||||
StoreID: storeID,
|
||||
ErrMsg: err.Error(),
|
||||
})
|
||||
} else {
|
||||
v.VendorActID = vendorActID
|
||||
}
|
||||
}
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CancelActs(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
for _, v := range storeSkuList {
|
||||
if err2 := ActivityDisable(utils.Str2Int64(v.VendorActID), utils.Int2Str(storeID), 0, 0); err2 != nil {
|
||||
failedList = append(failedList, &partner.StoreSkuInfoWithErr{
|
||||
StoreSkuInfo: v,
|
||||
VendoreID: model.VendorIDJD,
|
||||
StoreID: storeID,
|
||||
ErrMsg: err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
switch funcID {
|
||||
case partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice:
|
||||
batchSize = jdapi.MaxStoreSkuBatchSize
|
||||
case partner.FuncCreateActs, partner.FuncCancelActs:
|
||||
batchSize = 1
|
||||
}
|
||||
return batchSize
|
||||
}
|
||||
@@ -259,3 +261,33 @@ func SelectStoreSkuListByResponseList(storeSkuList []*partner.StoreSkuInfo, resp
|
||||
}
|
||||
return selectedStoreSkuList
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreSkusAct(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
for _, v := range storeSkuList {
|
||||
if vendorActID, err2 := createSkuAct(ctx, putils.GetFixDirectDownAct(storeID, v.SkuID), putils.StoreSku2ActStoreSku([]*partner.StoreSkuInfo{v})); err2 != nil {
|
||||
failedList = append(failedList, &partner.StoreSkuInfoWithErr{
|
||||
StoreSkuInfo: v,
|
||||
VendoreID: model.VendorIDJD,
|
||||
StoreID: storeID,
|
||||
ErrMsg: err.Error(),
|
||||
})
|
||||
} else {
|
||||
v.VendorActID = vendorActID
|
||||
}
|
||||
}
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CancelActs(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
for _, v := range storeSkuList {
|
||||
if err2 := cancelSkuAct(ctx, putils.GetFixDirectDownAct(storeID, v.SkuID), v.VendorActID); err2 != nil {
|
||||
failedList = append(failedList, &partner.StoreSkuInfoWithErr{
|
||||
StoreSkuInfo: v,
|
||||
VendoreID: model.VendorIDJD,
|
||||
StoreID: storeID,
|
||||
ErrMsg: err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
@@ -26,3 +26,11 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrg
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (successList []*partner.StoreSkuInfo, err error) {
|
||||
return successList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreSkusAct(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CancelActs(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
@@ -80,22 +80,34 @@ func isCreateOrUpdate(syncStatus int8) bool {
|
||||
return model.IsSyncStatusNeedCreate(syncStatus) || model.IsSyncStatusNeedUpdate(syncStatus)
|
||||
}
|
||||
|
||||
func createOneShopAct(act *model.Act2, vendorStoreID string, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func createOneShopAct(act *model.Act2, vendorStoreID string, actStoreSku []*model.ActStoreSku2) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
actData := storeSku2ActData(act, actStoreSku, isCreateOrUpdate)
|
||||
if len(actData) > 0 {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
actResult, err2 := api.MtwmAPI.RetailDiscountBatchSave(vendorStoreID, jxActType2Mtwm(act.Type), actData)
|
||||
globals.SugarLogger.Debugf("mtwm createOneShopAct err2:%v", err2)
|
||||
actResult, faileInfoList, err2 := api.MtwmAPI.RetailDiscountBatchSave2(vendorStoreID, jxActType2Mtwm(act.Type), actData)
|
||||
// globals.SugarLogger.Debugf("mtwm createOneShopAct err2:%v", err2)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
actResultMap := make(map[string]*mtwmapi.RetailDiscountActResult)
|
||||
for _, v := range actResult {
|
||||
actResultMap[v.AppFoodCode] = v
|
||||
return nil, err
|
||||
}
|
||||
actStoreSkuMap := make(map[int]*model.ActStoreSku2)
|
||||
for _, v := range actStoreSku {
|
||||
if result := actResultMap[utils.Int2Str(v.SkuID)]; result != nil {
|
||||
v.VendorActID = utils.Int64ToStr(result.ActID)
|
||||
actStoreSkuMap[v.SkuID] = v
|
||||
}
|
||||
for _, v := range actResult {
|
||||
if v2 := actStoreSkuMap[int(utils.Str2Int64WithDefault(v.AppFoodCode, 0))]; v2 != nil {
|
||||
v2.VendorActID = utils.Int64ToStr(v.ActID)
|
||||
}
|
||||
}
|
||||
for _, v := range faileInfoList {
|
||||
if v2 := actStoreSkuMap[int(utils.Str2Int64WithDefault(v.AppFoodCode, 0))]; v2 != nil {
|
||||
failedList = append(failedList, &partner.StoreSkuInfoWithErr{
|
||||
StoreSkuInfo: &partner.StoreSkuInfo{
|
||||
SkuID: v2.SkuID,
|
||||
},
|
||||
VendoreID: model.VendorIDMTWM,
|
||||
StoreID: int(utils.Str2Int64WithDefault(vendorStoreID, 0)),
|
||||
ErrMsg: v.ErrorMsg,
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -104,16 +116,16 @@ func createOneShopAct(act *model.Act2, vendorStoreID string, actStoreSku []*mode
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func cancelOneShopAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func cancelOneShopAct(act *model.Act2, vendorStoreID string, actStoreSku []*model.ActStoreSku2) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
if list := storeSku2ActData4Delete(actStoreSku, nil /*model.IsSyncStatusNeedDelete*/); len(list) > 0 {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailDiscountDelete(actStoreSku[0].VendorStoreID, jxActType2Mtwm(act.Type), list)
|
||||
err = api.MtwmAPI.RetailDiscountDelete(vendorStoreID, jxActType2Mtwm(act.Type), list)
|
||||
}
|
||||
}
|
||||
return err
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func getActStoreSkuFromTaskResult(taskReslt []interface{}) (list []*model.ActStoreSku2) {
|
||||
@@ -130,7 +142,7 @@ func createSkuAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.A
|
||||
task := tasksch.NewParallelTask("mtwm createSkuAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
list := batchItemList[0].([]*model.ActStoreSku2)
|
||||
if err = createOneShopAct(act, list[0].VendorStoreID, list); err == nil {
|
||||
if _, err = createOneShopAct(act, list[0].VendorStoreID, list); err == nil {
|
||||
retVal = []interface{}{list}
|
||||
}
|
||||
return retVal, err
|
||||
@@ -146,7 +158,7 @@ func cancelSkuAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.A
|
||||
task := tasksch.NewParallelTask("mtwm cancelSkuAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
actStoreSkuList := batchItemList[0].([]*model.ActStoreSku2)
|
||||
if err = cancelOneShopAct(ctx, act, actStoreSkuList); err == nil {
|
||||
if _, err = cancelOneShopAct(act, actStoreSkuList[0].VendorStoreID, actStoreSkuList); err == nil {
|
||||
retVal = []interface{}{actStoreSkuList}
|
||||
}
|
||||
return retVal, err
|
||||
|
||||
@@ -47,6 +47,10 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
batchSize = 1 // mtwmapi.MaxStoreSkuBatchSize
|
||||
case partner.FuncGetStoreSkusFullInfo:
|
||||
batchSize = 1
|
||||
case partner.FuncCreateActs:
|
||||
batchSize = mtwmapi.MaxRetailDiscountCreateBatchSize
|
||||
case partner.FuncCancelActs:
|
||||
batchSize = mtwmapi.MaxRetailDiscountDeleteBatchSize
|
||||
}
|
||||
return batchSize
|
||||
}
|
||||
@@ -574,3 +578,11 @@ func SelectStoreSkuListByFoodList(storeSkuList interface{}, foodList []*mtwmapi.
|
||||
}
|
||||
return selectedStoreSkuList
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStoreSkusAct(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
return createOneShopAct(putils.GetFixDirectDownAct(storeID, 0), vendorStoreID, putils.StoreSku2ActStoreSku(storeSkuList))
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CancelActs(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
return cancelOneShopAct(putils.GetFixDirectDownAct(storeID, 0), vendorStoreID, putils.StoreSku2ActStoreSku(storeSkuList))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user