|
@@ -60,14 +60,14 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J |
|
|
if levelMap[user.Level].LevelWeight >= levelMap[parentUser.Level].LevelWeight { |
|
|
if levelMap[user.Level].LevelWeight >= levelMap[parentUser.Level].LevelWeight { |
|
|
for _, vv := range vipAllocationSetStruct { |
|
|
for _, vv := range vipAllocationSetStruct { |
|
|
if vv.FromVipId == user.Level { |
|
|
if vv.FromVipId == user.Level { |
|
|
err = AutoAddVip(eg, user, req.ParentUid, vv) |
|
|
|
|
|
|
|
|
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
err = AddVipToParent(eg, user, req.ParentUid) |
|
|
|
|
|
|
|
|
err = AddVipToParent(eg, user, req.ParentUid, req.RegionId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@@ -75,7 +75,7 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J |
|
|
} else { |
|
|
} else { |
|
|
for _, vv := range vipAllocationSetStruct { |
|
|
for _, vv := range vipAllocationSetStruct { |
|
|
if vv.FromVipId == user.Level { |
|
|
if vv.FromVipId == user.Level { |
|
|
err = AutoAddVip(eg, user, req.ParentUid, vv) |
|
|
|
|
|
|
|
|
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@@ -87,15 +87,21 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// AutoAddVip 自动添加会员 |
|
|
// AutoAddVip 自动添加会员 |
|
|
func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocationSetStruct md.VipAllocationSetStruct) (err error) { |
|
|
|
|
|
|
|
|
func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocationSetStruct md.VipAllocationSetStruct, regionId int) (err error) { |
|
|
//1、查询出当前应该分配给哪个上级会员 |
|
|
//1、查询出当前应该分配给哪个上级会员 |
|
|
var serviceAwardDividendRelation models.ServiceAwardDividendRelation |
|
|
var serviceAwardDividendRelation models.ServiceAwardDividendRelation |
|
|
has, err := engine.In("vip_level", vipAllocationSetStruct.ToVipId).Asc("allocation_nums").Get(&serviceAwardDividendRelation) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
|
|
|
var hasServiceAwardDividendRelation bool |
|
|
|
|
|
if regionId != 0 { |
|
|
|
|
|
hasServiceAwardDividendRelation, err = engine.Where("region_id =?", regionId).In("vip_level", vipAllocationSetStruct.ToVipId).Asc("allocation_nums").Get(&serviceAwardDividendRelation) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if has == false { |
|
|
|
|
|
return errors.New("未查询到合适的绑定上级会员用户!") |
|
|
|
|
|
|
|
|
if !hasServiceAwardDividendRelation { |
|
|
|
|
|
hasServiceAwardDividendRelation, err = engine.In("vip_level", vipAllocationSetStruct.ToVipId).Asc("allocation_nums").Get(&serviceAwardDividendRelation) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
now := time.Now() |
|
|
now := time.Now() |
|
@@ -109,36 +115,59 @@ func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocat |
|
|
}() |
|
|
}() |
|
|
sess.Begin() |
|
|
sess.Begin() |
|
|
|
|
|
|
|
|
//2、新增 service_award_dividend_relation 记录 |
|
|
|
|
|
serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine) |
|
|
|
|
|
_, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{ |
|
|
|
|
|
Uid: user.Uid, |
|
|
|
|
|
ParentUid: parentUid, |
|
|
|
|
|
BindUid: serviceAwardDividendRelation.Uid, |
|
|
|
|
|
VipLevel: user.Level, |
|
|
|
|
|
AllocationNums: 0, |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if hasServiceAwardDividendRelation == false { |
|
|
|
|
|
//return errors.New("未查询到合适的绑定上级会员用户!") |
|
|
|
|
|
//TODO::未查询到合适的绑定上级会员用户时(新增 service_award_dividend_relation 记录) |
|
|
|
|
|
serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine) |
|
|
|
|
|
_, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{ |
|
|
|
|
|
Uid: user.Uid, |
|
|
|
|
|
ParentUid: parentUid, |
|
|
|
|
|
BindUid: 0, |
|
|
|
|
|
VipLevel: user.Level, |
|
|
|
|
|
AllocationNums: 0, |
|
|
|
|
|
RegionId: regionId, |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
return |
|
|
|
|
|
} else { |
|
|
|
|
|
//2、新增 service_award_dividend_relation 记录 |
|
|
|
|
|
serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine) |
|
|
|
|
|
_, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{ |
|
|
|
|
|
Uid: user.Uid, |
|
|
|
|
|
ParentUid: parentUid, |
|
|
|
|
|
BindUid: serviceAwardDividendRelation.Uid, |
|
|
|
|
|
VipLevel: user.Level, |
|
|
|
|
|
AllocationNums: 0, |
|
|
|
|
|
RegionId: regionId, |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//3、修改 绑定上级的 service_award_dividend_relation 记录 |
|
|
|
|
|
serviceAwardDividendRelation.AllocationNums++ |
|
|
|
|
|
updateRelationAfftecd, err := serviceAwardDividendRelationDb.SaveServiceAwardDividendRelation(sess, serviceAwardDividendRelation.Id, &serviceAwardDividendRelation, "allocation_nums") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
if updateRelationAfftecd <= 0 { |
|
|
|
|
|
return errors.New("更新 绑定上级的 service_award_dividend_relation 记录 失败!") |
|
|
|
|
|
|
|
|
//3、修改 绑定上级的 service_award_dividend_relation 记录 |
|
|
|
|
|
serviceAwardDividendRelation.AllocationNums++ |
|
|
|
|
|
updateRelationAfftecd, err := serviceAwardDividendRelationDb.SaveServiceAwardDividendRelation(sess, serviceAwardDividendRelation.Id, &serviceAwardDividendRelation, "allocation_nums") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
if updateRelationAfftecd <= 0 { |
|
|
|
|
|
return errors.New("更新 绑定上级的 service_award_dividend_relation 记录 失败!") |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return sess.Commit() |
|
|
return sess.Commit() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// AddVipToParent 添加会员至父级 |
|
|
// AddVipToParent 添加会员至父级 |
|
|
func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int) (err error) { |
|
|
|
|
|
|
|
|
func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int, regionId int) (err error) { |
|
|
//1、查询出当前应该分配给哪个上级会员 |
|
|
//1、查询出当前应该分配给哪个上级会员 |
|
|
var serviceAwardDividendRelation models.ServiceAwardDividendRelation |
|
|
var serviceAwardDividendRelation models.ServiceAwardDividendRelation |
|
|
has, err := engine.Where("uid =?", parentUid).Get(&serviceAwardDividendRelation) |
|
|
has, err := engine.Where("uid =?", parentUid).Get(&serviceAwardDividendRelation) |
|
|