正在显示
25 个修改的文件
包含
418 行增加
和
56 行删除
1 | version: v1 | 1 | version: v1 |
2 | kind: Method | 2 | kind: Method |
3 | metadata: | 3 | metadata: |
4 | - name: cancel | 4 | + name: cancelOrder |
5 | type: command | 5 | type: command |
6 | description: 取消订单服务 | 6 | description: 取消订单服务 |
7 | payload: | 7 | payload: |
8 | + - ref: orderId | ||
9 | + description: 订单id | ||
10 | + required: true | ||
8 | - ref: orderNo | 11 | - ref: orderNo |
9 | description: 订单编号 | 12 | description: 订单编号 |
10 | required: true | 13 | required: true |
1 | version: v1 | 1 | version: v1 |
2 | kind: Method | 2 | kind: Method |
3 | metadata: | 3 | metadata: |
4 | - name: receiving | 4 | + name: receivingGoods |
5 | type: command | 5 | type: command |
6 | description: 订单收货服务 | 6 | description: 订单收货服务 |
7 | payload: | 7 | payload: |
8 | + - ref: orderId | ||
9 | + description: 订单id | ||
10 | + required: true | ||
8 | - ref: orderNo | 11 | - ref: orderNo |
9 | description: 订单号 | 12 | description: 订单号 |
10 | required: true | 13 | required: true |
lastupdate.tmp
0 → 100755
1 | +{"/Users/steve/go/src/partner01/pkg/port/beego":1617679552608984079} |
partner01
0 → 100755
不能预览此文件类型
@@ -6,10 +6,34 @@ import ( | @@ -6,10 +6,34 @@ import ( | ||
6 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/domainService" | 6 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/domainService" |
7 | ) | 7 | ) |
8 | 8 | ||
9 | -func CreateShippingService(options map[string]interface{}) (service.ShippingService, error) { | 9 | +func CreateShippingService(options map[string]interface{}) (service.ShippingGoodsService, error) { |
10 | var transactionContext *pgTransaction.TransactionContext | 10 | var transactionContext *pgTransaction.TransactionContext |
11 | if value, ok := options["transactionContext"]; ok { | 11 | if value, ok := options["transactionContext"]; ok { |
12 | transactionContext = value.(*pgTransaction.TransactionContext) | 12 | transactionContext = value.(*pgTransaction.TransactionContext) |
13 | } | 13 | } |
14 | - return domainService.NewShippingService(transactionContext) | 14 | + return domainService.NewShippingGoodsService(transactionContext) |
15 | +} | ||
16 | + | ||
17 | +func CreateReceivingService(options map[string]interface{}) (service.ReceivingGoodsService, error) { | ||
18 | + var transactionContext *pgTransaction.TransactionContext | ||
19 | + if value, ok := options["transactionContext"]; ok { | ||
20 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
21 | + } | ||
22 | + return domainService.NewReceivingGoodsService(transactionContext) | ||
23 | +} | ||
24 | + | ||
25 | +func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) { | ||
26 | + var transactionContext *pgTransaction.TransactionContext | ||
27 | + if value, ok := options["transactionContext"]; ok { | ||
28 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
29 | + } | ||
30 | + return domainService.NewCancelOrderService(transactionContext) | ||
31 | +} | ||
32 | + | ||
33 | +func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoodsService, error) { | ||
34 | + var transactionContext *pgTransaction.TransactionContext | ||
35 | + if value, ok := options["transactionContext"]; ok { | ||
36 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
37 | + } | ||
38 | + return domainService.NewReturnGoodsService(transactionContext) | ||
15 | } | 39 | } |
@@ -7,7 +7,9 @@ import ( | @@ -7,7 +7,9 @@ import ( | ||
7 | "github.com/beego/beego/v2/core/validation" | 7 | "github.com/beego/beego/v2/core/validation" |
8 | ) | 8 | ) |
9 | 9 | ||
10 | -type CancelCommand struct { | 10 | +type CancelOrderCommand struct { |
11 | + // 订单ID | ||
12 | + OrderId int64 `json:"orderId" valid:"Required"` | ||
11 | // 订单编号 | 13 | // 订单编号 |
12 | OrderNo string `json:"orderNo" valid:"Required"` | 14 | OrderNo string `json:"orderNo" valid:"Required"` |
13 | // 公司id | 15 | // 公司id |
@@ -38,13 +40,13 @@ type CancelCommand struct { | @@ -38,13 +40,13 @@ type CancelCommand struct { | ||
38 | JobNumber string `json:"jobNumber" valid:"Required"` | 40 | JobNumber string `json:"jobNumber" valid:"Required"` |
39 | } | 41 | } |
40 | 42 | ||
41 | -func (cancelCommand *CancelCommand) Valid(validation *validation.Validation) { | ||
42 | - validation.SetError("CustomValid", "未实现的自定义认证") | 43 | +func (cancelOrderCommand *CancelOrderCommand) Valid(validation *validation.Validation) { |
44 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | } | 45 | } |
44 | 46 | ||
45 | -func (cancelCommand *CancelCommand) ValidateCommand() error { | 47 | +func (cancelOrderCommand *CancelOrderCommand) ValidateCommand() error { |
46 | valid := validation.Validation{} | 48 | valid := validation.Validation{} |
47 | - b, err := valid.Valid(cancelCommand) | 49 | + b, err := valid.Valid(cancelOrderCommand) |
48 | if err != nil { | 50 | if err != nil { |
49 | return err | 51 | return err |
50 | } | 52 | } |
@@ -7,7 +7,7 @@ import ( | @@ -7,7 +7,7 @@ import ( | ||
7 | "github.com/beego/beego/v2/core/validation" | 7 | "github.com/beego/beego/v2/core/validation" |
8 | ) | 8 | ) |
9 | 9 | ||
10 | -type ReturnCommand struct { | 10 | +type ReceivingGoodsCommand struct { |
11 | // 订单号 | 11 | // 订单号 |
12 | OrderNo string `json:"orderNo" valid:"Required"` | 12 | OrderNo string `json:"orderNo" valid:"Required"` |
13 | // 是否是公司负责人 | 13 | // 是否是公司负责人 |
@@ -38,13 +38,13 @@ type ReturnCommand struct { | @@ -38,13 +38,13 @@ type ReturnCommand struct { | ||
38 | CompanyId int64 `json:"companyId" valid:"Required"` | 38 | CompanyId int64 `json:"companyId" valid:"Required"` |
39 | } | 39 | } |
40 | 40 | ||
41 | -func (returnCommand *ReturnCommand) Valid(validation *validation.Validation) { | ||
42 | - validation.SetError("CustomValid", "未实现的自定义认证") | 41 | +func (receivingGoodsCommand *ReceivingGoodsCommand) Valid(validation *validation.Validation) { |
42 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | } | 43 | } |
44 | 44 | ||
45 | -func (returnCommand *ReturnCommand) ValidateCommand() error { | 45 | +func (receivingGoodsCommand *ReceivingGoodsCommand) ValidateCommand() error { |
46 | valid := validation.Validation{} | 46 | valid := validation.Validation{} |
47 | - b, err := valid.Valid(returnCommand) | 47 | + b, err := valid.Valid(receivingGoodsCommand) |
48 | if err != nil { | 48 | if err != nil { |
49 | return err | 49 | return err |
50 | } | 50 | } |
@@ -7,7 +7,7 @@ import ( | @@ -7,7 +7,7 @@ import ( | ||
7 | "github.com/beego/beego/v2/core/validation" | 7 | "github.com/beego/beego/v2/core/validation" |
8 | ) | 8 | ) |
9 | 9 | ||
10 | -type ReceivingCommand struct { | 10 | +type ReturnGoodsCommand struct { |
11 | // 订单号 | 11 | // 订单号 |
12 | OrderNo string `json:"orderNo" valid:"Required"` | 12 | OrderNo string `json:"orderNo" valid:"Required"` |
13 | // 是否是公司负责人 | 13 | // 是否是公司负责人 |
@@ -38,13 +38,13 @@ type ReceivingCommand struct { | @@ -38,13 +38,13 @@ type ReceivingCommand struct { | ||
38 | CompanyId int64 `json:"companyId" valid:"Required"` | 38 | CompanyId int64 `json:"companyId" valid:"Required"` |
39 | } | 39 | } |
40 | 40 | ||
41 | -func (receivingCommand *ReceivingCommand) Valid(validation *validation.Validation) { | ||
42 | - validation.SetError("CustomValid", "未实现的自定义认证") | 41 | +func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) { |
42 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
43 | } | 43 | } |
44 | 44 | ||
45 | -func (receivingCommand *ReceivingCommand) ValidateCommand() error { | 45 | +func (returnGoodsCommand *ReturnGoodsCommand) ValidateCommand() error { |
46 | valid := validation.Validation{} | 46 | valid := validation.Validation{} |
47 | - b, err := valid.Valid(receivingCommand) | 47 | + b, err := valid.Valid(returnGoodsCommand) |
48 | if err != nil { | 48 | if err != nil { |
49 | return err | 49 | return err |
50 | } | 50 | } |
@@ -6,7 +6,9 @@ import ( | @@ -6,7 +6,9 @@ import ( | ||
6 | "github.com/beego/beego/v2/core/validation" | 6 | "github.com/beego/beego/v2/core/validation" |
7 | ) | 7 | ) |
8 | 8 | ||
9 | -type ShippingCommand struct { | 9 | +type ShippingGoodsCommand struct { |
10 | + // 订单ID | ||
11 | + OrderId int `json:"orderId" valid:"Required"` | ||
10 | // 发货单号 | 12 | // 发货单号 |
11 | DeliveryCode string `json:"deliveryCode" valid:"Required"` | 13 | DeliveryCode string `json:"deliveryCode" valid:"Required"` |
12 | // 订单编号 | 14 | // 订单编号 |
@@ -15,13 +17,13 @@ type ShippingCommand struct { | @@ -15,13 +17,13 @@ type ShippingCommand struct { | ||
15 | OrderNum int64 `json:"orderNum" valid:"Required"` | 17 | OrderNum int64 `json:"orderNum" valid:"Required"` |
16 | } | 18 | } |
17 | 19 | ||
18 | -func (shippingCommand *ShippingCommand) Valid(validation *validation.Validation) { | ||
19 | - validation.SetError("CustomValid", "未实现的自定义认证") | 20 | +func (shippingGoodsCommand *ShippingGoodsCommand) Valid(validation *validation.Validation) { |
21 | + //_ = validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | } | 22 | } |
21 | 23 | ||
22 | -func (shippingCommand *ShippingCommand) ValidateCommand() error { | 24 | +func (shippingGoodsCommand *ShippingGoodsCommand) ValidateCommand() error { |
23 | valid := validation.Validation{} | 25 | valid := validation.Validation{} |
24 | - b, err := valid.Valid(shippingCommand) | 26 | + b, err := valid.Valid(shippingGoodsCommand) |
25 | if err != nil { | 27 | if err != nil { |
26 | return err | 28 | return err |
27 | } | 29 | } |
@@ -16,7 +16,7 @@ type OrderService struct { | @@ -16,7 +16,7 @@ type OrderService struct { | ||
16 | } | 16 | } |
17 | 17 | ||
18 | // 取消订单服务 | 18 | // 取消订单服务 |
19 | -func (orderService *OrderService) Cancel(cancelCommand *command.CancelCommand) (interface{}, error) { | 19 | +func (orderService *OrderService) Cancel(cancelCommand *command.CancelOrderCommand) (interface{}, error) { |
20 | if err := cancelCommand.ValidateCommand(); err != nil { | 20 | if err := cancelCommand.ValidateCommand(); err != nil { |
21 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 21 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
22 | } | 22 | } |
@@ -78,8 +78,8 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create | @@ -78,8 +78,8 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create | ||
78 | } | 78 | } |
79 | 79 | ||
80 | // 订单分红服务 | 80 | // 订单分红服务 |
81 | -func (orderService *OrderService) DarwDividends(darwDividendsCommand *command.DrawDividendsCommand) (interface{}, error) { | ||
82 | - if err := darwDividendsCommand.ValidateCommand(); err != nil { | 81 | +func (orderService *OrderService) DrawDividends(drawDividendsCommand *command.DrawDividendsCommand) (interface{}, error) { |
82 | + if err := drawDividendsCommand.ValidateCommand(); err != nil { | ||
83 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 83 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
84 | } | 84 | } |
85 | transactionContext, err := factory.CreateTransactionContext(nil) | 85 | transactionContext, err := factory.CreateTransactionContext(nil) |
@@ -172,7 +172,7 @@ func (orderService *OrderService) ListOrder(listOrderQuery *query.ListOrderQuery | @@ -172,7 +172,7 @@ func (orderService *OrderService) ListOrder(listOrderQuery *query.ListOrderQuery | ||
172 | } | 172 | } |
173 | 173 | ||
174 | // 订单收货服务 | 174 | // 订单收货服务 |
175 | -func (orderService *OrderService) Receiving(receivingCommand *command.ReceivingCommand) (interface{}, error) { | 175 | +func (orderService *OrderService) Receiving(receivingCommand *command.ReceivingGoodsCommand) (interface{}, error) { |
176 | if err := receivingCommand.ValidateCommand(); err != nil { | 176 | if err := receivingCommand.ValidateCommand(); err != nil { |
177 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 177 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
178 | } | 178 | } |
@@ -233,7 +233,7 @@ func (orderService *OrderService) RemoveOrder(removeOrderCommand *command.Remove | @@ -233,7 +233,7 @@ func (orderService *OrderService) RemoveOrder(removeOrderCommand *command.Remove | ||
233 | } | 233 | } |
234 | 234 | ||
235 | // 订单退货服务 | 235 | // 订单退货服务 |
236 | -func (orderService *OrderService) Return(returnCommand *command.ReturnCommand) (interface{}, error) { | 236 | +func (orderService *OrderService) Return(returnCommand *command.ReturnGoodsCommand) (interface{}, error) { |
237 | if err := returnCommand.ValidateCommand(); err != nil { | 237 | if err := returnCommand.ValidateCommand(); err != nil { |
238 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 238 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
239 | } | 239 | } |
@@ -254,7 +254,7 @@ func (orderService *OrderService) Return(returnCommand *command.ReturnCommand) ( | @@ -254,7 +254,7 @@ func (orderService *OrderService) Return(returnCommand *command.ReturnCommand) ( | ||
254 | } | 254 | } |
255 | 255 | ||
256 | // 订单发货服务 | 256 | // 订单发货服务 |
257 | -func (orderService *OrderService) Shipping(shippingCommand *command.ShippingCommand) (interface{}, error) { | 257 | +func (orderService *OrderService) Shipping(shippingCommand *command.ShippingGoodsCommand) (interface{}, error) { |
258 | if err := shippingCommand.ValidateCommand(); err != nil { | 258 | if err := shippingCommand.ValidateCommand(); err != nil { |
259 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 259 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
260 | } | 260 | } |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "fmt" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +// 订单类型 | ||
9 | +const ( | ||
10 | + ORDER_TYPE_ACTUAL = iota + 1 //实际订单 | ||
11 | + ORDER_TYPE_INTENTION // 意向订单 | ||
12 | +) | ||
13 | + | ||
14 | +// 订单状态 | ||
15 | +const ( | ||
16 | + ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 | ||
17 | + ORDER_STATUS_TRANSIT // 待收货(运输中) | ||
18 | + ORDER_STATUS_RECEIVED // 已收货 | ||
19 | + ORDER_STATUS_RETURN // 退换货 | ||
20 | + ORDER_STATUS_CANCELED // 已取消(关闭) | ||
21 | + ORDER_STATUS_COMPLETED // 已完成 | ||
22 | +) | ||
4 | 23 | ||
5 | // 订单实体 | 24 | // 订单实体 |
6 | type Order struct { | 25 | type Order struct { |
@@ -44,23 +63,24 @@ type Order struct { | @@ -44,23 +63,24 @@ type Order struct { | ||
44 | UpdateAt time.Time `json:"updateAt"` | 63 | UpdateAt time.Time `json:"updateAt"` |
45 | // 软删 | 64 | // 软删 |
46 | DeleteAt time.Time `json:"deleteAt"` | 65 | DeleteAt time.Time `json:"deleteAt"` |
66 | + // 当前状态 | ||
67 | + CurrentStatus OrderStatus `json:"-"` | ||
47 | } | 68 | } |
48 | 69 | ||
49 | -type OrderRepository interface { | ||
50 | - Save(order *Order) (*Order, error) | ||
51 | - Remove(order *Order) (*Order, error) | ||
52 | - FindOne(queryOptions map[string]interface{}) (*Order, error) | ||
53 | - Find(queryOptions map[string]interface{}) (int64, []*Order, error) | 70 | +// 订单状态机 |
71 | +type OrderStatus interface { | ||
72 | + Update(order *Order, data map[string]interface{}) error // 更新订单 | ||
73 | + Checkout(order *Order) error // 下单 | ||
74 | + Return(order *Order) error // 退换货 | ||
75 | + Cancel(order *Order) error // 取消订单 | ||
76 | + Receive(order *Order) error // 收货 | ||
54 | } | 77 | } |
55 | 78 | ||
56 | -func (order *Order) Identify() interface{} { | ||
57 | - if order.OrderId == 0 { | ||
58 | - return nil | ||
59 | - } | ||
60 | - return order.OrderId | ||
61 | -} | 79 | +// 代发货状态 |
80 | +type UnShippedStatus struct{} | ||
62 | 81 | ||
63 | -func (order *Order) Update(data map[string]interface{}) error { | 82 | +// 编辑待发货订单 |
83 | +func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error { | ||
64 | if orderId, ok := data["orderId"]; ok { | 84 | if orderId, ok := data["orderId"]; ok { |
65 | order.OrderId = orderId.(int64) | 85 | order.OrderId = orderId.(int64) |
66 | } | 86 | } |
@@ -174,3 +194,170 @@ func (order *Order) Update(data map[string]interface{}) error { | @@ -174,3 +194,170 @@ func (order *Order) Update(data map[string]interface{}) error { | ||
174 | } | 194 | } |
175 | return nil | 195 | return nil |
176 | } | 196 | } |
197 | + | ||
198 | +func (status *UnShippedStatus) Checkout(order *Order) error { | ||
199 | + return nil | ||
200 | +} | ||
201 | + | ||
202 | +func (status *UnShippedStatus) Return(order *Order) error { | ||
203 | + return fmt.Errorf("待发货订单不能退货") | ||
204 | +} | ||
205 | + | ||
206 | +func (status *UnShippedStatus) Cancel(order *Order) error { | ||
207 | + return nil | ||
208 | +} | ||
209 | + | ||
210 | +func (status *UnShippedStatus) Receive(order *Order) error { | ||
211 | + return fmt.Errorf("待发货订单不能收货") | ||
212 | +} | ||
213 | + | ||
214 | +// 待收货状态 | ||
215 | +type TransitStatus struct{} | ||
216 | + | ||
217 | +// 待收货订单不允许编辑 | ||
218 | +func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { | ||
219 | + return fmt.Errorf("已发货订单不允许编辑") | ||
220 | +} | ||
221 | + | ||
222 | +func (status *TransitStatus) Checkout(order *Order) error { | ||
223 | + return fmt.Errorf("待收货订单不能重复发货") | ||
224 | +} | ||
225 | + | ||
226 | +func (status *TransitStatus) Return(order *Order) error { | ||
227 | + return nil | ||
228 | +} | ||
229 | + | ||
230 | +func (status *TransitStatus) Cancel(order *Order) error { | ||
231 | + return fmt.Errorf("待收货订单不能取消") | ||
232 | +} | ||
233 | + | ||
234 | +func (status *TransitStatus) Receive(order *Order) error { | ||
235 | + return nil | ||
236 | +} | ||
237 | + | ||
238 | +// 收货状态 | ||
239 | +type ReceivedStatus struct{} | ||
240 | + | ||
241 | +func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { | ||
242 | + return fmt.Errorf("已收货订单不能编辑") | ||
243 | +} | ||
244 | + | ||
245 | +func (status *ReceivedStatus) Checkout(order *Order) error { | ||
246 | + return fmt.Errorf("已收货订单不能重复发货") | ||
247 | +} | ||
248 | + | ||
249 | +func (status *ReceivedStatus) Return(order *Order) error { | ||
250 | + return nil | ||
251 | +} | ||
252 | + | ||
253 | +func (status *ReceivedStatus) Cancel(order *Order) error { | ||
254 | + return fmt.Errorf("已收货订单不能取消") | ||
255 | +} | ||
256 | + | ||
257 | +func (status *ReceivedStatus) Receive(order *Order) error { | ||
258 | + return fmt.Errorf("已收货订单不能重复收货") | ||
259 | +} | ||
260 | + | ||
261 | +// 退货状态 | ||
262 | +type ReturnedStatus struct{} | ||
263 | + | ||
264 | +func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error { | ||
265 | + return fmt.Errorf("已退货订单不允许编辑") | ||
266 | +} | ||
267 | + | ||
268 | +func (status *ReturnedStatus) Checkout(order *Order) error { | ||
269 | + return fmt.Errorf("已退货订单不允许发货") | ||
270 | +} | ||
271 | + | ||
272 | +func (status *ReturnedStatus) Return(order *Order) error { | ||
273 | + return fmt.Errorf("已退货订单不允许再次退货") | ||
274 | +} | ||
275 | + | ||
276 | +func (status *ReturnedStatus) Cancel(order *Order) error { | ||
277 | + return fmt.Errorf("已退货订单不能取消") | ||
278 | +} | ||
279 | + | ||
280 | +func (status *ReturnedStatus) Receive(order *Order) error { | ||
281 | + return fmt.Errorf("已退货订单不能收货") | ||
282 | +} | ||
283 | + | ||
284 | +// 取消状态 | ||
285 | +type CanceledStatus struct{} | ||
286 | + | ||
287 | +func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error { | ||
288 | + return fmt.Errorf("已取消订单不能编辑") | ||
289 | +} | ||
290 | + | ||
291 | +func (status *CanceledStatus) Checkout(order *Order) error { | ||
292 | + return fmt.Errorf("已取消订单不能发货") | ||
293 | +} | ||
294 | + | ||
295 | +func (status *CanceledStatus) Return(order *Order) error { | ||
296 | + return fmt.Errorf("已取消订单不能退货") | ||
297 | +} | ||
298 | + | ||
299 | +func (status *CanceledStatus) Cancel(order *Order) error { | ||
300 | + return fmt.Errorf("已取消订单不能再次取消") | ||
301 | +} | ||
302 | + | ||
303 | +func (status *CanceledStatus) Receive(order *Order) error { | ||
304 | + return fmt.Errorf("已取消订单不能进行收货") | ||
305 | +} | ||
306 | + | ||
307 | +// 已完成状态 | ||
308 | +type CompletedStatus struct{} | ||
309 | + | ||
310 | +func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { | ||
311 | + return nil | ||
312 | +} | ||
313 | + | ||
314 | +func (status *CompletedStatus) Checkout(order *Order) error { | ||
315 | + return fmt.Errorf("已完成订单不能发货") | ||
316 | +} | ||
317 | + | ||
318 | +func (status *CompletedStatus) Return(order *Order) error { | ||
319 | + return fmt.Errorf("已完成订单不能退货") | ||
320 | +} | ||
321 | + | ||
322 | +func (status *CompletedStatus) Cancel(order *Order) error { | ||
323 | + return fmt.Errorf("已完成订单不能取消") | ||
324 | +} | ||
325 | + | ||
326 | +func (status *CompletedStatus) Receive(order *Order) error { | ||
327 | + return fmt.Errorf("已完成订单不能收货") | ||
328 | +} | ||
329 | + | ||
330 | +// 订单仓储 | ||
331 | +type OrderRepository interface { | ||
332 | + Save(order *Order) (*Order, error) | ||
333 | + Remove(order *Order) (*Order, error) | ||
334 | + FindOne(queryOptions map[string]interface{}) (*Order, error) | ||
335 | + Find(queryOptions map[string]interface{}) (int64, []*Order, error) | ||
336 | +} | ||
337 | + | ||
338 | +func (order *Order) Identify() interface{} { | ||
339 | + if order.OrderId == 0 { | ||
340 | + return nil | ||
341 | + } | ||
342 | + return order.OrderId | ||
343 | +} | ||
344 | + | ||
345 | +func (order *Order) Update(data map[string]interface{}) error { | ||
346 | + return order.CurrentStatus.Update(order, data) | ||
347 | +} | ||
348 | + | ||
349 | +func (order *Order) Checkout() error { | ||
350 | + return order.CurrentStatus.Checkout(order) | ||
351 | +} | ||
352 | + | ||
353 | +func (order *Order) Return() error { | ||
354 | + return order.CurrentStatus.Return(order) | ||
355 | +} | ||
356 | + | ||
357 | +func (order *Order) Receive() error { | ||
358 | + return order.CurrentStatus.Receive(order) | ||
359 | +} | ||
360 | + | ||
361 | +func (order *Order) Cancel() error { | ||
362 | + return order.CurrentStatus.Cancel(order) | ||
363 | +} |
pkg/domain/service/cancel_order.go
0 → 100644
pkg/domain/service/receiving_goods.go
0 → 100644
pkg/domain/service/return_goods.go
0 → 100644
pkg/domain/service/shipping.go
已删除
100644 → 0
pkg/domain/service/shipping_goods.go
0 → 100644
@@ -2,19 +2,26 @@ package domainService | @@ -2,19 +2,26 @@ package domainService | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
5 | 7 | ||
6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 8 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
7 | ) | 9 | ) |
8 | 10 | ||
9 | -type ShippingService struct { | 11 | +type CancelOrderService struct { |
12 | + coreDomain.BaseEventPublisher | ||
10 | transactionContext *pgTransaction.TransactionContext | 13 | transactionContext *pgTransaction.TransactionContext |
11 | } | 14 | } |
12 | 15 | ||
13 | -func NewShippingService(transactionContext *pgTransaction.TransactionContext) (*ShippingService, error) { | 16 | +func (service *CancelOrderService) Cancel(orderId int64) (*domain.Order, error) { |
17 | + return nil, nil | ||
18 | +} | ||
19 | + | ||
20 | +func NewCancelOrderService(transactionContext *pgTransaction.TransactionContext) (*CancelOrderService, error) { | ||
14 | if transactionContext == nil { | 21 | if transactionContext == nil { |
15 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 22 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
16 | } else { | 23 | } else { |
17 | - return &ShippingService{ | 24 | + return &CancelOrderService{ |
18 | transactionContext: transactionContext, | 25 | transactionContext: transactionContext, |
19 | }, nil | 26 | }, nil |
20 | } | 27 | } |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
7 | + | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | +) | ||
10 | + | ||
11 | +type ReceivingGoodsService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) { | ||
17 | + return nil, nil | ||
18 | +} | ||
19 | + | ||
20 | +func NewReceivingGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReceivingGoodsService, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &ReceivingGoodsService{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
7 | + | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | +) | ||
10 | + | ||
11 | +type ReturnGoodsService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *ReceivingGoodsService) Return(orderId int64) (*domain.Order, error) { | ||
17 | + return nil, nil | ||
18 | +} | ||
19 | + | ||
20 | +func NewReturnGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReturnGoodsService, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &ReturnGoodsService{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
7 | + | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | +) | ||
10 | + | ||
11 | +type ShippingGoodsService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *ShippingGoodsService) Shipping(orderId int64) (*domain.Order, error) { | ||
17 | + return nil, nil | ||
18 | +} | ||
19 | + | ||
20 | +func NewShippingGoodsService(transactionContext *pgTransaction.TransactionContext) (*ShippingGoodsService, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &ShippingGoodsService{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
@@ -7,7 +7,6 @@ import ( | @@ -7,7 +7,6 @@ import ( | ||
7 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/constant" |
8 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models" | 8 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models" |
9 | 9 | ||
10 | - //_ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models" | ||
11 | "github.com/linmadan/egglib-go/persistent/pg/hooks" | 10 | "github.com/linmadan/egglib-go/persistent/pg/hooks" |
12 | ) | 11 | ) |
13 | 12 |
@@ -22,7 +22,7 @@ func (controller *OrderController) CreateOrder() { | @@ -22,7 +22,7 @@ func (controller *OrderController) CreateOrder() { | ||
22 | func (controller *OrderController) UpdateOrder() { | 22 | func (controller *OrderController) UpdateOrder() { |
23 | orderService := service.NewOrderService(nil) | 23 | orderService := service.NewOrderService(nil) |
24 | updateOrderCommand := &command.UpdateOrderCommand{} | 24 | updateOrderCommand := &command.UpdateOrderCommand{} |
25 | - controller.Unmarshal(updateOrderCommand) | 25 | + _ = controller.Unmarshal(updateOrderCommand) |
26 | orderId, _ := controller.GetInt64(":orderId") | 26 | orderId, _ := controller.GetInt64(":orderId") |
27 | updateOrderCommand.OrderId = orderId | 27 | updateOrderCommand.OrderId = orderId |
28 | data, err := orderService.UpdateOrder(updateOrderCommand) | 28 | data, err := orderService.UpdateOrder(updateOrderCommand) |
@@ -41,7 +41,7 @@ func (controller *OrderController) GetOrder() { | @@ -41,7 +41,7 @@ func (controller *OrderController) GetOrder() { | ||
41 | func (controller *OrderController) RemoveOrder() { | 41 | func (controller *OrderController) RemoveOrder() { |
42 | orderService := service.NewOrderService(nil) | 42 | orderService := service.NewOrderService(nil) |
43 | removeOrderCommand := &command.RemoveOrderCommand{} | 43 | removeOrderCommand := &command.RemoveOrderCommand{} |
44 | - controller.Unmarshal(removeOrderCommand) | 44 | + _ = controller.Unmarshal(removeOrderCommand) |
45 | orderId, _ := controller.GetInt64(":orderId") | 45 | orderId, _ := controller.GetInt64(":orderId") |
46 | removeOrderCommand.OrderId = orderId | 46 | removeOrderCommand.OrderId = orderId |
47 | data, err := orderService.RemoveOrder(removeOrderCommand) | 47 | data, err := orderService.RemoveOrder(removeOrderCommand) |
@@ -58,3 +58,13 @@ func (controller *OrderController) ListOrder() { | @@ -58,3 +58,13 @@ func (controller *OrderController) ListOrder() { | ||
58 | data, err := orderService.ListOrder(listOrderQuery) | 58 | data, err := orderService.ListOrder(listOrderQuery) |
59 | controller.Response(data, err) | 59 | controller.Response(data, err) |
60 | } | 60 | } |
61 | + | ||
62 | +func (controller *OrderController) Shipping() { | ||
63 | + orderService := service.NewOrderService(nil) | ||
64 | + shippingCmd := &command.ShippingGoodsCommand{} | ||
65 | + _ = controller.Unmarshal(shippingCmd) | ||
66 | + orderId, _ := controller.GetInt(":orderId") | ||
67 | + shippingCmd.OrderId = orderId | ||
68 | + data, err := orderService.Shipping(shippingCmd) | ||
69 | + controller.Response(data, err) | ||
70 | +} |
@@ -9,7 +9,7 @@ import ( | @@ -9,7 +9,7 @@ import ( | ||
9 | pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | 9 | pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" |
10 | ) | 10 | ) |
11 | 11 | ||
12 | -var _ = Describe("创建订单增删改查", func() { | 12 | +var _ = FDescribe("创建订单增删改查", func() { |
13 | Describe("提交数据创建订单增删改查", func() { | 13 | Describe("提交数据创建订单增删改查", func() { |
14 | Context("提交正确的新订单实体数据", func() { | 14 | Context("提交正确的新订单实体数据", func() { |
15 | It("返回订单实体数据", func() { | 15 | It("返回订单实体数据", func() { |
-
请 注册 或 登录 后发表评论