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

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