huangjiajun pirms 1 gada
vecāks
revīzija
c415d2dfde
6 mainītis faili ar 153 papildinājumiem un 35 dzēšanām
  1. +39
    -0
      app/db/db_appreciation_flow.go
  2. +18
    -0
      app/db/model/appreciation_flow.go
  3. +2
    -1
      consume/init.go
  4. +11
    -1
      consume/md/consume_key.go
  5. +82
    -32
      consume/zhios_appreciation.go
  6. +1
    -1
      go.mod

+ 39
- 0
app/db/db_appreciation_flow.go Parādīt failu

@@ -0,0 +1,39 @@
package db

import (
"applet/app/db/model"
"applet/app/utils"
"errors"
"time"
"xorm.io/xorm"
)

func InsertAppreciation(sess *xorm.Session, coinId, uid, kind, types, oid, value, flowValue, beforeValue, beforeFlowValue string) error {
var flow = model.AppreciationFlow{
CoinId: utils.StrToInt(coinId),
Uid: utils.StrToInt(uid),
Kind: utils.StrToInt(kind),
Value: value,
Type: utils.StrToInt(types),
FlowValue: flowValue,
BeforeSum: beforeValue,
BeforeFlowSum: beforeFlowValue,
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
Oid: oid,
}
if types == "0" {
flow.AfterSum = utils.GetPrec(utils.Float64ToStrByPrec(utils.StrToFloat64(beforeValue)+utils.StrToFloat64(value), 5), "4")
flow.AfterFlowSum = utils.GetPrec(utils.Float64ToStrByPrec(utils.StrToFloat64(beforeFlowValue)+utils.StrToFloat64(flowValue), 5), "4")
}
if types == "1" {
flow.AfterSum = utils.GetPrec(utils.Float64ToStrByPrec(utils.StrToFloat64(beforeValue)-utils.StrToFloat64(value), 5), "4")
flow.AfterFlowSum = utils.GetPrec(utils.Float64ToStrByPrec(utils.StrToFloat64(beforeFlowValue)-utils.StrToFloat64(flowValue), 5), "4")
}

insert, err := sess.Insert(&flow)
if insert == 0 || err != nil {
return errors.New("失败")
}
return nil
}

+ 18
- 0
app/db/model/appreciation_flow.go Parādīt failu

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

