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