ad_event_record.go
3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package models
import (
"database/sql"
db "client/icesimba.ad/database"
)
type AdAppPosition struct {
AdId string
PositionId string
PositionApp string
PositionVersion string
}
type adAppPosition struct {
AdId sql.NullString
PositionId sql.NullString
PositionApp sql.NullString
PositionVersion sql.NullString
}
func PostAdEventRecord(
adId string,
positionId string,
gameId string,
positionVersion string,
iceVersion string,
channel string,
platform string,
model string,
deviceId string,
ip string,
eventCode string) (err error) {
eventObj, err := QueryEventByCode(eventCode)
adObj, err := QueryAdById(adId)
chanObj, err := QueryChannelByName(channel)
platObj, err := QueryPlatformByName(platform)
sqlIn := "INSERT INTO ice_ad_eventrecord(event_id,event_name," +
"ad_id,ad_app," +
"position_id,position_app,position_app_version," +
"device_id,channel_id,platform_id,model,ip,sdk_version)" +
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"
_, err = db.SqlDB.Exec(sqlIn,
eventObj.Id,
eventObj.Name,
adId,
adObj.AppId,
positionId,
gameId,
positionVersion,
deviceId,
chanObj.Id,
platObj.Id,
model,
ip,
iceVersion,
)
return
}
func PostAdEventActiveRecord(
adId string,
positionId string,
gameId string,
positionVersion string,
iceVersion string,
channel string,
platform string,
model string,
deviceId string,
ip string,
eventCode string) (err error) {
if IsAdEventRecordExist(deviceId, eventCode, gameId) {
return
}
adEventClickCode := "icead_click"
adEventRecordObj, err := QueryAdEventRecord(deviceId, adEventClickCode, gameId)
if err != nil {
return
}
eventObj, err := QueryEventByCode(eventCode)
chanObj, err := QueryChannelByName(channel)
platObj, err := QueryPlatformByName(platform)
sqlIn := "INSERT INTO ice_ad_eventrecord(event_id,event_name," +
"ad_id,ad_app," +
"position_id,position_app,position_app_version," +
"device_id,channel_id,platform_id,model,ip,sdk_version)" +
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"
_, err = db.SqlDB.Exec(sqlIn,
eventObj.Id,
eventObj.Name,
adEventRecordObj.AdId,
gameId,
adEventRecordObj.PositionId,
adEventRecordObj.PositionApp,
adEventRecordObj.PositionVersion,
deviceId,
chanObj.Id,
platObj.Id,
model,
ip,
iceVersion,
)
return
}
func IsAdEventRecordExist(deviceId string, eventCode string, gameId string) bool {
eventObj, err := QueryEventByCode(eventCode)
sqlQu := "select id from ice_ad_eventrecord where device_id=? and event_id=? and ad_app=? limit 1"
var idNull sql.NullString
err = db.SqlDB.QueryRow(
sqlQu,
deviceId,
eventObj.Id,
gameId,
).Scan(
&idNull,
)
if err != nil {
return false
}
return true
}
func QueryAdEventRecord(deviceId string, eventCode string, gameId string) (out AdAppPosition, err error) {
eventObj, err := QueryEventByCode(eventCode)
sqlQu := "SELECT ad_id,position_id,position_app,position_app_version" +
" FROM ice_ad_eventrecord" +
" WHERE create_time<=NOW() " +
" AND ad_app=? AND event_id=? AND device_id=?" +
" ORDER BY create_time DESC LIMIT 1"
adAppPosNull := adAppPosition{}
err = db.SqlDB.QueryRow(
sqlQu,
gameId,
eventObj.Id,
deviceId,
).Scan(
&adAppPosNull.AdId,
&adAppPosNull.PositionId,
&adAppPosNull.PositionApp,
&adAppPosNull.PositionVersion,
)
if err != nil {
return
}
if adAppPosNull.AdId.Valid {
out.AdId = adAppPosNull.AdId.String
}
if adAppPosNull.PositionId.Valid {
out.PositionId = adAppPosNull.PositionId.String
}
if adAppPosNull.PositionApp.Valid {
out.PositionApp = adAppPosNull.PositionApp.String
}
if adAppPosNull.PositionVersion.Valid {
out.PositionVersion = adAppPosNull.PositionVersion.String
}
return
}