蛋蛋星球-客户端
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.
 
 
 
 
 
 

524 lines
19 KiB

  1. package egg_energy
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/institutional_management/egg_energy"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum"
  10. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  11. "errors"
  12. "fmt"
  13. "github.com/gin-gonic/gin"
  14. "time"
  15. )
  16. // GetVirtualCoinList
  17. // @Summary 制度中心-蛋蛋能量-查询所有币种(获取)
  18. // @Tags 蛋蛋能量
  19. // @Description 查询所有币种(获取)
  20. // @Accept json
  21. // @Produce json
  22. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  23. // @Success 200 {object} []md.VirtualCoin "成功返回"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /api/institutionalManagement/eggEnergy/availableEnergy/list [post]
  26. func GetVirtualCoinList(c *gin.Context) {
  27. virtualCoinDb := implement.NewVirtualCoinDb(db.Db)
  28. coins, err := virtualCoinDb.VirtualCoinFindAll()
  29. if err != nil {
  30. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  31. return
  32. }
  33. list := make([]md.VirtualCoin, len(coins))
  34. for i, coin := range coins {
  35. list[i] = md.VirtualCoin{
  36. Id: coin.Id,
  37. Name: coin.Name,
  38. ExchangeRatio: coin.ExchangeRatio,
  39. IsUse: coin.IsUse,
  40. CreateAt: coin.CreateAt,
  41. UpdateAt: coin.UpdateAt,
  42. }
  43. }
  44. e.OutSuc(c, list, nil)
  45. }
  46. // GetEggEnergyBasic
  47. // @Summary 制度中心-蛋蛋能量-基础设置(获取)
  48. // @Tags 蛋蛋能量
  49. // @Description 基础设置(获取)
  50. // @Accept json
  51. // @Produce json
  52. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  53. // @Success 200 {object} md.GetEggEnergyBasicResp "具体数据"
  54. // @Failure 400 {object} md.Response "具体错误"
  55. // @Router /api/institutionalManagement/eggEnergy/getBasic [get]
  56. func GetEggEnergyBasic(c *gin.Context) {
  57. basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  58. basicSettings, err1 := basicSettingDb.EggEnergyBasicSettingGetOne()
  59. if err1 != nil {
  60. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  61. return
  62. }
  63. if basicSettings == nil {
  64. e.OutErr(c, e.ERR_NO_DATA, errors.New("未能获取基础设置"))
  65. return
  66. }
  67. var videoRewardSystem md2.VideoRewardSystemStruct
  68. utils.Unserialize([]byte(basicSettings.VideoRewardSystem), &videoRewardSystem)
  69. var destructionSetting md2.DestructionSettingStruct
  70. utils.Unserialize([]byte(basicSettings.DestructionSetting), &destructionSetting)
  71. var priceSetting md2.PriceSettingStruct
  72. utils.Unserialize([]byte(basicSettings.PriceSetting), &priceSetting)
  73. var exchangeRules md2.ExchangeRulesStruct
  74. utils.Unserialize([]byte(basicSettings.ExchangeRules), &exchangeRules)
  75. var rewardSystem md2.RewardSystemStruct
  76. utils.Unserialize([]byte(basicSettings.RewardSystem), &rewardSystem)
  77. var newUserRewardRules md2.NewUserRewardRules
  78. utils.Unserialize([]byte(basicSettings.NewUserIncentiveRules), &newUserRewardRules)
  79. var directPushReward md2.TeamRewardSettingStruct
  80. utils.Unserialize([]byte(basicSettings.DirectPushReward), &directPushReward)
  81. resp := md.GetEggEnergyBasicResp{
  82. BasicSetting: md.BasicSetting{
  83. IsOpen: basicSettings.IsOpen,
  84. PersonEggEnergyCoinId: basicSettings.PersonEggEnergyCoinId,
  85. TeamEggEnergyCoinId: basicSettings.TeamEggEnergyCoinId,
  86. PersonEggPointsCoinId: basicSettings.PersonEggPointsCoinId,
  87. TeamEggPointsCoinId: basicSettings.TeamEggPointsCoinId,
  88. DirectPushReward: md2.TeamRewardSettingStruct{
  89. RewardDecrementValue: directPushReward.RewardDecrementValue,
  90. RewardEndValue: directPushReward.RewardEndValue,
  91. MemberSelfIsOpenGetTeamReward: directPushReward.MemberSelfIsOpenGetTeamReward,
  92. OneRoundDuration: directPushReward.OneRoundDuration,
  93. },
  94. },
  95. VideoRewardSetting: md.VideoRewardSetting{
  96. VideoRewardIsOpen: basicSettings.VideoRewardIsOpen,
  97. VideoRewardSystem: md2.VideoRewardSystemStruct{
  98. RewardValue: videoRewardSystem.RewardValue,
  99. RewardTotalNum: videoRewardSystem.RewardTotalNum,
  100. IntervalMinutes: videoRewardSystem.IntervalMinutes,
  101. EachRoundHour: videoRewardSystem.EachRoundHour,
  102. },
  103. },
  104. DataSetting: md.DataSetting{
  105. TotalIssuanceAmount: basicSettings.TotalIssuanceAmount,
  106. TotalTechnologyTeam: basicSettings.TotalTechnologyTeam,
  107. TotalAngelInvestor: basicSettings.TotalAngelInvestor,
  108. TotalOperateFund: basicSettings.TotalOperateFund,
  109. TotalEcologicalDevelopment: basicSettings.TotalEcologicalDevelopment,
  110. TotalUserForPerson: basicSettings.TotalUserForPerson,
  111. TotalUserForTeam: basicSettings.TotalUserForTeam,
  112. },
  113. DestructionSetting: md2.DestructionSettingStruct{
  114. DestructionQuantity: destructionSetting.DestructionQuantity,
  115. PublicWelfareAndCharity: destructionSetting.PublicWelfareAndCharity,
  116. DevelopmentCommittee: destructionSetting.DevelopmentCommittee,
  117. StarLevelDividends: destructionSetting.StarLevelDividends,
  118. MarketplaceMerchant: destructionSetting.MarketplaceMerchant,
  119. CommunityDividends: destructionSetting.CommunityDividends,
  120. },
  121. PriceSetting: md2.PriceSettingStruct{
  122. PriceHigherThanValue: priceSetting.PriceHigherThanValue,
  123. MarketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue: priceSetting.MarketplaceMerchantsNumsExchangeMarketplaceMerchantsFundValue,
  124. PriceBelowValue: priceSetting.PriceBelowValue,
  125. MarketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue: priceSetting.MarketplaceMerchantsFundExchangeMarketplaceMerchantsNumsValue,
  126. },
  127. ExchangeRules: md2.ExchangeRulesStruct{
  128. AutoExchangeNumsByPerson: exchangeRules.AutoExchangeNumsByPerson,
  129. AutoExchangeRateByPerson: exchangeRules.AutoExchangeRateByPerson,
  130. AutoExchangeNumsByTeam: exchangeRules.AutoExchangeNumsByTeam,
  131. AutoExchangeRateByTeam: exchangeRules.AutoExchangeRateByTeam,
  132. },
  133. RewardSystem: md2.RewardSystemStruct{
  134. Level: rewardSystem.Level,
  135. RewardCondition: rewardSystem.RewardCondition,
  136. RewardValue: rewardSystem.RewardValue,
  137. },
  138. NewUserIncentiveRules: md2.NewUserRewardRules{
  139. InviteUserRewardValue: newUserRewardRules.InviteUserRewardValue,
  140. RewardCoefficient: newUserRewardRules.RewardCoefficient,
  141. ContinueDays: newUserRewardRules.ContinueDays,
  142. },
  143. SystemID: basicSettings.Id,
  144. }
  145. e.OutSuc(c, resp, nil)
  146. }
  147. // UpdateEggEnergyBasic
  148. // @Summary 制度中心-蛋蛋能量-基础设置(更新)
  149. // @Tags 蛋蛋能量
  150. // @Description 基础设置(更新)
  151. // @Accept json
  152. // @Produce json
  153. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  154. // @Param req body md.UpdateEggEnergyBasicReq true "system_id 必填"
  155. // @Success 200 {int} "修改数据条数"
  156. // @Failure 400 {object} md.Response "具体错误"
  157. // @Router /api/institutionalManagement/eggEnergy/updateBasic [post]
  158. func UpdateEggEnergyBasic(c *gin.Context) {
  159. var req *md.UpdateEggEnergyBasicReq
  160. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  161. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  162. return
  163. }
  164. destructionSettingStr := utils.SerializeStr(req.DestructionSetting)
  165. priceSettingStr := utils.SerializeStr(req.PriceSetting)
  166. videoRewardSystemStr := utils.SerializeStr(req.VideoRewardSetting.VideoRewardSystem)
  167. exchangeRulesStr := utils.SerializeStr(req.ExchangeRules)
  168. rewardSystemStr := utils.SerializeStr(req.RewardSystem)
  169. newUserIncentiveRulesStr := utils.SerializeStr(req.NewUserIncentiveRules)
  170. directPushRewardStr := utils.SerializeStr(req.BasicSetting.DirectPushReward)
  171. m := model.EggEnergyBasicSetting{
  172. Id: req.SystemID,
  173. IsOpen: req.BasicSetting.IsOpen,
  174. PersonEggEnergyCoinId: req.BasicSetting.PersonEggEnergyCoinId,
  175. TeamEggEnergyCoinId: req.BasicSetting.TeamEggEnergyCoinId,
  176. PersonEggPointsCoinId: req.BasicSetting.PersonEggPointsCoinId,
  177. TeamEggPointsCoinId: req.BasicSetting.TeamEggPointsCoinId,
  178. TotalIssuanceAmount: req.DataSetting.TotalIssuanceAmount,
  179. TotalTechnologyTeam: req.DataSetting.TotalTechnologyTeam,
  180. TotalAngelInvestor: req.DataSetting.TotalAngelInvestor,
  181. TotalOperateFund: req.DataSetting.TotalOperateFund,
  182. TotalEcologicalDevelopment: req.DataSetting.TotalEcologicalDevelopment,
  183. TotalUserForPerson: req.DataSetting.TotalUserForPerson,
  184. TotalUserForTeam: req.DataSetting.TotalUserForTeam,
  185. DestructionSetting: destructionSettingStr,
  186. DirectPushReward: directPushRewardStr,
  187. PriceSetting: priceSettingStr,
  188. VideoRewardIsOpen: req.VideoRewardSetting.VideoRewardIsOpen,
  189. VideoRewardSystem: videoRewardSystemStr,
  190. ExchangeRules: exchangeRulesStr,
  191. RewardSystem: rewardSystemStr,
  192. NewUserIncentiveRules: newUserIncentiveRulesStr,
  193. }
  194. forceColums := []string{"is_open", "video_reward_is_open"}
  195. energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  196. session := db.Db.NewSession()
  197. affected, err := energyBasicSettingDb.EggEnergyBasicSettingUpdate(session, req.SystemID, &m, forceColums...)
  198. if err != nil {
  199. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  200. return
  201. }
  202. e.OutSuc(c, affected, nil)
  203. }
  204. // GetEggCoreDataList
  205. // @Summary 制度中心-蛋蛋能量-数据概览(获取)
  206. // @Tags 蛋蛋能量
  207. // @Description 数据概览(获取)
  208. // @Accept json
  209. // @Produce json
  210. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  211. // @Success 200 {object} md.GetEggCoreDataListResp "具体数据"
  212. // @Failure 400 {object} md.Response "具体错误"
  213. // @Router /api/institutionalManagement/eggEnergy/globalData/coreDataList [get]
  214. func GetEggCoreDataList(c *gin.Context) {
  215. coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db)
  216. coreData, err := coreDataDb.EggEnergyCoreDataGet()
  217. if err != nil {
  218. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  219. return
  220. }
  221. if coreData == nil {
  222. e.OutErr(c, e.ERR_NO_DATA, errors.New("数据不存在"))
  223. return
  224. }
  225. sql := "SELECT SUM(amount) AS total, coin_id FORM `user_virtual_amount` GROUP BY (coin_id)"
  226. results, err := db.Db.QueryString(sql)
  227. if err != nil {
  228. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  229. return
  230. }
  231. coinsHoldMap := make(map[int]string)
  232. for _, result := range results {
  233. coinsHoldMap[utils.StrToInt(result["coin_id"])] = result["total"]
  234. }
  235. basicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  236. basicSetting, err := basicSettingDb.EggEnergyBasicSettingGetOne()
  237. if err != nil {
  238. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  239. return
  240. }
  241. userHoldTotalNumsMap := map[string]string{
  242. "PersonEggEnergyUserHoldTotal": coinsHoldMap[basicSetting.PersonEggEnergyCoinId],
  243. "TeamEggEnergyUserHoldTotal": coinsHoldMap[basicSetting.TeamEggEnergyCoinId],
  244. "PersonEggPointsUserHoldTotal": coinsHoldMap[basicSetting.PersonEggPointsCoinId],
  245. "TeamEggPointsUserHoldTotal": coinsHoldMap[basicSetting.TeamEggPointsCoinId],
  246. "ContributionUserHoldTotal": coinsHoldMap[basicSetting.ContributionCoinId],
  247. }
  248. resp := md.GetEggCoreDataListResp{
  249. PlanetTotalValue: coreData.PlanetTotalValue,
  250. NowPrice: coreData.NowPrice,
  251. NowEnergyTotalNums: coreData.NowEnergyTotalNums,
  252. UserHoldTotalNums: userHoldTotalNumsMap,
  253. }
  254. e.OutSuc(c, resp, nil)
  255. }
  256. // GetPriceCurve
  257. // @Summary 制度中心-蛋蛋能量-价格趋势(获取)
  258. // @Tags 蛋蛋能量
  259. // @Description 价格趋势(获取)
  260. // @Accept json
  261. // @Produce json
  262. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  263. // @Param kind query string false "1:按天 2:按小时 3:按周"
  264. // @Success 200 {object} md.GetPriceCurveResp "具体数据"
  265. // @Failure 400 {object} md.Response "具体错误"
  266. // @Router /api/institutionalManagement/eggEnergy/globalData/pointsCenterPriceCurve [get]
  267. func GetPriceCurve(c *gin.Context) {
  268. kind := c.DefaultQuery("kind", "1")
  269. now := time.Now()
  270. priceDb := implement.NewEggEnergyPriceDb(db.Db)
  271. m, has, err := priceDb.EggEnergyPriceGetLastOne()
  272. if err != nil {
  273. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  274. return
  275. }
  276. if has == false {
  277. e.OutErr(c, e.ERR_NO_DATA, "未查询到数据")
  278. return
  279. }
  280. var yData []interface{}
  281. var xData []interface{}
  282. switch kind {
  283. case "1":
  284. var date = now.AddDate(0, 0, -30).Format("2006-01-02")
  285. 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"))
  286. results, _ := db.Db.QueryString(sql)
  287. for _, v := range results {
  288. tmpDate := utils.TimeParseStd(v["date"])
  289. yData = append(yData, v["price"])
  290. xData = append(xData, tmpDate.Format("01-02"))
  291. }
  292. yData = append(yData, m.Price)
  293. tmpDate := utils.TimeParseStd(m.Date)
  294. xData = append(xData, tmpDate.Format("01-02"))
  295. break
  296. case "2":
  297. for i := 29; i >= 1; i-- {
  298. date := now.Add(-time.Hour * 4 * time.Duration(i)).Format("2006-01-02")
  299. hour := now.Add(-time.Hour * 4 * time.Duration(i)).Hour()
  300. var sql = "SELECT price,date,hour FROM `egg_energy_price` WHERE HOUR = %d AND DATE = \"%s\" "
  301. sql = fmt.Sprintf(sql, hour, date)
  302. results, _ := db.Db.QueryString(sql)
  303. if results != nil {
  304. //if results[0]["date"] != now.Format("2006-01-02") {
  305. // continue
  306. //}
  307. yData = append(yData, results[0]["price"])
  308. xData = append(xData, results[0]["hour"]+":00")
  309. }
  310. }
  311. yData = append(yData, m.Price)
  312. xData = append(xData, m.Hour+":00")
  313. break
  314. case "3":
  315. var nums = 29
  316. for i := nums; i >= 1; i-- {
  317. var date = now.AddDate(0, 0, -7*i).Format("2006-01-02")
  318. var sql = "SELECT price,date FROM `egg_energy_price` WHERE HOUR = 23 AND DATE = \"%s\" "
  319. sql = fmt.Sprintf(sql, date)
  320. results, _ := db.Db.QueryString(sql)
  321. if results != nil {
  322. tmpDate := utils.TimeParseStd(results[0]["date"])
  323. yData = append(yData, results[0]["price"])
  324. xData = append(xData, tmpDate.Format("01-02"))
  325. }
  326. }
  327. yData = append(yData, m.Price)
  328. tmpDate := utils.TimeParseStd(m.Date)
  329. xData = append(xData, tmpDate.Format("01-02"))
  330. break
  331. }
  332. e.OutSuc(c, md.GetPriceCurveResp{
  333. YData: yData,
  334. XData: xData,
  335. }, nil)
  336. return
  337. }
  338. // GetFundDataList
  339. // @Summary 制度中心-蛋蛋能量-新增数据列表(获取)
  340. // @Tags 蛋蛋能量
  341. // @Description 新增数据列表(获取)
  342. // @Accept json
  343. // @Produce json
  344. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  345. // @Param req body md.GetFundDataListReq true "分页信息必填"
  346. // @Success 200 {object} md.GetFundDataListResp "具体数据"
  347. // @Failure 400 {object} md.Response "具体错误"
  348. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataList [post]
  349. func GetFundDataList(c *gin.Context) {
  350. var req *md.GetFundDataListReq
  351. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  352. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  353. return
  354. }
  355. var kindList = []map[string]interface{}{
  356. {
  357. "name": enum.EggEnergyFundDataKind.String(enum.CompanySubsidies),
  358. "value": enum.CompanySubsidies,
  359. },
  360. {
  361. "name": enum.EggEnergyFundDataKind.String(enum.InvestmentByInvestors),
  362. "value": enum.InvestmentByInvestors,
  363. },
  364. {
  365. "name": enum.EggEnergyFundDataKind.String(enum.MarketExpectations),
  366. "value": enum.MarketExpectations,
  367. },
  368. }
  369. fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
  370. fundDataList, total, err := fundDataDb.EggEnergyFundDataFindAndCount(req.Page, req.Limit, req.Kind, req.StartAt, req.EndAt)
  371. if err != nil {
  372. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  373. return
  374. }
  375. list := make([]md.FundDataNode, len(fundDataList))
  376. for i, fundData := range fundDataList {
  377. list[i].Kind = fundData.Kind
  378. list[i].TotalAmount = fundData.TotalAmount
  379. list[i].Hours = fundData.Hours
  380. list[i].Memo = fundData.Memo
  381. list[i].BalanceTimes = fundData.BalanceTimes
  382. list[i].BalanceAmount = fundData.BalanceAmount
  383. list[i].CreateAt = fundData.CreateAt
  384. list[i].SystemID = fundData.Id
  385. }
  386. resp := md.GetFundDataListResp{
  387. KindList: kindList,
  388. Paginate: md.Paginate{
  389. Limit: req.Limit,
  390. Page: req.Page,
  391. Total: total,
  392. },
  393. List: list,
  394. }
  395. e.OutSuc(c, resp, nil)
  396. }
  397. // GetFundDataRecordList
  398. // @Summary 制度中心-蛋蛋能量-新增数据列表详情(查询)
  399. // @Tags 蛋蛋能量
  400. // @Description 新增数据列表详情(查询)
  401. // @Accept json
  402. // @Produce json
  403. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  404. // @Param req body md.GetFundDataRecordListReq true "获取到的 system_id 以及分页信息"
  405. // @Success 200 {object} md.GetFundDataRecordListResp "具体数据"
  406. // @Failure 400 {object} md.Response "具体错误"
  407. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataRecordList [post]
  408. func GetFundDataRecordList(c *gin.Context) {
  409. var req *md.GetFundDataRecordListReq
  410. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  411. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  412. return
  413. }
  414. recordsDb := implement.NewEggEnergyFundDataRecordsDb(db.Db)
  415. records, total, err := recordsDb.EggEnergyFundDataRecordsFindAndCount(req.Page, req.Limit, req.SystemID)
  416. if err != nil {
  417. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  418. return
  419. }
  420. var list []md.FundDataRecordNode
  421. for i, record := range records {
  422. list[i].TotalAmount = record.TotalAmount
  423. list[i].BalanceAmount = record.BalanceAmount
  424. list[i].BalanceTimes = record.BalanceTimes
  425. list[i].BeforePrice = record.BeforePrice
  426. list[i].AfterPrice = record.AfterPrice
  427. list[i].BeforePlanetTotalValue = record.BeforePlanetTotalValue
  428. list[i].AfterPlanetTotalValue = record.AfterPlanetTotalValue
  429. list[i].CreateAt = record.CreateAt
  430. }
  431. resp := md.GetFundDataRecordListResp{
  432. Paginate: md.Paginate{
  433. Limit: req.Limit,
  434. Page: req.Page,
  435. Total: total,
  436. },
  437. List: list,
  438. }
  439. e.OutSuc(c, resp, nil)
  440. }
  441. // AddFundData
  442. // @Summary 制度中心-蛋蛋能量-价值明细数据(新增)
  443. // @Tags 蛋蛋能量
  444. // @Description 价值明细数据(新增)
  445. // @Accept json
  446. // @Produce json
  447. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  448. // @Param req body md.AddFundDataReq true "数据种类、金额、时长(最长24h)、执行次数必填,备注选填"
  449. // @Success 200 {int} "插入数据 id"
  450. // @Failure 400 {object} md.Response "具体错误"
  451. // @Router /api/institutionalManagement/eggEnergy/globalData/fundDataAdd [post]
  452. func AddFundData(c *gin.Context) {
  453. var req *md.AddFundDataReq
  454. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  455. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  456. return
  457. }
  458. fundDataDb := implement.NewEggEnergyFundDataDb(db.Db)
  459. now := time.Now()
  460. hour := now.Hour()
  461. if req.Hours > 24 {
  462. hour = 24
  463. }
  464. // 十分钟执行一次
  465. times := req.Hours * 60 / req.Frequency
  466. m := model.EggEnergyFundData{
  467. Kind: req.Kind,
  468. TotalAmount: req.TotalAmount,
  469. BalanceAmount: req.TotalAmount,
  470. Hours: hour,
  471. BalanceTimes: times,
  472. Frequency: req.Frequency,
  473. Memo: req.Memo,
  474. CreateAt: now.Format("2006-01-02 15:04:05"),
  475. UpdateAt: now.Format("2006-01-02 15:04:05"),
  476. }
  477. id, err := fundDataDb.EggEnergyFundDataInsert(&m)
  478. if err != nil {
  479. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  480. return
  481. }
  482. e.OutSuc(c, id, nil)
  483. }