|
|
@@ -5,13 +5,15 @@ import ( |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" |
|
|
|
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" |
|
|
|
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"github.com/shopspring/decimal" |
|
|
|
"time" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount float64, title string, chain *model.OneCirclesGreenEnergyBasicSetting) error { |
|
|
|
func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount float64, title string, chain *model.OneCirclesGreenEnergyBasicSetting, nowPriceValue string) error { |
|
|
|
amountValue := decimal.NewFromFloat(amount) |
|
|
|
now := time.Now() |
|
|
|
var oneCirclesAvailableGreenEnergyPointsFlow model.OneCirclesAvailableGreenEnergyPointsFlow |
|
|
@@ -180,7 +182,7 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount float6 |
|
|
|
chain.StarLevelDividends = oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues //星级分红 |
|
|
|
chain.DestructionQuantityNums = oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues //销毁数量 |
|
|
|
|
|
|
|
nowPrice, _ := decimal.NewFromString(chain.NowPrice) |
|
|
|
nowPrice, _ := decimal.NewFromString(nowPriceValue) |
|
|
|
originalQuantityNums, _ := decimal.NewFromString(chain.OriginalQuantityNums) |
|
|
|
originalFunds := originalQuantityNums.Mul(nowPrice).RoundFloor(8).String() |
|
|
|
chain.OriginalFunds = originalFunds //原始资金 |
|
|
@@ -188,6 +190,42 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount float6 |
|
|
|
marketplaceMerchantFunds := marketplaceMerchantNums.Mul(nowPrice).RoundFloor(8).String() |
|
|
|
chain.MarketplaceMerchantFunds = marketplaceMerchantFunds //市商资金 |
|
|
|
//更新 `one_circles_green_energy_basic_setting` 表 |
|
|
|
if chain.NowPrice != nowPriceValue { |
|
|
|
chain.NowPrice = nowPriceValue |
|
|
|
// 新增 / 更新 one_circles_green_energy_price 记录 |
|
|
|
date := now.Format("2006-01-02") |
|
|
|
hour := zhios_order_relate_utils.IntToStr(now.Hour()) |
|
|
|
oneCirclesGreenEnergyPrice, err := db.OneCirclesGreenEnergyPriceGetOneByParamsBySession(session, map[string]interface{}{ |
|
|
|
"key": "date", |
|
|
|
"value": date, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if oneCirclesGreenEnergyPrice == nil || oneCirclesGreenEnergyPrice.Hour != hour { |
|
|
|
oneCirclesGreenEnergyPrice = &model.OneCirclesGreenEnergyPrice{ |
|
|
|
Price: nowPriceValue, |
|
|
|
Date: date, |
|
|
|
Hour: hour, |
|
|
|
} |
|
|
|
insertId, err1 := db.OneCirclesGreenEnergyPriceInsertBySession(session, oneCirclesGreenEnergyPrice) |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
} |
|
|
|
if insertId <= 0 { |
|
|
|
return errors.New("插入 one_circles_green_energy_price 失败") |
|
|
|
} |
|
|
|
} else { |
|
|
|
oneCirclesGreenEnergyPrice.Price = nowPriceValue |
|
|
|
updateAffected, err1 := db.OneCirclesGreenEnergyPriceUpdate(session, oneCirclesGreenEnergyPrice.Id, oneCirclesGreenEnergyPrice, "price") |
|
|
|
if err1 != nil { |
|
|
|
return err1 |
|
|
|
} |
|
|
|
if updateAffected <= 0 { |
|
|
|
return errors.New("更新 one_circles_green_energy_price 失败") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_, err := db.OneCirclesGreenEnergyBasicSettingUpdate(session, chain.Id, chain) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|