Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark
This commit is contained in:
@@ -359,7 +359,7 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
|
||||
if vendorID != model.VendorIDJX {
|
||||
dao.SetStoreSkuSyncStatus(db, vendorID, storeIDs, nil, model.SyncFlagPriceMask)
|
||||
} else {
|
||||
ReCalculateJxPrice(ctx, storeIDs)
|
||||
ReCalculateJxPrice(db, ctx, storeIDs)
|
||||
}
|
||||
}
|
||||
case model.ConfigTypeFreightPack:
|
||||
|
||||
@@ -1057,6 +1057,8 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
||||
} else {
|
||||
err = ErrCanNotFindVendor
|
||||
}
|
||||
} else {
|
||||
ReCalculateJxPrice(db, ctx, []int{storeID})
|
||||
}
|
||||
if err == nil {
|
||||
dao.WrapAddIDCULDEntity(storeMap, userName)
|
||||
@@ -1159,6 +1161,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
err = nil // todo 忽略读不到DeliveryType的错误
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||
if len(valid) > 0 {
|
||||
@@ -1196,6 +1199,10 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil {
|
||||
ReCalculateJxPrice(db, ctx, []int{storeID})
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
|
||||
@@ -3,9 +3,7 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -114,7 +112,7 @@ type SheetParam struct {
|
||||
}
|
||||
|
||||
type DataSuccess struct {
|
||||
NameID string `json:"商品编码"`
|
||||
NameID int `json:"商品编码"`
|
||||
Name string `json:"商品名称"`
|
||||
OrgPrice float64 `json:"原价"`
|
||||
NowPrice float64 `json:"现价"`
|
||||
@@ -2060,8 +2058,7 @@ func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int, isNeedSync bool) (
|
||||
return err
|
||||
}
|
||||
|
||||
func ReCalculateJxPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
|
||||
db := dao.GetDB()
|
||||
func ReCalculateJxPrice(db *dao.DaoDB, ctx *jxcontext.Context, storeIDs []int) (err error) {
|
||||
for _, storeID := range storeIDs {
|
||||
if storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJX); err == nil {
|
||||
if storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, nil); err == nil {
|
||||
@@ -2109,22 +2106,27 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
if len(files) == 0 {
|
||||
return "", errors.New("没有文件上传!")
|
||||
}
|
||||
func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// if len(files) == 0 {
|
||||
// return "", errors.New("没有文件上传!")
|
||||
// }
|
||||
if len(storeIDs) == 0 {
|
||||
return "", errors.New("请选择至少一个门店!")
|
||||
}
|
||||
fileHeader := files[0]
|
||||
file, err := fileHeader.Open()
|
||||
hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, file, true, true)
|
||||
file.Close()
|
||||
// fileHeader := files[0]
|
||||
// file, err := fileHeader.Open()
|
||||
hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, files, true, true)
|
||||
// file.Close()
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var storeSkuNamePriceList []*model.StoreSkuNamePrice
|
||||
func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
storeSkuNamePriceList []*model.StoreSkuNamePrice
|
||||
storeSkuNamePriceListUpdate []*model.StoreSkuNamePrice
|
||||
skuBindInfosInter []interface{}
|
||||
skuBindInfoList []*StoreSkuBindInfo
|
||||
)
|
||||
dataLock.dataFailedList = dataLock.dataFailedList[0:0]
|
||||
dataLock.dataSuccessList = dataLock.dataSuccessList[0:0]
|
||||
sheetParam := &SheetParam{
|
||||
@@ -2135,40 +2137,78 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
SkuUnitCol: 2,
|
||||
OutSkuIDCol: 0,
|
||||
}
|
||||
xlsx, err := excelize.OpenReader(reader)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
rows, _ := xlsx.GetRows(xlsx.GetSheetName(1))
|
||||
for rowNum, row := range rows {
|
||||
if rowNum < sheetParam.SkuRow {
|
||||
continue
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
// xlsx, err := excelize.OpenReader(reader)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
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{}
|
||||
GetCellIntoStruct(rowNum, row, sheetParam, storeSkuNamePrice)
|
||||
storeSkuNamePriceList = append(storeSkuNamePriceList, storeSkuNamePrice)
|
||||
return result, err
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -2184,9 +2224,11 @@ func CreateOrUpdateStoreSkuNamePriceByExcel(db *dao.DaoDB, ctx *jxcontext.Contex
|
||||
}
|
||||
}()
|
||||
for _, v := range storeSkuNamePriceList {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
if storeSkuNamePriceMap[v.OutSkuID] != nil {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
dao.UpdateEntity(db, storeSkuNamePriceMap[v.OutSkuID], "Price", "NameIDGroup", "Unit", "CreatedAt", "UpdatedAt", "LastOperator", "DeletedAt")
|
||||
v.ID = storeSkuNamePriceMap[v.OutSkuID].ID
|
||||
v.UpdatedAt = time.Now()
|
||||
dao.UpdateEntity(db, v)
|
||||
} else {
|
||||
dao.CreateEntity(db, v)
|
||||
}
|
||||
@@ -2198,7 +2240,6 @@ func CreateOrUpdateStoreSkuNamePriceByExcel(db *dao.DaoDB, ctx *jxcontext.Contex
|
||||
func StoreSkuNamePriceList2Map(ctx *jxcontext.Context, storeSkuNamePriceList []*model.StoreSkuNamePrice) (result map[string]*model.StoreSkuNamePrice) {
|
||||
result = make(map[string]*model.StoreSkuNamePrice, len(storeSkuNamePriceList))
|
||||
for _, v := range storeSkuNamePriceList {
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
result[v.OutSkuID] = v
|
||||
}
|
||||
return result
|
||||
@@ -2214,8 +2255,10 @@ func GetCellIntoStruct(rowNum int, row []string, sheetParam *SheetParam, storeSk
|
||||
}
|
||||
if k == sheetParam.SkuNameIDCol {
|
||||
cellReplace := strings.ReplaceAll(cell, ",", ",")
|
||||
if cellReplace[len(cellReplace)-1:len(cellReplace)] == "," {
|
||||
cellReplace = cellReplace[0 : len(cellReplace)-1]
|
||||
if cellReplace != "" {
|
||||
if cellReplace[len(cellReplace)-1:len(cellReplace)] == "," {
|
||||
cellReplace = cellReplace[0 : len(cellReplace)-1]
|
||||
}
|
||||
}
|
||||
storeSkuNamePrice.NameIDGroup = cellReplace
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if vendorID != model.VendorIDJX {
|
||||
sql += " AND t2.id IS NOT NULL"
|
||||
}
|
||||
// if vendorID != model.VendorIDJX {
|
||||
// sql += " AND t2.id IS NOT NULL"
|
||||
// }
|
||||
if storeID > 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
@@ -121,16 +121,16 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
||||
if err = GetRow(db, &storeDetail, sql, sqlParams...); err == nil {
|
||||
storeDetail.PricePercentagePackObj = PricePercentagePack2Obj(storeDetail.PricePercentagePackStr)
|
||||
storeDetail.FreightDeductionPackObj = FreightDeductionPack2Obj(storeDetail.FreightDeductionPackStr)
|
||||
if storeDetail.VendorStoreID == "" {
|
||||
storeDetail.VendorStatus = storeDetail.Status
|
||||
storeDetail.PricePercentage = model.DefVendorPricePercentage
|
||||
storeDetail.AutoPickup = 1
|
||||
storeDetail.DeliveryType = model.StoreDeliveryTypeByStore
|
||||
storeDetail.DeliveryCompetition = 1
|
||||
if vendorID == model.VendorIDJX {
|
||||
storeDetail.IsSync = 1
|
||||
}
|
||||
}
|
||||
// if storeDetail.VendorStoreID == "" {
|
||||
// storeDetail.VendorStatus = storeDetail.Status
|
||||
// storeDetail.PricePercentage = model.DefVendorPricePercentage
|
||||
// storeDetail.AutoPickup = 1
|
||||
// storeDetail.DeliveryType = model.StoreDeliveryTypeByStore
|
||||
// storeDetail.DeliveryCompetition = 1
|
||||
// if vendorID == model.VendorIDJX {
|
||||
// storeDetail.IsSync = 1
|
||||
// }
|
||||
// }
|
||||
return storeDetail, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -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) {
|
||||
sql := `
|
||||
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_name c ON b.name_id = c.id
|
||||
WHERE b.name_id = ?
|
||||
AND a.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
nameID,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND a.store_id in (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
|
||||
@@ -510,9 +510,9 @@ func (c *StoreSkuController) RefreshJxPriceByExcel() {
|
||||
var storeIDList []int
|
||||
c.callRefreshJxPriceByExcel(func(params *tStoreSkuRefreshJxPriceByExcelParams) (retVal interface{}, errCode string, err error) {
|
||||
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
|
||||
r := c.Ctx.Request
|
||||
files := r.MultipartForm.File["userfiles"]
|
||||
retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, files, params.IsAsync, params.IsContinueWhenError)
|
||||
// r := c.Ctx.Request
|
||||
// files := r.MultipartForm.File["userfiles"]
|
||||
retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, "files", params.IsAsync, params.IsContinueWhenError)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user