huangjiajun před 10 měsíci
rodič
revize
ec77b9002e
3 změnil soubory, kde provedl 108 přidání a 34 odebrání
  1. +22
    -20
      app/db/model/user_virtual_coin_flow.go
  2. +2
    -0
      consume/md/md_zhios_capital_pool_order_total.go
  3. +84
    -14
      consume/zhios_guide_store_order_success.go

+ 22
- 20
app/db/model/user_virtual_coin_flow.go Zobrazit soubor

@@ -5,24 +5,26 @@ import (
)

type UserVirtualCoinFlow struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"`
CoinId int `json:"coin_id" xorm:"not null comment('虚拟币id') INT(11)"`
Direction int `json:"direction" xorm:"not null comment('方向:1收入 2支出') TINYINT(255)"`
Title string `json:"title" xorm:"comment('标题') VARCHAR(255)"`
OrdId string `json:"ord_id" xorm:"comment('相关的订单id') VARCHAR(255)"`
Date string `json:"date" xorm:"comment('相关的订单id') VARCHAR(255)"`
Amout string `json:"amout" xorm:"not null comment('变更数量') DECIMAL(16,6)"`
BeforeAmout string `json:"before_amout" xorm:"not null comment('变更前数量') DECIMAL(16,6)"`
AfterAmout string `json:"after_amout" xorm:"not null comment('变更后数量') DECIMAL(16,6)"`
SysFee string `json:"sys_fee" xorm:"not null default 0.000000 comment('手续费') DECIMAL(16,6)"`
Price string `json:"price" xorm:"not null default 0.000000 comment('') DECIMAL(16,6)"`
CoinTransferData string `json:"coin_transfer_data" xorm:"not null comment('虚拟币转赠信息') TEXT"`
CreateTime time.Time `json:"create_time" xorm:"created default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
TransferType int `json:"transfer_type" xorm:"comment('转账类型:1全球分红,2管理员修改,3消费,4退回,5虚拟币兑换') TINYINT(100)"`
CoinIdTo int `json:"coin_id_to" xorm:"not null default 0 comment('兑换时目标币种id') INT(11)"`
IsRevoke int `json:"is_revoke" xorm:"not null default 0 comment('转赠是否撤回') INT(1)"`
TransferId int `json:"transfer_id" xorm:"not null default 0 comment('转赠关联id') INT(11)"`
ToUid int `json:"to_uid" xorm:"not null default 0 comment('转赠的用户id') INT(11)"`
TransferMoney string `json:"transfer_money" xorm:"not null default '0.000000' comment('转赠已撤回金额') INT(11)"`
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"`
CoinId int `json:"coin_id" xorm:"not null comment('虚拟币id') INT(11)"`
Direction int `json:"direction" xorm:"not null comment('方向:1收入 2支出') TINYINT(255)"`
Title string `json:"title" xorm:"comment('标题') VARCHAR(255)"`
OrdId string `json:"ord_id" xorm:"comment('相关的订单id') VARCHAR(255)"`
Date string `json:"date" xorm:"comment('相关的订单id') VARCHAR(255)"`
Amout string `json:"amout" xorm:"not null comment('变更数量') DECIMAL(16,6)"`
BeforeAmout string `json:"before_amout" xorm:"not null comment('变更前数量') DECIMAL(16,6)"`
AfterAmout string `json:"after_amout" xorm:"not null comment('变更后数量') DECIMAL(16,6)"`
SysFee string `json:"sys_fee" xorm:"not null default 0.000000 comment('手续费') DECIMAL(16,6)"`
Price string `json:"price" xorm:"not null default 0.000000 comment('') DECIMAL(16,6)"`
CoinTransferData string `json:"coin_transfer_data" xorm:"not null comment('虚拟币转赠信息') TEXT"`
CreateTime time.Time `json:"create_time" xorm:"created default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
TransferType int `json:"transfer_type" xorm:"comment('转账类型:1全球分红,2管理员修改,3消费,4退回,5虚拟币兑换') TINYINT(100)"`
CoinIdTo int `json:"coin_id_to" xorm:"not null default 0 comment('兑换时目标币种id') INT(11)"`
IsRevoke int `json:"is_revoke" xorm:"not null default 0 comment('转赠是否撤回') INT(1)"`
TransferId int `json:"transfer_id" xorm:"not null default 0 comment('转赠关联id') INT(11)"`
ToUid int `json:"to_uid" xorm:"not null default 0 comment('转赠的用户id') INT(11)"`
TransferMoney string `json:"transfer_money" xorm:"not null default '0.000000' comment('转赠已撤回金额') INT(11)"`
FreezeBeforeAmout string `json:"freeze_before_amout" xorm:"not null comment('变更前数量') DECIMAL(16,6)"`
FreezeAfterAmout string `json:"freeze_after_amout" xorm:"not null comment('变更后数量') DECIMAL(16,6)"`
}

+ 2
- 0
consume/md/md_zhios_capital_pool_order_total.go Zobrazit soubor

@@ -44,4 +44,6 @@ type ZhiosGuideStoreOrder struct {
State string `json:"state"`
ItemId string `json:"item_id"`
Type string `json:"type"`
CoinId string `json:"coin_id"`
Stock string `json:"stock"`
}

+ 84
- 14
consume/zhios_guide_store_order_success.go Zobrazit soubor

@@ -81,6 +81,30 @@ func handleZhiosGuideStoreOrderSuccess(msg []byte) error {
return err
}
}
if canalMsg.Type == "down" {
err := down(eg, canalMsg)
if err != nil {
return err
}
}
return nil
}

func down(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error {
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
//退积分
sum := canalMsg.DeductPrice
//退积分
// 111商家发布商品扣除 112商家商品审核失败退回 113 商家删除商品退回 114商品退款退回 115商家商品下架退回
err := UpdateUserFinValidAndInterFlowFreezeSess(sess,
utils.AnyToString(sum), "商品("+canalMsg.ItemId+")删除"+canalMsg.Stock+"个退回", "0", 1, utils.StrToInt(canalMsg.Uid), utils.StrToInt(canalMsg.CoinId), 113, utils.StrToInt64(utils.OrderUUID(utils.StrToInt(canalMsg.Uid))))
if err != nil {
sess.Rollback()
return err
}
sess.Commit()
return nil
}
func success(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error {
@@ -160,6 +184,44 @@ func fail(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error {
sess.Commit()
return nil
}
func UpdateUserFinValidAndInterFlowFreezeSess(session *xorm.Session, money, Title, fee string, types, uid, coinId, transferType int, ordId int64) error {
UserVirtualAmount, err := db.UserVirtualAmountFindByIdWithSession(session, uid, coinId)
if err != nil || UserVirtualAmount == nil {
if err == nil {
err = errors.New("获取用户余额信息失败")
}
return err
}
beforeAmount := UserVirtualAmount.Amount
freezeBeforeAmount := UserVirtualAmount.FreezeAmount

if types == 1 {
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) + utils.StrToFloat64(money))
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) - utils.StrToFloat64(money))
} else if types == 2 {
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) - utils.StrToFloat64(money))
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) + utils.StrToFloat64(money))
if utils.StrToFloat64(UserVirtualAmount.Amount) < 0 {
return errors.New("额度不足")
}
}
afterAmount := UserVirtualAmount.Amount
freezeAfterAmount := UserVirtualAmount.FreezeAmount

affected, err := db.UserVirtualAmountUpdateWithSession(session, uid, coinId, UserVirtualAmount, "amount,freeze_amount")
if err != nil || affected == 0 {
if err == nil {
err = errors.New("更新用户余额信息失败")
}
return err
}
err = virtualCoinFlowInsert(session, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount)
if err != nil {
return err
}
return nil
}

func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title, fee string, types, uid, coinId, transferType int, ordId int64) error {
UserVirtualAmount, err := db.UserVirtualAmountFindById(sess, uid, coinId)
if err != nil || UserVirtualAmount == nil {
@@ -169,6 +231,7 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title,
return err
}
beforeAmount := UserVirtualAmount.Amount
freezeBeforeAmount := UserVirtualAmount.FreezeAmount
if types == 2 {
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) - utils.StrToFloat64(money))
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) + utils.StrToFloat64(money))
@@ -177,6 +240,8 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title,
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) - utils.StrToFloat64(money))
}
afterAmount := UserVirtualAmount.Amount
freezeAfterAmount := UserVirtualAmount.FreezeAmount

affected, err := db.UserVirtualAmountUpdate(sess, uid, coinId, UserVirtualAmount, "amount")
if err != nil || affected == 0 {
if err == nil {
@@ -184,7 +249,7 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title,
}
return err
}
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount)
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount)
if err != nil {
return err
}
@@ -200,6 +265,8 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee
return err
}
beforeAmount := UserVirtualAmount.Amount
freezeBeforeAmount := UserVirtualAmount.FreezeAmount

if types == 2 {
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) - utils.StrToFloat64(money))
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) + utils.StrToFloat64(money))
@@ -208,6 +275,7 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) - utils.StrToFloat64(money))
}
afterAmount := UserVirtualAmount.Amount
freezeAfterAmount := UserVirtualAmount.FreezeAmount
affected, err := db.UserVirtualAmountUpdate(sess, uid, coinId, UserVirtualAmount, "freeze_amount,use_amount")
if err != nil || affected == 0 {
if err == nil {
@@ -215,28 +283,30 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee
}
return err
}
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount)
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount)
if err != nil {
return err
}
return nil
}
func virtualCoinFlowInsert(sess *xorm.Session, uid, coinId int, money, SysFee string, ordId int64, ItemTitle string, types, transferType int, beforeAmount string, afterAmount string) error {
func virtualCoinFlowInsert(sess *xorm.Session, uid, coinId int, money, SysFee string, ordId int64, ItemTitle string, types, transferType int, beforeAmount string, afterAmount string, freezeBeforeAmount string, freezeAfterAmount string) error {
now := time.Now()
if err := db.UserVirtualCoinFlowInsertOne(
sess,
&model.UserVirtualCoinFlow{
Uid: uid,
OrdId: utils.Int64ToStr(ordId),
CoinId: coinId,
Direction: types,
Title: ItemTitle,
Amout: money,
BeforeAmout: beforeAmount,
AfterAmout: afterAmount,
SysFee: SysFee,
CreateTime: now,
TransferType: transferType,
Uid: uid,
OrdId: utils.Int64ToStr(ordId),
CoinId: coinId,
Direction: types,
Title: ItemTitle,
Amout: money,
FreezeBeforeAmout: freezeBeforeAmount,
FreezeAfterAmout: freezeAfterAmount,
BeforeAmout: beforeAmount,
AfterAmout: afterAmount,
SysFee: SysFee,
CreateTime: now,
TransferType: transferType,
}); err != nil {
_ = logx.Warn(err)
return err


Načítá se…
Zrušit
Uložit