- 京东CreatePromotionSku超限处理
- 活动名字防重复 - 活动限购设置
This commit is contained in:
@@ -12,10 +12,6 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
ActionTypeNA = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
type ActOrderRuleParam struct {
|
type ActOrderRuleParam struct {
|
||||||
SalePrice int64 `orm:"" json:"salePrice"` // 满的价格
|
SalePrice int64 `orm:"" json:"salePrice"` // 满的价格
|
||||||
DeductPrice int64 `orm:"" json:"deductPrice"` // 减的价格
|
DeductPrice int64 `orm:"" json:"deductPrice"` // 减的价格
|
||||||
@@ -23,8 +19,6 @@ type ActOrderRuleParam struct {
|
|||||||
|
|
||||||
type ActStoreSkuParam struct {
|
type ActStoreSkuParam struct {
|
||||||
model.ActStoreSku
|
model.ActStoreSku
|
||||||
|
|
||||||
Action int // -1删除,1修改,2新增
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActDetail struct {
|
type ActDetail struct {
|
||||||
@@ -199,7 +193,10 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
|||||||
panic(r)
|
panic(r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
if act.LimitCount == 0 {
|
||||||
|
act.LimitCount = 1 // 缺省限购一份,如果确定不限,明确给一个很大的值
|
||||||
|
}
|
||||||
|
act.Status = model.ActStatusCreated
|
||||||
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
||||||
err = dao.CreateEntity(db, act)
|
err = dao.CreateEntity(db, act)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -318,7 +315,6 @@ func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isDeleteAll || isDeleteAtLeastOne {
|
if isDeleteAll || isDeleteAtLeastOne {
|
||||||
// globals.SugarLogger.Debugf("isDeleteAll:%t", isDeleteAll)
|
|
||||||
syncStatus := model.SyncFlagModifiedMask
|
syncStatus := model.SyncFlagModifiedMask
|
||||||
if isDeleteAll {
|
if isDeleteAll {
|
||||||
syncStatus = model.SyncFlagDeletedMask
|
syncStatus = model.SyncFlagDeletedMask
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ActSkuFake = 0 // 假活动,只用于存储活动结算信息
|
ActSkuFake = 0 // 假活动,只用于存储活动结算信息
|
||||||
@@ -27,15 +31,22 @@ type Act struct {
|
|||||||
Advertising string `orm:"size(255)" json:"advertising"`
|
Advertising string `orm:"size(255)" json:"advertising"`
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
LimitDevice int `json:"limitDevice"`
|
LimitUser int `json:"limitUser"` // 是否按用户限制
|
||||||
LimitPin int `json:"limitPin"`
|
LimitDaily int `json:"limitDaily"` // 每日限购单数
|
||||||
LimitDaily int `json:"limitDaily"`
|
LimitCount int `json:"limitCount"` // 第单限购数量
|
||||||
LimitCount int `json:"limitCount"`
|
|
||||||
Source string `orm:"size(255)" json:"source"`
|
Source string `orm:"size(255)" json:"source"`
|
||||||
CreateType int `json:"createType"`
|
CreateType int `json:"createType"`
|
||||||
PricePercentage int `json:"pricePercentage"` // 单品级活动才有效
|
PricePercentage int `json:"pricePercentage"` // 单品级活动才有效
|
||||||
BeginAt time.Time `orm:"type(datetime);index;null" json:"beginAt"`
|
BeginAt time.Time `orm:"type(datetime);index;null" json:"beginAt"`
|
||||||
EndAt time.Time `orm:"type(datetime);index;null" json:"endAt"`
|
EndAt time.Time `orm:"type(datetime);index;null" json:"endAt"`
|
||||||
|
|
||||||
|
Remark string `orm:"size(255)" json:"remark"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Act) TableUnique() [][]string {
|
||||||
|
return [][]string{
|
||||||
|
[]string{"Name", "Type", "DeletedAt"},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActMap struct {
|
type ActMap struct {
|
||||||
@@ -65,6 +76,13 @@ type Act2 struct {
|
|||||||
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Act2) GetRealActName() string {
|
||||||
|
if IsSyncStatusNeedCreate(a.SyncStatus) {
|
||||||
|
return a.Name
|
||||||
|
}
|
||||||
|
return a.Name + "_" + utils.Int64ToStr(time.Now().Unix())
|
||||||
|
}
|
||||||
|
|
||||||
type ActOrderRule struct {
|
type ActOrderRule struct {
|
||||||
ModelIDCULD
|
ModelIDCULD
|
||||||
|
|
||||||
@@ -77,17 +95,17 @@ type ActStoreSku struct {
|
|||||||
ModelIDCULD
|
ModelIDCULD
|
||||||
|
|
||||||
ActID int `orm:"column(act_id)" json:"actID"`
|
ActID int `orm:"column(act_id)" json:"actID"`
|
||||||
|
|
||||||
|
OriginalPrice int64 `orm:"" json:"originalPrice"` // 单品级活动用,创建活动时商品的原始京西价
|
||||||
|
|
||||||
|
// 以下字段,API中有效
|
||||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||||
|
|
||||||
// LocalStatus int // 这个状态是多个平台的
|
|
||||||
// RemoteStatus int // 这个状态是多个平台的
|
|
||||||
OriginalPrice int64 `orm:"" json:"originalPrice"` // 单品级活动用,创建活动时商品的原始京西价
|
|
||||||
PricePercentage int `orm:"" json:"pricePercentage"` // 单品级活动用,SKU级的价格比例,非0覆盖Act中的PricePercentage
|
PricePercentage int `orm:"" json:"pricePercentage"` // 单品级活动用,SKU级的价格比例,非0覆盖Act中的PricePercentage
|
||||||
ActPrice int64 `orm:"" json:"actPrice"` // 单品级活动用,SKU级指定的价格,非0覆盖CustomPricePercentage与Act中的PricePercentage
|
ActPrice int64 `orm:"" json:"actPrice"` // 单品级活动用,SKU级指定的价格,非0覆盖CustomPricePercentage与Act中的PricePercentage
|
||||||
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
||||||
|
Stock int `orm:"" json:"stock"` // 活动库存
|
||||||
Stock int `orm:"" json:"stock"` // 订单级活动用
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ActStoreSku) TableUnique() [][]string {
|
func (*ActStoreSku) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ func actStoreSu2Ebai4Add(oneStoreActSku []*model.ActStoreSku2) (skus []*ebaiapi.
|
|||||||
skus = append(skus, &ebaiapi.ActivitySkuInfo4Add{
|
skus = append(skus, &ebaiapi.ActivitySkuInfo4Add{
|
||||||
SkuID: v.VendorSkuID,
|
SkuID: v.VendorSkuID,
|
||||||
SpecialPrice: v.ActPrice,
|
SpecialPrice: v.ActPrice,
|
||||||
|
Stock: v.Stock,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,6 +50,7 @@ func actStoreSu2Ebai4Update(oneStoreActSku []*model.ActStoreSku2) (skus []*ebaia
|
|||||||
ShopID: utils.Int2Str(v.StoreID),
|
ShopID: utils.Int2Str(v.StoreID),
|
||||||
SkuID: v.VendorSkuID,
|
SkuID: v.VendorSkuID,
|
||||||
SpecialPrice: v.ActPrice,
|
SpecialPrice: v.ActPrice,
|
||||||
|
Stock: v.Stock,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,13 +68,20 @@ func actStoreSu2Ebai4Delete(oneStoreActSku []*model.ActStoreSku2) (skus []string
|
|||||||
|
|
||||||
func act2EbaiActivity(act *model.Act2, actOrderRules []*model.ActOrderRule) (activity *ebaiapi.ActivityInfo) {
|
func act2EbaiActivity(act *model.Act2, actOrderRules []*model.ActOrderRule) (activity *ebaiapi.ActivityInfo) {
|
||||||
activity = &ebaiapi.ActivityInfo{
|
activity = &ebaiapi.ActivityInfo{
|
||||||
ActivityName: act.Name,
|
ActivityName: act.GetRealActName(),
|
||||||
ActivityType: actType2Ebai(act.Type),
|
ActivityType: actType2Ebai(act.Type),
|
||||||
StartTime: act.BeginAt.Unix(),
|
StartTime: act.BeginAt.Unix(),
|
||||||
EndTime: act.EndAt.Unix(),
|
EndTime: act.EndAt.Unix(),
|
||||||
ActivityDesc: act.Advertising,
|
ActivityDesc: act.Advertising,
|
||||||
ShowCategory: act.Name,
|
ShowCategory: act.Name,
|
||||||
PromotionSkuDesc: act.Name,
|
PromotionSkuDesc: act.Name,
|
||||||
|
DayLimit: act.LimitDaily,
|
||||||
|
}
|
||||||
|
if act.LimitCount > 0 {
|
||||||
|
activity.OrderLimit = act.LimitCount
|
||||||
|
}
|
||||||
|
if activity.DayLimit == 0 {
|
||||||
|
activity.DayLimit = 999
|
||||||
}
|
}
|
||||||
if actOrderRules != nil {
|
if actOrderRules != nil {
|
||||||
activity.Rule = actOrderRules2Ebai(actOrderRules)
|
activity.Rule = actOrderRules2Ebai(actOrderRules)
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func storeSku2Jd(actStoreSku []*model.ActStoreSku2, handler func(syncStatus int)
|
|||||||
StationNo: utils.Str2Int64(v.VendorStoreID),
|
StationNo: utils.Str2Int64(v.VendorStoreID),
|
||||||
SkuID: utils.Str2Int64(v.VendorSkuID),
|
SkuID: utils.Str2Int64(v.VendorSkuID),
|
||||||
PromotionPrice: v.ActPrice,
|
PromotionPrice: v.ActPrice,
|
||||||
// LimitSkuCount:0,
|
LimitSkuCount: v.Stock,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,10 +161,10 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
|||||||
if act.VendorActID == "" {
|
if act.VendorActID == "" {
|
||||||
outInfoID = utils.Int2Str(act.ID)
|
outInfoID = utils.Int2Str(act.ID)
|
||||||
}
|
}
|
||||||
infoID, err2 := CreatePromotionInfos(act.Type, act.Name, act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceID)
|
infoID, err2 := CreatePromotionInfos(act.Type, act.GetRealActName(), act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceID)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
vendorActID = utils.Int64ToStr(infoID)
|
vendorActID = utils.Int64ToStr(infoID)
|
||||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitDevice, act.LimitPin, act.LimitCount, act.LimitDaily, traceID); err == nil {
|
if err = CreatePromotionRules(act.Type, infoID, "", 0, act.LimitUser, act.LimitCount, act.LimitDaily, traceID); err == nil {
|
||||||
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceID); err == nil {
|
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceID); err == nil {
|
||||||
if err = ConfirmPromotion(act.Type, infoID, "", traceID); err == nil {
|
if err = ConfirmPromotion(act.Type, infoID, "", traceID); err == nil {
|
||||||
for _, v := range actStoreSku {
|
for _, v := range actStoreSku {
|
||||||
|
|||||||
@@ -24,15 +24,23 @@ func actOrderRules2Mtwm(actOrderRules []*model.ActOrderRule) (actDetails []*mtwm
|
|||||||
}
|
}
|
||||||
|
|
||||||
func storeSku2ActData(act *model.Act2, actStoreSku []*model.ActStoreSku2, handler func(int) bool) (actData []*mtwmapi.RetailDiscountActData) {
|
func storeSku2ActData(act *model.Act2, actStoreSku []*model.ActStoreSku2, handler func(int) bool) (actData []*mtwmapi.RetailDiscountActData) {
|
||||||
|
orderLimit := 1
|
||||||
|
if act.LimitCount > 0 {
|
||||||
|
orderLimit = act.LimitCount
|
||||||
|
}
|
||||||
for _, v := range actStoreSku {
|
for _, v := range actStoreSku {
|
||||||
if handler == nil || handler(v.SyncStatus) {
|
if handler == nil || handler(v.SyncStatus) {
|
||||||
|
dayLimit := -1
|
||||||
|
if v.Stock > 0 {
|
||||||
|
dayLimit = v.Stock
|
||||||
|
}
|
||||||
actData = append(actData, &mtwmapi.RetailDiscountActData{
|
actData = append(actData, &mtwmapi.RetailDiscountActData{
|
||||||
AppFoodCode: utils.Int2Str(v.SkuID),
|
AppFoodCode: utils.Int2Str(v.SkuID),
|
||||||
// UserType: 0,
|
// UserType: 0,
|
||||||
StartTime: act.BeginAt.Unix(),
|
StartTime: act.BeginAt.Unix(),
|
||||||
EndTime: act.EndAt.Unix(),
|
EndTime: act.EndAt.Unix(),
|
||||||
OrderLimit: act.LimitCount,
|
OrderLimit: orderLimit,
|
||||||
DayLimit: act.LimitDaily,
|
DayLimit: dayLimit,
|
||||||
// Period: "",
|
// Period: "",
|
||||||
// WeeksTime: "",
|
// WeeksTime: "",
|
||||||
SettingType: mtwmapi.SettingTypeAsPrice,
|
SettingType: mtwmapi.SettingTypeAsPrice,
|
||||||
|
|||||||
Reference in New Issue
Block a user