jiantaoli 5 年之前
父节点
当前提交
fb4a35c9ad
共有 3 个文件被更改,包括 54 次插入29 次删除
  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
 <component name="ProjectDictionaryState">
1
 <component name="ProjectDictionaryState">
2
   <dictionary name="zhanlangpc">
2
   <dictionary name="zhanlangpc">
3
     <words>
3
     <words>
4
+      <w>imei</w>
5
+      <w>sadd</w>
4
       <w>smembers</w>
6
       <w>smembers</w>
7
+      <w>srandmember</w>
5
       <w>srem</w>
8
       <w>srem</w>
6
     </words>
9
     </words>
7
   </dictionary>
10
   </dictionary>

+ 22 - 4
adslib/addata/custom.go

@@ -10,6 +10,19 @@ import (
10
 	"time"
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
 func CombineOrderBy(adData *AdData, dsp *utils.DspParam) {
26
 func CombineOrderBy(adData *AdData, dsp *utils.DspParam) {
14
 	ads_item, extra_item = yield get_ads_infos(dsp, order_type = 1)
27
 	ads_item, extra_item = yield get_ads_infos(dsp, order_type = 1)
15
 	if extra_item == None:
28
 	if extra_item == None:
@@ -203,6 +216,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
203
 	curMinutefinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
216
 	curMinutefinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
204
 
217
 
205
 	if curMinutefinishedDispatchCnt < curMinuteNeedDispatchCnt {
218
 	if curMinutefinishedDispatchCnt < curMinuteNeedDispatchCnt {
219
+
206
 		data =
220
 		data =
207
 		{
221
 		{
208
 			"js_order_id":js_order_id,
222
 			"js_order_id":js_order_id,
@@ -232,11 +246,14 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
232
 
246
 
233
 		target = ads_item['target_url']
247
 		target = ads_item['target_url']
234
 
248
 
235
-		orderName := ads_item['title']
236
 		if strings.Index(order.Title, "_ios") != -1 {
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
 		data['user_agent'] = ios_ua
257
 		data['user_agent'] = ios_ua
241
 		if ads_item.get('imei_replace_flag', 0) == 1 and
258
 		if ads_item.get('imei_replace_flag', 0) == 1 and
242
 	ios_imei:
259
 	ios_imei:
@@ -247,6 +264,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag
247
 		show_url = show_url.replace('__OS__', '1')
264
 		show_url = show_url.replace('__OS__', '1')
248
 		click_url = click_url.replace('__OS__', '1')
265
 		click_url = click_url.replace('__OS__', '1')
249
 		target = target.replace('__OS__', '1')
266
 		target = target.replace('__OS__', '1')
267
+		}
250
 
268
 
251
 		elif
269
 		elif
252
 		order_name.find("_android") > 0 :
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
 	conn := ads_redis.RedisConn.Get()
257
 	conn := ads_redis.RedisConn.Get()
258
 	defer conn.Close()
258
 	defer conn.Close()
259
 
259
 
@@ -270,10 +270,9 @@ func GetRemainDispatchCount(key string) (int, error)  {
270
 	return count, nil
270
 	return count, nil
271
 }
271
 }
272
 
272
 
273
-
274
 // 获取已经投放的量
273
 // 获取已经投放的量
275
 // dispatchType: "click", "show"
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
 	conn := ads_redis.RedisConn.Get()
276
 	conn := ads_redis.RedisConn.Get()
278
 	defer conn.Close()
277
 	defer conn.Close()
279
 
278
 
@@ -293,7 +292,7 @@ func GetFinishedDispatchCount(orderId int64, dispatchType string, curTime time.T
293
 
292
 
294
 // 增加已经投放的量
293
 // 增加已经投放的量
295
 // dispatchType: "click", "show"
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
 	conn := ads_redis.RedisConn.Get()
296
 	conn := ads_redis.RedisConn.Get()
298
 	defer conn.Close()
297
 	defer conn.Close()
299
 
298
 
@@ -309,11 +308,11 @@ func IncrFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int,
309
 
308
 
310
 // 获取当前分钟已经投放的量
309
 // 获取当前分钟已经投放的量
311
 // dispatchType: "click", "show"
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
 	conn := ads_redis.RedisConn.Get()
312
 	conn := ads_redis.RedisConn.Get()
314
 	defer conn.Close()
313
 	defer conn.Close()
315
 
314
 
316
-	curMinutes := curTime.Hour() * 60 + curTime.Minute()
315
+	curMinutes := curTime.Hour()*60 + curTime.Minute()
317
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
316
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
318
 	rsp, err := conn.Do("GET", key)
317
 	rsp, err := conn.Do("GET", key)
319
 	if err != nil {
318
 	if err != nil {
@@ -330,11 +329,11 @@ func GetPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTi
330
 
329
 
331
 // 增加当前分钟已经投放的量
330
 // 增加当前分钟已经投放的量
332
 // dispatchType: "click", "show"
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
 	conn := ads_redis.RedisConn.Get()
333
 	conn := ads_redis.RedisConn.Get()
335
 	defer conn.Close()
334
 	defer conn.Close()
336
 
335
 
337
-	curMinutes := curTime.Hour() * 60 + curTime.Minute()
336
+	curMinutes := curTime.Hour()*60 + curTime.Minute()
338
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
337
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
339
 	rsp, err := conn.Do("INCR", key, incrCnt)
338
 	rsp, err := conn.Do("INCR", key, incrCnt)
340
 	if err != nil {
339
 	if err != nil {
@@ -360,13 +359,13 @@ func SetOrderPlanDispatchCount(orderId int64, dispatchType string, cnt int, curT
360
 	conn := ads_redis.RedisConn.Get()
359
 	conn := ads_redis.RedisConn.Get()
361
 	defer conn.Close()
360
 	defer conn.Close()
362
 
361
 
363
-	curMinutes := curTime.Hour() * 60 + curTime.Minute()
362
+	curMinutes := curTime.Hour()*60 + curTime.Minute()
364
 	key := fmt.Sprintf("plan_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
363
 	key := fmt.Sprintf("plan_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
365
 	conn.Do("SET", key, cnt, 3600*24)
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
 	conn := ads_redis.RedisConn.Get()
369
 	conn := ads_redis.RedisConn.Get()
371
 	defer conn.Close()
370
 	defer conn.Close()
372
 
371
 
@@ -387,21 +386,21 @@ func GetPerMinuteNeedDispatchCnt(orderId int64, curTime time.Time) (int, error){
387
 }
386
 }
388
 
387
 
389
 // 获取ios的ua和imei
388
 // 获取ios的ua和imei
390
-func GetIosUaImei(ip string) (string, string, error){
389
+func GetIosUaImei(ip string) (string, string, error) {
391
 	conn := ads_redis.RedisConn.Get()
390
 	conn := ads_redis.RedisConn.Get()
392
 	defer conn.Close()
391
 	defer conn.Close()
393
 
392
 
394
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
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
 	// "{'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'}"
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
 	if err != nil {
398
 	if err != nil {
400
 		return "", "", err
399
 		return "", "", err
401
 	}
400
 	}
402
 
401
 
403
 	if rsp == nil {
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
 		rsp, err = conn.Do("SRANDMEMBER", redisKey)
404
 		rsp, err = conn.Do("SRANDMEMBER", redisKey)
406
 		if err != nil {
405
 		if err != nil {
407
 			return "", "", err
406
 			return "", "", err
@@ -412,17 +411,22 @@ func GetIosUaImei(ip string) (string, string, error){
412
 
411
 
413
 		conn.Do("SREM", redisKey, rsp)
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
 }