Ver código fonte

add 蜂蜜分红兑换贡献值

master
dengbiao 3 meses atrás
pai
commit
dedea3450e
6 arquivos alterados com 179 adições e 8 exclusões
  1. +1
    -1
      go.mod
  2. +2
    -0
      go.sum
  3. +9
    -5
      md/block_star_chain.go
  4. +1
    -1
      md/fin_user_flow.go
  5. +12
    -1
      md/mq.go
  6. +154
    -0
      rule/honey_dividend/contribution.go

+ 1
- 1
go.mod Ver arquivo

@@ -7,7 +7,7 @@ go 1.15

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240816014008-a236ebf42395
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240830093306-94cbf0dfb7bd
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis v6.15.9+incompatible
github.com/gomodule/redigo v1.8.9


+ 2
- 0
go.sum Ver arquivo

@@ -10,6 +10,8 @@ code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240816012431-432a50e
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240816012431-432a50e554e4/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240816014008-a236ebf42395 h1:xM3v+GLMYQMYeyp48SzJOXvylsbNRbdlvWRMXViWwFI=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240816014008-a236ebf42395/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240830093306-94cbf0dfb7bd h1:dGyT+A2w9WXkThZdxZods3cYQQjGebqksKjBxuTAK74=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240830093306-94cbf0dfb7bd/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=


+ 9
- 5
md/block_star_chain.go Ver arquivo

@@ -80,7 +80,9 @@ const (
GreenCoinDoubleChainExchangeByCoin2 = "绿色积分双链兑换账户余额-减少贡献积分"
HappyOrchardGiveIntegral = "开心农场-赠送积分"

HoneyDividendForDestroy = "蜂蜜分红-销毁蜂蜜"
HoneyDividendForDestroy = "蜂蜜分红-销毁蜂蜜"
HoneyDividendForContributionExchangeAddHoney = "贡献值兑换-增加蜂蜜"
HoneyDividendForContributionExchangeSubContribution = "贡献值兑换-销毁贡献值"
)

const (
@@ -155,10 +157,12 @@ const (
OneCirclesSettlementStarLevelDividendsForUserVirtualCoinFlow = 169 //绿色能量分红(结算星级分红-得到结算绿色能量)
OneCirclesCommunityDividendsForUserVirtualCoinFlow = 172 //社区分红

GreenCoinDoubleChainExchangeByCoin1ForForUserVirtualCoinFlow = 170 //绿色积分双链兑换账户余额-减少绿色积分
GreenCoinDoubleChainExchangeByCoin2ForForUserVirtualCoinFlow = 171 //绿色积分双链兑换账户余额-减少贡献积分
HappyOrchardGiveIntegralForUserVirtualCoinFlow = 172 //开心农场-赠送积分
HoneyDividendForDestroyForUserVirtualCoinFlow = 173 //蜂蜜分红-销毁蜂蜜
GreenCoinDoubleChainExchangeByCoin1ForForUserVirtualCoinFlow = 170 //绿色积分双链兑换账户余额-减少绿色积分
GreenCoinDoubleChainExchangeByCoin2ForForUserVirtualCoinFlow = 171 //绿色积分双链兑换账户余额-减少贡献积分
HappyOrchardGiveIntegralForUserVirtualCoinFlow = 172 //开心农场-赠送积分
HoneyDividendForDestroyForUserVirtualCoinFlow = 173 //蜂蜜分红-销毁蜂蜜
HoneyDividendForContributionExchangeAddHoneyForUserVirtualCoinFlow = 174 //贡献值兑换-增加蜂蜜
HoneyDividendForContributionExchangeSubContributionForUserVirtualCoinFlow = 175 //贡献值兑换-销毁贡献值

)



+ 1
- 1
md/fin_user_flow.go Ver arquivo

@@ -33,7 +33,7 @@ const (
BalanceExchangeForGreenEnergyForFinUserFlow = 113 // 账户余额兑换
GreenCoinDoubleChainExchangeForBalanceForFinUserFlow = 114 // 绿色积分双链兑换账户余额
InstallmentPaymentAutoRepaidForFinUserFlow = 116 // 分期付-自动扣款
HoneyDividendForRewardForFinUserFlow = 117 // 分期付-自动扣款
HoneyDividendForRewardForFinUserFlow = 117 // 蜂蜜分红
)

const DealUserAmountRequestIdPrefix = "%s:deal_user_amount:%d"


+ 12
- 1
md/mq.go Ver arquivo

@@ -48,6 +48,17 @@ type HoneyDividendForUserDividend struct {
CoinId int `json:"coin_id"`
}

type HoneyContributionExchangeForUserDividend struct {
RecordsId int64 `json:"records_id"`
MasterId string `json:"master_id"`
Uid int `json:"uid"`
Amount string `json:"amount"`
DestroyValues string `json:"destroy_values"`
CoinId int `json:"coin_id"`
CoinIdForContribution int `json:"coin_id_for_contribution"`
}

const (
HoneyDividendRoutKeyForUserDividend = "user_dividend" // 签到
HoneyDividendRoutKeyForUserDividend = "user_dividend" // 分红
HoneyDividendRoutKeyForUserContributionExchange = "user_contribution_exchange" // 兑换
)

+ 154
- 0
rule/honey_dividend/contribution.go Ver arquivo

@@ -0,0 +1,154 @@
package service_award_dividend

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
"errors"
"fmt"
"github.com/shopspring/decimal"
"math/rand"
"time"
"xorm.io/xorm"
)

