exchange_cash_activity.go 2.9 KB
package domain

import (
	"time"
)

// 兑换现金活动
type ExchangeCashActivity struct {
	ActivityId           int64     `json:"activityId"`           // 兑换现金活动id
	ExchangeActivityName string    `json:"exchangeActivityName"` // 兑换现金活动名称
	CompanyId            int64     `json:"companyId"`            // 公司ID
	ExchangedCash        float64   `json:"exchangedCash"`        // 已兑换的现金
	ExchangedSuMoney     float64   `json:"exchangedSuMoney"`     // 已兑换的素币
	Deadline             time.Time `json:"deadline"`             // 兑换现金活动截止时间
	CountDown            int64     `json:"countDown"`            // 兑换现金活动结束倒计时
	Rate                 float64   `json:"rate"`                 // 兑换汇率
	CreateTime           time.Time `json:"createTime"`           // 创建兑换现金活动时间
}

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)
	FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
}

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

func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interface{}) error {
	if exchangeActivityName, ok := data["exchangeActivityName"]; ok && exchangeActivityName != "" {
		exchangeCashActivity.ExchangeActivityName = exchangeActivityName.(string)
	}
	if deadline, ok := data["deadline"]; ok && deadline != "" {
		exchangeCashActivity.Deadline = deadline.(time.Time)
	}
	if countDown, ok := data["countDown"]; ok && countDown != 0 {
		exchangeCashActivity.CountDown = countDown.(int64)
	}
	if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 {
		exchangeCashActivity.ExchangedSuMoney = exchangedSuMoney.(float64)
	}
	if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 {
		exchangeCashActivity.ExchangedCash = exchangedCash.(float64)
	}
	if exchangeRate, ok := data["exchangeRate"]; ok && exchangeRate != 0 {
		exchangeCashActivity.Rate = exchangeRate.(float64)
	}
	if createTime, ok := data["createTime"]; ok && createTime.(time.Time).IsZero() {
		exchangeCashActivity.CreateTime = createTime.(time.Time)
	}
 	return nil
}

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

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