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))) }