蛋蛋星球 后台端
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.
 
 
 
 

872 lines
30 KiB

  1. package egg_energy
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. "applet/app/e"
  6. md "applet/app/md/institutional_management/egg_energy"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. rule "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  11. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum"
  12. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  13. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc"
  14. "errors"
  15. "fmt"
  16. "github.com/gin-gonic/gin"
  17. "time"
  18. )
  19. // GetVirtualCoinList
  20. // @Summary 制度中心-蛋蛋能量-查询所有币种(获取)
  21. // @Tags 蛋蛋能量
  22. // @Description 查询所有币种(获取)
  23. // @Accept json
  24. // @Produce json
  25. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  26. // @Success 200 {object} []md.VirtualCoin "成功返回"
  27. // @Failure 400 {object} md.Response "具体错误"
  28. // @Router /api/institutionalManagement/eggEnergy/getVirtualCoinList [get]
  29. func GetVirtualCoinList(c *gin.Context) {
  30. virtualCoinDb := implement.NewVirtualCoinDb(db.Db)
  31. coins, err := virtualCoinDb.VirtualCoinFindAll()
  32. if err != nil {
  33. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  34. return
  35. }
  36. list := make([]md.VirtualCoin, len(coins))
  37. for i, coin := range coins {
  38. list[i] = md.VirtualCoin{
  39. Id: coin.Id,
  40. Name: coin.Name,
  41. ExchangeRatio: coin.ExchangeRatio,
  42. IsUse: coin.IsUse,
  43. CreateAt: coin.CreateAt,
  44. UpdateAt: coin.UpdateAt,
  45. }
  46. }
  47. e.OutSuc(c, list, nil)
  48. }
  49. // BatchAddVirtualCoins
  50. // @Summary 制度中心-蛋蛋能量-批量新增币种
  51. // @Tags 蛋蛋能量
  52. // @Description 批量新增币种
  53. // @Accept json
  54. // @Produce json
  55. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  56. // @Param req body md.BatchAddVirtualCoinsReq true "新增数据信息"
  57. // @Success 200 {int} "新增数据数量"
  58. // @Failure 400 {object} md.Response "具体错误"
  59. // @Router /api/institutionalManagement/eggEnergy/batchAddVirtualCoins [POST]
  60. func BatchAddVirtualCoins(c *gin.Context) {
  61. var req *md.BatchAddVirtualCoinsReq
  62. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  63. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  64. return
  65. }
  66. now := time.Now()
  67. coins := make([]model.VirtualCoin, len(req.List))
  68. for i, node := range req.List {
  69. coins[i].Name = node.Name
  70. coins[i].ExchangeRatio = node.ExchangeRatio
  71. coins[i].IsUse = node.IsUse
  72. coins[i].CreateAt = now.Format("2006-01-02 15:04:05")
  73. coins[i].UpdateAt = now.Format("2006-01-02 15:04:05")
  74. }
  75. coinDb := implement.NewVirtualCoinDb(db.Db)
  76. affected, err := coinDb.VirtualCoinBatchAdd(coins)
  77. if err != nil {
  78. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  79. return
  80. }
  81. e.OutSuc(c, affected, nil)
  82. return
  83. }
  84. // UpdateVirtualCoin
  85. // @Summary 制度中心-蛋蛋能量-更新币种信息
  86. // @Tags 蛋蛋能量
  87. // @Description 更新币种信息
  88. // @Accept json
  89. // @Produce json
  90. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  91. // @Param req body md.UpdateVirtualCoinReq true "更新数据信息"
  92. // @Success 200 {int} "更新数据数量"
  93. // @Failure 400 {object} md.Response "具体错误"
  94. // @Router /api/institutionalManagement/eggEnergy/updateVirtualCoin [POST]
  95. func UpdateVirtualCoin(c *gin.Context) {
  96. var req *md.UpdateVirtualCoinReq
  97. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  98. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  99. return
  100. }
  101. coinDb := implement.NewVirtualCoinDb(db.Db)
  102. coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{
  103. "key": "id",
  104. "value": req.Id,
  105. })
  106. if err != nil {
  107. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  108. return
  109. }
  110. if coin == nil {
  111. e.OutErr(c, e.ERR_NO_DATA, errors.New("该币种不存在"))
  112. return
  113. }
  114. m := model.VirtualCoin{
  115. Id: req.Id,
  116. Name: req.Name,
  117. ExchangeRatio: req.ExchangeRatio,
  118. IsUse: req.IsUse,
  119. }
  120. forceColumns := []string{"is_use"}
  121. affected, err := coinDb.VirtualCoinUpdate(&m, forceColumns...)
  122. if err != nil {
  123. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  124. return
  125. }
  126. e.OutSuc(c, affected, nil)
  127. }
  128. // DeleteVirtualCoin
  129. // @Summary 制度中心-蛋蛋能量-删除币种
  130. // @Tags 蛋蛋能量
  131. // @Description 删除币种
  132. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  133. // @Accept json
  134. // @Produce json
  135. // @Success 200 {int} "删除数据数量"
  136. // @Failure 400 {object} md.Response "具体错误"
  137. // @Router /api/institutionalManagement/eggEnergy/deleteVirtualCoin/{$id} [DELETE]
  138. func DeleteVirtualCoin(c *gin.Context) {
  139. id := c.Param("id")
  140. coinDb := implement.NewVirtualCoinDb(db.Db)
  141. affected, err := coinDb.VirtualCoinDelete(id)
  142. if err != nil {
  143. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  144. return
  145. }
  146. e.OutSuc(c, affected, nil)
  147. }
  148. // GetEggEnergyBasic
  149. // @Summary 制度中心-蛋蛋能量-基础设置(获取)
  150. // @Tags 蛋蛋能量
  151. // @Description 基础设置(获取)
  152. // @Accept json
  153. // @Produce json
  154. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  155. // @Success 200 {object} md.GetEggEnergyBasicResp "具体数据"
  156. // @Failure 400 {object} md.Response "具体错误"
  157. // @Router /api/institutionalManagement/eggEnergy/getBasic [get]
  158. func GetEggEnergyBasic(c *gin.Context) {
  159. basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  160. basicSettings, err1 := basicSettingDb.EggEnergyBasicSettingGetOne()
  161. if err1 != nil {
  162. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  163. return
  164. }
  165. if basicSettings == nil {
  166. e.OutErr(c, e.ERR_NO_DATA, errors.New("未能获取基础设置"))
  167. return
  168. }
  169. var videoRewardSystem md2.VideoRewardSystemStruct
  170. utils.Unserialize([]byte(basicSettings.VideoRewardSystem), &videoRewardSystem)
  171. var destructionSetting md2.DestructionSettingStruct
  172. utils.Unserialize([]byte(basicSettings.DestructionSetting), &destructionSetting)
  173. var priceSetting md2.PriceSettingStruct
  174. utils.Unserialize([]byte(basicSettings.PriceSetting), &priceSetting)
  175. var exchangeRules md2.ExchangeRulesStruct
  176. utils.Unserialize([]byte(basicSettings.ExchangeRules), &exchangeRules)
  177. var rewardSystem []md2.RewardSystemStruct
  178. utils.Unserialize([]byte(basicSettings.RewardSystem), &rewardSystem)
  179. var newUserRewardRules md2.NewUserRewardRules
  180. utils.Unserialize([]byte(basicSettings.NewUserIncentiveRules), &newUserRewardRules)
  181. var directPushReward md2.DirectPushRewardSettingStruct
  182. utils.Unserialize([]byte(basicSettings.DirectPushReward), &directPushReward)
  183. resp := md.GetEggEnergyBasicResp{
  184. BasicSetting: md.BasicSetting{
  185. IsOpen: basicSettings.IsOpen,
  186. PersonEggEnergyCoinId: basicSettings.PersonEggEnergyCoinId,
  187. TeamEggEnergyCoinId: basicSettings.TeamEggEnergyCoinId,
  188. PersonEggPointsCoinId: basicSettings.PersonEggPointsCoinId,
  189. TeamEggPointsCoinId: basicSettings.TeamEggPointsCoinId,
  190. DirectPushReward: md2.DirectPushRewardSettingStruct{
  191. RewardRateValue: directPushReward.RewardRateValue,
  192. MemberSelfIsOpenGetTeamReward: directPushReward.MemberSelfIsOpenGetTeamReward,
  193. },
  194. },
  195. VideoRewardSetting: md.VideoRewardSetting{
  196. VideoRewardIsOpen: basicSettings.VideoRewardIsOpen,
  197. VideoRewardSystem: md2.VideoRewardSystemStruct{
  198. RewardValue: videoRewardSystem.RewardValue,
  199. RewardTotalNum: videoRewardSystem.RewardTotalNum,
  200. IntervalMinutes: videoRewardSystem.IntervalMinutes,
  201. EachRoundHour: videoRewardSystem.EachRoundHour,
  202. },
  203. },
  204. DataSetting: md.DataSetting{
  205. TotalIssuanceAmount: basicSettings.TotalIssuanceAmount,
  206. TotalTechnologyTeam: basicSettings.TotalTechnologyTeam,
  207. TotalAngelInvestor: basicSettings.TotalAngelInvestor,
  208. TotalOperateFund: basicSettings.TotalOperateFund,
  209. TotalEcologicalDevelopment: basicSettings.TotalEcologicalDevelopment,
  210. TotalTeamDividends: basicSettings.TotalTeamDividends,
  211. TotalUserForPerson: basicSettings.TotalUserForPerson,
  212. TotalUserForTeam: basicSettings.TotalUserForTeam,
  213. },
  214. DestructionSetting: destructionSetting,
  215. PriceSetting: priceSetting,
  216. ExchangeRules: exchangeRules,
  217. RewardSystem: rewardSystem,
  218. NewUserIncentiveRules: newUserRewardRules,
  219. SystemID: basicSettings.Id,
  220. }
  221. e.OutSuc(c, resp, nil)
  222. }
  223. // UpdateEggEnergyBasic
  224. // @Summary 制度中心-蛋蛋能量-基础设置(更新)
  225. // @Tags 蛋蛋能量
  226. // @Description 基础设置(更新)
  227. // @Accept json
  228. // @Produce json
  229. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  230. // @Param req body md.UpdateEggEnergyBasicReq true "system_id 必填"
  231. // @Success 200 {int} "修改数据条数"
  232. // @Failure 400 {object} md.Response "具体错误"
  233. // @Router /api/institutionalManagement/eggEnergy/updateBasic [post]
  234. func UpdateEggEnergyBasic(c *gin.Context) {
  235. var req *md.UpdateEggEnergyBasicReq
  236. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  237. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  238. return
  239. }
  240. destructionSettingStr := utils.SerializeStr(req.DestructionSetting)
  241. priceSettingStr := utils.SerializeStr(req.PriceSetting)
  242. videoRewardSystemStr := utils.SerializeStr(req.VideoRewardSetting.VideoRewardSystem)
  243. exchangeRulesStr := utils.SerializeStr(req.ExchangeRules)
  244. rewardSystemStr := utils.SerializeStr(req.RewardSystem)
  245. newUserIncentiveRulesStr := utils.SerializeStr(req.NewUserIncentiveRules)
  246. directPushRewardStr := utils.SerializeStr(req.BasicSetting.DirectPushReward)
  247. m := model.EggEnergyBasicSetting{
  248. Id: req.SystemID,
  249. IsOpen: req.BasicSetting.IsOpen,
  250. PersonEggEnergyCoinId: req.BasicSetting.PersonEggEnergyCoinId,
  251. TeamEggEnergyCoinId: req.BasicSetting.TeamEggEnergyCoinId,
  252. PersonEggPointsCoinId: req.BasicSetting.PersonEggPointsCoinId,
  253. TeamEggPointsCoinId: req.BasicSetting.TeamEggPointsCoinId,
  254. TotalIssuanceAmount: req.DataSetting.TotalIssuanceAmount,
  255. TotalTechnologyTeam: req.DataSetting.TotalTechnologyTeam,
  256. TotalAngelInvestor: req.DataSetting.TotalAngelInvestor,
  257. TotalOperateFund: req.DataSetting.TotalOperateFund,
  258. TotalEcologicalDevelopment: req.DataSetting.TotalEcologicalDevelopment,
  259. TotalUserForPerson: req.DataSetting.TotalUserForPerson,
  260. TotalUserForTeam: req.DataSetting.TotalUserForTeam,
  261. DestructionSetting: destructionSettingStr,
  262. DirectPushReward: directPushRewardStr,
  263. PriceSetting: priceSettingStr,
  264. VideoRewardIsOpen: req.VideoRewardSetting.VideoRewardIsOpen,
  265. VideoRewardSystem: videoRewardSystemStr,
  266. ExchangeRules: exchangeRulesStr,
  267. RewardSystem: rewardSystemStr,
  268. NewUserIncentiveRules: newUserIncentiveRulesStr,
  269. TotalTeamDividends: req.DataSetting.TotalTeamDividends,
  270. }
  271. forceColums := []string{"is_open", "video_reward_is_open"}
  272. energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  273. session := db.Db.NewSession()
  274. defer session.Close()
  275. affected, err := energyBasicSettingDb.EggEnergyBasicSettingUpdate(session, req.SystemID, &m, forceColums...)
  276. if err != nil {
  277. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  278. return
  279. }
  280. e.OutSuc(c, affected, nil)
  281. }
  282. // GetEggEnergyVipSetting
  283. // @Summary 制度中心-蛋蛋能量-基础会员设置(获取)
  284. // @Tags 蛋蛋能量
  285. // @Description 基础会员设置(获取)
  286. // @Accept json
  287. // @Produce json
  288. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  289. // @Success 200 {object} md.GetEggEnergyVipSettingResp "具体数据"
  290. // @Failure 400 {object} md.Response "具体错误"
  291. // @Router /api/institutionalManagement/eggEnergy/getVipSetting [get]
  292. func GetEggEnergyVipSetting(c *gin.Context) {
  293. basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  294. basicSettings, err1 := basicSettingDb.EggEnergyBasicSettingGetOne()
  295. if err1 != nil {
  296. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  297. return
  298. }
  299. if basicSettings == nil {
  300. e.OutErr(c, e.ERR_NO_DATA, errors.New("未能获取基础设置"))
  301. return
  302. }
  303. var vipEquitySetting []md2.VipEquitySettingStruct
  304. utils.Unserialize([]byte(basicSettings.VipEquitySetting), &vipEquitySetting)
  305. levelDb := implement.NewUserLevelDb(db.Db)
  306. levels, err1 := levelDb.UserLevelAllByAsc()
  307. if err1 != nil {
  308. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  309. return
  310. }
  311. levelsList := make([]map[string]interface{}, 0)
  312. levelsMap := make(map[int]string)
  313. for _, level := range levels {
  314. levelsList = append(levelsList, map[string]interface{}{
  315. "id": level.Id,
  316. "name": level.LevelName,
  317. })
  318. levelsMap[level.Id] = level.LevelName
  319. }
  320. list := make([]md.VipEquitySettingNode, len(vipEquitySetting))
  321. for i, settingStruct := range vipEquitySetting {
  322. list[i].VipLevelName = levelsMap[utils.StrToInt(settingStruct.VipLevelId)]
  323. list[i].ExchangeAccountBalanceFee = settingStruct.ExchangeAccountBalanceFee
  324. list[i].DividendRatio = settingStruct.DividendRatio
  325. list[i].VipLevelID = settingStruct.VipLevelId
  326. }
  327. resp := md.GetEggEnergyVipSettingResp{
  328. LevelList: levelsList,
  329. List: list,
  330. }
  331. e.OutSuc(c, resp, nil)
  332. }
  333. // AddEggEnergyVipSetting
  334. // @Summary 制度中心-蛋蛋能量-会员设置(新增)
  335. // @Tags 蛋蛋能量
  336. // @Description 会员设置(新增)
  337. // @Accept json
  338. // @Produce json
  339. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  340. // @Param req body md.UpdateEggEnergyVipSettingReq true "system_id 必填"
  341. // @Success 200 {int} "修改数据条数"
  342. // @Failure 400 {object} md.Response "具体错误"
  343. // @Router /api/institutionalManagement/eggEnergy/addVipSetting [post]
  344. func AddEggEnergyVipSetting(c *gin.Context) {
  345. var req *md.AddEggEnergyVipSettingReq
  346. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  347. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  348. return
  349. }
  350. setting := md2.VipEquitySettingStruct{
  351. VipLevelId: req.VipLevelId,
  352. ExchangeAccountBalanceFee: req.ExchangeAccountBalanceFee,
  353. DividendRatio: req.DividendRatio,
  354. }
  355. basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  356. basicSettings, err1 := basicSettingDb.EggEnergyBasicSettingGetOne()
  357. if err1 != nil {
  358. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  359. return
  360. }
  361. if basicSettings == nil {
  362. e.OutErr(c, e.ERR_NO_DATA, errors.New("未能获取基础设置"))
  363. return
  364. }
  365. var vipEquitySetting []md2.VipEquitySettingStruct
  366. utils.Unserialize([]byte(basicSettings.VipEquitySetting), &vipEquitySetting)
  367. vipEquitySetting = append(vipEquitySetting, setting)
  368. vipEquitySettingStr := utils.SerializeStr(vipEquitySetting)
  369. basicSettings.VipEquitySetting = vipEquitySettingStr
  370. session := db.Db.NewSession()
  371. affected, err := basicSettingDb.EggEnergyBasicSettingUpdate(session, basicSettings.Id, basicSettings, "vip_equity_setting")
  372. if err != nil {
  373. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  374. return
  375. }
  376. e.OutSuc(c, affected, nil)
  377. }
  378. // UpdateEggEnergyVipSetting
  379. // @Summary 制度中心-蛋蛋能量-会员设置(更新)
  380. // @Tags 蛋蛋能量
  381. // @Description 会员设置(更新)
  382. // @Accept json
  383. // @Produce json
  384. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  385. // @Param req body md.UpdateEggEnergyVipSettingReq true "填入修改后的列表(会员等级名称、兑换余额手续费、分红比例)"
  386. // @Success 200 {int} "修改数据条数"
  387. // @Failure 400 {object} md.Response "具体错误"
  388. // @Router /api/institutionalManagement/eggEnergy/updateVipSetting [post]
  389. func UpdateEggEnergyVipSetting(c *gin.Context) {
  390. var req *md.UpdateEggEnergyVipSettingReq
  391. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  392. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  393. return
  394. }
  395. basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  396. basicSettings, err1 := basicSettingDb.EggEnergyBasicSettingGetOne()
  397. if err1 != nil {
  398. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  399. return
  400. }
  401. if basicSettings == nil {
  402. e.OutErr(c, e.ERR_NO_DATA, errors.New("未能获取基础设置"))
  403. return
  404. }
  405. levelDb := implement.NewUserLevelDb(db.Db)
  406. levels, err1 := levelDb.UserLevelAllByAsc()
  407. if err1 != nil {
  408. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  409. return
  410. }
  411. levelsList := make([]map[string]interface{}, 0)
  412. for _, level := range levels {
  413. levelsList = append(levelsList, map[string]interface{}{
  414. "id": level.Id,
  415. "name": level.LevelName,
  416. })
  417. }
  418. vipEquitySetting := make([]md2.VipEquitySettingStruct, len(req.List))
  419. for i, node := range req.List {
  420. vipEquitySetting[i] = md2.VipEquitySettingStruct{
  421. VipLevelId: node.VipLevelID,
  422. ExchangeAccountBalanceFee: node.ExchangeAccountBalanceFee,
  423. DividendRatio: node.DividendRatio,
  424. }
  425. }
  426. vipEquitySettingStr := utils.SerializeStr(vipEquitySetting)
  427. basicSettings.VipEquitySetting = vipEquitySettingStr
  428. session := db.Db.NewSession()
  429. affected, err := basicSettingDb.EggEnergyBasicSettingUpdate(session, basicSettings.Id, basicSettings, "vip_equity_setting")
  430. if err != nil {
  431. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  432. return
  433. }
  434. e.OutSuc(c, affected, nil)
  435. }
  436. // GetEggEnergyCoreData
  437. // @Summary 制度中心-蛋蛋能量-核心数据(获取)
  438. // @Tags 蛋蛋能量
  439. // @Description 核心数据(获取)
  440. // @Accept json
  441. // @Produce json
  442. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  443. // @Success 200 {object} md.GetEggEnergyCoreDataResp "具体数据"
  444. // @Failure 400 {object} md.Response "具体错误"
  445. // @Router /api/institutionalManagement/eggEnergy/coreData [GET]
  446. func GetEggEnergyCoreData(c *gin.Context) {
  447. dataDb := implement.NewEggEnergyCoreDataDb(db.Db)
  448. coreData, err := dataDb.EggEnergyCoreDataGet()
  449. if err != nil {
  450. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  451. return
  452. }
  453. resp := md.GetEggEnergyCoreDataResp{
  454. Id: coreData.Id,
  455. NowPrice: coreData.NowPrice,
  456. PlanetTotalValue: coreData.PlanetTotalValue,
  457. NowEnergyTotalNums: coreData.NowEnergyTotalNums,
  458. MarketplaceMerchantNums: coreData.MarketplaceMerchantNums,
  459. MarketplaceMerchantFunds: coreData.MarketplaceMerchantFunds,
  460. DevelopmentCommittee: coreData.DevelopmentCommittee,
  461. PublicWelfareAndCharity: coreData.PublicWelfareAndCharity,
  462. StarLevelDividends: coreData.StarLevelDividends,
  463. CommunityDividends: coreData.CommunityDividends,
  464. }
  465. e.OutSuc(c, resp, nil)
  466. }
  467. // UpdateEggEnergyCoreData
  468. // @Summary 制度中心-蛋蛋能量-核心数据(更新)
  469. // @Tags 蛋蛋能量
  470. // @Description 核心数据(更新)
  471. // @Accept json
  472. // @Produce json
  473. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  474. // @Param req body md.UpdateEggEnergyCoreDataReq true "需要修改的内容和 id"
  475. // @Success 200 {int} "修改数据条数"
  476. // @Failure 400 {object} md.Response "具体错误"
  477. // @Router /api/institutionalManagement/eggEnergy/coreData [POST]
  478. func UpdateEggEnergyCoreData(c *gin.Context) {
  479. var req *md.UpdateEggEnergyCoreDataReq
  480. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  481. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  482. return
  483. }
  484. engine := db.Db
  485. coreDataDb := implement.NewEggEnergyCoreDataDb(engine)
  486. rule.Init(cfg.RedisAddr)
  487. _, cb, err := svc.GetEggEnergyCoreData(engine)
  488. if err != nil {
  489. return
  490. }
  491. if cb != nil {
  492. defer cb() // 释放锁
  493. }
  494. session := engine.NewSession()
  495. defer session.Close()
  496. m := model.EggEnergyCoreData{
  497. NowPrice: req.NowPrice,
  498. PlanetTotalValue: req.PlanetTotalValue,
  499. NowEnergyTotalNums: req.NowEnergyTotalNums,
  500. MarketplaceMerchantNums: req.MarketplaceMerchantNums,
  501. MarketplaceMerchantFunds: req.MarketplaceMerchantFunds,
  502. DevelopmentCommittee: req.DevelopmentCommittee,
  503. PublicWelfareAndCharity: req.PublicWelfareAndCharity,
  504. StarLevelDividends: req.StarLevelDividends,
  505. CommunityDividends: req.CommunityDividends,
  506. }
  507. affected, err := coreDataDb.EggEnergyCoreDataUpdateBySession(session, req.Id, &m)
  508. if err != nil {
  509. session.Rollback()
  510. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  511. return
  512. }
  513. err = session.Commit()
  514. if err != nil {
  515. session.Rollback()
  516. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  517. return
  518. }
  519. e.OutSuc(c, affected, nil)
  520. }
  521. // GetEggCoreDataList
  522. // @Summary 制度中心-蛋蛋能量-数据概览(获取)
  523. // @Tags 蛋蛋能量
  524. // @Description 数据概览(获取)
  525. // @Accept json
  526. // @Produce json
  527. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  528. // @Success 200 {object} md.GetEggCoreDataListResp "具体数据"
  529. // @Failure 400 {object} md.Response "具体错误"
  530. // @Router /api/institutionalManagement/eggEnergy/globalData/coreDataList [get]
  531. func GetEggCoreDataList(c *gin.Context) {
  532. coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db)
  533. coreData, err := coreDataDb.EggEnergyCoreDataGet()
  534. if err != nil {
  535. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  536. return
  537. }
  538. if coreData == nil {
  539. e.OutErr(c, e.ERR_NO_DATA, errors.New("数据不存在"))
  540. return
  541. }
  542. sql := "SELECT SUM(amount) AS total, coin_id FROM `user_virtual_amount` GROUP BY (coin_id)"
  543. results, err := db.Db.QueryString(sql)
  544. if err != nil {
  545. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  546. return
  547. }
  548. settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  549. setting, err := settingDb.EggEnergyBasicSettingGetOne()
  550. if err != nil {
  551. e.OutErr(c, e.ERR_DB_ORM, nil)
  552. return
  553. }
  554. var userHoldTotalNums float64
  555. for _, result := range results {
  556. switch utils.StrToInt(result["coin_id"]) {
  557. case setting.PersonEggEnergyCoinId, setting.TeamEggEnergyCoinId, setting.PersonEggPointsCoinId, setting.TeamEggPointsCoinId:
  558. userHoldTotalNums += utils.StrToFloat64(result["total"])
  559. }
  560. }
  561. resp := md.GetEggCoreDataListResp{
  562. PlanetTotalValue: coreData.PlanetTotalValue,
  563. NowPrice: coreData.NowPrice,
  564. NowEnergyTotalNums: coreData.NowEnergyTotalNums,
  565. UserHoldTotalNums: utils.Float64ToStr(userHoldTotalNums),
  566. }
  567. e.OutSuc(c, resp, nil)
  568. }
  569. // GetPriceCurve
  570. // @Summary 制度中心-蛋蛋能量-价格趋势(获取)
  571. // @Tags 蛋蛋能量
  572. // @Description 价格趋势(获取)
  573. // @Accept json
  574. // @Produce json
  575. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  576. // @Param kind query string false "1:按天 2:按小时 3:按周"
  577. // @Success 200 {object} md.GetPriceCurveResp "具体数据"
  578. // @Failure 400 {object} md.Response "具体错误"
  579. // @Router /api/institutionalManagement/eggEnergy/globalData/pointsCenterPriceCurve [get]
  580. func GetPriceCurve(c *gin.Context) {
  581. kind := c.DefaultQuery("kind", "1")
  582. now := time.Now()
  583. var yData []interface{}
  584. var xData []interface{}
  585. priceDb := implement.NewEggEnergyPriceDb(db.Db)
  586. m, has, err := priceDb.EggEnergyPriceGetLastOne()
  587. if err != nil {
  588. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  589. return
  590. }
  591. if has == false {
  592. e.OutSuc(c, md.GetPriceCurveResp{
  593. YData: yData,
  594. XData: xData,
  595. }, nil)
  596. return
  597. }
  598. switch kind {
  599. case "1":
  600. var date = now.AddDate(0, 0, -30).Format("2006-01-02")
  601. 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"))
  602. results, _ := db.Db.QueryString(sql)
  603. for _, v := range results {
  604. tmpDate := utils.TimeParseStd(v["date"])
  605. yData = append(yData, v["price"])
  606. xData = append(xData, tmpDate.Format("01-02"))
  607. }
  608. yData = append(yData, m.Price)
  609. tmpDate := utils.TimeParseStd(m.Date)
  610. xData = append(xData, tmpDate.Format("01-02"))
  611. break
  612. case "2":
  613. for i := 29; i >= 1; i-- {
  614. date := now.Add(-time.Hour * 4 * time.Duration(i)).Format("2006-01-02")
  615. hour := now.Add(-time.Hour * 4 * time.Duration(i)).Hour()
  616. var sql = "SELECT price,date,hour FROM `egg_energy_price` WHERE HOUR = %d AND DATE = \"%s\" "
  617. sql = fmt.Sprintf(sql, hour, date)
  618. results, _ := db.Db.QueryString(sql)
  619. if results != nil {
  620. //if results[0]["date"] != now.Format("2006-01-02") {
  621. // continue
  622. //}
  623. yData = append(yData, results[0]["price"])
  624. xData = append(xData, results[0]["hour"]+":00")
  625. }
  626. }
  627. yData = append(yData, m.Price)
  628. xData = append(xData, m.Hour+":00")
  629. break
  630. case "3":
  631. var nums = 29
  632. for i := nums; i >= 1; i-- {
  633. var date = now.AddDate(0, 0, -7*i).Format("2006-01-02")
  634. var sql = "SELECT price,date FROM `egg_energy_price` WHERE HOUR = 23 AND DATE = \"%s\" "
  635. sql = fmt.Sprintf(sql, date)
  636. results, _ := db.Db.QueryString(sql)
  637. if results != nil {
  638. tmpDate := utils.TimeParseStd(results[0]["date"])
  639. yData = append(yData, results[0]["price"])
  640. xData = append(xData, tmpDate.Format("01-02"))
  641. }
  642. }
  643. yData = append(yData, m.Price)
  644. tmpDate := utils.TimeParseStd(m.Date)
  645. xData = append(xData, tmpDate.Format("01-02"))
  646. break
  647. }
  648. e.OutSuc(c, md.GetPriceCurveResp{
  649. YData: yData,
  650. XData: xData,
  651. }, nil)
  652. return
  653. }
  654. // GetFundDataList
  655. // @Summary 制度中心-蛋蛋能量-新增数据列表(获取)
  656. // @Tags 蛋蛋能量
  657. // @Description 新增数据列表(获取)
  658. // @Accept json
  659. // @Produce json
  660. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  661. // @Param req body md.GetFundDataListReq true "分页信息必填"
  662. // @Success 200 {object} md.GetFundDataListResp "具体数据"
  663. // @Failure 400 {object} md.Response "具体错误"
  664. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataList [post]
  665. func GetFundDataList(c *gin.Context) {
  666. var req *md.GetFundDataListReq
  667. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  668. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  669. return
  670. }
  671. var kindList = []map[string]interface{}{
  672. {
  673. "name": enum.EggEnergyFundDataKind.String(enum.CompanySubsidies),
  674. "value": enum.CompanySubsidies,
  675. },
  676. {
  677. "name": enum.EggEnergyFundDataKind.String(enum.InvestmentByInvestors),
  678. "value": enum.InvestmentByInvestors,
  679. },
  680. {
  681. "name": enum.EggEnergyFundDataKind.String(enum.MarketExpectations),
  682. "value": enum.MarketExpectations,
  683. },
  684. }
  685. fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
  686. fundDataList, total, err := fundDataDb.EggEnergyFundDataFindAndCount(req.Page, req.Limit, req.Kind, req.StartAt, req.EndAt)
  687. if err != nil {
  688. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  689. return
  690. }
  691. list := make([]md.FundDataNode, len(fundDataList))
  692. for i, fundData := range fundDataList {
  693. list[i].Kind = fundData.Kind
  694. list[i].TotalAmount = fundData.TotalAmount
  695. list[i].Hours = fundData.Hours
  696. list[i].Memo = fundData.Memo
  697. list[i].BalanceTimes = fundData.BalanceTimes
  698. list[i].BalanceAmount = fundData.BalanceAmount
  699. list[i].CreateAt = fundData.CreateAt
  700. list[i].SystemID = fundData.Id
  701. }
  702. resp := md.GetFundDataListResp{
  703. KindList: kindList,
  704. Paginate: md.Paginate{
  705. Limit: req.Limit,
  706. Page: req.Page,
  707. Total: total,
  708. },
  709. List: list,
  710. }
  711. e.OutSuc(c, resp, nil)
  712. }
  713. // GetFundDataRecordList
  714. // @Summary 制度中心-蛋蛋能量-新增数据列表详情(查询)
  715. // @Tags 蛋蛋能量
  716. // @Description 新增数据列表详情(查询)
  717. // @Accept json
  718. // @Produce json
  719. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  720. // @Param req body md.GetFundDataRecordListReq true "获取到的 system_id 以及分页信息"
  721. // @Success 200 {object} md.GetFundDataRecordListResp "具体数据"
  722. // @Failure 400 {object} md.Response "具体错误"
  723. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataRecordList [post]
  724. func GetFundDataRecordList(c *gin.Context) {
  725. var req *md.GetFundDataRecordListReq
  726. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  727. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  728. return
  729. }
  730. recordsDb := implement.NewEggEnergyFundDataRecordsDb(db.Db)
  731. records, total, err := recordsDb.EggEnergyFundDataRecordsFindAndCount(req.Page, req.Limit, req.SystemID)
  732. if err != nil {
  733. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  734. return
  735. }
  736. var list []md.FundDataRecordNode
  737. for i, record := range records {
  738. list[i].TotalAmount = record.TotalAmount
  739. list[i].BalanceAmount = record.BalanceAmount
  740. list[i].BalanceTimes = record.BalanceTimes
  741. list[i].BeforePrice = record.BeforePrice
  742. list[i].AfterPrice = record.AfterPrice
  743. list[i].BeforePlanetTotalValue = record.BeforePlanetTotalValue
  744. list[i].AfterPlanetTotalValue = record.AfterPlanetTotalValue
  745. list[i].CreateAt = record.CreateAt
  746. }
  747. resp := md.GetFundDataRecordListResp{
  748. Paginate: md.Paginate{
  749. Limit: req.Limit,
  750. Page: req.Page,
  751. Total: total,
  752. },
  753. List: list,
  754. }
  755. e.OutSuc(c, resp, nil)
  756. }
  757. // AddFundData
  758. // @Summary 制度中心-蛋蛋能量-价值明细数据(新增)
  759. // @Tags 蛋蛋能量
  760. // @Description 价值明细数据(新增)
  761. // @Accept json
  762. // @Produce json
  763. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  764. // @Param req body md.AddFundDataReq true "数据种类、金额、时长(最长24h)、执行次数必填,备注选填"
  765. // @Success 200 {int} "插入数据 id"
  766. // @Failure 400 {object} md.Response "具体错误"
  767. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataAdd [post]
  768. func AddFundData(c *gin.Context) {
  769. var req *md.AddFundDataReq
  770. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  771. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  772. return
  773. }
  774. fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
  775. now := time.Now()
  776. hour := now.Hour()
  777. if req.Hours > 24 {
  778. hour = 24
  779. }
  780. times := req.Hours * 60 / req.Frequency
  781. m := model.EggEnergyFundData{
  782. Kind: req.Kind,
  783. TotalAmount: req.TotalAmount,
  784. BalanceAmount: req.TotalAmount,
  785. Hours: hour,
  786. BalanceTimes: times,
  787. Frequency: req.Frequency,
  788. Memo: req.Memo,
  789. CreateAt: now.Format("2006-01-02 15:04:05"),
  790. UpdateAt: now.Format("2006-01-02 15:04:05"),
  791. }
  792. id, err := fundDataDb.EggEnergyFundDataInsert(&m)
  793. if err != nil {
  794. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  795. return
  796. }
  797. e.OutSuc(c, id, nil)
  798. }