|
- package egg_energy
-
- import (
- "applet/app/db"
- "applet/app/e"
- md "applet/app/md/institutional_management/egg_energy"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
- "errors"
- "github.com/gin-gonic/gin"
- )
-
- // GetVirtualCoinList
- // @Summary 制度中心-蛋蛋能量-查询所有币种(获取)
- // @Tags 蛋蛋能量
- // @Description 查询所有币种(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} []md.VirtualCoin "成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/availableEnergy/list [post]
- func GetVirtualCoinList(c *gin.Context) {
- virtualCoinDb := implement.NewVirtualCoinDb(db.Db)
- coins, err := virtualCoinDb.VirtualCoinFindAll()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- list := make([]md.VirtualCoin, len(coins))
- for i, coin := range coins {
- list[i] = md.VirtualCoin{
- Id: coin.Id,
- Name: coin.Name,
- ExchangeRatio: coin.ExchangeRatio,
- IsUse: coin.IsUse,
- CreateAt: coin.CreateAt,
- UpdateAt: coin.UpdateAt,
- }
- }
-
- e.OutSuc(c, list, nil)
-
- }
-
- // GetEggEnergyBasic
- // @Summary 制度中心-蛋蛋能量-基础设置(获取)
- // @Tags 蛋蛋能量
- // @Description 基础设置(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.GetEggEnergyBasicResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/getBasic [get]
- func GetEggEnergyBasic(c *gin.Context) {
- basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
- basicSettings, err1 := basicSettingDb.EggEnergyBasicSettingGetOne()
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- if basicSettings == nil {
- e.OutErr(c, e.ERR_NO_DATA, errors.New("未能获取基础设置"))
- return
- }
-
- var videoRewardSystem md2.VideoRewardSystemStruct
- utils.Unserialize([]byte(basicSettings.VideoRewardSystem), videoRewardSystem)
-
- var destructionSetting md2.DestructionSettingStruct
- utils.Unserialize([]byte(basicSettings.DestructionSetting), destructionSetting)
-
- var priceSetting md2.PriceSettingStruct
- utils.Unserialize([]byte(basicSettings.PriceSetting), priceSetting)
-
- var exchangeRules md2.ExchangeRulesStruct
- utils.Unserialize([]byte(basicSettings.ExchangeRules), exchangeRules)
-
- var rewardSystem md2.RewardSystemStruct
- utils.Unserialize([]byte(basicSettings.RewardSystem), rewardSystem)
-
- resp := md.GetEggEnergyBasicResp{
- BasicSetting: md.BasicSetting{
- IsOpen: basicSettings.IsOpen,
- PersonEggEnergyCoinId: basicSettings.PersonEggEnergyCoinId,
- TeamEggEnergyCoinId: basicSettings.TeamEggEnergyCoinId,
- PersonEggPointsCoinId: basicSettings.PersonEggPointsCoinId,
- TeamEggPointsCoinId: basicSettings.TeamEggPointsCoinId,
- DirectPushReward: basicSettings.DirectPushReward,
- },
- VideoRewardSetting: md.VideoRewardSetting{
- VideoRewardIsOpen: basicSettings.VideoRewardIsOpen,
- VideoRewardSystem: md2.VideoRewardSystemStruct{
- RewardValue: videoRewardSystem.RewardValue,
- RewardTotalNum: videoRewardSystem.RewardTotalNum,
- IntervalMinutes: videoRewardSystem.IntervalMinutes,
- EachRoundHour: videoRewardSystem.EachRoundHour,
- },
- },
- DataSetting: md.DataSetting{
- TotalIssuanceAmount: basicSettings.TotalIssuanceAmount,
- TotalTechnologyTeam: basicSettings.TotalTechnologyTeam,
- TotalAngelInvestor: basicSettings.TotalAngelInvestor,
- TotalOperateFund: basicSettings.TotalOperateFund,
- TotalEcologicalDevelopment: basicSettings.TotalEcologicalDevelopment,
- TotalUserForPerson: basicSettings.TotalUserForPerson,
- TotalUserForTeam: basicSettings.TotalUserForTeam,
- },
- DestructionSetting: md2.DestructionSettingStruct{
- DestructionQuantity: destructionSetting.DestructionQuantity,
- PublicWelfareAndCharity: destructionSetting.PublicWelfareAndCharity,
- DevelopmentCommittee: destructionSetting.DevelopmentCommittee,
- StarLevelDividends: destructionSetting.StarLevelDividends,
- MarketplaceMerchant: destructionSetting.MarketplaceMerchant,
- CommunityDividends: destructionSetting.CommunityDividends,
- },
- PriceSetting: md2.PriceSettingStruct{
- PriceHigherThanValue: priceSetting.PriceHigherThanValue,
- MarketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue: priceSetting.MarketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue,
- PriceBelowValue: priceSetting.PriceBelowValue,
- MarketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue: priceSetting.MarketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue,
- },
- ExchangeRules: md2.ExchangeRulesStruct{
- AutoExchangeNumsByPerson: exchangeRules.AutoExchangeNumsByPerson,
- AutoExchangeRateByPerson: exchangeRules.AutoExchangeRateByPerson,
- AutoExchangeNumsByTeam: exchangeRules.AutoExchangeNumsByTeam,
- AutoExchangeRateByTeam: exchangeRules.AutoExchangeRateByTeam,
- },
- RewardSystem: md2.RewardSystemStruct{
- Level: rewardSystem.Level,
- RewardCondition: rewardSystem.RewardCondition,
- RewardValue: rewardSystem.RewardValue,
- },
- SystemID: basicSettings.Id,
- }
-
- e.OutSuc(c, resp, nil)
- }
-
- // UpdateEggEnergyBasic
- // @Summary 制度中心-蛋蛋能量-基础设置(获取)
- // @Tags 蛋蛋能量
- // @Description 基础设置(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UpdateEggEnergyBasicReq true "system_id 必填"
- // @Success 200 {int} "修改数据条数"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/updateBasic [post]
- func UpdateEggEnergyBasic(c *gin.Context) {
- var req *md.UpdateEggEnergyBasicReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- destructionSettingStr := utils.SerializeStr(req.DestructionSetting)
- priceSettingStr := utils.SerializeStr(req.PriceSetting)
- videoRewardSystemStr := utils.SerializeStr(req.VideoRewardSetting.VideoRewardSystem)
- exchangeRulesStr := utils.SerializeStr(req.ExchangeRules)
- rewardSystemStr := utils.SerializeStr(req.RewardSystem)
-
- m := model.EggEnergyBasicSetting{
- Id: req.SystemID,
- IsOpen: req.BasicSetting.IsOpen,
- PersonEggEnergyCoinId: req.BasicSetting.PersonEggEnergyCoinId,
- TeamEggEnergyCoinId: req.BasicSetting.TeamEggEnergyCoinId,
- PersonEggPointsCoinId: req.BasicSetting.PersonEggPointsCoinId,
- TeamEggPointsCoinId: req.BasicSetting.TeamEggPointsCoinId,
- TotalIssuanceAmount: req.DataSetting.TotalIssuanceAmount,
- TotalTechnologyTeam: req.DataSetting.TotalTechnologyTeam,
- TotalAngelInvestor: req.DataSetting.TotalAngelInvestor,
- TotalOperateFund: req.DataSetting.TotalOperateFund,
- TotalEcologicalDevelopment: req.DataSetting.TotalEcologicalDevelopment,
- TotalUserForPerson: req.DataSetting.TotalUserForPerson,
- TotalUserForTeam: req.DataSetting.TotalUserForTeam,
- DestructionSetting: destructionSettingStr,
- DirectPushReward: req.BasicSetting.DirectPushReward,
- PriceSetting: priceSettingStr,
- VideoRewardIsOpen: req.VideoRewardSetting.VideoRewardIsOpen,
- VideoRewardSystem: videoRewardSystemStr,
- ExchangeRules: exchangeRulesStr,
- RewardSystem: rewardSystemStr,
- }
-
- energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
- session := db.Db.NewSession()
- affected, err := energyBasicSettingDb.EggEnergyBasicSettingUpdate(session, req.SystemID, &m)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, affected, nil)
- }
|