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

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