diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 08722141e..1d0b545cf 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -3,6 +3,7 @@ package yonghui import ( "errors" "fmt" + "io" "math" "mime/multipart" "unicode" @@ -16,6 +17,7 @@ import ( "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/dao" + "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" ) @@ -82,6 +84,17 @@ const ( ) func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync bool) (hint string, err error) { + if len(files) == 0 { + return "", errors.New("没有文件上传!") + } + fileHeader := files[0] + file, err := fileHeader.Open() + hint, err = LoadExcelBinByYongHui(ctx, file, isAsync) + file.Close() + return hint, err +} + +func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync bool) (hint string, err error) { var ( skuMap = make(map[string]float64) errMsg string @@ -90,18 +103,15 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i goodsIDListForPutAway []interface{} ) db := dao.GetDB() - if len(files) == 0 { - return "", errors.New("没有文件上传!") - } taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: //读取excel文件 - xlsx, err := excelize.OpenFile(files[0].Filename) + xlsx, err := excelize.OpenReader(reader) if err != nil { return "", err } - for k, _ := range sheetMap { + for k := range sheetMap { sheetParam := sheetMap[k] rows, _ := xlsx.GetRows(k) for rowNum, row := range rows { @@ -191,7 +201,7 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i for _, v := range batchItemList { int64Slice = append(int64Slice, v.(int64)) } - // PutAwayWeiMobSku(int64Slice) + PutAwayWeiMobSku(int64Slice) return retVal, err } taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway) @@ -215,11 +225,14 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i return hint, err } -func PutAwayWeiMobSku(goodsIDListForPutAway []int64) { - err := api.WeimobAPI.UpdateGoodsShelfStatus(goodsIDListForPutAway, false) +func PutAwayWeiMobSku(goodsIDListForPutAway []int64) (err error) { + if globals.EnableStoreWrite { + // err = api.WeimobAPI.UpdateGoodsShelfStatus(goodsIDListForPutAway, false) + } if err != nil { baseapi.SugarLogger.Errorf("UpdateGoodsShelfStatus error:%v", err) } + return err } func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[string]*weimobapi.GoodsInfo) { @@ -294,7 +307,10 @@ func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.Good updateGoodsParam := &weimobapi.UpdateGoodsParam{ Goods: goods, } - return api.WeimobAPI.UpdateGoods3(updateGoodsParam) + if globals.EnableStoreWrite { + goodsID, skuMap, err = api.WeimobAPI.UpdateGoods3(updateGoodsParam) + } + return goodsID, skuMap, err } func GetWeiMobGoodsList() (goodsList []*weimobapi.GoodsInfo, err error) { diff --git a/controllers/financial.go b/controllers/financial.go index 18b915519..893529fcb 100644 --- a/controllers/financial.go +++ b/controllers/financial.go @@ -8,6 +8,7 @@ import ( "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" "git.rosy.net.cn/jx-callback/business/jxstore/financial" + "git.rosy.net.cn/jx-callback/business/jxstore/yonghui" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/legacymodel" ) @@ -42,7 +43,11 @@ func (c *FinancialController) SendFilesToStores() { c.callSendFilesToStores(func(params *tFinancialSendFilesToStoresParams) (retVal interface{}, errCode string, err error) { r := c.Ctx.Request files := r.MultipartForm.File["userfiles"] - retVal, err = financial.SendFilesToStores(params.Ctx, files, params.Title, params.ShopName, params.IsAsync, params.Ctx.GetUserName()) + if params.Title != "永辉" { + retVal, err = financial.SendFilesToStores(params.Ctx, files, params.Title, params.ShopName, params.IsAsync, params.Ctx.GetUserName()) + } else { + retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) + } return retVal, "", err }) }