蛋蛋星球-客户端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_home_page.go 1.4 KiB

1 개월 전
3 주 전
1 개월 전
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  5. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  6. "github.com/shopspring/decimal"
  7. "time"
  8. "xorm.io/xorm"
  9. )
  10. // CalcTodayEggEnergyPriceRises 计算蛋蛋能量今日涨跌幅
  11. func CalcTodayEggEnergyPriceRises(engine *xorm.Engine, now time.Time) (err error, rises float64, isRises bool, nowPrice string, initialPrice string) {
  12. //1、查找昨日价格、今日价格 计算涨跌幅
  13. var m *model.EggEnergyPrice
  14. dateStr := now.AddDate(0, 0, -1).Format("2006-01-02")
  15. hourStr := now.AddDate(0, 0, -1).Hour()
  16. priceDb := implement.NewEggEnergyPriceDb(db.Db)
  17. m, err = priceDb.EggEnergyPriceGetOneByParams(dateStr, hourStr)
  18. if err != nil {
  19. return err, 0, false, "", ""
  20. }
  21. initialPrice = m.Price
  22. // todo 有数据后不需要此判断
  23. if initialPrice == "" {
  24. initialPrice = "1"
  25. }
  26. yesterdayPrice, _ := decimal.NewFromString(initialPrice)
  27. coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db)
  28. coreData, err := coreDataDb.EggEnergyCoreDataGet()
  29. if err != nil {
  30. return err, 0, false, "", ""
  31. }
  32. nowPrice = coreData.NowPrice
  33. todayPrice, _ := decimal.NewFromString(coreData.NowPrice)
  34. if todayPrice.GreaterThanOrEqual(yesterdayPrice) {
  35. isRises = true
  36. rises, _ = todayPrice.Sub(yesterdayPrice).Div(yesterdayPrice).Float64()
  37. } else {
  38. rises, _ = yesterdayPrice.Sub(todayPrice).Div(todayPrice).Float64()
  39. }
  40. return nil, rises, isRises, nowPrice, initialPrice
  41. }