Initial commit
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
package agentSer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stat/api/proto"
|
||||
"stat/models/appInfoMod"
|
||||
"stat/models/channelmod"
|
||||
)
|
||||
|
||||
func EnsureRangeInt64(value, min, max int64) int64 {
|
||||
if value < min {
|
||||
value = min
|
||||
}
|
||||
if value > max {
|
||||
value = max
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func InRangeInt64(value, min, max int64) bool {
|
||||
if value < min {
|
||||
return false
|
||||
}
|
||||
if value > max {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func MinInt64(x, y int64) int64 {
|
||||
if x < y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
func MaxInt64(x, y int64) int64 {
|
||||
if x > y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
func GetPageRange(totalLen, pageNum, pageSize int) (start, end int) {
|
||||
if pageNum < 1 {
|
||||
pageNum = 1
|
||||
}
|
||||
if pageSize < 1 {
|
||||
pageSize = 10
|
||||
}
|
||||
start = (pageNum - 1) * pageSize
|
||||
if start > totalLen {
|
||||
start = totalLen
|
||||
}
|
||||
end = start + pageSize
|
||||
if end > totalLen {
|
||||
end = totalLen
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c ChannelMap) GetChannelNames() []string {
|
||||
lst := make([]string, 0)
|
||||
for _, v := range c {
|
||||
lst = append(lst, v.Channel)
|
||||
}
|
||||
return lst
|
||||
}
|
||||
|
||||
func (c ChannelMap) GetChildChannels(channel string) []*channelmod.ChannelInfo {
|
||||
lst := make([]*channelmod.ChannelInfo, 0)
|
||||
for _, v := range c {
|
||||
if v.ParentAgent == channel {
|
||||
lst = append(lst, v)
|
||||
}
|
||||
}
|
||||
return lst
|
||||
}
|
||||
|
||||
func (c ChannelMap) GetParentChannels(channel string) []*channelmod.ChannelInfo {
|
||||
lst := make([]*channelmod.ChannelInfo, 0)
|
||||
self := c[channel]
|
||||
if self == nil {
|
||||
return lst
|
||||
}
|
||||
parent := c[self.ParentAgent]
|
||||
for parent != nil {
|
||||
lst = append(lst, parent)
|
||||
parent = c[parent.ParentAgent]
|
||||
}
|
||||
return lst
|
||||
}
|
||||
|
||||
func (c ChannelMap) GetLockStatusAndShowDivide(channelInfo *channelmod.ChannelInfo) (bool, bool, bool) {
|
||||
parents := c.GetParentChannels(channelInfo.Channel)
|
||||
parentShowDivide := true
|
||||
status := channelInfo.Status
|
||||
lock := channelInfo.Lock
|
||||
for _, parent := range parents {
|
||||
parentShowDivide = parentShowDivide && parent.ChildShowDivideRate
|
||||
status = status && parent.Status
|
||||
if parent.Lock {
|
||||
lock = true
|
||||
}
|
||||
}
|
||||
return lock, status, parentShowDivide && channelInfo.ChildShowDivideRate
|
||||
}
|
||||
|
||||
func (c ChannelMap) GetAncestorAndOffspringChannels(channel string) []*channelmod.ChannelInfo {
|
||||
out := make([]*channelmod.ChannelInfo, 0)
|
||||
cInfo := c[channel]
|
||||
if cInfo == nil {
|
||||
return out
|
||||
}
|
||||
children := c.GetChildChannels(cInfo.Channel)
|
||||
for len(children) > 0 {
|
||||
tmp := make([]*channelmod.ChannelInfo, 0)
|
||||
for _, child := range children {
|
||||
out = append(out, child)
|
||||
tmp = append(tmp, c.GetChildChannels(child.Channel)...)
|
||||
}
|
||||
children = tmp
|
||||
}
|
||||
for cInfo != nil {
|
||||
out = append(out, cInfo)
|
||||
if cInfo.ParentAgent != "" {
|
||||
cInfo = c[cInfo.ParentAgent]
|
||||
} else {
|
||||
cInfo = nil
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func GetAppMap(ctx context.Context) (AppMap, error) {
|
||||
appList, err := appInfoMod.GetAllAppInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
appMap := make(AppMap)
|
||||
for _, app := range appList {
|
||||
tmp := app
|
||||
appMap[app.AppId] = &tmp
|
||||
}
|
||||
return appMap, nil
|
||||
}
|
||||
|
||||
func (m AppMap) GetAppName(id int32) string {
|
||||
if app, ok := m[id]; ok {
|
||||
return app.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func AccumulateAgentChannelStat(base, stat *AgentChannelStat, ruleData bool) {
|
||||
channelmod.ChannelStatSummation(&base.ChannelStat, &stat.ChannelStat)
|
||||
base.Settlement = stat.Settlement
|
||||
base.ChildValidPayMoney += stat.ChildValidPayMoney
|
||||
base.ChildValidDirectCount += stat.ChildValidDirectCount
|
||||
AccumulateDeductedStat(base.DeductedStat, stat.DeductedStat, ruleData)
|
||||
for _, child := range stat.ChildChannelStats {
|
||||
base.DeductedStat.ChildRebate += child.DeductedStat.Income
|
||||
}
|
||||
}
|
||||
|
||||
func AccumulateDeductedStat(base, stat *proto.AgentDeductedStat, ruleData bool) {
|
||||
base.VisitCount += stat.VisitCount
|
||||
if !ruleData || (ruleData && stat.Settlement == channelmod.SettlementCPA) || (stat.Settlement == channelmod.SettlementCPS && CPS_SHOW_COUNT) {
|
||||
base.DirectCount += stat.DirectCount
|
||||
base.DirectCountChild += stat.DirectCountChild
|
||||
base.DirectCountSelf += stat.DirectCountSelf
|
||||
}
|
||||
if !ruleData || (ruleData && stat.Settlement == channelmod.SettlementCPS) || (stat.Settlement == channelmod.SettlementCPA && CPA_SHOW_MONEY) {
|
||||
base.Recharge += stat.Recharge
|
||||
base.RechargeChild += stat.RechargeChild
|
||||
base.RechargeSelf += stat.RechargeSelf
|
||||
}
|
||||
base.Income += stat.Income
|
||||
base.IncomeChild += stat.IncomeChild
|
||||
base.IncomeSelf += stat.IncomeSelf
|
||||
}
|
||||
|
||||
func AccumulateStatData(base *proto.StatDataDetail, stat *proto.AgentDeductedStat, ruleData bool) {
|
||||
base.ChildRebate += stat.ChildRebate
|
||||
base.VisitCount += stat.VisitCount
|
||||
if !ruleData || (ruleData && stat.Settlement == channelmod.SettlementCPA) || (stat.Settlement == channelmod.SettlementCPS && CPS_SHOW_COUNT) {
|
||||
base.DirectCount += stat.DirectCount
|
||||
base.DirectCountSelf += stat.DirectCountSelf
|
||||
base.DirectCountChild += stat.DirectCountChild
|
||||
}
|
||||
if !ruleData || (ruleData && stat.Settlement == channelmod.SettlementCPS) || (stat.Settlement == channelmod.SettlementCPA && CPA_SHOW_MONEY) {
|
||||
base.Recharge += stat.Recharge
|
||||
base.RechargeSelf += stat.RechargeSelf
|
||||
base.RechargeChild += stat.RechargeChild
|
||||
}
|
||||
base.Income += stat.Income
|
||||
base.IncomeSelf += stat.IncomeSelf
|
||||
base.IncomeChild += stat.IncomeChild
|
||||
}
|
||||
Reference in New Issue
Block a user