- 根据京东回调存储京东到家活动信息至本地
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user