cash_pool.go 1.6 KB
package domain

import "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 exchangedCash, ok := data["exchangedCash"]; ok {
		cashPool.ExchangedCash = exchangedCash.(float64)
	}
	if unExchangeCash, ok := data["unExchangeCash"]; ok {
		cashPool.UnExchangeCash = unExchangeCash.(float64)
	}
	if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok {
		cashPool.ExchangedSuMoney = exchangedSuMoney.(float64)
	}
	if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok {
		cashPool.UnExchangeSuMoney = unExchangeSuMoney.(float64)
	}
	if rate, ok := data["rate"]; ok {
		cashPool.Rate = rate.(float64)
	}
	return nil
}

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