From e2aa2457e09ec9ca17abc8c6f9dd8afd76ed09bb Mon Sep 17 00:00:00 2001 From: dengbiao Date: Fri, 13 Sep 2024 15:00:04 +0800 Subject: [PATCH 1/3] update --- rule/honey_dividend/dividend.go | 38 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/rule/honey_dividend/dividend.go b/rule/honey_dividend/dividend.go index 3abc655..b31e6cb 100644 --- a/rule/honey_dividend/dividend.go +++ b/rule/honey_dividend/dividend.go @@ -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))) } From fa0fc0ae78032e3abd023f61300e14de8aa3c5a4 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Fri, 13 Sep 2024 18:10:23 +0800 Subject: [PATCH 2/3] update --- db/db_user_level.go | 9 +++++++++ rule/service_award_dividend/index.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/db/db_user_level.go b/db/db_user_level.go index 7b17df9..6a12a6c 100644 --- a/db/db_user_level.go +++ b/db/db_user_level.go @@ -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) diff --git a/rule/service_award_dividend/index.go b/rule/service_award_dividend/index.go index 9118ebd..683607a 100644 --- a/rule/service_award_dividend/index.go +++ b/rule/service_award_dividend/index.go @@ -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 } From 5fc5d98aa38ea1f86c8fd29ab98818107d199cdf Mon Sep 17 00:00:00 2001 From: dengbiao Date: Sat, 14 Sep 2024 19:25:55 +0800 Subject: [PATCH 3/3] update --- rule/service_award_dividend/index.go | 16 ++++++++-------- .../md/service_award_dividend.go | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/rule/service_award_dividend/index.go b/rule/service_award_dividend/index.go index 683607a..ccaec54 100644 --- a/rule/service_award_dividend/index.go +++ b/rule/service_award_dividend/index.go @@ -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"), diff --git a/rule/service_award_dividend/md/service_award_dividend.go b/rule/service_award_dividend/md/service_award_dividend.go index d47f61f..9d1b064 100644 --- a/rule/service_award_dividend/md/service_award_dividend.go +++ b/rule/service_award_dividend/md/service_award_dividend.go @@ -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"` //分配次数 }