- use json to serialize promotion params.

- remove CreatePromotionByExcel
This commit is contained in:
gazebo
2018-11-05 08:58:15 +08:00
parent 3334466e70
commit 0eec70cce5
2 changed files with 82 additions and 84 deletions

View File

@@ -4,13 +4,11 @@ import (
"encoding/gob" "encoding/gob"
"errors" "errors"
"fmt" "fmt"
"mime/multipart"
"time" "time"
"git.rosy.net.cn/baseapi/platformapi/jdapi" "git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "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/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
@@ -235,9 +233,10 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
EndAt: params.EndAt, EndAt: params.EndAt,
} }
dao.WrapAddIDCULDEntity(promotion, userName) dao.WrapAddIDCULDEntity(promotion, userName)
if promotion.Params, err = jxutils.SerializeData(params); err != nil { // if promotion.Params, err = jxutils.SerializeData(params); err != nil {
return "", err // return "", err
} // }
promotion.Params = string(utils.MustMarshal(params))
dao.Begin(db) dao.Begin(db)
defer func() { defer func() {
dao.Rollback(db) dao.Rollback(db)
@@ -313,55 +312,55 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
return rootTask.ID, err return rootTask.ID, err
} }
func CreatePromotionByExcel(ctx *jxcontext.Context, isAsync bool, promotionType int, fileHeader *multipart.FileHeader, userName string) (hint string, err error) { // func CreatePromotionByExcel(ctx *jxcontext.Context, isAsync bool, promotionType int, fileHeader *multipart.FileHeader, userName string) (hint string, err error) {
file, err := fileHeader.Open() // file, err := fileHeader.Open()
if err != nil { // if err != nil {
return "", err // return "", err
} // }
contents := excel.Excel2Slice(file) // contents := excel.Excel2Slice(file)
file.Close() // file.Close()
var promotionParams *PromotionParams // var promotionParams *PromotionParams
for _, v := range contents { // for _, v := range contents {
promotionParams = &PromotionParams{ // promotionParams = &PromotionParams{
Name: v[1][colNameIndex], // Name: v[1][colNameIndex],
Type: promotionType, // Type: promotionType,
} // }
if promotionParams.BeginAt, err = excelStr2Time(v[1][colBeginAtIndex]); err != nil { // if promotionParams.BeginAt, err = excelStr2Time(v[1][colBeginAtIndex]); err != nil {
return "", err // return "", err
} // }
if promotionParams.EndAt, err = excelStr2Time(v[1][colEndAtIndex]); err != nil { // if promotionParams.EndAt, err = excelStr2Time(v[1][colEndAtIndex]); err != nil {
return "", err // return "", err
} // }
for rowIndex, row := range v { // for rowIndex, row := range v {
if rowIndex > 0 { // if rowIndex > 0 {
isBreak := true // isBreak := true
if row[colSkuIDIndex] != "" { // if row[colSkuIDIndex] != "" {
isBreak = false // isBreak = false
jdSkuID := int(utils.Str2Int64(row[colSkuIDIndex])) // jdSkuID := int(utils.Str2Int64(row[colSkuIDIndex]))
promotionParams.SkuPrices = append(promotionParams.SkuPrices, &SkuPrice{ // promotionParams.SkuPrices = append(promotionParams.SkuPrices, &SkuPrice{
SkuID: jdSkuID, // SkuID: jdSkuID,
PriceType: PriceTypePrice, // PriceType: PriceTypePrice,
Price: int(jxutils.StandardPrice2Int(utils.Str2Float64(row[colSkuPriceIndex]))), // Price: int(jxutils.StandardPrice2Int(utils.Str2Float64(row[colSkuPriceIndex]))),
}) // })
} // }
if row[colStoreIDIndex] != "" { // if row[colStoreIDIndex] != "" {
isBreak = false // isBreak = false
jdStoreID := int(utils.Str2Int64(row[colStoreIDIndex])) // jdStoreID := int(utils.Str2Int64(row[colStoreIDIndex]))
promotionParams.StoreIDs = append(promotionParams.StoreIDs, jdStoreID) // promotionParams.StoreIDs = append(promotionParams.StoreIDs, jdStoreID)
} // }
if isBreak { // if isBreak {
break // break
} // }
} // }
} // }
break // break
} // }
// globals.SugarLogger.Debug(utils.Format4Output(promotionParams, false)) // // globals.SugarLogger.Debug(utils.Format4Output(promotionParams, false))
// globals.SugarLogger.Debug(isAsync) // // globals.SugarLogger.Debug(isAsync)
return CreateJdPromotion(ctx, true, isAsync, promotionParams, userName) // return CreateJdPromotion(ctx, true, isAsync, promotionParams, userName)
} // }
func excelStr2Time(timeStr string) (tm time.Time, err error) { func excelStr2Time(timeStr string) (tm time.Time, err error) {
return time.ParseInLocation("2006年1月2日15点4分5秒", timeStr, time.Local) return time.ParseInLocation("2006年1月2日15点4分5秒", timeStr, time.Local)

View File

@@ -2,7 +2,6 @@ package controllers
import ( import (
"errors" "errors"
"io"
"github.com/astaxie/beego" "github.com/astaxie/beego"
@@ -53,37 +52,37 @@ func (c *PromotionController) CreatePromotion() {
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Title 发送文件给门店 // // @Title 发送文件给门店
// @Description 发送文件给门店调用GET方法得到浏览器端参考的上传HTML实现userfiles // // @Description 发送文件给门店调用GET方法得到浏览器端参考的上传HTML实现userfiles
// @Param type formData int true "促销类型3直降4限时抢购" // // @Param type formData int true "促销类型3直降4限时抢购"
// @Param isAsync formData bool false "是否异常,缺省否(暂时只支持同步)" // // @Param isAsync formData bool false "是否异常,缺省否(暂时只支持同步)"
// @Success 200 {object} controllers.CallResult // // @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult // // @Failure 200 {object} controllers.CallResult
// @router /CreatePromotionByExcel [post,get] // // @router /CreatePromotionByExcel [post,get]
func (c *PromotionController) CreatePromotionByExcel() { // func (c *PromotionController) CreatePromotionByExcel() {
if c.Ctx.Input.IsGet() { // if c.Ctx.Input.IsGet() {
w := c.Ctx.ResponseWriter // w := c.Ctx.ResponseWriter
// 上传页面 // // 上传页面
w.Header().Add("Content-Type", "text/html") // w.Header().Add("Content-Type", "text/html")
w.WriteHeader(200) // w.WriteHeader(200)
html := ` // html := `
<form enctype="multipart/form-data" action="/v2/promotion/CreatePromotionByExcel" method="POST"> // <form enctype="multipart/form-data" action="/v2/promotion/CreatePromotionByExcel" method="POST">
Send this file: <input name="userfile" accept="*.xlsx" type="file" /> // Send this file: <input name="userfile" accept="*.xlsx" type="file" />
<input type="text" name="type" /> // <input type="text" name="type" />
<input type="text" name="isAsync" /> // <input type="text" name="isAsync" />
<input type="submit" value="Send File" /> // <input type="submit" value="Send File" />
</form> // </form>
` // `
io.WriteString(w, html) // io.WriteString(w, html)
} else if c.Ctx.Input.IsPost() { // } else if c.Ctx.Input.IsPost() {
c.callCreatePromotionByExcel(func(params *tPromotionCreatePromotionByExcelParams) (retVal interface{}, errCode string, err error) { // c.callCreatePromotionByExcel(func(params *tPromotionCreatePromotionByExcelParams) (retVal interface{}, errCode string, err error) {
r := c.Ctx.Request // r := c.Ctx.Request
files := r.MultipartForm.File["userfile"] // files := r.MultipartForm.File["userfile"]
retVal, err = promotion.CreatePromotionByExcel(params.Ctx, params.IsAsync, params.Type, files[0], "userName") //params.Ctx.GetUserName()) // retVal, err = promotion.CreatePromotionByExcel(params.Ctx, params.IsAsync, params.Type, files[0], "userName") //params.Ctx.GetUserName())
return retVal, "", err // return retVal, "", err
}) // })
} // }
} // }
// @Title 创建促销 // @Title 创建促销
// @Description 创建促销 // @Description 创建促销