|
|
@@ -370,144 +370,241 @@ func EggPointDetails(c *gin.Context) { |
|
|
|
e.OutSuc(c, resp, nil) |
|
|
|
} |
|
|
|
|
|
|
|
// BasalRate |
|
|
|
// @Summary 蛋蛋星球-添加好友-基础速率(获取) |
|
|
|
// @Tags 添加好友 |
|
|
|
// @Description 基础速率(获取) |
|
|
|
// @Accept json |
|
|
|
// @Produce json |
|
|
|
// @param Authorization header string true "验证参数Bearer和token空格拼接" |
|
|
|
// @Success 200 {object} md.BasalRateResp "具体数据" |
|
|
|
// @Failure 400 {object} md.Response "具体错误" |
|
|
|
// @Router /api/v1/addFriend/basalRate [GET] |
|
|
|
func BasalRate(c *gin.Context) { |
|
|
|
//val, exists := c.Get("user") |
|
|
|
//if !exists { |
|
|
|
// e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) |
|
|
|
// return |
|
|
|
//} |
|
|
|
//user, ok := val.(*model.User) |
|
|
|
//if !ok { |
|
|
|
// e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) |
|
|
|
// return |
|
|
|
//} |
|
|
|
// |
|
|
|
////1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
|
//energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) |
|
|
|
//eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ |
|
|
|
// "key": "is_open", |
|
|
|
// "value": 1, |
|
|
|
//}) |
|
|
|
//if err != nil { |
|
|
|
// e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
// return |
|
|
|
//} |
|
|
|
//var teamRewardSetting *md2.TeamRewardSettingStruct |
|
|
|
//err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting) |
|
|
|
//if err != nil { |
|
|
|
// e.OutErr(c, e.ERR, err.Error()) |
|
|
|
// return |
|
|
|
//} |
|
|
|
//now := time.Now() |
|
|
|
//var oneRoundDuration = utils.StrToInt(teamRewardSetting.OneRoundDuration) |
|
|
|
//startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05") |
|
|
|
// |
|
|
|
//signInDb := implement.NewEggSignInDb(db.Db) |
|
|
|
//get, eggSignIn, err := signInDb.EggSignINGetOneByTimeAndUid(startTime, "", user.Id, 0) |
|
|
|
//if err != nil { |
|
|
|
// e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
// return |
|
|
|
//} |
|
|
|
//var signRewardEggEnergy string |
|
|
|
//var signCountdown string |
|
|
|
//if !get { |
|
|
|
// signRewardEggEnergy = "0.00" |
|
|
|
//} else { |
|
|
|
// signRewardEggEnergy = eggSignIn.EstimatePerSecondEggEnergyValue |
|
|
|
// endTime := utils.TimeParseStd(eggSignIn.EndTime) |
|
|
|
// if endTime.Before(now) { |
|
|
|
// //TODO::证明此时上一轮签到已结束,暂时还没结算 |
|
|
|
// signRewardEggEnergy = "0.00" |
|
|
|
// } else { |
|
|
|
// duration := endTime.Sub(now) // 计算时间差值 |
|
|
|
// hours := duration / time.Hour // 获取小时部分 |
|
|
|
// minutes := duration % time.Hour / time.Minute // 获取分钟部分(先除去小时后再乘以60) |
|
|
|
// seconds := int64(duration/time.Second) % 60 |
|
|
|
// signCountdown = fmt.Sprintf("%d:%d:%d", hours, minutes, seconds) //收益倒计时 |
|
|
|
// } |
|
|
|
//} |
|
|
|
//nowBasalRate := utils.StrToFloat64(signRewardEggEnergy) * 60 * 60 //每小时基础速率 |
|
|
|
// |
|
|
|
////2、组装距状图数据 |
|
|
|
//var signInRewards []*md.SignInRewardStruct |
|
|
|
//err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.SignInReward), &signInRewards) |
|
|
|
//if err != nil { |
|
|
|
// e.OutErr(c, e.ERR, err.Error()) |
|
|
|
// return |
|
|
|
//} |
|
|
|
//var barChartYData, barChartXData []string |
|
|
|
//for _, v := range signInRewards { |
|
|
|
// barChartYData = append(barChartYData, utils.Float64ToStrPrec8(utils.StrToFloat64(v.RewardValue)*60*60)) |
|
|
|
// var vipMemberStartNum, vipMemberEndNums int64 |
|
|
|
// vipMemberStartNum = utils.StrToInt64(v.VipMemberStartNums) |
|
|
|
// vipMemberEndNums = utils.StrToInt64(v.VipMemberEndNums) |
|
|
|
// var vipMemberStartNumStr, vipMemberEndNumsStr string |
|
|
|
// if vipMemberStartNum >= 10000 && vipMemberStartNum < 100000 { |
|
|
|
// vipMemberStartNum = vipMemberStartNum / 10000 |
|
|
|
// vipMemberStartNumStr = utils.Int64ToStr(vipMemberStartNum) + "万" |
|
|
|
// } else if vipMemberStartNum >= 100000 && vipMemberStartNum < 1000000 { |
|
|
|
// vipMemberStartNum = vipMemberStartNum / 100000 |
|
|
|
// vipMemberStartNumStr = utils.Int64ToStr(vipMemberStartNum) + "十万" |
|
|
|
// } else if vipMemberStartNum >= 1000000 && vipMemberStartNum < 10000000 { |
|
|
|
// vipMemberStartNum = vipMemberStartNum / 1000000 |
|
|
|
// vipMemberStartNumStr = utils.Int64ToStr(vipMemberStartNum) + "百万" |
|
|
|
// } else if vipMemberStartNum >= 10000000 && vipMemberStartNum < 100000000 { |
|
|
|
// vipMemberStartNum = vipMemberStartNum / 10000000 |
|
|
|
// vipMemberStartNumStr = utils.Int64ToStr(vipMemberStartNum) + "千万" |
|
|
|
// } else if vipMemberStartNum >= 100000000 { |
|
|
|
// vipMemberStartNum = vipMemberStartNum / 100000000 |
|
|
|
// vipMemberStartNumStr = utils.Int64ToStr(vipMemberStartNum) + "亿" |
|
|
|
// } else { |
|
|
|
// vipMemberStartNumStr = utils.Int64ToStr(vipMemberStartNum) |
|
|
|
// } |
|
|
|
// |
|
|
|
// if vipMemberEndNums >= 10000 && vipMemberEndNums < 100000 { |
|
|
|
// vipMemberEndNums = vipMemberEndNums / 10000 |
|
|
|
// vipMemberEndNumsStr = utils.Int64ToStr(vipMemberEndNums) + "万" |
|
|
|
// } else if vipMemberEndNums >= 100000 && vipMemberEndNums < 1000000 { |
|
|
|
// vipMemberEndNums = vipMemberEndNums / 100000 |
|
|
|
// vipMemberEndNumsStr = utils.Int64ToStr(vipMemberEndNums) + "十万" |
|
|
|
// } else if vipMemberEndNums >= 1000000 && vipMemberEndNums < 10000000 { |
|
|
|
// vipMemberEndNums = vipMemberEndNums / 1000000 |
|
|
|
// vipMemberEndNumsStr = utils.Int64ToStr(vipMemberEndNums) + "百万" |
|
|
|
// } else if vipMemberEndNums >= 10000000 && vipMemberEndNums < 100000000 { |
|
|
|
// vipMemberEndNums = vipMemberEndNums / 10000000 |
|
|
|
// vipMemberEndNumsStr = utils.Int64ToStr(vipMemberEndNums) + "千万" |
|
|
|
// } else if vipMemberEndNums >= 100000000 { |
|
|
|
// vipMemberEndNums = vipMemberEndNums / 100000000 |
|
|
|
// vipMemberEndNumsStr = utils.Int64ToStr(vipMemberEndNums) + "亿" |
|
|
|
// } else { |
|
|
|
// vipMemberEndNumsStr = utils.Int64ToStr(vipMemberEndNums) |
|
|
|
// |
|
|
|
// } |
|
|
|
// barChartXData = append(barChartXData, vipMemberStartNumStr+"~"+vipMemberEndNumsStr) |
|
|
|
//} |
|
|
|
// |
|
|
|
////3、统计当前平台累计用户、距离下次减产还剩多少人 |
|
|
|
//results, err := commDb.QueryNativeString(engine, "SELECT COUNT(*)AS total FROM user") |
|
|
|
//if err != nil { |
|
|
|
// e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
// return |
|
|
|
//} |
|
|
|
//userCount := utils.StrToInt64(results[0]["total"]) |
|
|
|
//var nextReduceMembers string |
|
|
|
//for k, v := range signInRewards { |
|
|
|
// if zhios_order_relate_utils.StrToInt64(v.VipMemberEndNums) >= userCount && userCount >= zhios_order_relate_utils.StrToInt64(v.VipMemberStartNums) { |
|
|
|
// nextReduceMembers = utils.Int64ToStr(utils.StrToInt64(signInRewards[k+1].VipMemberStartNums) - userCount) |
|
|
|
// } |
|
|
|
//} |
|
|
|
//e.OutSuc(c, map[string]interface{}{ |
|
|
|
// "now_basal_rate": nowBasalRate, |
|
|
|
// "sign_countdown": signCountdown, |
|
|
|
// "user_count": userCount, |
|
|
|
// "next_reduce_members": nextReduceMembers, |
|
|
|
// "bar_chart_data": map[string]interface{}{ |
|
|
|
// "x_data": barChartXData, |
|
|
|
// "y_data": barChartYData, |
|
|
|
// }, |
|
|
|
//}, nil) |
|
|
|
//return |
|
|
|
e.OutSuc(c, nil, nil) |
|
|
|
val, exists := c.Get("user") |
|
|
|
if !exists { |
|
|
|
e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
user, ok := val.(*model.User) |
|
|
|
if !ok { |
|
|
|
e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) |
|
|
|
eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ |
|
|
|
"key": "is_open", |
|
|
|
"value": 1, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
coinID := eggEnergyBasicSetting.PersonEggEnergyCoinId |
|
|
|
coinDb := implement.NewVirtualCoinDb(db.Db) |
|
|
|
coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{ |
|
|
|
"key": "id", |
|
|
|
"value": coinID, |
|
|
|
}) |
|
|
|
now := time.Now() |
|
|
|
nowStr := now.Format("2006-01-02 15:04:05") |
|
|
|
signInDb := implement.NewEggSignInDb(db.Db) |
|
|
|
has, eggSignIn, err := signInDb.EggSignINGetOneByTimeAndUid(nowStr, nowStr, user.Id, 0) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
if !has { |
|
|
|
resp := md.BasalRateResp{ |
|
|
|
ConsumedTime: "", |
|
|
|
ConsumedEggEnergy: "", |
|
|
|
RemainingTime: "", |
|
|
|
RemainingEggEnergy: "", |
|
|
|
BasalRate: "", |
|
|
|
ConsumedEggPoint: "", |
|
|
|
EstimatedRevenue: "", |
|
|
|
SignCountdown: "0000:00:00", |
|
|
|
} |
|
|
|
e.OutSuc(c, resp, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
ratio, err := decimal.NewFromString(coin.ExchangeRatio) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
estimatePerSecondEggEnergyValue, err := decimal.NewFromString(eggSignIn.EstimatePerSecondEggEnergyValue) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
// 消耗时间、已获得收益 |
|
|
|
consumedTimeSec := now.Unix() - utils.TimeParseStd(eggSignIn.StartTime).Unix() |
|
|
|
consumedTime := decimal.NewFromInt(consumedTimeSec).Div(decimal.NewFromInt(60 * 60)) |
|
|
|
consumedEggEnergy := decimal.NewFromInt(consumedTimeSec).Mul(estimatePerSecondEggEnergyValue) |
|
|
|
consumedAmount := consumedEggEnergy.Div(ratio) |
|
|
|
|
|
|
|
// 剩余时间、待收益 |
|
|
|
remainingTimeSec := utils.TimeParseStd(eggSignIn.EndTime).Unix() - now.Unix() |
|
|
|
remainingTime := decimal.NewFromInt(remainingTimeSec).Div(decimal.NewFromInt(60 * 60)) |
|
|
|
remainingEggEnergy := decimal.NewFromInt(remainingTimeSec).Mul(estimatePerSecondEggEnergyValue) |
|
|
|
remainingAmount := remainingEggEnergy.Div(ratio) |
|
|
|
|
|
|
|
// 预估收益 |
|
|
|
estimatedRevenue := consumedAmount.Add(remainingAmount) |
|
|
|
// 基础速率 / 每小时 |
|
|
|
basalRateDecimal, err := decimal.NewFromString(eggSignIn.EstimatePerSecondEggEnergyValue) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
basalRate := basalRateDecimal.Mul(decimal.NewFromInt(60 * 60)) |
|
|
|
// 收益倒计时 |
|
|
|
duration := utils.TimeParseStd(eggSignIn.EndTime).Sub(now) // 计算时间差值 |
|
|
|
hours := duration / time.Hour // 获取小时部分 |
|
|
|
minutes := duration % time.Hour / time.Minute // 获取分钟部分(先除去小时后再乘以60) |
|
|
|
seconds := int64(duration/time.Second) % 60 |
|
|
|
signCountdown := fmt.Sprintf("%d:%d:%d", hours, minutes, seconds) //收益倒计时 |
|
|
|
|
|
|
|
resp := md.BasalRateResp{ |
|
|
|
ConsumedTime: consumedTime.StringFixed(2), |
|
|
|
ConsumedEggEnergy: consumedEggEnergy.StringFixed(2), |
|
|
|
RemainingTime: remainingTime.StringFixed(2), |
|
|
|
RemainingEggEnergy: remainingEggEnergy.StringFixed(2), |
|
|
|
BasalRate: basalRate.StringFixed(2), |
|
|
|
ConsumedEggPoint: eggSignIn.TotalPersonEggPoints, |
|
|
|
EstimatedRevenue: estimatedRevenue.StringFixed(2), |
|
|
|
SignCountdown: signCountdown, |
|
|
|
} |
|
|
|
e.OutSuc(c, resp, nil) |
|
|
|
} |
|
|
|
|
|
|
|
// TotalRate |
|
|
|
// @Summary 蛋蛋星球-添加好友-总速率(获取) |
|
|
|
// @Tags 添加好友 |
|
|
|
// @Description 总速率(获取) |
|
|
|
// @Accept json |
|
|
|
// @Produce json |
|
|
|
// @param Authorization header string true "验证参数Bearer和token空格拼接" |
|
|
|
// @Success 200 {object} md.TotalRateResp "具体数据" |
|
|
|
// @Failure 400 {object} md.Response "具体错误" |
|
|
|
// @Router /api/v1/addFriend/totalRate [GET] |
|
|
|
func TotalRate(c *gin.Context) { |
|
|
|
val, exists := c.Get("user") |
|
|
|
if !exists { |
|
|
|
e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
user, ok := val.(*model.User) |
|
|
|
if !ok { |
|
|
|
e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) |
|
|
|
eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ |
|
|
|
"key": "is_open", |
|
|
|
"value": 1, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var teamRewardSetting *md2.TeamRewardSettingStruct |
|
|
|
err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
now := time.Now() |
|
|
|
|
|
|
|
signInDb := implement.NewEggSignInDb(db.Db) |
|
|
|
// 计算用户是否在团队收益时间段内签到 |
|
|
|
var oneRoundDuration = utils.StrToInt(teamRewardSetting.OneRoundDuration) |
|
|
|
startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05") |
|
|
|
exit, signIn, err := signInDb.EggSignInGetOne(startTime, now.Format("2006-01-02 15:04:05"), user.Id) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var signEggEnergy = "0.00" |
|
|
|
if exit && utils.TimeParseStd(signIn.EndTime).After(now) { |
|
|
|
//获取预估每秒获得蛋蛋能量数 |
|
|
|
estimatePerSecondEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondEggEnergyValue) |
|
|
|
if err1 != nil { |
|
|
|
e.OutErr(c, e.ERR, err1.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
signEggEnergy = estimatePerSecondEggEnergyValue.String() |
|
|
|
} |
|
|
|
|
|
|
|
nowBasalRate := utils.StrToFloat64(signEggEnergy) * 60 * 60 //每小时基础速率 |
|
|
|
var estimateLevel int |
|
|
|
nowBasalRateValue := decimal.NewFromFloat(nowBasalRate) |
|
|
|
for { |
|
|
|
estimateLevel++ |
|
|
|
rewardDecrementValue := utils.StrToFloat64(teamRewardSetting.RewardDecrementValue) / 100 |
|
|
|
tmpRewardBase := decimal.NewFromFloat(math.Pow(rewardDecrementValue, float64(estimateLevel))) |
|
|
|
tmpReward := nowBasalRateValue.Mul(tmpRewardBase) |
|
|
|
rewardEndValue, _ := decimal.NewFromString(teamRewardSetting.RewardEndValue) |
|
|
|
if !tmpReward.GreaterThanOrEqual(rewardEndValue) { |
|
|
|
estimateLevel-- |
|
|
|
break |
|
|
|
} |
|
|
|
if estimateLevel == 99 { |
|
|
|
e.OutErr(c, e.ERR, "奖励结束值设置有误") |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
relateDb := implement.NewUserRelateDb(db.Db) |
|
|
|
userRelates, err := relateDb.FindUserRelateByParentUid(user.Id, estimateLevel) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
var userRelatesUids []string |
|
|
|
var userRelatesMap = map[int64]model.UserRelate{} |
|
|
|
if userRelates != nil { |
|
|
|
for _, userRelate := range *userRelates { |
|
|
|
userRelatesUids = append(userRelatesUids, utils.Int64ToStr(userRelate.Uid)) |
|
|
|
userRelatesMap[userRelate.Uid] = userRelate |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var eggSignIns []*model.EggSignIn |
|
|
|
if len(userRelatesUids) > 0 { |
|
|
|
eggSignIns, err = signInDb.EggSignInFindByParams(map[string]interface{}{ |
|
|
|
"key": "uid", |
|
|
|
"value": userRelatesUids, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var nowTeamRate float64 //每小时基础速率 |
|
|
|
for _, vv := range eggSignIns { |
|
|
|
rewardDecrementValue := utils.StrToFloat64(teamRewardSetting.RewardDecrementValue) / 100 |
|
|
|
tmpRewardBase := decimal.NewFromFloat(math.Pow(rewardDecrementValue, float64(userRelatesMap[vv.Uid].Level))) |
|
|
|
tmpReward := nowBasalRateValue.Mul(tmpRewardBase) |
|
|
|
rewardEndValue, _ := decimal.NewFromString(teamRewardSetting.RewardEndValue) |
|
|
|
if tmpReward.GreaterThanOrEqual(rewardEndValue) { |
|
|
|
tmpRewardValue, _ := tmpReward.Float64() |
|
|
|
nowTeamRate += tmpRewardValue |
|
|
|
} |
|
|
|
} |
|
|
|
resp := md.TotalRateResp{ |
|
|
|
NowBasalRate: utils.Float64ToStr(nowBasalRate), |
|
|
|
NowTeamRate: utils.Float64ToStr(nowTeamRate), |
|
|
|
ConsumedPersonalEggPoint: signIn.TotalPersonEggPoints, |
|
|
|
ConsumedTeamEggPoint: signIn.TotalTeamEggPoints, |
|
|
|
NowTotalRate: utils.Float64ToStr(nowTeamRate + nowBasalRate), |
|
|
|
} |
|
|
|
e.OutSuc(c, resp, nil) |
|
|
|
} |
|
|
|
|
|
|
|
// MyFans |
|
|
|