|
|
@@ -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 |
|
|
|
} |