package statutils import ( "stat/common/utils" "stat/models/channelmod" "strings" ) type DeviceCategory struct { Android bool Ios bool Light bool H5 bool H5Android bool H5Ios bool H5Pc bool } type SourceCategory struct { Web bool // 是否官网 Normal bool // 是否自来 District bool // 是否渠道 Share bool // 是否分享 } type OtherCategory struct { Direct bool // 是否直推 Deduction bool // 是否扣量 Natural bool // 是否自然 Formal bool // H5正式用户 } type ClientInfo struct { //------设备------ DeviceCategory //------来源------ SourceCategory //------其他------ OtherCategory } func IsClientH5OrLight(devs ...string) bool { for _, name := range devs { dev := strings.ToLower(strings.TrimSpace(name)) if dev == string(DeviceNameLight) || dev == string(DeviceNameH5) || dev == string(DeviceNameH5Android) || dev == string(DeviceNameH5Ios) || dev == string(DeviceNameH5Pc) { return true } } return false } func IsClientH5(devs ...string) bool { for _, name := range devs { dev := strings.ToLower(strings.TrimSpace(name)) if dev == string(DeviceNameH5) || dev == string(DeviceNameH5Android) || dev == string(DeviceNameH5Ios) || dev == string(DeviceNameH5Pc) { return true } } return false } func IsClientPkg(devs ...string) bool { for _, name := range devs { dev := strings.ToLower(strings.TrimSpace(name)) if dev == string(DeviceNameIos) || dev == string(DeviceNameAndroid) { return true } } return false } func IsClientLight(devs ...string) bool { for _, name := range devs { dev := strings.ToLower(strings.TrimSpace(name)) if dev == string(DeviceNameLight) { return true } } return false } func IsClientAndroid(devs ...string) bool { for _, name := range devs { dev := strings.ToLower(strings.TrimSpace(name)) if dev == string(DeviceNameAndroid) { return true } } return false } func IsClientIos(devs ...string) bool { for _, name := range devs { dev := strings.ToLower(strings.TrimSpace(name)) if dev == string(DeviceNameIos) { return true } } return false } func GetDeviceInfo(dev1, dev2 string) DeviceCategory { ret := DeviceCategory{} ret.Android = utils.TowIsOR(dev1, dev2, string(DeviceNameAndroid)) if !ret.Android { ret.Ios = utils.TowIsOR(dev1, dev2, string(DeviceNameIos)) if !ret.Ios { ret.Light = utils.TowIsOR(dev1, dev2, string(DeviceNameLight)) if !ret.Light { ret.H5 = true ret.H5Android = utils.TowIsOR(dev1, dev2, string(DeviceNameH5Android)) if !ret.H5Android { ret.H5Ios = utils.TowIsOR(dev1, dev2, string(DeviceNameH5Ios)) if !ret.H5Ios { ret.H5Pc = true } } } } } return ret } func GetClientInfo(dev1, dev2 string, districtCode string, isDirect bool, isDeduction bool, isFormal bool) *ClientInfo { ret := &ClientInfo{ DeviceCategory: GetDeviceInfo(dev1, dev2), } isOfficial := channelmod.IsOfficialChannelOrEmpty(districtCode) if districtCode == "modelweb" { ret.Web = true } else if districtCode == "h5share" { ret.Share = true } else if isOfficial || !isDirect { ret.Normal = true } else { ret.District = true } ret.Direct = isDirect if isDirect && isOfficial { ret.Natural = true } ret.Deduction = isDeduction ret.Formal = isFormal return ret }