-
Notifications
You must be signed in to change notification settings - Fork 1
/
email.go
92 lines (79 loc) · 2.23 KB
/
email.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package logic
import (
"github.com/ic3network/mccs-alpha-api/internal/app/types"
mail "github.com/ic3network/mccs-alpha-api/internal/pkg/email"
"github.com/ic3network/mccs-alpha-api/util/l"
"go.uber.org/zap"
)
var Email = &email{
Transfer: t{},
}
type email struct {
Transfer t
}
type t struct{}
func (transfer *t) Initiate(req *types.TransferReq) {
mail.Transfer.Initiate(req)
}
func (transfer *t) Accept(j *types.Journal) {
info, err := transfer.getTransferEmailInfo(j)
if err != nil {
l.Logger.Error("logic.Email.Transfer.Accept failed", zap.Error(err))
return
}
mail.Transfer.Accept(info)
}
func (transfer *t) Reject(j *types.Journal, reason string) {
info, err := transfer.getTransferEmailInfo(j, reason)
if err != nil {
l.Logger.Error("logic.Email.Transfer.Reject failed", zap.Error(err))
return
}
mail.Transfer.Reject(info)
}
func (transfer *t) Cancel(j *types.Journal, reason string) {
info, err := transfer.getTransferEmailInfo(j, reason)
if err != nil {
l.Logger.Error("logic.Email.Transfer.Cancel failed", zap.Error(err))
return
}
mail.Transfer.Cancel(info)
}
func (transfer *t) CancelBySystem(j *types.Journal, reason string) {
info, err := transfer.getTransferEmailInfo(j, reason)
if err != nil {
l.Logger.Error("logic.Email.Transfer.CancelBySystem failed", zap.Error(err))
return
}
mail.Transfer.CancelBySystem(info)
}
func (transfer *t) getTransferEmailInfo(j *types.Journal, reason ...string) (*mail.TransferEmailInfo, error) {
info := &mail.TransferEmailInfo{
Amount: j.Amount,
}
if len(reason) > 0 {
info.Reason = reason[0]
}
fromEntity, err := Entity.FindByAccountNumber(j.FromAccountNumber)
if err != nil {
return nil, err
}
toEntity, err := Entity.FindByAccountNumber(j.ToAccountNumber)
if err != nil {
return nil, err
}
if j.InitiatedBy == j.FromAccountNumber {
info.TransferDirection = "out"
info.InitiatorEmail = fromEntity.Email
info.InitiatorEntityName = fromEntity.Name
info.ReceiverEmail = toEntity.Email
info.ReceiverEntityName = toEntity.Name
} else {
info.TransferDirection = "in"
info.InitiatorEmail = toEntity.Email
info.InitiatorEntityName = toEntity.Name
info.ReceiverEmail = fromEntity.Email
info.ReceiverEntityName = fromEntity.Name
}
return info, nil
}