295 lines
13 KiB
Go
295 lines
13 KiB
Go
package controllers
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"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"
|
||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||
"github.com/astaxie/beego"
|
||
)
|
||
|
||
type ActController struct {
|
||
beego.Controller
|
||
}
|
||
|
||
// @Title 预创建活动
|
||
// @Description 预创建活动
|
||
// @Param token header string true "认证token"
|
||
// @Param name formData string true "活动名,必须唯一(所以名子上最好带上日期)"
|
||
// @Param type formData int true "活动类型,3:直降,4:秒杀(美团当前不支持秒杀)"
|
||
// @Param vendorIDs formData string true "厂商ID,当前只支持,京东:0,京西(用于记录活动信息):99"
|
||
// @Param beginAt formData string true "开始日期"
|
||
// @Param endAt formData string true "结束日期"
|
||
// @Param pricePercentage formData int true "活动价格比例"
|
||
// @Param advertising formData string true "广告语"
|
||
// @Param actStoreSkuList formData string true "活动门店商品信息"
|
||
// @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 "备注"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /PreCreateAct [post]
|
||
func (c *ActController) PreCreateAct() {
|
||
c.callPreCreateAct(func(params *tActPreCreateActParams) (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],
|
||
Advertising: params.Advertising,
|
||
Remark: params.Remark,
|
||
}
|
||
retVal, err = act.PreCreateAct(params.Ctx, actObj, vendorIDs, nil, actStoreSkuList)
|
||
}
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 创建活动
|
||
// @Description 创建活动
|
||
// @Param token header string true "认证token"
|
||
// @Param name formData string true "活动名,必须唯一(所以名子上最好带上日期)"
|
||
// @Param type formData int true "活动类型,3:直降,4:秒杀(美团当前不支持秒杀)"
|
||
// @Param vendorIDs formData string true "厂商ID,当前只支持,京东:0,京西(用于记录活动信息):99"
|
||
// @Param beginAt formData string true "开始日期"
|
||
// @Param endAt formData string true "结束日期"
|
||
// @Param pricePercentage formData int true "活动价格比例"
|
||
// @Param advertising formData string true "广告语"
|
||
// @Param actStoreSkuList formData string true "活动门店商品信息"
|
||
// @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 "是否异步,缺省否(暂时只支持同步)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @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],
|
||
Advertising: params.Advertising,
|
||
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 false "创建开始日期"
|
||
// @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 vendorID query int false "包含平台"
|
||
// @Param typeList query string false "活动类型列表,3:直降,4:秒杀"
|
||
// @Param statusList query string false "活动状态列表"
|
||
// @Param createTypeList 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, createTypeList []int
|
||
if err = jxutils.Strings2Objs(params.TypeList, &typeList, params.StatusList, &statusList, params.CreateTypeList, &createTypeList); err == nil {
|
||
if params.MapData["vendorID"] == nil {
|
||
params.VendorID = -1
|
||
}
|
||
retVal, err = act.QueryActs(params.Ctx, params.ActID, params.Offset, params.PageSize, params.Keyword, params.VendorID,
|
||
statusList, typeList, createTypeList, 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 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
|
||
})
|
||
}
|
||
|
||
// @Title 同步活动
|
||
// @Description 同步活动
|
||
// @Param token header string true "认证token"
|
||
// @Param actID formData int true "活动id"
|
||
// @Param vendorIDs formData string false "厂商ID列表"
|
||
// @Param storeIDs formData string false "门店ID列表"
|
||
// @Param skuIDs formData string false "商品列表"
|
||
// @Param isAsync formData bool false "是否异步"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /SyncAct [put]
|
||
func (c *ActController) SyncAct() {
|
||
c.callSyncAct(func(params *tActSyncActParams) (retVal interface{}, errCode string, err error) {
|
||
var vendorIDs, storeIDs, skuIDs []int
|
||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs); err == nil {
|
||
retVal, err = act.SyncAct(params.Ctx, nil, params.ActID, vendorIDs, storeIDs, skuIDs, params.IsAsync)
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 添加SKU活动商品
|
||
// @Description 添加SKU活动商品
|
||
// @Param token header string true "认证token"
|
||
// @Param actID formData int true "活动id"
|
||
// @Param actStoreSkuAddList formData string false "需添加的活动商品信息"
|
||
// @Param actStoreSkuDeleteList formData string false "需删除的活动商品信息"
|
||
// @Param isAsync formData bool false "是否异步"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /UpdateActStoreSkuBind [put]
|
||
func (c *ActController) UpdateActStoreSkuBind() {
|
||
c.callUpdateActStoreSkuBind(func(params *tActUpdateActStoreSkuBindParams) (retVal interface{}, errCode string, err error) {
|
||
var actStoreSkuAddList, actStoreSkuDeleteList []*act.ActStoreSkuParam
|
||
if err = jxutils.Strings2Objs(params.ActStoreSkuAddList, &actStoreSkuAddList, params.ActStoreSkuDeleteList, &actStoreSkuDeleteList); err == nil {
|
||
if len(actStoreSkuAddList) == 0 && len(actStoreSkuDeleteList) == 0 {
|
||
err = fmt.Errorf("actStoreSkuAddList与actStoreSkuDeleteList不能都为空")
|
||
} else {
|
||
db := dao.GetDB()
|
||
dao.Begin(db)
|
||
func() {
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
dao.Rollback(db)
|
||
}
|
||
}()
|
||
if len(actStoreSkuAddList) > 0 {
|
||
if err = act.AddActStoreSkuBind(params.Ctx, db, params.ActID, actStoreSkuAddList); err != nil {
|
||
dao.Rollback(db)
|
||
return
|
||
}
|
||
}
|
||
if len(actStoreSkuDeleteList) > 0 {
|
||
if err = act.DeleteActStoreSkuBind(params.Ctx, db, params.ActID, actStoreSkuDeleteList); err != nil {
|
||
dao.Rollback(db)
|
||
return
|
||
}
|
||
}
|
||
dao.Commit(db)
|
||
}()
|
||
if err == nil {
|
||
retVal, err = act.SyncAct(params.Ctx, nil, params.ActID, nil, nil, nil, params.IsAsync)
|
||
}
|
||
}
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 添加SKU活动商品
|
||
// @Description 添加SKU活动商品
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorIDs formData string true "厂商ID列表"
|
||
// @Param createdFrom formData string true "创建开始日期"
|
||
// @Param isAsync formData bool false "是否异步"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /RefreshPageActs [put]
|
||
func (c *ActController) RefreshPageActs() {
|
||
c.callRefreshPageActs(func(params *tActRefreshPageActsParams) (retVal interface{}, errCode string, err error) {
|
||
timeList, err := jxutils.BatchStr2Time(params.CreatedFrom)
|
||
if err == nil {
|
||
var vendorIDs []int
|
||
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs); err == nil {
|
||
retVal, err = act.RefreshPageActs(params.Ctx, vendorIDs, timeList[0], params.IsAsync)
|
||
}
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 将SKU从所有活动中删除
|
||
// @Description 将SKU从所有活动中删除
|
||
// @Param token header string true "认证token"
|
||
// @Param skuIDs query string true "skuID列表"
|
||
// @Param vendorID query int true "厂商ID"
|
||
// @Param isAsync query bool false "是否异步"
|
||
// @Param isContinueWhenError query bool false "单个同步失败是否继续,缺省false"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /DeleteSkusFromAct [delete]
|
||
func (c *ActController) DeleteSkusFromAct() {
|
||
c.callDeleteSkusFromAct(func(params *tActDeleteSkusFromActParams) (retVal interface{}, errCode string, err error) {
|
||
var skuIDs []int
|
||
if err = jxutils.Strings2Objs(params.SkuIDs, &skuIDs); err == nil {
|
||
retVal, err = act.DeleteSkusFromAct(params.Ctx, params.VendorID, skuIDs, params.IsAsync, params.IsContinueWhenError)
|
||
}
|
||
return retVal, "", err
|
||
})
|
||
}
|