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

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