Kaynağa Gözat

update

master
DengBiao 11 ay önce
ebeveyn
işleme
05d868b504
3 değiştirilmiş dosya ile 52 ekleme ve 5 silme
  1. +11
    -2
      db/db_one_circles_green_energy_price.go
  2. +40
    -2
      rule/one_circles/one_circles_deal_available_green_energy_points.go
  3. +1
    -1
      rule/one_circles/one_circles_sign_in_green_energy_settlement.go

+ 11
- 2
db/db_one_circles_green_energy_price.go Dosyayı Görüntüle

@@ -29,6 +29,15 @@ func OneCirclesGreenEnergyPriceInsert(Db *xorm.Engine, OneCirclesGreenEnergyPric
return OneCirclesGreenEnergyPrice.Id, nil
}

// OneCirclesGreenEnergyPriceInsertBySession 插入单条数据
func OneCirclesGreenEnergyPriceInsertBySession(session *xorm.Session, OneCirclesGreenEnergyPrice *model.OneCirclesGreenEnergyPrice) (int64, error) {
_, err := session.InsertOne(OneCirclesGreenEnergyPrice)
if err != nil {
return 0, err
}
return OneCirclesGreenEnergyPrice.Id, nil
}

// BatchAddOneCirclesGreenEnergyPrices 批量新增数据
func BatchAddOneCirclesGreenEnergyPrices(Db *xorm.Engine, OneCirclesGreenEnergyPriceData []*model.OneCirclesGreenEnergyPrice) (int64, error) {
affected, err := Db.Insert(OneCirclesGreenEnergyPriceData)
@@ -78,12 +87,12 @@ func OneCirclesGreenEnergyPriceUpdate(session *xorm.Session, id interface{}, One
func OneCirclesGreenEnergyPriceGetOneByParamsBySession(session *xorm.Session, params map[string]interface{}) (*model.OneCirclesGreenEnergyPrice, error) {
var m model.OneCirclesGreenEnergyPrice
var query = fmt.Sprintf("%s =?", params["key"])
has, err := session.Where(query, params["value"]).Get(&m)
has, err := session.Where(query, params["value"]).Desc("hour").Get(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, errors.New("未查询到相应的 block_star_chain 记录")
return nil, nil
}
return &m, nil
}


+ 40
- 2
rule/one_circles/one_circles_deal_available_green_energy_points.go Dosyayı Görüntüle

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


+ 1
- 1
rule/one_circles/one_circles_sign_in_green_energy_settlement.go Dosyayı Görüntüle

@@ -111,7 +111,7 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string) (err erro
}

//5、减少“活跃赠送” 中的绿色能量
err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting)
err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice)
if err != nil {
_ = session.Rollback()
fmt.Println("err:::::55555", err)


Yükleniyor…
İptal
Kaydet