type AppreciationFlow struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
CoinId int `json:"coin_id" xorm:"not null default 0 comment('虚拟币id') INT(11)"`
Type int `json:"type" xorm:"not null default 0 comment('') INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
Kind int `json:"kind" xorm:"not null default 1 comment('流水类型') TINYINT(1)"`
Value string `json:"value" xorm:"not null default 0.0000 comment('虚拟币值') DECIMAL(20,4)"`
FlowValue string `json:"flow_value" xorm:"not null default 0.0000 comment('虚拟币值') DECIMAL(20,4)"`
BeforeFlowSum string `json:"before_flow_sum" xorm:"not null default 0.0000 comment('变动前-流通资产') DECIMAL(20,4)"`
AfterFlowSum string `json:"after_flow_sum" xorm:"not null default 0.0000 comment('变动后-流通资产') DECIMAL(20,4)"`
BeforeSum string `json:"before_sum" xorm:"not null default 0.0000 comment('变动前-总资产') DECIMAL(20,4)"`
AfterSum string `json:"after_sum" xorm:"not null default 0.0000 comment('变动后-总资产') DECIMAL(20,4)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
Oid string `json:"oid" xorm:"not null default '' VARCHAR(255)"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
}

+ 2
- 1
consume/init.go Parādīt failu

@@ -17,8 +17,9 @@ func Init() {

// 增加消费任务队列
func initConsumes() {
//jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation
//jobs[consumeMd.ZhiosAppreciationDevFunName] = ZhiosAppreciation

jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation
jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser

//jobs[consumeMd.ZhiosAcquisitionConditionDevFunName] = ZhiosAcquisitionCondition


+ 11
- 1
consume/md/consume_key.go Parādīt failu

@@ -236,6 +236,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiosValidUser",
},
{
ExchangeName: "zhios.appreciation.exchange",
Name: "zhios_appreciation",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "appreciation",
BindKey: "",
ConsumeFunName: "ZhiosAppreciation",
},
{
ExchangeName: "zhios.appreciation.exchange",
Name: "zhios_appreciation_dev",
@@ -243,7 +252,7 @@ var RabbitMqQueueKeyList = []*MqQueue{
IsPersistent: false,
RoutKey: "appreciation_dev",
BindKey: "",
ConsumeFunName: "ZhiosAppreciation",
ConsumeFunName: "ZhiosAppreciationDev",
},
}

@@ -273,5 +282,6 @@ const (
ZhiosAcquisitionConditionFunName = "ZhiosAcquisitionCondition"
ZhiosValidUserFunName = "ZhiosValidUser"
ZhiosAppreciationFunName = "ZhiosAppreciation"
ZhiosAppreciationDevFunName = "ZhiosAppreciationDev"
ZhiosAcquisitionConditionDevFunName = "ZhiosAcquisitionConditionDev"
)

+ 82
- 32
consume/zhios_appreciation.go Parādīt failu

@@ -7,6 +7,8 @@ import (
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
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"
"encoding/json"
"errors"
"fmt"
@@ -115,9 +117,21 @@ func exchange(eg *xorm.Engine, msg *md.ZhiosAppreciation) error {
sess.Rollback()
return err
}
base := db.GetAppreciationBase(sess)
beforeValue := "0"
beforeFlowValue := "0"
if base != nil {
beforeValue = base.Sum
beforeFlowValue = base.FlowSum
}
err = db.InsertAppreciation(sess, appreciationCoinId, msg.Uid, "0", "0", msg.Oid, biliMap["coin"], biliMap["in_coin"], beforeValue, beforeFlowValue)
if err != nil {
sess.Rollback()
return err
}
//加入资金池
sql := `UPDATE appreciation_base SET sum=sum+?,flow_sum=flow_sum+? WHERE is_use=1;`
_, err = sess.Exec(sql, biliMap["coin"], biliMap["in_coin"])
_, err = sess.Exec(sql, utils.StrToFloat64(biliMap["coin"]), utils.StrToFloat64(biliMap["in_coin"]))
if err != nil {
sess.Rollback()
return err
@@ -133,40 +147,95 @@ func withdraw(eg *xorm.Engine, msg *md.ZhiosAppreciation) error {
sess.Begin()
args := make(map[string]string)
json.Unmarshal([]byte(msg.Ext), &args)
coinMap := coinPriceEg(eg)
//资产价值
appreciationWithdrawFee := db.SysCfgGetWithDb(eg, msg.Mid, "appreciation_withdraw_fee")
appreciationWithdrawBack := db.SysCfgGetWithDb(eg, msg.Mid, "appreciation_withdraw_back")
//实际到账的
amount := utils.StrToFloat64(args["amount"]) * (1 - (utils.StrToFloat64(appreciationWithdrawFee) / 100))
newAmount := utils.GetPrec(utils.Float64ToStrByPrec(amount*utils.StrToFloat64(coinMap["price"]), 5), "4")
feeMap := md2.DealWithdrawalFeeResp{
WithdrawalCommissionFee: utils.StrToFloat64(appreciationWithdrawFee) / 100,
WithdrawalDestroyFee: (utils.StrToFloat64(appreciationWithdrawFee) - utils.StrToFloat64(appreciationWithdrawBack)) / 100,
WithdrawalRefluxFee: utils.StrToFloat64(appreciationWithdrawBack) / 100,
}
_, resp := rule.DealWithdrawalAndDestroy(sess, feeMap, utils.StrToFloat64(args["amount"]))
//这是到手的
newAmount := utils.GetPrec(utils.Float64ToStrByPrec(resp.TransferOutValue-resp.AmountOut, 5), "4")
//扣的
coinSum := utils.StrToFloat64(args["amount"]) * (1 - (utils.StrToFloat64(appreciationWithdrawFee) / 100) - (utils.StrToFloat64(appreciationWithdrawBack) / 100))
coinSum := utils.GetPrec(utils.Float64ToStrByPrec(resp.TransferOut-resp.RefluxValue, 20), "4")
err := svc.UpdateUserFinValidAndInterFlowSess(sess,
newAmount, args["amount"]+"个积分转余额", "appreciation", 0, 56, utils.StrToInt(msg.Uid), utils.StrToInt(msg.Oid), utils.StrToInt64(msg.Oid), utils.StrToInt64(msg.Oid))
if err != nil {
sess.Rollback()
return err
}
base := db.GetAppreciationBase(sess)
beforeValue := "0"
beforeFlowValue := "0"
if base != nil {
beforeValue = base.Sum
beforeFlowValue = base.FlowSum
}
appreciationCoinId := db.SysCfgGetWithDb(eg, msg.Mid, "appreciation_coin_id")
//转出
err = db.InsertAppreciation(sess, appreciationCoinId, msg.Uid, "1", "1", msg.Oid, args["amount"], args["amount"], beforeValue, beforeFlowValue)
if err != nil {
sess.Rollback()
return err
}
////销毁的
beforeValue = utils.GetPrec(utils.Float64ToStrByPrec(utils.StrToFloat64(beforeValue)-utils.StrToFloat64(args["amount"]), 5), "4")
beforeFlowValue = utils.GetPrec(utils.Float64ToStrByPrec(utils.StrToFloat64(beforeFlowValue)-utils.StrToFloat64(args["amount"]), 5), "4")
//DestroyValue := utils.GetPrec(utils.Float64ToStrByPrec(resp.DestroyValue, 5), "4")
//err = db.InsertAppreciation(sess, appreciationCoinId, args["uid"], "2", "1", DestroyValue, "0", beforeValue, beforeFlowValue)
//if err != nil {
// sess.Rollback()
// return err
//}
//回流的
RefluxValue := utils.GetPrec(utils.Float64ToStrByPrec(resp.RefluxValue, 5), "4")
err = db.InsertAppreciation(sess, appreciationCoinId, msg.Uid, "3", "0", msg.Oid, RefluxValue, "0", beforeValue, beforeFlowValue)
if err != nil {
sess.Rollback()
return err
}
sql := `UPDATE appreciation_base SET sum=sum-?,flow_sum=flow_sum-? WHERE is_use=1;`
_, err = eg.Exec(sql, coinSum, args["amount"])
_, err = eg.Exec(sql, utils.StrToFloat64(coinSum), utils.StrToFloat64(args["amount"]))
if err != nil {
sess.Rollback()
return err
}
sess.Commit()
return err
return nil
}

//购物销毁
func destroy(eg *xorm.Engine, msg *md.ZhiosAppreciation) error {
args := make(map[string]string)
json.Unmarshal([]byte(msg.Ext), &args)
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
base := db.GetAppreciationBase(sess)
beforeValue := "0"
beforeFlowValue := "0"
if base != nil {
beforeValue = base.Sum
beforeFlowValue = base.FlowSum
}
appreciationCoinId := db.SysCfgGetWithDb(eg, msg.Mid, "appreciation_coin_id")
//转出
err := db.InsertAppreciation(sess, appreciationCoinId, msg.Uid, "4", "1", msg.Oid, args["amount"], args["amount"], beforeValue, beforeFlowValue)
if err != nil {
sess.Rollback()
return err
}

sql := `UPDATE appreciation_base SET sum=sum-?,flow_sum=flow_sum-? WHERE is_use=1;`
_, err := eg.Exec(sql, args["amount"], args["amount"])
_, err = eg.Exec(sql, utils.StrToFloat64(args["amount"]), utils.StrToFloat64(args["amount"]))
if err != nil {
sess.Rollback()
return err
}
return err
sess.Commit()
return nil
}

func caleBili(eg *xorm.Engine, sess *xorm.Session, dbName string, args map[string]string) map[string]string {
@@ -185,10 +254,10 @@ func caleBili(eg *xorm.Engine, sess *xorm.Session, dbName string, args map[strin
//这是只返70%
appreciationCoinFee := db.SysCfgGetWithDb(eg, dbName, "appreciation_coin_fee")
bCoins := amoney * (utils.StrToFloat64(appreciationCoinFee) / 100)
coinPriceMap := coinPrice(sess)
//除以当前的资产价值
bCoins = bCoins / utils.StrToFloat64(coinPriceMap["price"])
bCoinStr = utils.GetPrec(utils.Float64ToStrByPrec(bCoins, 5), "4")
_, value := rule.DealTransferIn(sess, bCoins)
bCoins = value
bCoinStr = utils.GetPrec(utils.Float64ToStrByPrec(bCoins, 20), "4")
}
res := map[string]string{
"in_coin": bCoinStr,
@@ -196,25 +265,6 @@ func caleBili(eg *xorm.Engine, sess *xorm.Session, dbName string, args map[strin
}
return res
}
func coinPrice(sess *xorm.Session) map[string]string {
base := db.GetAppreciationBase(sess)
sum := "0"
flowSum := "0"
price := "1"
if base != nil {
sum = base.Sum
flowSum = base.FlowSum
}
if utils.StrToFloat64(base.Sum) > 0 {
price = utils.GetPrec(utils.Float64ToStrByPrec(utils.StrToFloat64(sum)/utils.StrToFloat64(flowSum), 5), "4")
}
res := map[string]string{
"price": price,
"sum": sum,
"flow_sum": flowSum,
}
return res
}
func coinPriceEg(eg *xorm.Engine) map[string]string {
base := db.GetAppreciationBaseEg(eg)
sum := "0"


+ 1
- 1
go.mod Parādīt failu

@@ -6,7 +6,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20231117125527-cb06c9e24f3f
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.20231120064838-61e5516cbe7a
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20231123111753-0198ed7513e2
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b
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


Notiek ielāde…
Atcelt
Saglabāt