Browse Source

更新

three
huangjiajun 1 year ago
parent
commit
c8a67b300b
7 changed files with 189 additions and 1 deletions
  1. +6
    -0
      app/db/db_user.go
  2. +23
    -0
      app/db/model/fin_withdraw_apply.go
  3. +1
    -0
      consume/init.go
  4. +10
    -0
      consume/md/consume_key.go
  5. +4
    -0
      consume/md/md_zhios_capital_pool_order_total.go
  6. +142
    -0
      consume/zhios_withdraw_reward.go
  7. +3
    -1
      go.mod

+ 6
- 0
app/db/db_user.go View File

@@ -326,3 +326,9 @@ func UserProfileFindByID(Db *xorm.Engine, id interface{}) (*model.UserProfile, e
}
return &m, nil
}

func UserFindByLevel(eg *xorm.Engine, level int) []model.User {
var data []model.User
eg.Where("level=?", level).Find(&data)
return data
}

+ 23
- 0
app/db/model/fin_withdraw_apply.go View File

@@ -0,0 +1,23 @@
package model

import (
"time"
)

type FinWithdrawApply struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') index INT(10)"`
AdmId int `json:"adm_id" xorm:"not null default 0 comment('审核人ID,0为系统自动') INT(10)"`
Amount string `json:"amount" xorm:"not null default 0.00 comment('提现金额') DECIMAL(10,2)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注,失败请备注原因') VARCHAR(500)"`
Type int `json:"type" xorm:"not null default 1 comment('提现类型;1:手动;2:自动') TINYINT(1)"`
WithdrawAccount string `json:"withdraw_account" xorm:"not null default '' comment('提现账号') VARCHAR(64)"`
WithdrawName string `json:"withdraw_name" xorm:"not null default '' comment('提现人姓名') VARCHAR(12)"`
Reason int `json:"reason" xorm:"not null default 0 comment('审核失败(驳回理由);1:当前账号不满足提现规则;2:账号异常;3:资金异常') TINYINT(1)"`
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('申请时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('处理时间') TIMESTAMP"`
State int `json:"state" xorm:"not null default 0 comment('0申请中,1通过,2完成,3失败') TINYINT(1)"`
WithdrawRefundType int `json:"withdraw_refund_type" xorm:"not null default 0 comment('') TINYINT(1)"`
WithdrawDealType int `json:"withdraw_deal_type" xorm:"not null default 0 comment('') TINYINT(1)"`
WithdrawMoney string `json:"withdraw_money" xorm:"not null default '' comment('') VARCHAR(255)" `
}

+ 1
- 0
consume/init.go View File

@@ -45,6 +45,7 @@ func initConsumes() {

jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal
jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail
jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward

//jobs[consumeMd.ZhiosRechargeOrderFailDevFunName] = ZhiosRechargeOrderFailDev



+ 10
- 0
consume/md/consume_key.go View File

@@ -210,6 +210,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "zhiosExpressOrderFail",
},
{
ExchangeName: "zhios.withdraw.reward.exchange",
Name: "zhios_withdraw_reward",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "withdraw_reward",
BindKey: "",
ConsumeFunName: "zhiosWithdrawReward",
},
}

