init: hgmj server initial commit
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user