Files
jx-callback/controllers/promotion.go

174 lines
7.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package controllers
import (
"errors"
"github.com/astaxie/beego"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/promotion"
"git.rosy.net.cn/jx-callback/business/model"
)
type PromotionController struct {
beego.Controller
}
// @Title 创建活动
// @Description 创建活动
// @Param token header string true "认证token"
// @Param vendorID formData int true "厂商ID当前只支持京东0 "
// @Param name formData string true "活动名,必须唯一(所以名子上最好带上日期)"
// @Param beginAt formData string true "开始日期"
// @Param endAt formData string true "结束日期"
// @Param type formData int true "活动类型3直降4限时抢购"
// @Param storeIDs formData string true "json数据storeID列表[1,2,3]"
// @Param skuPrices formData string true "json数据价格信息列表"
// @Param isAsync formData bool false "是否异步,缺省否(暂时只支持同步)"
// @Param isContinueWhenError formData bool false "单个同步失败是否继续缺省false"
// @Param advertising formData string false "广告语"
// @Param vendorPromotionID formData string false "厂商活动id设置此字段表示关联京东活动并不会真正去创建"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreatePromotion [post]
func (c *PromotionController) CreatePromotion() {
c.callCreatePromotion(func(params *tPromotionCreatePromotionParams) (retVal interface{}, errCode string, err error) {
if params.VendorID != model.VendorIDJD {
return nil, "", errors.New("当前只支持创建京东活动")
}
beginAt, err := utils.TryStr2Time(params.BeginAt)
if err != nil {
return retVal, "", err
}
endAt, err := utils.TryStr2Time(params.EndAt)
if err != nil {
return retVal, "", err
}
promotionParams := &promotion.PromotionParams{
Name: params.Name,
BeginAt: beginAt,
EndAt: endAt,
Type: params.Type,
Advertising: params.Advertising,
}
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &promotionParams.StoreIDs); err == nil {
if err = utils.UnmarshalUseNumber([]byte(params.SkuPrices), &promotionParams.SkuPrices); err == nil {
retVal, err = promotion.CreateJdPromotion(params.Ctx, false, params.IsAsync, params.IsContinueWhenError, params.VendorPromotionID, promotionParams, params.Ctx.GetUserName())
}
}
return retVal, "", err
})
}
// @Param token header string true "认证token"
// // @Title 发送文件给门店
// // @Description 发送文件给门店调用GET方法得到浏览器端参考的上传HTML实现userfiles
// // @Param type formData int true "活动类型3直降4限时抢购"
// // @Param isAsync formData bool false "是否异常,缺省否(暂时只支持同步)"
// // @Success 200 {object} controllers.CallResult
// // @Failure 200 {object} controllers.CallResult
// // @router /CreatePromotionByExcel [post,get]
// func (c *PromotionController) CreatePromotionByExcel() {
// if c.Ctx.Input.IsGet() {
// w := c.Ctx.ResponseWriter
// // 上传页面
// w.Header().Add("Content-Type", "text/html")
// w.WriteHeader(200)
// html := `
// <form enctype="multipart/form-data" action="/v2/promotion/CreatePromotionByExcel" method="POST">
// Send this file: <input name="userfile" accept="*.xlsx" type="file" />
// <input type="text" name="type" />
// <input type="text" name="isAsync" />
// <input type="submit" value="Send File" />
// </form>
// `
// io.WriteString(w, html)
// } else if c.Ctx.Input.IsPost() {
// c.callCreatePromotionByExcel(func(params *tPromotionCreatePromotionByExcelParams) (retVal interface{}, errCode string, err error) {
// r := c.Ctx.Request
// files := r.MultipartForm.File["userfile"]
// retVal, err = promotion.CreatePromotionByExcel(params.Ctx, params.IsAsync, params.Type, files[0], "userName") //params.Ctx.GetUserName())
// return retVal, "", err
// })
// }
// }
// @Title 根据历史订单信息发送活动消息
// @Description 根据历史订单信息发送活动消息
// @Param token header string true "认证token"
// @Param advertising formData string true "广告语"
// @Param days formData int false "多少天以内订单数据中的用户(-1全部060天缺省0"
// @Param isAsync formData bool false "是否异步,缺省否"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SendAdvertingByGoodsOrder [post]
func (c *PromotionController) SendAdvertingByGoodsOrder() {
c.callSendAdvertingByGoodsOrder(func(params *tPromotionSendAdvertingByGoodsOrderParams) (retVal interface{}, errCode string, err error) {
retVal, err = promotion.SendAdvertingByGoodsOrder(params.Ctx, params.Advertising, params.Days, params.IsAsync, params.Ctx.GetUserName())
return retVal, "", err
})
}
// @Title 查询活动
// @Description 查询活动
// @Param token header string true "认证token"
// @Param keyword query string false "关键字"
// @Param vendorID query int false "厂商ID当前只支持京东0 "
// @Param promotionID query int false "活动id"
// @Param vendorPromotionID query string false "厂商活动id"
// @Param days query int false "多少天内创建的缺省7天"
// @Param name query string false "活动名,不完全匹配"
// @Param beginAt query string false "开始日期,包括"
// @Param endAt query string false "结束日期,包括"
// @Param type query int false "活动类型3直降4限时抢购"
// @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 /GetPromotions [get]
func (c *PromotionController) GetPromotions() {
c.callGetPromotions(func(params *tPromotionGetPromotionsParams) (retVal interface{}, errCode string, err error) {
retVal, err = promotion.GetJdPromotions(params.Ctx, params.Keyword, params.MapData, params.Offset, params.PageSize)
return retVal, "", err
})
}
// @Title 取消活动
// @Description 取消活动
// @Param token header string true "认证token"
// @Param promotionID formData int true "活动id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CancelPromotion [put]
func (c *PromotionController) CancelPromotion() {
c.callCancelPromotion(func(params *tPromotionCancelPromotionParams) (retVal interface{}, errCode string, err error) {
err = promotion.CancelJdPromotion(params.Ctx, params.PromotionID)
return retVal, "", err
})
}
// @Title 锁定解锁活动SKU
// @Description 锁定解锁活动SKU
// @Param token header string true "认证token"
// @Param promotionID formData int true "活动id"
// @Param isLock formData int true "锁定标志0不锁定1锁定"
// @Param skuIDs formData string false "缺省全部"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /LockPromotionSkus [put]
func (c *PromotionController) LockPromotionSkus() {
c.callLockPromotionSkus(func(params *tPromotionLockPromotionSkusParams) (retVal interface{}, errCode string, err error) {
var skuIDs []int
if params.SkuIDs != "" {
if err = utils.UnmarshalUseNumber([]byte(params.SkuIDs), &skuIDs); err != nil {
return retVal, "", err
}
}
retVal, err = promotion.LockPromotionSkus(params.Ctx, params.PromotionID, params.IsLock, skuIDs)
return retVal, "", err
})
}