gengxin
This commit is contained in:
@@ -16,44 +16,91 @@ type ApiCursorEquipmentController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// cursorIpInfo 对应 ip-api.com 返回的 JSON 结构
|
||||
type cursorIpInfo struct {
|
||||
Status string `json:"status"`
|
||||
Country string `json:"country"`
|
||||
CountryCode string `json:"countryCode"`
|
||||
Region string `json:"region"`
|
||||
RegionName string `json:"regionName"`
|
||||
City string `json:"city"`
|
||||
Zip string `json:"zip"`
|
||||
Lat float64 `json:"lat"`
|
||||
Lon float64 `json:"lon"`
|
||||
Timezone string `json:"timezone"`
|
||||
ISP string `json:"isp"`
|
||||
Org string `json:"org"`
|
||||
As string `json:"as"`
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
type cursorEquipmentReportPayload struct {
|
||||
DeviceInfo string `json:"deviceInfo"`
|
||||
DeviceInfoSnake string `json:"device_info"`
|
||||
MachineCode string `json:"machineCode"`
|
||||
MachineCodeSnake string `json:"machine_code"`
|
||||
Status *int8 `json:"status"`
|
||||
System string `json:"system"`
|
||||
Version string `json:"version"`
|
||||
BindAccount string `json:"bindAccount"`
|
||||
BindAccountSnake string `json:"bind_account"`
|
||||
OwnerUserID *uint64 `json:"ownerUserId"`
|
||||
OwnerUserIDSnake *uint64 `json:"owner_user_id"`
|
||||
OwnerUserName string `json:"ownerUserName"`
|
||||
OwnerUserNameSnake string `json:"owner_user_name"`
|
||||
ActivationTime string `json:"activationTime"`
|
||||
ActivationTimeSnake string `json:"activation_time"`
|
||||
ExpireTime string `json:"expireTime"`
|
||||
ExpireTimeSnake string `json:"expire_time"`
|
||||
Remark string `json:"remark"`
|
||||
DeviceInfo string `json:"deviceInfo"`
|
||||
DeviceInfoSnake string `json:"device_info"`
|
||||
MachineCode string `json:"machineCode"`
|
||||
MachineCodeSnake string `json:"machine_code"`
|
||||
Status *int8 `json:"status"`
|
||||
System string `json:"system"`
|
||||
Version string `json:"version"`
|
||||
BindAccount string `json:"bindAccount"`
|
||||
BindAccountSnake string `json:"bind_account"`
|
||||
OwnerUserID *uint64 `json:"ownerUserId"`
|
||||
OwnerUserIDSnake *uint64 `json:"owner_user_id"`
|
||||
OwnerUserName string `json:"ownerUserName"`
|
||||
OwnerUserNameSnake string `json:"owner_user_name"`
|
||||
ActivationTime string `json:"activationTime"`
|
||||
ActivationTimeSnake string `json:"activation_time"`
|
||||
ExpireTime string `json:"expireTime"`
|
||||
ExpireTimeSnake string `json:"expire_time"`
|
||||
Remark string `json:"remark"`
|
||||
IpInfo *cursorIpInfo `json:"ipInfo"`
|
||||
}
|
||||
|
||||
type cursorEquipmentActivatePayload struct {
|
||||
Code string `json:"code"`
|
||||
ActivationCode string `json:"activationCode"`
|
||||
ActivationCodeSnake string `json:"activation_code"`
|
||||
DeviceInfo string `json:"deviceInfo"`
|
||||
DeviceInfoSnake string `json:"device_info"`
|
||||
MachineCode string `json:"machineCode"`
|
||||
MachineCodeSnake string `json:"machine_code"`
|
||||
System string `json:"system"`
|
||||
Version string `json:"version"`
|
||||
BindAccount string `json:"bindAccount"`
|
||||
BindAccountSnake string `json:"bind_account"`
|
||||
OwnerUserID *uint64 `json:"ownerUserId"`
|
||||
OwnerUserIDSnake *uint64 `json:"owner_user_id"`
|
||||
OwnerUserName string `json:"ownerUserName"`
|
||||
OwnerUserNameSnake string `json:"owner_user_name"`
|
||||
Remark string `json:"remark"`
|
||||
Code string `json:"code"`
|
||||
ActivationCode string `json:"activationCode"`
|
||||
ActivationCodeSnake string `json:"activation_code"`
|
||||
DeviceInfo string `json:"deviceInfo"`
|
||||
DeviceInfoSnake string `json:"device_info"`
|
||||
MachineCode string `json:"machineCode"`
|
||||
MachineCodeSnake string `json:"machine_code"`
|
||||
System string `json:"system"`
|
||||
Version string `json:"version"`
|
||||
BindAccount string `json:"bindAccount"`
|
||||
BindAccountSnake string `json:"bind_account"`
|
||||
OwnerUserID *uint64 `json:"ownerUserId"`
|
||||
OwnerUserIDSnake *uint64 `json:"owner_user_id"`
|
||||
OwnerUserName string `json:"ownerUserName"`
|
||||
OwnerUserNameSnake string `json:"owner_user_name"`
|
||||
Remark string `json:"remark"`
|
||||
IpInfo *cursorIpInfo `json:"ipInfo"`
|
||||
}
|
||||
|
||||
// cursorSaveIpLog 将 ipInfo 写入设备 IP 日志表(异步,失败不影响主流程)
|
||||
func cursorSaveIpLog(equipmentID uint64, machineCode, source string, ip *cursorIpInfo) {
|
||||
if ip == nil {
|
||||
return
|
||||
}
|
||||
log := &models.PlatformCursorEquipmentIpLog{
|
||||
EquipmentID: equipmentID,
|
||||
MachineCode: machineCode,
|
||||
Source: source,
|
||||
Status: ip.Status,
|
||||
Country: ip.Country,
|
||||
CountryCode: ip.CountryCode,
|
||||
Region: ip.Region,
|
||||
RegionName: ip.RegionName,
|
||||
City: ip.City,
|
||||
Zip: ip.Zip,
|
||||
Lat: ip.Lat,
|
||||
Lon: ip.Lon,
|
||||
Timezone: ip.Timezone,
|
||||
ISP: ip.ISP,
|
||||
Org: ip.Org,
|
||||
AsInfo: ip.As,
|
||||
Query: ip.Query,
|
||||
}
|
||||
_, _ = models.Orm.Insert(log)
|
||||
}
|
||||
|
||||
func cursorFirstNonEmpty(values ...string) string {
|
||||
@@ -293,6 +340,9 @@ func (c *ApiCursorEquipmentController) Report() {
|
||||
row.UpdateTime = &now
|
||||
}
|
||||
|
||||
// 记录 IP 日志
|
||||
cursorSaveIpLog(row.ID, machineCode, "report", p.IpInfo)
|
||||
|
||||
// 查询该设备最新激活码,补全激活时间和到期时间
|
||||
var retActivationTime interface{} = row.ActivationTime
|
||||
var retExpireTime interface{} = row.ExpireTime
|
||||
@@ -569,6 +619,9 @@ func (c *ApiCursorEquipmentController) ActivateByCode() {
|
||||
}
|
||||
rollback = false
|
||||
|
||||
// 记录 IP 日志
|
||||
cursorSaveIpLog(device.ID, machineCode, "activateByCode", p.IpInfo)
|
||||
|
||||
c.jsonResult(200, "success", map[string]interface{}{
|
||||
"activated": true,
|
||||
"reused": false,
|
||||
|
||||
Reference in New Issue
Block a user