刷新调价包
This commit is contained in:
@@ -1051,6 +1051,8 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
|||||||
} else {
|
} else {
|
||||||
err = ErrCanNotFindVendor
|
err = ErrCanNotFindVendor
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ReCalculateJxPrice(ctx, []int{storeID})
|
||||||
}
|
}
|
||||||
dao.WrapAddIDCULDEntity(storeMap, userName)
|
dao.WrapAddIDCULDEntity(storeMap, userName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -1148,6 +1150,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
|||||||
}
|
}
|
||||||
err = nil // todo 忽略读不到DeliveryType的错误
|
err = nil // todo 忽略读不到DeliveryType的错误
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||||
if len(valid) > 0 {
|
if len(valid) > 0 {
|
||||||
@@ -1168,6 +1171,9 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
|||||||
}
|
}
|
||||||
if err == nil && num > 0 {
|
if err == nil && num > 0 {
|
||||||
if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil {
|
if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil {
|
||||||
|
if vendorID == model.VendorIDJX {
|
||||||
|
ReCalculateJxPrice(ctx, []int{storeID})
|
||||||
|
}
|
||||||
storeSkuBind := &model.StoreSkuBind{}
|
storeSkuBind := &model.StoreSkuBind{}
|
||||||
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{
|
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{
|
||||||
model.FieldStoreID: storeID,
|
model.FieldStoreID: storeID,
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ package cms
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"math"
|
"math"
|
||||||
"mime/multipart"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -114,7 +112,7 @@ type SheetParam struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DataSuccess struct {
|
type DataSuccess struct {
|
||||||
NameID string `json:"商品编码"`
|
NameID int `json:"商品编码"`
|
||||||
Name string `json:"商品名称"`
|
Name string `json:"商品名称"`
|
||||||
OrgPrice float64 `json:"原价"`
|
OrgPrice float64 `json:"原价"`
|
||||||
NowPrice float64 `json:"现价"`
|
NowPrice float64 `json:"现价"`
|
||||||
@@ -2109,22 +2107,27 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
if len(files) == 0 {
|
// if len(files) == 0 {
|
||||||
return "", errors.New("没有文件上传!")
|
// return "", errors.New("没有文件上传!")
|
||||||
}
|
// }
|
||||||
if len(storeIDs) == 0 {
|
if len(storeIDs) == 0 {
|
||||||
return "", errors.New("请选择至少一个门店!")
|
return "", errors.New("请选择至少一个门店!")
|
||||||
}
|
}
|
||||||
fileHeader := files[0]
|
// fileHeader := files[0]
|
||||||
file, err := fileHeader.Open()
|
// file, err := fileHeader.Open()
|
||||||
hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, file, true, true)
|
hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, files, true, true)
|
||||||
file.Close()
|
// file.Close()
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
var storeSkuNamePriceList []*model.StoreSkuNamePrice
|
var (
|
||||||
|
storeSkuNamePriceList []*model.StoreSkuNamePrice
|
||||||
|
storeSkuNamePriceListUpdate []*model.StoreSkuNamePrice
|
||||||
|
skuBindInfosInter []interface{}
|
||||||
|
skuBindInfoList []*StoreSkuBindInfo
|
||||||
|
)
|
||||||
dataLock.dataFailedList = dataLock.dataFailedList[0:0]
|
dataLock.dataFailedList = dataLock.dataFailedList[0:0]
|
||||||
dataLock.dataSuccessList = dataLock.dataSuccessList[0:0]
|
dataLock.dataSuccessList = dataLock.dataSuccessList[0:0]
|
||||||
sheetParam := &SheetParam{
|
sheetParam := &SheetParam{
|
||||||
@@ -2135,40 +2138,78 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
|||||||
SkuUnitCol: 2,
|
SkuUnitCol: 2,
|
||||||
OutSkuIDCol: 0,
|
OutSkuIDCol: 0,
|
||||||
}
|
}
|
||||||
xlsx, err := excelize.OpenReader(reader)
|
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
if err != nil {
|
switch step {
|
||||||
return "", err
|
case 0:
|
||||||
}
|
xlsx, err := excelize.OpenFile("111.xlsx")
|
||||||
rows, _ := xlsx.GetRows(xlsx.GetSheetName(1))
|
// xlsx, err := excelize.OpenReader(reader)
|
||||||
for rowNum, row := range rows {
|
if err != nil {
|
||||||
if rowNum < sheetParam.SkuRow {
|
return "", err
|
||||||
continue
|
}
|
||||||
|
rows, _ := xlsx.GetRows(xlsx.GetSheetName(1))
|
||||||
|
for rowNum, row := range rows {
|
||||||
|
if rowNum < sheetParam.SkuRow {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
storeSkuNamePrice := &model.StoreSkuNamePrice{}
|
||||||
|
GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
||||||
|
storeSkuNamePriceList = append(storeSkuNamePriceList, storeSkuNamePrice)
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
db := dao.GetDB()
|
||||||
|
storeSkuNamePriceListOrg, _ := dao.GetStoreSkuNamePrice(db)
|
||||||
|
CreateOrUpdateStoreSkuNamePriceByExcel(db, ctx, storeSkuNamePriceList, storeSkuNamePriceListOrg)
|
||||||
|
storeSkuNamePriceListNew, _ := dao.GetStoreSkuNamePrice(db)
|
||||||
|
storeSkuNamePriceMapNew := StoreSkuNamePriceList2Map(ctx, storeSkuNamePriceListNew)
|
||||||
|
for _, v := range storeSkuNamePriceList {
|
||||||
|
if storeSkuNamePriceMapNew[v.OutSkuID] != nil {
|
||||||
|
storeSkuNamePriceListUpdate = append(storeSkuNamePriceListUpdate, storeSkuNamePriceMapNew[v.OutSkuID])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
storeSkuNamePrice := batchItemList[0].(*model.StoreSkuNamePrice)
|
||||||
|
var skuBindInfos []*StoreSkuBindInfo
|
||||||
|
nameIDGroup := strings.Split(storeSkuNamePrice.NameIDGroup, ",")
|
||||||
|
for _, v := range nameIDGroup {
|
||||||
|
if v != "" {
|
||||||
|
nameID := int(utils.Str2Int64(v))
|
||||||
|
storeSkuBindInfo := &StoreSkuBindInfo{
|
||||||
|
NameID: nameID,
|
||||||
|
UnitPrice: storeSkuNamePrice.Price,
|
||||||
|
}
|
||||||
|
skuBindInfos = append(skuBindInfos, storeSkuBindInfo)
|
||||||
|
for _, vv := range storeIDs {
|
||||||
|
skuList, err2 := dao.GetStoreSkusByNameIDs(db, []int{vv}, nameID)
|
||||||
|
err = err2
|
||||||
|
if len(skuList) > 0 {
|
||||||
|
outSuccess := DataSuccess{NameID: nameID}
|
||||||
|
dataLock.AppendDataSuccess(outSuccess)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
retVal = skuBindInfos
|
||||||
|
return retVal, err
|
||||||
|
}
|
||||||
|
taskParallel := tasksch.NewParallelTask("刷新京西价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeSkuNamePriceListUpdate)
|
||||||
|
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||||
|
skuBindInfosInter, err = taskParallel.GetResult(0)
|
||||||
|
case 2:
|
||||||
|
for _, v := range skuBindInfosInter {
|
||||||
|
skuBindInfoList = append(skuBindInfoList, v.(*StoreSkuBindInfo))
|
||||||
|
}
|
||||||
|
// UpdateStoresSkus(ctx, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError)
|
||||||
}
|
}
|
||||||
storeSkuNamePrice := &model.StoreSkuNamePrice{}
|
return result, err
|
||||||
GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
}
|
||||||
storeSkuNamePriceList = append(storeSkuNamePriceList, storeSkuNamePrice)
|
taskSeq := tasksch.NewSeqTask2("根据Excel刷新京西价", ctx, isContinueWhenError, taskSeqFunc, 3)
|
||||||
|
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||||
|
if !isAsync {
|
||||||
|
_, err = taskSeq.GetResult(0)
|
||||||
|
hint = "1"
|
||||||
|
} else {
|
||||||
|
hint = taskSeq.GetID()
|
||||||
}
|
}
|
||||||
db := dao.GetDB()
|
|
||||||
storeSkuNamePriceListOrg, err := dao.GetStoreSkuNamePrice(db)
|
|
||||||
CreateOrUpdateStoreSkuNamePriceByExcel(db, ctx, storeSkuNamePriceList, storeSkuNamePriceListOrg)
|
|
||||||
hint, err = RefershJxPrice(db)
|
|
||||||
return hint, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func RefershJxPrice(db *dao.DaoDB) (hint string, err error) {
|
|
||||||
// storeSkuNamePriceList, err := dao.GetStoreSkuNamePrice(db)
|
|
||||||
// task := tasksch.NewParallelTask("根据Excel刷新京西价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
|
||||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
|
||||||
|
|
||||||
// return retVal, err
|
|
||||||
// }, orderList)
|
|
||||||
// tasksch.HandleTask(task, nil, true).Run()
|
|
||||||
// if !isAsync {
|
|
||||||
// _, err = task.GetResult(0)
|
|
||||||
// hint = "1"
|
|
||||||
// } else {
|
|
||||||
// hint = task.GetID()
|
|
||||||
// }
|
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2184,9 +2225,11 @@ func CreateOrUpdateStoreSkuNamePriceByExcel(db *dao.DaoDB, ctx *jxcontext.Contex
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
for _, v := range storeSkuNamePriceList {
|
for _, v := range storeSkuNamePriceList {
|
||||||
|
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||||
if storeSkuNamePriceMap[v.OutSkuID] != nil {
|
if storeSkuNamePriceMap[v.OutSkuID] != nil {
|
||||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
v.ID = storeSkuNamePriceMap[v.OutSkuID].ID
|
||||||
dao.UpdateEntity(db, storeSkuNamePriceMap[v.OutSkuID], "Price", "NameIDGroup", "Unit", "CreatedAt", "UpdatedAt", "LastOperator", "DeletedAt")
|
v.UpdatedAt = time.Now()
|
||||||
|
dao.UpdateEntity(db, v)
|
||||||
} else {
|
} else {
|
||||||
dao.CreateEntity(db, v)
|
dao.CreateEntity(db, v)
|
||||||
}
|
}
|
||||||
@@ -2198,7 +2241,6 @@ func CreateOrUpdateStoreSkuNamePriceByExcel(db *dao.DaoDB, ctx *jxcontext.Contex
|
|||||||
func StoreSkuNamePriceList2Map(ctx *jxcontext.Context, storeSkuNamePriceList []*model.StoreSkuNamePrice) (result map[string]*model.StoreSkuNamePrice) {
|
func StoreSkuNamePriceList2Map(ctx *jxcontext.Context, storeSkuNamePriceList []*model.StoreSkuNamePrice) (result map[string]*model.StoreSkuNamePrice) {
|
||||||
result = make(map[string]*model.StoreSkuNamePrice, len(storeSkuNamePriceList))
|
result = make(map[string]*model.StoreSkuNamePrice, len(storeSkuNamePriceList))
|
||||||
for _, v := range storeSkuNamePriceList {
|
for _, v := range storeSkuNamePriceList {
|
||||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
|
||||||
result[v.OutSkuID] = v
|
result[v.OutSkuID] = v
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@@ -2214,8 +2256,10 @@ func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSk
|
|||||||
}
|
}
|
||||||
if k == sheetParam.SkuNameIDCol {
|
if k == sheetParam.SkuNameIDCol {
|
||||||
cellReplace := strings.ReplaceAll(cell, ",", ",")
|
cellReplace := strings.ReplaceAll(cell, ",", ",")
|
||||||
if cellReplace[len(cellReplace)-1:len(cellReplace)] == "," {
|
if cellReplace != "" {
|
||||||
cellReplace = cellReplace[0 : len(cellReplace)-1]
|
if cellReplace[len(cellReplace)-1:len(cellReplace)] == "," {
|
||||||
|
cellReplace = cellReplace[0 : len(cellReplace)-1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
storeSkuNamePrice.NameIDGroup = cellReplace
|
storeSkuNamePrice.NameIDGroup = cellReplace
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -895,13 +895,15 @@ func UpdateStoreSkuBindSyncStatus(db *DaoDB, vendorIDs []int, storeID int) (num
|
|||||||
func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*StoreSkuSyncInfo, err error) {
|
func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*StoreSkuSyncInfo, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT a.*,c.unit,c.name
|
SELECT a.*,c.unit,c.name
|
||||||
FROM store_sku_bind a
|
FROM store_sku_bind a
|
||||||
JOIN sku b ON a.sku_id = b.id
|
JOIN sku b ON a.sku_id = b.id
|
||||||
JOIN sku_name c ON b.name_id = c.id
|
JOIN sku_name c ON b.name_id = c.id
|
||||||
WHERE b.name_id = ?
|
WHERE b.name_id = ?
|
||||||
|
AND a.deleted_at = ?
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
nameID,
|
nameID,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
}
|
}
|
||||||
if len(storeIDs) > 0 {
|
if len(storeIDs) > 0 {
|
||||||
sql += " AND a.store_id in (" + GenQuestionMarks(len(storeIDs)) + ")"
|
sql += " AND a.store_id in (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||||
@@ -1061,7 +1063,7 @@ func GetStoreSkuNamePrice(db *DaoDB) (storeSkuNamePriceList []*model.StoreSkuNam
|
|||||||
}
|
}
|
||||||
err = GetRows(db, &storeSkuNamePriceList, sql, sqlParams...)
|
err = GetRows(db, &storeSkuNamePriceList, sql, sqlParams...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,err
|
return nil, err
|
||||||
}
|
}
|
||||||
return storeSkuNamePriceList, err
|
return storeSkuNamePriceList, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -512,9 +512,9 @@ func (c *StoreSkuController) RefreshJxPriceByExcel() {
|
|||||||
var storeIDList []int
|
var storeIDList []int
|
||||||
c.callRefreshJxPriceByExcel(func(params *tStoreSkuRefreshJxPriceByExcelParams) (retVal interface{}, errCode string, err error) {
|
c.callRefreshJxPriceByExcel(func(params *tStoreSkuRefreshJxPriceByExcelParams) (retVal interface{}, errCode string, err error) {
|
||||||
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
|
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
|
||||||
r := c.Ctx.Request
|
// r := c.Ctx.Request
|
||||||
files := r.MultipartForm.File["userfiles"]
|
// files := r.MultipartForm.File["userfiles"]
|
||||||
retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, files, params.IsAsync, params.IsContinueWhenError)
|
retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, "files", params.IsAsync, params.IsContinueWhenError)
|
||||||
}
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user