order.go
5.0 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package domain
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"time"
)
const (
OrderStatusReserve = iota + 1 //预定中
OrderStatusDeliverSome //部分发货
OrderStatusDeliverAll //全部发货
)
const (
OrderReal = iota + 1 //实发订单
OrderIntention //意向订单
)
type OrderRepository interface {
Save(dm *Order) (*Order, error)
Remove(dm *Order) (*Order, error)
FindOne(queryOptions map[string]interface{}) (*Order, error)
Find(queryOptions map[string]interface{}) (int64, []*Order, error)
}
//Order 订单信息
type Order struct {
//id
Id int64 `json:"Id,omitempty"`
//订单类型
OrderType int `json:"orderType,omitempty"`
//订单编号
OrderCode string `json:"orderCode,omitempty"`
//订单名称
OrderName string `json:"orderName,omitempty"`
//订单状态
OrderStatus int `json:"orderStatus,omitempty"`
//订单数量
OrderCount int `json:"orderCount,omitempty"`
//实际订单数量
OrderActualCount int `json:"orderActualCount,omitempty"`
//订单金额
OrderAmount float64 `json:"admin_name,omitempty"`
//订单实际金额
OrderActualAmount float64 `json:"orderActualAmount,omitempty"`
//订单已支付金额(货款)
OrderPaymentAmount float64 `json:"orderPaymentAmount,omitempty"`
//订单区域信息
OrderRegionInfo *RegionInfo `json:"orderRegionInfo,omitempty"`
Buyer *Buyer `json:"buyer,omitempty"`
//合伙人编号
PartnerId int64 `json:"partnerId,omitempty"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent,omitempty"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent,omitempty"`
//创建时间
CreateAt time.Time `json:"createAt,omitempty"`
//更新时间
UpdateAt time.Time `json:"updateAt,omitempty"`
//上一次查看时间 已读情况
LastViewTime time.Time `json:"lastViewTime,omitempty"`
//订单更新理由
Reason string `json:"reason,omitempty"`
}
func (m *Order) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *Order) Update(data map[string]interface{}) error {
if orderType, ok := data["orderType"]; ok && orderType != 0 {
m.OrderType = orderType.(int)
}
if orderCode, ok := data["orderCode"]; ok && orderCode != "" {
m.OrderCode = orderCode.(string)
}
if orderName, ok := data["orderName"]; ok && orderName != "" {
m.OrderName = orderName.(string)
}
if orderStatus, ok := data["orderStatus"]; ok && orderStatus != 0 {
m.OrderStatus = orderStatus.(int)
}
if lastViewTime, ok := data["lastViewTime"]; ok && lastViewTime != 0 {
m.LastViewTime = lastViewTime.(time.Time)
}
m.UpdateAt = time.Now()
return nil
}
//合伙人
//订单累计分红
func (m *Order) OrderTotalBonus() float64 {
return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0))
}
//订单已收分红
func (m *Order) OrderBonusReceive() float64 {
return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0))
}
//订单未收分红
func (m *Order) OrderBonusWait() float64 {
bonusWait := m.OrderTotalBonus() - m.OrderBonusReceive()
if bonusWait < 0 {
return 0
}
return bonusWait
}
//分红支出
func (m *Order) OrderBonusOutstanding() float64 {
if m.OrderAmount <= m.OrderActualAmount {
return 0
}
return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0))
}
//订单被取消金额
func (m *Order) OrderAmountCancel() float64 {
if m.OrderAmount <= m.OrderActualAmount {
return 0
}
return utils.Decimal(m.OrderAmount - m.OrderActualAmount)
}
//订单是否已读
func (m *Order) IsRead() int {
if m.UpdateAt.After(m.LastViewTime) {
return 0
}
return 1
}
type OrderQueryOption struct {
PartnerId int64 `json:"partnerId,omitempty"`
OrderType int `json:"orderType,omitempty"`
OrderStatus int `json:"orderStatus,omitempty"`
BeginTime time.Time `json:"beginTime,omitempty"`
EndTime time.Time `json:"endTime,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}
type DividendOrdersQueryOption struct {
PartnerId int64 `json:"partnerId"`
OrderType int `json:"orderType"` //订单类型
DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细)
DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
StartTime int64 `json:"startTime" `
EndTime int64 `json:"endTime"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
}
//买家
type Buyer struct {
//买家姓名
BuyerName string `json:"buyerName"`
//联系方式
ContactInfo string `json:"contactInfo"`
//收获地址
ShippingAddress string `json:"shippingAddress"`
}