根据Excel更新京西价

This commit is contained in:
苏尹岚
2019-12-11 16:01:58 +08:00
parent 044750478c
commit d74a0d8079
2 changed files with 16 additions and 14 deletions

View File

@@ -3,7 +3,9 @@ package cms
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"math" "math"
"mime/multipart"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@@ -2144,21 +2146,21 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error
return err return err
} }
func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files string, isAsync, isContinueWhenError bool) (hint string, err error) { func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
// if len(files) == 0 { if len(files) == 0 {
// return "", errors.New("没有文件上传!") return "", errors.New("没有文件上传!")
// } }
if len(storeIDs) == 0 { if len(storeIDs) == 0 {
return "", errors.New("请选择至少一个门店!") return "", errors.New("请选择至少一个门店!")
} }
// fileHeader := files[0] fileHeader := files[0]
// file, err := fileHeader.Open() file, err := fileHeader.Open()
hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, files, true, true) hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, file, true, true)
// file.Close() file.Close()
return hint, err return hint, err
} }
func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader string, isAsync, isContinueWhenError bool) (hint string, err error) { func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
var ( var (
storeSkuNamePriceList []*model.StoreSkuNamePrice storeSkuNamePriceList []*model.StoreSkuNamePrice
storeSkuNamePriceListUpdate []*model.StoreSkuNamePrice storeSkuNamePriceListUpdate []*model.StoreSkuNamePrice
@@ -2178,8 +2180,8 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader str
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step { switch step {
case 0: case 0:
xlsx, err := excelize.OpenFile("111.xlsx") // xlsx, err := excelize.OpenFile("111.xlsx")
// xlsx, err := excelize.OpenReader(reader) xlsx, err := excelize.OpenReader(reader)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@@ -510,9 +510,9 @@ func (c *StoreSkuController) RefreshJxPriceByExcel() {
var storeIDList []int var storeIDList []int
c.callRefreshJxPriceByExcel(func(params *tStoreSkuRefreshJxPriceByExcelParams) (retVal interface{}, errCode string, err error) { c.callRefreshJxPriceByExcel(func(params *tStoreSkuRefreshJxPriceByExcelParams) (retVal interface{}, errCode string, err error) {
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
// r := c.Ctx.Request r := c.Ctx.Request
// files := r.MultipartForm.File["userfiles"] files := r.MultipartForm.File["userfiles"]
retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, "files", params.IsAsync, params.IsContinueWhenError) retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, files, params.IsAsync, params.IsContinueWhenError)
} }
return retVal, "", err return retVal, "", err
}) })