蛋蛋星球-客户端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

svc_home_page.go 1.3 KiB

6 gün önce
12345678910111213141516171819202122232425262728293031323334353637383940
  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. yesterdayPrice, _ := decimal.NewFromString(m.Price)
  23. coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db)
  24. coreData, err := coreDataDb.EggEnergyCoreDataGet()
  25. if err != nil {
  26. return err, 0, false, "", ""
  27. }
  28. nowPrice = coreData.NowPrice
  29. todayPrice, _ := decimal.NewFromString(coreData.NowPrice)
  30. if todayPrice.GreaterThanOrEqual(yesterdayPrice) {
  31. isRises = true
  32. rises, _ = todayPrice.Sub(yesterdayPrice).Div(yesterdayPrice).Float64()
  33. } else {
  34. rises, _ = yesterdayPrice.Sub(todayPrice).Div(todayPrice).Float64()
  35. }
  36. return nil, rises, isRises, nowPrice, initialPrice
  37. }