59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package reportser
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"91jd-server/common/dataReport"
|
|
"91jd-server/common/db"
|
|
"91jd-server/middleware/ua"
|
|
"91jd-server/models/v/usermod"
|
|
)
|
|
|
|
const (
|
|
LoginTypeDeviceID = "deviceid"
|
|
LoginTypePhone = "phone"
|
|
LoginTypeEmail = "email"
|
|
LoginTypeAccount = "username"
|
|
)
|
|
|
|
func ReportUserLogin(t *db.MongoTool, user *usermod.User, ua ua.UA, ip string, loginType string) error {
|
|
if user == nil {
|
|
return nil
|
|
}
|
|
if loginType == "" {
|
|
loginType = LoginTypeDeviceID
|
|
}
|
|
createTime := time.Now().Unix()
|
|
eventID := newEventId(dataReport.ReportAppId(), user.UID, "", createTime)
|
|
event := dataReport.NewCommonField(eventID, dataReport.EventTypeUserLogin, user.UID, user.DistrictCode, ua, ip)
|
|
event.Payload = jsonRawMessage(&dataReport.UserLoginEvent{
|
|
Type: loginType,
|
|
})
|
|
return persistEvent(t, event)
|
|
}
|
|
|
|
func LoginTypeEventValue(loginType int) string {
|
|
switch loginType {
|
|
case usermod.MobileLogin:
|
|
return LoginTypePhone
|
|
case usermod.DevIDLogin, usermod.TokenLogin, usermod.QrCodeLogin:
|
|
return LoginTypeDeviceID
|
|
default:
|
|
return LoginTypeDeviceID
|
|
}
|
|
}
|
|
|
|
func LoginTypeFromH5(p usermod.LoginWithH5) string {
|
|
switch {
|
|
case strings.TrimSpace(p.Mobile) != "":
|
|
return LoginTypePhone
|
|
case strings.TrimSpace(p.Email) != "":
|
|
return LoginTypeEmail
|
|
case strings.TrimSpace(p.Account) != "":
|
|
return LoginTypeAccount
|
|
default:
|
|
return LoginTypeDeviceID
|
|
}
|
|
}
|