订单分佣规则
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

71 строка
2.5 KiB

  1. package rule
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
  5. zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
  6. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache"
  7. "errors"
  8. "github.com/shopspring/decimal"
  9. "xorm.io/xorm"
  10. )
  11. func InitForAppreciation(redisAddr string) (err error) {
  12. if redisAddr != "" {
  13. cache.NewRedis(redisAddr)
  14. }
  15. _, err = cache.SelectDb(md.RedisDataBase)
  16. return
  17. }
  18. /*
  19. 计算增值积分当前价值
  20. TODO:: 公式【 总资产/流通资产=当前积分价值 】
  21. */
  22. func CalcAppreciationValue(session *xorm.Session) (err error, value float64) {
  23. var appreciationBase model.AppreciationBase
  24. //1、查询增值积分资产总值
  25. has, err := session.Table("appreciation_base").Where("is_use =1").Get(&appreciationBase)
  26. if err != nil {
  27. return err, value
  28. }
  29. if !has {
  30. return errors.New("未查询到`增值积分资产总值`记录"), value
  31. }
  32. if zhios_order_relate_utils.StrToFloat64(appreciationBase.Sum) == 0 { //默认是1
  33. return nil, 1
  34. }
  35. sum, _ := decimal.NewFromString(appreciationBase.Sum) //总资产
  36. flowSum, _ := decimal.NewFromString(appreciationBase.FlowSum) //流通资产
  37. value, _ = sum.Div(flowSum).RoundFloor(4).Float64()
  38. return
  39. }
  40. //DealTransferIn 处理转入
  41. func DealTransferIn(session *xorm.Session, amount float64) (err error, value float64) {
  42. amountValue := decimal.NewFromFloat(amount)
  43. err, nowValue := CalcAppreciationValue(session)
  44. if err != nil {
  45. return
  46. }
  47. nowValueF := decimal.NewFromFloat(nowValue)
  48. value, _ = amountValue.Div(nowValueF).Float64()
  49. return
  50. }
  51. // DealWithdrawalAndDestroy 处理给用户提现
  52. func DealWithdrawalAndDestroy(session *xorm.Session, feeMap md.DealWithdrawalFeeResp, transferOut float64) (err error, resp md.DealWithdrawalAndDestroyResp) {
  53. transferOutValue := decimal.NewFromFloat(transferOut).Mul(decimal.NewFromFloat(feeMap.WithdrawalCommissionFee))
  54. destroyValue := decimal.NewFromFloat(transferOut).Mul(decimal.NewFromFloat(feeMap.WithdrawalDestroyFee))
  55. refluxValue := decimal.NewFromFloat(transferOut).Mul(decimal.NewFromFloat(feeMap.WithdrawalRefluxFee))
  56. err, nowValue := CalcAppreciationValue(session)
  57. if err != nil {
  58. return
  59. }
  60. resp.TransferOut = transferOut
  61. resp.AmountOut, _ = transferOutValue.Mul(decimal.NewFromFloat(nowValue)).Float64()
  62. resp.DestroyValue, _ = destroyValue.Float64()
  63. resp.RefluxValue, _ = refluxValue.Float64()
  64. return
  65. }