蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

200 lines
8.1 KiB

  1. package egg_energy
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/institutional_management/egg_energy"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  10. "errors"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // GetVirtualCoinList
  14. // @Summary 制度中心-蛋蛋能量-查询所有币种(获取)
  15. // @Tags 蛋蛋能量
  16. // @Description 查询所有币种(获取)
  17. // @Accept json
  18. // @Produce json
  19. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  20. // @Success 200 {object} []md.VirtualCoin "成功返回"
  21. // @Failure 400 {object} md.Response "具体错误"
  22. // @Router /api/institutionalManagement/eggEnergy/availableEnergy/list [post]
  23. func GetVirtualCoinList(c *gin.Context) {
  24. virtualCoinDb := implement.NewVirtualCoinDb(db.Db)
  25. coins, err := virtualCoinDb.VirtualCoinFindAll()
  26. if err != nil {
  27. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  28. return
  29. }
  30. list := make([]md.VirtualCoin, len(coins))
  31. for i, coin := range coins {
  32. list[i] = md.VirtualCoin{
  33. Id: coin.Id,
  34. Name: coin.Name,
  35. ExchangeRatio: coin.ExchangeRatio,
  36. IsUse: coin.IsUse,
  37. CreateAt: coin.CreateAt,
  38. UpdateAt: coin.UpdateAt,
  39. }
  40. }
  41. e.OutSuc(c, list, nil)
  42. }
  43. // GetEggEnergyBasic
  44. // @Summary 制度中心-蛋蛋能量-基础设置(获取)
  45. // @Tags 蛋蛋能量
  46. // @Description 基础设置(获取)
  47. // @Accept json
  48. // @Produce json
  49. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  50. // @Success 200 {object} md.GetEggEnergyBasicResp "具体数据"
  51. // @Failure 400 {object} md.Response "具体错误"
  52. // @Router /api/institutionalManagement/eggEnergy/getBasic [get]
  53. func GetEggEnergyBasic(c *gin.Context) {
  54. basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  55. basicSettings, err1 := basicSettingDb.EggEnergyBasicSettingGetOne()
  56. if err1 != nil {
  57. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  58. return
  59. }
  60. if basicSettings == nil {
  61. e.OutErr(c, e.ERR_NO_DATA, errors.New("未能获取基础设置"))
  62. return
  63. }
  64. var videoRewardSystem md2.VideoRewardSystemStruct
  65. utils.Unserialize([]byte(basicSettings.VideoRewardSystem), videoRewardSystem)
  66. var destructionSetting md2.DestructionSettingStruct
  67. utils.Unserialize([]byte(basicSettings.DestructionSetting), destructionSetting)
  68. var priceSetting md2.PriceSettingStruct
  69. utils.Unserialize([]byte(basicSettings.PriceSetting), priceSetting)
  70. var exchangeRules md2.ExchangeRulesStruct
  71. utils.Unserialize([]byte(basicSettings.ExchangeRules), exchangeRules)
  72. var rewardSystem md2.RewardSystemStruct
  73. utils.Unserialize([]byte(basicSettings.RewardSystem), rewardSystem)
  74. resp := md.GetEggEnergyBasicResp{
  75. BasicSetting: md.BasicSetting{
  76. IsOpen: basicSettings.IsOpen,
  77. PersonEggEnergyCoinId: basicSettings.PersonEggEnergyCoinId,
  78. TeamEggEnergyCoinId: basicSettings.TeamEggEnergyCoinId,
  79. PersonEggPointsCoinId: basicSettings.PersonEggPointsCoinId,
  80. TeamEggPointsCoinId: basicSettings.TeamEggPointsCoinId,
  81. DirectPushReward: basicSettings.DirectPushReward,
  82. },
  83. VideoRewardSetting: md.VideoRewardSetting{
  84. VideoRewardIsOpen: basicSettings.VideoRewardIsOpen,
  85. VideoRewardSystem: md2.VideoRewardSystemStruct{
  86. RewardValue: videoRewardSystem.RewardValue,
  87. RewardTotalNum: videoRewardSystem.RewardTotalNum,
  88. IntervalMinutes: videoRewardSystem.IntervalMinutes,
  89. EachRoundHour: videoRewardSystem.EachRoundHour,
  90. },
  91. },
  92. DataSetting: md.DataSetting{
  93. TotalIssuanceAmount: basicSettings.TotalIssuanceAmount,
  94. TotalTechnologyTeam: basicSettings.TotalTechnologyTeam,
  95. TotalAngelInvestor: basicSettings.TotalAngelInvestor,
  96. TotalOperateFund: basicSettings.TotalOperateFund,
  97. TotalEcologicalDevelopment: basicSettings.TotalEcologicalDevelopment,
  98. TotalUserForPerson: basicSettings.TotalUserForPerson,
  99. TotalUserForTeam: basicSettings.TotalUserForTeam,
  100. },
  101. DestructionSetting: md2.DestructionSettingStruct{
  102. DestructionQuantity: destructionSetting.DestructionQuantity,
  103. PublicWelfareAndCharity: destructionSetting.PublicWelfareAndCharity,
  104. DevelopmentCommittee: destructionSetting.DevelopmentCommittee,
  105. StarLevelDividends: destructionSetting.StarLevelDividends,
  106. MarketplaceMerchant: destructionSetting.MarketplaceMerchant,
  107. CommunityDividends: destructionSetting.CommunityDividends,
  108. },
  109. PriceSetting: md2.PriceSettingStruct{
  110. PriceHigherThanValue: priceSetting.PriceHigherThanValue,
  111. MarketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue: priceSetting.MarketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue,
  112. PriceBelowValue: priceSetting.PriceBelowValue,
  113. MarketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue: priceSetting.MarketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue,
  114. },
  115. ExchangeRules: md2.ExchangeRulesStruct{
  116. AutoExchangeNumsByPerson: exchangeRules.AutoExchangeNumsByPerson,
  117. AutoExchangeRateByPerson: exchangeRules.AutoExchangeRateByPerson,
  118. AutoExchangeNumsByTeam: exchangeRules.AutoExchangeNumsByTeam,
  119. AutoExchangeRateByTeam: exchangeRules.AutoExchangeRateByTeam,
  120. },
  121. RewardSystem: md2.RewardSystemStruct{
  122. Level: rewardSystem.Level,
  123. RewardCondition: rewardSystem.RewardCondition,
  124. RewardValue: rewardSystem.RewardValue,
  125. },
  126. SystemID: basicSettings.Id,
  127. }
  128. e.OutSuc(c, resp, nil)
  129. }
  130. // UpdateEggEnergyBasic
  131. // @Summary 制度中心-蛋蛋能量-基础设置(获取)
  132. // @Tags 蛋蛋能量
  133. // @Description 基础设置(获取)
  134. // @Accept json
  135. // @Produce json
  136. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  137. // @Param req body md.UpdateEggEnergyBasicReq true "system_id 必填"
  138. // @Success 200 {int} "修改数据条数"
  139. // @Failure 400 {object} md.Response "具体错误"
  140. // @Router /api/institutionalManagement/eggEnergy/updateBasic [post]
  141. func UpdateEggEnergyBasic(c *gin.Context) {
  142. var req *md.UpdateEggEnergyBasicReq
  143. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  144. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  145. return
  146. }
  147. destructionSettingStr := utils.SerializeStr(req.DestructionSetting)
  148. priceSettingStr := utils.SerializeStr(req.PriceSetting)
  149. videoRewardSystemStr := utils.SerializeStr(req.VideoRewardSetting.VideoRewardSystem)
  150. exchangeRulesStr := utils.SerializeStr(req.ExchangeRules)
  151. rewardSystemStr := utils.SerializeStr(req.RewardSystem)
  152. m := model.EggEnergyBasicSetting{
  153. Id: req.SystemID,
  154. IsOpen: req.BasicSetting.IsOpen,
  155. PersonEggEnergyCoinId: req.BasicSetting.PersonEggEnergyCoinId,
  156. TeamEggEnergyCoinId: req.BasicSetting.TeamEggEnergyCoinId,
  157. PersonEggPointsCoinId: req.BasicSetting.PersonEggPointsCoinId,
  158. TeamEggPointsCoinId: req.BasicSetting.TeamEggPointsCoinId,
  159. TotalIssuanceAmount: req.DataSetting.TotalIssuanceAmount,
  160. TotalTechnologyTeam: req.DataSetting.TotalTechnologyTeam,
  161. TotalAngelInvestor: req.DataSetting.TotalAngelInvestor,
  162. TotalOperateFund: req.DataSetting.TotalOperateFund,
  163. TotalEcologicalDevelopment: req.DataSetting.TotalEcologicalDevelopment,
  164. TotalUserForPerson: req.DataSetting.TotalUserForPerson,
  165. TotalUserForTeam: req.DataSetting.TotalUserForTeam,
  166. DestructionSetting: destructionSettingStr,
  167. DirectPushReward: req.BasicSetting.DirectPushReward,
  168. PriceSetting: priceSettingStr,
  169. VideoRewardIsOpen: req.VideoRewardSetting.VideoRewardIsOpen,
  170. VideoRewardSystem: videoRewardSystemStr,
  171. ExchangeRules: exchangeRulesStr,
  172. RewardSystem: rewardSystemStr,
  173. }
  174. energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  175. session := db.Db.NewSession()
  176. affected, err := energyBasicSettingDb.EggEnergyBasicSettingUpdate(session, req.SystemID, &m)
  177. if err != nil {
  178. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  179. return
  180. }
  181. e.OutSuc(c, affected, nil)
  182. }