- 根据京东回调存储京东到家活动信息至本地
This commit is contained in:
@@ -66,6 +66,18 @@ type tPreCreateActInfo struct {
|
||||
ActStoreSku []*tPreCreateActStoreSku `json:"actStoreSku"`
|
||||
}
|
||||
|
||||
type ActManager struct {
|
||||
}
|
||||
|
||||
var (
|
||||
FixedActManager *ActManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
FixedActManager = &ActManager{}
|
||||
partner.InitActManager(FixedActManager)
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -331,6 +343,9 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(validVendorIDs) == 0 {
|
||||
return "", fmt.Errorf("没有一个合法平台可以创建活动")
|
||||
}
|
||||
|
||||
var actMapList []*model.ActMap
|
||||
for _, vendorID := range validVendorIDs {
|
||||
@@ -364,6 +379,115 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func vendorActInfo2Model(ctx *jxcontext.Context, db *dao.DaoDB, act2 *model.Act2, actStoreSku []*model.ActStoreSku2) (actStoreSkuList []*model.ActStoreSku, actStoreSkuMapList []*model.ActStoreSkuMap, err error) {
|
||||
vendorStoreIDMap := make(map[string]int)
|
||||
vendorSkuIDMap := make(map[string]int)
|
||||
for _, v := range actStoreSku {
|
||||
vendorStoreIDMap[v.VendorStoreID] = 1
|
||||
vendorSkuIDMap[v.VendorSkuID] = 1
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(vendorStoreIDMap, false))
|
||||
globals.SugarLogger.Debug(utils.Format4Output(vendorSkuIDMap, false))
|
||||
|
||||
vendorID := act2.VendorID
|
||||
storeSkuList, err2 := dao.GetStoresSkusInfoByVendorInfo(db, vendorID, jxutils.StringMap2List(vendorStoreIDMap), jxutils.StringMap2List(vendorSkuIDMap))
|
||||
if err = err2; err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
storeSkuMap := make(map[string]*dao.StoreSkuBindWithVendorInfo)
|
||||
for _, v := range storeSkuList {
|
||||
storeSkuMap[v.VendorStoreID+"/"+v.VendorSkuID] = v
|
||||
}
|
||||
|
||||
for _, v := range actStoreSku {
|
||||
if storeSkuInfo := storeSkuMap[v.VendorStoreID+"/"+v.VendorSkuID]; storeSkuInfo != nil {
|
||||
actSku := &model.ActStoreSku{
|
||||
ActID: act2.ID,
|
||||
StoreID: storeSkuInfo.StoreID,
|
||||
SkuID: storeSkuInfo.SkuID,
|
||||
|
||||
Stock: v.Stock,
|
||||
ActPrice: v.ActualActPrice,
|
||||
OriginalPrice: int64(storeSkuInfo.Price),
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actSku, ctx.GetUserName())
|
||||
actStoreSkuList = append(actStoreSkuList, actSku)
|
||||
|
||||
actSkuMap := &model.ActStoreSkuMap{
|
||||
ActID: act2.ID,
|
||||
VendorActID: act2.VendorActID,
|
||||
StoreID: storeSkuInfo.StoreID,
|
||||
SkuID: storeSkuInfo.SkuID,
|
||||
VendorID: vendorID,
|
||||
|
||||
SyncStatus: 0,
|
||||
VendorPrice: 0,
|
||||
ActualActPrice: v.ActualActPrice,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actSkuMap, ctx.GetUserName())
|
||||
actStoreSkuMapList = append(actStoreSkuMapList, actSkuMap)
|
||||
}
|
||||
}
|
||||
return actStoreSkuList, actStoreSkuMapList, err
|
||||
}
|
||||
|
||||
func (a *ActManager) CreateActFromVendor(ctx *jxcontext.Context, act2 *model.Act2, actStoreSku []*model.ActStoreSku2) (actID int, err error) {
|
||||
globals.SugarLogger.Debugf("CreateActFromVendor vendorID:%d, vendorActID:%s", act2.VendorID, act2.VendorActID)
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
act := &act2.Act
|
||||
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, act)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
actMap := &model.ActMap{
|
||||
ActID: act.ID,
|
||||
VendorID: act2.VendorID,
|
||||
VendorActID: act2.VendorActID,
|
||||
SyncStatus: 0,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actMap, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, actMap)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
actStoreSkuList, actStoreSkuMapList, err := vendorActInfo2Model(ctx, db, act2, actStoreSku)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
if err = addActStoreSkuBind(ctx, db, actStoreSkuList, actStoreSkuMapList); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
dao.Commit(db)
|
||||
|
||||
return act.ID, nil
|
||||
}
|
||||
|
||||
func (a *ActManager) IsVendorActExist(ctx *jxcontext.Context, vendorActID string, vendorID int) (isExist bool) {
|
||||
db := dao.GetDB()
|
||||
actMap := &model.ActMap{
|
||||
VendorActID: vendorActID,
|
||||
VendorID: vendorID,
|
||||
}
|
||||
actMap.DeletedAt = utils.ZeroTimeValue
|
||||
if err := dao.GetEntity(db, actMap, "VendorActID", "VendorID", "DeletedAt"); err == nil {
|
||||
isExist = true
|
||||
}
|
||||
return isExist
|
||||
}
|
||||
|
||||
func QueryActs(ctx *jxcontext.Context, actID int, offset, pageSize int, keyword string, statusList []int, actTypeList []int, storeID, skuID, cityCode int, beginAt, endAt, createdAtFrom, createdAtTo time.Time) (pagedInfo *dao.PagedActListInfo, err error) {
|
||||
return dao.QueryActs(dao.GetDB(), actID, offset, pageSize, keyword, statusList, actTypeList, storeID, skuID, cityCode, beginAt, endAt, createdAtFrom, createdAtTo)
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ package act
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -68,42 +66,49 @@ func TestCreateActOnAlpha(t *testing.T) {
|
||||
|
||||
func TestCreateActOnDev(t *testing.T) {
|
||||
actStoreSkuList := []*ActStoreSkuParam{
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100884,
|
||||
// SkuID: 22716,
|
||||
// },
|
||||
// },
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100884,
|
||||
// SkuID: 22717,
|
||||
// },
|
||||
// },
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100920,
|
||||
// SkuID: 22714,
|
||||
// },
|
||||
// },
|
||||
// &ActStoreSkuParam{
|
||||
// ActStoreSku: model.ActStoreSku{
|
||||
// StoreID: 100920,
|
||||
// SkuID: 22715,
|
||||
// },
|
||||
// },
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100884,
|
||||
SkuID: 22716,
|
||||
},
|
||||
},
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100884,
|
||||
SkuID: 22717,
|
||||
},
|
||||
},
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100920,
|
||||
SkuID: 22714,
|
||||
},
|
||||
},
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100920,
|
||||
SkuID: 22715,
|
||||
StoreID: 100119,
|
||||
SkuID: 26595,
|
||||
},
|
||||
},
|
||||
}
|
||||
actID, err := CreateAct(jxcontext.AdminCtx, &model.Act{
|
||||
Name: "测试活动",
|
||||
PricePercentage: 80,
|
||||
Type: model.ActSkuDirectDown,
|
||||
BeginAt: time.Now().Add(-24 * time.Hour),
|
||||
EndAt: time.Now().Add(10 * 24 * time.Hour),
|
||||
}, []int{model.VendorIDJD, model.VendorIDMTWM /*, model.VendorIDEBAI*/}, nil, actStoreSkuList, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
globals.SugarLogger.Debug(actID)
|
||||
t.Log(utils.Format4Output(actStoreSkuList, true))
|
||||
// actID, err := CreateAct(jxcontext.AdminCtx, &model.Act{
|
||||
// Name: "测试活动",
|
||||
// PricePercentage: 80,
|
||||
// Type: model.ActSkuDirectDown,
|
||||
// BeginAt: time.Now().Add(-24 * time.Hour),
|
||||
// EndAt: time.Now().Add(10 * 24 * time.Hour),
|
||||
// }, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}, nil, actStoreSkuList, false)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// globals.SugarLogger.Debug(actID)
|
||||
}
|
||||
|
||||
func TestCancelAct(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user