- 取消活动同步后,不会删除act_map
- 添加Act.VendorMask用于方便平台查询 - QueryActs添加vendorID参数
This commit is contained in:
@@ -333,6 +333,7 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
if err = checkActValidation(act, vendorIDs); err != nil {
|
||||
return "", err
|
||||
}
|
||||
act.VendorMask = model.GetVendorMask(vendorIDs...)
|
||||
setActDefault(act)
|
||||
|
||||
db := dao.GetDB()
|
||||
@@ -453,6 +454,7 @@ func (a *ActManager) CreateActFromVendor(ctx *jxcontext.Context, act2 *model.Act
|
||||
}
|
||||
}()
|
||||
act := &act2.Act
|
||||
act.VendorMask = model.GetVendorMask(act2.VendorID)
|
||||
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, act)
|
||||
if err != nil {
|
||||
@@ -499,8 +501,8 @@ func (a *ActManager) IsVendorActExist(ctx *jxcontext.Context, vendorActID string
|
||||
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)
|
||||
func QueryActs(ctx *jxcontext.Context, actID int, offset, pageSize int, keyword string, vendorID int, 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, vendorID, statusList, actTypeList, storeID, skuID, cityCode, beginAt, endAt, createdAtFrom, createdAtTo)
|
||||
}
|
||||
|
||||
func GetActVendorInfo(ctx *jxcontext.Context, actID int) (actVendorInfo *ActVendorInfo, err error) {
|
||||
|
||||
@@ -2,10 +2,12 @@ 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"
|
||||
@@ -66,49 +68,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: 100119,
|
||||
SkuID: 26595,
|
||||
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: 100119,
|
||||
// SkuID: 26595,
|
||||
// },
|
||||
// },
|
||||
}
|
||||
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)
|
||||
// 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) {
|
||||
|
||||
@@ -58,8 +58,8 @@ type Act struct {
|
||||
PricePercentage int `json:"pricePercentage"` // 单品级活动才有效
|
||||
BeginAt time.Time `orm:"type(datetime);index" json:"beginAt"`
|
||||
EndAt time.Time `orm:"type(datetime);index" json:"endAt"`
|
||||
|
||||
Remark string `orm:"size(255)" json:"remark"`
|
||||
VendorMask int `json:"-"`
|
||||
Remark string `orm:"size(255)" json:"remark"`
|
||||
}
|
||||
|
||||
func (*Act) TableUnique() [][]string {
|
||||
|
||||
@@ -410,3 +410,10 @@ func IsAfsOrderFinalStatus(status int) bool {
|
||||
const (
|
||||
DefaultEarningPricePercentage = 70 // 门店缺省结算百分比
|
||||
)
|
||||
|
||||
func GetVendorMask(vendorIDs ...int) (vendorMask int) {
|
||||
for _, vendorID := range vendorIDs {
|
||||
vendorMask |= 1 << uint(vendorID)
|
||||
}
|
||||
return vendorMask
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type PagedActListInfo struct {
|
||||
TotalCount int
|
||||
Data []*model.Act
|
||||
TotalCount int `json:"totalCount"`
|
||||
Data []*model.Act `json:"data"`
|
||||
}
|
||||
|
||||
func GetActVendorInfo(db *DaoDB, actID int, vendorIDs []int) (actMap map[int]*model.Act2, err error) {
|
||||
@@ -119,7 +119,7 @@ func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
return actStoreSkuMap, err
|
||||
}
|
||||
|
||||
func QueryActs(db *DaoDB, actID int, offset, pageSize int, keyword string, statusList []int, actTypeList []int, storeID, skuID, cityCode int, beginAt, endAt, createdAtFrom, createdAtTo time.Time) (pagedInfo *PagedActListInfo, err error) {
|
||||
func QueryActs(db *DaoDB, actID int, offset, pageSize int, keyword string, vendorID int, statusList []int, actTypeList []int, storeID, skuID, cityCode int, beginAt, endAt, createdAtFrom, createdAtTo time.Time) (pagedInfo *PagedActListInfo, err error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*
|
||||
@@ -163,6 +163,10 @@ func QueryActs(db *DaoDB, actID int, offset, pageSize int, keyword string, statu
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
if vendorID > 0 {
|
||||
sql += " AND t1.vendor_mask & ? <> 0"
|
||||
sqlParams = append(sqlParams, model.GetVendorMask(vendorID))
|
||||
}
|
||||
if len(statusList) > 0 {
|
||||
sql += " AND t1.status IN (" + GenQuestionMarks(len(statusList)) + ")"
|
||||
sqlParams = append(sqlParams, statusList)
|
||||
@@ -218,33 +222,17 @@ func GetEffectiveActStoreSkuInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuI
|
||||
if utils.IsTimeZero(toTime) {
|
||||
toTime = fromTime
|
||||
}
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT t2.*
|
||||
FROM`
|
||||
sqlParams := []interface{}{}
|
||||
if len(vendorIDs) > 0 {
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, vendorIDs, fromTime, toTime)
|
||||
actSQL := ""
|
||||
if actID > 0 {
|
||||
actSQL = " AND t11.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
sql += fmt.Sprintf(`
|
||||
(
|
||||
SELECT t11.id, t11.begin_at, t11.end_at, t11.status
|
||||
FROM act t11
|
||||
JOIN act_map t12 ON t12.act_id = t11.id AND t12.deleted_at = ? AND t12.vendor_id IN (`+GenQuestionMarks(len(vendorIDs))+`)
|
||||
WHERE t11.begin_at <= ? AND t11.end_at >= ? %s
|
||||
GROUP BY 1,2,3
|
||||
) t1`, actSQL)
|
||||
} else {
|
||||
sql += `
|
||||
act t1`
|
||||
}
|
||||
sql += `
|
||||
FROM act t1
|
||||
JOIN act_store_sku t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
WHERE t1.status = ? AND t1.begin_at <= ? AND t1.end_at >= ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.ActStatusCreated, fromTime, toTime)
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_mask & ? <> 0"
|
||||
sqlParams = append(sqlParams, model.GetVendorMask(vendorIDs...))
|
||||
}
|
||||
if actID > 0 {
|
||||
sql = " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
|
||||
@@ -295,7 +295,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
canceledList, err2 := cancelSkuAct(ctx, nil, vendorActInfoMap)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagDeletedMask)...)
|
||||
if err = err2; err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagDeletedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
} else if model.IsSyncStatusNew(act.SyncStatus) {
|
||||
createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
|
||||
|
||||
@@ -252,7 +252,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
for _, actStoreSkuList := range vendorActInfoMap {
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList, model.SyncFlagDeletedMask)...)
|
||||
}
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagDeletedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
} else if model.IsSyncStatusNew(act.SyncStatus) {
|
||||
if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
|
||||
return err
|
||||
|
||||
@@ -165,7 +165,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
canceledList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagDeletedMask)...)
|
||||
if err = err2; err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagDeletedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
} else if model.IsSyncStatusNew(act.SyncStatus) {
|
||||
createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
|
||||
|
||||
@@ -122,6 +122,7 @@ func (c *ActController) CreateAct() {
|
||||
// @Param cityCode query int false "活动门店所属城市code"
|
||||
// @Param beginAt query string false "开始日期,包括"
|
||||
// @Param endAt query string false "结束日期,包括"
|
||||
// @Param vendorID query int false "包含平台"
|
||||
// @Param typeList query string false "活动类型列表,3:直降,4:秒杀"
|
||||
// @Param statusList query string false "活动状态列表"
|
||||
// @Param storeID query int false "包含门店"
|
||||
@@ -137,7 +138,7 @@ func (c *ActController) QueryActs() {
|
||||
if err == nil {
|
||||
var typeList, statusList []int
|
||||
if err = jxutils.Strings2Objs(params.TypeList, &typeList, params.StatusList, &statusList); err == nil {
|
||||
retVal, err = act.QueryActs(params.Ctx, params.ActID, params.Offset, params.PageSize, params.Keyword, statusList, typeList,
|
||||
retVal, err = act.QueryActs(params.Ctx, params.ActID, params.Offset, params.PageSize, params.Keyword, params.VendorID, statusList, typeList,
|
||||
params.StoreID, params.SkuID, params.CityCode, timeList[2], timeList[3], timeList[0], timeList[1])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user