const (
@@ -230,6 +239,7 @@ const (
ZhiosRechargeOrderFailDevFunName = "ZhiosRechargeOrderFailDev"
ZhiosCapitalPoolOrderTotalFunName = "ZhiosCapitalPoolOrderTotal"
ZhiosExpressOrderFail = "zhiosExpressOrderFail"
ZhiosWithdrawReward = "zhiosWithdrawReward"
ZhiosTikTokUpdateFunName = "ZhiosTikTokUpdate"
ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate"
CloudIssuanceAsyncMLoginFunName = "CloudIssuanceAsyncMLoginConsume"


+ 4
- 0
consume/md/md_zhios_capital_pool_order_total.go View File

@@ -14,3 +14,7 @@ type ZhiosExpressOrderFails struct {
Oid string `json:"oid"`
IsFail string `json:"is_fail"`
}
type ZhiosWithdraw struct {
Id string `json:"id"`
Mid string `json:"mid"`
}

+ 142
- 0
consume/zhios_withdraw_reward.go View File

@@ -0,0 +1,142 @@
package consume

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"github.com/tidwall/gjson"
"time"
"xorm.io/xorm"
)

func ZhiosWithdrawReward(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(20)
delivery := ch.Consume(queue.Name, false)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
//fmt.Println(string(res.Body))
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
err = handleZhiosWithdrawReward(res.Body)
//_ = res.Reject(false)
if err == nil {
_ = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosWithdrawReward(msg []byte) error {
//1、解析canal采集至mq中queue的数据结构体
var canalMsg *md.ZhiosWithdraw
fmt.Println(string(msg))
var tmpString string
err := json.Unmarshal(msg, &tmpString)
if err != nil {
fmt.Println(err.Error())
return err
}
fmt.Println(tmpString)
err = json.Unmarshal([]byte(tmpString), &canalMsg)
if err != nil {
return err
}
mid := canalMsg.Mid
eg := db.DBs[mid]
if eg == nil {
return nil
}
//判断用户是什么等级
var apply model.FinWithdrawApply
get, err := eg.Where("id=?", canalMsg.Id).Get(&apply)
if get == false || err != nil {
return nil
}
if apply.Uid == 0 {
return nil
}
//
withdrawSetting := db.SysCfgGetWithDb(eg, mid, "withdraw_setting")
withdrawFirstBili := gjson.Get(withdrawSetting, "withdrawFirstBili").String()
publicWithdrawTeamBili := db.SysCfgGetWithDb(eg, mid, "public_withdraw_team_bili")
publicWithdrawTeamCount := db.SysCfgGetWithDb(eg, mid, "public_withdraw_team_count")
if utils.StrToFloat64(withdrawFirstBili) > 0 {
level := 0
all, _ := db.UserLevlEgAll(eg)
for k, v := range all {
if k == 0 {
level = v.Id
}
}
//分给粉丝
levelUser := db.UserFindByLevel(eg, level)
if len(levelUser) == 0 {
return nil
}
ids := make([]int64, 0)
for _, v := range levelUser {
ids = append(ids, int64(v.Uid))
}
money := utils.FloatFormat(utils.StrToFloat64(apply.Amount)*(utils.StrToFloat64(withdrawFirstBili)/100)/float64(len(levelUser)), 6)
comm(eg, canalMsg.Id, ids, money, "全网提现分红", "withdraw_reward", "92")
}
if utils.StrToFloat64(publicWithdrawTeamBili) > 0 && utils.StrToFloat64(publicWithdrawTeamCount) > 0 {
//分给粉丝
user, _ := rule.FindRandUser(eg, utils.StrToInt(publicWithdrawTeamCount))
money := utils.FloatFormat(utils.StrToFloat64(apply.Amount)*(utils.StrToFloat64(publicWithdrawTeamBili)/100)/float64(len(user)), 6)
comm(eg, canalMsg.Id, user, money, "公排团队提现分红", "withdraw_team_reward", "93")
}
return nil
}
func comm(eg *xorm.Engine, id string, levelUser []int64, money float64, title, types, ordAction string) {
for _, v := range levelUser {
profile, err := db.UserProfileFindByID(eg, v)
if err != nil || profile == nil {
continue
}
oldAmount := profile.FinValid
profile.FinValid = utils.Float64ToStrByPrec(utils.StrToFloat64(profile.FinValid)+money, 6)
eg.Where("uid=?", profile.Uid).Update(profile)
var flow = model.FinUserFlow{
Uid: int(v),
Type: 0,
Amount: utils.Float64ToStrByPrec(money, 6),
BeforeAmount: oldAmount,
AfterAmount: profile.FinValid,
OrdType: types,
OrdId: id,
OrdTitle: title,
OrdAction: utils.StrToInt(ordAction),
OrdTime: int(time.Now().Unix()),
State: 2,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
eg.Insert(&flow)
}

}

+ 3
- 1
go.mod View File

@@ -6,6 +6,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20230518064344-fe7bba4f9ff8
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20230925093625-5df62f2a76c5
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20230825083620-ef8b12df8cf8
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20230911014653-22cc8e626d17
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
@@ -27,7 +28,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/makiuchi-d/gozxing v0.1.1
github.com/robfig/cron/v3 v3.0.1
github.com/shopspring/decimal v1.2.0
github.com/shopspring/decimal v1.3.1
github.com/sony/sonyflake v1.0.0
github.com/streadway/amqp v1.0.0
github.com/swaggo/swag v1.7.0
@@ -78,6 +79,7 @@ require (
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.0 // indirect


Loading…
Cancel
Save