Browse Source

update 共富制度

tags/v1.7.5
DengBiao 2 years ago
parent
commit
e69b0e330c
4 changed files with 544 additions and 252 deletions
  1. +9
    -13
      db/db_user_small_public_platoon_relation.go
  2. +40
    -5
      db/model/user_small_public_platoon_relation.go
  3. +40
    -0
      md/small_public_platoon_relate_commission.go
  4. +455
    -234
      rule/small_public_platoon_relate_commission.go

+ 9
- 13
db/db_user_small_public_platoon_relation.go View File

@@ -101,28 +101,24 @@ func UserSmallPublicPlatoonRelationGetOneByPid(Db *xorm.Engine, recommendUid str
return &m, nil
}

func UserSmallPublicPlatoonRelationFindByPid(Db *xorm.Engine, pid int) ([]model.UserSmallPublicPlatoonRelation, error) {
func UserSmallPublicPlatoonRelationFindByPid(Db *xorm.Engine, pid, fatherUid int, pidName, fatherName, positionName string) ([]model.UserSmallPublicPlatoonRelation, error) {
var m []model.UserSmallPublicPlatoonRelation
if err := Db.Where("pid = ?", pid).OrderBy("position Desc").
var query1 = fmt.Sprintf("%s >= ?", pidName)
var query2 = fmt.Sprintf("%s = ?", fatherName)
var order = fmt.Sprintf("%s Desc", positionName)
if err := Db.Where(query1, pid).And(query2, fatherUid).OrderBy(order).
Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return m, nil
}

func UserSmallPublicPlatoonRelationFindByPidLike(Db *xorm.Engine, pid string) ([]model.UserSmallPublicPlatoonRelation, error) {
var m []model.UserSmallPublicPlatoonRelation
if err := Db.Where("father_uid like ?", "%"+pid+"%").OrderBy("id Desc").
Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return m, nil
}

func UserSmallPublicPlatoonRelationFindCountByPosition(Db *xorm.Engine, startPosition, endPosition int64) ([]model.UserSmallPublicPlatoonRelation, int64, error) {
func UserSmallPublicPlatoonRelationFindCountByPosition(Db *xorm.Engine, positionName string, startPosition, endPosition int64) ([]model.UserSmallPublicPlatoonRelation, int64, error) {
var m []model.UserSmallPublicPlatoonRelation
var count int64
if count, err := Db.Where("position >= ?", startPosition).And("position <= ?", endPosition).OrderBy("has_son_num Desc").
var query1 = fmt.Sprintf("%s >= ?", positionName)
var query2 = fmt.Sprintf("%s <= ?", positionName)
if count, err := Db.Where(query1, startPosition).And(query2, endPosition).OrderBy("has_son_num ASC").
FindAndCount(&m); err != nil {
return nil, count, zhios_order_relate_logx.Warn(err)
}


+ 40
- 5
db/model/user_small_public_platoon_relation.go View File

@@ -7,12 +7,47 @@ import (
type UserSmallPublicPlatoonRelation struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id(若为-1,则代表等待新用户填充)') unique INT(11)"`
FatherUid string `json:"father_uid" xorm:"not null default '' comment('父级id(123456-563464-438384)') index VARCHAR(100)"`
Pid int `json:"pid" xorm:"not null default 0 comment('父级id') INT(11)"`
RecommendUid int `json:"recommend_uid" xorm:"not null default 0 comment('推荐人id') INT(11)"`
Level int `json:"level" xorm:"not null default 1 comment('等级(整个系统)') INT(11)"`
Position int `json:"position" xorm:"not null default 1 comment('位置') unique INT(11)"`
UniqueIdentifier string `json:"unique_identifier" xorm:"not null default '' comment('唯一标识符(父级id-uid-等级-位置)') unique CHAR(100)"`
FatherUid string `json:"father_uid" xorm:"not null default '' comment('父级uid(123456-563464-438384)') index VARCHAR(100)"`
FatherUid1 int `json:"father_uid1" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid2 int `json:"father_uid2" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid3 int `json:"father_uid3" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid4 int `json:"father_uid4" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid5 int `json:"father_uid5" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid6 int `json:"father_uid6" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid7 int `json:"father_uid7" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid8 int `json:"father_uid8" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
FatherUid9 int `json:"father_uid9" xorm:"not null default 0 comment('父级uid_1)') INT(11)"`
Pid1 int `json:"pid1" xorm:"not null default 0 comment('父级id_1)') INT(11)"`
Pid2 int `json:"pid2" xorm:"not null default 0 comment('父级id_2') INT(11)"`
Pid3 int `json:"pid3" xorm:"not null default 0 comment('父级id_3') INT(11)"`
Pid4 int `json:"pid4" xorm:"not null default 0 comment('父级id_4') INT(11)"`
Pid5 int `json:"pid5" xorm:"not null default 0 comment('父级id_5') INT(11)"`
Pid6 int `json:"pid6" xorm:"not null default 0 comment('父级id_6') INT(11)"`
Pid7 int `json:"pid7" xorm:"not null default 0 comment('父级id_7') INT(11)"`
Pid8 int `json:"pid8" xorm:"not null default 0 comment('父级id_8') INT(11)"`
Pid9 int `json:"pid9" xorm:"not null default 0 comment('父级id_9') INT(11)"`
Position int `json:"position" xorm:"not null default 1 comment('位置(以自己为创始人)') unique INT(11)"`
Position1 int `json:"position1" xorm:"not null default 1 comment('位置_1(以pid1为创始人中网的位置)') unique INT(11)"`
Position2 int `json:"position2" xorm:"not null default 1 comment('位置_2') unique INT(11)"`
Position3 int `json:"position3" xorm:"not null default 1 comment('位置_3') unique INT(11)"`
Position4 int `json:"position4" xorm:"not null default 1 comment('位置_4') unique INT(11)"`
Position5 int `json:"position5" xorm:"not null default 1 comment('位置_5') unique INT(11)"`
Position6 int `json:"position6" xorm:"not null default 1 comment('位置_6') unique INT(11)"`
Position7 int `json:"position7" xorm:"not null default 1 comment('位置_7') unique INT(11)"`
Position8 int `json:"position8" xorm:"not null default 1 comment('位置_8') unique INT(11)"`
Position9 int `json:"position9" xorm:"not null default 1 comment('位置_9') unique INT(11)"`
Level int `json:"level" xorm:"not null default 1 comment('等级(以自己为创始人)') INT(11)"`
Level1 int `json:"level1" xorm:"not null default 1 comment('等级_1(以pid1为创始人中网的等级)') INT(11)"`
Level2 int `json:"level2" xorm:"not null default 1 comment('等级_2') INT(11)"`
Level3 int `json:"level3" xorm:"not null default 1 comment('等级_3') INT(11)"`
Level4 int `json:"level4" xorm:"not null default 1 comment('等级_4') INT(11)"`
Level5 int `json:"level5" xorm:"not null default 1 comment('等级_5') INT(11)"`
Level6 int `json:"level6" xorm:"not null default 1 comment('等级_6') INT(11)"`
Level7 int `json:"level7" xorm:"not null default 1 comment('等级_7') INT(11)"`
Level8 int `json:"level8" xorm:"not null default 1 comment('等级_8') INT(11)"`
Level9 int `json:"level9" xorm:"not null default 1 comment('等级_9') INT(11)"`
LevelTotal int `json:"level_total" xorm:"not null default 1 comment('等级(整个系统)') INT(11)"`
ReturnCommissionNum int `json:"return_commission_num" xorm:"not null default 0 comment('返佣次数') INT(11)"`
JoinAt time.Time `json:"join_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('加入公排时间') DATETIME"`
WaitForSettlementDate string `json:"wait_for_settlement_date" xorm:"not null default '' comment('待结算时间(0000-00)') CHAR(50)"`


+ 40
- 0
md/small_public_platoon_relate_commission.go View File

@@ -35,3 +35,43 @@ type SmallAddPublicPlatoonRelateCommissionReq struct {
Uid string `json:"uid"`
RecommendUid string `json:"recommend_uid"` //推荐人uid
}

type StandardSmallPublicPlatoonRelation struct {
FatherUid1 int `json:"father_uid1"`
FatherUid2 int `json:"father_uid2"`
FatherUid3 int `json:"father_uid3"`
FatherUid4 int `json:"father_uid4"`
FatherUid5 int `json:"father_uid5"`
FatherUid6 int `json:"father_uid6"`
FatherUid7 int `json:"father_uid7"`
FatherUid8 int `json:"father_uid8"`
FatherUid9 int `json:"father_uid9"`
Pid1 int `json:"pid1"`
Pid2 int `json:"pid2"`
Pid3 int `json:"pid3"`
Pid4 int `json:"pid4"`
Pid5 int `json:"pid5"`
Pid6 int `json:"pid6"`
Pid7 int `json:"pid7"`
Pid8 int `json:"pid8"`
Pid9 int `json:"pid9"`
Position1 int `json:"position1"`
Position2 int `json:"position2"`
Position3 int `json:"position3"`
Position4 int `json:"position4"`
Position5 int `json:"position5"`
Position6 int `json:"position6"`
Position7 int `json:"position7"`
Position8 int `json:"position8"`
Position9 int `json:"position9"`
Level1 int `json:"level1"`
Level2 int `json:"level2"`
Level3 int `json:"level3"`
Level4 int `json:"level4"`
Level5 int `json:"level5"`
Level6 int `json:"level6"`
Level7 int `json:"level7"`
Level8 int `json:"level8"`
Level9 int `json:"level9"`
LevelTotal int `json:"level_total"`
}

+ 455
- 234
rule/small_public_platoon_relate_commission.go View File

@@ -49,9 +49,6 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl
}
if userSmallPublicPlatoonRelation != nil {
userSmallPublicPlatoonRelation.Uid = zhios_order_relate_utils.StrToInt(param.Uid)
uniqueIdentifier := strings.Split(userSmallPublicPlatoonRelation.UniqueIdentifier, "-")
uniqueIdentifier[1] = param.Uid
userSmallPublicPlatoonRelation.UniqueIdentifier = strings.Join(uniqueIdentifier, "-")
updateAffected, err := db.UserSmallPublicPlatoonRelationUpdate(engine.NewSession(), userSmallPublicPlatoonRelation.Id, userSmallPublicPlatoonRelation)
if err != nil {
return nil, err
@@ -69,58 +66,57 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl
return nil, err
}
resp[param.Uid] = &res
} else {
//3、无推荐人

//3.1 判断是否有uid为-1 (代表等待新用户填充) 的记录
userSmallPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationFindByEmptyPosition(engine)
if err != nil {
return nil, err
}
if userSmallPublicPlatoonRelation != nil {
userSmallPublicPlatoonRelation.Uid = zhios_order_relate_utils.StrToInt(param.Uid)
uniqueIdentifier := strings.Split(userSmallPublicPlatoonRelation.UniqueIdentifier, "-")
uniqueIdentifier[1] = param.Uid
userSmallPublicPlatoonRelation.UniqueIdentifier = strings.Join(uniqueIdentifier, "-")
updateAffected, err := db.UserSmallPublicPlatoonRelationUpdate(engine.NewSession(), userSmallPublicPlatoonRelation.Id, userSmallPublicPlatoonRelation)
if err != nil {
return nil, err
}
if updateAffected == 0 {
err = errors.New("更新 user_public_platoon_relation 记录失败")
return nil, err
} else {
resp[param.Uid] = userSmallPublicPlatoonRelation
}
continue
}

// 查找当前 user_public_platoon_relation 中 `position` 最大的记录
var m model.UserSmallPublicPlatoonRelation
has, err := engine.Where("recommend_uid = 0").OrderBy("id desc").Get(&m)
if err != nil {
return nil, err
}
if has == false {
return nil, errors.New("查询 user_public_platoon_relation 记录失败")
}

// 查找当前大于 `position` 的所有记录
mlist, err := db.UserSmallPublicPlatoonRelationFindRecommends(engine)
if err != nil {
return nil, err
}
var mapBigUserSmallPublicPlatoonRelations = map[int]interface{}{}
for _, item := range mlist {
mapBigUserSmallPublicPlatoonRelations[item.Position] = true
}

res, err := naturalSmallPublicPlatoon(engine, zhios_order_relate_utils.StrToInt(param.Uid), &m.Position, *userPublicPlatoonSetting, mapBigUserSmallPublicPlatoonRelations)
if err != nil {
return nil, err
}
resp[param.Uid] = &res
}

//else {
// //3、无推荐人
//
// //3.1 判断是否有uid为-1 (代表等待新用户填充) 的记录
// userSmallPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationFindByEmptyPosition(engine)
// if err != nil {
// return nil, err
// }
// if userSmallPublicPlatoonRelation != nil {
// userSmallPublicPlatoonRelation.Uid = zhios_order_relate_utils.StrToInt(param.Uid)
// updateAffected, err := db.UserSmallPublicPlatoonRelationUpdate(engine.NewSession(), userSmallPublicPlatoonRelation.Id, userSmallPublicPlatoonRelation)
// if err != nil {
// return nil, err
// }
// if updateAffected == 0 {
// err = errors.New("更新 user_public_platoon_relation 记录失败")
// return nil, err
// } else {
// resp[param.Uid] = userSmallPublicPlatoonRelation
// }
// continue
// }
//
// // 查找当前 user_public_platoon_relation 中 `position` 最大的记录
// var m model.UserSmallPublicPlatoonRelation
// has, err := engine.Where("recommend_uid = 0").OrderBy("id desc").Get(&m)
// if err != nil {
// return nil, err
// }
// if has == false {
// return nil, errors.New("查询 user_public_platoon_relation 记录失败")
// }
//
// // 查找当前大于 `position` 的所有记录
// mlist, err := db.UserSmallPublicPlatoonRelationFindRecommends(engine)
// if err != nil {
// return nil, err
// }
// var mapBigUserSmallPublicPlatoonRelations = map[int]interface{}{}
// for _, item := range mlist {
// mapBigUserSmallPublicPlatoonRelations[item.Position] = true
// }
//
// res, err := naturalSmallPublicPlatoon(engine, zhios_order_relate_utils.StrToInt(param.Uid), &m.Position, *userPublicPlatoonSetting, mapBigUserSmallPublicPlatoonRelations)
// if err != nil {
// return nil, err
// }
// resp[param.Uid] = &res
//}
}
return resp, nil
}
@@ -134,8 +130,9 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl
4: 根据最新自增`id` 逆向推导 position {levelFirstPosition + (position-1)%5}
*/
func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPlatoonSetting model.UserPublicPlatoonSetting) (model.UserSmallPublicPlatoonRelation, error) {
var standardSmallPublicPlatoonRelation md.StandardSmallPublicPlatoonRelation
var userSmallPublicPlatoonRelation model.UserSmallPublicPlatoonRelation
var fatherUid int
//1、 查找当前 user_small_public_platoon_relation 中 recommendUid 的记录
m, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "uid",
@@ -146,141 +143,169 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl
}

//2、 查找当前 user_small_public_platoon_relation 中 recommendUid 所有的子记录
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPid(engine, m.Position)
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPid(engine, m.Position1, m.Uid, "pid1", "father_uid1", "position1")
if err != nil {
return model.UserSmallPublicPlatoonRelation{}, err
}

var position, pid int
var level float64
if len(userSmallPublicPlatoonRelations) == 0 {
fatherUid = m.Uid

//证明是第一个
position = smallSearchPositionFirstSonPosition(m.Position, userPublicPlatoonSetting.SeveralTimes)
level = float64(m.Level) + 1
pid = m.Position
standardSmallPublicPlatoonRelation.FatherUid1 = m.Uid
standardSmallPublicPlatoonRelation.FatherUid2 = m.FatherUid1
standardSmallPublicPlatoonRelation.FatherUid3 = m.FatherUid2
standardSmallPublicPlatoonRelation.FatherUid4 = m.FatherUid3
standardSmallPublicPlatoonRelation.FatherUid5 = m.FatherUid4
standardSmallPublicPlatoonRelation.FatherUid6 = m.FatherUid5
standardSmallPublicPlatoonRelation.FatherUid7 = m.FatherUid6
standardSmallPublicPlatoonRelation.FatherUid8 = m.FatherUid7
standardSmallPublicPlatoonRelation.FatherUid9 = m.FatherUid8

standardSmallPublicPlatoonRelation.Pid1 = m.Position
standardSmallPublicPlatoonRelation.Pid2 = m.Position1
standardSmallPublicPlatoonRelation.Pid3 = m.Position2
standardSmallPublicPlatoonRelation.Pid4 = m.Position3
standardSmallPublicPlatoonRelation.Pid5 = m.Position4
standardSmallPublicPlatoonRelation.Pid6 = m.Position5
standardSmallPublicPlatoonRelation.Pid7 = m.Position6
standardSmallPublicPlatoonRelation.Pid8 = m.Position7
standardSmallPublicPlatoonRelation.Pid9 = m.Position8

standardSmallPublicPlatoonRelation.Position1 = smallSearchPositionFirstSonPosition(m.Position, userPublicPlatoonSetting.SeveralTimes)
standardSmallPublicPlatoonRelation.Position2 = smallReverseDeductionPositionByFather(m.Position1, m.Level1, userPublicPlatoonSetting.SeveralTimes, 0)
standardSmallPublicPlatoonRelation.Position3 = smallReverseDeductionPositionByFather(m.Position2, m.Level2, userPublicPlatoonSetting.SeveralTimes, 0)
standardSmallPublicPlatoonRelation.Position4 = smallReverseDeductionPositionByFather(m.Position3, m.Level3, userPublicPlatoonSetting.SeveralTimes, 0)
standardSmallPublicPlatoonRelation.Position5 = smallReverseDeductionPositionByFather(m.Position4, m.Level4, userPublicPlatoonSetting.SeveralTimes, 0)
standardSmallPublicPlatoonRelation.Position6 = smallReverseDeductionPositionByFather(m.Position5, m.Level5, userPublicPlatoonSetting.SeveralTimes, 0)
standardSmallPublicPlatoonRelation.Position7 = smallReverseDeductionPositionByFather(m.Position6, m.Level6, userPublicPlatoonSetting.SeveralTimes, 0)
standardSmallPublicPlatoonRelation.Position8 = smallReverseDeductionPositionByFather(m.Position7, m.Level7, userPublicPlatoonSetting.SeveralTimes, 0)
standardSmallPublicPlatoonRelation.Position9 = smallReverseDeductionPositionByFather(m.Position8, m.Level8, userPublicPlatoonSetting.SeveralTimes, 0)

standardSmallPublicPlatoonRelation.Level1 = m.Level + 1
standardSmallPublicPlatoonRelation.Level2 = m.Level1 + 1
standardSmallPublicPlatoonRelation.Level3 = m.Level2 + 1
standardSmallPublicPlatoonRelation.Level4 = m.Level3 + 1
standardSmallPublicPlatoonRelation.Level5 = m.Level4 + 1
standardSmallPublicPlatoonRelation.Level6 = m.Level5 + 1
standardSmallPublicPlatoonRelation.Level7 = m.Level6 + 1
standardSmallPublicPlatoonRelation.Level8 = m.Level7 + 1
standardSmallPublicPlatoonRelation.Level9 = m.Level8 + 1
standardSmallPublicPlatoonRelation.LevelTotal = m.LevelTotal + 1
} else {
//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))
var times = 1
data, father, err := smallFindSuitablePosition(engine, &m.Position, float64(userPublicPlatoonSetting.SeveralTimes), int(fatherLevel), &times)
if err != nil {
return model.UserSmallPublicPlatoonRelation{}, err
}
fatherUid = father
standardSmallPublicPlatoonRelation = data
} else {
position = m.Position + 1
level = float64(m.Level) + 1
pid = m.Position
fatherUid = m.Uid

standardSmallPublicPlatoonRelation.FatherUid1 = m.Uid
standardSmallPublicPlatoonRelation.FatherUid2 = m.FatherUid1
standardSmallPublicPlatoonRelation.FatherUid3 = m.FatherUid2
standardSmallPublicPlatoonRelation.FatherUid4 = m.FatherUid3
standardSmallPublicPlatoonRelation.FatherUid5 = m.FatherUid4
standardSmallPublicPlatoonRelation.FatherUid6 = m.FatherUid5
standardSmallPublicPlatoonRelation.FatherUid7 = m.FatherUid6
standardSmallPublicPlatoonRelation.FatherUid8 = m.FatherUid7
standardSmallPublicPlatoonRelation.FatherUid9 = m.FatherUid8

standardSmallPublicPlatoonRelation.Pid1 = m.Position
standardSmallPublicPlatoonRelation.Pid2 = m.Position1
standardSmallPublicPlatoonRelation.Pid3 = m.Position2
standardSmallPublicPlatoonRelation.Pid4 = m.Position3
standardSmallPublicPlatoonRelation.Pid5 = m.Position4
standardSmallPublicPlatoonRelation.Pid6 = m.Position5
standardSmallPublicPlatoonRelation.Pid7 = m.Position6
standardSmallPublicPlatoonRelation.Pid8 = m.Position7
standardSmallPublicPlatoonRelation.Pid9 = m.Position8

standardSmallPublicPlatoonRelation.Position1 = userSmallPublicPlatoonRelations[0].Position1 + 1
standardSmallPublicPlatoonRelation.Position2 = userSmallPublicPlatoonRelations[0].Position2 + 1
standardSmallPublicPlatoonRelation.Position3 = userSmallPublicPlatoonRelations[0].Position3 + 1
standardSmallPublicPlatoonRelation.Position4 = userSmallPublicPlatoonRelations[0].Position4 + 1
standardSmallPublicPlatoonRelation.Position5 = userSmallPublicPlatoonRelations[0].Position5 + 1
standardSmallPublicPlatoonRelation.Position6 = userSmallPublicPlatoonRelations[0].Position6 + 1
standardSmallPublicPlatoonRelation.Position7 = userSmallPublicPlatoonRelations[0].Position7 + 1
standardSmallPublicPlatoonRelation.Position8 = userSmallPublicPlatoonRelations[0].Position8 + 1
standardSmallPublicPlatoonRelation.Position9 = userSmallPublicPlatoonRelations[0].Position9 + 1

standardSmallPublicPlatoonRelation.Level1 = userSmallPublicPlatoonRelations[0].Level1
standardSmallPublicPlatoonRelation.Level2 = userSmallPublicPlatoonRelations[0].Level2
standardSmallPublicPlatoonRelation.Level3 = userSmallPublicPlatoonRelations[0].Level3
standardSmallPublicPlatoonRelation.Level4 = userSmallPublicPlatoonRelations[0].Level4
standardSmallPublicPlatoonRelation.Level5 = userSmallPublicPlatoonRelations[0].Level5
standardSmallPublicPlatoonRelation.Level6 = userSmallPublicPlatoonRelations[0].Level6
standardSmallPublicPlatoonRelation.Level7 = userSmallPublicPlatoonRelations[0].Level7
standardSmallPublicPlatoonRelation.Level8 = userSmallPublicPlatoonRelations[0].Level8
standardSmallPublicPlatoonRelation.Level9 = userSmallPublicPlatoonRelations[0].Level9
standardSmallPublicPlatoonRelation.LevelTotal = userSmallPublicPlatoonRelations[0].LevelTotal

}

//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 记录
var m1 model.UserSmallPublicPlatoonRelation
if has, err := engine.Where("position=?", pid).Get(&m1); err != nil || has == false {
if has, err := engine.Where("uid=?", fatherUid).Get(&m1); err != nil || has == false {
return userSmallPublicPlatoonRelation, err
}
var fatherUid string
var fatherUidStr string
if m1.FatherUid == "" {
//TODO::顶级
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position)
fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Position)
} else {
fatherUids := strings.Split(m1.FatherUid, "-")
if len(fatherUids) > userPublicPlatoonSetting.SeveralRows {
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + strings.Join(fatherUids[0:userPublicPlatoonSetting.SeveralRows:len(fatherUids)], "-")
fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Uid) + "-" + strings.Join(fatherUids[0:userPublicPlatoonSetting.SeveralRows:len(fatherUids)], "-")
} else {
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + m1.FatherUid
fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Uid) + "-" + m1.FatherUid
}
}

//唯一标识符(父级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)

if userPublicPlatoonSetting.SettleDay == 0 {
userPublicPlatoonSetting.SettleDay = 30
}

// 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 记录
// 3、插入 user_public_platoon_relation 记录
now := time.Now()
userSmallPublicPlatoonRelation.Uid = uid
userSmallPublicPlatoonRelation.FatherUid = fatherUid
userSmallPublicPlatoonRelation.Pid = pid
userSmallPublicPlatoonRelation.FatherUid = fatherUidStr
userSmallPublicPlatoonRelation.Pid1 = standardSmallPublicPlatoonRelation.Pid1
userSmallPublicPlatoonRelation.Pid2 = standardSmallPublicPlatoonRelation.Pid2
userSmallPublicPlatoonRelation.Pid3 = standardSmallPublicPlatoonRelation.Pid3
userSmallPublicPlatoonRelation.Pid4 = standardSmallPublicPlatoonRelation.Pid4
userSmallPublicPlatoonRelation.Pid5 = standardSmallPublicPlatoonRelation.Pid5
userSmallPublicPlatoonRelation.Pid6 = standardSmallPublicPlatoonRelation.Pid6
userSmallPublicPlatoonRelation.Pid7 = standardSmallPublicPlatoonRelation.Pid7
userSmallPublicPlatoonRelation.Pid8 = standardSmallPublicPlatoonRelation.Pid8
userSmallPublicPlatoonRelation.Pid9 = standardSmallPublicPlatoonRelation.Pid9
userSmallPublicPlatoonRelation.Position1 = standardSmallPublicPlatoonRelation.Position1
userSmallPublicPlatoonRelation.Position2 = standardSmallPublicPlatoonRelation.Position2
userSmallPublicPlatoonRelation.Position3 = standardSmallPublicPlatoonRelation.Position3
userSmallPublicPlatoonRelation.Position4 = standardSmallPublicPlatoonRelation.Position4
userSmallPublicPlatoonRelation.Position5 = standardSmallPublicPlatoonRelation.Position5
userSmallPublicPlatoonRelation.Position6 = standardSmallPublicPlatoonRelation.Position6
userSmallPublicPlatoonRelation.Position7 = standardSmallPublicPlatoonRelation.Position7
userSmallPublicPlatoonRelation.Position8 = standardSmallPublicPlatoonRelation.Position8
userSmallPublicPlatoonRelation.Position9 = standardSmallPublicPlatoonRelation.Position9
userSmallPublicPlatoonRelation.Level1 = standardSmallPublicPlatoonRelation.Level1
userSmallPublicPlatoonRelation.Level2 = standardSmallPublicPlatoonRelation.Level2
userSmallPublicPlatoonRelation.Level3 = standardSmallPublicPlatoonRelation.Level3
userSmallPublicPlatoonRelation.Level4 = standardSmallPublicPlatoonRelation.Level4
userSmallPublicPlatoonRelation.Level5 = standardSmallPublicPlatoonRelation.Level5
userSmallPublicPlatoonRelation.Level6 = standardSmallPublicPlatoonRelation.Level6
userSmallPublicPlatoonRelation.Level7 = standardSmallPublicPlatoonRelation.Level7
userSmallPublicPlatoonRelation.Level8 = standardSmallPublicPlatoonRelation.Level8
userSmallPublicPlatoonRelation.Level9 = standardSmallPublicPlatoonRelation.Level9
userSmallPublicPlatoonRelation.RecommendUid = recommendUid
userSmallPublicPlatoonRelation.Level = int(level)
userSmallPublicPlatoonRelation.Position = position
userSmallPublicPlatoonRelation.UniqueIdentifier = uniqueIdentifier
userSmallPublicPlatoonRelation.WaitForSettlementDate = now.AddDate(0, 0, userPublicPlatoonSetting.SettleDay).Format("2006-01-02")
userSmallPublicPlatoonRelation.JoinAt = now
userSmallPublicPlatoonRelation.CreateAt = now //
@@ -290,83 +315,92 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl
if err != nil {
return model.UserSmallPublicPlatoonRelation{}, err
}
return userSmallPublicPlatoonRelation, nil
}

func naturalSmallPublicPlatoon(engine *xorm.Engine, uid int, originalPosition *int, userPublicPlatoonSetting model.UserPublicPlatoonSetting, mapBigUserSmallPublicPlatoonRelations map[int]interface{}) (model.UserSmallPublicPlatoonRelation, error) {
var userPublicPlatoonRelation model.UserSmallPublicPlatoonRelation
//TODO::判断 `position + userPublicPlatoonSetting.SeveralTimes(几乘)` OR `position + 1`
var position, position1, position2 int
position1 = *originalPosition + 1
position2 = *originalPosition + userPublicPlatoonSetting.SeveralTimes
var level, level1, level2 float64
smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level1)
smallMakeSearchLevel(&position2, float64(userPublicPlatoonSetting.SeveralTimes), &level2)
level = level1
if level > 2 {
if level1 != level2 {
position = smallReverseDeductionPosition(*originalPosition, smallGetLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes), userPublicPlatoonSetting.SeveralTimes)
} else {
if position1 == smallGetLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes) {
position = position1
} else {
position = position2
}
}
} else {
position = position1
}
if mapBigUserSmallPublicPlatoonRelations[position] != nil {
originalPosition = &position
return naturalSmallPublicPlatoon(engine, uid, originalPosition, userPublicPlatoonSetting, mapBigUserSmallPublicPlatoonRelations)
}

