读取永辉Excel测试
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
@@ -90,21 +92,24 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i
|
|||||||
}
|
}
|
||||||
fileHeader := files[0]
|
fileHeader := files[0]
|
||||||
file, err := fileHeader.Open()
|
file, err := fileHeader.Open()
|
||||||
fmt.Println(fileHeader.Filename)
|
fileName := fileHeader.Filename
|
||||||
// hint, err = LoadExcelBinByYongHui(ctx, file, true, true)
|
hint, err = LoadExcelBinByYongHui(ctx, file, fileName, true, true)
|
||||||
file.Close()
|
file.Close()
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, fileName string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
var (
|
var (
|
||||||
skuMap = make(map[string]float64)
|
skuMap = make(map[string]float64)
|
||||||
errMsg string
|
errMsg string
|
||||||
costPrice float64 //成本价
|
costPrice float64 //成本价
|
||||||
goodsList []*weimobapi.GoodsInfo
|
goodsList []*weimobapi.GoodsInfo
|
||||||
goodsIDListForPutAway []interface{}
|
goodsIDListForPutAway []interface{}
|
||||||
|
isCompare bool
|
||||||
|
skuMap2 = make(map[string]float64)
|
||||||
)
|
)
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
|
skuMap2["999386"] = 3.99
|
||||||
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:
|
||||||
@@ -132,7 +137,7 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
//修改分组名
|
//修改分组名
|
||||||
// 分类名格式为:可定XX日
|
// 分类名格式为:可定XX日
|
||||||
// XX为上传永辉 提供的 价格表时间 +2天
|
// XX为上传永辉 提供的 价格表时间 +2天
|
||||||
|
isCompare, err = UpdateClassifyAndGetLastClassify(fileName)
|
||||||
case 1:
|
case 1:
|
||||||
//获取微盟所有商品
|
//获取微盟所有商品
|
||||||
goodsList, err = GetWeiMobGoodsList()
|
goodsList, err = GetWeiMobGoodsList()
|
||||||
@@ -170,7 +175,7 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
spuCode := goodsDetail.OuterGoodsCode
|
spuCode := goodsDetail.OuterGoodsCode
|
||||||
if spuCode != "" {
|
if spuCode != "" {
|
||||||
//如果微盟商品里找得到excel中的商品
|
//如果微盟商品里找得到excel中的商品
|
||||||
if skuMap[spuCode] != 0 {
|
if skuMap2[spuCode] != 0 {
|
||||||
//获取京西库商品
|
//获取京西库商品
|
||||||
skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil)
|
skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil)
|
||||||
if len(skuList) == 0 {
|
if len(skuList) == 0 {
|
||||||
@@ -178,15 +183,15 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
} else {
|
} else {
|
||||||
if skuList[0].Unit == "份" {
|
if skuList[0].Unit == "份" {
|
||||||
if goodsDetail.SkuMap.SingleSku.B2CSku.Weight == 0 {
|
if goodsDetail.SkuMap.SingleSku.B2CSku.Weight == 0 {
|
||||||
costPrice = skuMap[spuCode]
|
costPrice = skuMap2[spuCode]
|
||||||
} else {
|
} else {
|
||||||
costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode])
|
costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap2[spuCode])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
costPrice = skuMap[spuCode]
|
costPrice = skuMap2[spuCode]
|
||||||
}
|
}
|
||||||
// if errMsg == "" {
|
// if errMsg == "" {
|
||||||
_, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail)
|
_, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], isCompare, goodsDetail)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -211,7 +216,7 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
for _, v := range batchItemList {
|
for _, v := range batchItemList {
|
||||||
int64Slice = append(int64Slice, v.(int64))
|
int64Slice = append(int64Slice, v.(int64))
|
||||||
}
|
}
|
||||||
PutAwayWeiMobSku(int64Slice)
|
// PutAwayWeiMobSku(int64Slice)
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
|
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
|
||||||
@@ -264,13 +269,14 @@ func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[st
|
|||||||
// return list
|
// return list
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) {
|
func updateWeiMobGoods(costPrice, salePrice float64, isCompare bool, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) {
|
||||||
var (
|
var (
|
||||||
categoryList []*weimobapi.CategoryList
|
categoryList []*weimobapi.CategoryList
|
||||||
skuListInfo = goodsDetail.SkuList[0]
|
skuListInfo = goodsDetail.SkuList[0]
|
||||||
skuListParam []*weimobapi.SkuList
|
skuListParam []*weimobapi.SkuList
|
||||||
categoryID int
|
categoryID int
|
||||||
deliveryTypeListSlice []int64
|
deliveryTypeListSlice []int64
|
||||||
|
newSkuTitle string
|
||||||
)
|
)
|
||||||
|
|
||||||
//查询配送方式
|
//查询配送方式
|
||||||
@@ -297,16 +303,51 @@ func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.Good
|
|||||||
return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息!goodsID : [%v] ,", goodsDetail.GoodsID))
|
return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息!goodsID : [%v] ,", goodsDetail.GoodsID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//商品分组(原有的分组IDs)
|
||||||
selectedClassifyList := goodsDetail.SelectedClassifyList
|
selectedClassifyList := goodsDetail.SelectedClassifyList
|
||||||
var selectedClassifyListID []int64
|
selectedClassifyListIDMap := make(map[int64]int64)
|
||||||
if len(selectedClassifyList) > 0 {
|
if len(selectedClassifyList) > 0 {
|
||||||
for _, v := range selectedClassifyList {
|
for _, v := range selectedClassifyList {
|
||||||
selectedClassifyListID = append(selectedClassifyListID, v.ChildrenClassify[0].ClassifyID)
|
for _, v := range v.ChildrenClassify {
|
||||||
|
selectedClassifyListIDMap[v.ClassifyID] = v.ClassifyID
|
||||||
}
|
}
|
||||||
// categoryID = categoryList[len(categoryList)-1].CategoryID
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//上次上传价格和这次上传价格对比
|
||||||
|
// 4、微盟商品。两个重要分组
|
||||||
|
// 降价超0.2元,与前一日数据对比,需要将此类商品增加分类到这里,不改变原分类
|
||||||
|
// 涨价超0.2元,与前一日数据对比,需要将此类商品增加分类到这里,不改变原分类
|
||||||
|
// 其他商品,取消 这两个分类
|
||||||
|
// 同一天第二次上传的处理,需要注意是与前一天价格的对比,不是当天的价格对比。
|
||||||
|
|
||||||
|
// 5. 涨价和跌价值保留2位小数
|
||||||
|
// 需要在每个商品中增加↑0.01或↓0.02。
|
||||||
|
// 显示在商品最前的括号里,如果没有括号,需要增加。都用小写的括号,大写括号需要删除。
|
||||||
|
// 包装菜需要增加“精”,其他不需要加字,比如:
|
||||||
|
// (精↓2.11)新土豆1kg/袋
|
||||||
|
// (↓2.11)新土豆1kg
|
||||||
|
//salePrice 这次上传的价格 goodsDetail.SkuMap.SingleSku.SalePrice 上次上传的价格 priceMix 两次上传价格差 priceMixRound 保留两位后的价格差
|
||||||
|
if !isCompare {
|
||||||
|
priceMix := salePrice - goodsDetail.SkuMap.SingleSku.SalePrice
|
||||||
|
if priceMix > 0.2 {
|
||||||
|
delete(selectedClassifyListIDMap, 1064198248)
|
||||||
|
delete(selectedClassifyListIDMap, 1065246248)
|
||||||
|
selectedClassifyListIDMap[1064198248] = 1064198248
|
||||||
|
} else if priceMix < -0.2 {
|
||||||
|
delete(selectedClassifyListIDMap, 1064198248)
|
||||||
|
delete(selectedClassifyListIDMap, 1065246248)
|
||||||
|
selectedClassifyListIDMap[1065246248] = 1065246248
|
||||||
} else {
|
} else {
|
||||||
return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息!goodsID : [%v] ,", goodsDetail.GoodsID))
|
delete(selectedClassifyListIDMap, 1064198248)
|
||||||
|
delete(selectedClassifyListIDMap, 1065246248)
|
||||||
}
|
}
|
||||||
|
priceMixRound := Float64Round(priceMix)
|
||||||
|
newSkuTitle = GetNewSkuTitle(priceMixRound, goodsDetail.Title, goodsDetail.OuterGoodsCode)
|
||||||
|
} else {
|
||||||
|
newSkuTitle = goodsDetail.Title
|
||||||
|
}
|
||||||
|
|
||||||
b2CSku := &weimobapi.B2CSku{
|
b2CSku := &weimobapi.B2CSku{
|
||||||
Weight: skuListInfo.B2CSku.Weight,
|
Weight: skuListInfo.B2CSku.Weight,
|
||||||
Volume: skuListInfo.B2CSku.Volume,
|
Volume: skuListInfo.B2CSku.Volume,
|
||||||
@@ -328,7 +369,7 @@ func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.Good
|
|||||||
goods := &weimobapi.Goods{
|
goods := &weimobapi.Goods{
|
||||||
B2CGoods: b2CGoods,
|
B2CGoods: b2CGoods,
|
||||||
SkuList: skuListParam,
|
SkuList: skuListParam,
|
||||||
Title: goodsDetail.Title,
|
Title: newSkuTitle,
|
||||||
IsMultiSku: goodsDetail.IsMultiSku,
|
IsMultiSku: goodsDetail.IsMultiSku,
|
||||||
IsPutAway: weimobapi.GoodsTypeNormal,
|
IsPutAway: weimobapi.GoodsTypeNormal,
|
||||||
GoodsImageURL: goodsDetail.GoodsImageURL,
|
GoodsImageURL: goodsDetail.GoodsImageURL,
|
||||||
@@ -336,7 +377,7 @@ func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.Good
|
|||||||
CategoryID: categoryID,
|
CategoryID: categoryID,
|
||||||
OuterGoodsCode: goodsDetail.OuterGoodsCode,
|
OuterGoodsCode: goodsDetail.OuterGoodsCode,
|
||||||
PointDeductRatio: goodsDetail.PointDeductRatio,
|
PointDeductRatio: goodsDetail.PointDeductRatio,
|
||||||
SelectedClassifyIDList: selectedClassifyListID,
|
SelectedClassifyIDList: Map2Int64Slice(selectedClassifyListIDMap),
|
||||||
}
|
}
|
||||||
updateGoodsParam := &weimobapi.UpdateGoodsParam{
|
updateGoodsParam := &weimobapi.UpdateGoodsParam{
|
||||||
Goods: goods,
|
Goods: goods,
|
||||||
@@ -422,3 +463,66 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM
|
|||||||
func Float64Round(f float64) (flt float64) {
|
func Float64Round(f float64) (flt float64) {
|
||||||
return math.Round(f*100) / 100
|
return math.Round(f*100) / 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Map2Int64Slice(m map[int64]int64) (result []int64) {
|
||||||
|
for _, v := range m {
|
||||||
|
result = append(result, v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateClassifyAndGetLastClassify(fileName string) (isCompare bool, err error) {
|
||||||
|
var lastTitle string
|
||||||
|
classfiyList, err := api.WeimobAPI.QueryClassifyInfoList()
|
||||||
|
for _, v := range classfiyList {
|
||||||
|
if v.ClassifyID == 1065244148 {
|
||||||
|
lastTitle = v.Title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
title := "可定"
|
||||||
|
now := time.Now()
|
||||||
|
year := now.Year()
|
||||||
|
s := fileName[0:strings.LastIndex(fileName, ".")]
|
||||||
|
fileTimeStr := s[12:len(s)]
|
||||||
|
fileMonth := fileTimeStr[0:strings.Index(fileTimeStr, ".")]
|
||||||
|
fileDay := fileTimeStr[strings.Index(fileTimeStr, ".")+1 : len(fileTimeStr)]
|
||||||
|
fileTime := utils.Str2Time(utils.Int2Str(year) + "-" + fileMonth + "-" + fileDay + " 00:00:00")
|
||||||
|
title += utils.Int2Str(fileTime.AddDate(0, 0, 2).Day()) + "日"
|
||||||
|
err = api.WeimobAPI.UpdateClassify(1065244148, title, "")
|
||||||
|
return lastTitle == title, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNewSkuTitle(priceMixRound float64, title, outerGoodsCode string) (name string) {
|
||||||
|
var prefix = ""
|
||||||
|
if outerGoodsCode[0:1] != "0" {
|
||||||
|
prefix += "(精"
|
||||||
|
if priceMixRound > 0 {
|
||||||
|
prefix += "↑"
|
||||||
|
} else if priceMixRound < 0 {
|
||||||
|
prefix += "↓"
|
||||||
|
} else {
|
||||||
|
prefix += ")"
|
||||||
|
return GetReplaceNewTitle(title, prefix)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if priceMixRound > 0 {
|
||||||
|
prefix += "(↑"
|
||||||
|
} else if priceMixRound < 0 {
|
||||||
|
prefix += "(↓"
|
||||||
|
} else {
|
||||||
|
return GetReplaceNewTitle(title, prefix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prefix += utils.Float64ToStr(priceMixRound) + ")"
|
||||||
|
return GetReplaceNewTitle(title, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetReplaceNewTitle(title, prefix string) (newTitle string) {
|
||||||
|
if title[0:3] == "(" {
|
||||||
|
return strings.Replace(title, title[0:strings.Index(title, ")")+3], prefix, 1)
|
||||||
|
} else if title[0:1] == "(" {
|
||||||
|
return strings.Replace(title, title[0:strings.Index(title, ")")+1], prefix, 1)
|
||||||
|
} else {
|
||||||
|
return prefix + title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user