Compare commits
No commits in common. 'eef18c22d392ec329cc07f3d19b1fe173a936637' and '89adb1779f1e80b3b9348d5d9c7994a791b3b78d' have entirely different histories.
eef18c22d3
...
89adb1779f
11 changed files with 77 additions and 171 deletions
@ -1,60 +0,0 @@ |
|||||||
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, 10*time.Minute) |
|
||||||
} |
|
||||||
if client.Exists(ctx, successKey).Val() == 0 { |
|
||||||
client.Set(ctx, successKey, 0, 10*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 |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue