|
|
@@ -42,7 +42,7 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl |
|
|
|
//判断是否有uid为-2 (代表等待新用户填充) 的记录 |
|
|
|
userSmallPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationGetOneByPid(engine, param.RecommendUid, map[string]interface{}{ |
|
|
|
"key": "uid", |
|
|
|
"value": -1, |
|
|
|
"value": -2, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
@@ -70,10 +70,7 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl |
|
|
|
//3、无推荐人 |
|
|
|
|
|
|
|
//3.1 判断是否有uid为-1 (代表等待新用户填充) 的记录 |
|
|
|
userSmallPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ |
|
|
|
"key": "uid", |
|
|
|
"value": -1, |
|
|
|
}) |
|
|
|
userSmallPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationFindByEmptyPosition(engine) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@@ -93,7 +90,7 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl |
|
|
|
} |
|
|
|
|
|
|
|
// 查找当前 user_public_platoon_relation 中 `position` 最大的记录 |
|
|
|
var m model.UserPublicPlatoonRelation |
|
|
|
var m model.UserSmallPublicPlatoonRelation |
|
|
|
has, err := engine.Where("recommend_uid = 0").OrderBy("id desc").Get(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
@@ -103,16 +100,13 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl |
|
|
|
} |
|
|
|
|
|
|
|
// 查找当前大于 `position` 的所有记录 |
|
|
|
mlist, err := db.UserSmallPublicPlatoonRelationFindByPosition(engine, map[string]interface{}{ |
|
|
|
"key": "position", |
|
|
|
"value": m.Position, |
|
|
|
}) |
|
|
|
mlist, err := db.UserSmallPublicPlatoonRelationFindRecommends(engine) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
var mapBigUserSmallPublicPlatoonRelations map[int]interface{} |
|
|
|
var mapBigUserSmallPublicPlatoonRelations = map[int]interface{}{} |
|
|
|
for _, item := range mlist { |
|
|
|
mapBigUserSmallPublicPlatoonRelations[item.Position] = item |
|
|
|
mapBigUserSmallPublicPlatoonRelations[item.Position] = true |
|
|
|
} |
|
|
|
|
|
|
|
res, err := naturalSmallPublicPlatoon(engine, zhios_order_relate_utils.StrToInt(param.Uid), &m.Position, *userPublicPlatoonSetting, mapBigUserSmallPublicPlatoonRelations) |
|
|
@@ -146,38 +140,65 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl |
|
|
|
} |
|
|
|
|
|
|
|
//2、 查找当前 user_small_public_platoon_relation 中 recommendUid 所有的子记录 |
|
|
|
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPidLike(engine, strconv.Itoa(recommendUid)) |
|
|
|
userSmallPublicPlatoonRelations, err := db.UserSmallPublicPlatoonRelationFindByPidLike(engine, strconv.Itoa(m.Position)) |
|
|
|
if err != nil { |
|
|
|
return model.UserSmallPublicPlatoonRelation{}, err |
|
|
|
} |
|
|
|
|
|
|
|
var position, position1, position2, pid int |
|
|
|
var level float64 |
|
|
|
var level, level1, level2 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{} |
|
|
|
var mapUserSmallPublicPlatoonRelations = map[int]interface{}{} |
|
|
|
for _, item := range userSmallPublicPlatoonRelations { |
|
|
|
mapUserSmallPublicPlatoonRelations[item.Position] = item |
|
|
|
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 { |
|
|
|
//属于 |
|
|
|
position = position1 |
|
|
|
pid = fatherPosition1 |
|
|
|
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])))) |
|
|
|
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 |
|
|
@@ -188,8 +209,8 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl |
|
|
|
} |
|
|
|
} else { |
|
|
|
//新的一级 |
|
|
|
tmpPosition := (userSmallPublicPlatoonRelations[0].Position + 1) - int(math.Pow(float64(userPublicPlatoonSetting.SeveralTimes), float64(smallSearchPositionSonForLevel(userSmallPublicPlatoonRelations[0])))) |
|
|
|
position = smallSearchPositionFirstSonPosition(m.Position, userPublicPlatoonSetting.SeveralTimes) |
|
|
|
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 |
|
|
|
} |
|
|
@@ -197,7 +218,7 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl |
|
|
|
} |
|
|
|
|
|
|
|
//2、查找对应pid的 user_public_platoon_relation 记录 |
|
|
|
var m1 model.UserPublicPlatoonRelation |
|
|
|
var m1 model.UserSmallPublicPlatoonRelation |
|
|
|
if has, err := engine.Where("position=?", pid).Get(&m1); err != nil || has == false { |
|
|
|
return userSmallPublicPlatoonRelation, err |
|
|
|
} |
|
|
@@ -244,14 +265,14 @@ func naturalSmallPublicPlatoon(engine *xorm.Engine, uid int, originalPosition *i |
|
|
|
position1 = *originalPosition + 1 |
|
|
|
position2 = *originalPosition + userPublicPlatoonSetting.SeveralTimes |
|
|
|
var level, level1, level2 float64 |
|
|
|
makeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level1) |
|
|
|
makeSearchLevel(&position2, float64(userPublicPlatoonSetting.SeveralTimes), &level2) |
|
|
|
level = level1 + 1 //TODO::根据公式需要 + 1 |
|
|
|
smallMakeSearchLevel(&position1, float64(userPublicPlatoonSetting.SeveralTimes), &level1) |
|
|
|
smallMakeSearchLevel(&position2, float64(userPublicPlatoonSetting.SeveralTimes), &level2) |
|
|
|
level = level1 |
|
|
|
if level > 2 { |
|
|
|
if level1 != level2 { |
|
|
|
position = reverseDeductionPosition(*originalPosition, getLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes), userPublicPlatoonSetting.SeveralTimes) |
|
|
|
position = smallReverseDeductionPosition(*originalPosition, smallGetLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes), userPublicPlatoonSetting.SeveralTimes) |
|
|
|
} else { |
|
|
|
if position1 == getLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes) { |
|
|
|
if position1 == smallGetLevelForFirstPosition(int(level), userPublicPlatoonSetting.SeveralTimes) { |
|
|
|
position = position1 |
|
|
|
} else { |
|
|
|
position = position2 |
|
|
@@ -261,13 +282,14 @@ func naturalSmallPublicPlatoon(engine *xorm.Engine, uid int, originalPosition *i |
|
|
|
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.UserPublicPlatoonRelation |
|
|
|
var m1 model.UserSmallPublicPlatoonRelation |
|
|
|
if has, err := engine.Where("position=?", pid).Get(&m1); err != nil || has == false { |
|
|
|
return userPublicPlatoonRelation, err |
|
|
|
} |
|
|
@@ -326,11 +348,11 @@ func smallGetLevelForFirstPosition(level, severalTimes int) (position int) { |
|
|
|
//递归查找等级 |
|
|
|
func smallMakeSearchLevel(position *int, rows float64, times *float64) (level int) { |
|
|
|
difference := *position - int(math.Pow(rows, *times)) |
|
|
|
*times++ |
|
|
|
if difference <= 0 { |
|
|
|
return int(*times) |
|
|
|
} else { |
|
|
|
position = &difference |
|
|
|
*times++ |
|
|
|
return smallMakeSearchLevel(position, rows, times) |
|
|
|
} |
|
|
|
} |
|
|
@@ -359,10 +381,10 @@ func smallSearchPositionFirstSonPosition(position int, times int) (sonPosition i |
|
|
|
} |
|
|
|
|
|
|
|
//查找当前位位置相当于父级的等级 |
|
|
|
func smallSearchPositionSonForLevel(m model.UserSmallPublicPlatoonRelation) (level int) { |
|
|
|
fatherUids := strings.Split(m.FatherUid, "-") |
|
|
|
func smallSearchPositionSonForLevel(fatherUid string, fatherPosition int) (level int) { |
|
|
|
fatherUids := strings.Split(fatherUid, "-") |
|
|
|
for key, item := range fatherUids { |
|
|
|
if item == strconv.Itoa(m.Pid) { |
|
|
|
if item == strconv.Itoa(fatherPosition) { |
|
|
|
level = key + 1 |
|
|
|
break |
|
|
|
} |
|
|
@@ -373,7 +395,7 @@ func smallSearchPositionSonForLevel(m model.UserSmallPublicPlatoonRelation) (lev |
|
|
|
// smallFindWaitForDealUsers 查询待处理的用户 |
|
|
|
func smallFindWaitForDealUsers(engine *xorm.Engine, page, pageSize int) (err error, resp []int) { |
|
|
|
now := time.Now().Format("2006-01-02") |
|
|
|
lists, err := db.UserPublicPlatoonRelationFindByParamsByPage(engine, map[string]interface{}{ |
|
|
|
lists, err := db.UserSmallPublicPlatoonRelationFindByParamsByPage(engine, map[string]interface{}{ |
|
|
|
"key": "wait_for_settlement_date", |
|
|
|
"value": now, |
|
|
|
}, page, pageSize) |
|
|
@@ -389,7 +411,7 @@ func smallFindWaitForDealUsers(engine *xorm.Engine, page, pageSize int) (err err |
|
|
|
// SmallUpdateWaitForSettlementDate 改变 `wait_for_settlement_date` 待结算时间 |
|
|
|
func SmallUpdateWaitForSettlementDate(engine *xorm.Engine, userIds []string) (err error) { |
|
|
|
//Todo:: 将 user_public_platoon_relation 中 wait_for_settlement_date 设置为 30天后 |
|
|
|
sql := "update user_public_platoon_amount set wait_for_settlement_date = ? where uid in (" + strings.Join(userIds, ",") + ")" |
|
|
|
sql := "update user_small_public_platoon_relation set wait_for_settlement_date = ? where uid in (" + strings.Join(userIds, ",") + ")" |
|
|
|
waitForSettlementDate := time.Now().AddDate(0, 0, 30).Format("2006-01-02") |
|
|
|
_, err = engine.Exec(sql, waitForSettlementDate) |
|
|
|
if err != nil { |
|
|
@@ -528,7 +550,13 @@ func SmallDealCommonWealthPunish(engine *xorm.Engine, uid int, reason string) (e |
|
|
|
err = errors.New("未查询到公排关系记录") |
|
|
|
_ = session.Rollback() |
|
|
|
} |
|
|
|
params.Uid = -1 |
|
|
|
//TODO::判断是否为推荐用户 |
|
|
|
if params.RecommendUid == 0 { |
|
|
|
params.Uid = -1 |
|
|
|
} else { |
|
|
|
params.Uid = -2 |
|
|
|
} |
|
|
|
|
|
|
|
updateAffected, err := db.UserPublicPlatoonRelationUpdate(session, params.Id, params) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|