Browse Source

Merge remote-tracking branch 'origin/master'

master
huangjiajun 3 months ago
parent
commit
23f34f5538
4 changed files with 47 additions and 29 deletions
  1. +9
    -0
      db/db_user_level.go
  2. +23
    -15
      rule/honey_dividend/dividend.go
  3. +9
    -9
      rule/service_award_dividend/index.go
  4. +6
    -5
      rule/service_award_dividend/md/service_award_dividend.go

+ 9
- 0
db/db_user_level.go View File

@@ -17,6 +17,15 @@ func UserLevelInIDescByWeightLow(Db *xorm.Engine) ([]*model.UserLevel, error) {

}

func UserLevelInIDescByWeightLowV1(Db *xorm.Engine) ([]*model.UserLevel, error) {
var ms []*model.UserLevel
if err := Db.Where("is_use=1").Asc("level_weight").Limit(100).Find(&ms); err != nil {
return nil, err
}
return ms, nil

}

//UserLevelByID is 根据用户id 获取对应的等级信息
func UserLevelByID(Db *xorm.Engine, id interface{}) (*model.UserLevel, error) {
m := new(model.UserLevel)


+ 23
- 15
rule/honey_dividend/dividend.go View File

@@ -42,7 +42,7 @@ func CollectDividendData(eg *xorm.Engine, masterId string, ch *rabbit.Channel) (
nowHoneys := results1[0]["total"] //当前蜂蜜总量

//2、统计当前`可以分红`的用户数量
var sql2 = fmt.Sprintf("SELECT COUNT(*)AS total FROM `user_virtual_amount` uva LEFT JOIN user u on u.uid=uva.uid WHERE uva.coin_id = %d AND uva.amount >= %s and u.level > %d", base.CoinId, base.DestroyHoneyValues, base.DividendVipLevel)
var sql2 = fmt.Sprintf("SELECT COUNT(*)AS total FROM `user_virtual_amount` uva LEFT JOIN user u on u.uid=uva.uid WHERE uva.coin_id = %d AND uva.amount >= %s and u.level >= %d", base.CoinId, base.EveryMonthExchangeOneCashDestroyHoneyValues, base.DividendVipLevel)
results2, _ := db.QueryNativeString(eg, sql2)
nowUsers := results2[0]["total"] //当前用户总量

@@ -55,7 +55,7 @@ func CollectDividendData(eg *xorm.Engine, masterId string, ch *rabbit.Channel) (

//4、计算数据
honeyDividendsRecords := new(models.HoneyDividendsRecords)
has, err := eg.Where("state =?", 0).Desc("id").Get(&honeyDividendsRecords)
has, err := eg.Where("state =?", 0).Desc("id").Get(honeyDividendsRecords)
if err != nil {
return
}
@@ -72,7 +72,7 @@ func CollectDividendData(eg *xorm.Engine, masterId string, ch *rabbit.Channel) (
var pageSize = 100
for {
var list []model.UserVirtualAmount
err = eg.Where("coin_id = ? and amount >= ?", base.CoinId, base.DestroyHoneyValues).Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&list)
err = eg.Where("coin_id = ? and amount >= ?", base.CoinId, base.EveryMonthExchangeOneCashDestroyHoneyValues).Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&list)
if err != nil {
fmt.Println("err:::::1111", err)
return
@@ -82,19 +82,27 @@ func CollectDividendData(eg *xorm.Engine, masterId string, ch *rabbit.Channel) (
}

for _, v := range list {
tmpValue, _ := decimal.NewFromString(v.Amount)
amount := unitPrice.Mul(tmpValue).String()
//TODO::推入rabbitmq 异步处理
ch.Publish(md2.HoneyDividendExchange, md2.HoneyDividendForUserDividend{
RecordsId: honeyDividendsRecords.Id,
MasterId: masterId,
Uid: v.Uid,
Amount: amount,
DestroyHoneyValues: base.DestroyHoneyValues,
CoinId: base.CoinId,
DividendVipLevel: base.DividendVipLevel,
}, md2.HoneyDividendRoutKeyForUserDividend)
var m model.User
has1, err1 := eg.Where("uid = ?", v.Uid).Get(&m)
if err1 != nil || has1 == false {
continue
}
if m.Level >= base.DividendVipLevel {
tmpValue, _ := decimal.NewFromString(v.Amount)
amount := unitPrice.Mul(tmpValue).String()
//TODO::推入rabbitmq 异步处理
ch.Publish(md2.HoneyDividendExchange, md2.HoneyDividendForUserDividend{
RecordsId: honeyDividendsRecords.Id,
MasterId: masterId,
Uid: v.Uid,
Amount: amount,
DestroyHoneyValues: base.EveryMonthExchangeOneCashDestroyHoneyValues,
CoinId: base.CoinId,
DividendVipLevel: base.DividendVipLevel,
}, md2.HoneyDividendRoutKeyForUserDividend)
}
}
page++
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
}



+ 9
- 9
rule/service_award_dividend/index.go View File

@@ -56,7 +56,7 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, req md.JoinServiceAwardDi
return err
}
var levelMap = map[int]model.UserLevel{}
lvList, err := db.UserLevelInIDescByWeightLow(eg)
lvList, err := db.UserLevelInIDescByWeightLowV1(eg)
for _, v := range lvList {
levelMap[v.Id] = *v
}
@@ -64,14 +64,14 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, req md.JoinServiceAwardDi
if levelMap[user.Level].LevelWeight >= levelMap[parentUser.Level].LevelWeight {
for _, vv := range vipAllocationSetStruct {
if zhios_order_relate_utils.StrToInt(vv.FromVipId) == user.Level {
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId, req.CreateAt)
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId, req.CreateAt, req.AllocationNums)
if err != nil {
return err
}
}
}
} else {
err = AddVipToParent(eg, user, req.ParentUid, req.RegionId, req.CreateAt)
err = AddVipToParent(eg, user, req.ParentUid, req.RegionId, req.CreateAt, req.AllocationNums)
if err != nil {
return err
}
@@ -79,7 +79,7 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, req md.JoinServiceAwardDi
} else {
for _, vv := range vipAllocationSetStruct {
if zhios_order_relate_utils.StrToInt(vv.FromVipId) == user.Level {
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId, req.CreateAt)
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId, req.CreateAt, req.AllocationNums)
if err != nil {
return err
}
@@ -91,7 +91,7 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, req md.JoinServiceAwardDi
}

