StoreSkuAct
This commit is contained in:
@@ -13,6 +13,11 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
type StoreSkuAndAct struct {
|
||||
*model.StoreSkuBind
|
||||
ActMap map[int]*model.StoreSkuAct
|
||||
}
|
||||
|
||||
var (
|
||||
dataResFieldMap = map[int]string{
|
||||
model.VendorIDMTWM: "mtwm_url",
|
||||
@@ -796,6 +801,55 @@ func GetStoresSkusInfo(db *DaoDB, storeIDs, skuIDs []int) (storeSkuList []*model
|
||||
return storeSkuList, err
|
||||
}
|
||||
|
||||
func GetStoresSkusAndActInfo(db *DaoDB, storeIDs, skuIDs, vendorIDs []int) (storeSkuAndActList []*StoreSkuAndAct, err error) {
|
||||
storeSkuList, err := GetStoresSkusInfo(db, storeIDs, skuIDs)
|
||||
if err == nil && len(storeSkuList) > 0 {
|
||||
storeSkuActList, err2 := GetStoresSkusAct(db, storeIDs, skuIDs, vendorIDs)
|
||||
if err = err2; err == nil {
|
||||
actMap := make(map[int64][]*model.StoreSkuAct)
|
||||
for _, v := range storeSkuActList {
|
||||
actMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] = append(actMap[jxutils.Combine2Int(v.StoreID, v.SkuID)], v)
|
||||
}
|
||||
for _, v := range storeSkuList {
|
||||
storeSkuAct := &StoreSkuAndAct{
|
||||
StoreSkuBind: v,
|
||||
ActMap: make(map[int]*model.StoreSkuAct),
|
||||
}
|
||||
for _, vv := range actMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] {
|
||||
storeSkuAct.ActMap[vv.VendorID] = vv
|
||||
}
|
||||
storeSkuAndActList = append(storeSkuAndActList, storeSkuAct)
|
||||
}
|
||||
}
|
||||
}
|
||||
return storeSkuAndActList, err
|
||||
}
|
||||
|
||||
func GetStoresSkusAct(db *DaoDB, storeIDs, skuIDs, vendorIDs []int) (storeSkuActList []*model.StoreSkuAct, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM store_sku_act t1
|
||||
WHERE t1.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
err = GetRows(db, &storeSkuActList, sql, sqlParams...)
|
||||
return storeSkuActList, err
|
||||
}
|
||||
|
||||
// vendorID, vendorStoreIDs和vendorSkuIDs都是必须参数
|
||||
func GetStoresSkusInfoByVendorInfo(db *DaoDB, vendorID int, vendorStoreIDs, vendorSkuIDs []string) (storeSkuList []*StoreSkuBindWithVendorInfo, err error) {
|
||||
if len(vendorStoreIDs) == 0 || len(vendorSkuIDs) == 0 {
|
||||
|
||||
@@ -161,3 +161,32 @@ func (*StoreOpRequest) TableIndex() [][]string {
|
||||
[]string{"StoreID", "Status", "Type"},
|
||||
}
|
||||
}
|
||||
|
||||
type StoreSkuAct struct {
|
||||
ModelIDCULD // DeletedAt用于表示请求操作结束,而并不一定是删除
|
||||
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
SkuID int `orm:"column(sku_id)"`
|
||||
VendorID int
|
||||
|
||||
ActID int `orm:"column(act_id);index" json:"actID"`
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48);index" json:"vendorActID"`
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
VendorPrice int64 `json:"vendorPrice"` // 创建活动时的平台价格
|
||||
ActualActPrice int64 `json:"actualActPrice"` // 单品级活动用,创建活动时商品的活动价格
|
||||
|
||||
EarningActID int `orm:"column(earning_act_id);index" json:"earningActID"`
|
||||
EarningPrice int `json:"earningPrice"`
|
||||
}
|
||||
|
||||
func (*StoreSkuAct) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreID", "SkuID", "VendorID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*StoreSkuAct) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"SkuID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,9 @@ var (
|
||||
)
|
||||
|
||||
// 是否按单一门店商品维度创建活动
|
||||
func isCreateTypeSingle() bool {
|
||||
return !globals.IsProductEnv()
|
||||
func isCreateTypeSingleStoreSku() bool {
|
||||
return false
|
||||
// return !globals.IsProductEnv()
|
||||
}
|
||||
|
||||
func splitPromotionSku(skus []*jdapi.PromotionSku, maxCount int) (skusList [][]*jdapi.PromotionSku) {
|
||||
@@ -219,6 +220,23 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
||||
return vendorActID, err
|
||||
}
|
||||
|
||||
func proxyCreateSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.ActStoreSku2) (vendorActID string, err error) {
|
||||
if isCreateTypeSingleStoreSku() && len(actStoreSku) > 1 {
|
||||
errList := errlist.New()
|
||||
vendorActID := act.VendorActID
|
||||
act.VendorActID = "placeholder"
|
||||
for _, v := range actStoreSku {
|
||||
_, err := createSkuAct(ctx, act, []*model.ActStoreSku2{v})
|
||||
errList.AddErr(err)
|
||||
}
|
||||
act.VendorActID = vendorActID
|
||||
err = errList.GetErrListAsOne()
|
||||
} else {
|
||||
vendorActID, err = createSkuAct(ctx, act, actStoreSku)
|
||||
}
|
||||
return vendorActID, err
|
||||
}
|
||||
|
||||
func cancelSkuActSkus(ctx *jxcontext.Context, act *model.Act2, vendorActID string, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if vendorActID != "" {
|
||||
if skuList := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(skuList) > 0 {
|
||||
@@ -282,7 +300,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
} else if model.IsSyncStatusNew(act.SyncStatus) {
|
||||
if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err == nil {
|
||||
if act.VendorActID, err = proxyCreateSkuAct(ctx, act, actStoreSkuList4Create); err == nil {
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask))
|
||||
} else {
|
||||
@@ -294,7 +312,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
} else if model.IsSyncStatusUpdate(act.SyncStatus) {
|
||||
errList := errlist.New()
|
||||
if len(actStoreSkuList4Create) > 0 {
|
||||
if _, err = createSkuAct(ctx, act, actStoreSkuList4Create); err == nil {
|
||||
if _, err = proxyCreateSkuAct(ctx, act, actStoreSkuList4Create); err == nil {
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
} else {
|
||||
errList.AddErr(err)
|
||||
|
||||
@@ -56,6 +56,8 @@ func Init() {
|
||||
orm.RegisterModel(&model.OrderFinancial{}, &model.AfsOrder{}, &model.OrderDiscountFinancial{}, &model.OrderSkuFinancial{})
|
||||
orm.RegisterModel(&model.Act{}, &model.ActOrderRule{}, &model.ActStoreSku{})
|
||||
orm.RegisterModel(&model.ActMap{}, &model.ActStoreSkuMap{})
|
||||
// orm.RegisterModel(&model.StoreSkuAct{})
|
||||
|
||||
orm.RegisterModel(&model.NewConfig{})
|
||||
|
||||
orm.RegisterModel(&model.CasbinRule{})
|
||||
|
||||
Reference in New Issue
Block a user