pid := makeSearchPid(position, userPublicPlatoonSetting.SeveralTimes)

//2、查找对应pid的 user_public_platoon_relation 记录
var m1 model.UserSmallPublicPlatoonRelation
if has, err := engine.Where("position=?", pid).Get(&m1); err != nil || has == false {
return userPublicPlatoonRelation, err
}
var fatherUid string
if m1.FatherUid == "" {
//TODO::顶级
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position)
} else {
fatherUids := strings.Split(m1.FatherUid, "-")
if len(fatherUids) > userPublicPlatoonSetting.SeveralRows {
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + strings.Join(fatherUids[0:userPublicPlatoonSetting.SeveralRows:len(fatherUids)], "-")
} else {
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + m1.FatherUid
}
}

//唯一标识符(父级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 记录
if userPublicPlatoonSetting.SettleDay == 0 {
userPublicPlatoonSetting.SettleDay = 30
}
now := time.Now()
userPublicPlatoonRelation.Uid = uid
userPublicPlatoonRelation.FatherUid = fatherUid
userPublicPlatoonRelation.Pid = pid
userPublicPlatoonRelation.RecommendUid = 0
userPublicPlatoonRelation.Level = int(level)
userPublicPlatoonRelation.Position = position
userPublicPlatoonRelation.UniqueIdentifier = uniqueIdentifier
userPublicPlatoonRelation.WaitForSettlementDate = now.AddDate(0, 0, userPublicPlatoonSetting.SettleDay).Format("2006-01-02")
userPublicPlatoonRelation.JoinAt = now
userPublicPlatoonRelation.CreateAt = now
userPublicPlatoonRelation.UpdateAt = now
_, err := db.UserSmallPublicPlatoonRelationInsert(engine, &userPublicPlatoonRelation)
// 4、改变直属父级的 has_son_num 数量
update, err := engine.Where("uid = ?", fatherUid).SetExpr("has_son_num", "has_son_num + 1").Update(new(model.UserSmallPublicPlatoonRelation))
if err != nil {
return model.UserSmallPublicPlatoonRelation{}, err
return userSmallPublicPlatoonRelation, err
}
if update == 0 {
return userSmallPublicPlatoonRelation, errors.New("更新has_son_num数据出错")
}
return userPublicPlatoonRelation, nil
return userSmallPublicPlatoonRelation, nil
}

