修改门店评分细节

This commit is contained in:
Rosy-zhudan
2019-09-16 16:20:46 +08:00
parent 22f8d169d0
commit e35d86f690
6 changed files with 104 additions and 60 deletions

View File

@@ -1,6 +1,7 @@
package misc package misc
import ( import (
"fmt"
"math" "math"
"reflect" "reflect"
"sync" "sync"
@@ -48,6 +49,7 @@ var (
scoreStoreTimeList = []string{ scoreStoreTimeList = []string{
"22:00:00", "22:00:00",
} }
scoreStoreCheckTimeEnd = "23:30:00"
fullVendorList = map[int]bool{ fullVendorList = map[int]bool{
model.VendorIDJD: true, model.VendorIDJD: true,
model.VendorIDMTWM: true, model.VendorIDMTWM: true,
@@ -68,6 +70,8 @@ var (
storeScoreDataWrapper StoreScoreDataWrapper storeScoreDataWrapper StoreScoreDataWrapper
allStoreSkusWrapper AllStoreSkusWrapper allStoreSkusWrapper AllStoreSkusWrapper
scoreDate time.Time
isScoring bool
) )
type AllStoreSkusWrapper struct { type AllStoreSkusWrapper struct {
@@ -127,6 +131,7 @@ func (s *StoreScoreDataWrapper) SetData(storeID int, valueName string, value int
if data == nil { if data == nil {
data = &model.StoreScore{} data = &model.StoreScore{}
data.StoreID = storeID data.StoreID = storeID
data.ScoreDate = scoreDate
s.storeScoreData[storeID] = data s.storeScoreData[storeID] = data
} }
valueInfo := reflect.ValueOf(data).Elem() valueInfo := reflect.ValueOf(data).Elem()
@@ -251,10 +256,11 @@ func ScoreStoreOpenTime(storeInfo *cms.StoreExt) {
finalScore := 0 finalScore := 0
if isStoreOpen { if isStoreOpen {
for _, storeMap := range storeInfo.StoreMaps { for _, storeMap := range storeInfo.StoreMaps {
isSyncStoreSku := int(utils.MustInterface2Int64(storeMap["isSync"]))
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 && isSyncStoreSku != 0 {
opTime := GetOpenTime(opTimeList) opTime := GetOpenTime(opTimeList)
if opTime >= StoreOpenTimeNormalTime { if opTime >= StoreOpenTimeNormalTime {
finalScore = ItemTotalScore finalScore = ItemTotalScore
@@ -278,15 +284,6 @@ func ScoreSaleSkuCount(storeInfo *cms.StoreExt) {
finalScore := 0 finalScore := 0
if len(skusMapData) > 0 { if len(skusMapData) > 0 {
saleSkuCount := len(skusMapData) saleSkuCount := len(skusMapData)
// saleSkuCount := 0
// for _, value := range skusMapData {
// for _, skuInfo := range value.Skus2 {
// saleStatus := jxutils.MergeSkuStatus(skuInfo.SkuStatus, skuInfo.StoreSkuStatus)
// if saleStatus == model.SkuStatusNormal {
// saleSkuCount++
// }
// }
// }
finalScore = int(math.Round(float64(saleSkuCount) * SaleSkuScorePerUnit)) finalScore = int(math.Round(float64(saleSkuCount) * SaleSkuScorePerUnit))
if finalScore > ItemTotalScore { if finalScore > ItemTotalScore {
finalScore = ItemTotalScore finalScore = ItemTotalScore
@@ -299,7 +296,7 @@ func ScoreSaleSkuCount(storeInfo *cms.StoreExt) {
func ScoreAveragePickupTime(storeInfo *cms.StoreExt) { func ScoreAveragePickupTime(storeInfo *cms.StoreExt) {
storeID := storeInfo.ID storeID := storeInfo.ID
db := dao.GetDB() db := dao.GetDB()
orderList, err := dao.GetDailyFinishOrderList(db, storeID) orderList, err := dao.GetDailyFinishOrderList(db, storeID, scoreDate)
orderListCount := len(orderList) orderListCount := len(orderList)
finalScore := 0 finalScore := 0
if err == nil && orderListCount > 0 { if err == nil && orderListCount > 0 {
@@ -392,7 +389,7 @@ func ScorePromotionSku(storeInfo *cms.StoreExt) {
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, nil, []int{storeID}, nil, beginTime, endTime)
finalScore := 0 finalScore := 0
if err == nil && len(actStoreSkuList) > 0 { if err == nil && len(actStoreSkuList) > 0 {
actStoreSkuMap := make(map[int]int) actStoreSkuMap := make(map[int]int)
@@ -424,10 +421,11 @@ func ScoreFullVendor(storeInfo *cms.StoreExt) {
isStoreOpen := storeStatus == model.StoreStatusOpened isStoreOpen := storeStatus == model.StoreStatusOpened
count := 0 count := 0
for _, storeMap := range storeInfo.StoreMaps { for _, storeMap := range storeInfo.StoreMaps {
isSyncStoreSku := int(utils.MustInterface2Int64(storeMap["isSync"]))
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 && isSyncStoreSku != 0 {
count++ count++
} }
} }
@@ -573,6 +571,8 @@ 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) {
isScoring = true
scoreDate = utils.GetCurDate()
var storeList []*cms.StoreExt var storeList []*cms.StoreExt
taskCount := 5 taskCount := 5
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
@@ -590,13 +590,13 @@ func ScoreStore(ctx *jxcontext.Context, storeIDList []int) (retVal interface{},
baseapi.SugarLogger.Debugf("ScoreStore step1 end") baseapi.SugarLogger.Debugf("ScoreStore step1 end")
case 2: case 2:
db := dao.GetDB() db := dao.GetDB()
storeCountList, _ := dao.GetDailyBadCommentOrderCount(db) storeCountList, _ := dao.GetDailyBadCommentOrderCount(db, scoreDate)
storeScoreDataWrapper.SetDailyBadCommentOrderCount(storeCountList) storeScoreDataWrapper.SetDailyBadCommentOrderCount(storeCountList)
storeCountList, _ = dao.GetDailyUnFinishOrderCount(db) storeCountList, _ = dao.GetDailyUnFinishOrderCount(db, scoreDate)
storeScoreDataWrapper.SetDailyUnFinishOrderCount(storeCountList) storeScoreDataWrapper.SetDailyUnFinishOrderCount(storeCountList)
storeCountList, _ = dao.GetDailyFinishOrderCount(db) storeCountList, _ = dao.GetDailyFinishOrderCount(db, scoreDate)
storeScoreDataWrapper.SetDailyFinishOrderCount(storeCountList) storeScoreDataWrapper.SetDailyFinishOrderCount(storeCountList)
storeCountList, _ = dao.GetDailyAbsentGoodsOrderCount(db) storeCountList, _ = dao.GetDailyAbsentGoodsOrderCount(db, scoreDate)
storeScoreDataWrapper.SetDailyAbsentGoodsOrderCount(storeCountList) storeScoreDataWrapper.SetDailyAbsentGoodsOrderCount(storeCountList)
case 3: case 3:
baseapi.SugarLogger.Debugf("ScoreStore step2 begin") baseapi.SugarLogger.Debugf("ScoreStore step2 begin")
@@ -631,6 +631,7 @@ func ScoreStore(ctx *jxcontext.Context, storeIDList []int) (retVal interface{},
storeScoreDataWrapper.ClearData() storeScoreDataWrapper.ClearData()
allStoreSkusWrapper.ClearData() allStoreSkusWrapper.ClearData()
baseapi.SugarLogger.Debugf("ScoreStore step3 end") baseapi.SugarLogger.Debugf("ScoreStore step3 end")
isScoring = false
} }
return result, err return result, err
} }
@@ -643,8 +644,29 @@ func ScoreStore(ctx *jxcontext.Context, storeIDList []int) (retVal interface{},
func ScheduleScoreStore() { func ScheduleScoreStore() {
if EnableScheduleScoreStore { if EnableScheduleScoreStore {
ScheduleTimerFunc("ScheduleScoreStore", func() { ScheduleTimerFunc("ScheduleScoreStore", func() {
ScoreStore(jxcontext.AdminCtx, []int{}) if !isScoring {
ScoreStore(jxcontext.AdminCtx, nil)
}
}, scoreStoreTimeList) }, scoreStoreTimeList)
CheckScoreStore()
}
}
func CheckScoreStore() {
if !isScoring {
curTime := time.Now()
year, month, day := curTime.Date()
checkTimeStr1 := fmt.Sprintf("%d-%d-%d "+scoreStoreTimeList[0], year, int(month), day)
checkTime1 := utils.Str2Time(checkTimeStr1)
checkTimeStr2 := fmt.Sprintf("%d-%d-%d "+scoreStoreCheckTimeEnd, year, int(month), day)
checkTime2 := utils.Str2Time(checkTimeStr2)
if curTime.Unix() >= checkTime1.Unix() && curTime.Unix() <= checkTime2.Unix() {
db := dao.GetDB()
hasStoreScoreData, err := dao.CheckHasStoreScoreData(db, time.Now())
if err == nil && !hasStoreScoreData {
ScoreStore(jxcontext.AdminCtx, nil)
}
}
} }
} }

View File

@@ -194,18 +194,6 @@ func EarthDistance(lng1, lat1, lng2, lat2 float64) float64 {
return dist * radius return dist * radius
} }
//计算多边形平面面积
func CalcPolygonArea(points [][2]float64) (area float64) {
count := len(points)
for i := 0; i < count-1; i++ {
area += (points[i][0] - points[i+1][0]) * (points[i][1] + points[i+1][1])
}
area += (points[count-1][0] - points[0][0]) * (points[count-1][1] + points[0][1])
area = math.Abs(area) / 2
return area
}
func ConvertToRadian(value float64) float64 { func ConvertToRadian(value float64) float64 {
return value * math.Pi / 180 return value * math.Pi / 180
} }

View File

@@ -73,8 +73,3 @@ type OrderFinancialSkuExt struct {
OrderSkuFinancial OrderSkuFinancial
Image string `json:"image"` Image string `json:"image"`
} }
type OrderPickupTime struct {
StatusTime time.Time
PickDeadline time.Time
}

View File

@@ -291,51 +291,70 @@ func GetStoreAfsOrderSkuList(db *DaoDB, storeIDs []int, finishedAtBegin, finishe
return afsSkuList, err return afsSkuList, err
} }
func GetDailyFinishOrderList(db *DaoDB, storeID int) (orderList []*model.OrderPickupTime, err error) { func GetDailyFinishOrderList(db *DaoDB, storeID int, dateTime time.Time) (orderList []*model.OrderPickupTime, err error) {
sql := ` sql := `
select t2.status_time, t1.pick_deadline SELECT t2.status_time, t1.pick_deadline
from goods_order t1 FROM goods_order t1
left join order_status t2 on t1.vendor_order_id = t2.vendor_order_id JOIN order_status t2 ON t1.vendor_order_id = t2.vendor_order_id AND t1.vendor_id = t2.vendor_id
where t1.jx_store_id = ? and t2.order_type = ? and t2.status = ? and DATE(t1.order_finished_at) = CURDATE() WHERE t1.jx_store_id = ? AND t2.order_type = ? AND t2.status = ? AND DATE(t1.order_finished_at) = DATE(?)
` `
sqlParams := []interface{}{ sqlParams := []interface{}{
storeID, storeID,
1, 1,
model.OrderStatusFinishedPickup, model.OrderStatusFinishedPickup,
dateTime,
} }
return orderList, GetRows(db, &orderList, sql, sqlParams...) return orderList, GetRows(db, &orderList, sql, sqlParams...)
} }
func GetDailyBadCommentOrderCount(db *DaoDB) (storeCountList []*model.StoreCount, err error) { func GetDailyBadCommentOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) {
sql := `select jxstoreid store_id, COUNT(*) count from jx_bad_comments where DATE(createtime) = CURDATE() GROUP BY jxstoreid` sql := `
err = GetRows(db, &storeCountList, sql) SELECT jxstoreid store_id, COUNT(*) count
FROM jx_bad_comments
WHERE DATE(createtime) = DATE(?)
GROUP BY jxstoreid
`
sqlParams := []interface{}{
dateTime,
}
err = GetRows(db, &storeCountList, sql, sqlParams)
return storeCountList, err return storeCountList, err
} }
func GetDailyUnFinishOrderCount(db *DaoDB) (storeCountList []*model.StoreCount, err error) { func GetDailyUnFinishOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) {
return GetDailyEndOrderCount(db, []int{model.OrderStatusCanceled}, false) return GetDailyEndOrderCount(db, []int{model.OrderStatusCanceled}, false, dateTime)
} }
func GetDailyFinishOrderCount(db *DaoDB) (storeCountList []*model.StoreCount, err error) { func GetDailyFinishOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) {
return GetDailyEndOrderCount(db, []int{model.OrderStatusFinished}, false) return GetDailyEndOrderCount(db, []int{model.OrderStatusFinished}, false, dateTime)
} }
func GetDailyAbsentGoodsOrderCount(db *DaoDB) (storeCountList []*model.StoreCount, err error) { func GetDailyAbsentGoodsOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) {
return GetDailyEndOrderCount(db, []int{model.OrderStatusFinished, model.OrderStatusCanceled}, true) return GetDailyEndOrderCount(db, []int{model.OrderStatusFinished, model.OrderStatusCanceled}, true, dateTime)
} }
func GetDailyEndOrderCount(db *DaoDB, statusList []int, isAbsentOrder bool) (storeCountList []*model.StoreCount, err error) { func GetDailyEndOrderCount(db *DaoDB, statusList []int, isAbsentOrder bool, dateTime time.Time) (storeCountList []*model.StoreCount, err error) {
sql := `SELECT jx_store_id store_id, COUNT(*) count FROM goods_order sql := `
WHERE DATE(order_finished_at) = CURDATE() SELECT jx_store_id store_id, COUNT(*) count
AND status IN (` + GenQuestionMarks(len(statusList)) + `)` FROM goods_order
WHERE DATE(order_finished_at) = DATE(?)
`
sqlParams := []interface{}{
dateTime,
}
if len(statusList) > 0 {
sql += ` AND status IN (` + GenQuestionMarks(len(statusList)) + `)`
sqlParams = append(sqlParams, statusList)
}
if isAbsentOrder { if isAbsentOrder {
sql += ` sql += `
AND adjust_count > 0` AND adjust_count > 0
`
} }
sql += ` sql += `
GROUP BY jx_store_id` GROUP BY jx_store_id`
err = GetRow(db, &storeCountList, sql) err = GetRow(db, &storeCountList, sql, sqlParams)
return storeCountList, err return storeCountList, err
} }

View File

@@ -6,7 +6,6 @@ import (
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
) )
// func InsertStoreScore(storeID int, scores map[string]int) error {
func InsertStoreScore(storeScore *model.StoreScore) error { func InsertStoreScore(storeScore *model.StoreScore) error {
storeScore.CreatedAt = time.Now() storeScore.CreatedAt = time.Now()
return CreateEntity(nil, storeScore) return CreateEntity(nil, storeScore)
@@ -17,7 +16,7 @@ func GetLatestWeeklyStoreScoreList(db *DaoDB, storeID, weekNum int) (storeScoreL
SELECT t2.name store_name, t1.* FROM store_score t1 SELECT t2.name store_name, t1.* FROM store_score t1
JOIN store t2 ON t1.store_id = t2.id JOIN store t2 ON t1.store_id = t2.id
WHERE t1.store_id = ? WHERE t1.store_id = ?
AND DATE(t1.created_at) >= DATE_SUB( AND DATE(t1.ScoreDate) >= DATE_SUB(
DATE_SUB( DATE_SUB(
CURDATE(), CURDATE(),
INTERVAL INTERVAL
@@ -29,7 +28,7 @@ func GetLatestWeeklyStoreScoreList(db *DaoDB, storeID, weekNum int) (storeScoreL
), ),
INTERVAL ? DAY INTERVAL ? DAY
) )
AND DATE(t1.created_at) <= DATE_SUB( AND DATE(t1.ScoreDate) <= DATE_SUB(
CURDATE(), CURDATE(),
INTERVAL INTERVAL
IF ( IF (
@@ -38,7 +37,7 @@ func GetLatestWeeklyStoreScoreList(db *DaoDB, storeID, weekNum int) (storeScoreL
DAYOFWEEK(CURDATE()) - 1 DAYOFWEEK(CURDATE()) - 1
) DAY ) DAY
) )
ORDER BY created_at DESC ORDER BY ScoreDate DESC
` `
if weekNum <= 0 { if weekNum <= 0 {
weekNum = 1 weekNum = 1
@@ -51,3 +50,18 @@ func GetLatestWeeklyStoreScoreList(db *DaoDB, storeID, weekNum int) (storeScoreL
err = GetRows(db, &storeScoreList, sql, sqlParams) err = GetRows(db, &storeScoreList, sql, sqlParams)
return storeScoreList, err return storeScoreList, err
} }
func CheckHasStoreScoreData(db *DaoDB, dateTime time.Time) (hasStoreScoreData bool, err error) {
sql := `
SELECT COUNT(*) count
FROM store_score
WHERE DATE(createtime) = DATE(?)
`
sqlParams := []interface{}{
dateTime,
}
count := 0
err = GetRow(db, &count, sql, sqlParams)
hasStoreScoreData = count > 0
return hasStoreScoreData, err
}

View File

@@ -20,6 +20,7 @@ const (
type StoreScore struct { type StoreScore struct {
ID int `orm:"column(id)" json:"id"` ID int `orm:"column(id)" json:"id"`
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"` CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
ScoreDate time.Time `orm:"auto_now_add;type(datetime)" json:"scoreDate"`
StoreID int `orm:"column(store_id)" json:"storeID"` StoreID int `orm:"column(store_id)" json:"storeID"`
StoreOpenTime int `orm:"column(store_open_time)" json:"storeOpenTime"` StoreOpenTime int `orm:"column(store_open_time)" json:"storeOpenTime"`
@@ -52,3 +53,8 @@ type StoreCount struct {
StoreID int `orm:"column(store_id)"` StoreID int `orm:"column(store_id)"`
Count int Count int
} }
type OrderPickupTime struct {
StatusTime time.Time
PickDeadline time.Time
}