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

hdl_basic.go 24 KiB

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