Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark
This commit is contained in:
@@ -6,6 +6,9 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
@@ -14,6 +17,8 @@ import (
|
|||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
|
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
|
||||||
|
"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/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
@@ -26,64 +31,139 @@ import (
|
|||||||
type SheetParam struct {
|
type SheetParam struct {
|
||||||
SkuIDCol int
|
SkuIDCol int
|
||||||
SkuPriceCol int
|
SkuPriceCol int
|
||||||
|
SkuNameCol int
|
||||||
OrgSkuIdCol int
|
OrgSkuIdCol int
|
||||||
OrgSkuPriceCol int
|
OrgSkuPriceCol int
|
||||||
|
OrgSkuNameCol int
|
||||||
SkuRow int
|
SkuRow int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DataSuccessLock struct {
|
||||||
|
dataSuccessList []DataSuccess
|
||||||
|
locker sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataFailedLock struct {
|
||||||
|
dataFailedList []DataFailed
|
||||||
|
locker sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataSuccess struct {
|
||||||
|
NameID string `json:"商品nameID"`
|
||||||
|
Name string `json:"商品名称"`
|
||||||
|
Unit string `json:"单位"`
|
||||||
|
OrgPrice float64 `json:"原价"`
|
||||||
|
NowPrice float64 `json:"现价"`
|
||||||
|
MixPrice float64 `json:"涨跌"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataFailed struct {
|
||||||
|
GoodsID string `json:"商品ID"`
|
||||||
|
GoodsName string `json:"商品名称"`
|
||||||
|
Comment string `json:"备注"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExcelParam struct {
|
||||||
|
SpuCode string
|
||||||
|
Name string
|
||||||
|
Price float64
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
sheetMap = map[string]*SheetParam{
|
sheetMap = map[string]*SheetParam{
|
||||||
"蔬菜": &SheetParam{
|
"蔬菜": &SheetParam{
|
||||||
SkuIDCol: 0,
|
SkuIDCol: 0,
|
||||||
SkuPriceCol: 14,
|
SkuPriceCol: 14,
|
||||||
|
SkuNameCol: 1,
|
||||||
OrgSkuIdCol: 5,
|
OrgSkuIdCol: 5,
|
||||||
OrgSkuPriceCol: 8,
|
OrgSkuPriceCol: 8,
|
||||||
|
OrgSkuNameCol: 6,
|
||||||
SkuRow: 2,
|
SkuRow: 2,
|
||||||
}, "水果": &SheetParam{
|
}, "水果": &SheetParam{
|
||||||
SkuIDCol: 0,
|
SkuIDCol: 0,
|
||||||
SkuPriceCol: 14,
|
SkuPriceCol: 14,
|
||||||
|
SkuNameCol: 1,
|
||||||
OrgSkuIdCol: 5,
|
OrgSkuIdCol: 5,
|
||||||
OrgSkuPriceCol: 8,
|
OrgSkuPriceCol: 8,
|
||||||
|
OrgSkuNameCol: 6,
|
||||||
SkuRow: 2,
|
SkuRow: 2,
|
||||||
}, "肉禽": &SheetParam{
|
}, "肉禽": &SheetParam{
|
||||||
SkuIDCol: 0,
|
SkuIDCol: 0,
|
||||||
SkuPriceCol: 12,
|
SkuPriceCol: 12,
|
||||||
|
SkuNameCol: 1,
|
||||||
OrgSkuIdCol: 4,
|
OrgSkuIdCol: 4,
|
||||||
OrgSkuPriceCol: 7,
|
OrgSkuPriceCol: 7,
|
||||||
|
OrgSkuNameCol: 5,
|
||||||
SkuRow: 1,
|
SkuRow: 1,
|
||||||
}, "净配": &SheetParam{
|
}, "净配": &SheetParam{
|
||||||
SkuIDCol: 0,
|
SkuIDCol: 0,
|
||||||
SkuPriceCol: 12,
|
SkuPriceCol: 12,
|
||||||
|
SkuNameCol: 1,
|
||||||
OrgSkuIdCol: 4,
|
OrgSkuIdCol: 4,
|
||||||
OrgSkuPriceCol: 7,
|
OrgSkuPriceCol: 7,
|
||||||
|
OrgSkuNameCol: 5,
|
||||||
SkuRow: 1,
|
SkuRow: 1,
|
||||||
}, "水产": &SheetParam{
|
}, "水产": &SheetParam{
|
||||||
SkuIDCol: 1,
|
SkuIDCol: 1,
|
||||||
SkuPriceCol: 15,
|
SkuPriceCol: 15,
|
||||||
|
SkuNameCol: 2,
|
||||||
OrgSkuIdCol: 6,
|
OrgSkuIdCol: 6,
|
||||||
OrgSkuPriceCol: 9,
|
OrgSkuPriceCol: 9,
|
||||||
|
OrgSkuNameCol: 7,
|
||||||
SkuRow: 1,
|
SkuRow: 1,
|
||||||
}, "干货": &SheetParam{
|
}, "干货": &SheetParam{
|
||||||
SkuIDCol: 0,
|
SkuIDCol: 0,
|
||||||
SkuPriceCol: 13,
|
SkuPriceCol: 13,
|
||||||
|
SkuNameCol: 1,
|
||||||
OrgSkuIdCol: 4,
|
OrgSkuIdCol: 4,
|
||||||
OrgSkuPriceCol: 7,
|
OrgSkuPriceCol: 7,
|
||||||
|
OrgSkuNameCol: 5,
|
||||||
SkuRow: 2,
|
SkuRow: 2,
|
||||||
}, "MINI肉禽价格": &SheetParam{
|
}, "MINI肉禽价格": &SheetParam{
|
||||||
SkuIDCol: 1,
|
SkuIDCol: 1,
|
||||||
SkuPriceCol: 5,
|
SkuPriceCol: 5,
|
||||||
|
SkuNameCol: 2,
|
||||||
OrgSkuIdCol: -1,
|
OrgSkuIdCol: -1,
|
||||||
OrgSkuPriceCol: -1,
|
OrgSkuPriceCol: -1,
|
||||||
|
OrgSkuNameCol: -1,
|
||||||
SkuRow: 1,
|
SkuRow: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
titleListSuccess = []string{
|
||||||
|
"商品nameID",
|
||||||
|
"商品名称",
|
||||||
|
"单位",
|
||||||
|
"原价",
|
||||||
|
"现价",
|
||||||
|
"涨跌",
|
||||||
|
}
|
||||||
|
titleListFailed = []string{
|
||||||
|
"商品ID",
|
||||||
|
"商品名称",
|
||||||
|
"备注",
|
||||||
|
}
|
||||||
|
dataSuccess DataSuccessLock
|
||||||
|
dataFailed DataFailedLock
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
parallelCount = 5
|
parallelCount = 5
|
||||||
UpdateGoodsShelfStatusCount = 50 //微盟下架商品api限制一次50个
|
UpdateGoodsShelfStatusCount = 50 //微盟下架商品api限制一次50个
|
||||||
|
fileExt = ".xlsx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (d *DataSuccessLock) AppendData(dataSuccess DataSuccess) {
|
||||||
|
d.locker.Lock()
|
||||||
|
defer d.locker.Unlock()
|
||||||
|
d.dataSuccessList = append(d.dataSuccessList, dataSuccess)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DataFailedLock) AppendData2(dataFailed DataFailed) {
|
||||||
|
d.locker.Lock()
|
||||||
|
defer d.locker.Unlock()
|
||||||
|
d.dataFailedList = append(d.dataFailedList, dataFailed)
|
||||||
|
}
|
||||||
|
|
||||||
func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return "", errors.New("没有文件上传!")
|
return "", errors.New("没有文件上传!")
|
||||||
@@ -97,11 +177,12 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i
|
|||||||
|
|
||||||
func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
var (
|
var (
|
||||||
skuMap = make(map[string]float64)
|
skuMap = make(map[string]*ExcelParam)
|
||||||
errMsg string
|
errMsg string
|
||||||
costPrice float64 //成本价
|
costPrice float64 //成本价
|
||||||
goodsList []*weimobapi.GoodsInfo
|
goodsList []*weimobapi.GoodsInfo
|
||||||
goodsIDListForPutAway []interface{}
|
goodsIDListForPutAway []interface{}
|
||||||
|
isCompare bool
|
||||||
)
|
)
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
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) {
|
||||||
@@ -119,7 +200,7 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
if rowNum < sheetParam.SkuRow {
|
if rowNum < sheetParam.SkuRow {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
GetCellIntoMap(sheetParam.SkuIDCol, sheetParam.SkuPriceCol, sheetParam.OrgSkuIdCol, sheetParam.OrgSkuPriceCol, skuMap, row, k, rowNum)
|
GetCellIntoMap(sheetParam, skuMap, row, k, rowNum)
|
||||||
if len(skuMap) < 1 {
|
if len(skuMap) < 1 {
|
||||||
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]\n", k)
|
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]\n", k)
|
||||||
}
|
}
|
||||||
@@ -128,6 +209,10 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
return "", errors.New(errMsg)
|
return "", errors.New(errMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//修改分组名
|
||||||
|
// 分类名格式为:可定XX日
|
||||||
|
// XX为上传永辉 提供的 价格表时间 +2天
|
||||||
|
isCompare, err = UpdateClassifyAndGetLastClassify()
|
||||||
case 1:
|
case 1:
|
||||||
//获取微盟所有商品
|
//获取微盟所有商品
|
||||||
goodsList, err = GetWeiMobGoodsList()
|
goodsList, err = GetWeiMobGoodsList()
|
||||||
@@ -151,12 +236,15 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
for k, _ := range skuMap {
|
for k, _ := range skuMap {
|
||||||
//表示excel上有,微盟上没有
|
//表示excel上有,微盟上没有
|
||||||
if goodsInfoAndDetailMap[k] == nil {
|
if goodsInfoAndDetailMap[k] == nil {
|
||||||
errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k)
|
outPutData := DataFailed{
|
||||||
|
GoodsID: k,
|
||||||
|
GoodsName: skuMap[k].Name,
|
||||||
|
Comment: "在微盟上未找到该商品",
|
||||||
|
}
|
||||||
|
dataFailed.AppendData2(outPutData)
|
||||||
|
// errMsg += fmt.Sprintf("在微盟上未找到该商品xxx", xxx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if errMsg != "" {
|
|
||||||
// return "", errors.New(errMsg)
|
|
||||||
// }
|
|
||||||
case 2:
|
case 2:
|
||||||
//找出微盟上有,excel上没有的,有就更新,没有就下架
|
//找出微盟上有,excel上没有的,有就更新,没有就下架
|
||||||
taskFunc3 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
taskFunc3 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
@@ -165,24 +253,48 @@ 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 skuMap[spuCode] != nil {
|
||||||
//获取京西库商品
|
//获取京西库商品
|
||||||
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 {
|
||||||
return "", errors.New(fmt.Sprintf("在京西库中未找到该商品!name_id : [%v]\n", goodsDetail.SkuMap.SingleSku.OuterSkuCode))
|
outPutData := DataFailed{
|
||||||
|
GoodsID: spuCode,
|
||||||
|
GoodsName: skuMap[spuCode].Name,
|
||||||
|
Comment: "在京西库中未找到该商品",
|
||||||
|
}
|
||||||
|
dataFailed.AppendData2(outPutData)
|
||||||
|
// return "", errors.New(fmt.Sprintf("在京西库中未找到该商品!name_id : [%v]\n", goodsDetail.SkuMap.SingleSku.OuterSkuCode))
|
||||||
} 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 = skuMap[spuCode].Price
|
||||||
} else {
|
} else {
|
||||||
costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode])
|
costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode].Price)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
costPrice = skuMap[spuCode]
|
costPrice = skuMap[spuCode].Price
|
||||||
|
}
|
||||||
|
_, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode].Price, isCompare, goodsDetail)
|
||||||
|
if err != nil {
|
||||||
|
if errExt, ok := err.(*utils.ErrorWithCode); ok {
|
||||||
|
outPutData := DataFailed{
|
||||||
|
GoodsID: spuCode,
|
||||||
|
GoodsName: skuMap[spuCode].Name,
|
||||||
|
Comment: errExt.ErrMsg(),
|
||||||
|
}
|
||||||
|
dataFailed.AppendData2(outPutData)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
outPutData := DataSuccess{
|
||||||
|
NameID: goodsDetail.SkuMap.SingleSku.OuterSkuCode,
|
||||||
|
Name: goodsDetail.Title,
|
||||||
|
Unit: skuList[0].Unit,
|
||||||
|
OrgPrice: goodsDetail.SkuMap.SingleSku.SalePrice,
|
||||||
|
NowPrice: skuMap[spuCode].Price,
|
||||||
|
MixPrice: Float64Round(skuMap[spuCode].Price - goodsDetail.SkuMap.SingleSku.SalePrice),
|
||||||
|
}
|
||||||
|
dataSuccess.AppendData(outPutData)
|
||||||
}
|
}
|
||||||
// if errMsg == "" {
|
|
||||||
_, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//下架微盟商品
|
//下架微盟商品
|
||||||
@@ -191,7 +303,7 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
}
|
}
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc3, goodsList)
|
taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc3, goodsList)
|
||||||
tasksch.HandleTask(taskParallel3, task, true).Run()
|
tasksch.HandleTask(taskParallel3, task, true).Run()
|
||||||
goodsIDListForPutAwayInterface, err2 := taskParallel3.GetResult(0)
|
goodsIDListForPutAwayInterface, err2 := taskParallel3.GetResult(0)
|
||||||
if err = err2; err != nil {
|
if err = err2; err != nil {
|
||||||
@@ -200,7 +312,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
goodsIDListForPutAway = goodsIDListForPutAwayInterface
|
goodsIDListForPutAway = goodsIDListForPutAwayInterface
|
||||||
case 3:
|
case 3:
|
||||||
// 批量下架微盟商品
|
// 批量下架微盟商品
|
||||||
// if errMsg == "" {
|
|
||||||
taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
int64Slice := []int64{}
|
int64Slice := []int64{}
|
||||||
for _, v := range batchItemList {
|
for _, v := range batchItemList {
|
||||||
@@ -212,14 +323,15 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
|||||||
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
|
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
|
||||||
tasksch.HandleTask(taskParallel4, task, true).Run()
|
tasksch.HandleTask(taskParallel4, task, true).Run()
|
||||||
_, err = taskParallel4.GetResult(0)
|
_, err = taskParallel4.GetResult(0)
|
||||||
|
case 4:
|
||||||
|
WriteToExcel(task, dataSuccess.dataSuccessList, dataFailed.dataFailedList)
|
||||||
|
}
|
||||||
|
// if errMsg != "" {
|
||||||
|
// return result, errors.New(errMsg)
|
||||||
// }
|
// }
|
||||||
}
|
|
||||||
if errMsg != "" {
|
|
||||||
return result, errors.New(errMsg)
|
|
||||||
}
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
taskSeq := tasksch.NewSeqTask2("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, isContinueWhenError, taskSeqFunc, 4)
|
taskSeq := tasksch.NewSeqTask2("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, isContinueWhenError, taskSeqFunc, 5)
|
||||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||||
if !isAsync {
|
if !isAsync {
|
||||||
_, err = taskSeq.GetResult(0)
|
_, err = taskSeq.GetResult(0)
|
||||||
@@ -259,13 +371,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
|
||||||
)
|
)
|
||||||
|
|
||||||
//查询配送方式
|
//查询配送方式
|
||||||
@@ -292,16 +405,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,
|
||||||
@@ -323,7 +471,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,
|
||||||
@@ -331,7 +479,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,
|
||||||
@@ -372,15 +520,24 @@ func IsChineseChar(str string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuMap map[string]float64, row []string, sheetName string, rowNum int) {
|
func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row []string, sheetName string, rowNum int) {
|
||||||
var (
|
var (
|
||||||
skuID string
|
skuID string
|
||||||
orgSkuID string
|
orgSkuID string
|
||||||
skuPrice float64
|
skuPrice float64
|
||||||
orgSkuPrice float64
|
orgSkuPrice float64
|
||||||
|
skuName string
|
||||||
|
orgSkuName string
|
||||||
|
skuIDCol = sheetParam.SkuIDCol
|
||||||
|
skuPriceCol = sheetParam.SkuPriceCol
|
||||||
|
skuNameCol = sheetParam.SkuNameCol
|
||||||
|
orgSkuIDCol = sheetParam.OrgSkuIdCol
|
||||||
|
orgSkuPriceCol = sheetParam.OrgSkuPriceCol
|
||||||
|
orgSkuNameCol = sheetParam.OrgSkuNameCol
|
||||||
)
|
)
|
||||||
for k, cell := range row {
|
for k, cell := range row {
|
||||||
if !IsChineseChar(cell) && cell != "" {
|
if cell != "" {
|
||||||
|
if !IsChineseChar(cell) {
|
||||||
if k == skuIDCol && skuIDCol >= 0 {
|
if k == skuIDCol && skuIDCol >= 0 {
|
||||||
skuID = cell
|
skuID = cell
|
||||||
}
|
}
|
||||||
@@ -394,26 +551,161 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM
|
|||||||
orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if k == skuNameCol && skuNameCol >= 0 {
|
||||||
|
skuName = cell
|
||||||
}
|
}
|
||||||
if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice {
|
if k == orgSkuNameCol && orgSkuNameCol >= 0 {
|
||||||
if skuPrice > skuMap[skuID] {
|
orgSkuName = cell
|
||||||
skuMap[skuID] = skuPrice
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(skuMap) > 0 {
|
||||||
|
if skuMap[skuID] != nil {
|
||||||
|
if skuMap[skuID].Price != 0 && skuMap[skuID].Price != skuPrice && skuPrice != 0 {
|
||||||
|
if skuPrice > skuMap[skuID].Price {
|
||||||
|
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||||
}
|
}
|
||||||
// fmt.Sprintf("读取excel表格出错!有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v] , 商品编码 :[%v] , 价格:[%v]\n", sheetName, rowNum, skuID, skuPrice)
|
|
||||||
} else {
|
} else {
|
||||||
skuMap[skuID] = skuPrice
|
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||||
}
|
}
|
||||||
if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice {
|
} else if skuPrice != 0 {
|
||||||
if orgSkuPrice > skuMap[orgSkuID] {
|
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||||
skuMap[orgSkuID] = orgSkuPrice
|
|
||||||
}
|
}
|
||||||
// fmt.Sprintf("读取excel表格出错!有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v], 商品编码 :[%v] , 价格:[%v]\n", sheetName, rowNum, orgSkuID, orgSkuPrice)
|
if skuMap[orgSkuID] != nil {
|
||||||
} else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 {
|
if skuMap[orgSkuID].Price != 0 && skuMap[orgSkuID].Price != orgSkuPrice && orgSkuPrice != 0 {
|
||||||
skuMap[orgSkuID] = orgSkuPrice
|
if orgSkuPrice > skuMap[orgSkuID].Price {
|
||||||
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
|
}
|
||||||
|
} else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 && orgSkuNameCol >= 0 {
|
||||||
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
|
}
|
||||||
|
} else if orgSkuPrice != 0 {
|
||||||
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||||
|
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||||
}
|
}
|
||||||
delete(skuMap, "")
|
delete(skuMap, "")
|
||||||
}
|
}
|
||||||
|
func BuildSkuMap(id, name string, price float64, skuMap map[string]*ExcelParam) {
|
||||||
|
excelParam := &ExcelParam{
|
||||||
|
SpuCode: id,
|
||||||
|
Price: price,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
skuMap[id] = excelParam
|
||||||
|
}
|
||||||
|
|
||||||
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() (isCompare bool, err error) {
|
||||||
|
var lastTitle string
|
||||||
|
classfiyList, err := api.WeimobAPI.QueryClassifyInfoList()
|
||||||
|
if len(classfiyList) > 0 {
|
||||||
|
for _, v := range classfiyList {
|
||||||
|
if v.ClassifyID == 1065244148 {
|
||||||
|
lastTitle = v.Title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
title := "可定"
|
||||||
|
now := time.Now()
|
||||||
|
afterDay := now.AddDate(0, 0, 2).Day()
|
||||||
|
title += utils.Int2Str(afterDay) + "日"
|
||||||
|
if lastTitle == title {
|
||||||
|
return true, err
|
||||||
|
} else {
|
||||||
|
err = api.WeimobAPI.UpdateClassify(1065244148, title, "")
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNewSkuTitle(priceMixRound float64, orgTitle, outerGoodsCode string) (name string) {
|
||||||
|
var prefix = ""
|
||||||
|
title1 := strings.ReplaceAll(orgTitle, "(", "(")
|
||||||
|
title := strings.ReplaceAll(title1, ")", ")")
|
||||||
|
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(math.Abs(priceMixRound)) + ")"
|
||||||
|
return GetReplaceNewTitle(title, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetReplaceNewTitle(title, prefix string) (newTitle string) {
|
||||||
|
if title[0:1] == "(" {
|
||||||
|
return strings.Replace(title, title[0:strings.Index(title, ")")+1], prefix, 1)
|
||||||
|
} else {
|
||||||
|
return prefix + title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteToExcel(task *tasksch.SeqTask, dataSuccess []DataSuccess, dataFailed []DataFailed) (err error) {
|
||||||
|
var sheetList1 []*excel.Obj2ExcelSheetConfig
|
||||||
|
var sheetList2 []*excel.Obj2ExcelSheetConfig
|
||||||
|
var downloadURL1, downloadURL2, fileName1, fileName2 string
|
||||||
|
excelConf1 := &excel.Obj2ExcelSheetConfig{
|
||||||
|
Title: "sheet1",
|
||||||
|
Data: dataSuccess,
|
||||||
|
CaptionList: titleListSuccess,
|
||||||
|
}
|
||||||
|
sheetList1 = append(sheetList1, excelConf1)
|
||||||
|
excelConf2 := &excel.Obj2ExcelSheetConfig{
|
||||||
|
Title: "sheet1",
|
||||||
|
Data: dataFailed,
|
||||||
|
CaptionList: titleListFailed,
|
||||||
|
}
|
||||||
|
sheetList2 = append(sheetList2, excelConf2)
|
||||||
|
if excelConf1 != nil {
|
||||||
|
downloadURL1, fileName1, err = UploadExeclAndPushMsg(sheetList1, "已更新商品")
|
||||||
|
} else {
|
||||||
|
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
|
||||||
|
}
|
||||||
|
if excelConf2 != nil {
|
||||||
|
downloadURL2, fileName2, err = UploadExeclAndPushMsg(sheetList2, "缺少商品_微盟")
|
||||||
|
} else {
|
||||||
|
baseapi.SugarLogger.Debug("WriteToExcel: dataFailed is nil!")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, fileName2, err)
|
||||||
|
} else {
|
||||||
|
noticeMsg := fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path1=%s, path2=%s \n", globals.BackstageHost, downloadURL1, downloadURL2)
|
||||||
|
task.SetNoticeMsg(noticeMsg)
|
||||||
|
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s ,%s success, downloadURL1:%s ,downloadURL2:%s", fileName1, fileName2, downloadURL1, downloadURL2)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func UploadExeclAndPushMsg(sheetList []*excel.Obj2ExcelSheetConfig, name string) (downloadURL, fileName string, err error) {
|
||||||
|
excelBin := excel.Obj2Excel(sheetList)
|
||||||
|
timeStr := utils.Int64ToStr(time.Now().Unix())
|
||||||
|
fileName = name + timeStr + fileExt
|
||||||
|
baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", fileName)
|
||||||
|
downloadURL, err = jxutils.UploadExportContent(excelBin, fileName)
|
||||||
|
return downloadURL, fileName, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user