From a7b2dc3abd6d7499d596c749e9b10150f29ff015 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Fri, 27 Sep 2019 10:36:34 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E9=97=A8=E5=BA=97=E7=BA=A2=E7=BA=BF?= =?UTF-8?q?=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 255 ++++++++++++++++++++ business/jxstore/misc/store_score.go | 29 ++- business/model/Store_Alert_Inform.go | 16 ++ business/model/dao/Store_Alert_Inform.go | 3 + business/model/dao/dao_order.go | 224 ++++++++++++++++- business/model/store_score.go | 5 + controllers/cms_store.go | 6 +- controllers/temp_op.go | 14 ++ routers/commentsRouter_controllers.go | 9 + 9 files changed, 540 insertions(+), 21 deletions(-) create mode 100644 business/jxstore/misc/Store_Alert_Inform.go create mode 100644 business/model/Store_Alert_Inform.go create mode 100644 business/model/dao/Store_Alert_Inform.go diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go new file mode 100644 index 000000000..68135d9e8 --- /dev/null +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -0,0 +1,255 @@ +package misc + +import ( + "fmt" + "time" + + "git.rosy.net.cn/jx-callback/business/jxstore/cms" + "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" +) + +const ( + CheckStoreAlertOneMonthDayNum = 30 + CheckStoreAlertOneDayNum = 1 + CheckStoreAlertOneWeekDayNum = 7 + MonthCheckOnWeekDay = 1 + + AlertTypePickTimeOrderDaDa = 0 + AlertTypeBadCommentOrder = 1 + AlertTypeAbsentGoodsOrder = 2 + AlertTypePickTimeOrderSelfDelivery = 3 + AlertTypePickUpTimeOrderDaDa = 4 + + OneDayName = "单日" + OneWeekDayName = "七日" + OneMonthDayName = "三十日" + YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,可能会被系统下线,请及时补救。" + RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,会被系统下线,需要马上补救。" + NoOrderAlertInfo = "您的店铺京西菜市-%s,由于近%s无订单,会被系统下线,需要马上补救。" +) + +var ( + checkStoreAlertTimeList = []string{ + "18:30:00", + } + + AlertTypeNameMap = map[int]string{ + AlertTypePickTimeOrderDaDa: "拣货履约率(达达)", + AlertTypeBadCommentOrder: "差评率", + AlertTypeAbsentGoodsOrder: "缺货率", + AlertTypePickTimeOrderSelfDelivery: "按时履约率(商家自送)", + AlertTypePickUpTimeOrderDaDa: "10分钟取货完成率(达达)", + } +) + +func ConvertListToMap(listData []*model.StoreCount) (mapData map[int]int) { + mapData = make(map[int]int) + for _, value := range listData { + mapData[value.StoreID] = value.Count + } + + return mapData +} + +func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, ratio int) (info string) { + if dayNum == CheckStoreAlertOneDayNum { + if isRedAlert { + info = fmt.Sprintf(RedAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], ratio) + } else { + info = fmt.Sprintf(YellowAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], ratio) + } + } else if dayNum == CheckStoreAlertOneWeekDayNum { + if isRedAlert { + info = fmt.Sprintf(RedAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], ratio) + } else { + info = fmt.Sprintf(YellowAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], ratio) + } + } else if dayNum == CheckStoreAlertOneMonthDayNum { + info = fmt.Sprintf(NoOrderAlertInfo, storeName, OneMonthDayName) + } + + return info +} + +func GetAlertRatio(alertType int, dayNum int) (yellowRatio, redRatio float64) { + switch alertType { + case AlertTypePickTimeOrderDaDa: + if dayNum == CheckStoreAlertOneDayNum { + yellowRatio = -1 + redRatio = 0 + } else { + yellowRatio = 70 + redRatio = 50 + } + case AlertTypeBadCommentOrder: + if dayNum == CheckStoreAlertOneDayNum { + yellowRatio = -1 + redRatio = 100 + } else { + yellowRatio = 1 + redRatio = 3 + } + case AlertTypeAbsentGoodsOrder: + if dayNum == CheckStoreAlertOneDayNum { + yellowRatio = -1 + redRatio = 100 + } else { + yellowRatio = 3 + redRatio = 5 + } + case AlertTypePickTimeOrderSelfDelivery: + yellowRatio = 85 + redRatio = 70 + case AlertTypePickUpTimeOrderDaDa: + yellowRatio = 85 + redRatio = 70 + default: + yellowRatio = -1 + redRatio = -1 + } + + return float64(yellowRatio), float64(redRatio) +} + +func CheckStoreDayAlert(storeMapData map[int]*cms.StoreExt, dayNum int) (retVal interface{}, err error) { + db := dao.GetDB() + //拣货履约率(达达) + pickTimeOrderCountDaDa, err := dao.GetStandardPickTimeOrderCountByDaDa(db, dayNum, true) + pickTimeOrderCountDaDaMapData := ConvertListToMap(pickTimeOrderCountDaDa) + //完成订单(达达) + finishOrderCountDaDa, err := dao.GetFinishOrderCountByDaDa(db, dayNum, true) + finishOrderCountDaDaMapData := ConvertListToMap(finishOrderCountDaDa) + //差评订单 + badCommentOrderCount, err := dao.GetBadCommentOrderCountByDayNum(db, dayNum, true) + badCommentOrderCountMapData := ConvertListToMap(badCommentOrderCount) + //缺货订单 + absentGoodsOrderCount, err := dao.GetAbsentGoodsOrderCountByDayNum(db, dayNum, true) + absentGoodsOrderCountMapData := ConvertListToMap(absentGoodsOrderCount) + //完成订单 + finishOrderCount, err := dao.GetFinishOrderCountByDayNum(db, dayNum, true) + finishOrderCountMapData := ConvertListToMap(finishOrderCount) + //按时履约订单(商家自送) + standardFinishTimeOrderCountSelfDelivery, err := dao.GetStandardFinishTimeOrderCountBySelfDelivery(db, dayNum, true) + standardFinishTimeOrderCountSelfDeliveryMapData := ConvertListToMap(standardFinishTimeOrderCountSelfDelivery) + //完成订单(商家自送) + finishOrderCountSelfDelivery, err := dao.GetFinishOrderCountBySelfDelivery(db, dayNum, true) + finishOrderCountSelfDeliveryMapData := ConvertListToMap(finishOrderCountSelfDelivery) + //10分钟取货完成订单量(达达) + standardPickUpTimeOrderCountSelfDelivery, err := dao.GetStandardPickUpTimeOrderCountBySelfDelivery(db, dayNum, true) + standardPickUpTimeOrderCountSelfDeliveryMapData := ConvertListToMap(standardPickUpTimeOrderCountSelfDelivery) + + pickTimeOrderDaDaStoreIDListRed := []int{} + badCommentOrderStoreIDListRed := []int{} + absentGoodsOrderStoreIDListRed := []int{} + + pickTimeOrderDaDaStoreIDListYellow := []int{} + badCommentOrderStoreIDListYellow := []int{} + absentGoodsOrderStoreIDListYellow := []int{} + for _, storeInfo := range storeMapData { + storeID := storeInfo.ID + pickTimeOrderCountDaDa := pickTimeOrderCountDaDaMapData[storeID] + finishOrderCountDaDa := finishOrderCountDaDaMapData[storeID] + if finishOrderCountDaDa > 0 { + pickTimeOrderDaDaRatio := float64(pickTimeOrderCountDaDa) * 100 / float64(finishOrderCountDaDa) + yellowRatio, redRatio := GetAlertRatio(AlertTypePickTimeOrderDaDa, dayNum) + if redRatio != -1 && pickTimeOrderDaDaRatio <= redRatio { + pickTimeOrderDaDaStoreIDListRed = append(pickTimeOrderDaDaStoreIDListRed, storeID) + } else if yellowRatio != -1 && pickTimeOrderDaDaRatio <= yellowRatio { + pickTimeOrderDaDaStoreIDListYellow = append(pickTimeOrderDaDaStoreIDListYellow, storeID) + } + } + + badCommentOrderCount := badCommentOrderCountMapData[storeID] + absentGoodsOrderCount := absentGoodsOrderCountMapData[storeID] + finishOrderCount := finishOrderCountMapData[storeID] + if finishOrderCount > 0 { + badCommentOrderRatio := float64(badCommentOrderCount) * 100 / float64(finishOrderCount) + yellowRatio, redRatio := GetAlertRatio(AlertTypeBadCommentOrder, dayNum) + if redRatio != -1 && badCommentOrderRatio >= redRatio { + badCommentOrderStoreIDListRed = append(badCommentOrderStoreIDListRed, storeID) + } else if yellowRatio != -1 && badCommentOrderRatio >= yellowRatio { + badCommentOrderStoreIDListYellow = append(badCommentOrderStoreIDListYellow, storeID) + } + + absentGoodsOrderRatio := float64(absentGoodsOrderCount) * 100 / float64(finishOrderCount) + yellowRatio, redRatio = GetAlertRatio(AlertTypeAbsentGoodsOrder, dayNum) + if redRatio != -1 && absentGoodsOrderRatio >= redRatio { + absentGoodsOrderStoreIDListRed = append(absentGoodsOrderStoreIDListRed, storeID) + } else if yellowRatio != -1 && absentGoodsOrderRatio >= yellowRatio { + absentGoodsOrderStoreIDListYellow = append(absentGoodsOrderStoreIDListYellow, storeID) + } + } + + if dayNum == CheckStoreAlertOneWeekDayNum { + standardFinishTimeOrderCountSelfDelivery := standardFinishTimeOrderCountSelfDeliveryMapData[storeID] + finishOrderCountSelfDelivery := finishOrderCountSelfDeliveryMapData[storeID] + if finishOrderCountSelfDelivery > 0 { + standardFinishTimeOrderSelfDeliveryRatio := float64(standardFinishTimeOrderCountSelfDelivery) * 100 / float64(finishOrderCountSelfDelivery) + yellowRatio, redRatio := GetAlertRatio(AlertTypePickTimeOrderSelfDelivery, dayNum) + if redRatio != -1 && standardFinishTimeOrderSelfDeliveryRatio <= redRatio { + + } else if yellowRatio != -1 && standardFinishTimeOrderSelfDeliveryRatio <= yellowRatio { + + } + } + + standardPickUpTimeOrderCountSelfDelivery := standardPickUpTimeOrderCountSelfDeliveryMapData[storeID] + finishOrderCountDaDa := finishOrderCountDaDaMapData[storeID] + if finishOrderCountSelfDelivery > 0 { + standardPickUpTimeOrderSelfDeliveryRatio := float64(standardPickUpTimeOrderCountSelfDelivery) * 100 / float64(finishOrderCountDaDa) + yellowRatio, redRatio := GetAlertRatio(AlertTypePickUpTimeOrderDaDa, dayNum) + if redRatio != -1 && standardPickUpTimeOrderSelfDeliveryRatio <= redRatio { + + } else if yellowRatio != -1 && standardPickUpTimeOrderSelfDeliveryRatio <= yellowRatio { + + } + } + } + } + + return retVal, err +} + +func CheckStoreMonthAlert(storeMapData map[int]*cms.StoreExt) (retVal interface{}, err error) { + db := dao.GetDB() + storeCountList, err := dao.GetFinishOrderCountByDayNum(db, CheckStoreAlertOneMonthDayNum, true) + storeCountMapData := make(map[int]int) + for _, value := range storeCountList { + storeCountMapData[value.StoreID] = value.Count + } + + alertStoreIDList := []int{} + for _, storeInfo := range storeMapData { + storeID := storeInfo.ID + if _, ok := storeCountMapData[storeID]; !ok { + alertStoreIDList = append(alertStoreIDList, storeID) + } + } + + return retVal, err +} + +func CheckStoreAlert(ctx *jxcontext.Context) { + storeList, _ := GetStoreList(ctx) + storeMapData := make(map[int]*cms.StoreExt) + for _, value := range storeList { + storeMapData[value.ID] = value + } + if GetWeekDay() == MonthCheckOnWeekDay { + CheckStoreMonthAlert(storeMapData) + } + CheckStoreDayAlert(storeMapData, CheckStoreAlertOneDayNum) + CheckStoreDayAlert(storeMapData, CheckStoreAlertOneWeekDayNum) +} + +func GetWeekDay() int { + return int(time.Now().Weekday()) +} + +func ScheduleCheckStoreAlert() { + ScheduleTimerFunc("ScheduleCheckStoreAlert", func() { + CheckStoreAlert(jxcontext.AdminCtx) + }, checkStoreAlertTimeList) +} diff --git a/business/jxstore/misc/store_score.go b/business/jxstore/misc/store_score.go index 7079b5966..61b40fb50 100644 --- a/business/jxstore/misc/store_score.go +++ b/business/jxstore/misc/store_score.go @@ -808,10 +808,11 @@ func GetWeeklyStoreScore(storeID, weekIndexParam int) (outWeeklyStoreScoreDataLi return outWeeklyStoreScoreDataList, err } -func GetStoreTotalScoreList(storeIDList []int, cityCode int, keyWord string, beginTime, endTime time.Time, isDesc bool, checkScoreLow, checkScoreHigh int) (outStoreTotalScoreList []*model.StoreTotalScore, err error) { +func GetStoreTotalScoreList(storeIDList []int, cityCode int, keyWord string, beginTime, endTime time.Time, isDesc bool, checkScoreLow, checkScoreHigh, offset, pageSize int) (storeTotalScoreEx model.StoreTotalScoreEx, err error) { db := dao.GetDB() storeTotalScoreMapData := make(map[int]*model.StoreTotalScore) storeTotalScoreList, err := dao.GetStoreTotalScoreList(db, storeIDList, cityCode, keyWord, beginTime, endTime) + var filterStoreTotalScoreList []*model.StoreTotalScore if err == nil && len(storeTotalScoreList) > 0 { countDayNum := make(map[int]int) for _, value := range storeTotalScoreList { @@ -837,13 +838,13 @@ func GetStoreTotalScoreList(storeIDList []int, cityCode int, keyWord string, beg needAdd = false } if needAdd { - outStoreTotalScoreList = append(outStoreTotalScoreList, value) + filterStoreTotalScoreList = append(filterStoreTotalScoreList, value) } } if isDesc { - sort.Slice(outStoreTotalScoreList, func(i, j int) bool { - data1 := outStoreTotalScoreList[i] - data2 := outStoreTotalScoreList[j] + sort.Slice(filterStoreTotalScoreList, func(i, j int) bool { + data1 := filterStoreTotalScoreList[i] + data2 := filterStoreTotalScoreList[j] if data1.StoreScore == data2.StoreScore { return data1.StoreID < data2.StoreID } else { @@ -851,9 +852,9 @@ func GetStoreTotalScoreList(storeIDList []int, cityCode int, keyWord string, beg } }) } else { - sort.Slice(outStoreTotalScoreList, func(i, j int) bool { - data1 := outStoreTotalScoreList[i] - data2 := outStoreTotalScoreList[j] + sort.Slice(filterStoreTotalScoreList, func(i, j int) bool { + data1 := filterStoreTotalScoreList[i] + data2 := filterStoreTotalScoreList[j] if data1.StoreScore == data2.StoreScore { return data1.StoreID < data2.StoreID } else { @@ -863,5 +864,15 @@ func GetStoreTotalScoreList(storeIDList []int, cityCode int, keyWord string, beg } } - return outStoreTotalScoreList, err + offset = jxutils.FormalizePageOffset(offset) + pageSize = jxutils.FormalizePageSize(pageSize) + var pagedStoreTotalScoreList []*model.StoreTotalScore + for i := offset; i < offset+pageSize && i < len(filterStoreTotalScoreList); i++ { + pagedStoreTotalScoreList = append(pagedStoreTotalScoreList, filterStoreTotalScoreList[i]) + } + + storeTotalScoreEx.TotalCount = len(filterStoreTotalScoreList) + storeTotalScoreEx.StoreTotalScoreList = pagedStoreTotalScoreList + + return storeTotalScoreEx, err } diff --git a/business/model/Store_Alert_Inform.go b/business/model/Store_Alert_Inform.go new file mode 100644 index 000000000..6b799489c --- /dev/null +++ b/business/model/Store_Alert_Inform.go @@ -0,0 +1,16 @@ +package model + +import "time" + +type StoreOrderTime struct { + StoreID int `orm:"column(store_id)"` + OrderCreateTime time.Time `orm:"column(order_created_at)"` + OrderFinishedTime time.Time `orm:"column(order_finished_at)"` +} + +type StoreOrderStatus struct { + StoreID int `orm:"column(store_id)"` + VendorOrderID string `orm:"column(vendor_order_id)"` + StatusTime time.Time `orm:"column(status_time)"` + Status int `orm:"column(status)"` +} diff --git a/business/model/dao/Store_Alert_Inform.go b/business/model/dao/Store_Alert_Inform.go new file mode 100644 index 000000000..35b7c14c7 --- /dev/null +++ b/business/model/dao/Store_Alert_Inform.go @@ -0,0 +1,3 @@ +package dao + + diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index bbb20e382..4c771ea07 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -300,7 +300,7 @@ func GetDailyFinishOrderList(db *DaoDB, storeID int, dateTime time.Time) (orderL ` sqlParams := []interface{}{ storeID, - 1, + model.OrderTypeOrder, model.OrderStatusFinishedPickup, dateTime, } @@ -308,14 +308,25 @@ func GetDailyFinishOrderList(db *DaoDB, storeID int, dateTime time.Time) (orderL } func GetDailyBadCommentOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) { + beginTime, endTime := utils.GetTimeRange(dateTime, 1, true) + return GetBadCommentOrderCount(db, beginTime, endTime) +} + +func GetBadCommentOrderCountByDayNum(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) + return GetBadCommentOrderCount(db, beginTime, endTime) +} + +func GetBadCommentOrderCount(db *DaoDB, beginTime, endTime time.Time) (storeCountList []*model.StoreCount, err error) { sql := ` SELECT jxstoreid store_id, COUNT(*) count FROM jx_bad_comments - WHERE DATE(createtime) = DATE(?) + WHERE createtime >= ? AND createtime <= ? GROUP BY jxstoreid ` sqlParams := []interface{}{ - dateTime, + beginTime, + endTime, } err = GetRows(db, &storeCountList, sql, sqlParams) @@ -323,31 +334,64 @@ func GetDailyBadCommentOrderCount(db *DaoDB, dateTime time.Time) (storeCountList } func GetDailyUnFinishOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) { - return GetDailyEndOrderCount(db, []int{model.OrderStatusCanceled}, false, dateTime) + beginTime, endTime := utils.GetTimeRange(dateTime, 1, true) + return GetUnFinishOrderCount(db, beginTime, endTime) } func GetDailyFinishOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) { - return GetDailyEndOrderCount(db, []int{model.OrderStatusFinished}, false, dateTime) + beginTime, endTime := utils.GetTimeRange(dateTime, 1, true) + return GetFinishOrderCount(db, beginTime, endTime) } func GetDailyAbsentGoodsOrderCount(db *DaoDB, dateTime time.Time) (storeCountList []*model.StoreCount, err error) { - return GetDailyEndOrderCount(db, []int{model.OrderStatusFinished, model.OrderStatusCanceled}, true, dateTime) + beginTime, endTime := utils.GetTimeRange(dateTime, 1, true) + return GetAbsentGoodsOrderCount(db, beginTime, endTime) } -func GetDailyEndOrderCount(db *DaoDB, statusList []int, isAbsentOrder bool, dateTime time.Time) (storeCountList []*model.StoreCount, err error) { +func GetUnFinishOrderCount(db *DaoDB, beginTime, endTime time.Time) (storeCountList []*model.StoreCount, err error) { + return GetEndOrderCount(db, []int{model.OrderStatusCanceled}, false, beginTime, endTime) +} + +func GetFinishOrderCount(db *DaoDB, beginTime, endTime time.Time) (storeCountList []*model.StoreCount, err error) { + return GetEndOrderCount(db, []int{model.OrderStatusFinished}, false, beginTime, endTime) +} + +func GetAbsentGoodsOrderCount(db *DaoDB, beginTime, endTime time.Time) (storeCountList []*model.StoreCount, err error) { + return GetEndOrderCount(db, []int{model.OrderStatusFinished}, true, beginTime, endTime) +} + +func GetUnFinishOrderCountByDayNum(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + return GetEndOrderCountByDayNum(db, []int{model.OrderStatusCanceled}, false, dayNum, includeToday) +} + +func GetFinishOrderCountByDayNum(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + return GetEndOrderCountByDayNum(db, []int{model.OrderStatusFinished}, false, dayNum, includeToday) +} + +func GetAbsentGoodsOrderCountByDayNum(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + return GetEndOrderCountByDayNum(db, []int{model.OrderStatusFinished}, true, dayNum, includeToday) +} + +func GetEndOrderCountByDayNum(db *DaoDB, statusList []int, checkAbsentOrder bool, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) + return GetEndOrderCount(db, statusList, checkAbsentOrder, beginTime, endTime) +} + +func GetEndOrderCount(db *DaoDB, statusList []int, checkAbsentOrder bool, beginTime, endTime time.Time) (storeCountList []*model.StoreCount, err error) { sql := ` SELECT jx_store_id store_id, COUNT(*) count FROM goods_order - WHERE DATE(order_finished_at) = DATE(?) + WHERE order_finished_at >= ? AND order_finished_at <= ? ` sqlParams := []interface{}{ - dateTime, + beginTime, + endTime, } if len(statusList) > 0 { sql += ` AND status IN (` + GenQuestionMarks(len(statusList)) + `)` sqlParams = append(sqlParams, statusList) } - if isAbsentOrder { + if checkAbsentOrder { sql += ` AND adjust_count > 0 ` @@ -358,3 +402,163 @@ func GetDailyEndOrderCount(db *DaoDB, statusList []int, isAbsentOrder bool, date return storeCountList, err } + +func GetFinishOrderCountByDaDa(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + return GetFinishOrderCountByWayBillVendorID(db, model.VendorIDDada, dayNum, includeToday) +} + +func GetFinishOrderCountBySelfDelivery(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + return GetFinishOrderCountByWayBillVendorID(db, model.VendorIDUnknown, dayNum, includeToday) +} + +//通过运单平台ID来统计完成的订单量 +func GetFinishOrderCountByWayBillVendorID(db *DaoDB, wayBillVendorID, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + sql := ` + SELECT jx_store_id store_id, COUNT(*) count + FROM goods_order + where order_finished_at >= ? AND order_finished_at <= ? + AND status = ? + AND waybill_vendor_id = ? + GROUP BY jx_store_id + ` + beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) + sqlParams := []interface{}{ + beginTime, + endTime, + model.OrderStatusFinished, + wayBillVendorID, + } + + return storeCountList, GetRows(db, &storeCountList, sql, sqlParams) +} + +//拣货履约订单量, 仅统计达达专送 +func GetStandardPickTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + sql := ` + SELECT jx_store_id store_id, COUNT(*) count + FROM goods_order t1 + JOIN order_status t2 ON t2.vendor_order_id = t1.vendor_order_id + where t1.order_finished_at >= ? AND t1.order_finished_at <= ? + AND t1.status = ? + AND t1.waybill_vendor_id = ? + AND t2.order_type = ? + AND t2.status = ? + AND t2.status_time <= t1.pick_deadline + GROUP BY jx_store_id + ` + beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) + sqlParams := []interface{}{ + beginTime, + endTime, + model.OrderStatusFinished, + model.VendorIDDada, + model.OrderTypeOrder, + model.OrderStatusFinishedPickup, + } + + return storeCountList, GetRows(db, &storeCountList, sql, sqlParams) +} + +//按时履约订单量, 仅统计商家自送门店 +func GetStandardFinishTimeOrderCountBySelfDelivery(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + sql := ` + SELECT jx_store_id store_id, order_created_at orderCreateTime, order_finished_at orderFinishTime + FROM goods_order + where order_finished_at >= ? AND order_finished_at <= ? + AND status = ? + AND waybill_vendor_id = ? + ` + beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) + sqlParams := []interface{}{ + beginTime, + endTime, + model.OrderStatusFinished, + model.VendorIDUnknown, + } + + standardTime := int64(3600) + var storeOrderTimeList []*model.StoreOrderTime + storeOrderTimeMapData := make(map[int]int) + err = GetRows(db, &storeOrderTimeList, sql, sqlParams) + if err == nil && len(storeOrderTimeList) > 0 { + for _, value := range storeOrderTimeList { + if value.OrderFinishedTime.Unix()-value.OrderCreateTime.Unix() <= standardTime { + storeOrderTimeMapData[value.StoreID]++ + } + } + for storeID, count := range storeOrderTimeMapData { + storeCountList = append(storeCountList, &model.StoreCount{storeID, count}) + } + } + + return storeCountList, err +} + +//10分钟取货完成订单量, 仅统计达达专送 +func GetStandardPickUpTimeOrderCountBySelfDelivery(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { + sql := ` + SELECT t1.jx_store_id store_id, t1.vendor_order_id, t2.status_time, t2.status + FROM goods_order t1 + JOIN order_status t2 ON t2.vendor_order_id = t1.vendor_order_id + where t1.order_finished_at >= ? AND t1.order_finished_at <= ? + AND t1.status = ? + AND t1.waybill_vendor_id = ? + AND t2.status in (?, ?) + ORDER BY t1.vendor_order_id, t2.status_time + ` + beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) + sqlParams := []interface{}{ + beginTime, + endTime, + model.OrderStatusFinished, + model.VendorIDDada, + model.OrderStatusFinishedPickup, + model.OrderStatusDelivering, + } + + standardTime := int64(600) + var storeOrderStatusList []*model.StoreOrderStatus + storeOrderTimeMapData := make(map[int][]*model.StoreOrderStatus) + err = GetRows(db, &storeOrderStatusList, sql, sqlParams) + if err == nil && len(storeOrderStatusList) > 0 { + for _, value := range storeOrderStatusList { + if storeOrderTimeMapData[value.StoreID] == nil { + storeOrderTimeSubList := []*model.StoreOrderStatus{} + storeOrderTimeMapData[value.StoreID] = storeOrderTimeSubList + } + storeOrderTimeSubList := storeOrderTimeMapData[value.StoreID] + storeOrderTimeSubList = append(storeOrderTimeSubList, value) + } + for storeID, valueList := range storeOrderTimeMapData { + count := 0 + vendorOrderID := "" + statusBeginTime := int64(0) + statusEndTime := int64(0) + for _, value := range valueList { + if vendorOrderID != value.VendorOrderID { + if statusBeginTime != 0 && statusEndTime != 0 { + if statusEndTime-statusBeginTime <= standardTime { + count++ + } + } + vendorOrderID = value.VendorOrderID + statusBeginTime = int64(0) + statusEndTime = int64(0) + } + if value.Status == model.OrderStatusFinishedPickup { + statusBeginTime = value.StatusTime.Unix() + } else if value.Status == model.OrderStatusDelivering { + statusEndTime = value.StatusTime.Unix() + } + } + if statusBeginTime != 0 && statusEndTime != 0 { + if statusEndTime-statusBeginTime <= standardTime { + count++ + } + } + storeCountList = append(storeCountList, &model.StoreCount{storeID, count}) + } + } + + return storeCountList, err +} diff --git a/business/model/store_score.go b/business/model/store_score.go index fe2239216..b9e10857a 100644 --- a/business/model/store_score.go +++ b/business/model/store_score.go @@ -56,6 +56,11 @@ type StoreTotalScore struct { CityName string `orm:"column(city_name)" json:"cityName"` } +type StoreTotalScoreEx struct { + StoreTotalScoreList []*StoreTotalScore `json:"storeTotalScoreList"` + TotalCount int `json:"totalCount"` +} + type StoreCount struct { StoreID int `orm:"column(store_id)"` Count int diff --git a/controllers/cms_store.go b/controllers/cms_store.go index a1d44ee0d..baa99e1aa 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -462,12 +462,14 @@ func (c *StoreController) GetWeeklyStoreScore() { // @Param token header string true "认证token" // @Param storeIDs formData string false "京西门店ID列表" // @Param cityCode formData int false "城市编码" -// @Param keyWord formData string false "关键字" +// @Param keyword formData string false "关键字" // @Param beginTime formData string true "开始日期" // @Param endTime formData string true "结束日期" // @Param isDesc formData bool true "是否降序" // @Param checkScoreLow formData int false "在某个分数范围-低" // @Param checkScoreHigh formData int false "在某个分数范围-高" +// @Param offset formData int false "列表起始序号(以0开始,缺省为0)" +// @Param pageSize formData int false "列表页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /GetStoreTotalScoreList [post] @@ -477,7 +479,7 @@ func (c *StoreController) GetStoreTotalScoreList() { if err == nil { var storeIDList []int if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { - retVal, err = misc.GetStoreTotalScoreList(storeIDList, params.CityCode, params.KeyWord, timeList[0], timeList[1], params.IsDesc, params.CheckScoreLow, params.CheckScoreHigh) + retVal, err = misc.GetStoreTotalScoreList(storeIDList, params.CityCode, params.Keyword, timeList[0], timeList[1], params.IsDesc, params.CheckScoreLow, params.CheckScoreHigh, params.Offset, params.PageSize) } } return retVal, "", err diff --git a/controllers/temp_op.go b/controllers/temp_op.go index bc3ea66ff..30260038e 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -341,3 +341,17 @@ func (c *TempOpController) CreateConsumerFromOrders() { return retVal, "", err }) } + +// @Title 触犯红线通知 +// @Description 触犯红线通知 +// @Param token header string true "认证token" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /CheckStoreAlert [post] +func (c *TempOpController) CheckStoreAlert() { + c.callCheckStoreAlert(func(params *tTempopCheckStoreAlertParams) (retVal interface{}, errCode string, err error) { + misc.CheckStoreAlert(params.Ctx) + + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 64d9f5cf2..439d0a4ae 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1647,6 +1647,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"], + beego.ControllerComments{ + Method: "CheckStoreAlert", + Router: `/CheckStoreAlert`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"], beego.ControllerComments{ Method: "CreateConsumerFromOrders", From 6f579e7f1b08755defa6970227c5b30d6ff2f5ed Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Fri, 27 Sep 2019 16:30:18 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E9=97=A8=E5=BA=97=E8=A7=A6=E7=8A=AF?= =?UTF-8?q?=E7=BA=A2=E7=BA=BF=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 293 ++++++++++++-------- business/model/Store_Alert_Inform.go | 5 + business/model/dao/dao_order.go | 26 +- 3 files changed, 199 insertions(+), 125 deletions(-) diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go index 68135d9e8..24d242448 100644 --- a/business/jxstore/misc/Store_Alert_Inform.go +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -11,23 +11,25 @@ import ( ) const ( + IncludeToday = true CheckStoreAlertOneMonthDayNum = 30 CheckStoreAlertOneDayNum = 1 CheckStoreAlertOneWeekDayNum = 7 MonthCheckOnWeekDay = 1 - AlertTypePickTimeOrderDaDa = 0 - AlertTypeBadCommentOrder = 1 - AlertTypeAbsentGoodsOrder = 2 - AlertTypePickTimeOrderSelfDelivery = 3 - AlertTypePickUpTimeOrderDaDa = 4 + AlertTypePickTimeOrderDaDa = 0 + AlertTypeBadCommentOrder = 1 + AlertTypeAbsentGoodsOrder = 2 + AlertTypeStandardFinishTimeOrderSelfDelivery = 3 + AlertTypeStandardPickUpTimeOrderDaDa = 4 - OneDayName = "单日" - OneWeekDayName = "七日" - OneMonthDayName = "三十日" - YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,可能会被系统下线,请及时补救。" - RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,会被系统下线,需要马上补救。" - NoOrderAlertInfo = "您的店铺京西菜市-%s,由于近%s无订单,会被系统下线,需要马上补救。" + OneDayName = "单日" + OneWeekDayName = "七日" + OneMonthDayName = "三十日" + YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,可能会被系统下线,请及时补救。" + RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,会被系统下线,需要马上补救。" + NoOrderAlertInfo = "您的店铺京西菜市-%s,由于近%s无订单,会被系统下线,需要马上补救。" + RiskOrderAlertInfo = "系统检测到您的店铺可能有虚假定单,定单号为:%s,可能会被罚款,请及时与运营联系!" ) var ( @@ -36,11 +38,11 @@ var ( } AlertTypeNameMap = map[int]string{ - AlertTypePickTimeOrderDaDa: "拣货履约率(达达)", - AlertTypeBadCommentOrder: "差评率", - AlertTypeAbsentGoodsOrder: "缺货率", - AlertTypePickTimeOrderSelfDelivery: "按时履约率(商家自送)", - AlertTypePickUpTimeOrderDaDa: "10分钟取货完成率(达达)", + AlertTypePickTimeOrderDaDa: "拣货履约率(达达)", + AlertTypeBadCommentOrder: "差评率", + AlertTypeAbsentGoodsOrder: "缺货率", + AlertTypeStandardFinishTimeOrderSelfDelivery: "按时履约率(商家自送)", + AlertTypeStandardPickUpTimeOrderDaDa: "10分钟取货完成率(达达)", } ) @@ -53,7 +55,20 @@ func ConvertListToMap(listData []*model.StoreCount) (mapData map[int]int) { return mapData } -func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, ratio int) (info string) { +func ConvertListToMapEx(listData []*model.StoreOrder) (mapData map[int][]string) { + mapData = make(map[int][]string) + for _, value := range listData { + if mapData[value.StoreID] == nil { + mapData[value.StoreID] = []string{} + } + vendorOrderIDList := mapData[value.StoreID] + vendorOrderIDList = append(vendorOrderIDList, value.VendorOrderID) + } + + return mapData +} + +func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, ratio float64) (info string) { if dayNum == CheckStoreAlertOneDayNum { if isRedAlert { info = fmt.Sprintf(RedAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], ratio) @@ -73,162 +88,199 @@ func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, return info } -func GetAlertRatio(alertType int, dayNum int) (yellowRatio, redRatio float64) { +func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAlert, isRedAlert bool) { + yellowRatio := float64(-1) + redRatio := float64(-1) + extraCount := -1 + conditionLessEqual := false + switch alertType { case AlertTypePickTimeOrderDaDa: if dayNum == CheckStoreAlertOneDayNum { - yellowRatio = -1 redRatio = 0 - } else { + } else if dayNum == CheckStoreAlertOneWeekDayNum { yellowRatio = 70 redRatio = 50 + extraCount = 5 } + conditionLessEqual = false case AlertTypeBadCommentOrder: if dayNum == CheckStoreAlertOneDayNum { - yellowRatio = -1 redRatio = 100 - } else { + } else if dayNum == CheckStoreAlertOneWeekDayNum { yellowRatio = 1 redRatio = 3 + extraCount = 5 } + conditionLessEqual = true case AlertTypeAbsentGoodsOrder: if dayNum == CheckStoreAlertOneDayNum { - yellowRatio = -1 redRatio = 100 - } else { + } else if dayNum == CheckStoreAlertOneWeekDayNum { yellowRatio = 3 redRatio = 5 + extraCount = 5 } - case AlertTypePickTimeOrderSelfDelivery: + conditionLessEqual = true + case AlertTypeStandardFinishTimeOrderSelfDelivery: yellowRatio = 85 redRatio = 70 - case AlertTypePickUpTimeOrderDaDa: + conditionLessEqual = false + case AlertTypeStandardPickUpTimeOrderDaDa: yellowRatio = 85 redRatio = 70 - default: - yellowRatio = -1 - redRatio = -1 + conditionLessEqual = false } - return float64(yellowRatio), float64(redRatio) + if conditionLessEqual { + if extraCount != -1 && count >= extraCount { + isRedAlert = true + } else if redRatio != -1 && ratio <= redRatio { + isRedAlert = true + } else if yellowRatio != -1 && ratio <= yellowRatio { + isYellowAlert = true + } + } else { + if extraCount != -1 && count >= extraCount { + isRedAlert = true + } else if redRatio != -1 && ratio >= redRatio { + isRedAlert = true + } else if yellowRatio != -1 && ratio >= yellowRatio { + isYellowAlert = true + } + } + + return isYellowAlert, isRedAlert } -func CheckStoreDayAlert(storeMapData map[int]*cms.StoreExt, dayNum int) (retVal interface{}, err error) { +func SendAlertInfo(storeID int, alertInfo string) { + fmt.Printf("SendAlertInfo:%d %s\n", storeID, alertInfo) +} + +func SendAlertInfoWrapper(storeID int, storeName string, dayNum, alertType, count, totalCount int) { + if totalCount > 0 { + ratio := float64(count) * 100 / float64(totalCount) + yellowAlert, redAlert := CheckAlert(alertType, dayNum, ratio, count) + isAlert := false + isRedAlert := redAlert + isAlert = yellowAlert || redAlert + if isAlert { + alertInfo := GetAlertInfo(dayNum, isRedAlert, storeName, alertType, ratio) + SendAlertInfo(storeID, alertInfo) + } + } +} + +func CheckStoreDayAlert(storeMapData map[int]*cms.StoreExt, dayNum int) { db := dao.GetDB() - //拣货履约率(达达) - pickTimeOrderCountDaDa, err := dao.GetStandardPickTimeOrderCountByDaDa(db, dayNum, true) - pickTimeOrderCountDaDaMapData := ConvertListToMap(pickTimeOrderCountDaDa) + //拣货履约订单(达达) + pickTimeOrderCountDaDaList, _ := dao.GetStandardPickTimeOrderCountByDaDa(db, dayNum, IncludeToday) + pickTimeOrderCountDaDaMapData := ConvertListToMap(pickTimeOrderCountDaDaList) + //完成订单(达达) - finishOrderCountDaDa, err := dao.GetFinishOrderCountByDaDa(db, dayNum, true) - finishOrderCountDaDaMapData := ConvertListToMap(finishOrderCountDaDa) + finishOrderCountDaDaList, _ := dao.GetFinishOrderCountByDaDa(db, dayNum, IncludeToday) + finishOrderCountDaDaMapData := ConvertListToMap(finishOrderCountDaDaList) + //差评订单 - badCommentOrderCount, err := dao.GetBadCommentOrderCountByDayNum(db, dayNum, true) - badCommentOrderCountMapData := ConvertListToMap(badCommentOrderCount) + badCommentOrderCountList, _ := dao.GetBadCommentOrderCountByDayNum(db, dayNum, IncludeToday) + badCommentOrderCountMapData := ConvertListToMap(badCommentOrderCountList) + //缺货订单 - absentGoodsOrderCount, err := dao.GetAbsentGoodsOrderCountByDayNum(db, dayNum, true) - absentGoodsOrderCountMapData := ConvertListToMap(absentGoodsOrderCount) + absentGoodsOrderCountList, _ := dao.GetAbsentGoodsOrderCountByDayNum(db, dayNum, IncludeToday) + absentGoodsOrderCountMapData := ConvertListToMap(absentGoodsOrderCountList) + //完成订单 - finishOrderCount, err := dao.GetFinishOrderCountByDayNum(db, dayNum, true) - finishOrderCountMapData := ConvertListToMap(finishOrderCount) - //按时履约订单(商家自送) - standardFinishTimeOrderCountSelfDelivery, err := dao.GetStandardFinishTimeOrderCountBySelfDelivery(db, dayNum, true) - standardFinishTimeOrderCountSelfDeliveryMapData := ConvertListToMap(standardFinishTimeOrderCountSelfDelivery) - //完成订单(商家自送) - finishOrderCountSelfDelivery, err := dao.GetFinishOrderCountBySelfDelivery(db, dayNum, true) - finishOrderCountSelfDeliveryMapData := ConvertListToMap(finishOrderCountSelfDelivery) - //10分钟取货完成订单量(达达) - standardPickUpTimeOrderCountSelfDelivery, err := dao.GetStandardPickUpTimeOrderCountBySelfDelivery(db, dayNum, true) - standardPickUpTimeOrderCountSelfDeliveryMapData := ConvertListToMap(standardPickUpTimeOrderCountSelfDelivery) + finishOrderCountList, _ := dao.GetFinishOrderCountByDayNum(db, dayNum, IncludeToday) + finishOrderCountMapData := ConvertListToMap(finishOrderCountList) - pickTimeOrderDaDaStoreIDListRed := []int{} - badCommentOrderStoreIDListRed := []int{} - absentGoodsOrderStoreIDListRed := []int{} + var standardFinishTimeOrderCountSelfDeliveryList []*model.StoreCount + var standardFinishTimeOrderCountSelfDeliveryMapData map[int]int + var finishOrderCountSelfDeliveryList []*model.StoreCount + var finishOrderCountSelfDeliveryMapData map[int]int + var standardPickUpTimeOrderCountDaDaList []*model.StoreCount + var standardPickUpTimeOrderCountDaDaMapData map[int]int + isOneWeekDay := dayNum == CheckStoreAlertOneWeekDayNum + if isOneWeekDay { + //按时履约订单(商家自送) + standardFinishTimeOrderCountSelfDeliveryList, _ = dao.GetStandardFinishTimeOrderCountBySelfDelivery(db, dayNum, IncludeToday) + standardFinishTimeOrderCountSelfDeliveryMapData = ConvertListToMap(standardFinishTimeOrderCountSelfDeliveryList) + + //完成订单(商家自送) + finishOrderCountSelfDeliveryList, _ = dao.GetFinishOrderCountBySelfDelivery(db, dayNum, IncludeToday) + finishOrderCountSelfDeliveryMapData = ConvertListToMap(finishOrderCountSelfDeliveryList) + + //10分钟取货完成订单(达达) + standardPickUpTimeOrderCountDaDaList, _ = dao.GetStandardPickUpTimeOrderCountByDaDa(db, dayNum, IncludeToday) + standardPickUpTimeOrderCountDaDaMapData = ConvertListToMap(standardPickUpTimeOrderCountDaDaList) + } - pickTimeOrderDaDaStoreIDListYellow := []int{} - badCommentOrderStoreIDListYellow := []int{} - absentGoodsOrderStoreIDListYellow := []int{} for _, storeInfo := range storeMapData { storeID := storeInfo.ID - pickTimeOrderCountDaDa := pickTimeOrderCountDaDaMapData[storeID] - finishOrderCountDaDa := finishOrderCountDaDaMapData[storeID] - if finishOrderCountDaDa > 0 { - pickTimeOrderDaDaRatio := float64(pickTimeOrderCountDaDa) * 100 / float64(finishOrderCountDaDa) - yellowRatio, redRatio := GetAlertRatio(AlertTypePickTimeOrderDaDa, dayNum) - if redRatio != -1 && pickTimeOrderDaDaRatio <= redRatio { - pickTimeOrderDaDaStoreIDListRed = append(pickTimeOrderDaDaStoreIDListRed, storeID) - } else if yellowRatio != -1 && pickTimeOrderDaDaRatio <= yellowRatio { - pickTimeOrderDaDaStoreIDListYellow = append(pickTimeOrderDaDaStoreIDListYellow, storeID) - } - } + storeName := storeInfo.Name + count := pickTimeOrderCountDaDaMapData[storeID] + totalCount := finishOrderCountDaDaMapData[storeID] + SendAlertInfoWrapper(storeID, storeName, dayNum, AlertTypePickTimeOrderDaDa, count, totalCount) - badCommentOrderCount := badCommentOrderCountMapData[storeID] - absentGoodsOrderCount := absentGoodsOrderCountMapData[storeID] - finishOrderCount := finishOrderCountMapData[storeID] - if finishOrderCount > 0 { - badCommentOrderRatio := float64(badCommentOrderCount) * 100 / float64(finishOrderCount) - yellowRatio, redRatio := GetAlertRatio(AlertTypeBadCommentOrder, dayNum) - if redRatio != -1 && badCommentOrderRatio >= redRatio { - badCommentOrderStoreIDListRed = append(badCommentOrderStoreIDListRed, storeID) - } else if yellowRatio != -1 && badCommentOrderRatio >= yellowRatio { - badCommentOrderStoreIDListYellow = append(badCommentOrderStoreIDListYellow, storeID) - } + count = badCommentOrderCountMapData[storeID] + totalCount = finishOrderCountMapData[storeID] + SendAlertInfoWrapper(storeID, storeName, dayNum, AlertTypeBadCommentOrder, count, totalCount) + count = absentGoodsOrderCountMapData[storeID] + SendAlertInfoWrapper(storeID, storeName, dayNum, AlertTypeAbsentGoodsOrder, count, totalCount) - absentGoodsOrderRatio := float64(absentGoodsOrderCount) * 100 / float64(finishOrderCount) - yellowRatio, redRatio = GetAlertRatio(AlertTypeAbsentGoodsOrder, dayNum) - if redRatio != -1 && absentGoodsOrderRatio >= redRatio { - absentGoodsOrderStoreIDListRed = append(absentGoodsOrderStoreIDListRed, storeID) - } else if yellowRatio != -1 && absentGoodsOrderRatio >= yellowRatio { - absentGoodsOrderStoreIDListYellow = append(absentGoodsOrderStoreIDListYellow, storeID) - } - } + if isOneWeekDay { + count = standardFinishTimeOrderCountSelfDeliveryMapData[storeID] + totalCount = finishOrderCountSelfDeliveryMapData[storeID] + SendAlertInfoWrapper(storeID, storeName, dayNum, AlertTypeStandardFinishTimeOrderSelfDelivery, count, totalCount) - if dayNum == CheckStoreAlertOneWeekDayNum { - standardFinishTimeOrderCountSelfDelivery := standardFinishTimeOrderCountSelfDeliveryMapData[storeID] - finishOrderCountSelfDelivery := finishOrderCountSelfDeliveryMapData[storeID] - if finishOrderCountSelfDelivery > 0 { - standardFinishTimeOrderSelfDeliveryRatio := float64(standardFinishTimeOrderCountSelfDelivery) * 100 / float64(finishOrderCountSelfDelivery) - yellowRatio, redRatio := GetAlertRatio(AlertTypePickTimeOrderSelfDelivery, dayNum) - if redRatio != -1 && standardFinishTimeOrderSelfDeliveryRatio <= redRatio { - - } else if yellowRatio != -1 && standardFinishTimeOrderSelfDeliveryRatio <= yellowRatio { - - } - } - - standardPickUpTimeOrderCountSelfDelivery := standardPickUpTimeOrderCountSelfDeliveryMapData[storeID] - finishOrderCountDaDa := finishOrderCountDaDaMapData[storeID] - if finishOrderCountSelfDelivery > 0 { - standardPickUpTimeOrderSelfDeliveryRatio := float64(standardPickUpTimeOrderCountSelfDelivery) * 100 / float64(finishOrderCountDaDa) - yellowRatio, redRatio := GetAlertRatio(AlertTypePickUpTimeOrderDaDa, dayNum) - if redRatio != -1 && standardPickUpTimeOrderSelfDeliveryRatio <= redRatio { - - } else if yellowRatio != -1 && standardPickUpTimeOrderSelfDeliveryRatio <= yellowRatio { - - } - } + count = standardPickUpTimeOrderCountDaDaMapData[storeID] + totalCount = finishOrderCountDaDaMapData[storeID] + SendAlertInfoWrapper(storeID, storeName, dayNum, AlertTypeStandardPickUpTimeOrderDaDa, count, totalCount) } } - - return retVal, err } -func CheckStoreMonthAlert(storeMapData map[int]*cms.StoreExt) (retVal interface{}, err error) { +func CheckStoreMonthAlert(storeMapData map[int]*cms.StoreExt) { db := dao.GetDB() - storeCountList, err := dao.GetFinishOrderCountByDayNum(db, CheckStoreAlertOneMonthDayNum, true) + storeCountList, _ := dao.GetFinishOrderCountByDayNum(db, CheckStoreAlertOneMonthDayNum, IncludeToday) storeCountMapData := make(map[int]int) for _, value := range storeCountList { storeCountMapData[value.StoreID] = value.Count } - alertStoreIDList := []int{} for _, storeInfo := range storeMapData { storeID := storeInfo.ID + storeName := storeInfo.Name if _, ok := storeCountMapData[storeID]; !ok { - alertStoreIDList = append(alertStoreIDList, storeID) + alertInfo := GetAlertInfo(CheckStoreAlertOneMonthDayNum, true, storeName, -1, -1) + SendAlertInfo(storeID, alertInfo) } } +} - return retVal, err +func CheckStoreRiskOrderAlert(storeMapData map[int]*cms.StoreExt, dayNum int) { + db := dao.GetDB() + storeOrderList, _ := dao.GetRiskOrderCount(db, dayNum, IncludeToday) + storeOrderMapData := ConvertListToMapEx(storeOrderList) + for _, storeInfo := range storeMapData { + storeID := storeInfo.ID + vendorOrderIDList := storeOrderMapData[storeID] + if vendorOrderIDList != nil { + vendorOrderIDStr := "" + for index, vendorOrderID := range vendorOrderIDList { + if index == 0 { + vendorOrderIDStr += vendorOrderID + } else { + vendorOrderIDStr += "," + vendorOrderID + } + } + alertInfo := fmt.Sprintf(RiskOrderAlertInfo, vendorOrderIDStr) + SendAlertInfo(storeID, alertInfo) + } + } +} + +func GetWeekDay() int { + return int(time.Now().Weekday()) } func CheckStoreAlert(ctx *jxcontext.Context) { @@ -242,10 +294,7 @@ func CheckStoreAlert(ctx *jxcontext.Context) { } CheckStoreDayAlert(storeMapData, CheckStoreAlertOneDayNum) CheckStoreDayAlert(storeMapData, CheckStoreAlertOneWeekDayNum) -} - -func GetWeekDay() int { - return int(time.Now().Weekday()) + CheckStoreRiskOrderAlert(storeMapData, CheckStoreAlertOneDayNum) } func ScheduleCheckStoreAlert() { diff --git a/business/model/Store_Alert_Inform.go b/business/model/Store_Alert_Inform.go index 6b799489c..fec0c7089 100644 --- a/business/model/Store_Alert_Inform.go +++ b/business/model/Store_Alert_Inform.go @@ -14,3 +14,8 @@ type StoreOrderStatus struct { StatusTime time.Time `orm:"column(status_time)"` Status int `orm:"column(status)"` } + +type StoreOrder struct { + StoreID int `orm:"column(store_id)"` + VendorOrderID string `orm:"column(vendor_order_id)"` +} \ No newline at end of file diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 4c771ea07..163e33a81 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -435,7 +435,7 @@ func GetFinishOrderCountByWayBillVendorID(db *DaoDB, wayBillVendorID, dayNum int //拣货履约订单量, 仅统计达达专送 func GetStandardPickTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { sql := ` - SELECT jx_store_id store_id, COUNT(*) count + SELECT t1.jx_store_id store_id, COUNT(*) count FROM goods_order t1 JOIN order_status t2 ON t2.vendor_order_id = t1.vendor_order_id where t1.order_finished_at >= ? AND t1.order_finished_at <= ? @@ -444,7 +444,7 @@ func GetStandardPickTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday boo AND t2.order_type = ? AND t2.status = ? AND t2.status_time <= t1.pick_deadline - GROUP BY jx_store_id + GROUP BY t1.jx_store_id ` beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) sqlParams := []interface{}{ @@ -495,7 +495,7 @@ func GetStandardFinishTimeOrderCountBySelfDelivery(db *DaoDB, dayNum int, includ } //10分钟取货完成订单量, 仅统计达达专送 -func GetStandardPickUpTimeOrderCountBySelfDelivery(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { +func GetStandardPickUpTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { sql := ` SELECT t1.jx_store_id store_id, t1.vendor_order_id, t2.status_time, t2.status FROM goods_order t1 @@ -562,3 +562,23 @@ func GetStandardPickUpTimeOrderCountBySelfDelivery(db *DaoDB, dayNum int, includ return storeCountList, err } + +//风控定单(门店相关人员在自己的门店下单) +func GetRiskOrderCount(db *DaoDB, dayNum int, includeToday bool) (storeOrderList []*model.StoreOrder, err error) { + sql := ` + SELECT t1.jx_store_id store_id, t1.vendor_order_id + FROM goods_order t1 + JOIN store t2 ON t2.id = t1.jx_store_id + WHERE t1.order_finished_at >= ? AND t1.order_finished_at <= ? + AND t1.consignee_mobile2 <> "" + AND (t1.consignee_mobile2 = t2.tel1 or t1.consignee_mobile2 = t2.tel2) + GROUP BY t1.jx_store_id + ` + beginTime, endTime := utils.GetTimeRange(utils.GetCurDate(), dayNum, includeToday) + sqlParams := []interface{}{ + beginTime, + endTime, + } + + return storeOrderList, GetRows(db, &storeOrderList, sql, sqlParams) +} From 0c0ac4fd695246b94dcb1e5434e007b49a61607b Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Fri, 27 Sep 2019 17:59:39 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=A7=A6=E7=8A=AF=E7=BA=A2=E7=BA=BF?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 43 ++++++++++++--------- business/model/dao/dao_order.go | 12 +++--- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go index 24d242448..873991463 100644 --- a/business/jxstore/misc/Store_Alert_Inform.go +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -26,8 +26,8 @@ const ( OneDayName = "单日" OneWeekDayName = "七日" OneMonthDayName = "三十日" - YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,可能会被系统下线,请及时补救。" - RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s>=%d%%,会被系统下线,需要马上补救。" + YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%v%%,可能会被系统下线,请及时补救。" + RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%v%%,会被系统下线,需要马上补救。" NoOrderAlertInfo = "您的店铺京西菜市-%s,由于近%s无订单,会被系统下线,需要马上补救。" RiskOrderAlertInfo = "系统检测到您的店铺可能有虚假定单,定单号为:%s,可能会被罚款,请及时与运营联系!" ) @@ -61,25 +61,24 @@ func ConvertListToMapEx(listData []*model.StoreOrder) (mapData map[int][]string) if mapData[value.StoreID] == nil { mapData[value.StoreID] = []string{} } - vendorOrderIDList := mapData[value.StoreID] - vendorOrderIDList = append(vendorOrderIDList, value.VendorOrderID) + mapData[value.StoreID] = append(mapData[value.StoreID], value.VendorOrderID) } return mapData } -func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, ratio float64) (info string) { +func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, logicCondition string, ratio float64) (info string) { if dayNum == CheckStoreAlertOneDayNum { if isRedAlert { - info = fmt.Sprintf(RedAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], ratio) + info = fmt.Sprintf(RedAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], logicCondition, ratio) } else { - info = fmt.Sprintf(YellowAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], ratio) + info = fmt.Sprintf(YellowAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], logicCondition, ratio) } } else if dayNum == CheckStoreAlertOneWeekDayNum { if isRedAlert { - info = fmt.Sprintf(RedAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], ratio) + info = fmt.Sprintf(RedAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], logicCondition, ratio) } else { - info = fmt.Sprintf(YellowAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], ratio) + info = fmt.Sprintf(YellowAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], logicCondition, ratio) } } else if dayNum == CheckStoreAlertOneMonthDayNum { info = fmt.Sprintf(NoOrderAlertInfo, storeName, OneMonthDayName) @@ -88,7 +87,7 @@ func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, return info } -func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAlert, isRedAlert bool) { +func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAlert, isRedAlert bool, logicCondtion string, outRatio float64) { yellowRatio := float64(-1) redRatio := float64(-1) extraCount := -1 @@ -103,7 +102,7 @@ func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAl redRatio = 50 extraCount = 5 } - conditionLessEqual = false + conditionLessEqual = true case AlertTypeBadCommentOrder: if dayNum == CheckStoreAlertOneDayNum { redRatio = 100 @@ -112,7 +111,7 @@ func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAl redRatio = 3 extraCount = 5 } - conditionLessEqual = true + conditionLessEqual = false case AlertTypeAbsentGoodsOrder: if dayNum == CheckStoreAlertOneDayNum { redRatio = 100 @@ -121,36 +120,42 @@ func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAl redRatio = 5 extraCount = 5 } - conditionLessEqual = true + conditionLessEqual = false case AlertTypeStandardFinishTimeOrderSelfDelivery: yellowRatio = 85 redRatio = 70 - conditionLessEqual = false + conditionLessEqual = true case AlertTypeStandardPickUpTimeOrderDaDa: yellowRatio = 85 redRatio = 70 - conditionLessEqual = false + conditionLessEqual = true } if conditionLessEqual { + logicCondtion = "<=" if extraCount != -1 && count >= extraCount { isRedAlert = true } else if redRatio != -1 && ratio <= redRatio { isRedAlert = true + outRatio = redRatio } else if yellowRatio != -1 && ratio <= yellowRatio { isYellowAlert = true + outRatio = yellowRatio } } else { + logicCondtion = ">=" if extraCount != -1 && count >= extraCount { isRedAlert = true } else if redRatio != -1 && ratio >= redRatio { isRedAlert = true + outRatio = redRatio } else if yellowRatio != -1 && ratio >= yellowRatio { isYellowAlert = true + outRatio = yellowRatio } } - return isYellowAlert, isRedAlert + return isYellowAlert, isRedAlert, logicCondtion, outRatio } func SendAlertInfo(storeID int, alertInfo string) { @@ -160,12 +165,12 @@ func SendAlertInfo(storeID int, alertInfo string) { func SendAlertInfoWrapper(storeID int, storeName string, dayNum, alertType, count, totalCount int) { if totalCount > 0 { ratio := float64(count) * 100 / float64(totalCount) - yellowAlert, redAlert := CheckAlert(alertType, dayNum, ratio, count) + yellowAlert, redAlert, logicCondtion, outRatio := CheckAlert(alertType, dayNum, ratio, count) isAlert := false isRedAlert := redAlert isAlert = yellowAlert || redAlert if isAlert { - alertInfo := GetAlertInfo(dayNum, isRedAlert, storeName, alertType, ratio) + alertInfo := GetAlertInfo(dayNum, isRedAlert, storeName, alertType, logicCondtion, outRatio) SendAlertInfo(storeID, alertInfo) } } @@ -251,7 +256,7 @@ func CheckStoreMonthAlert(storeMapData map[int]*cms.StoreExt) { storeID := storeInfo.ID storeName := storeInfo.Name if _, ok := storeCountMapData[storeID]; !ok { - alertInfo := GetAlertInfo(CheckStoreAlertOneMonthDayNum, true, storeName, -1, -1) + alertInfo := GetAlertInfo(CheckStoreAlertOneMonthDayNum, true, storeName, -1, "", -1) SendAlertInfo(storeID, alertInfo) } } diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 163e33a81..d974f86dd 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -462,7 +462,7 @@ func GetStandardPickTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday boo //按时履约订单量, 仅统计商家自送门店 func GetStandardFinishTimeOrderCountBySelfDelivery(db *DaoDB, dayNum int, includeToday bool) (storeCountList []*model.StoreCount, err error) { sql := ` - SELECT jx_store_id store_id, order_created_at orderCreateTime, order_finished_at orderFinishTime + SELECT jx_store_id store_id, order_created_at, order_finished_at FROM goods_order where order_finished_at >= ? AND order_finished_at <= ? AND status = ? @@ -523,11 +523,9 @@ func GetStandardPickUpTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday b if err == nil && len(storeOrderStatusList) > 0 { for _, value := range storeOrderStatusList { if storeOrderTimeMapData[value.StoreID] == nil { - storeOrderTimeSubList := []*model.StoreOrderStatus{} - storeOrderTimeMapData[value.StoreID] = storeOrderTimeSubList + storeOrderTimeMapData[value.StoreID] = []*model.StoreOrderStatus{} } - storeOrderTimeSubList := storeOrderTimeMapData[value.StoreID] - storeOrderTimeSubList = append(storeOrderTimeSubList, value) + storeOrderTimeMapData[value.StoreID] = append(storeOrderTimeMapData[value.StoreID], value) } for storeID, valueList := range storeOrderTimeMapData { count := 0 @@ -556,7 +554,9 @@ func GetStandardPickUpTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday b count++ } } - storeCountList = append(storeCountList, &model.StoreCount{storeID, count}) + if count > 0 { + storeCountList = append(storeCountList, &model.StoreCount{storeID, count}) + } } } From 1ef5d248e89909bc8be61076d3bccfd88c213c94 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Sun, 29 Sep 2019 18:32:55 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E9=97=A8=E5=BA=97=E7=BA=A2=E7=BA=BF/?= =?UTF-8?q?=E9=BB=84=E7=BA=BF=E7=BB=9F=E8=AE=A1-=E5=86=99=E5=85=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 133 +++++++++++++++----- business/jxstore/misc/misc.go | 1 + business/jxutils/weixinmsg/weixinmsg.go | 34 ++++- business/model/Store_Alert_Inform.go | 72 ++++++++++- business/model/dao/Store_Alert_Inform.go | 46 +++++++ controllers/cms_store.go | 26 ++++ controllers/temp_op.go | 7 +- globals/beegodb/beegodb.go | 1 + routers/commentsRouter_controllers.go | 9 ++ 9 files changed, 291 insertions(+), 38 deletions(-) diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go index 873991463..4a7cb1e96 100644 --- a/business/jxstore/misc/Store_Alert_Inform.go +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -2,15 +2,24 @@ package misc import ( "fmt" + "math" + "reflect" "time" + "git.rosy.net.cn/jx-callback/business/jxutils" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/baseapi" "git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" ) const ( + EnableCheckStoreAlert = true + EnableSendStoreAlert = true + IncludeToday = true CheckStoreAlertOneMonthDayNum = 30 CheckStoreAlertOneDayNum = 1 @@ -26,10 +35,10 @@ const ( OneDayName = "单日" OneWeekDayName = "七日" OneMonthDayName = "三十日" - YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%v%%,可能会被系统下线,请及时补救。" - RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%v%%,会被系统下线,需要马上补救。" + YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%d%%,可能会被系统下线,请及时补救。" + RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%d%%,会被系统下线,需要马上补救。" NoOrderAlertInfo = "您的店铺京西菜市-%s,由于近%s无订单,会被系统下线,需要马上补救。" - RiskOrderAlertInfo = "系统检测到您的店铺可能有虚假定单,定单号为:%s,可能会被罚款,请及时与运营联系!" + RiskOrderAlertInfo = "您的店铺京西菜市-%s,可能有虚假定单,定单号为:%s,可能会被罚款,请及时与运营联系!" ) var ( @@ -44,8 +53,40 @@ var ( AlertTypeStandardFinishTimeOrderSelfDelivery: "按时履约率(商家自送)", AlertTypeStandardPickUpTimeOrderDaDa: "10分钟取货完成率(达达)", } + + storeAlertDataWrapper StoreAlertDataWrapper ) +type StoreAlertDataWrapper struct { + storeAlertList map[int]*model.StoreAlert +} + +func (s *StoreAlertDataWrapper) InitData() { + s.storeAlertList = make(map[int]*model.StoreAlert) +} + +func (s *StoreAlertDataWrapper) ClearData() { + s.storeAlertList = nil +} + +func (s *StoreAlertDataWrapper) SetData(storeID int, valueName string, value int) { + data := s.storeAlertList[storeID] + if data == nil { + data = &model.StoreAlert{} + data.StoreID = storeID + data.AlertDate = utils.GetCurDate() + s.storeAlertList[storeID] = data + } + valueInfo := reflect.ValueOf(data).Elem() + valueInfo.FieldByName(valueName).SetInt(int64(value)) +} + +func (s StoreAlertDataWrapper) InsertStoreAlertList() { + for _, value := range s.storeAlertList { + dao.InsertStoreAlert(value) + } +} + func ConvertListToMap(listData []*model.StoreCount) (mapData map[int]int) { mapData = make(map[int]int) for _, value := range listData { @@ -67,7 +108,7 @@ func ConvertListToMapEx(listData []*model.StoreOrder) (mapData map[int][]string) return mapData } -func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, logicCondition string, ratio float64) (info string) { +func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, logicCondition string, ratio int) (info string) { if dayNum == CheckStoreAlertOneDayNum { if isRedAlert { info = fmt.Sprintf(RedAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], logicCondition, ratio) @@ -87,9 +128,9 @@ func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, return info } -func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAlert, isRedAlert bool, logicCondtion string, outRatio float64) { - yellowRatio := float64(-1) - redRatio := float64(-1) +func CheckAlert(alertType int, dayNum int, ratio int, count int) (isYellowAlert, isRedAlert bool, logicCondtion string, outRatio int) { + yellowRatio := -1 + redRatio := -1 extraCount := -1 conditionLessEqual := false @@ -158,25 +199,29 @@ func CheckAlert(alertType int, dayNum int, ratio float64, count int) (isYellowAl return isYellowAlert, isRedAlert, logicCondtion, outRatio } -func SendAlertInfo(storeID int, alertInfo string) { - fmt.Printf("SendAlertInfo:%d %s\n", storeID, alertInfo) +func SendAlertInfo(storeID int, storeName, alertInfo string) { + if EnableSendStoreAlert { + baseapi.SugarLogger.Debugf("SendAlertInfo: %d, %s", storeID, alertInfo) + weixinmsg.NotifyStoreAlertMessage(storeID, storeName, "门店警告", alertInfo) + } } func SendAlertInfoWrapper(storeID int, storeName string, dayNum, alertType, count, totalCount int) { if totalCount > 0 { - ratio := float64(count) * 100 / float64(totalCount) + ratio := int(math.Round(float64(count) * 100 / float64(totalCount))) yellowAlert, redAlert, logicCondtion, outRatio := CheckAlert(alertType, dayNum, ratio, count) isAlert := false isRedAlert := redAlert isAlert = yellowAlert || redAlert if isAlert { alertInfo := GetAlertInfo(dayNum, isRedAlert, storeName, alertType, logicCondtion, outRatio) - SendAlertInfo(storeID, alertInfo) + SendAlertInfo(storeID, storeName, alertInfo) + storeAlertDataWrapper.SetData(storeID, model.FieldRiskOrderCount, ratio) } } } -func CheckStoreDayAlert(storeMapData map[int]*cms.StoreExt, dayNum int) { +func CheckStoreDayAlert(storeList []*cms.StoreExt, dayNum int) { db := dao.GetDB() //拣货履约订单(达达) pickTimeOrderCountDaDaList, _ := dao.GetStandardPickTimeOrderCountByDaDa(db, dayNum, IncludeToday) @@ -219,7 +264,7 @@ func CheckStoreDayAlert(storeMapData map[int]*cms.StoreExt, dayNum int) { standardPickUpTimeOrderCountDaDaMapData = ConvertListToMap(standardPickUpTimeOrderCountDaDaList) } - for _, storeInfo := range storeMapData { + for _, storeInfo := range storeList { storeID := storeInfo.ID storeName := storeInfo.Name count := pickTimeOrderCountDaDaMapData[storeID] @@ -244,7 +289,7 @@ func CheckStoreDayAlert(storeMapData map[int]*cms.StoreExt, dayNum int) { } } -func CheckStoreMonthAlert(storeMapData map[int]*cms.StoreExt) { +func CheckStoreMonthAlert(storeList []*cms.StoreExt) { db := dao.GetDB() storeCountList, _ := dao.GetFinishOrderCountByDayNum(db, CheckStoreAlertOneMonthDayNum, IncludeToday) storeCountMapData := make(map[int]int) @@ -252,22 +297,24 @@ func CheckStoreMonthAlert(storeMapData map[int]*cms.StoreExt) { storeCountMapData[value.StoreID] = value.Count } - for _, storeInfo := range storeMapData { + for _, storeInfo := range storeList { storeID := storeInfo.ID storeName := storeInfo.Name if _, ok := storeCountMapData[storeID]; !ok { alertInfo := GetAlertInfo(CheckStoreAlertOneMonthDayNum, true, storeName, -1, "", -1) - SendAlertInfo(storeID, alertInfo) + SendAlertInfo(storeID, storeName, alertInfo) + storeAlertDataWrapper.SetData(storeID, model.FieldNoOrderInMonth, 1) } } } -func CheckStoreRiskOrderAlert(storeMapData map[int]*cms.StoreExt, dayNum int) { +func CheckStoreRiskOrderAlert(storeList []*cms.StoreExt, dayNum int) { db := dao.GetDB() storeOrderList, _ := dao.GetRiskOrderCount(db, dayNum, IncludeToday) storeOrderMapData := ConvertListToMapEx(storeOrderList) - for _, storeInfo := range storeMapData { + for _, storeInfo := range storeList { storeID := storeInfo.ID + storeName := storeInfo.Name vendorOrderIDList := storeOrderMapData[storeID] if vendorOrderIDList != nil { vendorOrderIDStr := "" @@ -278,8 +325,9 @@ func CheckStoreRiskOrderAlert(storeMapData map[int]*cms.StoreExt, dayNum int) { vendorOrderIDStr += "," + vendorOrderID } } - alertInfo := fmt.Sprintf(RiskOrderAlertInfo, vendorOrderIDStr) - SendAlertInfo(storeID, alertInfo) + alertInfo := fmt.Sprintf(RiskOrderAlertInfo, storeName, vendorOrderIDStr) + SendAlertInfo(storeID, storeName, alertInfo) + storeAlertDataWrapper.SetData(storeID, model.FieldRiskOrderCount, len(vendorOrderIDList)) } } } @@ -288,22 +336,43 @@ func GetWeekDay() int { return int(time.Now().Weekday()) } -func CheckStoreAlert(ctx *jxcontext.Context) { +func CheckStoreAlert(ctx *jxcontext.Context, storeIDList []int) { + storeAlertDataWrapper.InitData() storeList, _ := GetStoreList(ctx) - storeMapData := make(map[int]*cms.StoreExt) - for _, value := range storeList { - storeMapData[value.ID] = value - } + storeIDMap := jxutils.IntList2Map(storeIDList) + storeList = GetFilterStoreListEx(storeList, storeIDMap) if GetWeekDay() == MonthCheckOnWeekDay { - CheckStoreMonthAlert(storeMapData) + CheckStoreMonthAlert(storeList) } - CheckStoreDayAlert(storeMapData, CheckStoreAlertOneDayNum) - CheckStoreDayAlert(storeMapData, CheckStoreAlertOneWeekDayNum) - CheckStoreRiskOrderAlert(storeMapData, CheckStoreAlertOneDayNum) + CheckStoreDayAlert(storeList, CheckStoreAlertOneDayNum) + CheckStoreDayAlert(storeList, CheckStoreAlertOneWeekDayNum) + CheckStoreRiskOrderAlert(storeList, CheckStoreAlertOneDayNum) + storeAlertDataWrapper.InsertStoreAlertList() + storeAlertDataWrapper.ClearData() } func ScheduleCheckStoreAlert() { - ScheduleTimerFunc("ScheduleCheckStoreAlert", func() { - CheckStoreAlert(jxcontext.AdminCtx) - }, checkStoreAlertTimeList) + if EnableCheckStoreAlert { + ScheduleTimerFunc("ScheduleCheckStoreAlert", func() { + CheckStoreAlert(jxcontext.AdminCtx, nil) + }, checkStoreAlertTimeList) + } +} + +func GetStoreAlertList(storeIDList []int, cityCode int, keyWord string, beginTime, endTime time.Time, offset, pageSize int) (storeAlertData model.StoreAlertData, err error) { + db := dao.GetDB() + storeAlertList, err := dao.GetStoreAlertList(db, storeIDList, cityCode, keyWord, beginTime, endTime) + if err == nil && len(storeAlertList) > 0 { + offset = jxutils.FormalizePageOffset(offset) + pageSize = jxutils.FormalizePageSize(pageSize) + var pagedStoreAlertList []*model.StoreAlertEx + for i := offset; i < offset+pageSize && i < len(storeAlertList); i++ { + pagedStoreAlertList = append(pagedStoreAlertList, storeAlertList[i]) + } + + storeAlertData.TotalCount = len(storeAlertList) + storeAlertData.StoreAlertList = pagedStoreAlertList + } + + return storeAlertData, err } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 8703031a1..2a2dc9a0a 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -105,6 +105,7 @@ func Init() { dao.UpdateActStatusByTime(dao.GetDB(), time.Now().Add(-48*time.Hour)) }, updateActStatusTimeList) ScheduleScoreStore() + ScheduleCheckStoreAlert() } ScheduleTimerFunc("AutoSaleStoreSku", func() { cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false) diff --git a/business/jxutils/weixinmsg/weixinmsg.go b/business/jxutils/weixinmsg/weixinmsg.go index b8a25c888..80f97c637 100644 --- a/business/jxutils/weixinmsg/weixinmsg.go +++ b/business/jxutils/weixinmsg/weixinmsg.go @@ -64,6 +64,8 @@ const ( WX_AFS_ORDER_STATUS_CHANGED_TEMPLATE_ID = "99T33rrXX0VboO1hljs4x8dDoLiSj3QX_rOikPHIXkg" WS_NOTIFY_STORE_STATUS_CHHANGED_TEMPLATE_ID = "Fl0vOnBKTQqRFx3-shGKxdCnxMdQXNeODzgkuwd7oxw" + + WX_STORE_ALERT_TEMPLATE_ID = "0AjzVl1wPl6iO4nFOS4IEsJYSzBymlT37DciIvcCOxE" ) var ( @@ -83,6 +85,7 @@ var ( debugOpenIDMap = map[string]int{ "oYN_usk0AeGc_C6VEZfmFQP5VHMQ": 1, // 周小扬 "oYN_ust9hXKEvEv0X6Mq6nlAWs_E": 1, // me + "oYN_usqnpGVQ4xxlao_yybsbYJh4": 1, // 朱丹 } ) @@ -144,7 +147,7 @@ func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) { func SendMsgToStore(storeID int, templateID, downloadURL, miniPageURL string, data interface{}) (err error) { globals.SugarLogger.Debugf("SendMsgToStore storeID:%d, templateID:%s, downloadURL:%s, miniPageURL:%s", storeID, templateID, downloadURL, miniPageURL) if storeID == 0 { // 测试,只发给我 - // SmartMessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", templateID, downloadURL, miniPageURL, data) + //SmartMessageTemplateSend("oYN_usk0AeGc_C6VEZfmFQP5VHMQ", templateID, downloadURL, miniPageURL, data) } else { openIDs := GetWeixinOpenIDsFromStoreID(storeID) successCount := 0 @@ -637,3 +640,32 @@ func NotifyStoreStatusChanged(openUserID, title, content string) (err error) { }) return err } + +func NotifyStoreAlertMessage(storeID int, storeName, title, content string) (err error) { + globals.SugarLogger.Debugf("NotifyStoreAlertMessage storeID:%d, storeName:%d, title:%s, content:%s", storeID, storeName, title, content) + templateID := WX_STORE_ALERT_TEMPLATE_ID + msgID, msgStatusID := -1, -1 + fileURL := globals.WxBackstageHost + fmt.Sprintf(WX_TO_SHOW_MSG, msgID, msgStatusID) + data := map[string]interface{}{ + "first": map[string]interface{}{ + "value": "", + "color": "#333333", + }, + "keyword1": map[string]interface{}{ + "value": storeName, + "color": "#2E408E", + }, + "keyword2": map[string]interface{}{ + "value": utils.GetCurTimeStr(), + "color": "#2E408E", + }, + "keyword3": map[string]interface{}{ + "value": content, + "color": "#2E408E", + }, + "remark": map[string]interface{}{ + "value": "", + }, + } + return SendMsgToStore(storeID, templateID, fileURL, fmt.Sprintf(WX_MINI_TO_SHOW_MSG, msgID, msgStatusID), data) +} diff --git a/business/model/Store_Alert_Inform.go b/business/model/Store_Alert_Inform.go index fec0c7089..ccd4cafd4 100644 --- a/business/model/Store_Alert_Inform.go +++ b/business/model/Store_Alert_Inform.go @@ -2,6 +2,72 @@ package model import "time" +const ( + FieldPickTimeDaDa = "PickTimeDaDa" + FieldBadComment = "BadComment" + FieldAbsentGoods = "AbsentGoods" + FieldPickTimeDaDaOneWeek = "PickTimeDaDaOneWeek" + FieldBadCommentOneWeek = "BadCommentOneWeek" + FieldAbsentGoodsOneWeek = "AbsentGoodsOneWeek" + FieldStandardFinishTimeSelfDelivery = "StandardFinishTimeSelfDelivery" + FieldStandardPickUpTimeDaDa = "StandardPickUpTimeDaDa" + FieldNoOrderInMonth = "NoOrderInMonth" + FieldRiskOrderCount = "RiskOrderCount" +) + +type StoreAlert struct { + ID int `orm:"column(id)" json:"id"` + CreatedTime time.Time `orm:"auto_now_add;type(datetime)" json:"createdTime"` + AlertDate time.Time `orm:"auto_now_add;type(datetime)" json:"alertDate"` + StoreID int `orm:"column(store_id)" json:"storeID"` + + PickTimeDaDa int `orm:"column(pick_time_order_dada)" json:"pickTimeDaDa"` + BadComment int `orm:"column(bad_comment)" json:"badComment"` + AbsentGoods int `orm:"column(absent_goods)" json:"absentGoods"` + PickTimeDaDaOneWeek int `orm:"column(pick_time_dada_oneweek)" json:"pickTimeDaDaOneWeek"` + BadCommentOneWeek int `orm:"column(bad_comment_oneweek)" json:"badCommentOneWeek"` + AbsentGoodsOneWeek int `orm:"column(absent_goods_oneweek)" json:"absentGoodsOneWeek"` + StandardFinishTimeSelfDelivery int `orm:"column(standard_finish_time_selfdelivery)" json:"standardFinishTimeSelfDelivery"` + StandardPickUpTimeDaDa int `orm:"column(standard_pickup_time_dada)" json:"standardPickUpTimeDaDa"` + + NoOrderInMonth int `json:"noOrderInMonth"` + RiskOrderCount int `json:"riskOrderCount"` +} + +type StoreAlertEx struct { + StoreAlert + StoreName string `json:"storeName"` +} + +type StoreAlertProperty struct { + Value string `json:"value"` + Color string `json:"color"` +} + +type StoreAlertAdvanced struct { + ID int `json:"id"` + CreatedTime time.Time `json:"createdTime"` + AlertDate time.Time `json:"alertDate"` + StoreID int `json:"storeID"` + + PickTimeDaDa StoreAlertProperty + BadComment StoreAlertProperty + AbsentGoods StoreAlertProperty + PickTimeDaDaOneWeek StoreAlertProperty + BadCommentOneWeek StoreAlertProperty + AbsentGoodsOneWeek StoreAlertProperty + StandardFinishTimeSelfDelivery StoreAlertProperty + StandardPickUpTimeDaDa StoreAlertProperty + + NoOrderInMonth StoreAlertProperty + RiskOrderCount StoreAlertProperty +} + +type StoreAlertData struct { + StoreAlertList []*StoreAlertEx `json:"storeAlertList"` + TotalCount int `json:"totalCount"` +} + type StoreOrderTime struct { StoreID int `orm:"column(store_id)"` OrderCreateTime time.Time `orm:"column(order_created_at)"` @@ -16,6 +82,6 @@ type StoreOrderStatus struct { } type StoreOrder struct { - StoreID int `orm:"column(store_id)"` - VendorOrderID string `orm:"column(vendor_order_id)"` -} \ No newline at end of file + StoreID int `orm:"column(store_id)"` + VendorOrderID string `orm:"column(vendor_order_id)"` +} diff --git a/business/model/dao/Store_Alert_Inform.go b/business/model/dao/Store_Alert_Inform.go index 35b7c14c7..0dd3f5526 100644 --- a/business/model/dao/Store_Alert_Inform.go +++ b/business/model/dao/Store_Alert_Inform.go @@ -1,3 +1,49 @@ package dao +import ( + "fmt" + "time" + "git.rosy.net.cn/jx-callback/business/model" +) + +func InsertStoreAlert(storeAlert *model.StoreAlert) error { + storeAlert.CreatedTime = time.Now() + return CreateEntity(nil, storeAlert) +} + +func GetStoreAlertList(db *DaoDB, storeIDList []int, cityCode int, keyWord string, beginTime, endTime time.Time) (storeAlertList []*model.StoreAlertEx, err error) { + sql := ` + SELECT t1.* + FROM store_alert t1 + JOIN store t2 ON t1.store_id = t2.id + JOIN place t3 ON t2.city_code = t3.code + WHERE DATE(t1.alert_date) >= DATE(?) AND DATE(t1.alert_date) <= DATE(?) + ` + sqlParams := []interface{}{ + beginTime, + endTime, + } + if len(storeIDList) > 0 { + sql += ` + AND t2.id in (` + GenQuestionMarks(len(storeIDList)) + `)` + sqlParams = append(sqlParams, storeIDList) + } + if cityCode > 0 { + sql += ` + AND t3.code = ?` + sqlParams = append(sqlParams, cityCode) + } + if keyWord != "" { + sql += ` + AND (t2.id LIKE ? OR t2.name LIKE ? OR t3.name LIKE ?)` + keyWord = fmt.Sprintf("%%%s%%", keyWord) + sqlParams = append(sqlParams, keyWord, keyWord, keyWord) + } + sql += ` + ORDER BY t1.store_id + ` + err = GetRows(db, &storeAlertList, sql, sqlParams) + + return storeAlertList, err +} diff --git a/controllers/cms_store.go b/controllers/cms_store.go index baa99e1aa..af62ada0d 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -485,3 +485,29 @@ func (c *StoreController) GetStoreTotalScoreList() { return retVal, "", err }) } + +// @Title 得到门店触犯红线/黄线数据 +// @Description 得到门店触犯红线/黄线数据 +// @Param token header string true "认证token" +// @Param storeIDs formData string false "京西门店ID列表" +// @Param cityCode formData int false "城市编码" +// @Param keyword formData string false "关键字" +// @Param beginTime formData string true "开始日期" +// @Param endTime formData string true "结束日期" +// @Param offset formData int false "列表起始序号(以0开始,缺省为0)" +// @Param pageSize formData int false "列表页大小(缺省为50,-1表示全部)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetStoreAlertList [post] +func (c *StoreController) GetStoreAlertList() { + c.callGetStoreAlertList(func(params *tStoreGetStoreAlertListParams) (retVal interface{}, errCode string, err error) { + timeList, err := jxutils.BatchStr2Time(params.BeginTime, params.EndTime) + if err == nil { + var storeIDList []int + if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { + retVal, err = misc.GetStoreAlertList(storeIDList, params.CityCode, params.Keyword, timeList[0], timeList[1], params.Offset, params.PageSize) + } + } + return retVal, "", err + }) +} diff --git a/controllers/temp_op.go b/controllers/temp_op.go index 4acb1cc3f..f27734b67 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -320,13 +320,16 @@ func (c *TempOpController) CreateConsumerFromOrders() { // @Title 触犯红线通知 // @Description 触犯红线通知 // @Param token header string true "认证token" +// @Param storeIDs formData string false "门店列表" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /CheckStoreAlert [post] func (c *TempOpController) CheckStoreAlert() { c.callCheckStoreAlert(func(params *tTempopCheckStoreAlertParams) (retVal interface{}, errCode string, err error) { - misc.CheckStoreAlert(params.Ctx) - + var storeIDs []int + if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil { + misc.CheckStoreAlert(params.Ctx, storeIDs) + } return retVal, "", err }) } diff --git a/globals/beegodb/beegodb.go b/globals/beegodb/beegodb.go index 2c0e11aca..eded1d8e9 100644 --- a/globals/beegodb/beegodb.go +++ b/globals/beegodb/beegodb.go @@ -55,6 +55,7 @@ func Init() { orm.RegisterModel(&model.CasbinRule{}) orm.RegisterModel(&model.SensitiveWord{}) orm.RegisterModel(&model.StoreScore{}) + orm.RegisterModel(&model.StoreAlert{}) orm.RegisterModel(&model.FoodRecipe{}, &model.FoodRecipeStep{}, &model.FoodRecipeItem{}, &model.FoodRecipeItemChoice{}, &model.FoodRecipeUser{}) orm.RegisterModel(&model.DataResource{}) diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 439d0a4ae..3b125721f 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1242,6 +1242,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], + beego.ControllerComments{ + Method: "GetStoreAlertList", + Router: `/GetStoreAlertList`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], beego.ControllerComments{ Method: "GetStoreCourierMaps", From ec6565992f1b6fa0ca759d573e00e30b82568b53 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Mon, 30 Sep 2019 10:45:29 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E9=97=A8=E5=BA=97=E7=BA=A2=E7=BA=BF-?= =?UTF-8?q?=E5=86=99=E5=85=A5=E5=92=8C=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 113 ++++++++++++++++++-- business/model/Store_Alert_Inform.go | 9 +- business/model/dao/Store_Alert_Inform.go | 9 +- controllers/cms_store.go | 7 +- 4 files changed, 120 insertions(+), 18 deletions(-) diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go index 4a7cb1e96..950e7ab54 100644 --- a/business/jxstore/misc/Store_Alert_Inform.go +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -6,10 +6,10 @@ import ( "reflect" "time" - "git.rosy.net.cn/jx-callback/business/jxutils" - "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi" + "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/jxutils/weixinmsg" "git.rosy.net.cn/jx-callback/business/model" @@ -32,6 +32,10 @@ const ( AlertTypeStandardFinishTimeOrderSelfDelivery = 3 AlertTypeStandardPickUpTimeOrderDaDa = 4 + ColorRed = "red" + ColorYellow = "yellow" + ColorUnknown = "Unknown" + OneDayName = "单日" OneWeekDayName = "七日" OneMonthDayName = "三十日" @@ -206,6 +210,35 @@ func SendAlertInfo(storeID int, storeName, alertInfo string) { } } +func GetFieldNameByAlertType(alertType, dayNum int) (fieldName string) { + switch alertType { + case AlertTypePickTimeOrderDaDa: + if dayNum == CheckStoreAlertOneDayNum { + fieldName = model.FieldPickTimeDaDa + } else if dayNum == CheckStoreAlertOneWeekDayNum { + fieldName = model.FieldPickTimeDaDaOneWeek + } + case AlertTypeBadCommentOrder: + if dayNum == CheckStoreAlertOneDayNum { + fieldName = model.FieldBadComment + } else if dayNum == CheckStoreAlertOneWeekDayNum { + fieldName = model.FieldBadCommentOneWeek + } + case AlertTypeAbsentGoodsOrder: + if dayNum == CheckStoreAlertOneDayNum { + fieldName = model.FieldAbsentGoods + } else if dayNum == CheckStoreAlertOneWeekDayNum { + fieldName = model.FieldAbsentGoodsOneWeek + } + case AlertTypeStandardFinishTimeOrderSelfDelivery: + fieldName = model.FieldStandardFinishTimeSelfDelivery + case AlertTypeStandardPickUpTimeOrderDaDa: + fieldName = model.FieldStandardPickUpTimeDaDa + } + + return fieldName +} + func SendAlertInfoWrapper(storeID int, storeName string, dayNum, alertType, count, totalCount int) { if totalCount > 0 { ratio := int(math.Round(float64(count) * 100 / float64(totalCount))) @@ -216,7 +249,8 @@ func SendAlertInfoWrapper(storeID int, storeName string, dayNum, alertType, coun if isAlert { alertInfo := GetAlertInfo(dayNum, isRedAlert, storeName, alertType, logicCondtion, outRatio) SendAlertInfo(storeID, storeName, alertInfo) - storeAlertDataWrapper.SetData(storeID, model.FieldRiskOrderCount, ratio) + fieldName := GetFieldNameByAlertType(alertType, dayNum) + storeAlertDataWrapper.SetData(storeID, fieldName, ratio) } } } @@ -359,9 +393,22 @@ func ScheduleCheckStoreAlert() { } } -func GetStoreAlertList(storeIDList []int, cityCode int, keyWord string, beginTime, endTime time.Time, offset, pageSize int) (storeAlertData model.StoreAlertData, err error) { +func GetValueColor(alertType, dayNum, ratio, count int) (color string) { + yellowAlert, redAlert, _, _ := CheckAlert(alertType, dayNum, ratio, count) + if yellowAlert { + color = ColorYellow + } else if redAlert { + color = ColorRed + } else { + color = ColorUnknown + } + + return color +} + +func GetStoreAlertList(storeIDList []int, cityCode int, keyWord string, dateTime time.Time, offset, pageSize int) (storeAlertData model.StoreAlertData, err error) { db := dao.GetDB() - storeAlertList, err := dao.GetStoreAlertList(db, storeIDList, cityCode, keyWord, beginTime, endTime) + storeAlertList, err := dao.GetStoreAlertList(db, storeIDList, cityCode, keyWord, dateTime) if err == nil && len(storeAlertList) > 0 { offset = jxutils.FormalizePageOffset(offset) pageSize = jxutils.FormalizePageSize(pageSize) @@ -370,8 +417,62 @@ func GetStoreAlertList(storeIDList []int, cityCode int, keyWord string, beginTim pagedStoreAlertList = append(pagedStoreAlertList, storeAlertList[i]) } + var storeAlertAdvancedList []*model.StoreAlertAdvanced + for _, value := range pagedStoreAlertList { + storeAlertAdvanced := &model.StoreAlertAdvanced{} + storeAlertAdvanced.ID = value.ID + storeAlertAdvanced.CreatedTime = value.CreatedTime + storeAlertAdvanced.AlertDate = value.AlertDate + storeAlertAdvanced.StoreID = value.StoreID + storeAlertAdvanced.StoreName = value.StoreName + storeAlertAdvanced.CityName = value.CityName + + storeAlertAdvanced.PickTimeDaDa.Value = fmt.Sprintf("%d%%", value.PickTimeDaDa) + storeAlertAdvanced.PickTimeDaDa.Color = GetValueColor(AlertTypePickTimeOrderDaDa, CheckStoreAlertOneDayNum, value.PickTimeDaDa, -1) + + storeAlertAdvanced.BadComment.Value = fmt.Sprintf("%d%%", value.BadComment) + storeAlertAdvanced.BadComment.Color = GetValueColor(AlertTypeBadCommentOrder, CheckStoreAlertOneDayNum, value.BadComment, -1) + + storeAlertAdvanced.AbsentGoods.Value = fmt.Sprintf("%d%%", value.AbsentGoods) + storeAlertAdvanced.AbsentGoods.Color = GetValueColor(AlertTypeAbsentGoodsOrder, CheckStoreAlertOneDayNum, value.AbsentGoods, -1) + + storeAlertAdvanced.PickTimeDaDaOneWeek.Value = fmt.Sprintf("%d%%", value.PickTimeDaDaOneWeek) + storeAlertAdvanced.PickTimeDaDaOneWeek.Color = GetValueColor(AlertTypePickTimeOrderDaDa, CheckStoreAlertOneWeekDayNum, value.PickTimeDaDaOneWeek, -1) + + storeAlertAdvanced.BadCommentOneWeek.Value = fmt.Sprintf("%d%%", value.BadCommentOneWeek) + storeAlertAdvanced.BadCommentOneWeek.Color = GetValueColor(AlertTypeBadCommentOrder, CheckStoreAlertOneWeekDayNum, value.BadCommentOneWeek, -1) + + storeAlertAdvanced.AbsentGoodsOneWeek.Value = fmt.Sprintf("%d%%", value.AbsentGoodsOneWeek) + storeAlertAdvanced.AbsentGoodsOneWeek.Color = GetValueColor(AlertTypeAbsentGoodsOrder, CheckStoreAlertOneWeekDayNum, value.AbsentGoodsOneWeek, -1) + + storeAlertAdvanced.StandardFinishTimeSelfDelivery.Value = fmt.Sprintf("%d%%", value.StandardFinishTimeSelfDelivery) + storeAlertAdvanced.StandardFinishTimeSelfDelivery.Color = GetValueColor(AlertTypeStandardFinishTimeOrderSelfDelivery, CheckStoreAlertOneWeekDayNum, value.StandardFinishTimeSelfDelivery, -1) + + storeAlertAdvanced.StandardPickUpTimeDaDa.Value = fmt.Sprintf("%d%%", value.StandardPickUpTimeDaDa) + storeAlertAdvanced.StandardPickUpTimeDaDa.Color = GetValueColor(AlertTypeStandardPickUpTimeOrderDaDa, CheckStoreAlertOneWeekDayNum, value.StandardPickUpTimeDaDa, -1) + + storeAlertAdvanced.StandardPickUpTimeDaDa.Value = fmt.Sprintf("%d%%", value.StandardPickUpTimeDaDa) + storeAlertAdvanced.StandardPickUpTimeDaDa.Color = GetValueColor(AlertTypeStandardPickUpTimeOrderDaDa, CheckStoreAlertOneWeekDayNum, value.StandardPickUpTimeDaDa, -1) + + if value.NoOrderInMonth == 1 { + storeAlertAdvanced.NoOrderInMonth.Value = "是" + storeAlertAdvanced.NoOrderInMonth.Color = ColorRed + } else { + storeAlertAdvanced.NoOrderInMonth.Value = "否" + storeAlertAdvanced.NoOrderInMonth.Color = ColorUnknown + } + + storeAlertAdvanced.RiskOrderCount.Value = utils.Int2Str(value.RiskOrderCount) + if value.RiskOrderCount > 0 { + storeAlertAdvanced.RiskOrderCount.Color = ColorRed + } else { + storeAlertAdvanced.RiskOrderCount.Color = ColorUnknown + } + + storeAlertAdvancedList = append(storeAlertAdvancedList, storeAlertAdvanced) + } storeAlertData.TotalCount = len(storeAlertList) - storeAlertData.StoreAlertList = pagedStoreAlertList + storeAlertData.StoreAlertList = storeAlertAdvancedList } return storeAlertData, err diff --git a/business/model/Store_Alert_Inform.go b/business/model/Store_Alert_Inform.go index ccd4cafd4..7af87259a 100644 --- a/business/model/Store_Alert_Inform.go +++ b/business/model/Store_Alert_Inform.go @@ -36,7 +36,8 @@ type StoreAlert struct { type StoreAlertEx struct { StoreAlert - StoreName string `json:"storeName"` + StoreName string `orm:"column(store_name)" json:"storeName"` + CityName string `orm:"column(city_name)" json:"cityName"` } type StoreAlertProperty struct { @@ -49,6 +50,8 @@ type StoreAlertAdvanced struct { CreatedTime time.Time `json:"createdTime"` AlertDate time.Time `json:"alertDate"` StoreID int `json:"storeID"` + StoreName string `json:"storeName"` + CityName string `json:"cityName"` PickTimeDaDa StoreAlertProperty BadComment StoreAlertProperty @@ -64,8 +67,8 @@ type StoreAlertAdvanced struct { } type StoreAlertData struct { - StoreAlertList []*StoreAlertEx `json:"storeAlertList"` - TotalCount int `json:"totalCount"` + StoreAlertList []*StoreAlertAdvanced `json:"storeAlertList"` + TotalCount int `json:"totalCount"` } type StoreOrderTime struct { diff --git a/business/model/dao/Store_Alert_Inform.go b/business/model/dao/Store_Alert_Inform.go index 0dd3f5526..cd7bcbf8e 100644 --- a/business/model/dao/Store_Alert_Inform.go +++ b/business/model/dao/Store_Alert_Inform.go @@ -12,17 +12,16 @@ func InsertStoreAlert(storeAlert *model.StoreAlert) error { return CreateEntity(nil, storeAlert) } -func GetStoreAlertList(db *DaoDB, storeIDList []int, cityCode int, keyWord string, beginTime, endTime time.Time) (storeAlertList []*model.StoreAlertEx, err error) { +func GetStoreAlertList(db *DaoDB, storeIDList []int, cityCode int, keyWord string, dateTime time.Time) (storeAlertList []*model.StoreAlertEx, err error) { sql := ` - SELECT t1.* + SELECT t1.*, t2.name store_name, t3.name city_name FROM store_alert t1 JOIN store t2 ON t1.store_id = t2.id JOIN place t3 ON t2.city_code = t3.code - WHERE DATE(t1.alert_date) >= DATE(?) AND DATE(t1.alert_date) <= DATE(?) + WHERE DATE(t1.alert_date) = DATE(?) ` sqlParams := []interface{}{ - beginTime, - endTime, + dateTime, } if len(storeIDList) > 0 { sql += ` diff --git a/controllers/cms_store.go b/controllers/cms_store.go index af62ada0d..a2213ca1e 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -492,8 +492,7 @@ func (c *StoreController) GetStoreTotalScoreList() { // @Param storeIDs formData string false "京西门店ID列表" // @Param cityCode formData int false "城市编码" // @Param keyword formData string false "关键字" -// @Param beginTime formData string true "开始日期" -// @Param endTime formData string true "结束日期" +// @Param dateTime formData string true "统计日期" // @Param offset formData int false "列表起始序号(以0开始,缺省为0)" // @Param pageSize formData int false "列表页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult @@ -501,11 +500,11 @@ func (c *StoreController) GetStoreTotalScoreList() { // @router /GetStoreAlertList [post] func (c *StoreController) GetStoreAlertList() { c.callGetStoreAlertList(func(params *tStoreGetStoreAlertListParams) (retVal interface{}, errCode string, err error) { - timeList, err := jxutils.BatchStr2Time(params.BeginTime, params.EndTime) + timeList, err := jxutils.BatchStr2Time(params.DateTime) if err == nil { var storeIDList []int if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { - retVal, err = misc.GetStoreAlertList(storeIDList, params.CityCode, params.Keyword, timeList[0], timeList[1], params.Offset, params.PageSize) + retVal, err = misc.GetStoreAlertList(storeIDList, params.CityCode, params.Keyword, timeList[0], params.Offset, params.PageSize) } } return retVal, "", err From 0079a04817df67e96ed57c4662566c2a20005e54 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Mon, 30 Sep 2019 18:55:46 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 146 ++++++++++++-------- business/model/Store_Alert_Inform.go | 26 +++- 2 files changed, 113 insertions(+), 59 deletions(-) diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go index 950e7ab54..4ba8e882f 100644 --- a/business/jxstore/misc/Store_Alert_Inform.go +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -3,7 +3,6 @@ package misc import ( "fmt" "math" - "reflect" "time" "git.rosy.net.cn/baseapi" @@ -14,6 +13,7 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg" "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 ( @@ -36,11 +36,16 @@ const ( ColorYellow = "yellow" ColorUnknown = "Unknown" + AlertLevelExtraRed = 1 + AlertLevelRed = 2 + AlertLevelYellow = 3 + OneDayName = "单日" OneWeekDayName = "七日" OneMonthDayName = "三十日" YellowAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%d%%,可能会被系统下线,请及时补救。" RedAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%d%%,会被系统下线,需要马上补救。" + ExtraRedAlertInfo = "您的店铺京西菜市-%s,由于%s%s%s%d%%,会被系统下线,需要马上补救。" NoOrderAlertInfo = "您的店铺京西菜市-%s,由于近%s无订单,会被系统下线,需要马上补救。" RiskOrderAlertInfo = "您的店铺京西菜市-%s,可能有虚假定单,定单号为:%s,可能会被罚款,请及时与运营联系!" ) @@ -58,6 +63,12 @@ var ( AlertTypeStandardPickUpTimeOrderDaDa: "10分钟取货完成率(达达)", } + AlertTypeExtraNameMap = map[int]string{ + AlertTypePickTimeOrderDaDa: "拣货超时订单(达达)", + AlertTypeBadCommentOrder: "差评订单", + AlertTypeAbsentGoodsOrder: "缺货订单", + } + storeAlertDataWrapper StoreAlertDataWrapper ) @@ -73,6 +84,10 @@ func (s *StoreAlertDataWrapper) ClearData() { s.storeAlertList = nil } +func (s *StoreAlertDataWrapper) IsStatusField(valueName string) bool { + return valueName == model.FieldYellowStatus || valueName == model.FieldRedStatus || valueName == model.FieldExtraRedStatus +} + func (s *StoreAlertDataWrapper) SetData(storeID int, valueName string, value int) { data := s.storeAlertList[storeID] if data == nil { @@ -81,8 +96,13 @@ func (s *StoreAlertDataWrapper) SetData(storeID int, valueName string, value int data.AlertDate = utils.GetCurDate() s.storeAlertList[storeID] = data } - valueInfo := reflect.ValueOf(data).Elem() - valueInfo.FieldByName(valueName).SetInt(int64(value)) + // valueInfo := reflect.ValueOf(data).Elem() + // valueInfo.FieldByName(valueName).SetInt(int64(value)) + if s.IsStatusField(valueName) { + srcFieldValue := refutil.GetObjFieldByName(data, valueName).(int) + value |= srcFieldValue + } + refutil.SetObjFieldByName(data, valueName, value) } func (s StoreAlertDataWrapper) InsertStoreAlertList() { @@ -112,18 +132,22 @@ func ConvertListToMapEx(listData []*model.StoreOrder) (mapData map[int][]string) return mapData } -func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, logicCondition string, ratio int) (info string) { +func GetAlertInfo(dayNum, alertLevel int, storeName string, alertType int, logicCondition string, value int) (info string) { if dayNum == CheckStoreAlertOneDayNum { - if isRedAlert { - info = fmt.Sprintf(RedAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], logicCondition, ratio) - } else { - info = fmt.Sprintf(YellowAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], logicCondition, ratio) + if alertLevel == AlertLevelExtraRed { + info = fmt.Sprintf(ExtraRedAlertInfo, storeName, OneDayName, AlertTypeExtraNameMap[alertType], logicCondition, value) + } else if alertLevel == AlertLevelRed { + info = fmt.Sprintf(RedAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], logicCondition, value) + } else if alertLevel == AlertLevelYellow { + info = fmt.Sprintf(YellowAlertInfo, storeName, OneDayName, AlertTypeNameMap[alertType], logicCondition, value) } } else if dayNum == CheckStoreAlertOneWeekDayNum { - if isRedAlert { - info = fmt.Sprintf(RedAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], logicCondition, ratio) - } else { - info = fmt.Sprintf(YellowAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], logicCondition, ratio) + if alertLevel == AlertLevelExtraRed { + info = fmt.Sprintf(ExtraRedAlertInfo, storeName, OneWeekDayName, AlertTypeExtraNameMap[alertType], logicCondition, value) + } else if alertLevel == AlertLevelRed { + info = fmt.Sprintf(RedAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], logicCondition, value) + } else if alertLevel == AlertLevelYellow { + info = fmt.Sprintf(YellowAlertInfo, storeName, OneWeekDayName, AlertTypeNameMap[alertType], logicCondition, value) } } else if dayNum == CheckStoreAlertOneMonthDayNum { info = fmt.Sprintf(NoOrderAlertInfo, storeName, OneMonthDayName) @@ -132,7 +156,7 @@ func GetAlertInfo(dayNum int, isRedAlert bool, storeName string, alertType int, return info } -func CheckAlert(alertType int, dayNum int, ratio int, count int) (isYellowAlert, isRedAlert bool, logicCondtion string, outRatio int) { +func CheckAlert(alertType int, dayNum int, ratio int, count int) (alertLevel int, logicCondtion string, outValue int) { yellowRatio := -1 redRatio := -1 extraCount := -1 @@ -179,28 +203,30 @@ func CheckAlert(alertType int, dayNum int, ratio int, count int) (isYellowAlert, if conditionLessEqual { logicCondtion = "<=" if extraCount != -1 && count >= extraCount { - isRedAlert = true + alertLevel = AlertLevelExtraRed + outValue = extraCount } else if redRatio != -1 && ratio <= redRatio { - isRedAlert = true - outRatio = redRatio + alertLevel = AlertLevelRed + outValue = redRatio } else if yellowRatio != -1 && ratio <= yellowRatio { - isYellowAlert = true - outRatio = yellowRatio + alertLevel = AlertLevelYellow + outValue = yellowRatio } } else { logicCondtion = ">=" if extraCount != -1 && count >= extraCount { - isRedAlert = true + alertLevel = AlertLevelExtraRed + outValue = extraCount } else if redRatio != -1 && ratio >= redRatio { - isRedAlert = true - outRatio = redRatio + alertLevel = AlertLevelRed + outValue = redRatio } else if yellowRatio != -1 && ratio >= yellowRatio { - isYellowAlert = true - outRatio = yellowRatio + alertLevel = AlertLevelYellow + outValue = yellowRatio } } - return isYellowAlert, isRedAlert, logicCondtion, outRatio + return alertLevel, logicCondtion, outValue } func SendAlertInfo(storeID int, storeName, alertInfo string) { @@ -210,47 +236,60 @@ func SendAlertInfo(storeID int, storeName, alertInfo string) { } } -func GetFieldNameByAlertType(alertType, dayNum int) (fieldName string) { +func GetFieldNameByAlertType(alertType, dayNum int) (fieldName string, fieldFlag int) { switch alertType { case AlertTypePickTimeOrderDaDa: if dayNum == CheckStoreAlertOneDayNum { fieldName = model.FieldPickTimeDaDa + fieldFlag = model.FlagPickTimeDaDa } else if dayNum == CheckStoreAlertOneWeekDayNum { fieldName = model.FieldPickTimeDaDaOneWeek + fieldFlag = model.FlagPickTimeDaDaOneWeek } case AlertTypeBadCommentOrder: if dayNum == CheckStoreAlertOneDayNum { fieldName = model.FieldBadComment + fieldFlag = model.FlagBadComment } else if dayNum == CheckStoreAlertOneWeekDayNum { fieldName = model.FieldBadCommentOneWeek + fieldFlag = model.FlagBadCommentOneWeek } case AlertTypeAbsentGoodsOrder: if dayNum == CheckStoreAlertOneDayNum { fieldName = model.FieldAbsentGoods + fieldFlag = model.FlagAbsentGoods } else if dayNum == CheckStoreAlertOneWeekDayNum { fieldName = model.FieldAbsentGoodsOneWeek + fieldFlag = model.FlagAbsentGoodsOneWeek } case AlertTypeStandardFinishTimeOrderSelfDelivery: fieldName = model.FieldStandardFinishTimeSelfDelivery + fieldFlag = model.FlagStandardFinishTimeSelfDelivery case AlertTypeStandardPickUpTimeOrderDaDa: fieldName = model.FieldStandardPickUpTimeDaDa + fieldFlag = model.FlagStandardPickUpTimeDaDa } - return fieldName + return fieldName, fieldFlag } func SendAlertInfoWrapper(storeID int, storeName string, dayNum, alertType, count, totalCount int) { if totalCount > 0 { ratio := int(math.Round(float64(count) * 100 / float64(totalCount))) - yellowAlert, redAlert, logicCondtion, outRatio := CheckAlert(alertType, dayNum, ratio, count) - isAlert := false - isRedAlert := redAlert - isAlert = yellowAlert || redAlert - if isAlert { - alertInfo := GetAlertInfo(dayNum, isRedAlert, storeName, alertType, logicCondtion, outRatio) + alertLevel, logicCondtion, outValue := CheckAlert(alertType, dayNum, ratio, count) + if alertLevel != 0 { + alertInfo := GetAlertInfo(dayNum, alertLevel, storeName, alertType, logicCondtion, outValue) SendAlertInfo(storeID, storeName, alertInfo) - fieldName := GetFieldNameByAlertType(alertType, dayNum) + fieldName, fieldFlag := GetFieldNameByAlertType(alertType, dayNum) storeAlertDataWrapper.SetData(storeID, fieldName, ratio) + + if alertLevel == AlertLevelExtraRed { + storeAlertDataWrapper.SetData(storeID, model.FieldExtraRedStatus, fieldFlag) + } else if alertLevel == AlertLevelRed { + storeAlertDataWrapper.SetData(storeID, model.FieldRedStatus, fieldFlag) + } else if alertLevel == AlertLevelYellow { + storeAlertDataWrapper.SetData(storeID, model.FieldYellowStatus, fieldFlag) + } } } } @@ -335,9 +374,10 @@ func CheckStoreMonthAlert(storeList []*cms.StoreExt) { storeID := storeInfo.ID storeName := storeInfo.Name if _, ok := storeCountMapData[storeID]; !ok { - alertInfo := GetAlertInfo(CheckStoreAlertOneMonthDayNum, true, storeName, -1, "", -1) + alertInfo := GetAlertInfo(CheckStoreAlertOneMonthDayNum, AlertLevelRed, storeName, -1, "", -1) SendAlertInfo(storeID, storeName, alertInfo) storeAlertDataWrapper.SetData(storeID, model.FieldNoOrderInMonth, 1) + storeAlertDataWrapper.SetData(storeID, model.FieldRedStatus, model.FlagNoOrderInMonth) } } } @@ -362,6 +402,7 @@ func CheckStoreRiskOrderAlert(storeList []*cms.StoreExt, dayNum int) { alertInfo := fmt.Sprintf(RiskOrderAlertInfo, storeName, vendorOrderIDStr) SendAlertInfo(storeID, storeName, alertInfo) storeAlertDataWrapper.SetData(storeID, model.FieldRiskOrderCount, len(vendorOrderIDList)) + storeAlertDataWrapper.SetData(storeID, model.FieldRedStatus, model.FlagRiskOrderCount) } } } @@ -393,12 +434,11 @@ func ScheduleCheckStoreAlert() { } } -func GetValueColor(alertType, dayNum, ratio, count int) (color string) { - yellowAlert, redAlert, _, _ := CheckAlert(alertType, dayNum, ratio, count) - if yellowAlert { - color = ColorYellow - } else if redAlert { +func GetValueColorByStatus(extraRedStatus, redStatus, yellowStatus, flag int) (color string) { + if (extraRedStatus&flag != 0) || (redStatus&flag != 0) { color = ColorRed + } else if yellowStatus&flag != 0 { + color = ColorYellow } else { color = ColorUnknown } @@ -428,46 +468,38 @@ func GetStoreAlertList(storeIDList []int, cityCode int, keyWord string, dateTime storeAlertAdvanced.CityName = value.CityName storeAlertAdvanced.PickTimeDaDa.Value = fmt.Sprintf("%d%%", value.PickTimeDaDa) - storeAlertAdvanced.PickTimeDaDa.Color = GetValueColor(AlertTypePickTimeOrderDaDa, CheckStoreAlertOneDayNum, value.PickTimeDaDa, -1) + storeAlertAdvanced.PickTimeDaDa.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagPickTimeDaDa) storeAlertAdvanced.BadComment.Value = fmt.Sprintf("%d%%", value.BadComment) - storeAlertAdvanced.BadComment.Color = GetValueColor(AlertTypeBadCommentOrder, CheckStoreAlertOneDayNum, value.BadComment, -1) + storeAlertAdvanced.BadComment.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagBadComment) storeAlertAdvanced.AbsentGoods.Value = fmt.Sprintf("%d%%", value.AbsentGoods) - storeAlertAdvanced.AbsentGoods.Color = GetValueColor(AlertTypeAbsentGoodsOrder, CheckStoreAlertOneDayNum, value.AbsentGoods, -1) + storeAlertAdvanced.AbsentGoods.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagAbsentGoods) storeAlertAdvanced.PickTimeDaDaOneWeek.Value = fmt.Sprintf("%d%%", value.PickTimeDaDaOneWeek) - storeAlertAdvanced.PickTimeDaDaOneWeek.Color = GetValueColor(AlertTypePickTimeOrderDaDa, CheckStoreAlertOneWeekDayNum, value.PickTimeDaDaOneWeek, -1) + storeAlertAdvanced.PickTimeDaDaOneWeek.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagPickTimeDaDaOneWeek) storeAlertAdvanced.BadCommentOneWeek.Value = fmt.Sprintf("%d%%", value.BadCommentOneWeek) - storeAlertAdvanced.BadCommentOneWeek.Color = GetValueColor(AlertTypeBadCommentOrder, CheckStoreAlertOneWeekDayNum, value.BadCommentOneWeek, -1) + storeAlertAdvanced.BadCommentOneWeek.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagBadCommentOneWeek) storeAlertAdvanced.AbsentGoodsOneWeek.Value = fmt.Sprintf("%d%%", value.AbsentGoodsOneWeek) - storeAlertAdvanced.AbsentGoodsOneWeek.Color = GetValueColor(AlertTypeAbsentGoodsOrder, CheckStoreAlertOneWeekDayNum, value.AbsentGoodsOneWeek, -1) + storeAlertAdvanced.AbsentGoodsOneWeek.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagAbsentGoodsOneWeek) storeAlertAdvanced.StandardFinishTimeSelfDelivery.Value = fmt.Sprintf("%d%%", value.StandardFinishTimeSelfDelivery) - storeAlertAdvanced.StandardFinishTimeSelfDelivery.Color = GetValueColor(AlertTypeStandardFinishTimeOrderSelfDelivery, CheckStoreAlertOneWeekDayNum, value.StandardFinishTimeSelfDelivery, -1) + storeAlertAdvanced.StandardFinishTimeSelfDelivery.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagStandardFinishTimeSelfDelivery) storeAlertAdvanced.StandardPickUpTimeDaDa.Value = fmt.Sprintf("%d%%", value.StandardPickUpTimeDaDa) - storeAlertAdvanced.StandardPickUpTimeDaDa.Color = GetValueColor(AlertTypeStandardPickUpTimeOrderDaDa, CheckStoreAlertOneWeekDayNum, value.StandardPickUpTimeDaDa, -1) - - storeAlertAdvanced.StandardPickUpTimeDaDa.Value = fmt.Sprintf("%d%%", value.StandardPickUpTimeDaDa) - storeAlertAdvanced.StandardPickUpTimeDaDa.Color = GetValueColor(AlertTypeStandardPickUpTimeOrderDaDa, CheckStoreAlertOneWeekDayNum, value.StandardPickUpTimeDaDa, -1) + storeAlertAdvanced.StandardPickUpTimeDaDa.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagStandardPickUpTimeDaDa) if value.NoOrderInMonth == 1 { storeAlertAdvanced.NoOrderInMonth.Value = "是" - storeAlertAdvanced.NoOrderInMonth.Color = ColorRed } else { storeAlertAdvanced.NoOrderInMonth.Value = "否" - storeAlertAdvanced.NoOrderInMonth.Color = ColorUnknown } + storeAlertAdvanced.NoOrderInMonth.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagNoOrderInMonth) storeAlertAdvanced.RiskOrderCount.Value = utils.Int2Str(value.RiskOrderCount) - if value.RiskOrderCount > 0 { - storeAlertAdvanced.RiskOrderCount.Color = ColorRed - } else { - storeAlertAdvanced.RiskOrderCount.Color = ColorUnknown - } + storeAlertAdvanced.RiskOrderCount.Color = GetValueColorByStatus(value.ExtraRedStatus, value.RedStatus, value.YellowStatus, model.FlagRiskOrderCount) storeAlertAdvancedList = append(storeAlertAdvancedList, storeAlertAdvanced) } diff --git a/business/model/Store_Alert_Inform.go b/business/model/Store_Alert_Inform.go index 7af87259a..bc9701edd 100644 --- a/business/model/Store_Alert_Inform.go +++ b/business/model/Store_Alert_Inform.go @@ -11,8 +11,26 @@ const ( FieldAbsentGoodsOneWeek = "AbsentGoodsOneWeek" FieldStandardFinishTimeSelfDelivery = "StandardFinishTimeSelfDelivery" FieldStandardPickUpTimeDaDa = "StandardPickUpTimeDaDa" - FieldNoOrderInMonth = "NoOrderInMonth" - FieldRiskOrderCount = "RiskOrderCount" + + FieldNoOrderInMonth = "NoOrderInMonth" + FieldRiskOrderCount = "RiskOrderCount" + + FieldYellowStatus = "YellowStatus" + FieldRedStatus = "RedStatus" + FieldExtraRedStatus = "ExtraRedStatus" +) + +const ( + FlagPickTimeDaDa = 1 + FlagBadComment = 2 + FlagAbsentGoods = 4 + FlagPickTimeDaDaOneWeek = 8 + FlagBadCommentOneWeek = 16 + FlagAbsentGoodsOneWeek = 32 + FlagStandardFinishTimeSelfDelivery = 64 + FlagStandardPickUpTimeDaDa = 128 + FlagNoOrderInMonth = 256 + FlagRiskOrderCount = 512 ) type StoreAlert struct { @@ -32,6 +50,10 @@ type StoreAlert struct { NoOrderInMonth int `json:"noOrderInMonth"` RiskOrderCount int `json:"riskOrderCount"` + + YellowStatus int + RedStatus int + ExtraRedStatus int } type StoreAlertEx struct { From 83349188fcf064e917ded7779897fa9b3465f1c1 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Wed, 9 Oct 2019 09:50:47 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go index 4ba8e882f..300afd605 100644 --- a/business/jxstore/misc/Store_Alert_Inform.go +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -34,7 +34,7 @@ const ( ColorRed = "red" ColorYellow = "yellow" - ColorUnknown = "Unknown" + ColorUnknown = "unknown" AlertLevelExtraRed = 1 AlertLevelRed = 2 From 1c5c0bbbcc4f7e8dfabdb24a451ec6f20ecf0086 Mon Sep 17 00:00:00 2001 From: Rosy-zhudan Date: Thu, 10 Oct 2019 09:42:41 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=8D=E9=A6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/misc/Store_Alert_Inform.go | 2 -- business/jxutils/weixinmsg/weixinmsg.go | 4 +--- business/model/dao/Store_Alert_Inform.go | 7 +++++-- business/model/dao/dao_order.go | 10 +++++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/business/jxstore/misc/Store_Alert_Inform.go b/business/jxstore/misc/Store_Alert_Inform.go index 300afd605..524e6d178 100644 --- a/business/jxstore/misc/Store_Alert_Inform.go +++ b/business/jxstore/misc/Store_Alert_Inform.go @@ -96,8 +96,6 @@ func (s *StoreAlertDataWrapper) SetData(storeID int, valueName string, value int data.AlertDate = utils.GetCurDate() s.storeAlertList[storeID] = data } - // valueInfo := reflect.ValueOf(data).Elem() - // valueInfo.FieldByName(valueName).SetInt(int64(value)) if s.IsStatusField(valueName) { srcFieldValue := refutil.GetObjFieldByName(data, valueName).(int) value |= srcFieldValue diff --git a/business/jxutils/weixinmsg/weixinmsg.go b/business/jxutils/weixinmsg/weixinmsg.go index f6dfcc353..a47fd3d2d 100644 --- a/business/jxutils/weixinmsg/weixinmsg.go +++ b/business/jxutils/weixinmsg/weixinmsg.go @@ -644,8 +644,6 @@ func NotifyStoreStatusChanged(openUserID, title, content string) (err error) { func NotifyStoreAlertMessage(storeID int, storeName, title, content string) (err error) { globals.SugarLogger.Debugf("NotifyStoreAlertMessage storeID:%d, storeName:%d, title:%s, content:%s", storeID, storeName, title, content) templateID := WX_STORE_ALERT_TEMPLATE_ID - msgID, msgStatusID := -1, -1 - fileURL := globals.WxBackstageHost + fmt.Sprintf(WX_TO_SHOW_MSG, msgID, msgStatusID) data := map[string]interface{}{ "first": map[string]interface{}{ "value": "", @@ -667,5 +665,5 @@ func NotifyStoreAlertMessage(storeID int, storeName, title, content string) (err "value": "", }, } - return SendMsgToStore(storeID, templateID, fileURL, fmt.Sprintf(WX_MINI_TO_SHOW_MSG, msgID, msgStatusID), data) + return SendMsgToStore(storeID, templateID, "", "", data) } diff --git a/business/model/dao/Store_Alert_Inform.go b/business/model/dao/Store_Alert_Inform.go index cd7bcbf8e..690ccc464 100644 --- a/business/model/dao/Store_Alert_Inform.go +++ b/business/model/dao/Store_Alert_Inform.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" ) @@ -18,10 +19,12 @@ func GetStoreAlertList(db *DaoDB, storeIDList []int, cityCode int, keyWord strin FROM store_alert t1 JOIN store t2 ON t1.store_id = t2.id JOIN place t3 ON t2.city_code = t3.code - WHERE DATE(t1.alert_date) = DATE(?) + WHERE t1.alert_date >= ? AND t1.alert_date <= ? ` + beginTime, endTime := utils.GetTimeRange(dateTime, 1, true) sqlParams := []interface{}{ - dateTime, + beginTime, + endTime, } if len(storeIDList) > 0 { sql += ` diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index a8b22cdbb..5933c8406 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -444,8 +444,8 @@ func GetStandardPickTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday boo sql := ` SELECT t1.jx_store_id store_id, COUNT(*) count FROM goods_order t1 - JOIN order_status t2 ON t2.vendor_order_id = t1.vendor_order_id - where t1.order_finished_at >= ? AND t1.order_finished_at <= ? + JOIN order_status t2 ON t1.vendor_order_id = t2.vendor_order_id AND t1.vendor_id = t2.vendor_id + WHERE t1.order_finished_at >= ? AND t1.order_finished_at <= ? AND t1.status = ? AND t1.waybill_vendor_id = ? AND t2.order_type = ? @@ -471,7 +471,7 @@ func GetStandardFinishTimeOrderCountBySelfDelivery(db *DaoDB, dayNum int, includ sql := ` SELECT jx_store_id store_id, order_created_at, order_finished_at FROM goods_order - where order_finished_at >= ? AND order_finished_at <= ? + WHERE order_finished_at >= ? AND order_finished_at <= ? AND status = ? AND waybill_vendor_id = ? ` @@ -506,8 +506,8 @@ func GetStandardPickUpTimeOrderCountByDaDa(db *DaoDB, dayNum int, includeToday b sql := ` SELECT t1.jx_store_id store_id, t1.vendor_order_id, t2.status_time, t2.status FROM goods_order t1 - JOIN order_status t2 ON t2.vendor_order_id = t1.vendor_order_id - where t1.order_finished_at >= ? AND t1.order_finished_at <= ? + JOIN order_status t2 ON t1.vendor_order_id = t2.vendor_order_id AND t1.vendor_id = t2.vendor_id + WHERE t1.order_finished_at >= ? AND t1.order_finished_at <= ? AND t1.status = ? AND t1.waybill_vendor_id = ? AND t2.status in (?, ?)