jiantaoli 4 år sedan
förälder
incheckning
fb4a35c9ad
3 ändrade filer med 54 tillägg och 29 borttagningar
  1. 3 0
      .idea/dictionaries/zhanlangpc.xml
  2. 22 4
      adslib/addata/custom.go
  3. 29 25
      adslib/redis_data/redis_data.go

+ 3 - 0
.idea/dictionaries/zhanlangpc.xml

@@ -1,7 +1,10 @@
1 1
 <component name="ProjectDictionaryState">
2 2
   <dictionary name="zhanlangpc">
3 3
     <words>
4
+      <w>imei</w>
5
+      <w>sadd</w>
4 6
       <w>smembers</w>
7
+      <w>srandmember</w>
5 8
       <w>srem</w>
6 9
     </words>
7 10
   </dictionary>

+ 22 - 4
adslib/addata/custom.go

@@ -10,6 +10,19 @@ import (
10 10
 	"time"
11 11
 )
12 12
 
13
+type CustomAdData struct {
14
+	Duration       int64         `json:"duration"`
15
+	ImageURL       string        `json:"image_url"`
16
+	JsOrderID      string        `json:"js_order_id"`
17
+	Msg            int64         `json:"msg"`
18
+	OrderName      string        `json:"order_name"`
19
+	Result         int64         `json:"result"`
20
+	Target         string        `json:"target"`
21
+	TargetAddition []interface{} `json:"target_addition"`
22
+	UserAgent      string        `json:"user_agent"`
23
+	VideoURL       string        `json:"video_url"`
24
+}
25
+
13 26
 func CombineOrderBy(adData *AdData, dsp *utils.DspParam) {
14 27
 	ads_item, extra_item = yield get_ads_infos(dsp, order_type = 1)
15 28
 	if extra_item == None:
@@ -203,6 +216,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
203 216
 	curMinutefinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
204 217
 
205 218
 	if curMinutefinishedDispatchCnt < curMinuteNeedDispatchCnt {
219
+
206 220
 		data =
207 221
 		{
208 222
 			"js_order_id":js_order_id,
@@ -232,11 +246,14 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
232 246
 
233 247
 		target = ads_item['target_url']
234 248
 
235
-		orderName := ads_item['title']
236 249
 		if strings.Index(order.Title, "_ios") != -1 {
237
-			ios_imei, ios_ua = get_ios_ua_imei(dsp)
238
-		}
239
-		if ios_ua:
250
+			iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
251
+			if err != nil {
252
+				return err
253
+			}
254
+			if iosUa {
255
+
256
+			}
240 257
 		data['user_agent'] = ios_ua
241 258
 		if ads_item.get('imei_replace_flag', 0) == 1 and
242 259
 	ios_imei:
@@ -247,6 +264,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
247 264
 		show_url = show_url.replace('__OS__', '1')
248 265
 		click_url = click_url.replace('__OS__', '1')
249 266
 		target = target.replace('__OS__', '1')
267
+		}
250 268
 
251 269
 		elif
252 270
 		order_name.find("_android") > 0 :

+ 29 - 25
adslib/redis_data/redis_data.go

@@ -253,7 +253,7 @@ func SetReqSourceView(adv string, reqSource string, source string) {
253 253
 }
254 254
 
255 255
 // 获取剩余总投放量
256
-func GetRemainDispatchCount(key string) (int, error)  {
256
+func GetRemainDispatchCount(key string) (int, error) {
257 257
 	conn := ads_redis.RedisConn.Get()
258 258
 	defer conn.Close()
259 259
 
@@ -270,10 +270,9 @@ func GetRemainDispatchCount(key string) (int, error)  {
270 270
 	return count, nil
271 271
 }
272 272
 
273
-
274 273
 // 获取已经投放的量
275 274
 // dispatchType: "click", "show"
276
-func GetFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, error)  {
275
+func GetFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, error) {
277 276
 	conn := ads_redis.RedisConn.Get()
278 277
 	defer conn.Close()
279 278
 
@@ -293,7 +292,7 @@ func GetFinishedDispatchCount(orderId int64, dispatchType string, curTime time.T
293 292
 
294 293
 // 增加已经投放的量
295 294
 // dispatchType: "click", "show"
296
-func IncrFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int, curTime time.Time) (int, error)  {
295
+func IncrFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int, curTime time.Time) (int, error) {
297 296
 	conn := ads_redis.RedisConn.Get()
298 297
 	defer conn.Close()
299 298
 
@@ -309,11 +308,11 @@ func IncrFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int,
309 308
 
310 309
 // 获取当前分钟已经投放的量
311 310
 // dispatchType: "click", "show"
312
-func GetPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, error)  {
311
+func GetPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, error) {
313 312
 	conn := ads_redis.RedisConn.Get()
314 313
 	defer conn.Close()
315 314
 
316
-	curMinutes := curTime.Hour() * 60 + curTime.Minute()
315
+	curMinutes := curTime.Hour()*60 + curTime.Minute()
317 316
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
318 317
 	rsp, err := conn.Do("GET", key)
319 318
 	if err != nil {
@@ -330,11 +329,11 @@ func GetPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTi
330 329
 
331 330
 // 增加当前分钟已经投放的量
332 331
 // dispatchType: "click", "show"
333
-func IncrPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int, curTime time.Time) (int, error)  {
332
+func IncrPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int, curTime time.Time) (int, error) {
334 333
 	conn := ads_redis.RedisConn.Get()
335 334
 	defer conn.Close()
336 335
 
337
-	curMinutes := curTime.Hour() * 60 + curTime.Minute()
336
+	curMinutes := curTime.Hour()*60 + curTime.Minute()
338 337
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
339 338
 	rsp, err := conn.Do("INCR", key, incrCnt)
340 339
 	if err != nil {
@@ -360,13 +359,13 @@ func SetOrderPlanDispatchCount(orderId int64, dispatchType string, cnt int, curT
360 359
 	conn := ads_redis.RedisConn.Get()
361 360
 	defer conn.Close()
362 361
 
363
-	curMinutes := curTime.Hour() * 60 + curTime.Minute()
362
+	curMinutes := curTime.Hour()*60 + curTime.Minute()
364 363
 	key := fmt.Sprintf("plan_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
365 364
 	conn.Do("SET", key, cnt, 3600*24)
366 365
 }
367 366
 
368 367
 // 获取每分钟要投放的量
369
-func GetPerMinuteNeedDispatchCnt(orderId int64, curTime time.Time) (int, error){
368
+func GetPerMinuteNeedDispatchCnt(orderId int64, curTime time.Time) (int, error) {
370 369
 	conn := ads_redis.RedisConn.Get()
371 370
 	defer conn.Close()
372 371
 
@@ -387,21 +386,21 @@ func GetPerMinuteNeedDispatchCnt(orderId int64, curTime time.Time) (int, error){
387 386
 }
388 387
 
389 388
 // 获取ios的ua和imei
390
-func GetIosUaImei(ip string) (string, string, error){
389
+func GetIosUaImei(ip string) (string, string, error) {
391 390
 	conn := ads_redis.RedisConn.Get()
392 391
 	defer conn.Close()
393 392
 
394 393
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
395
-	redisKey := fmt.Sprintf("ads_ios_%d_%s", dateInt, ip)
394
+	iosUaImeiRedisKey := fmt.Sprintf("ads_ios_%d_%s", dateInt, ip)
396 395
 
397 396
 	// "{'imei': 'F389E3E1-5459-4B30-83A9-1AD504F6293F', 'ua': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML like Gecko) Mobile/15E148'}"
398
-	rsp, err := conn.Do("GET", redisKey)
397
+	rsp, err := conn.Do("GET", iosUaImeiRedisKey)
399 398
 	if err != nil {
400 399
 		return "", "", err
401 400
 	}
402 401
 
403 402
 	if rsp == nil {
404
-		redisKey = fmt.Sprintf("new_ios_ua_v2_%d", dateInt)
403
+		redisKey := fmt.Sprintf("new_ios_ua_v2_%d", dateInt)
405 404
 		rsp, err = conn.Do("SRANDMEMBER", redisKey)
406 405
 		if err != nil {
407 406
 			return "", "", err
@@ -412,17 +411,22 @@ func GetIosUaImei(ip string) (string, string, error){
412 411
 
413 412
 		conn.Do("SREM", redisKey, rsp)
414 413
 
415
-		tomorrowDateInt := time.Unix(time.Now().Unix()+86400, 0).Format("20060102")
416
-		set_new_ios_ua(redis_value,tomorrow_day_id)
417
-		return eval(redis_value)
414
+		tomorrowDateInt, _ := strconv.Atoi(time.Unix(time.Now().Unix()+86400, 0).Format("20060102"))
415
+		redisKey = fmt.Sprintf("new_ios_ua_v2_%d", tomorrowDateInt)
416
+		conn.Do("SADD", redisKey, rsp)
417
+	}
418
+
419
+	if rsp == nil {
420
+		return "", "", nil
418 421
 	}
419 422
 
420
-	redis_ua_value = redis_ua.get_ip_ios_ua(ip)
421
-	if not redis_ua_value:
422
-	redis_ua_value = redis_ua.get_new_ios_ua()
423
-	if redis_ua_value:
424
-	redis_ua.set_ip_ios_ua(ip,redis_ua_value)
425
-	imei = redis_ua_value.get('imei','')
426
-	ua = redis_ua_value.get('ua','')
427
-	return imei,ua
423
+	conn.Do("SET", iosUaImeiRedisKey, rsp, 86520)
424
+
425
+	var uaImeiInfo struct {
426
+		Imei string
427
+		Ua   string
428
+	}
429
+	rspBytes, _ := redis.Bytes(rsp, err)
430
+	json.Unmarshal(rspBytes, &uaImeiInfo)
431
+	return uaImeiInfo.Imei, uaImeiInfo.Ua, nil
428 432
 }