- 启用新活动初始版本
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package act
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
@@ -25,6 +28,17 @@ type ActDetail struct {
|
||||
model.Act2
|
||||
}
|
||||
|
||||
type ActMapPureInfo struct {
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
||||
}
|
||||
|
||||
type ActVendorInfo struct {
|
||||
model.Act
|
||||
VendorList []*ActMapPureInfo
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -183,7 +197,7 @@ func AddActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreS
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (actID int, err error) {
|
||||
func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam, isAsync bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
|
||||
dao.Begin(db)
|
||||
@@ -201,12 +215,12 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
err = dao.CreateEntity(db, act)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
validVendorIDs, actStoreSkuList, actStoreSkuMapList, err := ActStoreSkuParam2Model(ctx, db, act, vendorIDs, actStoreSku)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
var actMapList []*model.ActMap
|
||||
@@ -224,27 +238,63 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
err = dao.CreateMultiEntities(db, actMapList)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
if err = addActStoreBind(ctx, db, actStoreSkuList, actStoreSkuMapList); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
return "", err
|
||||
}
|
||||
dao.Commit(db)
|
||||
|
||||
actID = act.ID
|
||||
err = SyncAct(ctx, actID, nil, nil, nil)
|
||||
return actID, err
|
||||
hint, err = SyncAct(ctx, nil, act.ID, nil, nil, nil, isAsync)
|
||||
if !isAsync {
|
||||
hint = utils.Int2Str(act.ID)
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func QueryActs(ctx *jxcontext.Context, actID int, keyword string, statusList []int, actTypeList []int, storeID, skuID int, beginAt, endAt time.Time) (actList []*model.Act, err error) {
|
||||
return actList, err
|
||||
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 GetActDetail(ctx *jxcontext.Context, actID int) (actDetail *ActDetail, err error) {
|
||||
return actDetail, err
|
||||
func GetActVendorInfo(ctx *jxcontext.Context, actID int) (actVendorInfo *ActVendorInfo, err error) {
|
||||
db := dao.GetDB()
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(actMap) == 0 {
|
||||
return nil, fmt.Errorf("不能找到活动:%d", actID)
|
||||
}
|
||||
actVendorInfo = &ActVendorInfo{}
|
||||
for vendorID, v := range actMap {
|
||||
if actVendorInfo.ID == 0 {
|
||||
actVendorInfo.Act = v.Act
|
||||
}
|
||||
actVendorInfo.VendorList = append(actVendorInfo.VendorList, &ActMapPureInfo{
|
||||
VendorID: vendorID,
|
||||
SyncStatus: v.SyncStatus,
|
||||
VendorActID: v.VendorActID,
|
||||
})
|
||||
}
|
||||
return actVendorInfo, err
|
||||
}
|
||||
|
||||
func GetActStoreSkuInfo(ctx *jxcontext.Context, actID int, vendorIDs []int) (actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
db := dao.GetDB()
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, vendorIDs, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(actStoreSkuMap) == 0 {
|
||||
return nil, fmt.Errorf("不能找到活动:%d", actID)
|
||||
}
|
||||
for _, v := range actStoreSkuMap {
|
||||
actStoreSkuList = append(actStoreSkuList, v...)
|
||||
}
|
||||
return actStoreSkuList, err
|
||||
}
|
||||
|
||||
func CancelAct(ctx *jxcontext.Context, actID int) (err error) {
|
||||
@@ -252,7 +302,7 @@ func CancelAct(ctx *jxcontext.Context, actID int) (err error) {
|
||||
if err = deleteActStoreBind(ctx, db, actID, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
err = SyncAct(ctx, actID, nil, nil, nil)
|
||||
_, err = SyncAct(ctx, nil, actID, nil, nil, nil, false)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -346,22 +396,37 @@ func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
return err
|
||||
}
|
||||
|
||||
func SyncAct(ctx *jxcontext.Context, actID int, vendorIDs, storeIDs, skuIDs []int) (err error) {
|
||||
func SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, actID int, vendorIDs, storeIDs, skuIDs []int, isAsync bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, vendorIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, storeIDs, skuIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
for vendorID := range actMap {
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformActHandler); handler != nil {
|
||||
if err = handler.SyncAct(ctx, nil, actMap[vendorID], nil, actStoreSkuMap[vendorID]); err != nil {
|
||||
return err
|
||||
if vendorIDs == nil {
|
||||
vendorIDs = partner.GetVendorIDsFromActMap(actMap)
|
||||
}
|
||||
task := tasksch.NewParallelTask("SyncAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := batchItemList[0].(int)
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformActHandler); handler != nil {
|
||||
if err = handler.SyncAct(ctx, nil, actMap[vendorID], nil, actStoreSkuMap[vendorID]); err == nil {
|
||||
retVal = []int{1}
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, vendorIDs)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if !isAsync {
|
||||
result, err2 := task.GetResult(0)
|
||||
if err = err2; err == nil {
|
||||
hint = utils.Int2Str(len(result))
|
||||
}
|
||||
} else {
|
||||
hint = task.GetID()
|
||||
}
|
||||
return err
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
@@ -26,11 +26,7 @@ func TestInitDb(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateAct(t *testing.T) {
|
||||
actID, err := CreateAct(jxcontext.AdminCtx, &model.Act{
|
||||
Name: "测试活动",
|
||||
PricePercentage: 80,
|
||||
Type: model.ActSkuDirectDown,
|
||||
}, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}, nil, []*ActStoreSkuParam{
|
||||
actStoreSkuList := []*ActStoreSkuParam{
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100884,
|
||||
@@ -55,7 +51,13 @@ func TestCreateAct(t *testing.T) {
|
||||
SkuID: 22715,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
// t.Log(utils.Format4Output(actStoreSkuList, true))
|
||||
actID, err := CreateAct(jxcontext.AdminCtx, &model.Act{
|
||||
Name: "测试活动",
|
||||
PricePercentage: 80,
|
||||
Type: model.ActSkuDirectDown,
|
||||
}, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}, nil, actStoreSkuList, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -134,7 +136,7 @@ func TestAddActStoreBind(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSyncAct(t *testing.T) {
|
||||
err := SyncAct(jxcontext.AdminCtx, 1, nil, nil, nil)
|
||||
_, err := SyncAct(jxcontext.AdminCtx, nil, 1, nil, nil, nil, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ const (
|
||||
ActStatusCreated = 1 // 需同步
|
||||
ActStatusCanceled = 2 // 需同步
|
||||
ActStatusEnded = 3 // 不需要同步,根据活动时间自动刷新的
|
||||
|
||||
ActCreateTypeAPI = 1
|
||||
ActCreateTypeCallback = 2
|
||||
ActCreateTypeSpider = 3
|
||||
)
|
||||
|
||||
type Act struct {
|
||||
|
||||
@@ -1,31 +1,50 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type PagedActListInfo struct {
|
||||
TotalCount int
|
||||
Data []*model.Act
|
||||
}
|
||||
|
||||
func GetActVendorInfo(db *DaoDB, actID int, vendorIDs []int) (actMap map[int]*model.Act2, err error) {
|
||||
sql := `
|
||||
leftOrEmpty := ""
|
||||
if len(vendorIDs) == 1 && vendorIDs[0] == -1 {
|
||||
leftOrEmpty = "LEFT"
|
||||
}
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT t1.*,
|
||||
t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status
|
||||
FROM act t1
|
||||
JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
WHERE t1.deleted_at = ? AND t1.id = ?
|
||||
`
|
||||
%s JOIN act_map t2 ON t2.act_id = t1.id AND t2.deleted_at = ?`, leftOrEmpty)
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
actID,
|
||||
}
|
||||
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
|
||||
sql += `
|
||||
WHERE t1.deleted_at = ? AND t1.id = ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, actID)
|
||||
|
||||
var actList []*model.Act2
|
||||
if err = GetRows(db, &actList, sql, sqlParams...); err == nil {
|
||||
actMap = make(map[int]*model.Act2)
|
||||
for _, v := range actList {
|
||||
if leftOrEmpty != "" {
|
||||
v.VendorID = -1
|
||||
}
|
||||
actMap[v.VendorID] = v
|
||||
}
|
||||
}
|
||||
@@ -33,7 +52,12 @@ func GetActVendorInfo(db *DaoDB, actID int, vendorIDs []int) (actMap map[int]*mo
|
||||
}
|
||||
|
||||
func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs []int) (actStoreSkuMap map[int][]*model.ActStoreSku2, err error) {
|
||||
sql := `
|
||||
globals.SugarLogger.Debugf("GetActStoreSkuVendorInfo actID:%d", actID)
|
||||
leftOrEmpty := ""
|
||||
if len(vendorIDs) == 1 && vendorIDs[0] == -1 {
|
||||
leftOrEmpty = "LEFT"
|
||||
}
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT t1.*,
|
||||
t2.id map_id, t2.vendor_id, t2.vendor_act_id, t2.sync_status,
|
||||
t3.vendor_store_id,
|
||||
@@ -47,24 +71,27 @@ func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
ELSE
|
||||
''
|
||||
END vendor_sku_id
|
||||
FROM act_store_sku_map t2
|
||||
JOIN act_store_sku t1 ON t1.id = t2.bind_id
|
||||
JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
||||
FROM act_store_sku t1
|
||||
%s JOIN act_store_sku_map t2 ON t2.bind_id = t1.id AND t2.deleted_at = ?`, leftOrEmpty)
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
|
||||
sql += fmt.Sprintf(`
|
||||
%s JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
||||
JOIN sku t4 ON t4.id = t1.sku_id AND t4.deleted_at = ?
|
||||
JOIN store_sku_bind t5 ON t5.sku_id = t1.sku_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
||||
WHERE t2.deleted_at = ? AND t2.act_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
WHERE t1.deleted_at = ? AND t1.act_id = ?
|
||||
`, leftOrEmpty)
|
||||
sqlParams = append(sqlParams,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
actID,
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
)
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
@@ -74,11 +101,109 @@ func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
var actStoreSkuList []*model.ActStoreSku2
|
||||
globals.SugarLogger.Debug(sql)
|
||||
globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
globals.SugarLogger.Debug(utils.Format4Output(actStoreSkuList, false))
|
||||
if err = GetRows(db, &actStoreSkuList, sql, sqlParams...); err == nil {
|
||||
actStoreSkuMap = make(map[int][]*model.ActStoreSku2)
|
||||
for _, v := range actStoreSkuList {
|
||||
if leftOrEmpty != "" {
|
||||
v.VendorID = -1
|
||||
}
|
||||
actStoreSkuMap[v.VendorID] = append(actStoreSkuMap[v.VendorID], v)
|
||||
}
|
||||
}
|
||||
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) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*
|
||||
FROM act t1
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
keywordInt := int64(0)
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND ( t1.name LIKE ? OR t1.advertising LIKE ? OR t1.remark LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike)
|
||||
keywordInt = utils.Str2Int64WithDefault(keyword, 0)
|
||||
if keywordInt > 0 {
|
||||
sql += `
|
||||
OR t1.id = ?`
|
||||
sqlParams = append(sqlParams, keywordInt)
|
||||
}
|
||||
sql += ")"
|
||||
}
|
||||
if storeID > 0 || skuID > 0 || cityCode > 0 {
|
||||
sql += ` AND (SELECT COUNT(*)
|
||||
FROM act_store_sku t2`
|
||||
if cityCode > 0 {
|
||||
sql += " JOIN store t3 ON t3.id = t2.store_id AND t3.city_code = ?"
|
||||
sqlParams = append(sqlParams, cityCode)
|
||||
}
|
||||
sql += `
|
||||
WHERE t2.act_id = t1.id`
|
||||
if storeID > 0 {
|
||||
sql += " AND t2.store_id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if skuID > 0 {
|
||||
sql += " AND t2.sku_id = ?"
|
||||
sqlParams = append(sqlParams, skuID)
|
||||
}
|
||||
sql += ") > 0"
|
||||
}
|
||||
if actID > 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
if len(statusList) > 0 {
|
||||
sql += " AND t1.status IN (" + GenQuestionMarks(len(statusList)) + ")"
|
||||
sqlParams = append(sqlParams, statusList)
|
||||
}
|
||||
if len(actTypeList) > 0 {
|
||||
sql += " AND t1.type IN (" + GenQuestionMarks(len(actTypeList)) + ")"
|
||||
sqlParams = append(sqlParams, actTypeList)
|
||||
}
|
||||
if !utils.IsTimeZero(beginAt) {
|
||||
sql += " AND t1.begin_at <= ?"
|
||||
sqlParams = append(sqlParams, beginAt)
|
||||
}
|
||||
if !utils.IsTimeZero(endAt) {
|
||||
sql += " AND t1.end_at >= ?"
|
||||
sqlParams = append(sqlParams, endAt)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtFrom) {
|
||||
sql += " AND t1.created_at >= ?"
|
||||
sqlParams = append(sqlParams, createdAtFrom)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtTo) {
|
||||
sql += " AND t1.created_at <= ?"
|
||||
sqlParams = append(sqlParams, createdAtTo)
|
||||
}
|
||||
sql += `
|
||||
ORDER by t1.id
|
||||
LIMIT ? OFFSET ?`
|
||||
sqlParams = append(sqlParams, FormalizePageSize(pageSize), FormalizePageOffset(offset))
|
||||
|
||||
pagedInfo = &PagedActListInfo{}
|
||||
Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
err = GetRows(db, &pagedInfo.Data, sql, sqlParams...)
|
||||
if err == nil {
|
||||
pagedInfo.TotalCount = GetLastTotalRowCount(db)
|
||||
Commit(db)
|
||||
} else {
|
||||
Rollback(db)
|
||||
pagedInfo = nil
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
@@ -181,3 +181,10 @@ func FormalizePageSize(pageSize int) int {
|
||||
}
|
||||
return pageSize
|
||||
}
|
||||
|
||||
func FormalizePageOffset(offset int) int {
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
return offset
|
||||
}
|
||||
|
||||
@@ -81,3 +81,10 @@ func ActStoreSku2Update(actStoreSkuList []*model.ActStoreSku2, syncStatus int) (
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func GetVendorIDsFromActMap(actMap map[int]*model.Act2) (vendorIDs []int) {
|
||||
for vendorID := range actMap {
|
||||
vendorIDs = append(vendorIDs, vendorID)
|
||||
}
|
||||
return vendorIDs
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/astaxie/beego"
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type ActController struct {
|
||||
beego.Controller
|
||||
@@ -15,17 +20,121 @@ type ActController struct {
|
||||
// @Param beginAt formData string true "开始日期"
|
||||
// @Param endAt formData string true "结束日期"
|
||||
// @Param pricePercentage formData int true "活动价格比例"
|
||||
// @Param actStoreSku formData string true "活动门店商品信息"
|
||||
// @Param actStoreSkuList formData string true "活动门店商品信息"
|
||||
// @Param advertising formData string false "广告语"
|
||||
// @Param limitDaily formData int false "是否按日0-不限,>0限购单数(限时抢需填)"
|
||||
// @Param limitUser formData int false "是否用户限购0-不限,1-限购"
|
||||
// @Param limitCount formData int false "限购件数 0-不限,如账号限购、设备限购有一个为1,则限购件数必须大于0的整数"
|
||||
// @Param remark formData string false "备注"
|
||||
// @Param isAsync formData bool false "是否异步,缺省否(暂时只支持同步)"
|
||||
// @Param isContinueWhenError formData bool false "单个广告失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CreatePromotion [post]
|
||||
// @router /CreateAct [post]
|
||||
func (c *ActController) CreateAct() {
|
||||
|
||||
c.callCreateAct(func(params *tActCreateActParams) (retVal interface{}, errCode string, err error) {
|
||||
var (
|
||||
vendorIDs []int
|
||||
actStoreSkuList []*act.ActStoreSkuParam
|
||||
)
|
||||
timeList, err := jxutils.BatchStr2Time(params.BeginAt, params.EndAt)
|
||||
if err == nil {
|
||||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.ActStoreSkuList, &actStoreSkuList); err == nil {
|
||||
actObj := &model.Act{
|
||||
Name: params.Name,
|
||||
Type: params.Type,
|
||||
LimitUser: params.LimitUser,
|
||||
LimitDaily: params.LimitDaily,
|
||||
LimitCount: params.LimitCount,
|
||||
// Source:,
|
||||
CreateType: model.ActCreateTypeAPI,
|
||||
PricePercentage: params.PricePercentage,
|
||||
BeginAt: timeList[0],
|
||||
EndAt: timeList[1],
|
||||
Remark: params.Remark,
|
||||
}
|
||||
retVal, err = act.CreateAct(params.Ctx, actObj, vendorIDs, nil, actStoreSkuList, params.IsAsync)
|
||||
}
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 查询活动
|
||||
// @Description 查询活动
|
||||
// @Param token header string true "认证token"
|
||||
// @Param createdAtFrom query string true "创建开始日期"
|
||||
// @Param createdAtTo query string false "创建结束日期"
|
||||
// @Param keyword query string false "关键字"
|
||||
// @Param actID query int false "活动id"
|
||||
// @Param name query string false "活动名,不完全匹配"
|
||||
// @Param cityCode query int false "活动门店所属城市code"
|
||||
// @Param beginAt query string false "开始日期,包括"
|
||||
// @Param endAt query string false "结束日期,包括"
|
||||
// @Param typeList query string false "活动类型列表,3:直降,4:限时抢购"
|
||||
// @Param statusList query string false "活动状态列表"
|
||||
// @Param storeID query int false "包含门店"
|
||||
// @Param skuID query int false "包含sku"
|
||||
// @Param offset query int false "活动列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "活动列表页大小(缺省为50,-1表示全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /QueryActs [get]
|
||||
func (c *ActController) QueryActs() {
|
||||
c.callQueryActs(func(params *tActQueryActsParams) (retVal interface{}, errCode string, err error) {
|
||||
timeList, err := jxutils.BatchStr2Time(params.CreatedAtFrom, params.CreatedAtTo, params.BeginAt, params.EndAt)
|
||||
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,
|
||||
params.StoreID, params.SkuID, params.CityCode, timeList[2], timeList[3], timeList[0], timeList[1])
|
||||
}
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 取消活动
|
||||
// @Description 取消活动
|
||||
// @Param token header string true "认证token"
|
||||
// @Param actID formData int true "活动id"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CancelAct [put]
|
||||
func (c *ActController) CancelAct() {
|
||||
c.callCancelAct(func(params *tActCancelActParams) (retVal interface{}, errCode string, err error) {
|
||||
err = act.CancelAct(params.Ctx, params.ActID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 得到活动平台信息
|
||||
// @Description 得到活动平台信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param actID query int false "活动id"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetActVendorInfo [get]
|
||||
func (c *ActController) GetActVendorInfo() {
|
||||
c.callGetActVendorInfo(func(params *tActGetActVendorInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = act.GetActVendorInfo(params.Ctx, params.ActID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 得到活动门店商品信息
|
||||
// @Description 得到活动门店商品信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param actID query int true "活动id"
|
||||
// @Param vendorIDs query string false "厂商ID列表"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetActStoreSkuInfo [get]
|
||||
func (c *ActController) GetActStoreSkuInfo() {
|
||||
c.callGetActStoreSkuInfo(func(params *tActGetActStoreSkuInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
var vendorIDs []int
|
||||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs); err == nil {
|
||||
retVal, err = act.GetActStoreSkuInfo(params.Ctx, params.ActID, vendorIDs)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ func Init() {
|
||||
|
||||
// 如下语句建表时要出错(INDEX名字太长了),暂时放一下,必须放最后一句
|
||||
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.Act{}, &model.ActOrderRule{}, &model.ActStoreSku{})
|
||||
orm.RegisterModel(&model.ActMap{}, &model.ActStoreSkuMap{})
|
||||
// create table
|
||||
orm.RunSyncdb("default", false, true)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,51 @@ import (
|
||||
|
||||
func init() {
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CancelAct",
|
||||
Router: `/CancelAct`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateAct",
|
||||
Router: `/CreateAct`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetActStoreSkuInfo",
|
||||
Router: `/GetActStoreSkuInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetActVendorInfo",
|
||||
Router: `/GetActVendorInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"],
|
||||
beego.ControllerComments{
|
||||
Method: "QueryActs",
|
||||
Router: `/QueryActs`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"],
|
||||
beego.ControllerComments{
|
||||
Method: "AddAuthBind",
|
||||
|
||||
@@ -111,6 +111,11 @@ func init() {
|
||||
&controllers.NetSpiderController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/act",
|
||||
beego.NSInclude(
|
||||
&controllers.ActController{},
|
||||
),
|
||||
),
|
||||
)
|
||||
beego.AddNamespace(ns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user