+ jxutils_act.go, ActStoreSkuMap

This commit is contained in:
gazebo
2019-07-24 14:36:27 +08:00
parent 95e055fe54
commit b513ee9c74
2 changed files with 298 additions and 264 deletions

View File

@@ -432,7 +432,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
if globals.EnableNewAct { if globals.EnableNewAct {
err = updateActPrice4StoreSkuNameNew(db, storeIDs, skuIDs, skuNamesInfo) err = updateActPrice4StoreSkuNameNew(db, storeIDs, skuIDs, skuNamesInfo)
} else { } else {
err = updateActPrice4StoreSkuName(db, storeIDs, skuIDs, skuNamesInfo) // err = updateActPrice4StoreSkuName(db, storeIDs, skuIDs, skuNamesInfo)
} }
globals.SugarLogger.Debugf("GetStoresSkusNew updateActPrice4StoreSkuName:%v", time.Now().Sub(beginTime)) globals.SugarLogger.Debugf("GetStoresSkusNew updateActPrice4StoreSkuName:%v", time.Now().Sub(beginTime))
} }
@@ -453,40 +453,40 @@ func GetStoreAndSkuIDsFromInfo(skuNamesInfo *StoreSkuNamesInfo) (storeIDs, skuID
return jxutils.IntMap2List(storeIDMap), jxutils.IntMap2List(skuIDMap) return jxutils.IntMap2List(storeIDMap), jxutils.IntMap2List(skuIDMap)
} }
func updateActPrice4StoreSkuName(db *dao.DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo) (err error) { // func updateActPrice4StoreSkuName(db *dao.DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo) (err error) {
// 活动商品信息 // // 活动商品信息
jxSkuPriceMap, err := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now()) // jxSkuPriceMap, err := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now())
if err != nil { // if err != nil {
globals.SugarLogger.Errorf("updateActPrice4StoreSkuName can not get sku promotion info for error:%v", err) // globals.SugarLogger.Errorf("updateActPrice4StoreSkuName can not get sku promotion info for error:%v", err)
return err // return err
} // }
jdSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJD, storeIDs, skuIDs, time.Now(), time.Now()) // jdSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJD, storeIDs, skuIDs, time.Now(), time.Now())
if err = err2; err != nil { // if err = err2; err != nil {
globals.SugarLogger.Errorf("updateActPrice4StoreSkuName can not get sku promotion info for error:%v", err) // globals.SugarLogger.Errorf("updateActPrice4StoreSkuName can not get sku promotion info for error:%v", err)
return err // return err
} // }
for _, skuName := range skuNamesInfo.SkuNames { // for _, skuName := range skuNamesInfo.SkuNames {
if len(skuName.Skus2) > 0 { // if len(skuName.Skus2) > 0 {
for _, v := range skuName.Skus2 { // for _, v := range skuName.Skus2 {
index := dao.GenSkuPriceMapKey(skuName.StoreID, v.SkuID) // index := dao.GenSkuPriceMapKey(skuName.StoreID, v.SkuID)
if jdSkuPriceMap[index] != nil { // if jdSkuPriceMap[index] != nil {
v.ActPrice = jdSkuPriceMap[index].Price // v.ActPrice = jdSkuPriceMap[index].Price
} // }
if jxSkuPriceMap[index] != nil { // if jxSkuPriceMap[index] != nil {
v.EarningPrice = jxSkuPriceMap[index].EarningPrice // v.EarningPrice = jxSkuPriceMap[index].EarningPrice
} // }
v.RealEarningPrice = v.EarningPrice // v.RealEarningPrice = v.EarningPrice
if v.RealEarningPrice == 0 { // if v.RealEarningPrice == 0 {
v.RealEarningPrice = int(jxutils.CaculateSkuEarningPrice(int64(v.BindPrice), int64(v.BindPrice), skuName.PayPercentage)) // v.RealEarningPrice = int(jxutils.CaculateSkuEarningPrice(int64(v.BindPrice), int64(v.BindPrice), skuName.PayPercentage))
} // }
} // }
} else { // } else {
skuName.UnitPrice = skuName.Price // skuName.UnitPrice = skuName.Price
} // }
} // }
return err // return err
} // }
func updateActPrice4StoreSkuNameNew(db *dao.DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo) (err error) { func updateActPrice4StoreSkuNameNew(db *dao.DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo) (err error) {
jxSkuPriceMap, err := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now()) jxSkuPriceMap, err := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now())
@@ -500,21 +500,16 @@ func updateActPrice4StoreSkuNameNew(db *dao.DaoDB, storeIDs, skuIDs []int, skuNa
globals.SugarLogger.Errorf("updateActPrice4StoreSkuNameNew can not get sku promotion info for error:%v", err) globals.SugarLogger.Errorf("updateActPrice4StoreSkuNameNew can not get sku promotion info for error:%v", err)
return err return err
} }
actStoreSkuMap := make(map[int64]*model.ActStoreSku2) actStoreSkuMap := jxutils.NewActStoreSkuMap(actStoreSkuList, true)
for _, v := range actStoreSkuList {
index := jxutils.Combine2Int(v.StoreID, v.SkuID)
if actStoreSkuMap[index] == nil || actStoreSkuMap[index].ActualActPrice > v.ActualActPrice {
actStoreSkuMap[index] = v
}
}
for _, skuName := range skuNamesInfo.SkuNames { for _, skuName := range skuNamesInfo.SkuNames {
if len(skuName.Skus2) > 0 { if len(skuName.Skus2) > 0 {
for _, v := range skuName.Skus2 { for _, v := range skuName.Skus2 {
index := dao.GenSkuPriceMapKey(skuName.StoreID, v.SkuID) actStoreSku := actStoreSkuMap.GetActStoreSku(skuName.StoreID, v.SkuID, -1)
if actStoreSkuMap[index] != nil { if actStoreSku != nil {
v.ActPrice = int(actStoreSkuMap[index].ActualActPrice) v.ActPrice = int(actStoreSku.ActualActPrice)
} }
index := dao.GenSkuPriceMapKey(skuName.StoreID, v.SkuID)
if jxSkuPriceMap[index] != nil { if jxSkuPriceMap[index] != nil {
v.EarningPrice = jxSkuPriceMap[index].EarningPrice v.EarningPrice = jxSkuPriceMap[index].EarningPrice
} }
@@ -593,230 +588,230 @@ func updateSaleInfo4StoreSkuName(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
// 商品不可售,直接排除 // 商品不可售,直接排除
// 如果门店商品是可售状态,那么会忽略区域限制。否则有区域限制 // 如果门店商品是可售状态,那么会忽略区域限制。否则有区域限制
func GetStoresSkusOld(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) { // func GetStoresSkusOld(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
db := dao.GetDB() // db := dao.GetDB()
sql, sqlParams, err := getGetStoresSkusBaseSQL(db, storeIDs, skuIDs, isFocus, keyword, isBySku, params) // sql, sqlParams, err := getGetStoresSkusBaseSQL(db, storeIDs, skuIDs, isFocus, keyword, isBySku, params)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
sql += ` // sql += `
GROUP BY // GROUP BY
t1.id, // t1.id,
t1.created_at, // t1.created_at,
t1.updated_at, // t1.updated_at,
t1.last_operator, // t1.last_operator,
t1.deleted_at, // t1.deleted_at,
t1.prefix, // t1.prefix,
t1.name, // t1.name,
t1.brand_id, // t1.brand_id,
t1.category_id, // t1.category_id,
t1.is_global, // t1.is_global,
t1.unit, // t1.unit,
t1.price, // t1.price,
t1.img, // t1.img,
t1.elm_img_hash_code, // t1.elm_img_hash_code,
t3.id, // t3.id,
t3.name, // t3.name,
t3.pay_percentage` // t3.pay_percentage`
if isBySku { // if isBySku {
sql += `, // sql += `,
t2.id` // t2.id`
} // }
sqlData := ` // sqlData := `
SELECT // SELECT
SQL_CALC_FOUND_ROWS // SQL_CALC_FOUND_ROWS
t1.id, // t1.id,
t1.created_at, // t1.created_at,
t1.updated_at, // t1.updated_at,
t1.last_operator, // t1.last_operator,
t1.deleted_at, // t1.deleted_at,
t1.prefix, // t1.prefix,
t1.name, // t1.name,
t1.brand_id, // t1.brand_id,
t1.category_id, // t1.category_id,
t1.is_global, // t1.is_global,
t1.unit, // t1.unit,
t1.price, // t1.price,
t1.img, // t1.img,
t1.elm_img_hash_code, // t1.elm_img_hash_code,
t3.id store_id, // t3.id store_id,
t3.name store_name, // t3.name store_name,
t3.pay_percentage, // t3.pay_percentage,
CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"id":', t2.id, ',"comment":"', t2.comment, '","status":', t2.status, ',"createdAt":"', // CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"id":', t2.id, ',"comment":"', t2.comment, '","status":', t2.status, ',"createdAt":"',
CONCAT(REPLACE(IF(t4.created_at IS NULL, '1970-01-01 00:00:00', t4.created_at)," ","T"),"+08:00"), '","updatedAt":"', CONCAT(REPLACE(IF(t4.updated_at IS NULL, '1970-01-01 00:00:00', t4.updated_at)," ","T"),"+08:00"), // CONCAT(REPLACE(IF(t4.created_at IS NULL, '1970-01-01 00:00:00', t4.created_at)," ","T"),"+08:00"), '","updatedAt":"', CONCAT(REPLACE(IF(t4.updated_at IS NULL, '1970-01-01 00:00:00', t4.updated_at)," ","T"),"+08:00"),
'","lastOperator":"', IF(t4.last_operator IS NULL, '', t4.last_operator), '","specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit, '","weight":', t2.weight, // '","lastOperator":"', IF(t4.last_operator IS NULL, '', t4.last_operator), '","specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit, '","weight":', t2.weight,
',"categoryID":', t2.category_id, ',"nameID":', t2.name_id, ',"subStoreID":', IF(t4.sub_store_id IS NULL, 0, t4.sub_store_id), // ',"categoryID":', t2.category_id, ',"nameID":', t2.name_id, ',"subStoreID":', IF(t4.sub_store_id IS NULL, 0, t4.sub_store_id),
',"price":', IF(t4.price IS NULL, 0, t4.price), ',"unitPrice":', IF(t4.unit_price IS NULL, t1.price, t4.unit_price), // ',"price":', IF(t4.price IS NULL, 0, t4.price), ',"unitPrice":', IF(t4.unit_price IS NULL, t1.price, t4.unit_price),
',"storeSkuStatus":', IF(t4.status IS NULL, 0, t4.status), // ',"storeSkuStatus":', IF(t4.status IS NULL, 0, t4.status),
',"jdID":', t2.jd_id, ',"jdSyncStatus":', IF(t4.jd_sync_status IS NULL, 0, t4.jd_sync_status), // ',"jdID":', t2.jd_id, ',"jdSyncStatus":', IF(t4.jd_sync_status IS NULL, 0, t4.jd_sync_status),
',"ebaiID":', IF(t4.ebai_id IS NULL, 0, t4.ebai_id), ',"ebaiSyncStatus":', IF(t4.ebai_sync_status IS NULL, 0, t4.ebai_sync_status), // ',"ebaiID":', IF(t4.ebai_id IS NULL, 0, t4.ebai_id), ',"ebaiSyncStatus":', IF(t4.ebai_sync_status IS NULL, 0, t4.ebai_sync_status),
',"mtwmID":', IF(t4.mtwm_id IS NULL, 0, t4.mtwm_id), ',"mtwmSyncStatus":', IF(t4.mtwm_sync_status IS NULL, 0, t4.mtwm_sync_status), // ',"mtwmID":', IF(t4.mtwm_id IS NULL, 0, t4.mtwm_id), ',"mtwmSyncStatus":', IF(t4.mtwm_sync_status IS NULL, 0, t4.mtwm_sync_status),
',"wscID":', IF(t4.wsc_id IS NULL, 0, t4.wsc_id), ',"wscSyncStatus":', IF(t4.wsc_sync_status IS NULL, 0, t4.wsc_sync_status), // ',"wscID":', IF(t4.wsc_id IS NULL, 0, t4.wsc_id), ',"wscSyncStatus":', IF(t4.wsc_sync_status IS NULL, 0, t4.wsc_sync_status),
"}")), "]") skus_str // "}")), "]") skus_str
` + sql + ` // ` + sql + `
ORDER BY t1.id DESC // ORDER BY t1.id DESC
LIMIT ? OFFSET ?` // LIMIT ? OFFSET ?`
pageSize = jxutils.FormalizePageSize(pageSize) // pageSize = jxutils.FormalizePageSize(pageSize)
sqlOffset := offset // sqlOffset := offset
sqlPageSize := pageSize // sqlPageSize := pageSize
isSaleInfo := params["stFromTime"] != nil // isSaleInfo := params["stFromTime"] != nil
if isSaleInfo { // if isSaleInfo {
sqlOffset = 0 // sqlOffset = 0
sqlPageSize = jxutils.FormalizePageSize(-1) // sqlPageSize = jxutils.FormalizePageSize(-1)
} // }
sqlParams = append(sqlParams, sqlPageSize, sqlOffset) // sqlParams = append(sqlParams, sqlPageSize, sqlOffset)
skuNamesInfo = &StoreSkuNamesInfo{} // skuNamesInfo = &StoreSkuNamesInfo{}
// globals.SugarLogger.Debug(sqlData) // // globals.SugarLogger.Debug(sqlData)
dao.Begin(db) // dao.Begin(db)
defer func() { // defer func() {
if r := recover(); r != nil { // if r := recover(); r != nil {
dao.Rollback(db) // dao.Rollback(db)
panic(r) // panic(r)
} // }
}() // }()
// globals.SugarLogger.Debug(sqlData, sqlParams) // // globals.SugarLogger.Debug(sqlData, sqlParams)
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil { // if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db) // skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
dao.Commit(db) // dao.Commit(db)
// 活动商品信息 // // 活动商品信息
jxSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now()) // jxSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now())
if err = err2; err != nil { // if err = err2; err != nil {
globals.SugarLogger.Errorf("GetStoresSkus can not get sku promotion info for error:%v", err) // globals.SugarLogger.Errorf("GetStoresSkus can not get sku promotion info for error:%v", err)
return nil, err // return nil, err
} // }
jdSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJD, storeIDs, skuIDs, time.Now(), time.Now()) // jdSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJD, storeIDs, skuIDs, time.Now(), time.Now())
if err = err2; err != nil { // if err = err2; err != nil {
globals.SugarLogger.Errorf("GetStoresSkus can not get sku promotion info for error:%v", err) // globals.SugarLogger.Errorf("GetStoresSkus can not get sku promotion info for error:%v", err)
return nil, err // return nil, err
} // }
for _, skuName := range skuNamesInfo.SkuNames { // for _, skuName := range skuNamesInfo.SkuNames {
if skuName.SkusStr != "" { // if skuName.SkusStr != "" {
if err = utils.UnmarshalUseNumber([]byte(skuName.SkusStr), &skuName.Skus); err != nil { // if err = utils.UnmarshalUseNumber([]byte(skuName.SkusStr), &skuName.Skus); err != nil {
return nil, err // return nil, err
} // }
if len(skuName.Skus) > 0 { // if len(skuName.Skus) > 0 {
skuName.UnitPrice = int(utils.MustInterface2Int64(skuName.Skus[0]["unitPrice"])) // skuName.UnitPrice = int(utils.MustInterface2Int64(skuName.Skus[0]["unitPrice"]))
for _, v := range skuName.Skus { // for _, v := range skuName.Skus {
index := dao.GenSkuPriceMapKey(skuName.StoreID, int(utils.MustInterface2Int64(v["id"]))) // index := dao.GenSkuPriceMapKey(skuName.StoreID, int(utils.MustInterface2Int64(v["id"])))
if jdSkuPriceMap[index] != nil { // if jdSkuPriceMap[index] != nil {
v["actPrice"] = jdSkuPriceMap[index].Price // v["actPrice"] = jdSkuPriceMap[index].Price
} else { // } else {
v["actPrice"] = 0 // v["actPrice"] = 0
} // }
earningPrice := 0 // earningPrice := 0
if jxSkuPriceMap[index] != nil { // if jxSkuPriceMap[index] != nil {
earningPrice = jxSkuPriceMap[index].EarningPrice // earningPrice = jxSkuPriceMap[index].EarningPrice
} // }
v["earningPrice"] = earningPrice // v["earningPrice"] = earningPrice
realEarningPrice := earningPrice // realEarningPrice := earningPrice
if realEarningPrice == 0 { // if realEarningPrice == 0 {
shopPrice := utils.Interface2Int64WithDefault(v["price"], 0) // shopPrice := utils.Interface2Int64WithDefault(v["price"], 0)
realEarningPrice = int(jxutils.CaculateSkuEarningPrice(shopPrice, shopPrice, skuName.PayPercentage)) // realEarningPrice = int(jxutils.CaculateSkuEarningPrice(shopPrice, shopPrice, skuName.PayPercentage))
} // }
v["realEarningPrice"] = realEarningPrice // v["realEarningPrice"] = realEarningPrice
delete(v, "unitPrice") // delete(v, "unitPrice")
} // }
} else { // } else {
skuName.UnitPrice = skuName.Price // skuName.UnitPrice = skuName.Price
} // }
} // }
} // }
if isSaleInfo { // if isSaleInfo {
var ( // var (
saleInfoList []*SkuSaleInfo // saleInfoList []*SkuSaleInfo
skuIDs []int // skuIDs []int
timeList []time.Time // timeList []time.Time
fromCount, toCount int // fromCount, toCount int
) // )
saleInfoMap := make(map[int64]*SkuSaleInfo) // saleInfoMap := make(map[int64]*SkuSaleInfo)
for _, skuName := range skuNamesInfo.SkuNames { // for _, skuName := range skuNamesInfo.SkuNames {
for _, sku := range skuName.Skus { // for _, sku := range skuName.Skus {
skuIDs = append(skuIDs, int(utils.MustInterface2Int64(sku["id"]))) // skuIDs = append(skuIDs, int(utils.MustInterface2Int64(sku["id"])))
} // }
} // }
toTimeStr := "" // toTimeStr := ""
if params["stToTime"] != nil { // if params["stToTime"] != nil {
toTimeStr = params["stToTime"].(string) // toTimeStr = params["stToTime"].(string)
} // }
if timeList, err = jxutils.BatchStr2Time(params["stFromTime"].(string), toTimeStr); err != nil { // if timeList, err = jxutils.BatchStr2Time(params["stFromTime"].(string), toTimeStr); err != nil {
return nil, err // return nil, err
} // }
if params["stFromCount"] != nil { // if params["stFromCount"] != nil {
fromCount = params["stFromCount"].(int) // fromCount = params["stFromCount"].(int)
} // }
toCount = math.MaxInt32 // toCount = math.MaxInt32
if params["stToCount"] != nil { // if params["stToCount"] != nil {
toCount = params["stToCount"].(int) // toCount = params["stToCount"].(int)
} // }
// 不能用SQL筛除否则不能区分是没有销量还是不在条件中 // // 不能用SQL筛除否则不能区分是没有销量还是不在条件中
if saleInfoList, err = GetStoresSkusSaleInfo(ctx, storeIDs, skuIDs, timeList[0], timeList[1], 0, math.MaxInt32); err != nil { // if saleInfoList, err = GetStoresSkusSaleInfo(ctx, storeIDs, skuIDs, timeList[0], timeList[1], 0, math.MaxInt32); err != nil {
return nil, err // return nil, err
} // }
for _, saleInfo := range saleInfoList { // for _, saleInfo := range saleInfoList {
saleInfoMap[int64(saleInfo.StoreID)*100000+int64(saleInfo.SkuID)] = saleInfo // saleInfoMap[int64(saleInfo.StoreID)*100000+int64(saleInfo.SkuID)] = saleInfo
} // }
var newSkuNames []*StoreSkuNameExt // var newSkuNames []*StoreSkuNameExt
for _, skuName := range skuNamesInfo.SkuNames { // for _, skuName := range skuNamesInfo.SkuNames {
var newSkus []map[string]interface{} // var newSkus []map[string]interface{}
storeID2 := int64(skuName.StoreID) * 100000 // storeID2 := int64(skuName.StoreID) * 100000
for _, sku := range skuName.Skus { // for _, sku := range skuName.Skus {
saleInfo := saleInfoMap[storeID2+utils.MustInterface2Int64(sku["id"])] // saleInfo := saleInfoMap[storeID2+utils.MustInterface2Int64(sku["id"])]
if saleInfo == nil && fromCount == 0 { // if saleInfo == nil && fromCount == 0 {
saleInfo = &SkuSaleInfo{} // saleInfo = &SkuSaleInfo{}
} // }
if saleInfo != nil && saleInfo.Count >= fromCount && saleInfo.Count <= toCount { // if saleInfo != nil && saleInfo.Count >= fromCount && saleInfo.Count <= toCount {
sku["times"] = saleInfo.Times // sku["times"] = saleInfo.Times
sku["count"] = saleInfo.Count // sku["count"] = saleInfo.Count
newSkus = append(newSkus, sku) // newSkus = append(newSkus, sku)
} // }
} // }
if len(newSkus) > 0 { // if len(newSkus) > 0 {
skuName.Skus = newSkus // skuName.Skus = newSkus
newSkuNames = append(newSkuNames, skuName) // newSkuNames = append(newSkuNames, skuName)
} // }
} // }
skuNamesInfo.TotalCount = len(newSkuNames) // skuNamesInfo.TotalCount = len(newSkuNames)
skuNamesInfo.SkuNames = nil // skuNamesInfo.SkuNames = nil
if offset < skuNamesInfo.TotalCount { // if offset < skuNamesInfo.TotalCount {
endIndex := offset + pageSize // endIndex := offset + pageSize
if endIndex > skuNamesInfo.TotalCount { // if endIndex > skuNamesInfo.TotalCount {
endIndex = skuNamesInfo.TotalCount // endIndex = skuNamesInfo.TotalCount
} // }
skuNamesInfo.SkuNames = newSkuNames[offset:endIndex] // skuNamesInfo.SkuNames = newSkuNames[offset:endIndex]
} // }
} // }
if globals.EnablePendingChange { // if globals.EnablePendingChange {
if isGetOpRequest, ok := params["isGetOpRequest"].(bool); ok && isGetOpRequest { // if isGetOpRequest, ok := params["isGetOpRequest"].(bool); ok && isGetOpRequest {
nameIDs := make([]int, len(skuNamesInfo.SkuNames)) // nameIDs := make([]int, len(skuNamesInfo.SkuNames))
for k, skuName := range skuNamesInfo.SkuNames { // for k, skuName := range skuNamesInfo.SkuNames {
nameIDs[k] = skuName.ID // nameIDs[k] = skuName.ID
} // }
pagedInfo, err2 := GetStoreOpRequests(ctx, utils.DefaultTimeValue, utils.DefaultTimeValue, "", storeIDs, nameIDs, nil, []int{model.RequestStatusNew}, 0, -1) // pagedInfo, err2 := GetStoreOpRequests(ctx, utils.DefaultTimeValue, utils.DefaultTimeValue, "", storeIDs, nameIDs, nil, []int{model.RequestStatusNew}, 0, -1)
if err = err2; err != nil { // if err = err2; err != nil {
return nil, err // return nil, err
} // }
requestList := pagedInfo.Data.([]*StoreOpRequestInfo) // requestList := pagedInfo.Data.([]*StoreOpRequestInfo)
requestMap := make(map[int]*StoreOpRequestInfo) // requestMap := make(map[int]*StoreOpRequestInfo)
for _, requestOp := range requestList { // for _, requestOp := range requestList {
requestMap[requestOp.ItemID] = requestOp // requestMap[requestOp.ItemID] = requestOp
} // }
for _, skuName := range skuNamesInfo.SkuNames { // for _, skuName := range skuNamesInfo.SkuNames {
if requestOp := requestMap[skuName.ID]; requestOp != nil { // if requestOp := requestMap[skuName.ID]; requestOp != nil {
skuName.PendingUnitPrice = requestOp.IntParam1 // skuName.PendingUnitPrice = requestOp.IntParam1
skuName.PendingOpType = requestOp.Type // skuName.PendingOpType = requestOp.Type
} // }
} // }
} // }
} // }
} else { // } else {
dao.Rollback(db) // dao.Rollback(db)
} // }
return skuNamesInfo, err // return skuNamesInfo, err
} // }
func getValidStoreVendorMap(db *dao.DaoDB, storeIDs []int) (realVendorMap map[int]int, err error) { func getValidStoreVendorMap(db *dao.DaoDB, storeIDs []int) (realVendorMap map[int]int, err error) {
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "") storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "")

View File

@@ -0,0 +1,39 @@
package jxutils
import "git.rosy.net.cn/jx-callback/business/model"
type ActStoreSkuMap struct {
actStoreSkuMap map[int64]map[int]*model.ActStoreSku2
}
func NewActStoreSkuMap(actStoreSkuList []*model.ActStoreSku2, isActPrice bool) (actMap *ActStoreSkuMap) {
actMap = &ActStoreSkuMap{}
actStoreSkuMap := make(map[int64]map[int]*model.ActStoreSku2)
for _, v := range actStoreSkuList {
index := Combine2Int(v.StoreID, v.SkuID)
if actStoreSkuMap[index] == nil {
actStoreSkuMap[index] = make(map[int]*model.ActStoreSku2)
}
if actStoreSkuMap[index][v.VendorID] == nil ||
(isActPrice && actStoreSkuMap[index][v.VendorID].ActualActPrice > v.ActualActPrice) ||
(!isActPrice && actStoreSkuMap[index][v.VendorID].EarningPrice > v.EarningPrice) {
actStoreSkuMap[index][v.VendorID] = v
}
}
actMap.actStoreSkuMap = actStoreSkuMap
return actMap
}
func (a *ActStoreSkuMap) GetActStoreSku(storeID, skuID, vendorID int) (storeSku *model.ActStoreSku2) {
index := Combine2Int(storeID, skuID)
if a.actStoreSkuMap[index] != nil {
if vendorID < 0 {
for k := range a.actStoreSkuMap[index] {
vendorID = k
break
}
}
storeSku = a.actStoreSkuMap[index][vendorID]
}
return storeSku
}