You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3171 lines
96 KiB
3171 lines
96 KiB
package data
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/go-xorm/xorm"
|
|
"github.com/shopspring/decimal"
|
|
"matchmaking-system/internal/biz/structure"
|
|
"matchmaking-system/internal/data/memory"
|
|
"matchmaking-system/internal/data/socket/publicData"
|
|
forexd "matchmaking-system/internal/data/tradedeal/forex"
|
|
"matchmaking-system/internal/data/tradedeal/virtual"
|
|
"matchmaking-system/internal/pkg/flags"
|
|
"matchmaking-system/internal/pkg/logging/applogger"
|
|
"matchmaking-system/internal/pkg/logging/common"
|
|
"strconv"
|
|
"time"
|
|
|
|
orders "matchmaking-system/internal/data/convert"
|
|
models "matchmaking-system/internal/pkg/model"
|
|
)
|
|
|
|
// userLevelRebate
|
|
// @Description:
|
|
type userLevelRebate struct {
|
|
RebatePrice decimal.Decimal
|
|
Level int
|
|
}
|
|
|
|
// SetPrice
|
|
// @Description:
|
|
type SetPrice struct {
|
|
PreStatus string
|
|
PreStartTime string
|
|
PreLimit string
|
|
PrePrices string
|
|
AfterStatus string
|
|
AfterStartTime string
|
|
AfterLimit string
|
|
AfterPrices string
|
|
Status string
|
|
Price string
|
|
}
|
|
|
|
// CalculateHandlingFees
|
|
//
|
|
// @Description: 手续费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId 用户Id
|
|
// @param marketType 市场类型:现货|合约|美股
|
|
// @param tradeType 交易类型:买入|卖出
|
|
// @param orderId 订单Id
|
|
// @param dealPrice 成交价格(开仓|平仓)
|
|
// @param faceValue
|
|
// @return string
|
|
// @return error
|
|
func (uo *userOrderRepo) CalculateHandlingFees(ctx context.Context, session *xorm.Session, userId, marketType, tradeType int, orderId, dealPrice, faceValue string) (string, error) {
|
|
var feeData decimal.Decimal
|
|
var feeList []models.BotFeeSetting
|
|
if err := session.Table(flags.BotFeeSetting).
|
|
Where("market_type = ?", marketType).
|
|
Find(&feeList); err != nil {
|
|
return flags.SetNull, flags.ErrMySqlDB
|
|
}
|
|
|
|
priceNew := decimal.RequireFromString(dealPrice)
|
|
for _, value := range feeList {
|
|
switch tradeType {
|
|
case flags.TradeTypeBuy:
|
|
feeData = decimal.RequireFromString(value.BuyFee).Mul(priceNew).Mul(decimal.RequireFromString(faceValue))
|
|
case flags.TradeTypeSell:
|
|
feeData = decimal.RequireFromString(value.SaleFee).Mul(priceNew).Mul(decimal.RequireFromString(faceValue))
|
|
default:
|
|
return flags.SetNull, flags.ErrOrderOne
|
|
}
|
|
}
|
|
|
|
tradeFee := orders.CreatBotTradeFee(ctx, userId, marketType, tradeType, feeData.String(), orderId)
|
|
_, err := session.Table(flags.BotTradeFee).Insert(&tradeFee)
|
|
if err != nil {
|
|
return flags.SetNull, flags.ErrMySqlDB
|
|
}
|
|
|
|
return feeData.String(), nil
|
|
}
|
|
|
|
// CalculateHandlingFeesShare
|
|
//
|
|
// @Description: 现货、合约、股票-手续费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param tradeType
|
|
// @param orderId
|
|
// @param dealPrice
|
|
// @return string
|
|
// @return error
|
|
func (uo *userOrderRepo) CalculateHandlingFeesShare(ctx context.Context, session *xorm.Session, userId, marketType, tradeType int, orderId, dealPrice string) (string, error) {
|
|
var feeData decimal.Decimal
|
|
var feeList []models.BotFeeSetting
|
|
if err := session.Table(flags.BotFeeSetting).
|
|
Where("market_type = ?", marketType).
|
|
Find(&feeList); err != nil {
|
|
return flags.SetNull, flags.ErrMySqlDB
|
|
}
|
|
|
|
priceNew := decimal.RequireFromString(dealPrice)
|
|
for _, value := range feeList {
|
|
switch tradeType {
|
|
case flags.TradeTypeBuy:
|
|
feeData = decimal.RequireFromString(value.BuyFee).Mul(priceNew)
|
|
case flags.TradeTypeSell:
|
|
feeData = decimal.RequireFromString(value.SaleFee).Mul(priceNew)
|
|
default:
|
|
return flags.SetNull, flags.ErrOrderOne
|
|
}
|
|
}
|
|
|
|
tradeFee := orders.CreatBotTradeFee(ctx, userId, marketType, tradeType, feeData.String(), orderId)
|
|
_, err := session.Table(flags.BotTradeFee).Insert(&tradeFee)
|
|
if err != nil {
|
|
return flags.SetNull, flags.ErrMySqlDB
|
|
}
|
|
|
|
return feeData.String(), nil
|
|
}
|
|
|
|
// CalculateHandlingFeesOption
|
|
//
|
|
// @Description: 期权手续费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param tradeType
|
|
// @param orderId
|
|
// @param dealPrice
|
|
// @return string
|
|
// @return error
|
|
func (uo *userOrderRepo) CalculateHandlingFeesOption(ctx context.Context, session *xorm.Session, userId, marketType, tradeType int, orderId, dealPrice, quantity string) (string, error) {
|
|
var feeData decimal.Decimal
|
|
var feeList []models.BotFeeSetting
|
|
if err := session.Table(flags.BotFeeSetting).
|
|
Where("market_type = ?", marketType).
|
|
Find(&feeList); err != nil {
|
|
return flags.SetNull, flags.ErrMySqlDB
|
|
}
|
|
|
|
//手续费(Total Fee)
|
|
// 1> 固定费用:Total Fee = Total Fee Fix Value(固定费用)
|
|
// 2> 按比例结算:Total Fee = Total Fee Ratio(总费用比例) * Option Filled Price(开仓价格) * Quantity(订单数量)
|
|
// 3> 按张结算:Total Fee = Total Fee Per Contract(每份费用) * Quantity(订单数量)
|
|
priceNew := decimal.RequireFromString(dealPrice)
|
|
orderNum := decimal.RequireFromString(quantity)
|
|
for _, value := range feeList {
|
|
switch tradeType {
|
|
case flags.TradeTypeBuy: // 开仓手续费
|
|
feeData = OptionFeeByPayType(value.PayType, priceNew, orderNum, decimal.RequireFromString(value.BuyFee))
|
|
case flags.TradeTypeSell: // 平仓手续费
|
|
feeData = OptionFeeByPayType(value.PayType, priceNew, orderNum, decimal.RequireFromString(value.SaleFee))
|
|
default:
|
|
return flags.SetNull, flags.ErrOrderOne
|
|
}
|
|
}
|
|
|
|
tradeFee := orders.CreatBotTradeFee(ctx, userId, marketType, tradeType, feeData.String(), orderId)
|
|
_, err := session.Table(flags.BotTradeFee).Insert(&tradeFee)
|
|
if err != nil {
|
|
return flags.SetNull, flags.ErrMySqlDB
|
|
}
|
|
|
|
return feeData.String(), nil
|
|
}
|
|
|
|
// OptionFeeByPayType
|
|
//
|
|
// @Description: 通过手续费类型计算手续费
|
|
// @param payType
|
|
// @param price
|
|
// @param orderNum
|
|
// @param fee
|
|
// @return decimal.Decimal
|
|
func OptionFeeByPayType(payType int, price, orderNum, fee decimal.Decimal) decimal.Decimal {
|
|
var feeData decimal.Decimal
|
|
|
|
switch payType {
|
|
case flags.FixedCosts: // 固定费用
|
|
feeData = fee
|
|
case flags.RatioCosts: // 按比例结算
|
|
feeData = price.Mul(orderNum).Mul(fee)
|
|
case flags.FixCosts: // 按张结算
|
|
feeData = fee.Mul(orderNum)
|
|
default:
|
|
feeData = decimal.Zero
|
|
}
|
|
|
|
return feeData
|
|
}
|
|
|
|
// SpotsRebateCalculation
|
|
//
|
|
// @Description: 现货返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId 用户Id
|
|
// @param marketType 市场类型:1现货|2合约|3美股
|
|
// @param brokType 返佣类型:0注册,1开仓,2平仓
|
|
// @param rebateCode 用户资金变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入,9-注册返佣,10-开仓返佣,11-平仓返佣,12-调整加钱,13-调整减钱,14-手续费
|
|
// @param cost 手续费(计算返佣金额)
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) SpotsRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderThree
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("接收返佣的用户ID:%v,接收返佣的用户返佣金额:%v", key, value)
|
|
}
|
|
|
|
// 写入返佣记录表
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 更新资产信息表(查询|更新)
|
|
var usableOld decimal.Decimal
|
|
usableOld, _, _, err = uo.GetBotUserDigital(session, int64(key), flags.BasicUnit)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
var checkNum int64
|
|
userDigitalUSDT := orders.UpdateBotUserDigitalByUsableNum(ctx, usableNew.String())
|
|
checkNum, err = session.Table(flags.BotUserDigital).
|
|
Where("user_id = ?", key).
|
|
Where("digital_id = ?", flags.BasicUnit).
|
|
Update(&userDigitalUSDT)
|
|
if err != nil || checkNum < 0 {
|
|
return err
|
|
}
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v,%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v,%v", key, usableNew)
|
|
}
|
|
|
|
// 写入资金明细表(平仓返佣)
|
|
if err = uo.CreatBotUserDigitalLogByRebate(ctx, session, int64(key), int64(rebateCode), value.RebatePrice.String(), orderId); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ContractRebateCalculation
|
|
//
|
|
// @Description: 返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ContractRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v,%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.Insert:%v", common.ErrContract, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
usableOld, frozenOld, _, err = uo.GetBotUserContract(session, int64(key), flags.BasicUnit)
|
|
if err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.GetBotUserContract:%v", common.ErrContract, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userContractUSDT := orders.UpdateBotUserContract(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserContract(session, int64(key), flags.BasicUnit, userContractUSDT); err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.UpdateBotUserContract:%v", common.ErrContract, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
uData := orders.CreatBotUserContractLog(ctx, int64(key), int64(rebateCode), flags.BasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserContractLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.CreatBotUserContractLogByRebate:%v", common.ErrContract, err)
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (uo *userOrderRepo) ForexRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v,%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.Insert:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
usableOld, frozenOld, _, err = uo.GetBotUserForex(session, int64(key), flags.ForexUnit)
|
|
if err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.GetBotUserForex:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userForexUSDT := orders.UpdateBotUserForex(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserForex(session, int64(key), flags.ForexUnit, userForexUSDT); err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.UpdateBotUserForex:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
uData := orders.CreatBotUserForexLog(ctx, int64(key), int64(rebateCode), flags.ForexUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserForexLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.CreatBotUserForexLogByRebate:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (uo *userOrderRepo) MoneyRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v,%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.Insert:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
usableOld, frozenOld, _, err = uo.GetBotUserMoney(session, int64(key), flags.ForexUnit)
|
|
if err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.GetBotUserMoney:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userMoneyUSDT := orders.UpdateBotUserMoney(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserMoney(session, int64(key), flags.MoneyUnit, userMoneyUSDT); err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.UpdateBotUserMoney:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
uData := orders.CreatBotUserMoneyLog(ctx, int64(key), int64(rebateCode), flags.MoneyUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserMoneyLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ContractRebateCalculation.CreatBotUserMoneyLogByRebate:%v", common.ErrForex, err)
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareUsRebateCalculation
|
|
//
|
|
// @Description: 美股返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareUsRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareUsRebateCalculation.Insert:%v", common.ErrShareUs, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockUsd, err := uo.GetBotUserStockByUserIdAndStockId(session, int64(key), flags.ShareUsBasicUnit)
|
|
if err != nil || userStockUsd == nil {
|
|
applogger.Error("%v ShareUsRebateCalculation.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockUSD := orders.UpdateBotUserStock(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockByUserIdAndStockId(session, int64(key), flags.ShareUsBasicUnit, userStockUSD); err != nil {
|
|
applogger.Error("%v ShareUsRebateCalculation.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockLog(ctx, int64(key), int64(rebateCode), flags.ShareUsBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockLogByRebate:%v", common.ErrShareUs, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareUsBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareUs, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareHkdRebateCalculation
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareHkdRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareHkdRebateCalculation.Insert:%v", common.ErrShareHkd, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockUsd, err := uo.GetBotUserStockHkdByUserIdAndStockId(session, int64(key), flags.ShareHkdBasicUnit)
|
|
if err != nil || userStockUsd == nil {
|
|
applogger.Error("%v ShareHkdRebateCalculation.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockUSD := orders.UpdateBotUserStockHkd(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockHkdByUserIdAndStockId(session, int64(key), flags.ShareHkdBasicUnit, userStockUSD); err != nil {
|
|
applogger.Error("%v ShareHkdRebateCalculation.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareHkd, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockHkdLog(ctx, int64(key), int64(rebateCode), flags.ShareHkdBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockHkdLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareHkdRebateCalculation.CreatBotUserStockHkdLogByRebate:%v", common.ErrShareHkd, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareHkdBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareHkdRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareHkd, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareIdnRebateCalculation
|
|
//
|
|
// @Description: 印尼股返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareIdnRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareIdnRebateCalculation.Insert:%v", common.ErrShareIdn, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockIdr, err := uo.GetBotUserStockIdnByUserIdAndStockId(session, int64(key), flags.ShareIdnBasicUnit)
|
|
if err != nil || userStockIdr == nil {
|
|
applogger.Error("%v ShareIdnRebateCalculation.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockIDR := orders.UpdateBotUserStockIdn(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockIdnByUserIdAndStockId(session, int64(key), flags.ShareIdnBasicUnit, userStockIDR); err != nil {
|
|
applogger.Error("%v ShareIdnRebateCalculation.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockIdnLog(ctx, int64(key), int64(rebateCode), flags.ShareIdnBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockIdnLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockIdnLogByRebate:%v", common.ErrShareIdn, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareIdnBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareIdn, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareInrRebateCalculation
|
|
//
|
|
// @Description: 印度股返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareInrRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareInrRebateCalculation.Insert:%v", common.ErrShareInr, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockIdr, err := uo.GetBotUserStockInByUserIdAndStockId(session, int64(key), flags.ShareInrBasicUnit)
|
|
if err != nil || userStockIdr == nil {
|
|
applogger.Error("%v ShareInrRebateCalculation.GetBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockIDR := orders.UpdateBotUserStockIn(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockInByUserIdAndStockId(session, int64(key), flags.ShareInrBasicUnit, userStockIDR); err != nil {
|
|
applogger.Error("%v ShareInrRebateCalculation.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err)
|
|
return err
|
|
}
|
|
|
|
// TODO: 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockInLog(ctx, int64(key), int64(rebateCode), flags.ShareInrBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockInLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareInrRebateCalculation.CreatBotUserStockInLogByRebate:%v", common.ErrShareInr, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareInrBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareInrRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareInr, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareGbxRebateCalculation
|
|
//
|
|
// @Description: 英股返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @param typeStatus
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareGbxRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareGbxRebateCalculation.Insert:%v", common.ErrShareGbx, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockIdr, err := uo.GetBotUserStockGbxByUserIdAndStockId(session, int64(key), flags.ShareGbxBasicUnit)
|
|
if err != nil || userStockIdr == nil {
|
|
applogger.Error("%v ShareGbxRebateCalculation.GetBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockIDR := orders.UpdateBotUserStockGbx(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockGbxByUserIdAndStockId(session, int64(key), flags.ShareGbxBasicUnit, userStockIDR); err != nil {
|
|
applogger.Error("%v ShareGbxRebateCalculation.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err)
|
|
return err
|
|
}
|
|
|
|
// TODO: 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockGbxLog(ctx, int64(key), int64(rebateCode), flags.ShareGbxBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockGbxLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareGbxRebateCalculation.CreatBotUserStockGbxLogByRebate:%v", common.ErrShareGbx, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareGbxBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareGbxRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareGbx, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareMysRebateCalculation
|
|
//
|
|
// @Description: 马股返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareMysRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareMysRebateCalculation.Insert:%v", common.ErrShareMys, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockIdr, err := uo.GetBotUserStockMysByUserIdAndStockId(session, int64(key), flags.ShareMysBasicUnit)
|
|
if err != nil || userStockIdr == nil {
|
|
applogger.Error("%v ShareMysRebateCalculation.GetBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockMYR := orders.UpdateBotUserStockMys(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockMysByUserIdAndStockId(session, int64(key), flags.ShareMysBasicUnit, userStockMYR); err != nil {
|
|
applogger.Error("%v ShareMysRebateCalculation.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockMysLog(ctx, int64(key), int64(rebateCode), flags.ShareMysBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockMysLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareMysRebateCalculation.CreatBotUserStockMysLogByRebate:%v", common.ErrShareMys, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareMysBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareMysRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareMys, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareThaRebateCalculation
|
|
//
|
|
// @Description: 泰股返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareThaRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Debug("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareThaRebateCalculation.Insert:%v", common.ErrShareTha, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockThb, err := uo.GetBotUserStockThaByUserIdAndStockId(session, int64(key), flags.ShareThaBasicUnit)
|
|
if err != nil || userStockThb == nil {
|
|
applogger.Error("%v ShareThaRebateCalculation.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockTHB := orders.UpdateBotUserStockTha(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockThaByUserIdAndStockId(session, int64(key), flags.ShareThaBasicUnit, userStockTHB); err != nil {
|
|
applogger.Error("%v ShareThaRebateCalculation.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err)
|
|
return err
|
|
}
|
|
|
|
// 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockThaLog(ctx, int64(key), int64(rebateCode), flags.ShareThaBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockThaLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareThaRebateCalculation.CreatBotUserStockThaLogByRebate:%v", common.ErrShareTha, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareThaBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareThaRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareTha, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareSgdRebateCalculation
|
|
//
|
|
// @Description: 新加坡返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareSgdRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareSgdRebateCalculation.Insert:%v", common.ErrShareSgd, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockThb, err := uo.GetBotUserStockSgdByUserIdAndStockId(session, int64(key), flags.ShareSgdBasicUnit)
|
|
if err != nil || userStockThb == nil {
|
|
applogger.Error("%v ShareSgdRebateCalculation.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockTHB := orders.UpdateBotUserStockSgd(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockSgdByUserIdAndStockId(session, int64(key), flags.ShareSgdBasicUnit, userStockTHB); err != nil {
|
|
applogger.Error("%v ShareSgdRebateCalculation.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err)
|
|
return err
|
|
}
|
|
|
|
// TODO: 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockSgdLog(ctx, int64(key), int64(rebateCode), flags.ShareSgdBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockSgdLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareSgdRebateCalculation.CreatBotUserStockSgdLogByRebate:%v", common.ErrShareSgd, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareSgdBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareSgdRebateCalculation.CreatBotUserStockSgdLogByRebate:%v", common.ErrShareSgd, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareEurRebateCalculation
|
|
//
|
|
// @Description: 德返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareEurRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareEurRebateCalculation.Insert:%v", common.ErrShareEur, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockThb, err := uo.GetBotUserStockEurByUserIdAndStockId(session, int64(key), flags.ShareEurBasicUnit)
|
|
if err != nil || userStockThb == nil {
|
|
applogger.Error("%v ShareEurRebateCalculation.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockTHB := orders.UpdateBotUserStockEur(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockEurByUserIdAndStockId(session, int64(key), flags.ShareEurBasicUnit, userStockTHB); err != nil {
|
|
applogger.Error("%v ShareEurRebateCalculation.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareEur, err)
|
|
return err
|
|
}
|
|
|
|
// TODO: 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockEurLog(ctx, int64(key), int64(rebateCode), flags.ShareEurBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockEurLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareEurRebateCalculation.CreatBotUserStockEurLogByRebate:%v", common.ErrShareEur, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareEurBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareEurRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareEur, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareBrlRebateCalculation
|
|
//
|
|
// @Description: 巴西返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @param typeStatus
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareBrlRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareBrlRebateCalculation.Insert:%v", common.ErrShareBrl, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockThb, err := uo.GetBotUserStockBrlByUserIdAndStockId(session, int64(key), flags.ShareBrlBasicUnit)
|
|
if err != nil || userStockThb == nil {
|
|
applogger.Error("%v ShareBrlRebateCalculation.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockTHB := orders.UpdateBotUserStockBrl(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockBrlByUserIdAndStockId(session, int64(key), flags.ShareBrlBasicUnit, userStockTHB); err != nil {
|
|
applogger.Error("%v ShareBrlRebateCalculation.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err)
|
|
return err
|
|
}
|
|
|
|
// TODO: 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockBrlLog(ctx, int64(key), int64(rebateCode), flags.ShareBrlBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockBrlLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareBrlRebateCalculation.CreatBotUserStockBrlLogByRebate:%v", common.ErrShareBrl, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareBrlBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareBrlRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareBrl, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareEurRebateCalculation
|
|
//
|
|
// @Description: 法返佣
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareFurRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareFurRebateCalculation.Insert:%v", common.ErrShareFur, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockThb, err := uo.GetBotUserStockFurByUserIdAndStockId(session, int64(key), flags.ShareFurBasicUnit)
|
|
if err != nil || userStockThb == nil {
|
|
applogger.Error("%v ShareFurRebateCalculation.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockTHB := orders.UpdateBotUserStockFur(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockFurByUserIdAndStockId(session, int64(key), flags.ShareFurBasicUnit, userStockTHB); err != nil {
|
|
applogger.Error("%v ShareFurRebateCalculation.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err)
|
|
return err
|
|
}
|
|
|
|
// TODO: 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockFurLog(ctx, int64(key), int64(rebateCode), flags.ShareFurBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockFurLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareFurRebateCalculation.CreatBotUserStockFurLogByRebate:%v", common.ErrShareFur, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareFurBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareFurRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareFur, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ShareJpyRebateCalculation
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param marketType
|
|
// @param brokType
|
|
// @param rebateCode
|
|
// @param cost
|
|
// @param orderId
|
|
// @param typeStatus
|
|
// @return error
|
|
func (uo *userOrderRepo) ShareJpyRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error {
|
|
rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 写入返佣记录表|更新用户资产表|记录交易明细
|
|
for key, value := range rebateMap {
|
|
if value == nil {
|
|
return flags.ErrOrderFour
|
|
}
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣记录:%v", key, value)
|
|
}
|
|
|
|
brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId)
|
|
_, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage)
|
|
if err != nil {
|
|
applogger.Error("%v ShareFurRebateCalculation.Insert:%v", common.ErrShareJpy, err)
|
|
return err
|
|
}
|
|
|
|
// 查询资产信息表
|
|
var usableOld, frozenOld decimal.Decimal
|
|
userStockThb, err := uo.GetBotUserStockJpyByUserIdAndStockId(session, int64(key), flags.ShareJpyBasicUnit)
|
|
if err != nil || userStockThb == nil {
|
|
applogger.Error("%v ShareJpyRebateCalculation.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err)
|
|
return err
|
|
}
|
|
usableNew := usableOld.Add(value.RebatePrice)
|
|
if !flags.CheckSetting {
|
|
applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld)
|
|
applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew)
|
|
}
|
|
|
|
// 更新返佣用户资产信息
|
|
userStockTHB := orders.UpdateBotUserStockJpy(ctx, usableNew.String(), frozenOld.String())
|
|
if err = uo.UpdateBotUserStockJpyByUserIdAndStockId(session, int64(key), flags.ShareJpyBasicUnit, userStockTHB); err != nil {
|
|
applogger.Error("%v ShareFurRebateCalculation.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err)
|
|
return err
|
|
}
|
|
|
|
// TODO: 写入资金明细表(返佣)
|
|
if !CheckTypeStatus(typeStatus) {
|
|
uData := orders.CreatBotUserStockJpyLog(ctx, int64(key), int64(rebateCode), flags.ShareJpyBasicUnit, value.RebatePrice.String(), orderId)
|
|
if err = uo.CreatBotUserStockJpyLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareJpyRebateCalculation.CreatBotUserStockJpyLogByRebate:%v", common.ErrShareJpy, err)
|
|
return err
|
|
}
|
|
} else {
|
|
uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareJpyBasicUnit, value.RebatePrice.String(), orderId, typeStatus)
|
|
if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil {
|
|
applogger.Error("%v ShareJpyRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareJpy, err)
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MapSetRebate
|
|
//
|
|
// @Description: 返佣层级关系
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param userId
|
|
// @param brokType
|
|
// @param cost
|
|
// @return map[int]*userLevelRebate
|
|
// @return error
|
|
func (uo *userOrderRepo) MapSetRebate(userId, brokType int, cost string) (map[int]*userLevelRebate, error) {
|
|
var level models.BotUserLevel
|
|
keyData := fmt.Sprintf("%v%v", flags.UserLevel, userId)
|
|
userLevel, err := Reds.HGetAll(context.Background(), keyData).Result()
|
|
if err != nil {
|
|
applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err)
|
|
return nil, err
|
|
}
|
|
for key, value := range userLevel {
|
|
valueId, err := strconv.Atoi(value)
|
|
if err != nil {
|
|
applogger.Error("%v MapSetRebate.Atoi:%v", common.ErrContract, err)
|
|
return nil, err
|
|
}
|
|
switch key {
|
|
case "user_id":
|
|
level.UserId = valueId
|
|
case "parent_id":
|
|
level.ParentId = valueId
|
|
case "grandpa_id":
|
|
level.GrandpaId = valueId
|
|
case "top_id":
|
|
level.TopId = valueId
|
|
}
|
|
}
|
|
if level.UserId == 0 {
|
|
return nil, flags.ErrOrderSix
|
|
}
|
|
|
|
// 查询当前用户--返佣计算比例
|
|
var setting map[string]string
|
|
var parentFee, grandpaFee, topFee decimal.Decimal
|
|
switch brokType {
|
|
case flags.Register: // 0 注册返佣
|
|
setting, err = Reds.HGetAll(context.Background(), flags.RegSetting).Result()
|
|
if err != nil {
|
|
applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err)
|
|
return nil, err
|
|
}
|
|
case flags.OpenPosition: // 1 开仓返佣 BROKERAGE:BUY:SETTING
|
|
setting, err = Reds.HGetAll(context.Background(), flags.BuySetting).Result()
|
|
if err != nil {
|
|
applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err)
|
|
return nil, err
|
|
}
|
|
case flags.ClosingPosition: // 2 平仓返佣 BROKERAGE:SALE:SETTING
|
|
setting, err = Reds.HGetAll(context.Background(), flags.SaleSetting).Result()
|
|
if err != nil {
|
|
applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err)
|
|
return nil, err
|
|
}
|
|
default:
|
|
return nil, flags.ErrOrderFive
|
|
}
|
|
for key, value := range setting {
|
|
switch key {
|
|
case "parent_fee":
|
|
parentFee = decimal.RequireFromString(value)
|
|
case "grandpa_fee":
|
|
grandpaFee = decimal.RequireFromString(value)
|
|
case "top_fee":
|
|
topFee = decimal.RequireFromString(value)
|
|
default:
|
|
continue
|
|
}
|
|
}
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Info("父级返佣比例ID:%v", parentFee)
|
|
applogger.Info("爷级返佣比例ID:%v", grandpaFee)
|
|
applogger.Info("祖级返佣比例ID:%v", topFee)
|
|
}
|
|
|
|
mapLevelFee := make(map[int]*userLevelRebate)
|
|
if level.ParentId > 0 {
|
|
mapLevelFee[level.ParentId] = &userLevelRebate{
|
|
RebatePrice: parentFee.Mul(decimal.RequireFromString(cost)),
|
|
Level: flags.ParentId,
|
|
}
|
|
}
|
|
if level.GrandpaId > 0 {
|
|
mapLevelFee[level.GrandpaId] = &userLevelRebate{
|
|
RebatePrice: grandpaFee.Mul(decimal.RequireFromString(cost)),
|
|
Level: flags.GrandpaId,
|
|
}
|
|
}
|
|
if level.TopId > 0 {
|
|
mapLevelFee[level.TopId] = &userLevelRebate{
|
|
RebatePrice: topFee.Mul(decimal.RequireFromString(cost)),
|
|
Level: flags.TopId,
|
|
}
|
|
}
|
|
|
|
return mapLevelFee, nil
|
|
}
|
|
|
|
// MapSetRebateMySqlDB
|
|
//
|
|
// @Description: 返佣比例
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param brokType
|
|
// @param cost
|
|
// @return map[int]*userLevelRebate
|
|
// @return error
|
|
func (uo *userOrderRepo) MapSetRebateMySqlDB(session *xorm.Session, userId, brokType int, cost string) (map[int]*userLevelRebate, error) {
|
|
// 获取用户等级-从缓存中取
|
|
var levelList []models.BotUserLevel
|
|
if err := session.Table(flags.BotUserLevel).
|
|
Where("user_id = ?", userId).
|
|
Find(&levelList); err != nil {
|
|
return map[int]*userLevelRebate{}, err
|
|
}
|
|
|
|
// 获取返佣比例-从缓存中取
|
|
var brokerSetList []models.BotBrokerageSetting
|
|
if err := session.Table(flags.BotBrokerageSetting).
|
|
Where("brok_type = ?", brokType).
|
|
Find(&brokerSetList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Info("查询用户返佣关系:%v", levelList)
|
|
}
|
|
|
|
// 统计需要返佣的用户数据
|
|
var parentFee, grandpaFee, topFee decimal.Decimal
|
|
for _, value := range brokerSetList {
|
|
parentFee = decimal.RequireFromString(value.ParentFee)
|
|
grandpaFee = decimal.RequireFromString(value.GrandpaFee)
|
|
topFee = decimal.RequireFromString(value.TopFee)
|
|
}
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Info("父级返佣比例ID:%v", parentFee)
|
|
applogger.Info("爷级返佣比例ID:%v", grandpaFee)
|
|
applogger.Info("祖级返佣比例ID:%v", topFee)
|
|
}
|
|
|
|
mapLevelFee := make(map[int]*userLevelRebate)
|
|
for _, value := range levelList {
|
|
if value.ParentId > 0 {
|
|
if !parentFee.IsZero() {
|
|
mapLevelFee[value.ParentId] = &userLevelRebate{
|
|
RebatePrice: parentFee.Mul(decimal.RequireFromString(cost)),
|
|
Level: flags.ParentId,
|
|
}
|
|
}
|
|
}
|
|
if value.GrandpaId > 0 {
|
|
if !grandpaFee.IsZero() {
|
|
mapLevelFee[value.GrandpaId] = &userLevelRebate{
|
|
RebatePrice: grandpaFee.Mul(decimal.RequireFromString(cost)),
|
|
Level: flags.GrandpaId,
|
|
}
|
|
}
|
|
}
|
|
if value.TopId > 0 {
|
|
if !topFee.IsZero() {
|
|
mapLevelFee[value.TopId] = &userLevelRebate{
|
|
RebatePrice: topFee.Mul(decimal.RequireFromString(cost)),
|
|
Level: flags.TopId,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if !flags.CheckSetting {
|
|
applogger.Info("展示数据:%v", mapLevelFee)
|
|
}
|
|
|
|
return mapLevelFee, nil
|
|
}
|
|
|
|
// CreatBotUserDigitalLog
|
|
//
|
|
// @Description: 资产--录入交易明细
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId 用户Id
|
|
// @param tradeType 用户资金变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入,9-注册返佣,10-开仓返佣,11-平仓返佣,12-调整加钱,13-调整减钱,14-手续费
|
|
// @param symbol 数字币代码
|
|
// @param changeNum 变动资产数量
|
|
// @param orderNum 变动资产数量
|
|
// @param cost
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserDigitalLog(ctx context.Context, session *xorm.Session, userId, tradeType int64, symbol, changeNum, orderNum, cost, orderId string) error {
|
|
var codeUSDT, codeFUSDT int64
|
|
switch tradeType {
|
|
case flags.TradeTypeBuy: // 买入
|
|
changeNum = NegativeValue(changeNum)
|
|
if symbol != flags.BasicUnit {
|
|
codeUSDT = flags.TransferOut // 用户账户转出
|
|
codeFUSDT = flags.ChangeInto // 用户账户非转入
|
|
}
|
|
case flags.TradeTypeSell: // 卖出
|
|
orderNum = NegativeValue(orderNum)
|
|
if symbol != flags.BasicUnit {
|
|
codeUSDT = flags.ChangeInto // 用户账户转入
|
|
codeFUSDT = flags.TransferOut // 用户账户非转出
|
|
}
|
|
default:
|
|
return nil
|
|
}
|
|
|
|
// 记录用户资产变动详情
|
|
uData := orders.CreatBotUserDigitalLog(ctx, userId, codeUSDT, flags.BasicUnit, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserDigitalLog).Insert(&uData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 记录用户非资产变动详情
|
|
qData := orders.CreatBotUserDigitalLog(ctx, userId, codeFUSDT, symbol, orderNum, orderId)
|
|
_, err = session.Table(flags.BotUserDigitalLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 记录用户(买入|卖出)手续费变动详情
|
|
cData := orders.CreatBotUserDigitalLog(ctx, userId, flags.CostMoney, flags.BasicUnit, NegativeValue(cost), orderId)
|
|
_, err = session.Table(flags.BotUserDigitalLog).Insert(&cData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (uo *userOrderRepo) CreatBotUserMoneyLog(ctx context.Context, session *xorm.Session, userId, tradeType int64, symbol, changeNum, orderNum, cost, orderId string) error {
|
|
var codeUSDT, codeFUSDT int64
|
|
switch tradeType {
|
|
case flags.TradeTypeBuy: // 买入
|
|
changeNum = NegativeValue(changeNum)
|
|
if symbol != flags.MoneyUnit {
|
|
codeUSDT = flags.TransferOut // 用户账户转出
|
|
codeFUSDT = flags.ChangeInto // 用户账户非转入
|
|
}
|
|
case flags.TradeTypeSell: // 卖出
|
|
orderNum = NegativeValue(orderNum)
|
|
if symbol != flags.MoneyUnit {
|
|
codeUSDT = flags.ChangeInto // 用户账户转入
|
|
codeFUSDT = flags.TransferOut // 用户账户非转出
|
|
}
|
|
default:
|
|
return nil
|
|
}
|
|
|
|
// 记录用户资产变动详情
|
|
uData := orders.CreatBotUserMoneyLog(ctx, userId, codeUSDT, flags.MoneyUnit, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserMoneyLog).Insert(&uData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 记录用户非资产变动详情
|
|
qData := orders.CreatBotUserMoneyLog(ctx, userId, codeFUSDT, symbol, orderNum, orderId)
|
|
_, err = session.Table(flags.BotUserMoneyLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 记录用户(买入|卖出)手续费变动详情
|
|
cData := orders.CreatBotUserMoneyLog(ctx, userId, flags.CostMoney, flags.MoneyUnit, NegativeValue(cost), orderId)
|
|
_, err = session.Table(flags.BotUserMoneyLog).Insert(&cData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserDigitalLogFreeze
|
|
//
|
|
// @Description: 创建现货交易日志信息
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param code
|
|
// @param symbol
|
|
// @param changeNum
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserDigitalLogFreeze(ctx context.Context, session *xorm.Session, userId, code int64, symbol, changeNum, orderId string) error {
|
|
uData := orders.CreatBotUserDigitalLog(ctx, userId, code, symbol, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserDigitalLog).Insert(&uData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserDigitalLogByRebate
|
|
//
|
|
// @Description: 返佣--录入交易明细
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId 用户Id
|
|
// @param tradeType 用户资金变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入,9-注册返佣,10-开仓返佣,11-平仓返佣,12-调整加钱,13-调整减钱,14-手续费
|
|
// @param changeNum 变动资产数量(返佣)
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserDigitalLogByRebate(ctx context.Context, session *xorm.Session, userId, tradeType int64, changeNum, orderId string) error {
|
|
uData := orders.CreatBotUserDigitalLog(ctx, userId, tradeType, flags.BasicUnit, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserDigitalLog).Insert(&uData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserContractLog
|
|
//
|
|
// @Description: 合约日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param changeType
|
|
// @param symbol
|
|
// @param changeNum
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserContractLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error {
|
|
qData := orders.CreatBotUserContractLog(ctx, userId, changeType, symbol, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserContractLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserContractLogList
|
|
//
|
|
// @Description: 合约日志列表记录
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserContractLogList(session *xorm.Session, list []models.BotUserContractLog) error {
|
|
_, err := session.Table(flags.BotUserContractLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (uo *userOrderRepo) CreatBotUserForexLogList(session *xorm.Session, list []models.BotUserForexLog) error {
|
|
_, err := session.Table(flags.BotUserForexLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (uo *userOrderRepo) CreatBotUserMoneyLogList(session *xorm.Session, list []models.BotUserMoneyLog) error {
|
|
_, err := session.Table(flags.BotUserMoneyLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserContractSecLogList
|
|
//
|
|
// @Description: 秒合约日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserContractSecLogList(session *xorm.Session, list []models.BotUserContractSecLog) error {
|
|
_, err := session.Table(flags.BotUserContractSecLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserContractLogNew
|
|
//
|
|
// @Description: 创建合约交易日志信息
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserContractLogNew(session *xorm.Session, log models.BotUserContractLog) error {
|
|
_, err := session.Table(flags.BotUserContractLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockLog
|
|
//
|
|
// @Description: 美股交易日志记录
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param changeType
|
|
// @param symbol
|
|
// @param changeNum
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error {
|
|
qData := orders.CreatBotUserStockLog(ctx, userId, changeType, symbol, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserStockLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockLogList
|
|
//
|
|
// @Description: 美股交易列表日志记录
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockLogList(session *xorm.Session, list []models.BotUserStockLog) error {
|
|
_, err := session.Table(flags.BotUserStockLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockBlockLogList
|
|
//
|
|
// @Description: 大宗交易列表日志记录
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockBlockLogList(session *xorm.Session, list []models.BotUserStockBlockLog) error {
|
|
_, err := session.Table(flags.BotUserStockBlockLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockHkdLogList
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockHkdLogList(session *xorm.Session, list []models.BotUserStockHkdLog) error {
|
|
_, err := session.Table(flags.BotUserStockHkdLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockIdnLog
|
|
//
|
|
// @Description: 印尼股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param changeType
|
|
// @param symbol
|
|
// @param changeNum
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockIdnLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error {
|
|
qData := orders.CreatBotUserStockIdnLog(ctx, userId, changeType, symbol, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserStockIdnLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockIdnLogList
|
|
//
|
|
// @Description: 印尼股列表日志记录
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockIdnLogList(session *xorm.Session, list []models.BotUserStockIdnLog) error {
|
|
_, err := session.Table(flags.BotUserStockIdnLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockInLog
|
|
//
|
|
// @Description: 印度股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param changeType
|
|
// @param symbol
|
|
// @param changeNum
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockInLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error {
|
|
qData := orders.CreatBotUserStockInLog(ctx, userId, changeType, symbol, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserStockInLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockInLogList
|
|
//
|
|
// @Description: 印度股日志列表记录
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockInLogList(session *xorm.Session, list []models.BotUserStockInLog) error {
|
|
_, err := session.Table(flags.BotUserStockInLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockGbxLogList
|
|
//
|
|
// @Description: 英股日志列表记录
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockGbxLogList(session *xorm.Session, list []models.BotUserStockGbxLog) error {
|
|
_, err := session.Table(flags.BotUserStockGbxLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockOptionInrLogList
|
|
//
|
|
// @Description: 期权-印度股列表日志记录
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockOptionInrLogList(session *xorm.Session, list []models.BotUserStockOptionInrLog) error {
|
|
_, err := session.Table(flags.BotUserStockOptionInrLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockMysLog
|
|
//
|
|
// @Description: 马股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param changeType
|
|
// @param symbol
|
|
// @param changeNum
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockMysLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error {
|
|
qData := orders.CreatBotUserStockMysLog(ctx, userId, changeType, symbol, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserStockMysLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockMysLogList
|
|
//
|
|
// @Description: 马股列表日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockMysLogList(session *xorm.Session, list []models.BotUserStockMysLog) error {
|
|
_, err := session.Table(flags.BotUserStockMysLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockThaLog
|
|
//
|
|
// @Description: 马股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param userId
|
|
// @param changeType
|
|
// @param symbol
|
|
// @param changeNum
|
|
// @param orderId
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockThaLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error {
|
|
qData := orders.CreatBotUserStockThaLog(ctx, userId, changeType, symbol, changeNum, orderId)
|
|
_, err := session.Table(flags.BotUserStockThaLog).Insert(&qData)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockThaLogList
|
|
//
|
|
// @Description: 马股列表日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockThaLogList(session *xorm.Session, list []models.BotUserStockThaLog) error {
|
|
_, err := session.Table(flags.BotUserStockThaLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockSgdLogList
|
|
//
|
|
// @Description: 新加坡股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockSgdLogList(session *xorm.Session, list []models.BotUserStockSgdLog) error {
|
|
_, err := session.Table(flags.BotUserStockSgdLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockEurLogList
|
|
//
|
|
// @Description: 德国股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockEurLogList(session *xorm.Session, list []models.BotUserStockEurLog) error {
|
|
_, err := session.Table(flags.BotUserStockEurLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockBrlLogList
|
|
//
|
|
// @Description: 巴西国股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockBrlLogList(session *xorm.Session, list []models.BotUserStockBrlLog) error {
|
|
_, err := session.Table(flags.BotUserStockBrlLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockFurLogList
|
|
//
|
|
// @Description: 法国股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockFurLogList(session *xorm.Session, list []models.BotUserStockFurLog) error {
|
|
_, err := session.Table(flags.BotUserStockFurLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockJpyLogList
|
|
//
|
|
// @Description: 日国股日志详情:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param list
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockJpyLogList(session *xorm.Session, list []models.BotUserStockJpLog) error {
|
|
_, err := session.Table(flags.BotUserStockJpyLog).Insert(&list)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserContractLogByRebate
|
|
//
|
|
// @Description: 德国列表股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserContractLogByRebate(session *xorm.Session, log models.BotUserContractLog) error {
|
|
_, err := session.Table(flags.BotUserContractLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserForexLogByRebate
|
|
//
|
|
// @Description: 外汇列表股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserForexLogByRebate(session *xorm.Session, log models.BotUserForexLog) error {
|
|
_, err := session.Table(flags.BotUserForexLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserMoneyLogByRebate
|
|
//
|
|
// @Description: 综合(现货|合约|外汇)列表股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserMoneyLogByRebate(session *xorm.Session, log models.BotUserMoneyLog) error {
|
|
_, err := session.Table(flags.BotUserMoneyLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockLogByRebate
|
|
//
|
|
// @Description: 美股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockLogByRebate(session *xorm.Session, log models.BotUserStockLog) error {
|
|
_, err := session.Table(flags.BotUserStockLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockBlockLogByRebate
|
|
//
|
|
// @Description: 大宗(美股)交易日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockBlockLogByRebate(session *xorm.Session, log models.BotUserStockBlockLog) error {
|
|
_, err := session.Table(flags.BotUserStockBlockLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockHkdLogByRebate
|
|
//
|
|
// @Description:
|
|
// @receiver uo
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockHkdLogByRebate(session *xorm.Session, log models.BotUserStockHkdLog) error {
|
|
_, err := session.Table(flags.BotUserStockHkdLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockIdnLogByRebate
|
|
//
|
|
// @Description: 印尼股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockIdnLogByRebate(session *xorm.Session, log models.BotUserStockIdnLog) error {
|
|
_, err := session.Table(flags.BotUserStockIdnLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockInLogByRebate
|
|
//
|
|
// @Description: 印度股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockInLogByRebate(session *xorm.Session, log models.BotUserStockInLog) error {
|
|
_, err := session.Table(flags.BotUserStockInLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockGbxLogByRebate
|
|
//
|
|
// @Description: 英股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockGbxLogByRebate(session *xorm.Session, log models.BotUserStockGbxLog) error {
|
|
_, err := session.Table(flags.BotUserStockGbxLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockOptionInrLogByRebate
|
|
//
|
|
// @Description: 期权印度股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockOptionInrLogByRebate(session *xorm.Session, log models.BotUserStockOptionInrLog) error {
|
|
_, err := session.Table(flags.BotUserStockOptionInrLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockMysLogByRebate
|
|
//
|
|
// @Description: 马股股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockMysLogByRebate(session *xorm.Session, log models.BotUserStockMysLog) error {
|
|
_, err := session.Table(flags.BotUserStockMysLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockThaLogByRebate
|
|
//
|
|
// @Description: 泰度股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockThaLogByRebate(session *xorm.Session, log models.BotUserStockThaLog) error {
|
|
_, err := session.Table(flags.BotUserStockThaLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockSgdLogByRebate
|
|
//
|
|
// @Description: 新加坡股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockSgdLogByRebate(session *xorm.Session, log models.BotUserStockSgdLog) error {
|
|
_, err := session.Table(flags.BotUserStockSgdLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockEurLogByRebate
|
|
//
|
|
// @Description: 德股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockEurLogByRebate(session *xorm.Session, log models.BotUserStockEurLog) error {
|
|
_, err := session.Table(flags.BotUserStockEurLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockBrlLogByRebate
|
|
//
|
|
// @Description: 巴西股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockBrlLogByRebate(session *xorm.Session, log models.BotUserStockBrlLog) error {
|
|
_, err := session.Table(flags.BotUserStockBrlLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockFurLogByRebate
|
|
//
|
|
// @Description: 法股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockFurLogByRebate(session *xorm.Session, log models.BotUserStockFurLog) error {
|
|
_, err := session.Table(flags.BotUserStockFurLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CreatBotUserStockJpyLogByRebate
|
|
//
|
|
// @Description: 日股日志详情-手续费:转出|转出|冻结|手续费|返佣费
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param session
|
|
// @param log
|
|
// @return error
|
|
func (uo *userOrderRepo) CreatBotUserStockJpyLogByRebate(session *xorm.Session, log models.BotUserStockJpLog) error {
|
|
_, err := session.Table(flags.BotUserStockJpyLog).Insert(&log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// CheckGlobalTread
|
|
//
|
|
// @Description: true:开启交易 false:关闭交易
|
|
//
|
|
// 股票:冷静期停止所有交易(全局设置)
|
|
// 熔断机制(后台配置冷静期)
|
|
// 触发幅度:10%,交易暂停15分钟
|
|
// 触发幅度:15%,交易暂停30分钟
|
|
// 触发幅度:20%,剩余交易时间(重新交易到休市时间)
|
|
//
|
|
// @param symbol
|
|
// @return bool
|
|
func CheckGlobalTread(symbol string) bool {
|
|
check := GetCacheStockMarketStatus(flags.StockMarketList, symbol)
|
|
|
|
return check
|
|
}
|
|
|
|
// CheckBlockTread
|
|
//
|
|
// @Description: true:开启交易 false:关闭交易
|
|
//
|
|
// 股票:冷静期停止所有交易(全局设置)
|
|
// 熔断机制(后台配置冷静期)
|
|
// 触发幅度:10%,交易暂停15分钟
|
|
// 触发幅度:15%,交易暂停30分钟
|
|
// 触发幅度:20%,剩余交易时间(重新交易到休市时间)
|
|
//
|
|
// @param cacheKey
|
|
// @param symbol
|
|
// @return bool
|
|
// @return string
|
|
// @return int
|
|
// @return time.Time
|
|
func CheckBlockTread(cacheKey, symbol string) (bool, string, int, time.Time) {
|
|
check, openPrice, minNum, today := GetCacheStockBlockStatus(cacheKey, symbol)
|
|
if check {
|
|
return check, openPrice, minNum, today
|
|
}
|
|
|
|
return check, openPrice, minNum, today
|
|
}
|
|
|
|
// GetShareChgUs
|
|
//
|
|
// @Description: 股票美股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgUs(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareUsChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockUsSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgIdn
|
|
//
|
|
// @Description: 股票印尼股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgIdn(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareIdnChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockYNSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgHkd
|
|
//
|
|
// @Description:
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgHkd(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareHkdChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockHKDSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgInr
|
|
//
|
|
// @Description: 股票印度股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgInr(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareInrChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockYDSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgGbx
|
|
//
|
|
// @Description:
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgGbx(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareGbxChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockUkSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetOptionChgInr
|
|
//
|
|
// @Description: 期权印度股涨跌幅
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetOptionChgInr(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.OptionInrChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
optionInrChg := GetCacheLimitOrDown(flags.OptionOpiSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(optionInrChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgMys
|
|
//
|
|
// @Description: 股票马股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgMys(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareMysChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockMGSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgTha
|
|
//
|
|
// @Description: 股票泰股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgTha(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareThaChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockTGSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgSgd
|
|
//
|
|
// @Description: 股票新加坡股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgSgd(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareSgdChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockSGDSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgEur
|
|
//
|
|
// @Description: 股票德股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgEur(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareEurChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockEURSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgBrl
|
|
//
|
|
// @Description: 股票巴西股涨跌幅
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgBrl(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareBrlChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockBRLSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgFur
|
|
//
|
|
// @Description: 股票法股涨跌幅
|
|
// @param ctx
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgFur(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareFurChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockFURSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetShareChgJpy
|
|
//
|
|
// @Description: 股票日股涨跌幅
|
|
// @param share
|
|
// @param symbol
|
|
// @return string
|
|
func GetShareChgJpy(share, symbol string) string {
|
|
closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg)
|
|
chg, err := memory.ShareJpyChgMark.Get(closingKey)
|
|
if err != nil {
|
|
return flags.SetZero
|
|
}
|
|
if len(string(chg)) == 0 {
|
|
chg = []byte(flags.SetOne)
|
|
}
|
|
chgV := decimal.RequireFromString(string(chg))
|
|
shareUsChg := GetCacheLimitOrDown(flags.StockJPYSystemSetUpKey, symbol) // 股票涨跌停读取缓存
|
|
|
|
var checkBoll bool
|
|
if chgV.Abs().Cmp(shareUsChg) >= 0 {
|
|
checkBoll = true // 到达涨跌幅上限
|
|
}
|
|
|
|
var checkChg string
|
|
if checkBoll {
|
|
if chgV.IsNegative() {
|
|
checkChg = flags.DownLimit // 跌停
|
|
} else {
|
|
checkChg = flags.UpLimit // 涨停
|
|
}
|
|
}
|
|
|
|
return checkChg
|
|
}
|
|
|
|
// GetBeforeAndAfterSetPrice
|
|
//
|
|
// @Description: 股票盘前和盘后下单 【pre_status|after_status 1、开启 2、关闭】
|
|
// @param ctx
|
|
// @param keyCache
|
|
// @return string
|
|
// @return error
|
|
func GetBeforeAndAfterSetPrice(keyCache string) (string, error) {
|
|
var setPrice string
|
|
setBAPrice, err := Reds.HGetAll(context.Background(), keyCache).Result()
|
|
if err != nil {
|
|
return setPrice, err
|
|
}
|
|
|
|
setModel := &SetPrice{}
|
|
for key, value := range setBAPrice {
|
|
switch key {
|
|
case "status": // 开启|关闭状态
|
|
setModel.Status = value
|
|
case "price": // 价格
|
|
setModel.Price = value
|
|
default:
|
|
}
|
|
}
|
|
|
|
if setModel != nil {
|
|
switch setModel.Status {
|
|
case flags.SetTwo:
|
|
setPrice = ""
|
|
case flags.SetOne:
|
|
return setModel.Price, nil
|
|
default:
|
|
}
|
|
}
|
|
|
|
return setPrice, nil
|
|
}
|
|
|
|
// GetOrderByStatusSort
|
|
//
|
|
// @Description: 查询列表数据排序
|
|
//
|
|
// 1、持仓订单:持仓时间越近越前;
|
|
// 2、委托订单:委托时间越近越前;
|
|
// 3、撤销订单:撤销时间越近越前;
|
|
// 4、平仓订单:平仓时间越近越前;
|
|
//
|
|
// @param status
|
|
// @return string
|
|
func GetOrderByStatusSort(status int64) string {
|
|
switch status {
|
|
case flags.EntrustStatus: // 委托
|
|
return "update_time"
|
|
case flags.PositionStatus: // 持仓
|
|
return "update_time"
|
|
case flags.CancelStatus: // 撤单
|
|
return "update_time"
|
|
case flags.CloseStatus: // 平仓
|
|
return "closing_time"
|
|
default:
|
|
return "create_time"
|
|
}
|
|
}
|
|
|
|
// GetForcedClosureValue
|
|
//
|
|
// @Description: 缓存强平阈值
|
|
// @param name
|
|
// @param symbol
|
|
// @return string
|
|
func GetForcedClosureValue(name, symbol string) string {
|
|
chgKey := publicData.SymbolCache(name, symbol, flags.TradeTypeForcedClosure)
|
|
switch name {
|
|
case flags.Us:
|
|
fb, err := memory.ShareUsForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Tha:
|
|
fb, err := memory.ShareThaForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Mys:
|
|
fb, err := memory.ShareMysForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Idn:
|
|
fb, err := memory.ShareIdnForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Inr:
|
|
fb, err := memory.ShareInrForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Hkd:
|
|
fb, err := memory.ShareHkdForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Sgd:
|
|
fb, err := memory.ShareSgdForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Gbx:
|
|
fb, err := memory.ShareGbxForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
case flags.Opi:
|
|
fb, err := memory.OptionInrForcedClosure.Get(chgKey)
|
|
if err != nil || len(string(fb)) == 0 {
|
|
return flags.ForcedClosure
|
|
}
|
|
return string(fb)
|
|
default:
|
|
return flags.ForcedClosure
|
|
}
|
|
}
|
|
|
|
// GetDigitalCurrencyPrice
|
|
//
|
|
// @Description: (现货|合约)最新价格
|
|
// @param ctx
|
|
// @param identifying
|
|
// @param symbol
|
|
// @return string
|
|
// @return error
|
|
func GetDigitalCurrencyPrice(ctx context.Context, identifying, symbol string) (string, error) {
|
|
var num int // 计数器
|
|
var err error // 错误定义
|
|
var priceNew string // 交易对最新价格
|
|
for {
|
|
subKey := publicData.SymbolCache(identifying, symbol, flags.TradeTypePrice)
|
|
switch identifying {
|
|
case flags.Hy:
|
|
priceNew, err = virtual.ContractSubMarketPrice(ctx, subKey) // 合约交易币价
|
|
case flags.Sd:
|
|
priceNew, err = virtual.SecondSubMarketPrice(ctx, subKey) // 秒合约交易币价
|
|
case flags.Xh:
|
|
priceNew, err = virtual.DealSpotsMarketPrice(ctx, subKey) // 现货交易币价
|
|
case flags.Wh:
|
|
priceNew, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易币价
|
|
default:
|
|
break
|
|
}
|
|
if err != nil {
|
|
applogger.Error("%v CreateBotContractTrade.ContractSubMarketPrice:%v", common.ErrContract, err)
|
|
time.Sleep(1 * time.Second)
|
|
num = num + 1
|
|
if num == 4 {
|
|
break
|
|
}
|
|
continue
|
|
}
|
|
break
|
|
}
|
|
|
|
return priceNew, err
|
|
}
|
|
|
|
// GetDigitalCurrencyForexPrice
|
|
//
|
|
// @Description: 外汇买一卖一最新报价
|
|
// @param ctx
|
|
// @param identifying
|
|
// @param symbol
|
|
// @param tradeType
|
|
// @return string
|
|
// @return error
|
|
func GetDigitalCurrencyForexPrice(ctx context.Context, identifying, symbol string, tradeType int64) (string, error) {
|
|
var num int // 计数器
|
|
var err error // 错误定义
|
|
var priceNew string // 交易对最新价格
|
|
for {
|
|
switch tradeType {
|
|
case 1: // 买入
|
|
subKey := publicData.SymbolCache(identifying, symbol, flags.TradeTypeBuy)
|
|
priceNew, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对买一最新报价
|
|
case 2: // 卖出
|
|
subKey := publicData.SymbolCache(identifying, symbol, flags.TradeTypeSell)
|
|
priceNew, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对卖一最新报价
|
|
default:
|
|
break
|
|
}
|
|
if err != nil {
|
|
applogger.Error("%v GetDigitalCurrencyForexPrice.ForexSubMarketPrice:%v", common.ErrForex, err)
|
|
time.Sleep(1 * time.Second)
|
|
num = num + 1
|
|
if num == 4 {
|
|
break
|
|
}
|
|
continue
|
|
}
|
|
break
|
|
}
|
|
|
|
return priceNew, err
|
|
}
|
|
|
|
// GetOptionInrCostPrice
|
|
//
|
|
// @Description: 期权-计算保证金
|
|
// @receiver uo
|
|
// @param order
|
|
// @return decimal.Decimal
|
|
func GetOptionInrCostPrice(limitOrMarketPrice decimal.Decimal, order structure.ShareOrder) decimal.Decimal {
|
|
// 保证金(Margin Ratio)
|
|
// 1> buy call & buy put:Margin = Open Filled Price(开仓价格) * Quantity(订单数量)
|
|
// 2> sell call & sell put:Margin = (Stock Price(行权价) * Option Multiplier(期权乘数)) * Margin Ratio(保证金比率) * Quantity(订单数量)
|
|
quantity := decimal.RequireFromString(order.OrderNumber)
|
|
stockPrice := decimal.RequireFromString(order.StrikePrice)
|
|
multiplier := decimal.RequireFromString(order.Multiplier)
|
|
ratio := decimal.RequireFromString(order.Ratio)
|
|
|
|
// 保证金计算
|
|
marginBuy := limitOrMarketPrice.Mul(quantity)
|
|
marginSell := stockPrice.Mul(multiplier).Mul(ratio.Div(decimal.RequireFromString(flags.DecimalOne))).Mul(quantity)
|
|
|
|
var marginRatio decimal.Decimal
|
|
switch order.TradeType {
|
|
case flags.OptionCalls: // CallS
|
|
switch order.TradingType {
|
|
case flags.OptionBuy: // buy
|
|
marginRatio = marginBuy
|
|
case flags.OptionSell: // sell
|
|
marginRatio = marginSell
|
|
default:
|
|
}
|
|
case flags.OptionPuts: // PUTS
|
|
switch order.TradingType {
|
|
case flags.OptionBuy: // buy
|
|
marginRatio = marginBuy
|
|
case flags.OptionSell: // sell
|
|
marginRatio = marginSell
|
|
default:
|
|
}
|
|
default:
|
|
}
|
|
|
|
return marginRatio
|
|
}
|
|
|
|
// GetOptionInrFloatingPL
|
|
//
|
|
// @Description: 期权-计算浮动盈亏
|
|
// @param order
|
|
// @param closePrice
|
|
// @param costPrice
|
|
// @param orderNumber
|
|
// @param totalAmount
|
|
// @return decimal.Decimal
|
|
func GetOptionInrFloatingPL(order structure.ShareOrder, openPrice, closePrice, orderNumber decimal.Decimal) decimal.Decimal {
|
|
// 一、浮动盈亏(P/L)
|
|
// 1>buy call & buy put: P/L = (Last Price(开仓价格) - Cost Price(当前价格)) * Contracts Quantity
|
|
// 2>sell call & sell put: P/L = (Cost Price(当前价格) - Last Price(开仓价格)) * Contracts Quantity
|
|
var resultPrice decimal.Decimal
|
|
switch order.TradeType {
|
|
case flags.OptionCalls: // CallS
|
|
switch order.TradingType {
|
|
case flags.OptionBuy: // buy
|
|
resultPrice = openPrice.Sub(closePrice).Mul(orderNumber)
|
|
case flags.OptionSell: // sell
|
|
resultPrice = closePrice.Sub(openPrice).Mul(orderNumber)
|
|
default:
|
|
}
|
|
case flags.OptionPuts: // PUTS
|
|
switch order.TradingType {
|
|
case flags.OptionBuy: // buy
|
|
resultPrice = openPrice.Sub(closePrice).Mul(orderNumber)
|
|
case flags.OptionSell: // sell
|
|
resultPrice = closePrice.Sub(openPrice).Mul(orderNumber)
|
|
default:
|
|
}
|
|
default:
|
|
}
|
|
|
|
return resultPrice
|
|
}
|
|
|