parent
89adb1779f
commit
d51ee18677
7 changed files with 119 additions and 67 deletions
@ -0,0 +1,55 @@ |
|||||||
|
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 |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue