更新调价包修改

This commit is contained in:
苏尹岚
2019-12-11 15:28:25 +08:00
parent c0cd4fe692
commit 7182ea87d5
3 changed files with 119 additions and 18 deletions

View File

@@ -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(db, ctx, storeIDs)
hint, err = ReCalculateJxPrice(db, ctx, storeIDs)
}
}
case model.ConfigTypeFreightPack:

View File

@@ -1058,7 +1058,7 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
err = ErrCanNotFindVendor
}
} else {
ReCalculateJxPrice(db, ctx, []int{storeID})
ReCalculateJxPriceLight(db, ctx, storeID)
}
if err == nil {
dao.WrapAddIDCULDEntity(storeMap, userName)
@@ -1201,7 +1201,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
}
} else {
if valid["pricePercentage"] != nil || valid["pricePercentagePack"] != nil {
ReCalculateJxPrice(db, ctx, []int{storeID})
ReCalculateJxPriceLight(db, ctx, storeID)
}
}
}

View File

@@ -10,6 +10,9 @@ import (
"sync"
"time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
@@ -112,15 +115,16 @@ type SheetParam struct {
}
type DataSuccess struct {
NameID int `json:"商品编码"`
NameID int `json:"商品NameID"`
Name string `json:"商品名称"`
Unit string `json:"单位"`
OrgPrice float64 `json:"原价"`
NowPrice float64 `json:"现价"`
MixPrice float64 `json:"涨跌"`
}
type DataFailed struct {
NameID string `json:"商品ID"`
NameID int `json:"商品NameID"`
Name string `json:"商品名称"`
Comment string `json:"备注"`
}
@@ -144,7 +148,20 @@ var (
"18180948107": 1, // 徐
// "13684045763": 1, // 周
}
dataLock DataLock
dataLock DataLock
titleListSuccess = []string{
"商品NameID",
"商品名称",
"单位",
"原价",
"现价",
"涨跌",
}
titleListFailed = []string{
"商品NameID",
"商品名称",
"备注",
}
)
func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus bool, keyword string, isBySku, isAct bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
@@ -680,8 +697,6 @@ func GetStoresSkusSaleInfo(ctx *jxcontext.Context, storeIDs []int, skuIDs []int,
HAVING count >= ? AND count <= ?
`
sqlParams = append(sqlParams, fromCount, toCount)
// fmt.Println(sql)
// fmt.Println(utils.Format4Output(sqlParams, false))
if err = dao.GetRows(db, &saleInfoList, sql, sqlParams...); err == nil {
// globals.SugarLogger.Debug(utils.Format4Output(saleInfoList, false))
return saleInfoList, nil
@@ -2058,8 +2073,31 @@ func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int, isNeedSync bool) (
return err
}
func ReCalculateJxPrice(db *dao.DaoDB, ctx *jxcontext.Context, storeIDs []int) (err error) {
for _, storeID := range storeIDs {
func ReCalculateJxPrice(db *dao.DaoDB, ctx *jxcontext.Context, storeIDs []int) (hint string, err error) {
task := tasksch.NewParallelTask("刷新京西平台价格", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeID := batchItemList[0].(int)
if storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJX); err == nil {
if storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, nil); err == nil {
for _, skuBind := range storeSkuList {
skuBind.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), skuBind.Price)
dao.UpdateEntity(db, skuBind)
}
} else {
return "", err
}
} else {
return "", err
}
return retVal, err
}, storeIDs)
tasksch.HandleTask(task, nil, true).Run()
hint = task.GetID()
return hint, err
}
func ReCalculateJxPriceLight(db *dao.DaoDB, ctx *jxcontext.Context, storeID int) (err error) {
if storeID != 0 {
if storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJX); err == nil {
if storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, nil); err == nil {
for _, skuBind := range storeSkuList {
@@ -2172,19 +2210,42 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader str
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}
storeSkuBindInfo := &StoreSkuBindInfo{
NameID: nameID,
UnitPrice: storeSkuNamePrice.Price,
}
skuBindInfos = append(skuBindInfos, storeSkuBindInfo)
outSuccess := DataSuccess{
NameID: nameID,
Name: skuList[0].Name,
Unit: storeSkuNamePrice.Unit,
OrgPrice: utils.Str2Float64(utils.Int64ToStr(skuList[0].UnitPrice / 100)),
NowPrice: utils.Str2Float64(utils.Int64ToStr(int64(storeSkuNamePrice.Price / 100))),
MixPrice: utils.Str2Float64(utils.Int64ToStr(int64(storeSkuNamePrice.Price) - skuList[0].UnitPrice)),
}
dataLock.AppendDataSuccess(outSuccess)
} else {
//京西xx门店没有关注该商品
outFailed := DataFailed{
NameID: nameID,
Name: storeSkuNamePrice.Name,
Comment: fmt.Sprintf("京西[%v]门店没有关注该商品商品nameID[%v]Excel上商品名[%v]", vv, nameID, storeSkuNamePrice.Name),
}
dataLock.AppendDataFailed(outFailed)
}
}
} else {
//nameID为空还未填写nameID
outFailed := DataFailed{
NameID: 0,
Name: storeSkuNamePrice.Name,
Comment: fmt.Sprintf("商品nameID为空还未填写商品nameIDExcel上商品名[%v]", storeSkuNamePrice.Name),
}
dataLock.AppendDataFailed(outFailed)
}
}
retVal = skuBindInfos
@@ -2194,14 +2255,18 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader str
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)
UpdateStoresSkus(ctx, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError)
case 3:
//写Excel
WriteToExcelJx(task, dataLock.dataSuccessList, dataLock.dataFailedList)
}
return result, err
}
taskSeq := tasksch.NewSeqTask2("根据Excel刷新京西价", ctx, isContinueWhenError, taskSeqFunc, 3)
taskSeq := tasksch.NewSeqTask2("根据Excel刷新京西价", ctx, isContinueWhenError, taskSeqFunc, 4)
tasksch.HandleTask(taskSeq, nil, true).Run()
if !isAsync {
_, err = taskSeq.GetResult(0)
@@ -2212,6 +2277,42 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader str
return hint, err
}
func WriteToExcelJx(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 = jxutils.UploadExeclAndPushMsg(sheetList1, "京西已更新商品")
} else {
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
}
if excelConf2 != nil {
downloadURL2, fileName2, err = jxutils.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("[详情点我]path1=%s, path2=%s \n", downloadURL1, downloadURL2)
task.SetNoticeMsg(noticeMsg)
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s ,%s success, downloadURL1:%s ,downloadURL2:%s", fileName1, fileName2, downloadURL1, downloadURL2)
}
return err
}
func CreateOrUpdateStoreSkuNamePriceByExcel(db *dao.DaoDB, ctx *jxcontext.Context, storeSkuNamePriceList []*model.StoreSkuNamePrice, storeSkuNamePriceListOrg []*model.StoreSkuNamePrice) (err error) {
storeSkuNamePriceMap := StoreSkuNamePriceList2Map(ctx, storeSkuNamePriceListOrg)
dao.Begin(db)