exchange_cash_activity.go
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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"` // 已兑换的素币
CreateTime time.Time `json:"createTime"` // 创建兑换现金活动时间
Deadline time.Time `json:"deadline"` // 兑换现金活动截止时间
CountDown int64 `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.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)
}
return nil
}
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 = int64(time.Until(exchangeCashActivity.Deadline))
return nil
}