//func naturalSmallPublicPlatoon(engine *xorm.Engine, uid int, originalPosition *int, userPublicPlatoonSetting model.UserPublicPlatoonSetting, mapBigUserSmallPublicPlatoonRelations map[int]interface{}) (model.UserSmallPublicPlatoonRelation, error) {
// var userPublicPlatoonRelation model.UserSmallPublicPlatoonRelation
// //TODO::判断 `position + userPublicPlatoonSetting.SeveralTimes(几乘)` OR `position + 1`
// var position, position1, position2 int
// position1 = *originalPosition + 1
// position2 = *originalPosition + userPublicPlatoonSetting.SeveralTimes
// var level, level1, level2 float64
// smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level1)
// smallMakeSearchLevel(&position2, float64(userPublicPlatoonSetting.SeveralTimes), &level2)
// level = level1
// if level > 2 {
// if level1 != level2 {
// position = smallReverseDeductionPosition(*originalPosition, smallGetLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes), userPublicPlatoonSetting.SeveralTimes)
// } else {
// if position1 == smallGetLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes) {
// position = position1
// } else {
// position = position2
// }
// }
// } else {
// position = position1
// }
// if mapBigUserSmallPublicPlatoonRelations[position] != nil {
// originalPosition = &position
// return naturalSmallPublicPlatoon(engine, uid, originalPosition, userPublicPlatoonSetting, mapBigUserSmallPublicPlatoonRelations)
// }
//
// pid := makeSearchPid(position, userPublicPlatoonSetting.SeveralTimes)
//
// //2、查找对应pid的 user_public_platoon_relation 记录
// var m1 model.UserSmallPublicPlatoonRelation
// if has, err := engine.Where("position=?", pid).Get(&m1); err != nil || has == false {
// return userPublicPlatoonRelation, err
// }
// var fatherUid string
// if m1.FatherUid == "" {
// //TODO::顶级
// fatherUid = zhios_order_relate_utils.IntToStr(m1.Position)
// } else {
// fatherUids := strings.Split(m1.FatherUid, "-")
// if len(fatherUids) > userPublicPlatoonSetting.SeveralRows {
// fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + strings.Join(fatherUids[0:userPublicPlatoonSetting.SeveralRows:len(fatherUids)], "-")
// } else {
// fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + m1.FatherUid
// }
// }
//
// //唯一标识符(父级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 记录
// if userPublicPlatoonSetting.SettleDay == 0 {
// userPublicPlatoonSetting.SettleDay = 30
// }
// now := time.Now()
// userPublicPlatoonRelation.Uid = uid
// userPublicPlatoonRelation.FatherUid = fatherUid
// userPublicPlatoonRelation.Pid = pid
// userPublicPlatoonRelation.RecommendUid = 0
// userPublicPlatoonRelation.Level = int(level)
// userPublicPlatoonRelation.Position = position
// userPublicPlatoonRelation.UniqueIdentifier = uniqueIdentifier
// userPublicPlatoonRelation.WaitForSettlementDate = now.AddDate(0, 0, userPublicPlatoonSetting.SettleDay).Format("2006-01-02")
// userPublicPlatoonRelation.JoinAt = now
// userPublicPlatoonRelation.CreateAt = now
// userPublicPlatoonRelation.UpdateAt = now
// _, err := db.UserSmallPublicPlatoonRelationInsert(engine, &userPublicPlatoonRelation)
// if err != nil {
// return model.UserSmallPublicPlatoonRelation{}, err
// }
// return userPublicPlatoonRelation, nil
//}

