package hdl import ( "applet/app/cfg" "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/svc" "applet/app/utils" "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "code.fnuoos.com/EggPlanet/egg_system_rules.git" "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" svc2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" "context" "encoding/json" "errors" "fmt" "github.com/gin-gonic/gin" "github.com/olivere/elastic/v7" "github.com/shopspring/decimal" "time" ) const PointsCenterCalcExchangeRedisKey = "Points_Center_Cache_Key" // PointsCenterGetBasic // @Summary 蛋蛋星球-积分中心-上部分基础信息(获取) // @Tags 积分中心 // @Description 上部分基础信息(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.PointsCenterGetBasicResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/basic [GET] func PointsCenterGetBasic(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 } settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) // 蛋蛋能量 (个人 + 团队) eggPersonalEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggTeamEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggEnergy := utils.StrToFloat64(eggPersonalEnergy.Amount) + utils.StrToFloat64(eggTeamEnergy.Amount) // 蛋蛋能量价值 coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db) coreData, err := coreDataDb.EggEnergyCoreDataGet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggEnergyAmount := utils.StrToFloat64(coreData.NowPrice) * eggEnergy // 活跃积分(蛋蛋积分 = 团队 + 个人) eggPersonalPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggPointsCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggTeamPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggPointsCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggPoint := utils.StrToFloat64(eggPersonalPoint.Amount) + utils.StrToFloat64(eggTeamPoint.Amount) // 蛋蛋积分价值 coinDb := implement.NewVirtualCoinDb(db.Db) coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{ "key": "id", "value": setting.PersonEggPointsCoinId, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } var eggPointValue decimal.Decimal if coin != nil { ratio, _ := decimal.NewFromString(coin.ExchangeRatio) eggPointValue = decimal.NewFromFloat(eggPoint).Div(ratio) } eggPointValue = decimal.NewFromInt(0) // 账户余额 walletDb := implement.NewUserWalletDb(db.Db) wallet, err := walletDb.GetUserVirtualWallet(user.Id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } resp := md.PointsCenterGetBasicResp{ Energy: utils.Float64ToStr(eggEnergy), EnergyValue: utils.Float64ToStr(eggEnergyAmount), WalletAmount: wallet.Amount, EggPoint: utils.Float64ToStr(eggPoint), EggPointValue: eggPointValue.String(), } e.OutSuc(c, resp, nil) } // InitialData // @Summary 蛋蛋星球-积分中心-初始数据(获取) // @Tags 积分中心 // @Description 初始数据(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.InitialDataResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/initialData [GET] func InitialData(c *gin.Context) { settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } resp := md.InitialDataResp{ InitialPrice: setting.InitialPrice, TotalIssuanceAmount: setting.TotalIssuanceAmount, TotalTechnologyTeam: setting.TotalTechnologyTeam, TotalAngelInvestor: setting.TotalAngelInvestor, TotalOperateFund: setting.TotalOperateFund, TotalEcologicalDevelopment: setting.TotalEcologicalDevelopment, } e.OutSuc(c, resp, nil) } // DynamicData // @Summary 蛋蛋星球-积分中心-动态数据(获取) // @Tags 积分中心 // @Description 动态数据(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.DynamicDataResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/dynamicData [GET] func DynamicData(c *gin.Context) { settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } // 1.用户持有总量 redisKey1 := PointsCenterCalcExchangeRedisKey + "_1" redisValue1, err := cache.GetString(redisKey1) if err != nil { if err.Error() == "redigo: nil returned" { amountDb := implement.NewUserVirtualAmountDb(db.Db) total, err := amountDb.UserVirtualAmountGetSumByCoinKind(setting.PersonEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } //将获取到的余额值缓存至redis redisValue1 = utils.Float64ToStr(total) cache.SetEx(redisKey1, redisValue1, 60) } else { e.OutErr(c, e.ERR, err.Error()) return } } // 2.星级分红 redisKey2 := PointsCenterCalcExchangeRedisKey + "_2" redisValue2, err := cache.GetString(redisKey2) if err != nil { if err.Error() == "redigo: nil returned" { coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db) coreData, err := coreDataDb.EggEnergyCoreDataGet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } redisValue2 = coreData.StarLevelDividends cache.SetEx(redisKey2, redisValue2, 60) } else { e.OutErr(c, e.ERR, err.Error()) return } } // 3.发展委员会 redisKey3 := PointsCenterCalcExchangeRedisKey + "_3" redisValue3, err := cache.GetString(redisKey3) if err != nil { if err.Error() == "redigo: nil returned" { coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db) coreData, err := coreDataDb.EggEnergyCoreDataGet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } redisValue3 = coreData.DevelopmentCommittee cache.SetEx(redisKey3, redisValue3, 60) } else { e.OutErr(c, e.ERR, err.Error()) return } } // 4.公益基金 redisKey4 := PointsCenterCalcExchangeRedisKey + "_4" redisValue4, err := cache.GetString(redisKey4) if err != nil { if err.Error() == "redigo: nil returned" { coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db) coreData, err := coreDataDb.EggEnergyCoreDataGet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } redisValue4 = coreData.PublicWelfareAndCharity cache.SetEx(redisKey4, redisValue4, 60) } else { e.OutErr(c, e.ERR, err.Error()) return } } resp := md.DynamicDataResp{ UserTotalHold: redisValue1, StarLevelDividends: redisValue2, DevelopmentCommittee: redisValue3, PublicWelfareAndCharity: redisValue4, } e.OutSuc(c, resp, nil) } // PointsExchangeGetBasic // @Summary 蛋蛋星球-积分中心-积分兑换基础信息(获取) // @Tags 积分中心 // @Description 积分兑换基础信息(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.PointsExchangeGetBasicResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/pointsExchangeBasic [GET] func PointsExchangeGetBasic(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. 获取蛋蛋能量货币类型 settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } coinID := setting.PersonEggEnergyCoinId // 2. 获取可兑蛋蛋能量 virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) eggEnergyAmount, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, coinID) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } // 3. 可用现金 walletDb := implement.NewUserWalletDb(db.Db) wallet, err := walletDb.GetUserVirtualWallet(user.Id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } resp := md.PointsExchangeGetBasicResp{ AvailableEnergy: eggEnergyAmount.Amount, AvailableCash: wallet.Amount, } e.OutSuc(c, resp, nil) } // GetPriceCurve // @Summary 蛋蛋星球-积分中心-价格趋势(获取) // @Tags 积分中心 // @Description 价格趋势(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param kind query string false "1:按天 2:按小时 3:按周" // @Success 200 {object} md.GetPriceCurveResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/priceCurve [GET] func GetPriceCurve(c *gin.Context) { kind := c.DefaultQuery("kind", "1") now := time.Now() priceDb := implement.NewEggEnergyPriceDb(db.Db) m, has, err := priceDb.EggEnergyPriceGetLastOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if has == false { e.OutErr(c, e.ERR_NO_DATA, "未查询到数据") return } var yData []interface{} var xData []interface{} switch kind { case "1": var date = now.AddDate(0, 0, -30).Format("2006-01-02") var sql = fmt.Sprintf("SELECT price,date FROM `egg_energy_price` WHERE HOUR = 23 AND DATE >= \"%s\" AND DATE != \"%s\" ORDER BY DATE ASC ", date, now.Format("2006-01-02")) results, _ := db.Db.QueryString(sql) for _, v := range results { tmpDate := utils.TimeParseStd(v["date"]) yData = append(yData, v["price"]) xData = append(xData, tmpDate.Format("01-02")) } yData = append(yData, m.Price) tmpDate := utils.TimeParseStd(m.Date) xData = append(xData, tmpDate.Format("01-02")) break case "2": for i := 29; i >= 1; i-- { date := now.Add(-time.Hour * 4 * time.Duration(i)).Format("2006-01-02") hour := now.Add(-time.Hour * 4 * time.Duration(i)).Hour() var sql = "SELECT price,date,hour FROM `egg_energy_price` WHERE HOUR = %d AND DATE = \"%s\" " sql = fmt.Sprintf(sql, hour, date) results, _ := db.Db.QueryString(sql) if results != nil { //if results[0]["date"] != now.Format("2006-01-02") { // continue //} yData = append(yData, results[0]["price"]) xData = append(xData, results[0]["hour"]+":00") } } yData = append(yData, m.Price) xData = append(xData, m.Hour+":00") break case "3": var nums = 29 for i := nums; i >= 1; i-- { var date = now.AddDate(0, 0, -7*i).Format("2006-01-02") var sql = "SELECT price, date FROM `egg_energy_price` WHERE HOUR = 23 AND DATE = \"%s\" " sql = fmt.Sprintf(sql, date) results, _ := db.Db.QueryString(sql) if results != nil { tmpDate := utils.TimeParseStd(results[0]["date"]) yData = append(yData, results[0]["price"]) xData = append(xData, tmpDate.Format("01-02")) } } yData = append(yData, m.Price) tmpDate := utils.TimeParseStd(m.Date) xData = append(xData, tmpDate.Format("01-02")) break } e.OutSuc(c, md.GetPriceCurveResp{ YData: yData, XData: xData, }, nil) return } // ExchangeEnergy // @Summary 蛋蛋星球-积分中心-能量兑换 // @Tags 积分中心 // @Description 能量兑换 // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param req body md.ExchangeEnergyReq true "需要兑换的能量值" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/exchangeEnergy [POST] func ExchangeEnergy(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 } var req *md.ExchangeEnergyReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return } // 1. 获取蛋蛋能量货币类型 settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } coinID := setting.PersonEggEnergyCoinId session := db.Db.NewSession() defer session.Close() // 2. 计算蛋蛋能量兑换的金额 egg_system_rules.Init(cfg.RedisAddr) eggEnergyCoreData, cb, err1 := svc2.GetEggEnergyCoreData(db.Db) if err1 != nil { fmt.Println("EggEnergyAutoRecordPrices_ERR:::::", err1.Error()) return } if cb != nil { defer cb() // 释放锁 } energyAmount, err := decimal.NewFromString(req.EnergyAmount) if err != nil { e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) return } nowPrice, err := decimal.NewFromString(eggEnergyCoreData.NowPrice) if err != nil { e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) return } amount, ok := energyAmount.Div(nowPrice).Float64() if !ok { e.OutErr(c, e.ERR_UNMARSHAL, nil) return } // 3. 获取用户蛋蛋能量余额 eggEnergyAmount, err := rule.GetUserCoinAmount(session, coinID, user.Id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } // 4. 判断蛋蛋能量是否足够兑换 if utils.StrToFloat64(eggEnergyAmount) < utils.StrToFloat64(req.EnergyAmount) { e.OutErr(c, e.ERR_BALANCE_NOT_ENOUGH, nil) } // 5. 调用降价公式 err, calcPriceReductionFormula := egg_energy.CalcPriceReductionFormula(req.EnergyAmount, eggEnergyCoreData) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } // 6. 更改动态数据 err = egg_energy.DealAvailableEggEnergyCoin(session, int(enum.EggEnergyExchangeAccountBalance), eggEnergyCoreData, md3.DealAvailableEggEnergyCoinReq{ Amount: calcPriceReductionFormula.GetEggEnergyAmount, AmountFee: "", BeforePrice: calcPriceReductionFormula.BeforePrice, AfterPrice: calcPriceReductionFormula.AfterPrice, BeforePlanetTotalValue: calcPriceReductionFormula.BeforePlanetTotalValue, AfterPlanetTotalValue: calcPriceReductionFormula.AfterPlanetTotalValue, BeforeEnergyTotalNums: calcPriceReductionFormula.BeforeEnergyTotalNums, AfterEnergyTotalNums: calcPriceReductionFormula.AfterEnergyTotalNums, }) if err != nil { fmt.Println("ActivityCoinAutoExchangeEggPersonEnergy:::::err111:::", err) _ = session.Rollback() return } // 7. 扣除蛋蛋能量 dealUserVirtualCoinReq := md2.DealUserVirtualCoinReq{ Kind: "sub", Title: enum.EggEnergyToExchangeToAmount.String(), TransferType: int(enum.EggEnergyToExchangeToAmount), CoinId: coinID, Uid: user.Id, Amount: utils.StrToFloat64(req.EnergyAmount), } err = rule.DealUserVirtualCoin(session, dealUserVirtualCoinReq) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) session.Rollback() return } // 8. 增加账户余额 dealUserWalletReq := md2.DealUserWalletReq{ Direction: "add", Kind: int(enum.EggEnergyExchangeAccountBalance), Title: enum.EggEnergyExchangeAccountBalance.String(), Uid: user.Id, Amount: amount, } err = rule.DealUserWallet(session, dealUserWalletReq) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) session.Rollback() return } err = session.Commit() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) } // GetContributionValue // @Summary 蛋蛋星球-积分中心-贡献值(获取) // @Tags 积分中心 // @Description 贡献值(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.GetContributionValueResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/contributionValue [GET] func GetContributionValue(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 } settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } coinID := setting.ContributionCoinId virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) virtualAmount, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, coinID) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var contributionValue string if virtualAmount != nil { contributionValue = virtualAmount.Amount } coinDb := implement.NewVirtualCoinDb(db.Db) coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{ "key": "id", "value": coinID, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var ratio string if coin != nil { ratio = coin.ExchangeRatio } resp := md.GetContributionValueResp{ ContributionValue: contributionValue, Ratio: ratio, } e.OutSuc(c, resp, nil) } // GetContributionValueFlow // @Summary 蛋蛋星球-积分中心-贡献值明细(获取) // @Tags 积分中心 // @Description 贡献值明细(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param limit query string true "每页大小" // @Param page query string true "页数" // @Success 200 {object} md.GetContributionValueFlowResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/contributionValueFlow [GET] func GetContributionValueFlow(c *gin.Context) { page := c.DefaultQuery("page", "1") limit := c.DefaultQuery("limit", "10") 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 } settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } coinID := setting.ContributionCoinId flowDb := implement.NewUserVirtualCoinFlowDb(db.Db) flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(utils.StrToInt(page), utils.StrToInt(limit), coinID, user.Id, "", "", 0, false, 0) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } list := make([]md.ContributionValueFlowNode, len(flows)) for i, flow := range flows { list[i].Title = flow.Title list[i].Amount = flow.Amount list[i].Direction = utils.IntToStr(flow.Direction) list[i].CreateAt = flow.CreateAt } resp := md.GetContributionValueFlowResp{ List: list, Paginate: md.Paginate{ Limit: utils.StrToInt(limit), Page: utils.StrToInt(page), Total: total, }, } e.OutSuc(c, resp, nil) } func GetPointMap(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 } now := time.Now() // 1. 获取当期有效蛋蛋分 nowIndex := es2.GetLatestEffectiveIndexFromAlias(now) boolQuery := elastic.NewBoolQuery() boolQuery.Filter(elastic.NewTermQuery("uid", user.Id)) searchResult, err := es.EsClient.Search(). Index(nowIndex). Query(boolQuery). Pretty(true). Do(context.Background()) if searchResult == nil { e.OutErr(c, e.ERR_DB_ORM, errors.New("failed to get current egg score")) return } var results []md.UserEggFlowReqRespList if searchResult.Hits.TotalHits.Value != 0 { // 解析结果 for _, hit := range searchResult.Hits.Hits { var doc md.UserEggFlowReqRespList err = json.Unmarshal(hit.Source, &doc) if err != nil { e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) return } results = append(results, doc) } } // nowScore := utils.Float64ToStr(results[0].ScoreValue) // todo 计算分数权重 } // GetEggPointRecord // @Summary 蛋蛋星球-积分中心-蛋蛋分明细(获取) // @Tags 积分中心 // @Description 蛋蛋分明细(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param limit query string true "每页大小" // @Param page query string true "页数" // @Success 200 {object} md.GetEggPointRecordResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/record [GET] func GetEggPointRecord(c *gin.Context) { // todo 待补充 pageStr := c.DefaultQuery("page", "1") limitStr := c.DefaultQuery("limit", "5") page := utils.StrToInt(pageStr) limit := utils.StrToInt(limitStr) 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 } now := time.Now() list, nowScore, indexNum, err := svc.GetEggPointRecordBase(now, user.Id, page, limit) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } resp := md.GetEggPointRecordResp{ NowScore: nowScore, List: list, Paginate: md.Paginate{ Limit: limit, Page: page, Total: int64(indexNum), }, } e.OutSuc(c, resp, nil) } // GetEggEnergyFlow // @Summary 蛋蛋星球-积分中心-收支明细(获取) // @Tags 积分中心 // @Description 收支明细(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param limit query string true "每页大小" // @Param page query string true "页数" // @Param startAt query string false "开始时间" // @Param endAt query string false "结束时间" // @Param direction query string false "流水方向(1.收入 2.支出 0.全部)" // @Success 200 {object} md.GetEggEnergyFlowResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/pointsCenter/energyFlow [GET] func GetEggEnergyFlow(c *gin.Context) { pageStr := c.DefaultQuery("page", "1") limitStr := c.DefaultQuery("limit", "10") startAt := c.Query("startAt") endAt := c.Query("endAt") directionStr := c.Query("direction") 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 } coinDb := implement.NewVirtualCoinDb(db.Db) coins, err := coinDb.VirtualCoinFindAll() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if coins == nil { e.OutErr(c, e.ERR_NO_DATA, errors.New("未初始化货币")) return } coinsList := make([]map[string]interface{}, len(coins)) coinsMap := map[int]string{} for i, coin := range coins { coinsList[i] = map[string]interface{}{ "coinID": coin.Id, "name": coin.Name, } coinsMap[coin.Id] = coin.Name } direction := 0 switch directionStr { case "1": direction = 1 case "2": direction = 2 } page := utils.StrToInt(pageStr) limit := utils.StrToInt(limitStr) flowDb := implement.NewUserVirtualCoinFlowDb(db.Db) flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(page, limit, 0, user.Id, startAt, endAt, direction, false, 0) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } list := make([]md.EggEnergyFlowNode, len(flows)) for i, flow := range flows { list[i].Title = flow.Title list[i].Amount = flow.Amount list[i].Direction = flow.Direction list[i].CreateAt = flow.CreateAt list[i].Id = flow.Id list[i].BeforeAmount = flow.BeforeAmount list[i].AfterAmount = flow.AfterAmount list[i].CoinName = coinsMap[flow.CoinId] list[i].SysFee = flow.SysFee list[i].TransferType = enum.UserVirtualAmountFlowTransferType(flow.TransferType).String() } resp := md.GetEggEnergyFlowResp{ List: list, Paginate: md.Paginate{ Limit: limit, Page: page, Total: total, }, } e.OutSuc(c, resp, nil) }