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

876 lines
30 KiB

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