门店评分并发修改

This commit is contained in:
Rosy-zhudan
2019-09-11 14:49:59 +08:00
parent 3784696334
commit bfaea1b998

View File

@@ -6,6 +6,7 @@ import (
"sync" "sync"
"time" "time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
@@ -18,6 +19,7 @@ import (
const ( const (
EnableScheduleScoreStore = !true EnableScheduleScoreStore = !true
ParallelCount = 5
GoldMedalScore = 90 GoldMedalScore = 90
SilverMedalScore = 80 SilverMedalScore = 80
@@ -38,7 +40,8 @@ const (
AbsentGoodsOrderNormalRatio = 1.0 //百分比 AbsentGoodsOrderNormalRatio = 1.0 //百分比
StoreRangeGoodRadius = 2.0 //千米 StoreRangeGoodRadius = 2.0 //千米
StoreRangeBadRadius = 1.0 //千米 StoreRangeBadRadius = 1.0 //千米
SaleSkuPriceRatio = 90 //百分比 SaleSkuPriceRatio = 90 //千米
SaleSkuCheckRange = 5.0 //千米
) )
var ( var (
@@ -115,7 +118,7 @@ func (s *StoreScoreDataWrapper) SetData(storeID int, valueName string, value int
} }
//得到所有门店的商品 //得到所有门店的商品
func GetAllStoreSkus(ctx *jxcontext.Context, storeList []*cms.StoreExt) { func GetAllStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeList []*cms.StoreExt) {
allStoreSkusWrapper.InitData() allStoreSkusWrapper.InitData()
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeInfo := batchItemList[0].(*cms.StoreExt) storeInfo := batchItemList[0].(*cms.StoreExt)
@@ -133,8 +136,8 @@ func GetAllStoreSkus(ctx *jxcontext.Context, storeList []*cms.StoreExt) {
allStoreSkusWrapper.SetData(storeID, jxSkuMapData) allStoreSkusWrapper.SetData(storeID, jxSkuMapData)
return retVal, err return retVal, err
} }
taskParallel := tasksch.NewParallelTask("GetAllStoreSkus", nil, ctx, taskFunc, storeList) taskParallel := tasksch.NewParallelTask("得到所有门店商品", nil, ctx, taskFunc, storeList)
tasksch.HandleTask(taskParallel, nil, true).Run() tasksch.HandleTask(taskParallel, parentTask, true).Run()
taskParallel.GetResult(0) taskParallel.GetResult(0)
} }
@@ -153,263 +156,244 @@ func GetOpenTime(opTimeList []int16) (opTime float64) {
} }
//营业时间12小时及以上满分总分10分每少一个小时扣1分 //营业时间12小时及以上满分总分10分每少一个小时扣1分
func ScoreStoreOpenTime(storeList []*cms.StoreExt) { func ScoreStoreOpenTime(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { storeID := storeInfo.ID
storeID := storeInfo.ID storeStatus := storeInfo.Status
storeStatus := storeInfo.Status isStoreOpen := storeStatus == model.StoreStatusOpened
isStoreOpen := storeStatus == model.StoreStatusOpened for _, storeMap := range storeInfo.StoreMaps {
for _, storeMap := range storeInfo.StoreMaps { vendorStoreStatus := int(utils.MustInterface2Int64(storeMap["status"]))
vendorStoreStatus := int(utils.MustInterface2Int64(storeMap["status"])) isVendorStoreOpen := vendorStoreStatus == model.StoreStatusOpened
isVendorStoreOpen := vendorStoreStatus == model.StoreStatusOpened opTimeList := storeInfo.GetOpTimeList()
opTimeList := storeInfo.GetOpTimeList() if len(opTimeList) > 0 && isStoreOpen && isVendorStoreOpen {
if len(opTimeList) > 0 && isStoreOpen && isVendorStoreOpen { finalScore := 0
finalScore := 0 opTime := GetOpenTime(opTimeList)
opTime := GetOpenTime(opTimeList) if opTime >= StoreOpenTimeNormalTime {
if opTime >= StoreOpenTimeNormalTime { finalScore = ItemTotalScore
finalScore = ItemTotalScore } else {
} else { decScore := int(math.Round(StoreOpenTimeNormalTime - opTime))
decScore := int(math.Round(StoreOpenTimeNormalTime - opTime)) finalScore = ItemTotalScore - decScore
finalScore = ItemTotalScore - decScore if finalScore < 0 {
if finalScore < 0 { finalScore = 0
finalScore = 0
}
} }
storeScoreDataWrapper.SetData(storeID, model.FieldStoreOpenTime, finalScore)
} }
storeScoreDataWrapper.SetData(storeID, model.FieldStoreOpenTime, finalScore)
} }
} }
} }
//可售商品数量大于1000总分10分按比例扣 //可售商品数量大于1000总分10分按比例扣
func ScoreSaleSkuCount(ctx *jxcontext.Context, storeList []*cms.StoreExt) { func ScoreSaleSkuCount(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { storeID := storeInfo.ID
storeID := storeInfo.ID skusMapData := allStoreSkusWrapper.GetData(storeID)
skusMapData := allStoreSkusWrapper.GetData(storeID) if len(skusMapData) > 0 {
if len(skusMapData) > 0 { finalScore := 0
finalScore := 0 saleSkuCount := 0
saleSkuCount := 0 for _, value := range skusMapData {
for _, value := range skusMapData { for _, skuInfo := range value.Skus2 {
for _, skuInfo := range value.Skus2 { saleStatus := jxutils.MergeSkuStatus(skuInfo.SkuStatus, skuInfo.StoreSkuStatus)
saleStatus := jxutils.MergeSkuStatus(skuInfo.SkuStatus, skuInfo.StoreSkuStatus) if saleStatus == model.SkuStatusNormal {
if saleStatus == model.SkuStatusNormal { saleSkuCount++
saleSkuCount++
}
} }
} }
finalScore = int(math.Round(float64(saleSkuCount) * SaleSkuScorePerUnit))
if finalScore > ItemTotalScore {
finalScore = ItemTotalScore
}
storeScoreDataWrapper.SetData(storeID, model.FieldSaleSkuCount, finalScore)
} }
finalScore = int(math.Round(float64(saleSkuCount) * SaleSkuScorePerUnit))
if finalScore > ItemTotalScore {
finalScore = ItemTotalScore
}
storeScoreDataWrapper.SetData(storeID, model.FieldSaleSkuCount, finalScore)
} }
} }
//平均捡货时间小于等于拣货截止时间为10分满分每超出1分钟减1分 //平均捡货时间小于等于拣货截止时间为10分满分每超出1分钟减1分
func ScoreAveragePickupTime(storeList []*cms.StoreExt) { func ScoreAveragePickupTime(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { storeID := storeInfo.ID
storeID := storeInfo.ID db := dao.GetDB()
db := dao.GetDB() orderList, err := dao.GetDailyFinishOrderList(db, storeID)
orderList, err := dao.GetDailyFinishOrderList(db, storeID) orderListCount := len(orderList)
orderListCount := len(orderList) if err == nil && orderListCount > 0 {
if err == nil && orderListCount > 0 { totalScore := 0
totalScore := 0 for _, value := range orderList {
for _, value := range orderList { statusTime := value.StatusTime.Unix()
statusTime := value.StatusTime.Unix() pickDeadline := value.PickDeadline.Unix()
pickDeadline := value.PickDeadline.Unix() if statusTime <= pickDeadline {
if statusTime <= pickDeadline { totalScore += ItemTotalScore
totalScore += ItemTotalScore } else {
} else { decScore := int(math.Round(float64(statusTime-pickDeadline) / 60))
decScore := int(math.Round(float64(statusTime-pickDeadline) / 60)) tempScore := ItemTotalScore - decScore
tempScore := ItemTotalScore - decScore if tempScore < 0 {
if tempScore < 0 { tempScore = 0
tempScore = 0
}
totalScore += tempScore
} }
totalScore += tempScore
} }
finalScore := totalScore / orderListCount
storeScoreDataWrapper.SetData(storeID, model.FieldAveragePickupTime, finalScore)
} }
finalScore := totalScore / orderListCount
storeScoreDataWrapper.SetData(storeID, model.FieldAveragePickupTime, finalScore)
} }
} }
//差评订单和完成订单比例小于0.2%,得满分10分每增加0.1%减1分 //差评订单和完成订单比例小于0.2%,得满分10分每增加0.1%减1分
func ScoreBadCommentOrder(storeList []*cms.StoreExt) { func ScoreBadCommentOrder(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { storeID := storeInfo.ID
storeID := storeInfo.ID db := dao.GetDB()
db := dao.GetDB() badCommentOrderCount, _ := dao.GetDailyBadCommentOrderCount(db, storeID)
badCommentOrderCount, _ := dao.GetDailyBadCommentOrderCount(db, storeID) finishOrderCount, _ := dao.GetDailyFinishOrderCount(db, storeID)
finishOrderCount, _ := dao.GetDailyFinishOrderCount(db, storeID) if finishOrderCount > 0 {
if finishOrderCount > 0 { finalScore := 0
finalScore := 0 badCommentOrderRatio := float64(badCommentOrderCount) * 100 / float64(finishOrderCount)
badCommentOrderRatio := float64(badCommentOrderCount) * 100 / float64(finishOrderCount) if badCommentOrderRatio <= BadCommentOrderNormalRatio {
if badCommentOrderRatio <= BadCommentOrderNormalRatio { finalScore = ItemTotalScore
finalScore = ItemTotalScore } else {
} else { decScore := int(math.Round((badCommentOrderRatio - BadCommentOrderNormalRatio) / 0.1))
decScore := int(math.Round((badCommentOrderRatio - BadCommentOrderNormalRatio) / 0.1)) finalScore = ItemTotalScore - decScore
finalScore = ItemTotalScore - decScore if finalScore < 0 {
if finalScore < 0 { finalScore = 0
finalScore = 0
}
} }
storeScoreDataWrapper.SetData(storeID, model.FieldBadCommentOrder, finalScore)
} }
storeScoreDataWrapper.SetData(storeID, model.FieldBadCommentOrder, finalScore)
} }
} }
//未完成订单和完成订单比小于1%得满分10分比例每增加5%分数减1 //未完成订单和完成订单比小于1%得满分10分比例每增加5%分数减1
func ScoreUnfinishOrder(storeList []*cms.StoreExt) { func ScoreUnfinishOrder(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { storeID := storeInfo.ID
storeID := storeInfo.ID db := dao.GetDB()
db := dao.GetDB() unFinishOrderCount, _ := dao.GetDailyUnFinishOrderCount(db, storeID)
unFinishOrderCount, _ := dao.GetDailyUnFinishOrderCount(db, storeID) finishOrderCount, _ := dao.GetDailyFinishOrderCount(db, storeID)
finishOrderCount, _ := dao.GetDailyFinishOrderCount(db, storeID) if finishOrderCount > 0 {
if finishOrderCount > 0 { finalScore := 0
finalScore := 0 unfinishOrderRatio := float64(unFinishOrderCount) * 100 / float64(finishOrderCount)
unfinishOrderRatio := float64(unFinishOrderCount) * 100 / float64(finishOrderCount) if unfinishOrderRatio <= UnfinishOrderNormalRatio {
if unfinishOrderRatio <= UnfinishOrderNormalRatio { finalScore = ItemTotalScore
finalScore = ItemTotalScore } else {
} else { decScore := int(math.Round((unfinishOrderRatio - UnfinishOrderNormalRatio) / 5))
decScore := int(math.Round((unfinishOrderRatio - UnfinishOrderNormalRatio) / 5)) finalScore = ItemTotalScore - decScore
finalScore = ItemTotalScore - decScore if finalScore < 0 {
if finalScore < 0 { finalScore = 0
finalScore = 0
}
} }
storeScoreDataWrapper.SetData(storeID, model.FieldUnfinishOrder, finalScore)
} }
storeScoreDataWrapper.SetData(storeID, model.FieldUnfinishOrder, finalScore)
} }
} }
//缺货订单和完成订单比小于1%得10分比例每增加0.1%减1分 //缺货订单和完成订单比小于1%得10分比例每增加0.1%减1分
func ScoreAbsentGoodsOrder(storeList []*cms.StoreExt) { func ScoreAbsentGoodsOrder(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { storeID := storeInfo.ID
storeID := storeInfo.ID db := dao.GetDB()
db := dao.GetDB() absentGoodsOrderCount, _ := dao.GetDailyAbsentGoodsOrderCount(db, storeID)
absentGoodsOrderCount, _ := dao.GetDailyAbsentGoodsOrderCount(db, storeID) finishOrderCount, _ := dao.GetDailyFinishOrderCount(db, storeID)
finishOrderCount, _ := dao.GetDailyFinishOrderCount(db, storeID) if finishOrderCount > 0 {
if finishOrderCount > 0 { finalScore := 0
finalScore := 0 absentGoodsOrderRatio := float64(absentGoodsOrderCount) * 100 / float64(finishOrderCount)
absentGoodsOrderRatio := float64(absentGoodsOrderCount) * 100 / float64(finishOrderCount) if absentGoodsOrderRatio <= AbsentGoodsOrderNormalRatio {
if absentGoodsOrderRatio <= AbsentGoodsOrderNormalRatio { finalScore = ItemTotalScore
finalScore = ItemTotalScore } else {
} else { decScore := int(math.Round((absentGoodsOrderRatio - AbsentGoodsOrderNormalRatio) / 0.1))
decScore := int(math.Round((absentGoodsOrderRatio - AbsentGoodsOrderNormalRatio) / 0.1)) finalScore = ItemTotalScore - decScore
finalScore = ItemTotalScore - decScore if finalScore < 0 {
if finalScore < 0 { finalScore = 0
finalScore = 0
}
} }
storeScoreDataWrapper.SetData(storeID, model.FieldAbsentGoodsOrder, finalScore)
} }
storeScoreDataWrapper.SetData(storeID, model.FieldAbsentGoodsOrder, finalScore)
} }
} }
//促销品数量20个以上为满分10分每少2个扣1分 //促销品数量20个以上为满分10分每少2个扣1分
func ScorePromotionSku(storeList []*cms.StoreExt) { func ScorePromotionSku(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { storeID := storeInfo.ID
storeID := storeInfo.ID db := dao.GetDB()
db := dao.GetDB() beginTime := time.Now()
beginTime := time.Now() endTime := time.Now()
endTime := time.Now() actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, -1, []int{}, []int{storeID}, []int{}, beginTime, endTime)
actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, -1, []int{}, []int{storeID}, []int{}, beginTime, endTime) if err == nil && len(actStoreSkuList) > 0 {
if err == nil && len(actStoreSkuList) > 0 { finalScore := 0
finalScore := 0 actStoreSkuMap := make(map[int]int)
actStoreSkuMap := make(map[int]int) for _, value := range actStoreSkuList {
for _, value := range actStoreSkuList { if value.Type != model.ActSkuFake {
if value.Type != model.ActSkuFake { actStoreSkuMap[value.SkuID] = 1
actStoreSkuMap[value.SkuID] = 1
}
} }
promotionSkuCount := len(actStoreSkuMap)
if promotionSkuCount >= PromotionSkuNormalCount {
finalScore = ItemTotalScore
} else {
decScore := (PromotionSkuNormalCount - promotionSkuCount) / 2
finalScore = ItemTotalScore - decScore
if finalScore < 0 {
finalScore = 0
}
}
storeScoreDataWrapper.SetData(storeID, model.FieldPromotionSku, finalScore)
} }
promotionSkuCount := len(actStoreSkuMap)
if promotionSkuCount >= PromotionSkuNormalCount {
finalScore = ItemTotalScore
} else {
decScore := (PromotionSkuNormalCount - promotionSkuCount) / 2
finalScore = ItemTotalScore - decScore
if finalScore < 0 {
finalScore = 0
}
}
storeScoreDataWrapper.SetData(storeID, model.FieldPromotionSku, finalScore)
} }
} }
//经营全平台满分10分每少一个平台扣2分(一个平台没有得0分) //经营全平台满分10分每少一个平台扣2分(一个平台没有得0分)
func ScoreFullVendor(storeList []*cms.StoreExt) { func ScoreFullVendor(storeInfo *cms.StoreExt) {
fullVendorCount := len(fullVendorList) fullVendorCount := len(fullVendorList)
for _, storeInfo := range storeList { finalScore := 0
finalScore := 0 storeID := storeInfo.ID
storeID := storeInfo.ID storeStatus := storeInfo.Status
storeStatus := storeInfo.Status isStoreOpen := storeStatus == model.StoreStatusOpened
isStoreOpen := storeStatus == model.StoreStatusOpened count := 0
count := 0 for _, storeMap := range storeInfo.StoreMaps {
for _, storeMap := range storeInfo.StoreMaps { vendorStoreStatus := int(utils.MustInterface2Int64(storeMap["status"]))
vendorStoreStatus := int(utils.MustInterface2Int64(storeMap["status"])) isVendorStoreOpen := vendorStoreStatus == model.StoreStatusOpened
isVendorStoreOpen := vendorStoreStatus == model.StoreStatusOpened opTimeList := storeInfo.GetOpTimeList()
opTimeList := storeInfo.GetOpTimeList() if len(opTimeList) > 0 && isStoreOpen && isVendorStoreOpen {
if len(opTimeList) > 0 && isStoreOpen && isVendorStoreOpen { count++
count++
}
} }
if count > 0 {
if count == fullVendorCount {
finalScore = ItemTotalScore
} else {
decScore := (fullVendorCount - count) * 2
finalScore = ItemTotalScore - decScore
}
}
storeScoreDataWrapper.SetData(storeID, model.FieldFullVendor, finalScore)
} }
if count > 0 {
if count == fullVendorCount {
finalScore = ItemTotalScore
} else {
decScore := (fullVendorCount - count) * 2
finalScore = ItemTotalScore - decScore
}
}
storeScoreDataWrapper.SetData(storeID, model.FieldFullVendor, finalScore)
} }
//经营范围面积大于半径2km的圆得满分10分低于1km得分0 //经营范围面积大于半径2km的圆得满分10分低于1km得分0
func ScoreStoreRange(storeList []*cms.StoreExt) { func ScoreStoreRange(storeInfo *cms.StoreExt) {
for _, storeInfo := range storeList { finalScore := 0
finalScore := 0 storeID := storeInfo.ID
storeID := storeInfo.ID if storeInfo.DeliveryRangeType == model.DeliveryRangeTypePolygon {
if storeInfo.DeliveryRangeType == model.DeliveryRangeTypePolygon { points := jxutils.CoordinateStr2Points(storeInfo.DeliveryRange)
points := jxutils.CoordinateStr2Points(storeInfo.DeliveryRange) area := jxutils.CalcPolygonAreaByLngAndLat(points)
area := jxutils.CalcPolygonAreaByLngAndLat(points) goodArea := math.Pi * StoreRangeGoodRadius * StoreRangeGoodRadius
goodArea := math.Pi * StoreRangeGoodRadius * StoreRangeGoodRadius badArea := math.Pi * StoreRangeBadRadius * StoreRangeBadRadius
badArea := math.Pi * StoreRangeBadRadius * StoreRangeBadRadius if area >= goodArea {
if area >= goodArea { finalScore = ItemTotalScore
finalScore = ItemTotalScore } else if area <= badArea {
} else if area <= badArea { finalScore = 0
finalScore = 0 } else {
} else { diff := goodArea - area
diff := goodArea - area ratio := float64(ItemTotalScore) / (goodArea - badArea)
ratio := float64(ItemTotalScore) / (goodArea - badArea) finalScore = ItemTotalScore - int(math.Round(diff*ratio))
finalScore = ItemTotalScore - int(math.Round(diff*ratio)) }
} } else if storeInfo.DeliveryRangeType == model.DeliveryRangeTypeRadius {
} else if storeInfo.DeliveryRangeType == model.DeliveryRangeTypeRadius { deliveryRadius := utils.Str2Float64WithDefault(storeInfo.DeliveryRange, 0) / 1000
deliveryRadius := utils.Str2Float64(storeInfo.DeliveryRange) / 1000 if deliveryRadius >= StoreRangeGoodRadius {
if deliveryRadius >= StoreRangeGoodRadius { finalScore = ItemTotalScore
finalScore = ItemTotalScore } else if deliveryRadius <= StoreRangeBadRadius {
} else if deliveryRadius <= StoreRangeBadRadius { finalScore = 0
finalScore = 0 } else {
} else { diff := StoreRangeGoodRadius - deliveryRadius
diff := StoreRangeGoodRadius - deliveryRadius ratio := float64(ItemTotalScore) / (StoreRangeGoodRadius - StoreRangeBadRadius)
ratio := float64(ItemTotalScore) / (StoreRangeGoodRadius - StoreRangeBadRadius) finalScore = ItemTotalScore - int(math.Round(diff*ratio))
finalScore = ItemTotalScore - int(math.Round(diff*ratio))
}
} }
storeScoreDataWrapper.SetData(storeID, model.FieldStoreRange, finalScore)
} }
storeScoreDataWrapper.SetData(storeID, model.FieldStoreRange, finalScore)
} }
//得到距离某个门店多少KM内的所有门店信息 //得到距离某个门店多少KM内的所有门店信息
func GetRangeStoreList(storeID int, lng, lat, checkDist float64, storeList []*cms.StoreExt) (outStoreList []*cms.StoreExt) { func GetRangeStoreList(storeID int, lng, lat, checkRange float64, storeList []*cms.StoreExt) (outStoreList []*cms.StoreExt) {
for _, storeInfo := range storeList { for _, storeInfo := range storeList {
if storeInfo.ID == storeID { if storeInfo.ID == storeID {
outStoreList = append(outStoreList, storeInfo) outStoreList = append(outStoreList, storeInfo)
} else { } else {
distance := jxutils.EarthDistance(lng, lat, storeInfo.FloatLng, storeInfo.FloatLat) distance := jxutils.EarthDistance(lng, lat, storeInfo.FloatLng, storeInfo.FloatLat)
if distance <= checkDist { if distance <= checkRange {
outStoreList = append(outStoreList, storeInfo) outStoreList = append(outStoreList, storeInfo)
} }
} }
@@ -454,29 +438,27 @@ func GetSkusCountLessEqualAvgPrice(storeID int, skusAveragePrice map[int]int) (c
} }
//可售商品价格在附近5km内门店比较价格低于等于平均值的商品数占90%以上满分10分比例每降低10%减1分100%超标得0分 //可售商品价格在附近5km内门店比较价格低于等于平均值的商品数占90%以上满分10分比例每降低10%减1分100%超标得0分
func ScoreSaleSkuPrice(ctx *jxcontext.Context, storeList []*cms.StoreExt) { func ScoreSaleSkuPrice(storeInfo *cms.StoreExt, storeList []*cms.StoreExt) {
for _, storeInfo := range storeList { finalScore := 0
finalScore := 0 storeID := storeInfo.ID
storeID := storeInfo.ID totalCount := len(allStoreSkusWrapper.GetData(storeID))
totalCount := len(allStoreSkusWrapper.GetData(storeID)) if totalCount > 0 {
if totalCount > 0 { rangeStoreList := GetRangeStoreList(storeID, storeInfo.FloatLng, storeInfo.FloatLat, SaleSkuCheckRange, storeList)
rangeStoreList := GetRangeStoreList(storeID, storeInfo.FloatLng, storeInfo.FloatLat, 5, storeList) skusAveragePrice := GetStoreSkusAveragePrice(rangeStoreList)
skusAveragePrice := GetStoreSkusAveragePrice(rangeStoreList) count := GetSkusCountLessEqualAvgPrice(storeID, skusAveragePrice)
count := GetSkusCountLessEqualAvgPrice(storeID, skusAveragePrice) if count > 0 {
if count > 0 { ratio := int(math.Round(float64(count) * 100 / float64(totalCount)))
ratio := int(math.Round(float64(count) * 100 / float64(totalCount))) if ratio >= SaleSkuPriceRatio {
if ratio >= SaleSkuPriceRatio { finalScore = ItemTotalScore
finalScore = ItemTotalScore } else {
} else { decScore := (SaleSkuPriceRatio - ratio) / 10
decScore := (SaleSkuPriceRatio - ratio) / 10 finalScore = ItemTotalScore - decScore
finalScore = ItemTotalScore - decScore if finalScore < 0 {
if finalScore < 0 { finalScore = 0
finalScore = 0
}
} }
} }
storeScoreDataWrapper.SetData(storeID, model.FieldSaleSkuPrice, finalScore)
} }
storeScoreDataWrapper.SetData(storeID, model.FieldSaleSkuPrice, finalScore)
} }
} }
@@ -506,24 +488,55 @@ func GetFilterStoreListEx(storeList []*cms.StoreExt, storeIDMap map[int]int) (ou
} }
func ScoreStore(ctx *jxcontext.Context, storeIDList []int) (retVal interface{}, err error) { func ScoreStore(ctx *jxcontext.Context, storeIDList []int) (retVal interface{}, err error) {
storeScoreDataWrapper.InitData() var storeList []*cms.StoreExt
storeList, err := GetStoreList(ctx) taskCount := 4
storeIDMap := jxutils.IntList2Map(storeIDList) taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
storeList = GetFilterStoreListEx(storeList, storeIDMap) switch step {
case 0:
GetAllStoreSkus(ctx, storeList) baseapi.SugarLogger.Debugf("ScoreStore step0 begin")
ScoreStoreOpenTime(storeList) storeScoreDataWrapper.InitData()
ScoreSaleSkuCount(ctx, storeList) storeList, err = GetStoreList(ctx)
ScoreAveragePickupTime(storeList) storeIDMap := jxutils.IntList2Map(storeIDList)
ScoreBadCommentOrder(storeList) storeList = GetFilterStoreListEx(storeList, storeIDMap)
ScoreUnfinishOrder(storeList) baseapi.SugarLogger.Debugf("ScoreStore step0 end")
ScoreAbsentGoodsOrder(storeList) case 1:
ScorePromotionSku(storeList) baseapi.SugarLogger.Debugf("ScoreStore step1 begin")
ScoreFullVendor(storeList) GetAllStoreSkus(ctx, task, storeList)
ScoreStoreRange(storeList) baseapi.SugarLogger.Debugf("ScoreStore step1 end")
ScoreSaleSkuPrice(ctx, storeList) case 2:
InsertStoreScore() baseapi.SugarLogger.Debugf("ScoreStore step2 begin")
allStoreSkusWrapper.ClearData() taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeInfo := batchItemList[0].(*cms.StoreExt)
ScoreStoreOpenTime(storeInfo)
ScoreSaleSkuCount(storeInfo)
ScoreAveragePickupTime(storeInfo)
ScoreBadCommentOrder(storeInfo)
ScoreUnfinishOrder(storeInfo)
ScoreAbsentGoodsOrder(storeInfo)
ScorePromotionSku(storeInfo)
ScoreFullVendor(storeInfo)
ScoreStoreRange(storeInfo)
ScoreSaleSkuPrice(storeInfo, storeList)
return retVal, err
}
taskParallel := tasksch.NewParallelTask("计算门店得分", tasksch.NewParallelConfig().SetParallelCount(ParallelCount), ctx, taskFunc, storeList)
tasksch.HandleTask(taskParallel, task, true).Run()
taskParallel.GetResult(0)
_, err = taskParallel.GetResult(0)
if err != nil {
baseapi.SugarLogger.Debugf("ScoreStore taskParallel error:%v", err)
}
baseapi.SugarLogger.Debugf("ScoreStore step2 end")
case 3:
baseapi.SugarLogger.Debugf("ScoreStore step3 begin")
InsertStoreScore()
allStoreSkusWrapper.ClearData()
baseapi.SugarLogger.Debugf("ScoreStore step3 end")
}
return result, err
}
taskSeq := tasksch.NewSeqTask("门店评分-序列任务", ctx, taskSeqFunc, taskCount)
tasksch.HandleTask(taskSeq, nil, true).Run()
return retVal, err return retVal, err
} }