From 46f31a7136349f3fb53e1b0c8a5e24f3a5fecc8a Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Tue, 10 Sep 2019 08:48:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E5=BA=97=E8=AF=84=E5=88=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/store_score.go | 51 +++++++++++++++++++++------- business/model/dao/dao_order.go | 32 +++++++++++------ 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/business/jxstore/misc/store_score.go b/business/jxstore/misc/store_score.go index a52d71aa3..6300a2066 100644 --- a/business/jxstore/misc/store_score.go +++ b/business/jxstore/misc/store_score.go @@ -6,14 +6,13 @@ import ( "sync" "time" - "git.rosy.net.cn/jx-callback/globals/refutil" - "git.rosy.net.cn/baseapi/utils" "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/jxcontext" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals/refutil" ) const ( @@ -28,16 +27,17 @@ const ( ItemTotalScore = 10 - StoreOpenTimeNormalTime = 12.0 //小时 - SaleSkuNormalCount = 1000 - SaleSkuScorePerUnit = float64(ItemTotalScore) / SaleSkuNormalCount - PromotionSkuNormalCount = 20 - AveragePickupTimeNormalTime = 10.0 //分钟 - BadCommentOrderNormalRatio = 0.2 - UnfinishOrderNormalRatio = 1.0 - StoreRangeGoodRadius = 2.0 //千米 - StoreRangeBadRadius = 1.0 //千米 - SaleSkuPriceRatio = 90 //百分比 + StoreOpenTimeNormalTime = 12.0 //小时 + SaleSkuNormalCount = 1000 //数量 + SaleSkuScorePerUnit = float64(ItemTotalScore) / SaleSkuNormalCount //分数 + PromotionSkuNormalCount = 20 //数量 + AveragePickupTimeNormalTime = 10.0 //分钟 + BadCommentOrderNormalRatio = 0.2 //百分比 + UnfinishOrderNormalRatio = 1.0 //百分比 + AbsentGoodsOrderNormalRatio = 1.0 //百分比 + StoreRangeGoodRadius = 2.0 //千米 + StoreRangeBadRadius = 1.0 //千米 + SaleSkuPriceRatio = 90 //百分比 ) var ( @@ -263,7 +263,27 @@ func ScoreUnfinishOrder(storeList []*cms.StoreExt) { //缺货订单和完成订单比小于1%得10分,比例每增加0.1%减1分 func ScoreAbsentGoodsOrder(storeList []*cms.StoreExt) { - + for _, storeInfo := range storeList { + storeID := storeInfo.ID + storeName := storeInfo.Name + db := dao.GetDB() + absentGoodsOrderCount, _ := dao.GetDailyAbsentGoodsOrderCount(db, storeID) + finishOrderCount, _ := dao.GetDailyFinishOrderCount(db, storeID) + if finishOrderCount > 0 { + finalScore := 0 + absentGoodsOrderRatio := float64(absentGoodsOrderCount) * 100 / float64(finishOrderCount) + if absentGoodsOrderRatio <= AbsentGoodsOrderNormalRatio { + finalScore = ItemTotalScore + } else { + decScore := int(math.Round((absentGoodsOrderRatio - AbsentGoodsOrderNormalRatio) / 0.1)) + finalScore = ItemTotalScore - decScore + if finalScore < 0 { + finalScore = 0 + } + } + storeScoreDataWrapper.SetData(storeID, storeName, model.FieldAbsentGoodsOrder, finalScore) + } + } } //促销品数量20个以上为满分10分,每少2个扣1分 @@ -461,11 +481,16 @@ func GetFilterStoreListEx(storeList []*cms.StoreExt, storeIDMap map[int]int) (ou continue } } + var tempStoreMaps []map[string]interface{} for _, vendorStoreInfo := range storeInfo.StoreMaps { vendorID := int(utils.MustInterface2Int64(vendorStoreInfo["vendorID"])) if _, ok := fullVendorList[vendorID]; !ok { continue } + tempStoreMaps = append(tempStoreMaps, vendorStoreInfo) + } + if len(tempStoreMaps) > 0 { + storeInfo.StoreMaps = tempStoreMaps outStoreList = append(outStoreList, storeInfo) } } diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index c5297e687..e103524e1 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -306,30 +306,42 @@ func GetDailyFinishOrderList(db *DaoDB, storeID int) (orderList []*model.OrderPi return orderList, GetRows(db, &orderList, sql, sqlParams...) } -func GetDailyBadCommentOrderCount(db *DaoDB, storeID int) (num int64, err error) { +func GetDailyBadCommentOrderCount(db *DaoDB, storeID int) (count int64, err error) { sql := `select count(*) from jx_bad_comments where DATE(createtime) = CURDATE() and jxstoreid = ?` sqlParams := []interface{}{ storeID, } - return ExecuteSQL(db, sql, sqlParams) + err = GetRow(db, &count, sql, sqlParams...) + + return count, err } func GetDailyUnFinishOrderCount(db *DaoDB, storeID int) (num int64, err error) { - return GetDailyEndOrderCount(db, storeID, []int{model.OrderStatusCanceled}) + return GetDailyEndOrderCount(db, storeID, []int{model.OrderStatusCanceled}, false) } func GetDailyFinishOrderCount(db *DaoDB, storeID int) (num int64, err error) { - return GetDailyEndOrderCount(db, storeID, []int{model.OrderStatusFinished}) + return GetDailyEndOrderCount(db, storeID, []int{model.OrderStatusFinished}, false) } -func GetDailyEndOrderCount(db *DaoDB, storeID int, statusList []int) (num int64, err error) { - sql := `select count(*) from goods_order - where DATE(order_finished_at) = CURDATE() - and jx_store_id = ? - and status in (` + GenQuestionMarks(len(statusList)) + `)` +func GetDailyAbsentGoodsOrderCount(db *DaoDB, storeID int) (num int64, err error) { + return GetDailyEndOrderCount(db, storeID, []int{model.OrderStatusFinished, model.OrderStatusCanceled}, true) +} + +func GetDailyEndOrderCount(db *DaoDB, storeID int, statusList []int, isAbsentOrder bool) (count int64, err error) { + sql := `SELECT COUNT(*) FROM goods_order + WHERE DATE(order_finished_at) = CURDATE() + AND jx_store_id = ? + AND status IN (` + GenQuestionMarks(len(statusList)) + `)` + if isAbsentOrder { + sql += ` + AND adjust_count > 0` + } sqlParams := []interface{}{ storeID, } sqlParams = append(sqlParams, statusList) - return ExecuteSQL(db, sql, sqlParams) + err = GetRow(db, &count, sql, sqlParams...) + + return count, err }