Browse Source

update 绿色积分

tags/v3.6.8
DengBiao 2 years ago
parent
commit
c9b7b79fc9
3 changed files with 173 additions and 2 deletions
  1. +157
    -0
      db/db_block_green_coin_platform_guide_price_for_coin_records.go
  2. +14
    -0
      db/model/block_green_coin_platform_guide_price_for_coin_records.go
  3. +2
    -2
      rule/block_green_chain_settlement.go

+ 157
- 0
db/db_block_green_coin_platform_guide_price_for_coin_records.go View File

@@ -0,0 +1,157 @@
package db

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx"
"errors"
"fmt"
"reflect"
"xorm.io/xorm"
)

// BatchSelectBlockGreenCoinPlatformGuidePriceForCoinRecords 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `BlockGreenCoinPlatformGuidePriceForCoinRecordsFindByParams` 方法
func BatchSelectBlockGreenCoinPlatformGuidePriceForCoinRecords(Db *xorm.Engine, params map[string]interface{}) (*[]model.BlockGreenCoinPlatformGuidePriceForCoinRecords, error) {
var BlockGreenCoinPlatformGuidePriceForCoinRecordsData []model.BlockGreenCoinPlatformGuidePriceForCoinRecords
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).
Find(&BlockGreenCoinPlatformGuidePriceForCoinRecordsData); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &BlockGreenCoinPlatformGuidePriceForCoinRecordsData, nil
}

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

// BatchAddBlockGreenCoinPlatformGuidePriceForCoinRecords 批量新增数据
func BatchAddBlockGreenCoinPlatformGuidePriceForCoinRecords(Db *xorm.Engine, BlockGreenCoinPlatformGuidePriceForCoinRecordsData []*model.BlockGreenCoinPlatformGuidePriceForCoinRecords) (int64, error) {
affected, err := Db.Insert(BlockGreenCoinPlatformGuidePriceForCoinRecordsData)
if err != nil {
return 0, err
}
return affected, nil
}

func GetBlockGreenCoinPlatformGuidePriceForCoinRecordsCount(Db *xorm.Engine) int {
var BlockGreenCoinPlatformGuidePriceForCoinRecords model.BlockGreenCoinPlatformGuidePriceForCoinRecords
session := Db.Where("")
count, err := session.Count(&BlockGreenCoinPlatformGuidePriceForCoinRecords)
if err != nil {
return 0
}
return int(count)
}

// BlockGreenCoinPlatformGuidePriceForCoinRecordsDelete 删除记录
func BlockGreenCoinPlatformGuidePriceForCoinRecordsDelete(Db *xorm.Engine, id interface{}) (int64, error) {
if reflect.TypeOf(id).Kind() == reflect.Slice {
return Db.In("id", id).Delete(model.BlockGreenCoinPlatformGuidePriceForCoinRecords{})
} else {
return Db.Where("id = ?", id).Delete(model.BlockGreenCoinPlatformGuidePriceForCoinRecords{})
}
}

// BlockGreenCoinPlatformGuidePriceForCoinRecordsUpdate 更新记录
func BlockGreenCoinPlatformGuidePriceForCoinRecordsUpdate(session *xorm.Session, id interface{}, BlockGreenCoinPlatformGuidePriceForCoinRecords *model.BlockGreenCoinPlatformGuidePriceForCoinRecords, forceColums ...string) (int64, error) {
var (
affected int64
err error
)
if forceColums != nil {
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(BlockGreenCoinPlatformGuidePriceForCoinRecords)
} else {
affected, err = session.Where("id=?", id).Update(BlockGreenCoinPlatformGuidePriceForCoinRecords)
}
if err != nil {
return 0, err
}
return affected, nil
}

// BlockGreenCoinPlatformGuidePriceForCoinRecordsGetOneByParams 通过传入的参数查询数据(单条)
func BlockGreenCoinPlatformGuidePriceForCoinRecordsGetOneByParams(session *xorm.Session, params map[string]interface{}) (*model.BlockGreenCoinPlatformGuidePriceForCoinRecords, error) {
var m model.BlockGreenCoinPlatformGuidePriceForCoinRecords
var query = fmt.Sprintf("%s =?", params["key"])
has, err := session.Where(query, params["value"]).Get(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, errors.New("未查询到相应的 block_star_chain 记录")
}
return &m, nil
}

// BlockGreenCoinPlatformGuidePriceForCoinRecordsFindByParams 通过传入的参数查询数据(多条)
func BlockGreenCoinPlatformGuidePriceForCoinRecordsFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.BlockGreenCoinPlatformGuidePriceForCoinRecords, error) {
var m []model.BlockGreenCoinPlatformGuidePriceForCoinRecords
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := Db.Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}

}
}

func BlockGreenCoinPlatformGuidePriceForCoinRecordsFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.BlockGreenCoinPlatformGuidePriceForCoinRecords, error) {
var m []model.BlockGreenCoinPlatformGuidePriceForCoinRecords
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if page == 0 && pageSize == 0 {
page = 1
pageSize = 10
}

if params["key"] == nil {
//查询全部数据
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}

}
}

+ 14
- 0
db/model/block_green_coin_platform_guide_price_for_coin_records.go View File

@@ -0,0 +1,14 @@
package model

import (
"time"
)

type BlockGreenCoinPlatformGuidePriceForCoinRecords struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
CoinId int `json:"coin_id" xorm:"not null comment('虚拟币id') INT(11)"`
PlatformGuidePriceForCoin string `json:"platform_guide_price_for_coin" xorm:"not null default 0.0000000000 comment('平台区块币指导价') DECIMAL(22,10)"`
Date string `json:"date" xorm:"not null default '0000-00' comment('日期') VARCHAR(50)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('变更数量') DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('变更前总数量') DATETIME"`
}

+ 2
- 2
rule/block_green_chain_settlement.go View File

@@ -190,14 +190,14 @@ func DailySettlementBlockGreenChain(engine *xorm.Engine, mid string, isTask bool
}

//9、将昨日的“平台区块币指导价”插入到 block_coin_platform_guide_price_for_coin_records
var blockCoinPlatformGuidePriceForCoinRecords = model.BlockCoinPlatformGuidePriceForCoinRecords{
var blockGreenCoinPlatformGuidePriceForCoinRecords = model.BlockGreenCoinPlatformGuidePriceForCoinRecords{
CoinId: blockGreenChain.Coin1,
PlatformGuidePriceForCoin: blockGreenChain.PlatformGuidePriceForCoin,
Date: now.AddDate(0, 0, -1).Format("2006-01-02"),
CreateAt: now,
UpdateAt: now,
}
_, err = db.BlockCoinPlatformGuidePriceForCoinRecordsInsert(session, &blockCoinPlatformGuidePriceForCoinRecords)
_, err = db.BlockGreenCoinPlatformGuidePriceForCoinRecordsInsert(session, &blockGreenCoinPlatformGuidePriceForCoinRecords)
if err != nil {
_ = session.Rollback()
return err


Loading…
Cancel
Save