func InitContribution(redisAddr string) (err error) {
if redisAddr != "" {
cache.NewRedis(redisAddr)
}
_, err = cache.SelectDb(md2.RedisDataBase)
return
}

func CollectContributionExchangeData(eg *xorm.Engine, masterId string, ch *rabbit.Channel) (err error) {
honeyDividendBasicDb := implement.NewHoneyDividendBasicDb(eg)
base, _ := honeyDividendBasicDb.GetHoneyDividendBasic()
if base.IsOpen != 1 {
err = errors.New("蜂蜜分红未开启!")
return
}

//1、统计当前`现有贡献值数量`
var sql1 = fmt.Sprintf("SELECT SUM(amount) AS total FROM `user_virtual_amount` WHERE coin_id = %d", base.CoinIdForContribution)
results1, _ := db.QueryNativeString(eg, sql1)
nowHoneys := results1[0]["total"] //当前贡献值总量

//2、统计当前`可以兑换`的用户数量
var sql2 = fmt.Sprintf("SELECT COUNT(*)AS total FROM `user_virtual_amount` WHERE coin_id = %d and amount >= %d", base.CoinIdForContribution, base.ContributionExchangeLowerLimit)
results2, _ := db.QueryNativeString(eg, sql2)
nowUsers := results2[0]["total"] //当前用户总量

//3、计算数据
honeyContributionExchangeRecords := new(models.HoneyContributionExchangeRecords)
has, err := eg.Where("state =?", 0).Desc("id").Get(&honeyContributionExchangeRecords)
if err != nil {
return
}
if has == false {
fmt.Println(">>>>>>>>>>>当前没有需要兑换的记录")
return nil
}
honeyContributionExchangeRecordsAmountValue, _ := decimal.NewFromString(honeyContributionExchangeRecords.Amount)
nowHoneyValue, _ := decimal.NewFromString(nowHoneys)

//3、进行分红(推入mq处理)
var page = 1
var pageSize = 100
var totalValues decimal.Decimal
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)
if err != nil {
fmt.Println("err:::::1111", err)
return
}
if len(list) <= 0 {
break
}

for _, v := range list {
tmpValue, _ := decimal.NewFromString(v.Amount)
amount := tmpValue.Div(nowHoneyValue).Mul(honeyContributionExchangeRecordsAmountValue).String()
//TODO::推入rabbitmq 异步处理
ch.Publish(md2.HoneyDividendExchange, md2.HoneyContributionExchangeForUserDividend{
RecordsId: honeyContributionExchangeRecords.Id,
MasterId: masterId,
Uid: v.Uid,
Amount: amount,
DestroyValues: v.Amount,
CoinId: base.CoinId,
CoinIdForContribution: base.CoinIdForContribution,
}, md2.HoneyDividendRoutKeyForUserContributionExchange)
totalValues = totalValues.Add(tmpValue)
}
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
}

//6、修改分红记录数据
honeyContributionExchangeRecords.TotalContributionValues = totalValues.String()
honeyContributionExchangeRecords.TotalExchangeHoneyValues = nowHoneys
honeyContributionExchangeRecords.UserNums = zhios_order_relate_utils.StrToInt(nowUsers)
honeyContributionExchangeRecords.State = 1

honeyContributionExchangeRecordsDb := implement.NewHoneyContributionExchangeRecordsDb(eg)
_, err = honeyContributionExchangeRecordsDb.UpdateHoneyContributionExchangeRecords(honeyContributionExchangeRecords,
"total_contribution_values", "total_exchange_honey_values", "user_nums", "state")
if err != nil {
return err
}

return
}

func DealContributionExchange(session *xorm.Session, data md2.HoneyContributionExchangeForUserDividend) error {
//1、进行贡献值销毁
err := rule.DealUserCoin(session, md2.DealUserCoinReq{
Kind: "sub",
Mid: data.MasterId,
Title: md2.HoneyDividendForContributionExchangeSubContribution,
TransferType: md2.HoneyDividendForContributionExchangeSubContributionForUserVirtualCoinFlow,
OrdId: "",
CoinId: data.CoinIdForContribution,
Uid: data.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(data.DestroyValues),
})
if err != nil {
return err
}

//2、给用户加上蜂蜜
err = rule.DealUserCoin(session, md2.DealUserCoinReq{
Kind: "add",
Mid: data.MasterId,
Title: md2.HoneyDividendForContributionExchangeAddHoney,
TransferType: md2.HoneyDividendForContributionExchangeAddHoneyForUserVirtualCoinFlow,
OrdId: "",
CoinId: data.CoinId,
Uid: data.Uid,
Amount: zhios_order_relate_utils.StrToFloat64(data.Amount),
})
if err != nil {
return err
}

//3、进行数据记录
honeyContributionExchangeRecordsWithFlowDb := implement.NewHoneyContributionExchangeRecordsWithFlowDb(nil)
_, err = honeyContributionExchangeRecordsWithFlowDb.HoneyContributionExchangeRecordsWithFlowInsert(session, &models.HoneyContributionExchangeRecordsWithFlow{
RecordsId: int(data.RecordsId),
Uid: data.Uid,
Amount: data.Amount,
DestroyValues: data.DestroyValues,
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
})
if err != nil {
return err
}
return nil
}

Carregando…
Cancelar
Salvar