|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875 |
- package egg_energy
-
- import (
- "applet/app/cfg"
- "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"
- rule "code.fnuoos.com/EggPlanet/egg_system_rules.git"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum"
- md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc"
- "errors"
- "fmt"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- // 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/getVirtualCoinList [get]
- 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)
-
- }
-
- // BatchAddVirtualCoins
- // @Summary 制度中心-蛋蛋能量-批量新增币种
- // @Tags 蛋蛋能量
- // @Description 批量新增币种
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.BatchAddVirtualCoinsReq true "新增数据信息"
- // @Success 200 {int} "新增数据数量"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/batchAddVirtualCoins [POST]
- func BatchAddVirtualCoins(c *gin.Context) {
- var req *md.BatchAddVirtualCoinsReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
- now := time.Now()
- coins := make([]model.VirtualCoin, len(req.List))
- for i, node := range req.List {
- coins[i].Name = node.Name
- coins[i].ExchangeRatio = node.ExchangeRatio
- coins[i].IsUse = node.IsUse
- coins[i].CreateAt = now.Format("2006-01-02 15:04:05")
- coins[i].UpdateAt = now.Format("2006-01-02 15:04:05")
- }
-
- coinDb := implement.NewVirtualCoinDb(db.Db)
- affected, err := coinDb.VirtualCoinBatchAdd(coins)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, affected, nil)
- return
- }
-
- // UpdateVirtualCoin
- // @Summary 制度中心-蛋蛋能量-更新币种信息
- // @Tags 蛋蛋能量
- // @Description 更新币种信息
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UpdateVirtualCoinReq true "更新数据信息"
- // @Success 200 {int} "更新数据数量"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/updateVirtualCoin [POST]
- func UpdateVirtualCoin(c *gin.Context) {
- var req *md.UpdateVirtualCoinReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- coinDb := implement.NewVirtualCoinDb(db.Db)
- coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": req.Id,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if coin == nil {
- e.OutErr(c, e.ERR_NO_DATA, errors.New("该币种不存在"))
- return
- }
-
- m := model.VirtualCoin{
- Id: req.Id,
- Name: req.Name,
- ExchangeRatio: req.ExchangeRatio,
- IsUse: req.IsUse,
- }
- forceColumns := []string{"is_use"}
- affected, err := coinDb.VirtualCoinUpdate(&m, forceColumns...)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, affected, nil)
- }
-
- // DeleteVirtualCoin
- // @Summary 制度中心-蛋蛋能量-删除币种
- // @Tags 蛋蛋能量
- // @Description 删除币种
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Success 200 {int} "删除数据数量"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/deleteVirtualCoin/{$id} [DELETE]
- func DeleteVirtualCoin(c *gin.Context) {
- id := c.Param("id")
-
- coinDb := implement.NewVirtualCoinDb(db.Db)
- affected, err := coinDb.VirtualCoinDelete(id)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, affected, 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)
-
- var newUserRewardRules md2.NewUserRewardRules
- utils.Unserialize([]byte(basicSettings.NewUserIncentiveRules), &newUserRewardRules)
-
- var directPushReward md2.DirectPushRewardSettingStruct
- utils.Unserialize([]byte(basicSettings.DirectPushReward), &directPushReward)
-
- resp := md.GetEggEnergyBasicResp{
- BasicSetting: md.BasicSetting{
- IsOpen: basicSettings.IsOpen,
- InitialPrice: basicSettings.InitialPrice,
- PersonEggEnergyCoinId: basicSettings.PersonEggEnergyCoinId,
- TeamEggEnergyCoinId: basicSettings.TeamEggEnergyCoinId,
- PersonEggPointsCoinId: basicSettings.PersonEggPointsCoinId,
- TeamEggPointsCoinId: basicSettings.TeamEggPointsCoinId,
- DirectPushReward: md2.DirectPushRewardSettingStruct{
- RewardRateValue: directPushReward.RewardRateValue,
- MemberSelfIsOpenGetTeamReward: directPushReward.MemberSelfIsOpenGetTeamReward,
- },
- },
- 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,
- TotalTeamDividends: basicSettings.TotalTeamDividends,
- TotalUserForPerson: basicSettings.TotalUserForPerson,
- TotalUserForTeam: basicSettings.TotalUserForTeam,
- },
- DestructionSetting: destructionSetting,
- PriceSetting: priceSetting,
- ExchangeRules: exchangeRules,
- RewardSystem: rewardSystem,
- NewUserIncentiveRules: newUserRewardRules,
- SystemID: basicSettings.Id,
- SettlementQuantity: basicSettings.SettlementQuantity,
- }
-
- 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)
- newUserIncentiveRulesStr := utils.SerializeStr(req.NewUserIncentiveRules)
- directPushRewardStr := utils.SerializeStr(req.BasicSetting.DirectPushReward)
-
- 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: directPushRewardStr,
- PriceSetting: priceSettingStr,
- VideoRewardIsOpen: req.VideoRewardSetting.VideoRewardIsOpen,
- VideoRewardSystem: videoRewardSystemStr,
- ExchangeRules: exchangeRulesStr,
- RewardSystem: rewardSystemStr,
- NewUserIncentiveRules: newUserIncentiveRulesStr,
- TotalTeamDividends: req.DataSetting.TotalTeamDividends,
- SettlementQuantity: utils.StrToInt(req.SettlementQuantity),
- }
-
- forceColums := []string{"is_open", "video_reward_is_open"}
- energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
- session := db.Db.NewSession()
- defer session.Close()
- affected, err := energyBasicSettingDb.EggEnergyBasicSettingUpdate(session, req.SystemID, &m, forceColums...)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, affected, nil)
- }
-
- // GetEggEnergyVipSetting
- // @Summary 制度中心-蛋蛋能量-基础会员设置(获取)
- // @Tags 蛋蛋能量
- // @Description 基础会员设置(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.GetEggEnergyVipSettingResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/getVipSetting [get]
- func GetEggEnergyVipSetting(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 vipEquitySetting []md2.VipEquitySettingStruct
- utils.Unserialize([]byte(basicSettings.VipEquitySetting), &vipEquitySetting)
-
- levelDb := implement.NewUserLevelDb(db.Db)
- levels, err1 := levelDb.UserLevelAllByAsc()
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- levelsList := make([]map[string]interface{}, 0)
- levelsMap := make(map[int]string)
- for _, level := range levels {
- levelsList = append(levelsList, map[string]interface{}{
- "id": level.Id,
- "name": level.LevelName,
- })
- levelsMap[level.Id] = level.LevelName
- }
-
- list := make([]md.VipEquitySettingNode, len(vipEquitySetting))
- for i, settingStruct := range vipEquitySetting {
- list[i].VipLevelName = levelsMap[utils.StrToInt(settingStruct.VipLevelId)]
- list[i].ExchangeAccountBalanceFee = settingStruct.ExchangeAccountBalanceFee
- list[i].DividendRatio = settingStruct.DividendRatio
- list[i].VipLevelID = settingStruct.VipLevelId
- }
-
- resp := md.GetEggEnergyVipSettingResp{
- LevelList: levelsList,
- List: list,
- }
-
- e.OutSuc(c, resp, nil)
- }
-
- // AddEggEnergyVipSetting
- // @Summary 制度中心-蛋蛋能量-会员设置(新增)
- // @Tags 蛋蛋能量
- // @Description 会员设置(新增)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UpdateEggEnergyVipSettingReq true "system_id 必填"
- // @Success 200 {int} "修改数据条数"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/addVipSetting [post]
- func AddEggEnergyVipSetting(c *gin.Context) {
- var req *md.AddEggEnergyVipSettingReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- setting := md2.VipEquitySettingStruct{
- VipLevelId: req.VipLevelId,
- ExchangeAccountBalanceFee: req.ExchangeAccountBalanceFee,
- DividendRatio: req.DividendRatio,
- }
-
- 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 vipEquitySetting []md2.VipEquitySettingStruct
- utils.Unserialize([]byte(basicSettings.VipEquitySetting), &vipEquitySetting)
-
- vipEquitySetting = append(vipEquitySetting, setting)
- vipEquitySettingStr := utils.SerializeStr(vipEquitySetting)
- basicSettings.VipEquitySetting = vipEquitySettingStr
-
- session := db.Db.NewSession()
- affected, err := basicSettingDb.EggEnergyBasicSettingUpdate(session, basicSettings.Id, basicSettings, "vip_equity_setting")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, affected, nil)
- }
-
- // UpdateEggEnergyVipSetting
- // @Summary 制度中心-蛋蛋能量-会员设置(更新)
- // @Tags 蛋蛋能量
- // @Description 会员设置(更新)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UpdateEggEnergyVipSettingReq true "填入修改后的列表(会员等级名称、兑换余额手续费、分红比例)"
- // @Success 200 {int} "修改数据条数"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/updateVipSetting [post]
- func UpdateEggEnergyVipSetting(c *gin.Context) {
- var req *md.UpdateEggEnergyVipSettingReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- 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
- }
-
- levelDb := implement.NewUserLevelDb(db.Db)
- levels, err1 := levelDb.UserLevelAllByAsc()
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- levelsList := make([]map[string]interface{}, 0)
- for _, level := range levels {
- levelsList = append(levelsList, map[string]interface{}{
- "id": level.Id,
- "name": level.LevelName,
- })
- }
-
- vipEquitySetting := make([]md2.VipEquitySettingStruct, len(req.List))
- for i, node := range req.List {
- vipEquitySetting[i] = md2.VipEquitySettingStruct{
- VipLevelId: node.VipLevelID,
- ExchangeAccountBalanceFee: node.ExchangeAccountBalanceFee,
- DividendRatio: node.DividendRatio,
- }
- }
-
- vipEquitySettingStr := utils.SerializeStr(vipEquitySetting)
- basicSettings.VipEquitySetting = vipEquitySettingStr
- session := db.Db.NewSession()
- affected, err := basicSettingDb.EggEnergyBasicSettingUpdate(session, basicSettings.Id, basicSettings, "vip_equity_setting")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, affected, nil)
- }
-
- // GetEggEnergyCoreData
- // @Summary 制度中心-蛋蛋能量-核心数据(获取)
- // @Tags 蛋蛋能量
- // @Description 核心数据(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.GetEggEnergyCoreDataResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/coreData [GET]
- func GetEggEnergyCoreData(c *gin.Context) {
- dataDb := implement.NewEggEnergyCoreDataDb(db.Db)
- coreData, err := dataDb.EggEnergyCoreDataGet()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- resp := md.GetEggEnergyCoreDataResp{
- Id: coreData.Id,
- NowPrice: coreData.NowPrice,
- PlanetTotalValue: coreData.PlanetTotalValue,
- NowEnergyTotalNums: coreData.NowEnergyTotalNums,
- MarketplaceMerchantNums: coreData.MarketplaceMerchantNums,
- MarketplaceMerchantFunds: coreData.MarketplaceMerchantFunds,
- DevelopmentCommittee: coreData.DevelopmentCommittee,
- PublicWelfareAndCharity: coreData.PublicWelfareAndCharity,
- StarLevelDividends: coreData.StarLevelDividends,
- CommunityDividends: coreData.CommunityDividends,
- DestructionQuantityNums: coreData.DestructionQuantityNums,
- }
- e.OutSuc(c, resp, nil)
- }
-
- // UpdateEggEnergyCoreData
- // @Summary 制度中心-蛋蛋能量-核心数据(更新)
- // @Tags 蛋蛋能量
- // @Description 核心数据(更新)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UpdateEggEnergyCoreDataReq true "需要修改的内容和 id"
- // @Success 200 {int} "修改数据条数"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/coreData [POST]
- func UpdateEggEnergyCoreData(c *gin.Context) {
- var req *md.UpdateEggEnergyCoreDataReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- engine := db.Db
- coreDataDb := implement.NewEggEnergyCoreDataDb(engine)
- rule.Init(cfg.RedisAddr)
- _, cb, err := svc.GetEggEnergyCoreData(engine)
- if err != nil {
- return
- }
- if cb != nil {
- defer cb() // 释放锁
- }
-
- session := engine.NewSession()
- defer session.Close()
-
- m := model.EggEnergyCoreData{
- NowPrice: req.NowPrice,
- PlanetTotalValue: req.PlanetTotalValue,
- NowEnergyTotalNums: req.NowEnergyTotalNums,
- MarketplaceMerchantNums: req.MarketplaceMerchantNums,
- MarketplaceMerchantFunds: req.MarketplaceMerchantFunds,
- DevelopmentCommittee: req.DevelopmentCommittee,
- PublicWelfareAndCharity: req.PublicWelfareAndCharity,
- StarLevelDividends: req.StarLevelDividends,
- CommunityDividends: req.CommunityDividends,
- }
-
- affected, err := coreDataDb.EggEnergyCoreDataUpdateBySession(session, req.Id, &m)
- if err != nil {
- session.Rollback()
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- err = session.Commit()
- if err != nil {
- session.Rollback()
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, affected, nil)
- }
-
- // GetEggCoreDataList
- // @Summary 制度中心-蛋蛋能量-数据概览(获取)
- // @Tags 蛋蛋能量
- // @Description 数据概览(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.GetEggCoreDataListResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/globalData/coreDataList [get]
- func GetEggCoreDataList(c *gin.Context) {
- coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db)
- coreData, err := coreDataDb.EggEnergyCoreDataGet()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if coreData == nil {
- e.OutErr(c, e.ERR_NO_DATA, errors.New("数据不存在"))
- return
- }
-
- sql := "SELECT SUM(amount) AS total, coin_id FROM `user_virtual_amount` GROUP BY (coin_id)"
- results, err := db.Db.QueryString(sql)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
- setting, err := settingDb.EggEnergyBasicSettingGetOne()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, nil)
- return
- }
-
- var userHoldTotalNums float64
- for _, result := range results {
- switch utils.StrToInt(result["coin_id"]) {
- case setting.PersonEggEnergyCoinId, setting.TeamEggEnergyCoinId, setting.PersonEggPointsCoinId, setting.TeamEggPointsCoinId:
- userHoldTotalNums += utils.StrToFloat64(result["total"])
- }
- }
-
- resp := md.GetEggCoreDataListResp{
- PlanetTotalValue: coreData.PlanetTotalValue,
- NowPrice: coreData.NowPrice,
- NowEnergyTotalNums: coreData.NowEnergyTotalNums,
- UserHoldTotalNums: utils.Float64ToStr(userHoldTotalNums),
- }
-
- 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/institutionalManagement/eggEnergy/globalData/pointsCenterPriceCurve [get]
- func GetPriceCurve(c *gin.Context) {
- kind := c.DefaultQuery("kind", "1")
- now := time.Now()
-
- var yData []interface{}
- var xData []interface{}
-
- 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.OutSuc(c, md.GetPriceCurveResp{
- YData: yData,
- XData: xData,
- }, nil)
- return
- }
-
- 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
- }
-
- // GetFundDataList
- // @Summary 制度中心-蛋蛋能量-新增数据列表(获取)
- // @Tags 蛋蛋能量
- // @Description 新增数据列表(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.GetFundDataListReq true "分页信息必填"
- // @Success 200 {object} md.GetFundDataListResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataList [post]
- func GetFundDataList(c *gin.Context) {
- var req *md.GetFundDataListReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- var kindList = []map[string]interface{}{
- {
- "name": enum.EggEnergyFundDataKind.String(enum.CompanySubsidies),
- "value": enum.CompanySubsidies,
- },
- {
- "name": enum.EggEnergyFundDataKind.String(enum.InvestmentByInvestors),
- "value": enum.InvestmentByInvestors,
- },
- {
- "name": enum.EggEnergyFundDataKind.String(enum.MarketExpectations),
- "value": enum.MarketExpectations,
- },
- }
-
- fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
- fundDataList, total, err := fundDataDb.EggEnergyFundDataFindAndCount(req.Page, req.Limit, req.Kind, req.StartAt, req.EndAt)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- list := make([]md.FundDataNode, len(fundDataList))
- for i, fundData := range fundDataList {
- list[i].Kind = fundData.Kind
- list[i].TotalAmount = fundData.TotalAmount
- list[i].Hours = fundData.Hours
- list[i].Memo = fundData.Memo
- list[i].BalanceTimes = fundData.BalanceTimes
- list[i].BalanceAmount = fundData.BalanceAmount
- list[i].CreateAt = fundData.CreateAt
- list[i].SystemID = fundData.Id
- }
-
- resp := md.GetFundDataListResp{
- KindList: kindList,
- Paginate: md.Paginate{
- Limit: req.Limit,
- Page: req.Page,
- Total: total,
- },
- List: list,
- }
- e.OutSuc(c, resp, nil)
- }
-
- // GetFundDataRecordList
- // @Summary 制度中心-蛋蛋能量-新增数据列表详情(查询)
- // @Tags 蛋蛋能量
- // @Description 新增数据列表详情(查询)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.GetFundDataRecordListReq true "获取到的 system_id 以及分页信息"
- // @Success 200 {object} md.GetFundDataRecordListResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataRecordList [post]
- func GetFundDataRecordList(c *gin.Context) {
- var req *md.GetFundDataRecordListReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- recordsDb := implement.NewEggEnergyFundDataRecordsDb(db.Db)
- records, total, err := recordsDb.EggEnergyFundDataRecordsFindAndCount(req.Page, req.Limit, req.SystemID)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- var list []md.FundDataRecordNode
- for i, record := range records {
- list[i].TotalAmount = record.TotalAmount
- list[i].BalanceAmount = record.BalanceAmount
- list[i].BalanceTimes = record.BalanceTimes
- list[i].BeforePrice = record.BeforePrice
- list[i].AfterPrice = record.AfterPrice
- list[i].BeforePlanetTotalValue = record.BeforePlanetTotalValue
- list[i].AfterPlanetTotalValue = record.AfterPlanetTotalValue
- list[i].CreateAt = record.CreateAt
- }
-
- resp := md.GetFundDataRecordListResp{
- Paginate: md.Paginate{
- Limit: req.Limit,
- Page: req.Page,
- Total: total,
- },
- List: list,
- }
-
- e.OutSuc(c, resp, nil)
- }
-
- // AddFundData
- // @Summary 制度中心-蛋蛋能量-价值明细数据(新增)
- // @Tags 蛋蛋能量
- // @Description 价值明细数据(新增)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.AddFundDataReq true "数据种类、金额、时长(最长24h)、执行次数必填,备注选填"
- // @Success 200 {int} "插入数据 id"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataAdd [post]
- func AddFundData(c *gin.Context) {
- var req *md.AddFundDataReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
- now := time.Now()
- hour := now.Hour()
- if req.Hours > 24 {
- hour = 24
- }
- times := req.Hours * 60 / req.Frequency
- m := model.EggEnergyFundData{
- Kind: req.Kind,
- TotalAmount: req.TotalAmount,
- BalanceAmount: req.TotalAmount,
- Hours: hour,
- BalanceTimes: times,
- Frequency: req.Frequency,
- Memo: req.Memo,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- id, err := fundDataDb.EggEnergyFundDataInsert(&m)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, id, nil)
- }
|