package controllers import ( "errors" "io" "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 advertising formData string false "广告语" // @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("当前只支持创建京东促销") } promotionParams := &promotion.PromotionParams{ Name: params.Name, BeginAt: utils.Str2Time(params.BeginAt), EndAt: utils.Str2Time(params.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, 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 := `
` 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:全部,0:60天,缺省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 }) }