|
|
@@ -146,81 +146,96 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl |
|
|
|
} |
|
|
|
|
|
|
|
//2、 查找当前 user_small_public_platoon_relation 中 recommendUid 所有的子记录 |
|
|
|
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPidLike(engine, strconv.Itoa(m.Position)) |
|
|
|
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPid(engine, m.Position) |
|
|
|
if err != nil { |
|
|
|
return model.UserSmallPublicPlatoonRelation{}, err |
|
|
|
} |
|
|
|
|
|
|
|
var position, position1, position2, pid int |
|
|
|
var level, level1, level2 float64 |
|
|
|
var position, pid int |
|
|
|
var level float64 |
|
|
|
if len(userSmallPublicPlatoonRelations) == 0 { |
|
|
|
//证明是第一个 |
|
|
|
position = smallSearchPositionFirstSonPosition(m.Position, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
level = float64(m.Level) + 1 |
|
|
|
pid = m.Position |
|
|
|
} else { |
|
|
|
var mapUserSmallPublicPlatoonRelations = map[int]interface{}{} |
|
|
|
for _, item := range userSmallPublicPlatoonRelations { |
|
|
|
mapUserSmallPublicPlatoonRelations[item.Position] = &item |
|
|
|
} |
|
|
|
mapUserSmallPublicPlatoonRelations[m.Position] = m |
|
|
|
|
|
|
|
position1 = userSmallPublicPlatoonRelations[0].Position + userPublicPlatoonSetting.SeveralTimes |
|
|
|
position2 = userSmallPublicPlatoonRelations[0].Position + 1 |
|
|
|
level = float64(userSmallPublicPlatoonRelations[0].Level) |
|
|
|
smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level1) |
|
|
|
smallMakeSearchLevel(&position2, float64(userPublicPlatoonSetting.SeveralTimes), &level2) |
|
|
|
|
|
|
|
//判断 position1 的上级是否还属于 |
|
|
|
fatherPosition1 := smallMakeSearchPid(position1, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
fatherPosition2 := smallMakeSearchPid(position2, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
if mapUserSmallPublicPlatoonRelations[fatherPosition1] != nil { |
|
|
|
//属于 |
|
|
|
if level != level1 { |
|
|
|
if mapUserSmallPublicPlatoonRelations[fatherPosition2] != nil { |
|
|
|
//同级 |
|
|
|
tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1 + userPublicPlatoonSetting.SeveralTimes) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
if mapUserSmallPublicPlatoonRelations[tmpPosition] != nil { |
|
|
|
position = position2 |
|
|
|
pid = fatherPosition2 |
|
|
|
level = level2 |
|
|
|
} else { |
|
|
|
//回归 |
|
|
|
position = tmpPosition |
|
|
|
pid = smallMakeSearchPid(position, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
} |
|
|
|
} else { |
|
|
|
//新的一级 |
|
|
|
tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
position = smallSearchPositionFirstSonPosition(tmpPosition, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level) |
|
|
|
pid = tmpPosition |
|
|
|
} |
|
|
|
} else { |
|
|
|
position = position1 |
|
|
|
pid = fatherPosition1 |
|
|
|
level = level1 |
|
|
|
//TODO::判断直属下级是否排满 |
|
|
|
if len(userSmallPublicPlatoonRelations) == userPublicPlatoonSetting.SeveralTimes { |
|
|
|
var fatherLevel float64 |
|
|
|
smallMakeSearchLevel(&m.Position, float64(userPublicPlatoonSetting.SeveralTimes), &fatherLevel) |
|
|
|
position, pid, level, err = smallFindSuitablePosition(engine, &m.Position, float64(userPublicPlatoonSetting.SeveralTimes), int(fatherLevel)) |
|
|
|
if err != nil { |
|
|
|
return model.UserSmallPublicPlatoonRelation{}, err |
|
|
|
} |
|
|
|
} else { |
|
|
|
if mapUserSmallPublicPlatoonRelations[fatherPosition2] != nil { |
|
|
|
//同级 |
|
|
|
tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1 + userPublicPlatoonSetting.SeveralTimes) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
if mapUserSmallPublicPlatoonRelations[tmpPosition] != nil { |
|
|
|
position = position2 |
|
|
|
pid = fatherPosition2 |
|
|
|
} else { |
|
|
|
//回归 |
|
|
|
position = tmpPosition |
|
|
|
pid = smallMakeSearchPid(position, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
} |
|
|
|
} else { |
|
|
|
//新的一级 |
|
|
|
tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
position = smallSearchPositionFirstSonPosition(tmpPosition, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level) |
|
|
|
pid = tmpPosition |
|
|
|
} |
|
|
|
position = m.Position + 1 |
|
|
|
level = float64(m.Level) + 1 |
|
|
|
pid = m.Position |
|
|
|
} |
|
|
|
|
|
|
|
//var mapUserSmallPublicPlatoonRelations = map[int]interface{}{} |
|
|
|
//for _, item := range userSmallPublicPlatoonRelations { |
|
|
|
// mapUserSmallPublicPlatoonRelations[item.Position] = &item |
|
|
|
//} |
|
|
|
//mapUserSmallPublicPlatoonRelations[m.Position] = m |
|
|
|
// |
|
|
|
//position1 = userSmallPublicPlatoonRelations[0].Position + userPublicPlatoonSetting.SeveralTimes |
|
|
|
//position2 = userSmallPublicPlatoonRelations[0].Position + 1 |
|
|
|
//level = float64(userSmallPublicPlatoonRelations[0].Level) |
|
|
|
//smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level1) |
|
|
|
//smallMakeSearchLevel(&position2, float64(userPublicPlatoonSetting.SeveralTimes), &level2) |
|
|
|
// |
|
|
|
////判断 position1 的上级是否还属于 |
|
|
|
//fatherPosition1 := smallMakeSearchPid(position1, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
//fatherPosition2 := smallMakeSearchPid(position2, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
//if mapUserSmallPublicPlatoonRelations[fatherPosition1] != nil { |
|
|
|
// //属于 |
|
|
|
// if level != level1 { |
|
|
|
// if mapUserSmallPublicPlatoonRelations[fatherPosition2] != nil { |
|
|
|
// //同级 |
|
|
|
// tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1 + userPublicPlatoonSetting.SeveralTimes) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
// if mapUserSmallPublicPlatoonRelations[tmpPosition] != nil { |
|
|
|
// position = position2 |
|
|
|
// pid = fatherPosition2 |
|
|
|
// level = level2 |
|
|
|
// } else { |
|
|
|
// //回归 |
|
|
|
// position = tmpPosition |
|
|
|
// pid = smallMakeSearchPid(position, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// //新的一级 |
|
|
|
// tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
// position = smallSearchPositionFirstSonPosition(tmpPosition, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
// smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level) |
|
|
|
// pid = tmpPosition |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// position = position1 |
|
|
|
// pid = fatherPosition1 |
|
|
|
// level = level1 |
|
|
|
// } |
|
|
|
//} |
|
|
|
//else { |
|
|
|
// if mapUserSmallPublicPlatoonRelations[fatherPosition2] != nil { |
|
|
|
// //同级 |
|
|
|
// tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1 + userPublicPlatoonSetting.SeveralTimes) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
// if mapUserSmallPublicPlatoonRelations[tmpPosition] != nil { |
|
|
|
// position = position2 |
|
|
|
// pid = fatherPosition2 |
|
|
|
// } else { |
|
|
|
// //回归 |
|
|
|
// position = tmpPosition |
|
|
|
// pid = smallMakeSearchPid(position, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// //新的一级 |
|
|
|
// tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0].FatherUid, m.Position)))) |
|
|
|
// position = smallSearchPositionFirstSonPosition(tmpPosition, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
// smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level) |
|
|
|
// pid = tmpPosition |
|
|
|
// } |
|
|
|
//} |
|
|
|
} |
|
|
|
|
|
|
|
//2、查找对应pid的 user_public_platoon_relation 记录 |
|
|
@@ -243,10 +258,22 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl |
|
|
|
|
|
|
|
//唯一标识符(父级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) |
|
|
|
<<<<<<< HEAD |
|
|
|
if userPublicPlatoonSetting.SettleDay == 0 { |
|
|
|
userPublicPlatoonSetting.SettleDay = 30 |
|
|
|
} |
|
|
|
// 3、插入 user_public_platoon_relation 记录 |
|
|
|
======= |
|
|
|
// 3、改变直属父级的 has_son_num 数量 |
|
|
|
update, err := engine.Where("position = ?", pid).SetExpr("has_son_num", "has_son_num + 1").Update(new(model.UserSmallPublicPlatoonRelation)) |
|
|
|
if err != nil { |
|
|
|
return userSmallPublicPlatoonRelation, err |
|
|
|
} |
|
|
|
if update == 0 { |
|
|
|
return userSmallPublicPlatoonRelation, errors.New("更新has_son_num数据出错") |
|
|
|
} |
|
|
|
// 4、插入 user_public_platoon_relation 记录 |
|
|
|
>>>>>>> 64fd8a9 (update) |
|
|
|
now := time.Now() |
|
|
|
userSmallPublicPlatoonRelation.Uid = uid |
|
|
|
userSmallPublicPlatoonRelation.FatherUid = fatherUid |
|
|
@@ -259,6 +286,7 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl |
|
|
|
userSmallPublicPlatoonRelation.JoinAt = now |
|
|
|
userSmallPublicPlatoonRelation.CreateAt = now // |
|
|
|
userSmallPublicPlatoonRelation.UpdateAt = now |
|
|
|
userSmallPublicPlatoonRelation.HasSonNum = 0 |
|
|
|
_, err = db.UserSmallPublicPlatoonRelationInsert(engine, &userSmallPublicPlatoonRelation) |
|
|
|
if err != nil { |
|
|
|
return model.UserSmallPublicPlatoonRelation{}, err |
|
|
@@ -347,6 +375,36 @@ func smallReverseDeductionPosition(calcPosition, levelFirstPosition, severalTime |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func smallFindSuitablePosition(engine *xorm.Engine, position *int, severalTimes float64, fatherLevel int) (suitablePosition, pid int, level float64, err error) { |
|
|
|
firstSonPosition := smallSearchPositionFirstSonPosition(*position, int(severalTimes)) |
|
|
|
var tempLevel float64 |
|
|
|
smallMakeSearchLevel(&firstSonPosition, severalTimes, &tempLevel) |
|
|
|
firstSonLevel := int(tempLevel) |
|
|
|
endSonPosition := firstSonPosition + int(math.Pow(severalTimes, float64(fatherLevel-firstSonLevel))) - 1 |
|
|
|
list, _, err := db.UserSmallPublicPlatoonRelationFindCountByPosition(engine, int64(firstSonPosition), int64(endSonPosition)) |
|
|
|
if err != nil { |
|
|
|
return 0, 0, 0, err |
|
|
|
} |
|
|
|
if list[0].HasSonNum == int(severalTimes) { |
|
|
|
//TODO::则证明该层直属下级无空位 |
|
|
|
position = &firstSonPosition |
|
|
|
return smallFindSuitablePosition(engine, position, severalTimes, fatherLevel) |
|
|
|
} else if list[0].HasSonNum == 0 { |
|
|
|
//TODO::新的一层 |
|
|
|
suitablePosition = smallSearchPositionFirstSonPosition(*position, int(severalTimes)) |
|
|
|
pid = firstSonPosition |
|
|
|
level = float64(firstSonLevel + 1) |
|
|
|
} else { |
|
|
|
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPid(engine, list[0].Position) |
|
|
|
if err != nil { |
|
|
|
return 0, 0, 0, err |
|
|
|
} |
|
|
|
return userSmallPublicPlatoonRelations[0].Position + 1, userSmallPublicPlatoonRelations[0].Pid, float64(userSmallPublicPlatoonRelations[0].Level), nil |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// smallGetLevelForFirstPosition 返回当前等级的起始值 |
|
|
|
func smallGetLevelForFirstPosition(level, severalTimes int) (position int) { |
|
|
|
position = position + 1 |
|
|
|