// smallReverseDeductionPosition 逆向推导 position
func smallReverseDeductionPosition(calcPosition, levelFirstPosition, severalTimes int) (position int) {
remainder := (calcPosition - 1) % severalTimes
@@ -374,31 +408,218 @@ func smallReverseDeductionPosition(calcPosition, levelFirstPosition, severalTime
return
}

func smallFindSuitablePosition(engine *xorm.Engine, position *int, severalTimes float64, fatherLevel int) (suitablePosition, pid int, level float64, err error) {
func smallReverseDeductionPositionByFather(fatherPosition, level, severalTimes, remainder int) (position int) {
firstPosition := smallGetLevelForFirstPosition(level, severalTimes)
endPosition := firstPosition + int(math.Pow(float64(severalTimes), float64(level))) - 1
position = fatherPosition + (fatherPosition-firstPosition)*severalTimes + (endPosition - fatherPosition) + remainder
return
}

func smallFindSuitablePosition(engine *xorm.Engine, position *int, severalTimes float64, fatherLevel int, times *int) (standardSmallPublicPlatoonRelation md.StandardSmallPublicPlatoonRelation, fatherUid int, err error) {
*times++
positionName := "position" + zhios_order_relate_utils.IntToStr(*times)
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))
endSonPosition := firstSonPosition + int(math.Pow(severalTimes, float64(firstSonLevel-fatherLevel))) - 1
list, _, err := db.UserSmallPublicPlatoonRelationFindCountByPosition(engine, positionName, int64(firstSonPosition), int64(endSonPosition))
if err != nil {
return 0, 0, 0, err
return standardSmallPublicPlatoonRelation, fatherUid, err
}
if list[0].HasSonNum == int(severalTimes) {
//TODO::则证明该层直属下级无空位
position = &firstSonPosition
return smallFindSuitablePosition(engine, position, severalTimes, fatherLevel)
return smallFindSuitablePosition(engine, position, severalTimes, fatherLevel, times)
} else if list[0].HasSonNum == 0 {
fatherUid = list[0].Uid

//TODO::新的一层
suitablePosition = smallSearchPositionFirstSonPosition(*position, int(severalTimes))
pid = firstSonPosition
level = float64(firstSonLevel + 1)
standardSmallPublicPlatoonRelation.FatherUid1 = list[0].Uid
standardSmallPublicPlatoonRelation.FatherUid2 = list[0].FatherUid1
standardSmallPublicPlatoonRelation.FatherUid3 = list[0].FatherUid2
standardSmallPublicPlatoonRelation.FatherUid4 = list[0].FatherUid3
standardSmallPublicPlatoonRelation.FatherUid5 = list[0].FatherUid4
standardSmallPublicPlatoonRelation.FatherUid6 = list[0].FatherUid5
standardSmallPublicPlatoonRelation.FatherUid7 = list[0].FatherUid6
standardSmallPublicPlatoonRelation.FatherUid8 = list[0].FatherUid7
standardSmallPublicPlatoonRelation.FatherUid9 = list[0].FatherUid8

standardSmallPublicPlatoonRelation.Pid1 = list[0].Position
standardSmallPublicPlatoonRelation.Pid2 = list[0].Position1
standardSmallPublicPlatoonRelation.Pid3 = list[0].Position2
standardSmallPublicPlatoonRelation.Pid4 = list[0].Position3
standardSmallPublicPlatoonRelation.Pid5 = list[0].Position4
standardSmallPublicPlatoonRelation.Pid6 = list[0].Position5
standardSmallPublicPlatoonRelation.Pid7 = list[0].Position6
standardSmallPublicPlatoonRelation.Pid8 = list[0].Position7
standardSmallPublicPlatoonRelation.Pid9 = list[0].Position8

standardSmallPublicPlatoonRelation.Position1 = smallSearchPositionFirstSonPosition(list[0].Position, int(severalTimes))
standardSmallPublicPlatoonRelation.Position2 = smallReverseDeductionPositionByFather(list[0].Position1, list[0].Level1, int(severalTimes), 0)
standardSmallPublicPlatoonRelation.Position3 = smallReverseDeductionPositionByFather(list[0].Position2, list[0].Level2, int(severalTimes), 0)
standardSmallPublicPlatoonRelation.Position4 = smallReverseDeductionPositionByFather(list[0].Position3, list[0].Level3, int(severalTimes), 0)
standardSmallPublicPlatoonRelation.Position5 = smallReverseDeductionPositionByFather(list[0].Position4, list[0].Level4, int(severalTimes), 0)
standardSmallPublicPlatoonRelation.Position6 = smallReverseDeductionPositionByFather(list[0].Position5, list[0].Level5, int(severalTimes), 0)
standardSmallPublicPlatoonRelation.Position7 = smallReverseDeductionPositionByFather(list[0].Position6, list[0].Level6, int(severalTimes), 0)
standardSmallPublicPlatoonRelation.Position8 = smallReverseDeductionPositionByFather(list[0].Position7, list[0].Level7, int(severalTimes), 0)
standardSmallPublicPlatoonRelation.Position9 = smallReverseDeductionPositionByFather(list[0].Position8, list[0].Level8, int(severalTimes), 0)

standardSmallPublicPlatoonRelation.Level1 = list[0].Level + 1
standardSmallPublicPlatoonRelation.Level2 = list[0].Level1 + 1
standardSmallPublicPlatoonRelation.Level3 = list[0].Level2 + 1
standardSmallPublicPlatoonRelation.Level4 = list[0].Level3 + 1
standardSmallPublicPlatoonRelation.Level5 = list[0].Level4 + 1
standardSmallPublicPlatoonRelation.Level6 = list[0].Level5 + 1
standardSmallPublicPlatoonRelation.Level7 = list[0].Level6 + 1
standardSmallPublicPlatoonRelation.Level8 = list[0].Level7 + 1
standardSmallPublicPlatoonRelation.Level9 = list[0].Level8 + 1
standardSmallPublicPlatoonRelation.LevelTotal = list[0].LevelTotal + 1
} else {
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPid(engine, list[0].Position)
fatherUid = list[0].Uid

getPositionValue, _, _, _, getPositionName, gePidName, _, fatherUidName := getPosition(list[0], *times+1)
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPid(engine, getPositionValue, list[0].Uid, gePidName, fatherUidName, getPositionName)
//userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPid(engine, m.Position1, m.Uid, "pid1", "father_uid1", "position1")

if err != nil {
return 0, 0, 0, err
return standardSmallPublicPlatoonRelation, fatherUid, err
}

standardSmallPublicPlatoonRelation = md.StandardSmallPublicPlatoonRelation{
FatherUid1: userSmallPublicPlatoonRelations[0].FatherUid1,
FatherUid2: userSmallPublicPlatoonRelations[0].FatherUid2,
FatherUid3: userSmallPublicPlatoonRelations[0].FatherUid3,
FatherUid4: userSmallPublicPlatoonRelations[0].FatherUid4,
FatherUid5: userSmallPublicPlatoonRelations[0].FatherUid5,
FatherUid6: userSmallPublicPlatoonRelations[0].FatherUid6,
FatherUid7: userSmallPublicPlatoonRelations[0].FatherUid7,
FatherUid8: userSmallPublicPlatoonRelations[0].FatherUid8,
FatherUid9: userSmallPublicPlatoonRelations[0].FatherUid9,
Pid1: userSmallPublicPlatoonRelations[0].Pid1,
Pid2: userSmallPublicPlatoonRelations[0].Pid2,
Pid3: userSmallPublicPlatoonRelations[0].Pid3,
Pid4: userSmallPublicPlatoonRelations[0].Pid4,
Pid5: userSmallPublicPlatoonRelations[0].Pid5,
Pid6: userSmallPublicPlatoonRelations[0].Pid6,
Pid7: userSmallPublicPlatoonRelations[0].Pid7,
Pid8: userSmallPublicPlatoonRelations[0].Pid8,
Pid9: userSmallPublicPlatoonRelations[0].Pid9,
Position1: userSmallPublicPlatoonRelations[0].Position1 + 1,
Position2: userSmallPublicPlatoonRelations[0].Position2 + 1,
Position3: userSmallPublicPlatoonRelations[0].Position3 + 1,
Position4: userSmallPublicPlatoonRelations[0].Position4 + 1,
Position5: userSmallPublicPlatoonRelations[0].Position5 + 1,
Position6: userSmallPublicPlatoonRelations[0].Position6 + 1,
Position7: userSmallPublicPlatoonRelations[0].Position7 + 1,
Position8: userSmallPublicPlatoonRelations[0].Position8 + 1,
Position9: userSmallPublicPlatoonRelations[0].Position9 + 1,
Level1: userSmallPublicPlatoonRelations[0].Level1,
Level2: userSmallPublicPlatoonRelations[0].Level2,
Level3: userSmallPublicPlatoonRelations[0].Level3,
Level4: userSmallPublicPlatoonRelations[0].Level4,
Level5: userSmallPublicPlatoonRelations[0].Level5,
Level6: userSmallPublicPlatoonRelations[0].Level6,
Level7: userSmallPublicPlatoonRelations[0].Level7,
Level8: userSmallPublicPlatoonRelations[0].Level8,
Level9: userSmallPublicPlatoonRelations[0].Level9,
LevelTotal: userSmallPublicPlatoonRelations[0].LevelTotal,
}
return userSmallPublicPlatoonRelations[0].Position + 1, userSmallPublicPlatoonRelations[0].Pid, float64(userSmallPublicPlatoonRelations[0].Level), nil
return standardSmallPublicPlatoonRelation, fatherUid, nil
}
return
}

