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

669 lines
24 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. // 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 FROM `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. settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  364. setting, err := settingDb.EggEnergyBasicSettingGetOne()
  365. if err != nil {
  366. e.OutErr(c, e.ERR_DB_ORM, nil)
  367. return
  368. }
  369. var userHoldTotalNums float64
  370. for _, result := range results {
  371. switch utils.StrToInt(result["coin_id"]) {
  372. case setting.PersonEggEnergyCoinId, setting.TeamEggEnergyCoinId, setting.PersonEggPointsCoinId, setting.TeamEggPointsCoinId:
  373. userHoldTotalNums += utils.StrToFloat64(result["total"])
  374. }
  375. }
  376. resp := md.GetEggCoreDataListResp{
  377. PlanetTotalValue: coreData.PlanetTotalValue,
  378. NowPrice: coreData.NowPrice,
  379. NowEnergyTotalNums: coreData.NowEnergyTotalNums,
  380. UserHoldTotalNums: utils.Float64ToStr(userHoldTotalNums),
  381. }
  382. e.OutSuc(c, resp, nil)
  383. }
  384. // GetPriceCurve
  385. // @Summary 制度中心-蛋蛋能量-价格趋势(获取)
  386. // @Tags 蛋蛋能量
  387. // @Description 价格趋势(获取)
  388. // @Accept json
  389. // @Produce json
  390. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  391. // @Param kind query string false "1:按天 2:按小时 3:按周"
  392. // @Success 200 {object} md.GetPriceCurveResp "具体数据"
  393. // @Failure 400 {object} md.Response "具体错误"
  394. // @Router /api/institutionalManagement/eggEnergy/globalData/pointsCenterPriceCurve [get]
  395. func GetPriceCurve(c *gin.Context) {
  396. kind := c.DefaultQuery("kind", "1")
  397. now := time.Now()
  398. priceDb := implement.NewEggEnergyPriceDb(db.Db)
  399. m, has, err := priceDb.EggEnergyPriceGetLastOne()
  400. if err != nil {
  401. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  402. return
  403. }
  404. if has == false {
  405. e.OutErr(c, e.ERR_NO_DATA, "未查询到数据")
  406. return
  407. }
  408. var yData []interface{}
  409. var xData []interface{}
  410. switch kind {
  411. case "1":
  412. var date = now.AddDate(0, 0, -30).Format("2006-01-02")
  413. 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"))
  414. results, _ := db.Db.QueryString(sql)
  415. for _, v := range results {
  416. tmpDate := utils.TimeParseStd(v["date"])
  417. yData = append(yData, v["price"])
  418. xData = append(xData, tmpDate.Format("01-02"))
  419. }
  420. yData = append(yData, m.Price)
  421. tmpDate := utils.TimeParseStd(m.Date)
  422. xData = append(xData, tmpDate.Format("01-02"))
  423. break
  424. case "2":
  425. for i := 29; i >= 1; i-- {
  426. date := now.Add(-time.Hour * 4 * time.Duration(i)).Format("2006-01-02")
  427. hour := now.Add(-time.Hour * 4 * time.Duration(i)).Hour()
  428. var sql = "SELECT price,date,hour FROM `egg_energy_price` WHERE HOUR = %d AND DATE = \"%s\" "
  429. sql = fmt.Sprintf(sql, hour, date)
  430. results, _ := db.Db.QueryString(sql)
  431. if results != nil {
  432. //if results[0]["date"] != now.Format("2006-01-02") {
  433. // continue
  434. //}
  435. yData = append(yData, results[0]["price"])
  436. xData = append(xData, results[0]["hour"]+":00")
  437. }
  438. }
  439. yData = append(yData, m.Price)
  440. xData = append(xData, m.Hour+":00")
  441. break
  442. case "3":
  443. var nums = 29
  444. for i := nums; i >= 1; i-- {
  445. var date = now.AddDate(0, 0, -7*i).Format("2006-01-02")
  446. var sql = "SELECT price,date FROM `egg_energy_price` WHERE HOUR = 23 AND DATE = \"%s\" "
  447. sql = fmt.Sprintf(sql, date)
  448. results, _ := db.Db.QueryString(sql)
  449. if results != nil {
  450. tmpDate := utils.TimeParseStd(results[0]["date"])
  451. yData = append(yData, results[0]["price"])
  452. xData = append(xData, tmpDate.Format("01-02"))
  453. }
  454. }
  455. yData = append(yData, m.Price)
  456. tmpDate := utils.TimeParseStd(m.Date)
  457. xData = append(xData, tmpDate.Format("01-02"))
  458. break
  459. }
  460. e.OutSuc(c, md.GetPriceCurveResp{
  461. YData: yData,
  462. XData: xData,
  463. }, nil)
  464. return
  465. }
  466. // GetFundDataList
  467. // @Summary 制度中心-蛋蛋能量-新增数据列表(获取)
  468. // @Tags 蛋蛋能量
  469. // @Description 新增数据列表(获取)
  470. // @Accept json
  471. // @Produce json
  472. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  473. // @Param req body md.GetFundDataListReq true "分页信息必填"
  474. // @Success 200 {object} md.GetFundDataListResp "具体数据"
  475. // @Failure 400 {object} md.Response "具体错误"
  476. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataList [post]
  477. func GetFundDataList(c *gin.Context) {
  478. var req *md.GetFundDataListReq
  479. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  480. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  481. return
  482. }
  483. var kindList = []map[string]interface{}{
  484. {
  485. "name": enum.EggEnergyFundDataKind.String(enum.CompanySubsidies),
  486. "value": enum.CompanySubsidies,
  487. },
  488. {
  489. "name": enum.EggEnergyFundDataKind.String(enum.InvestmentByInvestors),
  490. "value": enum.InvestmentByInvestors,
  491. },
  492. {
  493. "name": enum.EggEnergyFundDataKind.String(enum.MarketExpectations),
  494. "value": enum.MarketExpectations,
  495. },
  496. }
  497. fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
  498. fundDataList, total, err := fundDataDb.EggEnergyFundDataFindAndCount(req.Page, req.Limit, req.Kind, req.StartAt, req.EndAt)
  499. if err != nil {
  500. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  501. return
  502. }
  503. list := make([]md.FundDataNode, len(fundDataList))
  504. for i, fundData := range fundDataList {
  505. list[i].Kind = fundData.Kind
  506. list[i].TotalAmount = fundData.TotalAmount
  507. list[i].Hours = fundData.Hours
  508. list[i].Memo = fundData.Memo
  509. list[i].BalanceTimes = fundData.BalanceTimes
  510. list[i].BalanceAmount = fundData.BalanceAmount
  511. list[i].CreateAt = fundData.CreateAt
  512. list[i].SystemID = fundData.Id
  513. }
  514. resp := md.GetFundDataListResp{
  515. KindList: kindList,
  516. Paginate: md.Paginate{
  517. Limit: req.Limit,
  518. Page: req.Page,
  519. Total: total,
  520. },
  521. List: list,
  522. }
  523. e.OutSuc(c, resp, nil)
  524. }
  525. // GetFundDataRecordList
  526. // @Summary 制度中心-蛋蛋能量-新增数据列表详情(查询)
  527. // @Tags 蛋蛋能量
  528. // @Description 新增数据列表详情(查询)
  529. // @Accept json
  530. // @Produce json
  531. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  532. // @Param req body md.GetFundDataRecordListReq true "获取到的 system_id 以及分页信息"
  533. // @Success 200 {object} md.GetFundDataRecordListResp "具体数据"
  534. // @Failure 400 {object} md.Response "具体错误"
  535. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataRecordList [post]
  536. func GetFundDataRecordList(c *gin.Context) {
  537. var req *md.GetFundDataRecordListReq
  538. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  539. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  540. return
  541. }
  542. recordsDb := implement.NewEggEnergyFundDataRecordsDb(db.Db)
  543. records, total, err := recordsDb.EggEnergyFundDataRecordsFindAndCount(req.Page, req.Limit, req.SystemID)
  544. if err != nil {
  545. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  546. return
  547. }
  548. var list []md.FundDataRecordNode
  549. for i, record := range records {
  550. list[i].TotalAmount = record.TotalAmount
  551. list[i].BalanceAmount = record.BalanceAmount
  552. list[i].BalanceTimes = record.BalanceTimes
  553. list[i].BeforePrice = record.BeforePrice
  554. list[i].AfterPrice = record.AfterPrice
  555. list[i].BeforePlanetTotalValue = record.BeforePlanetTotalValue
  556. list[i].AfterPlanetTotalValue = record.AfterPlanetTotalValue
  557. list[i].CreateAt = record.CreateAt
  558. }
  559. resp := md.GetFundDataRecordListResp{
  560. Paginate: md.Paginate{
  561. Limit: req.Limit,
  562. Page: req.Page,
  563. Total: total,
  564. },
  565. List: list,
  566. }
  567. e.OutSuc(c, resp, nil)
  568. }
  569. // AddFundData
  570. // @Summary 制度中心-蛋蛋能量-价值明细数据(新增)
  571. // @Tags 蛋蛋能量
  572. // @Description 价值明细数据(新增)
  573. // @Accept json
  574. // @Produce json
  575. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  576. // @Param req body md.AddFundDataReq true "数据种类、金额、时长(最长24h)、执行次数必填,备注选填"
  577. // @Success 200 {int} "插入数据 id"
  578. // @Failure 400 {object} md.Response "具体错误"
  579. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataAdd [post]
  580. func AddFundData(c *gin.Context) {
  581. var req *md.AddFundDataReq
  582. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  583. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  584. return
  585. }
  586. fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
  587. now := time.Now()
  588. hour := now.Hour()
  589. if req.Hours > 24 {
  590. hour = 24
  591. }
  592. times := req.Hours * 60 / req.Frequency
  593. m := model.EggEnergyFundData{
  594. Kind: req.Kind,
  595. TotalAmount: req.TotalAmount,
  596. BalanceAmount: req.TotalAmount,
  597. Hours: hour,
  598. BalanceTimes: times,
  599. Frequency: req.Frequency,
  600. Memo: req.Memo,
  601. CreateAt: now.Format("2006-01-02 15:04:05"),
  602. UpdateAt: now.Format("2006-01-02 15:04:05"),
  603. }
  604. id, err := fundDataDb.EggEnergyFundDataInsert(&m)
  605. if err != nil {
  606. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  607. return
  608. }
  609. e.OutSuc(c, id, nil)
  610. }