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