根据Excel更新京西价
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
|
||||
@@ -2179,6 +2180,8 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
storeSkuNamePriceListUpdate []*model.StoreSkuNamePrice
|
||||
skuBindInfosInter []interface{}
|
||||
skuBindInfoList []*StoreSkuBindInfo
|
||||
errMsg string
|
||||
isErr bool = false
|
||||
)
|
||||
dataLock.dataFailedList = dataLock.dataFailedList[0:0]
|
||||
dataLock.dataSuccessList = dataLock.dataSuccessList[0:0]
|
||||
@@ -2194,7 +2197,6 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
switch step {
|
||||
case 0:
|
||||
xlsx, err := excelize.OpenReader(reader)
|
||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -2204,9 +2206,14 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
continue
|
||||
}
|
||||
storeSkuNamePrice := &model.StoreSkuNamePrice{}
|
||||
GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
||||
errMsg += GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
||||
storeSkuNamePriceList = append(storeSkuNamePriceList, storeSkuNamePrice)
|
||||
}
|
||||
if errMsg != "" {
|
||||
return "", errors.New(errMsg)
|
||||
} else {
|
||||
isErr = true
|
||||
}
|
||||
case 1:
|
||||
db := dao.GetDB()
|
||||
storeSkuNamePriceListOrg, _ := dao.GetStoreSkuNamePrice(db)
|
||||
@@ -2244,9 +2251,9 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
NameID: nameID,
|
||||
Name: skuList[0].Name,
|
||||
Unit: storeSkuNamePrice.Unit,
|
||||
OrgPrice: utils.Str2Float64(utils.Int64ToStr(skuList[0].UnitPrice / 100)),
|
||||
NowPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice / 100))),
|
||||
MixPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice) - skuList[0].UnitPrice)),
|
||||
OrgPrice: utils.Str2Float64(utils.Int64ToStr(skuList[0].UnitPrice)) / 100,
|
||||
NowPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice))) / 100,
|
||||
MixPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice)-skuList[0].UnitPrice)) / 100,
|
||||
}
|
||||
dataLock.AppendDataSuccess(outSuccess)
|
||||
} else {
|
||||
@@ -2280,7 +2287,9 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
for _, v := range skuBindInfosInter {
|
||||
skuBindInfoList = append(skuBindInfoList, v.(*StoreSkuBindInfo))
|
||||
}
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError)
|
||||
if isErr {
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
case 3:
|
||||
//写Excel
|
||||
WriteToExcelJx(task, dataLock.dataSuccessList, dataLock.dataFailedList)
|
||||
@@ -2367,9 +2376,12 @@ func StoreSkuNamePriceList2Map(ctx *jxcontext.Context, storeSkuNamePriceList []*
|
||||
return result
|
||||
}
|
||||
|
||||
func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSkuNamePrice *model.StoreSkuNamePrice) {
|
||||
func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSkuNamePrice *model.StoreSkuNamePrice) (errMsg string) {
|
||||
for k, cell := range row {
|
||||
if k == sheetParam.OutSkuIDCol {
|
||||
if IsChineseChar(cell) {
|
||||
return fmt.Sprintf("Excel格式排版发生了变化!在[%v]列,[%v]行附近可能增加或减少了一列", k+1, rowNum+1)
|
||||
}
|
||||
storeSkuNamePrice.OutSkuID = cell
|
||||
}
|
||||
if k == sheetParam.SkuNameCol {
|
||||
@@ -2385,12 +2397,16 @@ func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSk
|
||||
storeSkuNamePrice.NameIDGroup = cellReplace
|
||||
}
|
||||
if k == sheetParam.SkuPriceCol {
|
||||
if IsChineseChar(cell) {
|
||||
return fmt.Sprintf("Excel格式排版发生了变化!在[%v]列,[%v]行附近可能增加或减少了一列", k+1, rowNum+1)
|
||||
}
|
||||
storeSkuNamePrice.Price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100))
|
||||
}
|
||||
if k == sheetParam.SkuUnitCol {
|
||||
storeSkuNamePrice.Unit = cell
|
||||
}
|
||||
}
|
||||
return errMsg
|
||||
}
|
||||
|
||||
func (d *DataLock) AppendDataSuccess(dataSuccess DataSuccess) {
|
||||
@@ -2404,3 +2420,12 @@ func (d *DataLock) AppendDataFailed(dataFailed DataFailed) {
|
||||
defer d.locker.Unlock()
|
||||
d.dataFailedList = append(d.dataFailedList, dataFailed)
|
||||
}
|
||||
|
||||
func IsChineseChar(str string) bool {
|
||||
for _, r := range str {
|
||||
if unicode.Is(unicode.Scripts["Han"], r) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -555,15 +554,6 @@ func GetWeiMobGoodsList(param *weimobapi.QueryGoodsListParam) (goodsList []*weim
|
||||
return goodsList, err
|
||||
}
|
||||
|
||||
func IsChineseChar(str string) bool {
|
||||
for _, r := range str {
|
||||
if unicode.Is(unicode.Scripts["Han"], r) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row []string, sheetName string, rowNum int) (errMsg string) {
|
||||
var (
|
||||
skuID string
|
||||
@@ -613,10 +603,8 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [
|
||||
}
|
||||
if rowNum >= sheetParam.SkuRow {
|
||||
if rowNum == sheetParam.SkuRow {
|
||||
if IsChineseChar(skuID) {
|
||||
if IsChineseChar(skuID) {
|
||||
errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能增加了一行,请确认!", sheetName, rowNum)
|
||||
}
|
||||
if cms.IsChineseChar(skuID) {
|
||||
errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能增加了一行,请确认!", sheetName, rowNum)
|
||||
}
|
||||
}
|
||||
if len(skuMap) > 0 {
|
||||
@@ -649,7 +637,7 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [
|
||||
delete(skuMap, "")
|
||||
} else {
|
||||
for i := rowNum; i < sheetParam.SkuRow; i++ {
|
||||
if !IsChineseChar(skuID) {
|
||||
if !cms.IsChineseChar(skuID) {
|
||||
errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能减少了一行,请确认!", sheetName, rowNum)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user