exchange_cash_activity.go 2.3 KB
package domain

import "time"

// 兑换现金活动
type ExchangeCashActivity struct {
	ExchangeCashActivityId int64           `json:"exchangeActivityId"`         // 兑换现金活动id
	ExchangeActivityName string                  `json:"exchangeActivityName"` // 兑换现金活动名称
	CompanyId int64                              `json:"companyId"`            // 公司ID
	ExchangedCash float64                        `json:"exchangedCash"`        // 已兑换的现金
	ExchangedSuMoney float64                     `json:"exchangedSuMoney"`     // 已兑换的素币
	CreateTime time.Time                         `json:"createTime"`           // 创建兑换现金活动时间
	Deadline time.Time                           `json:"deadline"`             // 兑换现金活动截止时间
	CountDown string                             `json:"countDown"`            // 兑换现金活动结束倒计时
	Rate float64                                 `json:"rate"`                 // 兑换汇率
	LastRate float64                             `json:"lastRate"`             // 上期兑换汇率
	Operator *EmployeeInfo                       `json:"operator"`             // 活动发布人
	ExchangeCashPeople []*ExchangeCashPersonList `json:"exchangeCashPeople"`   // 兑换现金人员清单
}

type ExchangeActivityRepository interface {
	Save(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
	Remove(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
	FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivity, error)
	Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
}

func (exchangeCashActivity *ExchangeCashActivity) Identity() interface{} {
	if exchangeCashActivity.ExchangeCashActivityId == 0 {
		return nil
	}
	return exchangeCashActivity.ExchangeCashActivityId
}

func (exchangeCashActivity *ExchangeCashActivity) TransferSuMoney(rate float64) error {
	exchangeCashActivity.ExchangedSuMoney = exchangeCashActivity.ExchangedCash * rate
	return nil
}

func (exchangeCashActivity *ExchangeCashActivity) TransferLastRate(lastRate float64) error {
	exchangeCashActivity.LastRate = lastRate
	return nil
}

func (exchangeCashActivity *ExchangeCashActivity) TransferCountDown() error {
	exchangeCashActivity.CountDown = string(time.Until(exchangeCashActivity.Deadline))
	return nil
}