读取永辉excel文件
This commit is contained in:
125
business/jxstore/yonghui/yonghui.go
Normal file
125
business/jxstore/yonghui/yonghui.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package yonghui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
"unicode"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
var (
|
||||
sheetNames = []string{"蔬菜", "水果", "肉禽", "净配", "水产", "干货", "MINI肉禽价格"}
|
||||
)
|
||||
|
||||
//sheet1 蔬菜
|
||||
var (
|
||||
sheet1SkuIdCol = 0
|
||||
sheet1SkuPriceCol = 14
|
||||
sheet1OrgSkuIdCol = 5
|
||||
sheet1OrgSkuPriceCol = 8
|
||||
)
|
||||
|
||||
func SendFilesToStores(ctx *jxcontext.Context, files []*multipart.FileHeader) (hint string, err error) {
|
||||
var (
|
||||
// skuId string
|
||||
// skuPrice string
|
||||
skuMap = make(map[string]string)
|
||||
)
|
||||
param := &weimobapi.QueryGoodsListParam{
|
||||
PageNum: 1,
|
||||
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds,
|
||||
}
|
||||
// if len(files) == 0 {
|
||||
// return "", errors.New("没有文件上传!")
|
||||
// }
|
||||
xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
for _, v := range sheetNames {
|
||||
// goodsParam := &weimobapi.GoodsParameter{}
|
||||
rows, _ := xlsx.GetRows(v)
|
||||
switch v {
|
||||
case "蔬菜":
|
||||
for _, row := range rows {
|
||||
for k, _ := range row {
|
||||
if k == sheet1SkuIdCol {
|
||||
|
||||
}
|
||||
// if !IsChineseChar(colCell) {
|
||||
|
||||
// }
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// xlFile, err := xlsx.OpenFile("111.xlsx")
|
||||
// if err != nil {
|
||||
// errors.New(err.Error())
|
||||
// }
|
||||
// excelize
|
||||
// for _, sheet := range xlFile.Sheets {
|
||||
// if sheet.Name == "蔬菜" {
|
||||
// for j := 0; j < len(sheet.Rows); j++ {
|
||||
// cells := sheet.Rows[j].Cells
|
||||
// for i := 0; i < len(cells); i++ {
|
||||
// cell := cells[i]
|
||||
// if i == 0 {
|
||||
// if _, err := strconv.Atoi(cell.String()); err != nil || cell.String() == "" {
|
||||
// continue
|
||||
// }
|
||||
// skuId = cell.String()
|
||||
// }
|
||||
// if i == 14 {
|
||||
// skuPrice = cell.String()
|
||||
// }
|
||||
// skuMap[skuId] = skuPrice
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for k, v := range skuMap {
|
||||
fmt.Println(k)
|
||||
fmt.Println(v)
|
||||
}
|
||||
|
||||
GetWeiMoGoodsList(param)
|
||||
return "", err
|
||||
}
|
||||
|
||||
func GetWeiMoGoodsList(param *weimobapi.QueryGoodsListParam) {
|
||||
// for {
|
||||
// skuList, _, err2 := getAPI("").QuerySkuInfos(param)
|
||||
// if err = err2; err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if len(skuList) > 0 {
|
||||
// batchSkuNameList := make([]*partner.SkuNameInfo, len(skuList))
|
||||
// for k, v := range skuList {
|
||||
// batchSkuNameList[k] = vendorSku2Jx(v)
|
||||
// }
|
||||
// setSkuNameListPic(batchSkuNameList)
|
||||
// skuNameList = append(skuNameList, batchSkuNameList...)
|
||||
// }
|
||||
// if len(skuList) < param.PageSize {
|
||||
// break
|
||||
// }
|
||||
// param.PageNum++
|
||||
// }
|
||||
}
|
||||
|
||||
func IsChineseChar(str string) bool {
|
||||
for _, r := range str {
|
||||
if unicode.Is(unicode.Scripts["Han"], r) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user