ソースを参照

update

master
DengBiao 9ヶ月前
コミット
9e670edf94
1個のファイルの変更31行の追加0行の削除
  1. +31
    -0
      rule/one_circles/one_circles_sign_in_green_energy_settlement.go

+ 31
- 0
rule/one_circles/one_circles_sign_in_green_energy_settlement.go ファイルの表示

@@ -10,6 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/shopspring/decimal"
"time"
"xorm.io/xorm"
)
@@ -137,3 +138,33 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string) (err erro
}
return
}

// CalcTodayGreenEnergyPriceRises 计算绿色能量今日价格涨幅
func CalcTodayGreenEnergyPriceRises(engine *xorm.Engine, oneCirclesGreenEnergyBasicSetting *model.OneCirclesGreenEnergyBasicSetting) (err error, rises float64, isRises bool) {
now := time.Now()
if oneCirclesGreenEnergyBasicSetting == nil {
//1、查找 `one_circles_green_energy_basic_setting` 基础设置
oneCirclesGreenEnergyBasicSetting, err = db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})
if err != nil {
return
}
}

//2、查找昨日价格
var m model.OneCirclesGreenEnergyPrice
if has, err := engine.Where("date =?", now.AddDate(0, 0, -1).Format("2006-01-02")).Desc("hour").Get(&m); err != nil || has == false {
return
}
yesterdayPrice, _ := decimal.NewFromString(m.Price)
todayPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice)
if todayPrice.GreaterThanOrEqual(yesterdayPrice) {
isRises = true
rises, _ = todayPrice.Sub(yesterdayPrice).Div(yesterdayPrice).Float64()
} else {
rises, _ = yesterdayPrice.Sub(todayPrice).Div(todayPrice).Float64()
}
return
}

読み込み中…
キャンセル
保存