|
|
|
|
@ -115,13 +115,13 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
"package_name": req.PackageName, |
|
|
|
|
"customer_active_time": fmt.Sprint(time.Now().UnixMilli()), // 毫秒时间戳,客户激活归因时间点
|
|
|
|
|
} |
|
|
|
|
var adData []entity.AdvertisementOceanegine |
|
|
|
|
model := dao.AdvertisementOceanegine.Ctx(ctx).Order("last_touch_time desc") |
|
|
|
|
var adDatas []entity.AdvertisementOceanegine1 |
|
|
|
|
model := dao.AdvertisementOceanegine1.Ctx(ctx) |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
if req.AndroidId != "" && req.AndroidId != "00000000-0000-0000-0000-000000000000" { |
|
|
|
|
_ = model.Where("adv_android_id=?", req.AndroidId).Page(1, 1).Scan(&adData) |
|
|
|
|
if req.AndroidId != "" && req.AndroidId != "__ANDROIDID__" && req.AndroidId != "00000000-0000-0000-0000-000000000000" { |
|
|
|
|
_ = model.Where("adv_android_id=?", req.AndroidId).Where("os=?", 0).Scan(&adDatas) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
if len(adDatas) == 0 { |
|
|
|
|
log.Printf("AttributionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
@ -129,20 +129,20 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
data["android_id"] = req.AndroidId |
|
|
|
|
} else if req.Platform == "ios" { |
|
|
|
|
if req.Idfa != "" && req.Idfa != "00000000-0000-0000-0000-000000000000" { |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Page(1, 1).Scan(&adData) |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Where("os=?", 1).Scan(&adDatas) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
if len(adDatas) == 0 { |
|
|
|
|
if req.Caid != "" { |
|
|
|
|
var list []map[string]string |
|
|
|
|
_ = json.Unmarshal([]byte(req.Caid), &list) |
|
|
|
|
for _, v := range list { |
|
|
|
|
_ = model.Where("caid=?", v["caid"]).Page(1, 1).Scan(&adData) |
|
|
|
|
if len(adData) > 0 { |
|
|
|
|
_ = model.Where("caid=?", v["caid"]).Where("os=?", 1).Scan(&adDatas) |
|
|
|
|
if len(adDatas) > 0 { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
if len(adDatas) == 0 { |
|
|
|
|
log.Printf("AttributionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
@ -153,7 +153,17 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
err = errors.New("platform is error " + req.Platform) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 || adData[0].CallbackParam == "" { |
|
|
|
|
if len(adDatas) == 0 { |
|
|
|
|
err = errors.New("无广告!") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
var adData entity.AdvertisementOceanegine1 |
|
|
|
|
for _, v := range adDatas { |
|
|
|
|
if adData.Id == 0 || v.LastTouchTime > adData.LastTouchTime || (v.LastTouchTime == adData.LastTouchTime && v.CDate.Unix() > adData.CDate.Unix()) { |
|
|
|
|
adData = v |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if adData.CallbackParam == "" { |
|
|
|
|
err = errors.New("无广告!") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
@ -188,11 +198,11 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
// advIdfv = req.Idfv
|
|
|
|
|
//}
|
|
|
|
|
lastTouchTime := resJson.Get("last_touch_time").Int64() * 1000 |
|
|
|
|
if adData[0].LastTouchTime == lastTouchTime { |
|
|
|
|
if adData.LastTouchTime > lastTouchTime { |
|
|
|
|
err = errors.New("lastTouchTime repeat") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
advertiseData := do.AdvertisementOceanegine{AdvAndroidId: androidId, Idfa: idfa, AdvIdfv: advIdfv, |
|
|
|
|
advertiseData := do.AdvertisementOceanegine1{AdvAndroidId: androidId, Idfa: idfa, AdvIdfv: advIdfv, |
|
|
|
|
CallbackUrl: callbackUrl, CallbackParam: callbackParam, LastTouchTime: lastTouchTime, UnitId: req.UnitId} |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
advertiseData.Os = 0 |
|
|
|
|
@ -212,7 +222,7 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, err = dao.AdvertisementOceanegine.Ctx(ctx).Insert(advertiseData) |
|
|
|
|
_, err = dao.AdvertisementOceanegine1.Ctx(ctx).WherePri(adData.Id).Update(advertiseData) |
|
|
|
|
} else { |
|
|
|
|
err = errors.New("获取失败") |
|
|
|
|
return |
|
|
|
|
@ -223,63 +233,66 @@ func AttributionHugeAmount(ctx context.Context, req *game.ATHAReq) (res *game.AT
|
|
|
|
|
|
|
|
|
|
func ConversionHugeAmount(ctx context.Context, req *game.CSHAReq) (res *game.CSHARes, err error) { |
|
|
|
|
//log.Printf("ConversionHugeAmount: %s", gjson.MustEncodeString(req))
|
|
|
|
|
var adData []entity.AdvertisementOceanegine |
|
|
|
|
var adDatas []entity.AdvertisementOceanegine1 |
|
|
|
|
device := map[string]interface{}{ |
|
|
|
|
"platform": req.Platform, |
|
|
|
|
} |
|
|
|
|
model := dao.AdvertisementOceanegine.Ctx(ctx).Order("last_touch_time desc") |
|
|
|
|
model := dao.AdvertisementOceanegine1.Ctx(ctx) |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
if req.Id != "" && req.Id != "00000000-0000-0000-0000-000000000000" { |
|
|
|
|
_ = model.Where("adv_android_id=?", req.Id).Page(1, 1).Scan(&adData) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("ConversionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
_ = model.Where("adv_android_id=?", req.Id).Where("os=?", 0).Scan(&adDatas) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
device["android_id"] = req.Id |
|
|
|
|
} else if req.Platform == "ios" { |
|
|
|
|
if req.Idfa != "" && req.Idfa != "00000000-0000-0000-0000-000000000000" { |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Page(1, 1).Scan(&adData) |
|
|
|
|
_ = model.Where("idfa=?", req.Idfa).Where("os=?", 1).Scan(&adDatas) |
|
|
|
|
} |
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
if len(adDatas) == 0 { |
|
|
|
|
if req.Caid != "" { |
|
|
|
|
var list []map[string]string |
|
|
|
|
_ = json.Unmarshal([]byte(req.Caid), &list) |
|
|
|
|
for _, v := range list { |
|
|
|
|
_ = model.Where("caid=?", v["caid"]).Page(1, 1).Scan(&adData) |
|
|
|
|
if len(adData) > 0 { |
|
|
|
|
_ = model.Where("caid=?", v["caid"]).Where("os=?", 1).Scan(&adDatas) |
|
|
|
|
if len(adDatas) > 0 { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(adData) == 0 { |
|
|
|
|
log.Printf("ConversionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
device["idfv"] = req.Id |
|
|
|
|
} else { |
|
|
|
|
err = errors.New("platform is error " + req.Platform) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if adData[0].CallbackParam == "" { |
|
|
|
|
|
|
|
|
|
if len(adDatas) == 0 { |
|
|
|
|
log.Printf("ConversionHugeAmount: adData is nil %s", gjson.MustEncodeString(req)) |
|
|
|
|
err = errors.New("account is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
var adData entity.AdvertisementOceanegine1 |
|
|
|
|
for _, v := range adDatas { |
|
|
|
|
if adData.Id == 0 || v.LastTouchTime > adData.LastTouchTime || (v.LastTouchTime == adData.LastTouchTime && v.CDate.Unix() > adData.CDate.Unix()) { |
|
|
|
|
adData = v |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if adData.CallbackParam == "" { |
|
|
|
|
err = errors.New("callbackParam is nil") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if req.EventType == consts.EventType_Active && adData[0].Active == 1 { |
|
|
|
|
if req.EventType == consts.EventType_Active && adData.Active == 1 { |
|
|
|
|
err = errors.New("already activated !") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if req.EventType == consts.EventType_Register && adData[0].Register == 1 { |
|
|
|
|
if req.EventType == consts.EventType_Register && adData.Register == 1 { |
|
|
|
|
err = errors.New("already register!") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ad := map[string]interface{}{ |
|
|
|
|
"callback": adData[0].CallbackParam, |
|
|
|
|
"callback": adData.CallbackParam, |
|
|
|
|
} |
|
|
|
|
ct := map[string]interface{}{ |
|
|
|
|
"ad": ad, |
|
|
|
|
@ -313,14 +326,14 @@ func ConversionHugeAmount(ctx context.Context, req *game.CSHAReq) (res *game.CSH
|
|
|
|
|
if resJson != nil && resJson.Get("code").Int() != 0 { |
|
|
|
|
err = errors.New(resJson.Get("message").String()) |
|
|
|
|
} else if resJson.Get("code").Int() == 0 { |
|
|
|
|
saveData := do.AdvertisementOceanegine{} |
|
|
|
|
saveData := do.AdvertisementOceanegine1{} |
|
|
|
|
if req.EventType == consts.EventType_Active { |
|
|
|
|
saveData.Active = 1 |
|
|
|
|
} |
|
|
|
|
if req.EventType == consts.EventType_Register { |
|
|
|
|
saveData.Register = 1 |
|
|
|
|
} |
|
|
|
|
dao.AdvertisementOceanegine.Ctx(ctx).WherePri(adData[0].Id).Update(saveData) |
|
|
|
|
dao.AdvertisementOceanegine1.Ctx(ctx).WherePri(adData.Id).Update(saveData) |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
@ -372,7 +385,6 @@ func HugeAmount(ctx context.Context, req *game.AdvertiseHAReq) {
|
|
|
|
|
PackageName: req.PackageName, |
|
|
|
|
Caid: req.Caid, |
|
|
|
|
Idfa: req.Idfa, |
|
|
|
|
//UnitId: req.UnitId,
|
|
|
|
|
} |
|
|
|
|
if req.Platform == "android" { |
|
|
|
|
req1.AndroidId = req.Id |
|
|
|
|
|