|
|
|
|
package call
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"server/db"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// AddChannel 添加渠道
|
|
|
|
|
func AddChannel(channelID int, isSuccess bool) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
client := db.Redis().GetRedis()
|
|
|
|
|
|
|
|
|
|
totalKey := fmt.Sprintf("channel_total_%v", channelID)
|
|
|
|
|
successKey := fmt.Sprintf("channel_success_%v", channelID)
|
|
|
|
|
|
|
|
|
|
// 检查键是否存在,如果不存在则设置过期时间
|
|
|
|
|
if client.Exists(ctx, totalKey).Val() == 0 {
|
|
|
|
|
client.Set(ctx, totalKey, 0, 30*time.Minute)
|
|
|
|
|
}
|
|
|
|
|
if client.Exists(ctx, successKey).Val() == 0 {
|
|
|
|
|
client.Set(ctx, successKey, 0, 30*time.Minute)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加总订单数
|
|
|
|
|
client.Incr(ctx, totalKey)
|
|
|
|
|
|
|
|
|
|
// 如果订单成功,增加成功订单数
|
|
|
|
|
if isSuccess {
|
|
|
|
|
client.Incr(ctx, successKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetChannelStatus 获取渠道状态
|
|
|
|
|
func GetChannelStatus(channelID int) int {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
client := db.Redis().GetRedis()
|
|
|
|
|
|
|
|
|
|
totalKey := fmt.Sprintf("channel_total_%v", channelID)
|
|
|
|
|
successKey := fmt.Sprintf("channel_success_%v", channelID)
|
|
|
|
|
|
|
|
|
|
totalOrders, _ := client.Get(ctx, totalKey).Int64()
|
|
|
|
|
successOrders, _ := client.Get(ctx, successKey).Int64()
|
|
|
|
|
|
|
|
|
|
// 如果总订单数小于10,状态为绿色
|
|
|
|
|
if totalOrders < 10 {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据成功订单数判断渠道状态
|
|
|
|
|
if successOrders >= 5 {
|
|
|
|
|
return 1
|
|
|
|
|
} else if successOrders >= 3 {
|
|
|
|
|
return 2
|
|
|
|
|
} else {
|
|
|
|
|
return 3
|
|
|
|
|
}
|
|
|
|
|
}
|