cash_pool.go 2.0 KB
package domain

import (
	"fmt"
	"strconv"
	"time"
)

// 现金池
type CashPool struct {
	CashPoolId int64 `json:"cashPoolId"`  // 现金池id
	Cash float64 `json:"cash"`  // 投入现金池的现金
	CompanyId int64 `json:"companyId"`	// 公司id
	ExchangedCash float64 `json:"exchangedCash"`  // 已兑换的现金
	UnExchangeCash float64 `json:"unExchangeCash"`  // 未兑换的现金
	ExchangedSuMoney float64 `json:"exchangedSuMoney"` 	// 已兑换的素币
	UnExchangeSuMoney float64 `json:"unExchangeSuMoney"`  // 未兑换的素币
	Rate float64 `json:"rate"` 	// 平均兑换汇率
	LastRate float64 `json:"lastRate"`  // 上期活动兑换汇率
	CreateTime time.Time `json:"createTime"`  // 现金投入现金池时间
}

type CashPoolRepository interface {
	Save(cashPool *CashPool) (*CashPool, error)
	FindOne(queryOptions map[string]interface{}) (*CashPool, error)
	Find(queryOptions map[string]interface{}) (int64, []*CashPool, error)
}

func (cashPool *CashPool) Update(data map[string]interface{}) error {
	if cash, ok := data["cash"]; ok {
		cashPool.Cash = cash.(float64)
	}
	if exchangedCash, ok := data["exchangedCash"]; ok {
		cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedCash.(float64)), 64)
	}
	if unExchangeCash, ok := data["unExchangeCash"]; ok {
		cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeCash.(float64)), 64)
	}
	if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok {
		cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedSuMoney.(float64)), 64)
	}
	if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok {
		cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeSuMoney.(float64)), 64)
	}
	if rate, ok := data["rate"]; ok {
		cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", rate.(float64)), 64)
	}
	return nil
}

func (cashPool *CashPool) Identity() interface{} {
	if cashPool.CashPoolId == 0 {
		return nil
	}
	return cashPool.CashPoolId
}