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

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