diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 980d8675a..1bfa564f0 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -3,8 +3,8 @@ package yonghui import ( "errors" "fmt" + "math" "mime/multipart" - "strconv" "unicode" "git.rosy.net.cn/baseapi" @@ -29,7 +29,51 @@ type SheetParam struct { } var ( - sheetMap = make(map[string]*SheetParam) + sheetMap = map[string]*SheetParam{ + "蔬菜": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 14, + OrgSkuIdCol: 5, + OrgSkuPriceCol: 8, + SkuRow: 2, + }, "水果": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 14, + OrgSkuIdCol: 5, + OrgSkuPriceCol: 8, + SkuRow: 2, + }, "肉禽": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 12, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 1, + }, "净配": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 12, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 1, + }, "水产": &SheetParam{ + SkuIDCol: 1, + SkuPriceCol: 15, + OrgSkuIdCol: 6, + OrgSkuPriceCol: 9, + SkuRow: 1, + }, "干货": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 13, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 2, + }, "MINI肉禽价格": &SheetParam{ + SkuIDCol: 1, + SkuPriceCol: 5, + OrgSkuIdCol: -1, + OrgSkuPriceCol: -1, + SkuRow: 1, + }, + } ) const ( @@ -43,23 +87,20 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i errMsg string costPrice float64 //成本价 goodsList []*weimobapi.GoodsInfo - goodsIDListForPutAway []int64 + goodsIDListForPutAway []interface{} ) db := dao.GetDB() if len(files) == 0 { return "", errors.New("没有文件上传!") } - - //读取excel文件 - xlsx, err := excelize.OpenFile(files[0].Filename) - // xlsx, err := excelize.OpenFile("111.xlsx") - if err != nil { - return "", err - } - initSheetMap() 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) + if err != nil { + return "", err + } for k, _ := range sheetMap { sheetParam := sheetMap[k] rows, _ := xlsx.GetRows(k) @@ -111,7 +152,6 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i goods := batchItemList[0].(*weimobapi.GoodsInfo) goodsDetail := goods.GoodsDetailInfo spuCode := goodsDetail.OuterGoodsCode - goodsIDListForPutAway := []int64{} if spuCode != "" { //如果微盟商品里找得到excel中的商品 if skuMap[spuCode] != 0 { @@ -131,10 +171,9 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i } } else { //下架微盟商品 - goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID) + retVal = []int64{goodsDetail.GoodsID} } } - retVal = goodsIDListForPutAway return retVal, err } taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc3, goodsList) @@ -144,9 +183,7 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i return "", err } // 批量下架微盟商品 - for _, v := range goodsIDListForPutAwayInterface { - goodsIDListForPutAway = append(goodsIDListForPutAway, v.(int64)) - } + goodsIDListForPutAway = goodsIDListForPutAwayInterface case 3: if errMsg == "" { taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { @@ -297,13 +334,13 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM skuID = cell } if k == skuPriceCol && skuPriceCol >= 0 { - skuPrice = Float64Round(utils.Str2Float64(cell)) + skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) } if k == orgSkuIDCol && orgSkuIDCol >= 0 { orgSkuID = "0" + cell } if k == orgSkuPriceCol && orgSkuPriceCol >= 0 { - orgSkuPrice = Float64Round(utils.Str2Float64(cell)) + orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) } } } @@ -327,61 +364,5 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM } func Float64Round(f float64) (flt float64) { - flt, err := strconv.ParseFloat(fmt.Sprintf("%.2f", f), 64) - if err != nil { - flt = 0 - } - return flt -} - -func initSheetMap() { - sheetMap["蔬菜"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 14, - OrgSkuIdCol: 5, - OrgSkuPriceCol: 8, - SkuRow: 2, - } - sheetMap["水果"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 14, - OrgSkuIdCol: 5, - OrgSkuPriceCol: 8, - SkuRow: 2, - } - sheetMap["肉禽"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 12, - OrgSkuIdCol: 4, - OrgSkuPriceCol: 7, - SkuRow: 1, - } - sheetMap["净配"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 12, - OrgSkuIdCol: 4, - OrgSkuPriceCol: 7, - SkuRow: 1, - } - sheetMap["水产"] = &SheetParam{ - SkuIDCol: 1, - SkuPriceCol: 15, - OrgSkuIdCol: 6, - OrgSkuPriceCol: 9, - SkuRow: 1, - } - sheetMap["干货"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 13, - OrgSkuIdCol: 4, - OrgSkuPriceCol: 7, - SkuRow: 2, - } - sheetMap["MINI肉禽价格"] = &SheetParam{ - SkuIDCol: 1, - SkuPriceCol: 5, - OrgSkuIdCol: -1, - OrgSkuPriceCol: -1, - SkuRow: 1, - } + return math.Round(f*100) / 100 }