|
@@ -48,8 +48,84 @@ func NewCalcPriceIncreaseFormula(userAmountValue string, oneCirclesGreenEnergyBa |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// CalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得钱) |
|
|
|
|
|
//func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string, uid int) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { |
|
|
|
|
|
// //1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
|
|
|
// oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
|
|
|
// "key": "is_open", |
|
|
|
|
|
// "value": 1, |
|
|
|
|
|
// }) |
|
|
|
|
|
// if err != nil { |
|
|
|
|
|
// return |
|
|
|
|
|
// } |
|
|
|
|
|
// var vipEquitySetting []*md2.VipEquitySettingStruct |
|
|
|
|
|
// err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.VipEquitySetting), &vipEquitySetting) |
|
|
|
|
|
// if err != nil { |
|
|
|
|
|
// return |
|
|
|
|
|
// } |
|
|
|
|
|
// var exchangeAccountBalanceFeeValue string |
|
|
|
|
|
// for _, v := range vipEquitySetting { |
|
|
|
|
|
// if v.VipLevelId == levelId { |
|
|
|
|
|
// exchangeAccountBalanceFeeValue = v.ExchangeAccountBalanceFee |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if exchangeAccountBalanceFeeValue == "" { |
|
|
|
|
|
// err = errors.New("未查询到当前会员等级兑换余额手续费") |
|
|
|
|
|
// return |
|
|
|
|
|
// } |
|
|
|
|
|
// decimalRate := decimal.NewFromInt(100) //百分比 |
|
|
|
|
|
// exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 |
|
|
|
|
|
// //TODO::统计当前有多少直推用户昨天签到了 |
|
|
|
|
|
// userRelates, err := db.DbsUserRelateByParentUid(engine, uid, 1) |
|
|
|
|
|
// if err != nil { |
|
|
|
|
|
// return |
|
|
|
|
|
// } |
|
|
|
|
|
// var userRelatesUids []int |
|
|
|
|
|
// if userRelates != nil { |
|
|
|
|
|
// for _, userRelate := range *userRelates { |
|
|
|
|
|
// userRelatesUids = append(userRelatesUids, userRelate.Uid) |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if len(userRelatesUids) > 0 { |
|
|
|
|
|
// now := time.Now() |
|
|
|
|
|
// startDate := now.AddDate(0, 0, -1).Format("2006-01-02") + " 00:00:00" |
|
|
|
|
|
// endDate := now.Format("2006-01-02") + " 00:00:00" |
|
|
|
|
|
// var oneCirclesGreenEnergySignIns []*model.OneCirclesGreenEnergySignIn |
|
|
|
|
|
// err = engine.Where("start_time >= ?", startDate).And("start_time <=?", endDate).In("uid", userRelatesUids).And("is_completed =?", 0).Find(&oneCirclesGreenEnergySignIns) |
|
|
|
|
|
// if err != nil { |
|
|
|
|
|
// return |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// decimalRateV2 := decimal.NewFromInt(10) //百分比 |
|
|
|
|
|
// if len(oneCirclesGreenEnergySignIns) > 0 { |
|
|
|
|
|
// decimalBase := decimal.NewFromInt(1) //基数 |
|
|
|
|
|
// userRelatesUidsValue := decimal.NewFromInt(int64(len(userRelatesUids))) |
|
|
|
|
|
// oneCirclesGreenEnergySignInsValue := decimal.NewFromInt(int64(len(oneCirclesGreenEnergySignIns))) |
|
|
|
|
|
// exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalBase.Sub(oneCirclesGreenEnergySignInsValue.Div(userRelatesUidsValue)).Mul(decimalRateV2)) |
|
|
|
|
|
// } else { |
|
|
|
|
|
// exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalRateV2) |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 |
|
|
|
|
|
// originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 |
|
|
|
|
|
// nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 |
|
|
|
|
|
// originalQuantityFunds, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalFunds) //原始资金 |
|
|
|
|
|
// afterPrice := originalQuantityFunds.Div(userExchangeNums.Add(originalQuantityNums)) //降价后的价格 |
|
|
|
|
|
// |
|
|
|
|
|
// greenEnergyValues := userExchangeNums.Mul(afterPrice) //绿色能量个数 |
|
|
|
|
|
// greenEnergyFeeValues := greenEnergyValues.Mul(exchangeAccountBalanceFee.Div(decimalRate)) //绿色能量个数扣除手续费价值 |
|
|
|
|
|
// |
|
|
|
|
|
// values = greenEnergyValues.Sub(greenEnergyFeeValues).Truncate(8).String() //用户实际得到的钱 |
|
|
|
|
|
// greenEnergy = greenEnergyValues.Truncate(8).String() //原本兑换到的钱 |
|
|
|
|
|
// greenEnergyFee = userExchangeNums.Mul(exchangeAccountBalanceFee.Div(decimalRate)).Truncate(8).String() //绿色能量手续费 |
|
|
|
|
|
// nowPriceValue = nowPrice.String() |
|
|
|
|
|
// afterPriceValue = afterPrice.String() |
|
|
|
|
|
// return |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
// CalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得钱) |
|
|
// CalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得钱) |
|
|
func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string, uid int) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { |
|
|
|
|
|
|
|
|
func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { |
|
|
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
"key": "is_open", |
|
|
"key": "is_open", |
|
@@ -73,40 +149,8 @@ func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string |
|
|
err = errors.New("未查询到当前会员等级兑换余额手续费") |
|
|
err = errors.New("未查询到当前会员等级兑换余额手续费") |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
decimalRate := decimal.NewFromInt(100) //百分比 |
|
|
|
|
|
exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 |
|
|
|
|
|
//TODO::统计当前有多少直推用户昨天签到了 |
|
|
|
|
|
userRelates, err := db.DbsUserRelateByParentUid(engine, uid, 1) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
var userRelatesUids []int |
|
|
|
|
|
if userRelates != nil { |
|
|
|
|
|
for _, userRelate := range *userRelates { |
|
|
|
|
|
userRelatesUids = append(userRelatesUids, userRelate.Uid) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if len(userRelatesUids) > 0 { |
|
|
|
|
|
now := time.Now() |
|
|
|
|
|
startDate := now.AddDate(0, 0, -1).Format("2006-01-02") + " 00:00:00" |
|
|
|
|
|
endDate := now.Format("2006-01-02") + " 00:00:00" |
|
|
|
|
|
var oneCirclesGreenEnergySignIns []*model.OneCirclesGreenEnergySignIn |
|
|
|
|
|
err = engine.Where("start_time >= ?", startDate).And("start_time <=?", endDate).In("uid", userRelatesUids).And("is_completed =?", 0).Find(&oneCirclesGreenEnergySignIns) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
decimalRateV2 := decimal.NewFromInt(10) //百分比 |
|
|
|
|
|
if len(oneCirclesGreenEnergySignIns) > 0 { |
|
|
|
|
|
decimalBase := decimal.NewFromInt(1) //基数 |
|
|
|
|
|
userRelatesUidsValue := decimal.NewFromInt(int64(len(userRelatesUids))) |
|
|
|
|
|
oneCirclesGreenEnergySignInsValue := decimal.NewFromInt(int64(len(oneCirclesGreenEnergySignIns))) |
|
|
|
|
|
exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalBase.Sub(oneCirclesGreenEnergySignInsValue.Div(userRelatesUidsValue)).Mul(decimalRateV2)) |
|
|
|
|
|
} else { |
|
|
|
|
|
exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalRateV2) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
decimalRate := decimal.NewFromInt(100) //百分比 |
|
|
|
|
|
exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 |
|
|
userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 |
|
|
userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 |
|
|
originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 |
|
|
originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 |
|
|
nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 |
|
|
nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 |
|
|