|
|
@@ -27,12 +27,12 @@ func AddPublicPlatoonDoubleNetworkRelateCommission(engine *xorm.Engine, AddPubli |
|
|
|
} |
|
|
|
for _, param := range AddPublicPlatoonDoubleNetworkRelateCommissionReqList { |
|
|
|
//TODO::判断是否有uid为-1 (代表等待新用户填充) 的记录 |
|
|
|
userPublicPlatoonDoubleNetworkRelation, err := db.UserPublicPlatoonDoubleNetworkRelationGetOneByParams(engine, map[string]interface{}{ |
|
|
|
userPublicPlatoonDoubleNetworkRelation, err2 := db.UserPublicPlatoonDoubleNetworkRelationGetOneByParams(engine, map[string]interface{}{ |
|
|
|
"key": "uid", |
|
|
|
"value": -1, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
if err2 != nil { |
|
|
|
return nil, err2 |
|
|
|
} |
|
|
|
if userPublicPlatoonDoubleNetworkRelation != nil { |
|
|
|
now := time.Now() |
|
|
@@ -46,21 +46,21 @@ func AddPublicPlatoonDoubleNetworkRelateCommission(engine *xorm.Engine, AddPubli |
|
|
|
userPublicPlatoonDoubleNetworkRelation.JoinAt = now |
|
|
|
userPublicPlatoonDoubleNetworkRelation.CreateAt = now |
|
|
|
userPublicPlatoonDoubleNetworkRelation.UpdateAt = now |
|
|
|
updateAffected, err := db.UserPublicPlatoonDoubleNetworkRelationUpdate(engine.NewSession(), userPublicPlatoonDoubleNetworkRelation.Id, userPublicPlatoonDoubleNetworkRelation) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
updateAffected, err1 := db.UserPublicPlatoonDoubleNetworkRelationUpdate(engine.NewSession(), userPublicPlatoonDoubleNetworkRelation.Id, userPublicPlatoonDoubleNetworkRelation) |
|
|
|
if err1 != nil { |
|
|
|
return nil, err1 |
|
|
|
} |
|
|
|
if updateAffected == 0 { |
|
|
|
err = errors.New("更新 user_public_platoon_relation 记录失败") |
|
|
|
return nil, err |
|
|
|
err1 = errors.New("更新 user_public_platoon_double_network_relation 记录失败") |
|
|
|
return nil, err1 |
|
|
|
} else { |
|
|
|
resp[param.Uid] = userPublicPlatoonDoubleNetworkRelation |
|
|
|
} |
|
|
|
continue |
|
|
|
} |
|
|
|
res, err := publicPlatoonDoubleNetwork(engine, zhios_order_relate_utils.StrToInt(param.Uid), zhios_order_relate_utils.StrToInt(param.RecommendUid), *userPublicPlatoonDoubleNetworkSetting) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
res, err1 := publicPlatoonDoubleNetwork(engine, zhios_order_relate_utils.StrToInt(param.Uid), zhios_order_relate_utils.StrToInt(param.RecommendUid), *userPublicPlatoonDoubleNetworkSetting) |
|
|
|
if err1 != nil { |
|
|
|
return nil, err1 |
|
|
|
} |
|
|
|
resp[param.Uid] = &res |
|
|
|
} |
|
|
@@ -78,14 +78,14 @@ func AddPublicPlatoonDoubleNetworkRelateCommission(engine *xorm.Engine, AddPubli |
|
|
|
func publicPlatoonDoubleNetwork(engine *xorm.Engine, uid, recommendUid int, userPublicPlatoonDoubleNetworkSetting model.UserPublicPlatoonDoubleNetworkSetting) (model.UserPublicPlatoonDoubleNetworkRelation, error) { |
|
|
|
var userPublicPlatoonDoubleNetworkRelation model.UserPublicPlatoonDoubleNetworkRelation |
|
|
|
|
|
|
|
//1、 查找当前 user_public_platoon_relation 中 `position` 最大的记录 |
|
|
|
//1、 查找当前 user_public_platoon_double_network_relation 中 `position` 最大的记录 |
|
|
|
var m model.UserPublicPlatoonDoubleNetworkRelation |
|
|
|
has, err := engine.OrderBy("id desc").Get(&m) |
|
|
|
if err != nil { |
|
|
|
return userPublicPlatoonDoubleNetworkRelation, err |
|
|
|
} |
|
|
|
if has == false { |
|
|
|
return userPublicPlatoonDoubleNetworkRelation, errors.New("查询 user_public_platoon_relation 记录失败") |
|
|
|
return userPublicPlatoonDoubleNetworkRelation, errors.New("查询 user_public_platoon_double_network_relation 记录失败") |
|
|
|
} |
|
|
|
|
|
|
|
//TODO::判断 `position + userPublicPlatoonDoubleNetworkSetting.SeveralTimes(几乘)` OR `position + 1` |
|
|
@@ -98,11 +98,7 @@ func publicPlatoonDoubleNetwork(engine *xorm.Engine, uid, recommendUid int, user |
|
|
|
level = level1 + 1 //TODO::根据公式需要 + 1 |
|
|
|
if level > 2 { |
|
|
|
if level1 != level2 { |
|
|
|
//if position1 == getLevelForLastPositionDoubleNetwork(int(level), userPublicPlatoonDoubleNetworkSetting.SeveralTimes) { |
|
|
|
// position = position1 |
|
|
|
//} else { |
|
|
|
position = reverseDeductionPositionDoubleNetwork(m.Position, getLevelForFirstPositionDoubleNetwork(int(level), userPublicPlatoonDoubleNetworkSetting.SeveralTimes), userPublicPlatoonDoubleNetworkSetting.SeveralTimes) |
|
|
|
//} |
|
|
|
} else { |
|
|
|
if position1 == getLevelForFirstPositionDoubleNetwork(int(level), userPublicPlatoonDoubleNetworkSetting.SeveralTimes) { |
|
|
|
position = position1 |
|
|
@@ -116,7 +112,7 @@ func publicPlatoonDoubleNetwork(engine *xorm.Engine, uid, recommendUid int, user |
|
|
|
|
|
|
|
pid := makeSearchPidDoubleNetwork(position, userPublicPlatoonDoubleNetworkSetting.SeveralTimes) |
|
|
|
|
|
|
|
//2、查找对应pid的 user_public_platoon_relation 记录 |
|
|
|
//2、查找对应pid的 user_public_platoon_double_network_relation 记录 |
|
|
|
var m1 model.UserPublicPlatoonDoubleNetworkRelation |
|
|
|
if has, err := engine.Where("position=?", pid).Get(&m1); err != nil || has == false { |
|
|
|
return userPublicPlatoonDoubleNetworkRelation, err |
|
|
@@ -136,7 +132,7 @@ func publicPlatoonDoubleNetwork(engine *xorm.Engine, uid, recommendUid int, user |
|
|
|
|
|
|
|
//唯一标识符(父级id-uid-等级-位置) |
|
|
|
var uniqueIdentifier = zhios_order_relate_utils.IntToStr(pid) + "-" + zhios_order_relate_utils.IntToStr(uid) + "-" + zhios_order_relate_utils.IntToStr(int(level)) + "-" + zhios_order_relate_utils.IntToStr(position) |
|
|
|
// 3、插入 user_public_platoon_relation 记录 |
|
|
|
// 3、插入 user_public_platoon_double_network_relation 记录 |
|
|
|
now := time.Now() |
|
|
|
userPublicPlatoonDoubleNetworkRelation.Uid = uid |
|
|
|
userPublicPlatoonDoubleNetworkRelation.FatherUid = fatherUid |
|
|
@@ -172,7 +168,7 @@ func getLevelForFirstPositionDoubleNetwork(level, severalTimes int) (position in |
|
|
|
} |
|
|
|
|
|
|
|
// getLevelForLastPositionDoubleNetwork 每个等级的结束值 |
|
|
|
func getLevelForLastPositionDoubleNetwork(level, severalTimes int) (position int) { |
|
|
|
func etLevelForLastPositionDoubleNetwork(level, severalTimes int) (position int) { |
|
|
|
for n := 0; n <= (level - 1); n++ { |
|
|
|
position += int(math.Pow(float64(severalTimes), float64(n))) |
|
|
|
} |
|
|
@@ -209,7 +205,7 @@ func makeSearchPidDoubleNetwork(position int, row int) (pid int) { |
|
|
|
} |
|
|
|
|
|
|
|
// JudgeUserBelowLevelDoubleNetwork 判断当前用户下几级排满 |
|
|
|
func JudgeUserBelowLevelDoubleNetworkDoubleNetwork(engine *xorm.Engine, uid int) (level int, err error) { |
|
|
|
func JudgeUserBelowLevelDoubleNetwork(engine *xorm.Engine, uid int) (level int, err error) { |
|
|
|
//1、查找 `user_public_platoon_setting` 基础设置 |
|
|
|
userPublicPlatoonDoubleNetworkSetting, err := db.UserPublicPlatoonDoubleNetworkSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
|
"key": "is_open", |
|
|
|