// AutoAddVip 自动添加会员
func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocationSetStruct md.VipAllocationSetStruct, regionId int, createAt string) (err error) {
func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocationSetStruct md.VipAllocationSetStruct, regionId int, createAt string, allocationNums int) (err error) {
//1、查询出当前应该分配给哪个上级会员
var serviceAwardDividendRelation models.ServiceAwardDividendRelation
var hasServiceAwardDividendRelation bool
@@ -128,7 +128,7 @@ func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocat
ParentUid: parentUid,
BindUid: 0,
VipLevel: user.Level,
AllocationNums: 0,
AllocationNums: allocationNums,
RegionId: regionId,
CreateAt: createAt,
UpdateAt: now.Format("2006-01-02 15:04:05"),
@@ -146,7 +146,7 @@ func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocat
ParentUid: parentUid,
BindUid: serviceAwardDividendRelation.Uid,
VipLevel: user.Level,
AllocationNums: 0,
AllocationNums: allocationNums,
RegionId: regionId,
CreateAt: createAt,
UpdateAt: now.Format("2006-01-02 15:04:05"),
@@ -171,7 +171,7 @@ func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocat
}

// AddVipToParent 添加会员至父级
func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int, regionId int, createAt string) (err error) {
func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int, regionId int, createAt string, allocationNums int) (err error) {
//1、查询出当前应该分配给哪个上级会员
var serviceAwardDividendRelation models.ServiceAwardDividendRelation
has, err := engine.Where("uid =?", parentUid).Get(&serviceAwardDividendRelation)
@@ -200,7 +200,7 @@ func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int, region
ParentUid: parentUid,
BindUid: serviceAwardDividendRelation.Uid,
VipLevel: user.Level,
AllocationNums: 0,
AllocationNums: allocationNums,
RegionId: regionId,
CreateAt: createAt,
UpdateAt: now.Format("2006-01-02 15:04:05"),


+ 6
- 5
rule/service_award_dividend/md/service_award_dividend.go View File

@@ -6,9 +6,10 @@ type VipAllocationSetStruct struct {
}

type JoinServiceAwardDividendRelationReq struct {
MasterId string `json:"master_id"` //站长ID
Uid int `json:"uid"` //用户id
ParentUid int `json:"parent_uid"` //父级id
RegionId int `json:"region_id"` //用户区域id
CreateAt string `json:"create_at"` //创建时间
MasterId string `json:"master_id"` //站长ID
Uid int `json:"uid"` //用户id
ParentUid int `json:"parent_uid"` //父级id
RegionId int `json:"region_id"` //用户区域id
CreateAt string `json:"create_at"` //创建时间
AllocationNums int `json:"allocation_nums"` //分配次数
}

Loading…
Cancel
Save