func getPosition(m model.UserSmallPublicPlatoonRelation, times int) (position, pid, level, fatherUid int, positionName, pidName, levelName, fatherUidName string) {
if times == 1 {
position = m.Position1
positionName = "position1"
pid = m.Pid1
pidName = "pid1"
level = m.Level1
levelName = "level1"
fatherUid = m.FatherUid1
levelName = "father_uid1"
}
if times == 2 {
position = m.Position2
positionName = "position2"
pid = m.Pid2
pidName = "pid2"
level = m.Level2
levelName = "level2"
fatherUid = m.FatherUid2
levelName = "father_uid2"
}
if times == 3 {
position = m.Position3
positionName = "position3"
pid = m.Pid3
pidName = "pid3"
level = m.Level3
levelName = "level3"
fatherUid = m.FatherUid3
levelName = "father_uid3"
}
if times == 4 {
position = m.Position4
positionName = "position4"
pid = m.Pid4
pidName = "pid4"
level = m.Level4
levelName = "level4"
fatherUid = m.FatherUid4
levelName = "father_uid4"
}
if times == 5 {
position = m.Position5
positionName = "position5"
pid = m.Pid5
pidName = "pid5"
level = m.Level5
levelName = "level5"
fatherUid = m.FatherUid5
levelName = "father_uid5"
}
if times == 6 {
position = m.Position6
positionName = "position6"
pid = m.Pid6
pidName = "pid6"
level = m.Level6
levelName = "level6"
fatherUid = m.FatherUid6
levelName = "father_uid6"
}
if times == 7 {
position = m.Position7
positionName = "position7"
pid = m.Pid7
pidName = "pid7"
level = m.Level7
levelName = "level7"
fatherUid = m.FatherUid7
levelName = "father_uid7"
}
if times == 8 {
position = m.Position8
positionName = "position8"
pid = m.Pid8
pidName = "pid8"
level = m.Level8
levelName = "level8"
fatherUid = m.FatherUid8
levelName = "father_uid8"
}
if times == 9 {
position = m.Position9
positionName = "position9"
pid = m.Pid9
pidName = "pid9"
level = m.Level9
levelName = "level9"
fatherUid = m.FatherUid9
levelName = "father_uid9"
}
return
}


Loading…
Cancel
Save