印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

1 year ago
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)
// 增加总订单数
client.Incr(ctx, totalKey)
// 如果订单成功,增加成功订单数
if isSuccess {
client.Incr(ctx, successKey)
}
// 设置过期时间为10分钟
client.Expire(ctx, totalKey, 10*time.Minute)
client.Expire(ctx, successKey, 10*time.Minute)
}
// 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
}
}