作者 yangfu

merge '6-order-domain-service' to 'dev'

Resolve "order-domain-service"
正在显示 56 个修改的文件 包含 732 行增加346 行删除
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsDetail 4 + name: goodDetail
5 description: 商品详情 5 description: 商品详情
6 type: 6 type:
7 - schema: goodsDetail 7 + schema: goodDetail
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsDividend 4 + name: goodDividend
5 description: 商品分红支付信息 5 description: 商品分红支付信息
6 type: 6 type:
7 schema: dividend 7 schema: dividend
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsDividendStatus 4 + name: goodDividendStatus
5 description: 商品分红支付状态 5 description: 商品分红支付状态
6 type: 6 type:
7 primitive: int 7 primitive: int
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsId 4 + name: goodId
5 description: 商品id 5 description: 商品id
6 type: 6 type:
7 primitive: int64 7 primitive: int64
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsName 4 + name: goodName
5 description: 商品名称 5 description: 商品名称
6 type: 6 type:
7 primitive: string 7 primitive: string
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsNum 4 + name: goodNum
5 description: 预定的货品数量 5 description: 预定的货品数量
6 type: 6 type:
7 primitive: int 7 primitive: int
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsTotalPrice 4 + name: goodTotalPrice
5 description: 商品单价 5 description: 商品单价
6 type: 6 type:
7 primitive: float64 7 primitive: float64
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: actualNumber 4 + name: actualNum
5 description: 调整后的实际货品数量 5 description: 调整后的实际货品数量
6 type: 6 type:
7 primitive: int 7 primitive: int
1 version: v1 1 version: v1
2 kind: Attribute 2 kind: Attribute
3 metadata: 3 metadata:
4 - name: goodsDetailId 4 + name: goodDetailId
5 description: 商品详情id 5 description: 商品详情id
6 type: 6 type:
7 primitive: int64 7 primitive: int64
  1 +version: v1
  2 +kind: Attribute
  3 +metadata:
  4 + name: deliveryTime
  5 + description: 发货时间
  6 + type:
  7 + primitive: datetime
@@ -4,4 +4,4 @@ metadata: @@ -4,4 +4,4 @@ metadata:
4 name: orderGoods 4 name: orderGoods
5 description: 订单货品 5 description: 订单货品
6 type: 6 type:
7 - array: goods 7 + array: good
1 version: v1 1 version: v1
2 kind: Schema 2 kind: Schema
3 metadata: 3 metadata:
4 - name: goods 4 + name: good
5 description: 订单商品实体 5 description: 订单商品实体
6 attributes: 6 attributes:
7 - - ref: goodsId 7 + - ref: goodId
8 required: true 8 required: true
9 - - ref: goodsNum 9 + - ref: goodNum
10 required: true 10 required: true
11 - - ref: goodsDividend 11 + - ref: goodDividend
12 required: true 12 required: true
13 - - ref: goodsDividendStatus 13 + - ref: goodDividendStatus
14 required: true 14 required: true
15 - - ref: goodsName 15 + - ref: goodName
16 required: true 16 required: true
17 - - ref: goodsTotalPrice 17 + - ref: goodTotalPrice
18 required: true 18 required: true
19 - ref: remarks 19 - ref: remarks
20 required: true 20 required: true
21 - ref: orderNo 21 - ref: orderNo
22 required: true 22 required: true
23 - - name: goodsDetail 23 + - name: goodDetail
24 required: true 24 required: true
25 - ref: createAt 25 - ref: createAt
26 required: true 26 required: true
1 version: v1 1 version: v1
2 kind: Schema 2 kind: Schema
3 metadata: 3 metadata:
4 - name: goodsDetail 4 + name: goodDetail
5 description: 商品详情值对象 5 description: 商品详情值对象
6 attributes: 6 attributes:
7 - - ref: goodsDetailId 7 + - ref: goodDetailId
8 required: true 8 required: true
9 - ref: adjustedNum 9 - ref: adjustedNum
10 required: true 10 required: true
@@ -10,10 +10,12 @@ metadata: @@ -10,10 +10,12 @@ metadata:
10 required: true 10 required: true
11 - ref: companyId 11 - ref: companyId
12 required: true 12 required: true
13 - - ref: partnerId 13 + - ref: userId
14 required: true 14 required: true
15 - ref: deliveryCode 15 - ref: deliveryCode
16 required: true 16 required: true
  17 + - ref: delieveryTime
  18 + required: true
17 - ref: isDisable 19 - ref: isDisable
18 required: true 20 required: true
19 - ref: orderNo 21 - ref: orderNo
1 -version: v1  
2 -kind: Schema  
3 -metadata:  
4 - name: partner  
5 - description: 合伙人实体  
6 - attributes:  
7 - - ref: partnerId  
8 - required: true  
9 - - ref: cooperateTime  
10 - required: true  
11 - - ref: partnerCategory  
12 - required: true  
13 - - ref: partnerCategoryInfos  
14 - required: true  
15 - - ref: partnerInfo  
16 - required: true  
17 - - ref: salesman  
18 - required: true  
19 - - ref: status  
20 - required: true  
@@ -22,6 +22,14 @@ func CreateReceivingService(options map[string]interface{}) (service.ReceivingGo @@ -22,6 +22,14 @@ func CreateReceivingService(options map[string]interface{}) (service.ReceivingGo
22 return domainService.NewReceivingGoodsService(transactionContext) 22 return domainService.NewReceivingGoodsService(transactionContext)
23 } 23 }
24 24
  25 +func CreateCreateOrderService(options map[string]interface{}) (service.CreateOrderService, error) {
  26 + var transactionContext *pgTransaction.TransactionContext
  27 + if value, ok := options["transactionContext"]; ok {
  28 + transactionContext = value.(*pgTransaction.TransactionContext)
  29 + }
  30 + return domainService.NewCreateOrderService(transactionContext)
  31 +}
  32 +
25 func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) { 33 func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) {
26 var transactionContext *pgTransaction.TransactionContext 34 var transactionContext *pgTransaction.TransactionContext
27 if value, ok := options["transactionContext"]; ok { 35 if value, ok := options["transactionContext"]; ok {
@@ -38,7 +38,7 @@ func CreateOrderRepository(options map[string]interface{}) (domain.OrderReposito @@ -38,7 +38,7 @@ func CreateOrderRepository(options map[string]interface{}) (domain.OrderReposito
38 return repository.NewOrderRepository(transactionContext) 38 return repository.NewOrderRepository(transactionContext)
39 } 39 }
40 40
41 -func CreateGoodsRepository(options map[string]interface{}) (domain.GoodsRepository, error) { 41 +func CreateGoodsRepository(options map[string]interface{}) (domain.GoodRepository, error) {
42 var transactionContext *pg.TransactionContext 42 var transactionContext *pg.TransactionContext
43 if value, ok := options["transactionContext"]; ok { 43 if value, ok := options["transactionContext"]; ok {
44 transactionContext = value.(*pg.TransactionContext) 44 transactionContext = value.(*pg.TransactionContext)
@@ -2,11 +2,14 @@ package command @@ -2,11 +2,14 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
5 6
6 "github.com/beego/beego/v2/core/validation" 7 "github.com/beego/beego/v2/core/validation"
7 ) 8 )
8 9
9 type CreateOrderCommand struct { 10 type CreateOrderCommand struct {
  11 + // 订单ID
  12 + OrderId int64 `json:"orderId"`
10 // 订单编号 13 // 订单编号
11 OrderNo string `json:"orderNo" valid:"Required"` 14 OrderNo string `json:"orderNo" valid:"Required"`
12 // 公司Id 15 // 公司Id
@@ -15,16 +18,30 @@ type CreateOrderCommand struct { @@ -15,16 +18,30 @@ type CreateOrderCommand struct {
15 BuyerName string `json:"buyerName,omitempty"` 18 BuyerName string `json:"buyerName,omitempty"`
16 // 联系信息 19 // 联系信息
17 ContactInfo string `json:"contactInfo,omitempty"` 20 ContactInfo string `json:"contactInfo,omitempty"`
18 - // 货地址 21 + // 货地址
19 ShippingAddress string `json:"shippingAddress,omitempty"` 22 ShippingAddress string `json:"shippingAddress,omitempty"`
  23 + // 买家备注
  24 + Remarks string `json:"remarks,omitempty"`
20 // 订单商品总数 25 // 订单商品总数
21 OrderNum int64 `json:"orderNum" valid:"Required"` 26 OrderNum int64 `json:"orderNum" valid:"Required"`
22 // 订单总价 27 // 订单总价
23 TotalPrice float64 `json:"totalPrice" valid:"Required"` 28 TotalPrice float64 `json:"totalPrice" valid:"Required"`
  29 + // 订单合伙人ID
  30 + PartnerId int64 `json:"partnerId"`
  31 + // 订单状态
  32 + OrderStatus int `json:"orderStatus"`
  33 + // 订单类型
  34 + OrderType int `json:"orderType"`
  35 + // 订单商品
  36 + OrderGoods []*domain.Good `json:"orderGoods"`
  37 + // 合伙人分红比例
  38 + PartnerBonusPercent float64 `json:"partnerBonusPercent"`
  39 + // 业务员抽成比例
  40 + SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
24 } 41 }
25 42
26 func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) { 43 func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) {
27 - validation.SetError("CustomValid", "未实现的自定义认证") 44 + //validation.SetError("CustomValid", "未实现的自定义认证")
28 } 45 }
29 46
30 func (createOrderCommand *CreateOrderCommand) ValidateCommand() error { 47 func (createOrderCommand *CreateOrderCommand) ValidateCommand() error {
@@ -14,7 +14,7 @@ type DrawDividendsCommand struct { @@ -14,7 +14,7 @@ type DrawDividendsCommand struct {
14 } 14 }
15 15
16 func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) { 16 func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error { 20 func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error {
@@ -12,7 +12,7 @@ type RemoveOrderCommand struct { @@ -12,7 +12,7 @@ type RemoveOrderCommand struct {
12 } 12 }
13 13
14 func (removeOrderCommand *RemoveOrderCommand) Valid(validation *validation.Validation) { 14 func (removeOrderCommand *RemoveOrderCommand) Valid(validation *validation.Validation) {
15 - validation.SetError("CustomValid", "未实现的自定义认证") 15 + //validation.SetError("CustomValid", "未实现的自定义认证")
16 } 16 }
17 17
18 func (removeOrderCommand *RemoveOrderCommand) ValidateCommand() error { 18 func (removeOrderCommand *RemoveOrderCommand) ValidateCommand() error {
@@ -2,40 +2,16 @@ package command @@ -2,40 +2,16 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "time"  
6 -  
7 "github.com/beego/beego/v2/core/validation" 5 "github.com/beego/beego/v2/core/validation"
8 ) 6 )
9 7
10 type ReturnGoodsCommand struct { 8 type ReturnGoodsCommand struct {
  9 + // 订单ID
  10 + OrderId int64 `json:"orderId" valid:"Required"`
11 // 订单号 11 // 订单号
12 OrderNo string `json:"orderNo" valid:"Required"` 12 OrderNo string `json:"orderNo" valid:"Required"`
13 - // 是否是公司负责人  
14 - IsPrincipal bool `json:"isPrincipal" valid:"Required"`  
15 // 统一用户id 13 // 统一用户id
16 Uid int64 `json:"uid" valid:"Required"` 14 Uid int64 `json:"uid" valid:"Required"`
17 - // 用户账号  
18 - UserAccount string `json:"userAccount" valid:"Required"`  
19 - // 用户头像URL  
20 - UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`  
21 - // 用户名称  
22 - UserName string `json:"userName" valid:"Required"`  
23 - // 邮件地址  
24 - Email string `json:"email" valid:"Required"`  
25 - // 性别  
26 - Gender int `json:"gender" valid:"Required"`  
27 - // 入职时间  
28 - EntryTime time.Time `json:"entryTime" valid:"Required"`  
29 - // 分机  
30 - Extension string `json:"extension" valid:"Required"`  
31 - // 工作地  
32 - Workplace string `json:"workplace" valid:"Required"`  
33 - // 私人电话  
34 - PrivateNumber string `json:"privateNumber" valid:"Required"`  
35 - // 工号  
36 - JobNumber string `json:"jobNumber" valid:"Required"`  
37 - // 公司id  
38 - CompanyId int64 `json:"companyId" valid:"Required"`  
39 } 15 }
40 16
41 func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) { 17 func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) {
@@ -9,10 +9,18 @@ import ( @@ -9,10 +9,18 @@ import (
9 type UpdateOrderCommand struct { 9 type UpdateOrderCommand struct {
10 // 订单id 10 // 订单id
11 OrderId int64 `json:"orderId" valid:"Required"` 11 OrderId int64 `json:"orderId" valid:"Required"`
  12 + // 发货地址
  13 + BuyerName string `json:"buyerName"`
  14 + // 订单商品总数
  15 + OrderNum int `json:"orderNum"`
  16 + // 订单总价
  17 + TotalPrice float64 `json:"totalPrice"`
  18 + // 收货地址
  19 + ShippingAddress string `json:"shippingAddress,omitempty"`
12 } 20 }
13 21
14 func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) { 22 func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) {
15 - validation.SetError("CustomValid", "未实现的自定义认证") 23 + //validation.SetError("CustomValid", "未实现的自定义认证")
16 } 24 }
17 25
18 func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error { 26 func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error {
@@ -12,7 +12,7 @@ type GetOrderQuery struct { @@ -12,7 +12,7 @@ type GetOrderQuery struct {
12 } 12 }
13 13
14 func (getOrderQuery *GetOrderQuery) Valid(validation *validation.Validation) { 14 func (getOrderQuery *GetOrderQuery) Valid(validation *validation.Validation) {
15 - validation.SetError("CustomValid", "未实现的自定义认证") 15 + //validation.SetError("CustomValid", "未实现的自定义认证")
16 } 16 }
17 17
18 func (getOrderQuery *GetOrderQuery) ValidateQuery() error { 18 func (getOrderQuery *GetOrderQuery) ValidateQuery() error {
@@ -8,13 +8,13 @@ import ( @@ -8,13 +8,13 @@ import (
8 8
9 type ListOrderQuery struct { 9 type ListOrderQuery struct {
10 // 查询偏离量 10 // 查询偏离量
11 - Offset int `json:"offset" valid:"Required"` 11 + Offset int `json:"offset"`
12 // 查询限制 12 // 查询限制
13 Limit int `json:"limit" valid:"Required"` 13 Limit int `json:"limit" valid:"Required"`
14 } 14 }
15 15
16 func (listOrderQuery *ListOrderQuery) Valid(validation *validation.Validation) { 16 func (listOrderQuery *ListOrderQuery) Valid(validation *validation.Validation) {
17 - validation.SetError("CustomValid", "未实现的自定义认证") 17 + //validation.SetError("CustomValid", "未实现的自定义认证")
18 } 18 }
19 19
20 func (listOrderQuery *ListOrderQuery) ValidateQuery() error { 20 func (listOrderQuery *ListOrderQuery) ValidateQuery() error {
@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query" 9 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query"
10 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" 10 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
11 "strconv" 11 "strconv"
  12 + "time"
12 ) 13 )
13 14
14 // 订单基础服务 15 // 订单基础服务
@@ -52,23 +53,36 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create @@ -52,23 +53,36 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create
52 _ = transactionContext.RollbackTransaction() 53 _ = transactionContext.RollbackTransaction()
53 }() 54 }()
54 newOrder := &domain.Order{ 55 newOrder := &domain.Order{
55 - OrderNo: createOrderCommand.OrderNo,  
56 - CompanyId: createOrderCommand.CompanyId, 56 + OrderNo: createOrderCommand.OrderNo,
  57 + CompanyId: createOrderCommand.CompanyId,
  58 + PartnerId: createOrderCommand.PartnerId,
  59 + IsDisable: false,
  60 + OrderGoods: createOrderCommand.OrderGoods,
  61 + OrderDividend: &domain.Dividend{
  62 + PartnerBonusPercent: createOrderCommand.PartnerBonusPercent,
  63 + SalesmanBonusPercent: createOrderCommand.SalesmanBonusPercent,
  64 + },
57 Buyer: &domain.BuyerInfo{ 65 Buyer: &domain.BuyerInfo{
58 - BuyerName: createOrderCommand.BuyerName, 66 + BuyerName: createOrderCommand.BuyerName,
  67 + ContactInfo: createOrderCommand.ContactInfo,
  68 + ShippingAddress: createOrderCommand.ShippingAddress,
  69 + Remarks: createOrderCommand.Remarks,
59 }, 70 },
60 - TotalPrice: createOrderCommand.TotalPrice, 71 + TotalPrice: createOrderCommand.TotalPrice,
  72 + CreateAt: time.Now(),
  73 + OrderStatus: domain.ORDER_STATUS_UNSHIPPED,
  74 + OrderType: createOrderCommand.OrderType,
  75 + CurrentStatus: &domain.UnShippedStatus{},
61 } 76 }
62 - var orderRepository domain.OrderRepository  
63 - if value, err := factory.CreateOrderRepository(map[string]interface{}{ 77 + createOrderService, err := factory.CreateCreateOrderService(map[string]interface{}{
64 "transactionContext": transactionContext, 78 "transactionContext": transactionContext,
65 - }); err != nil {  
66 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
67 - } else {  
68 - orderRepository = value 79 + })
  80 + if err != nil {
  81 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
69 } 82 }
70 - if order, err := orderRepository.Save(newOrder); err != nil {  
71 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 83 + order, err := createOrderService.Create(newOrder)
  84 + if err != nil {
  85 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
72 } else { 86 } else {
73 if err := transactionContext.CommitTransaction(); err != nil { 87 if err := transactionContext.CommitTransaction(); err != nil {
74 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 88 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -8,4 +8,6 @@ type BuyerInfo struct { @@ -8,4 +8,6 @@ type BuyerInfo struct {
8 ContactInfo string `json:"contactInfo"` 8 ContactInfo string `json:"contactInfo"`
9 // 发货地址 9 // 发货地址
10 ShippingAddress string `json:"shippingAddress"` 10 ShippingAddress string `json:"shippingAddress"`
  11 + // 买家备注
  12 + Remarks string `json:"remarks"`
11 } 13 }
1 package domain 1 package domain
2 2
  3 +const (
  4 + Dividend_Unpaid = iota + 1
  5 + Dividend_Payed
  6 +)
  7 +
3 // 分红值对象 8 // 分红值对象
4 type Dividend struct { 9 type Dividend struct {
5 // 计划分红 10 // 计划分红
@@ -3,24 +3,25 @@ package domain @@ -3,24 +3,25 @@ package domain
3 import "time" 3 import "time"
4 4
5 // 订单商品实体 5 // 订单商品实体
6 -type Goods struct { 6 +type Good struct {
7 // 商品id 7 // 商品id
8 - GoodsId int64 `json:"goodsId"` 8 + GoodId int64 `json:"goodId"`
9 // 预定的货品数量 9 // 预定的货品数量
10 - GoodsNum int `json:"goodsNum"` 10 + GoodNum int `json:"goodNum"`
11 // 商品分红支付信息 11 // 商品分红支付信息
12 - GoodsDividend *Dividend `json:"goodsDividend"` 12 + GoodDividend *Dividend `json:"goodDividend"`
13 // 商品分红支付状态 13 // 商品分红支付状态
14 - GoodsDividendStatus int `json:"goodsDividendStatus"` 14 + GoodDividendStatus int `json:"goodDividendStatus"`
15 // 商品名称 15 // 商品名称
16 - GoodsName string `json:"goodsName"` 16 + GoodName string `json:"goodName"`
17 // 商品单价 17 // 商品单价
18 - GoodsTotalPrice float64 `json:"goodsTotalPrice"` 18 + GoodTotalPrice float64 `json:"goodTotalPrice"`
19 // 备注 19 // 备注
20 Remarks string `json:"remarks"` 20 Remarks string `json:"remarks"`
21 // 订单编号 21 // 订单编号
22 - OrderNo string `json:"orderNo"`  
23 - GoodsDetail string `json:"goodsDetail"` 22 + OrderNo string `json:"orderNo"`
  23 + // 商品详情
  24 + GoodDetail string `json:"goodDetail"`
24 // 创建时间 25 // 创建时间
25 CreateAt time.Time `json:"createAt"` 26 CreateAt time.Time `json:"createAt"`
26 // 更新时间 27 // 更新时间
@@ -29,80 +30,80 @@ type Goods struct { @@ -29,80 +30,80 @@ type Goods struct {
29 DeleteAt time.Time `json:"deleteAt"` 30 DeleteAt time.Time `json:"deleteAt"`
30 } 31 }
31 32
32 -type GoodsRepository interface {  
33 - Save(goods *Goods) (*Goods, error)  
34 - Remove(goods *Goods) (*Goods, error)  
35 - FindOne(queryOptions map[string]interface{}) (*Goods, error)  
36 - Find(queryOptions map[string]interface{}) (int64, []*Goods, error) 33 +type GoodRepository interface {
  34 + Save(good *Good) (*Good, error)
  35 + Remove(good *Good) (*Good, error)
  36 + FindOne(queryOptions map[string]interface{}) (*Good, error)
  37 + Find(queryOptions map[string]interface{}) (int64, []*Good, error)
37 } 38 }
38 39
39 -func (goods *Goods) Identify() interface{} {  
40 - if goods.GoodsId == 0 { 40 +func (good *Good) Identify() interface{} {
  41 + if good.GoodId == 0 {
41 return nil 42 return nil
42 } 43 }
43 - return goods.GoodsId 44 + return good.GoodId
44 } 45 }
45 46
46 -func (goods *Goods) Update(data map[string]interface{}) error {  
47 - if goodsId, ok := data["goodsId"]; ok {  
48 - goods.GoodsId = goodsId.(int64) 47 +func (good *Good) Update(data map[string]interface{}) error {
  48 + if goodId, ok := data["goodId"]; ok {
  49 + good.GoodId = goodId.(int64)
49 } 50 }
50 - if goodsNum, ok := data["goodsNum"]; ok {  
51 - goods.GoodsNum = goodsNum.(int) 51 + if goodNum, ok := data["goodNum"]; ok {
  52 + good.GoodNum = goodNum.(int)
52 } 53 }
53 if planBonus, ok := data["planBonus"]; ok { 54 if planBonus, ok := data["planBonus"]; ok {
54 - goods.GoodsDividend.PlanBonus = planBonus.(float64) 55 + good.GoodDividend.PlanBonus = planBonus.(float64)
55 } 56 }
56 if useBonus, ok := data["useBonus"]; ok { 57 if useBonus, ok := data["useBonus"]; ok {
57 - goods.GoodsDividend.UseBonus = useBonus.(float64) 58 + good.GoodDividend.UseBonus = useBonus.(float64)
58 } 59 }
59 if bonusHas, ok := data["bonusHas"]; ok { 60 if bonusHas, ok := data["bonusHas"]; ok {
60 - goods.GoodsDividend.BonusHas = bonusHas.(float64) 61 + good.GoodDividend.BonusHas = bonusHas.(float64)
61 } 62 }
62 if bonusNot, ok := data["bonusNot"]; ok { 63 if bonusNot, ok := data["bonusNot"]; ok {
63 - goods.GoodsDividend.BonusNot = bonusNot.(float64) 64 + good.GoodDividend.BonusNot = bonusNot.(float64)
64 } 65 }
65 if bonusExpense, ok := data["bonusExpense"]; ok { 66 if bonusExpense, ok := data["bonusExpense"]; ok {
66 - goods.GoodsDividend.BonusExpense = bonusExpense.(float64) 67 + good.GoodDividend.BonusExpense = bonusExpense.(float64)
67 } 68 }
68 if bonusStatus, ok := data["bonusStatus"]; ok { 69 if bonusStatus, ok := data["bonusStatus"]; ok {
69 - goods.GoodsDividend.BonusStatus = bonusStatus.(int) 70 + good.GoodDividend.BonusStatus = bonusStatus.(int)
70 } 71 }
71 if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok { 72 if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
72 - goods.GoodsDividend.PartnerBonusPercent = partnerBonusPercent.(float64) 73 + good.GoodDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
73 } 74 }
74 if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok { 75 if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
75 - goods.GoodsDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64) 76 + good.GoodDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
76 } 77 }
77 if salesmanBonus, ok := data["salesmanBonus"]; ok { 78 if salesmanBonus, ok := data["salesmanBonus"]; ok {
78 - goods.GoodsDividend.SalesmanBonus = salesmanBonus.(float64) 79 + good.GoodDividend.SalesmanBonus = salesmanBonus.(float64)
79 } 80 }
80 - if goodsDividendStatus, ok := data["goodsDividendStatus"]; ok {  
81 - goods.GoodsDividendStatus = goodsDividendStatus.(int) 81 + if goodDividendStatus, ok := data["goodDividendStatus"]; ok {
  82 + good.GoodDividendStatus = goodDividendStatus.(int)
82 } 83 }
83 - if goodsName, ok := data["goodsName"]; ok {  
84 - goods.GoodsName = goodsName.(string) 84 + if goodName, ok := data["goodName"]; ok {
  85 + good.GoodName = goodName.(string)
85 } 86 }
86 - if goodsTotalPrice, ok := data["goodsTotalPrice"]; ok {  
87 - goods.GoodsTotalPrice = goodsTotalPrice.(float64) 87 + if goodTotalPrice, ok := data["goodTotalPrice"]; ok {
  88 + good.GoodTotalPrice = goodTotalPrice.(float64)
88 } 89 }
89 if remarks, ok := data["remarks"]; ok { 90 if remarks, ok := data["remarks"]; ok {
90 - goods.Remarks = remarks.(string) 91 + good.Remarks = remarks.(string)
91 } 92 }
92 if orderNo, ok := data["orderNo"]; ok { 93 if orderNo, ok := data["orderNo"]; ok {
93 - goods.OrderNo = orderNo.(string) 94 + good.OrderNo = orderNo.(string)
94 } 95 }
95 - if goodsDetail, ok := data["goodsDetail"]; ok {  
96 - goods.GoodsDetail = goodsDetail.(string) 96 + if goodDetail, ok := data["goodDetail"]; ok {
  97 + good.GoodDetail = goodDetail.(string)
97 } 98 }
98 if createAt, ok := data["createAt"]; ok { 99 if createAt, ok := data["createAt"]; ok {
99 - goods.CreateAt = createAt.(time.Time) 100 + good.CreateAt = createAt.(time.Time)
100 } 101 }
101 if updateAt, ok := data["updateAt"]; ok { 102 if updateAt, ok := data["updateAt"]; ok {
102 - goods.UpdateAt = updateAt.(time.Time) 103 + good.UpdateAt = updateAt.(time.Time)
103 } 104 }
104 if deleteAt, ok := data["deleteAt"]; ok { 105 if deleteAt, ok := data["deleteAt"]; ok {
105 - goods.DeleteAt = deleteAt.(time.Time) 106 + good.DeleteAt = deleteAt.(time.Time)
106 } 107 }
107 return nil 108 return nil
108 } 109 }
@@ -13,12 +13,14 @@ const ( @@ -13,12 +13,14 @@ const (
13 13
14 // 订单状态 14 // 订单状态
15 const ( 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 // 已完成 16 + ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
  17 + ORDER_STATUS_SHIPPING // 已发货
  18 + ORDER_STATUS_PART_SHIPPING // 部分发货
  19 + ORDER_STATUS_RECEIVED // 已收货
  20 + ORDER_STATUS_RETURN // 退换货
  21 + ORDER_STATUS_CANCELED // 已取消
  22 + ORDER_STATUS_COMPLETED // 已完成
  23 + ORDER_STATUS_CLOSED // 已关闭
22 ) 24 )
23 25
24 // 订单实体 26 // 订单实体
@@ -33,8 +35,10 @@ type Order struct { @@ -33,8 +35,10 @@ type Order struct {
33 PartnerId int64 `json:"partnerId"` 35 PartnerId int64 `json:"partnerId"`
34 // 发货单号 36 // 发货单号
35 DeliveryCode string `json:"deliveryCode"` 37 DeliveryCode string `json:"deliveryCode"`
  38 + // 发货时间
  39 + DeliveryTime time.Time `json:"deliveryTime"`
36 // 是否关闭订单标志 40 // 是否关闭订单标志
37 - IsDisable int `json:"isDisable"` 41 + IsDisable bool `json:"isDisable"`
38 // 订单编号 42 // 订单编号
39 OrderNo string `json:"orderNo"` 43 OrderNo string `json:"orderNo"`
40 // 订单详情 44 // 订单详情
@@ -44,7 +48,7 @@ type Order struct { @@ -44,7 +48,7 @@ type Order struct {
44 // 订单分红支付状态 48 // 订单分红支付状态
45 OrderDividendStatus int `json:"orderDividendStatus"` 49 OrderDividendStatus int `json:"orderDividendStatus"`
46 // 订单货品 50 // 订单货品
47 - OrderGoods []*Goods `json:"orderGoods"` 51 + OrderGoods []*Good `json:"orderGoods"`
48 // 订单数据来源 52 // 订单数据来源
49 OrderSource *OrderSource `json:"orderSource"` 53 OrderSource *OrderSource `json:"orderSource"`
50 // 订单类型(1.实际订单;2.意向订单) 54 // 订单类型(1.实际订单;2.意向订单)
@@ -70,13 +74,14 @@ type Order struct { @@ -70,13 +74,14 @@ type Order struct {
70 // 订单状态机 74 // 订单状态机
71 type OrderStatus interface { 75 type OrderStatus interface {
72 Update(order *Order, data map[string]interface{}) error // 更新订单 76 Update(order *Order, data map[string]interface{}) error // 更新订单
73 - Checkout(order *Order) error // 下单 77 + Shipping(order *Order) error // 发货(全部发货,部分发货)
74 Return(order *Order) error // 退换货 78 Return(order *Order) error // 退换货
75 Cancel(order *Order) error // 取消订单 79 Cancel(order *Order) error // 取消订单
76 Receive(order *Order) error // 收货 80 Receive(order *Order) error // 收货
  81 + Close(order *Order) error // 关闭订单
77 } 82 }
78 83
79 -// 发货状态 84 +// 发货状态
80 type UnShippedStatus struct{} 85 type UnShippedStatus struct{}
81 86
82 // 编辑待发货订单 87 // 编辑待发货订单
@@ -103,7 +108,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) @@ -103,7 +108,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
103 order.DeliveryCode = deliveryCode.(string) 108 order.DeliveryCode = deliveryCode.(string)
104 } 109 }
105 if isDisable, ok := data["isDisable"]; ok { 110 if isDisable, ok := data["isDisable"]; ok {
106 - order.IsDisable = isDisable.(int) 111 + order.IsDisable = isDisable.(bool)
107 } 112 }
108 if orderNo, ok := data["orderNo"]; ok { 113 if orderNo, ok := data["orderNo"]; ok {
109 order.OrderNo = orderNo.(string) 114 order.OrderNo = orderNo.(string)
@@ -157,7 +162,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) @@ -157,7 +162,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
157 order.OrderDividendStatus = orderDividendStatus.(int) 162 order.OrderDividendStatus = orderDividendStatus.(int)
158 } 163 }
159 if orderGoods, ok := data["orderGoods"]; ok { 164 if orderGoods, ok := data["orderGoods"]; ok {
160 - order.OrderGoods = orderGoods.([]*Goods) 165 + order.OrderGoods = orderGoods.([]*Good)
161 } 166 }
162 if dataSourceId, ok := data["dataSourceId"]; ok { 167 if dataSourceId, ok := data["dataSourceId"]; ok {
163 order.OrderSource.DataSourceId = dataSourceId.(int64) 168 order.OrderSource.DataSourceId = dataSourceId.(int64)
@@ -183,150 +188,283 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) @@ -183,150 +188,283 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
183 if remarks, ok := data["remarks"]; ok { 188 if remarks, ok := data["remarks"]; ok {
184 order.Remarks = remarks.(string) 189 order.Remarks = remarks.(string)
185 } 190 }
186 - if createAt, ok := data["createAt"]; ok {  
187 - order.CreateAt = createAt.(time.Time)  
188 - }  
189 - if updateAt, ok := data["updateAt"]; ok {  
190 - order.UpdateAt = updateAt.(time.Time)  
191 - }  
192 - if deleteAt, ok := data["deleteAt"]; ok {  
193 - order.DeleteAt = deleteAt.(time.Time)  
194 - } 191 + order.UpdateAt = time.Now()
  192 +
  193 + order.ComputeDividend()
195 return nil 194 return nil
196 } 195 }
197 196
198 -func (status *UnShippedStatus) Checkout(order *Order) error { 197 +// 发货
  198 +func (status *UnShippedStatus) Shipping(order *Order) error {
  199 + currentTime := time.Now()
  200 + order.DeliveryTime = currentTime
  201 + if order.OrderType == ORDER_TYPE_INTENTION {
  202 + order.OrderStatus = ORDER_STATUS_SHIPPING
  203 + order.CurrentStatus = &TransitStatus{}
  204 + }
199 return nil 205 return nil
200 } 206 }
201 207
  208 +// 待发货订单不能退货
202 func (status *UnShippedStatus) Return(order *Order) error { 209 func (status *UnShippedStatus) Return(order *Order) error {
203 return fmt.Errorf("待发货订单不能退货") 210 return fmt.Errorf("待发货订单不能退货")
204 } 211 }
205 212
  213 +// 取消订单
206 func (status *UnShippedStatus) Cancel(order *Order) error { 214 func (status *UnShippedStatus) Cancel(order *Order) error {
  215 + order.CurrentStatus = &CanceledStatus{}
207 return nil 216 return nil
208 } 217 }
209 218
  219 +// 待发货订单不能收货
210 func (status *UnShippedStatus) Receive(order *Order) error { 220 func (status *UnShippedStatus) Receive(order *Order) error {
211 return fmt.Errorf("待发货订单不能收货") 221 return fmt.Errorf("待发货订单不能收货")
212 } 222 }
213 223
  224 +// 待收货订单不能关闭
  225 +func (status *UnShippedStatus) Close(order *Order) error {
  226 + return fmt.Errorf("待收货订单不能关闭")
  227 +}
  228 +
214 // 待收货状态 229 // 待收货状态
215 type TransitStatus struct{} 230 type TransitStatus struct{}
216 231
  232 +// 待收货订单不能再次发货
  233 +func (status *TransitStatus) Shipping(order *Order) error {
  234 + return fmt.Errorf("待收货订单不能重复发货")
  235 +}
  236 +
217 // 待收货订单不允许编辑 237 // 待收货订单不允许编辑
218 func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { 238 func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error {
219 return fmt.Errorf("已发货订单不允许编辑") 239 return fmt.Errorf("已发货订单不允许编辑")
220 } 240 }
221 241
222 -func (status *TransitStatus) Checkout(order *Order) error {  
223 - return fmt.Errorf("待收货订单不能重复发货")  
224 -}  
225 - 242 +// 退货
226 func (status *TransitStatus) Return(order *Order) error { 243 func (status *TransitStatus) Return(order *Order) error {
  244 + order.CurrentStatus = &ReturnedStatus{}
227 return nil 245 return nil
228 } 246 }
229 247
  248 +// 待收货订单不能取消
230 func (status *TransitStatus) Cancel(order *Order) error { 249 func (status *TransitStatus) Cancel(order *Order) error {
231 return fmt.Errorf("待收货订单不能取消") 250 return fmt.Errorf("待收货订单不能取消")
232 } 251 }
233 252
  253 +// 收货
234 func (status *TransitStatus) Receive(order *Order) error { 254 func (status *TransitStatus) Receive(order *Order) error {
  255 + order.CurrentStatus = &ReceivedStatus{}
235 return nil 256 return nil
236 } 257 }
237 258
  259 +// 待收货订单不能关闭
  260 +func (status *TransitStatus) Close(order *Order) error {
  261 + return fmt.Errorf("待收货订单不能关闭")
  262 +}
  263 +
238 // 收货状态 264 // 收货状态
239 type ReceivedStatus struct{} 265 type ReceivedStatus struct{}
240 266
  267 +// 已收货订单不能编辑
241 func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { 268 func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error {
242 return fmt.Errorf("已收货订单不能编辑") 269 return fmt.Errorf("已收货订单不能编辑")
243 } 270 }
244 271
245 -func (status *ReceivedStatus) Checkout(order *Order) error {  
246 - return fmt.Errorf("已收货订单不能重复发货") 272 +// 已收货订单不能再次收货
  273 +func (status *ReceivedStatus) Shipping(order *Order) error {
  274 + return fmt.Errorf("已收货订单不能再次发货")
247 } 275 }
248 276
  277 +// 退货
249 func (status *ReceivedStatus) Return(order *Order) error { 278 func (status *ReceivedStatus) Return(order *Order) error {
  279 + order.CurrentStatus = &ReturnedStatus{}
250 return nil 280 return nil
251 } 281 }
252 282
  283 +// 已取消订单不能再次取消
253 func (status *ReceivedStatus) Cancel(order *Order) error { 284 func (status *ReceivedStatus) Cancel(order *Order) error {
254 return fmt.Errorf("已收货订单不能取消") 285 return fmt.Errorf("已收货订单不能取消")
255 } 286 }
256 287
  288 +// 已收货订单不能重复收货
257 func (status *ReceivedStatus) Receive(order *Order) error { 289 func (status *ReceivedStatus) Receive(order *Order) error {
258 return fmt.Errorf("已收货订单不能重复收货") 290 return fmt.Errorf("已收货订单不能重复收货")
259 } 291 }
260 292
  293 +// 关闭订单
  294 +func (status *ReceivedStatus) Close(order *Order) error {
  295 + order.IsDisable = true
  296 + order.CurrentStatus = &ClosedStatus{}
  297 + return nil
  298 +}
  299 +
261 // 退货状态 300 // 退货状态
262 type ReturnedStatus struct{} 301 type ReturnedStatus struct{}
263 302
  303 +// 已退货订单不能编辑
264 func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error { 304 func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error {
265 return fmt.Errorf("已退货订单不允许编辑") 305 return fmt.Errorf("已退货订单不允许编辑")
266 } 306 }
267 307
268 -func (status *ReturnedStatus) Checkout(order *Order) error {  
269 - return fmt.Errorf("已退货订单不允许发货") 308 +// 已收货订单不能再次收货
  309 +func (status *ReturnedStatus) Shipping(order *Order) error {
  310 + return fmt.Errorf("已收货订单不能再次发货")
270 } 311 }
271 312
  313 +// 已退货订单不能再次发货
272 func (status *ReturnedStatus) Return(order *Order) error { 314 func (status *ReturnedStatus) Return(order *Order) error {
273 return fmt.Errorf("已退货订单不允许再次退货") 315 return fmt.Errorf("已退货订单不允许再次退货")
274 } 316 }
275 317
  318 +// 已退货订单不能取消
276 func (status *ReturnedStatus) Cancel(order *Order) error { 319 func (status *ReturnedStatus) Cancel(order *Order) error {
277 return fmt.Errorf("已退货订单不能取消") 320 return fmt.Errorf("已退货订单不能取消")
278 } 321 }
279 322
  323 +// 已退货订单不能重复守护
280 func (status *ReturnedStatus) Receive(order *Order) error { 324 func (status *ReturnedStatus) Receive(order *Order) error {
281 return fmt.Errorf("已退货订单不能收货") 325 return fmt.Errorf("已退货订单不能收货")
282 } 326 }
283 327
  328 +// 关闭已退货订单
  329 +func (status *ReturnedStatus) Close(order *Order) error {
  330 + order.IsDisable = true
  331 + order.CurrentStatus = &ClosedStatus{}
  332 + return nil
  333 +}
  334 +
284 // 取消状态 335 // 取消状态
285 type CanceledStatus struct{} 336 type CanceledStatus struct{}
286 337
  338 +// 已取消订单不能编辑
287 func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error { 339 func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error {
288 return fmt.Errorf("已取消订单不能编辑") 340 return fmt.Errorf("已取消订单不能编辑")
289 } 341 }
290 342
291 -func (status *CanceledStatus) Checkout(order *Order) error {  
292 - return fmt.Errorf("已取消订单不能发货") 343 +// 已取消订单不能发货
  344 +func (status *CanceledStatus) Shipping(order *Order) error {
  345 + return fmt.Errorf("已取消订单不能再次发货")
293 } 346 }
294 347
  348 +// 已取消的订单不能退货
295 func (status *CanceledStatus) Return(order *Order) error { 349 func (status *CanceledStatus) Return(order *Order) error {
296 return fmt.Errorf("已取消订单不能退货") 350 return fmt.Errorf("已取消订单不能退货")
297 } 351 }
298 352
  353 +// 已取消定案不能再次取消
299 func (status *CanceledStatus) Cancel(order *Order) error { 354 func (status *CanceledStatus) Cancel(order *Order) error {
300 return fmt.Errorf("已取消订单不能再次取消") 355 return fmt.Errorf("已取消订单不能再次取消")
301 } 356 }
302 357
  358 +// 已取消订单不能收货
303 func (status *CanceledStatus) Receive(order *Order) error { 359 func (status *CanceledStatus) Receive(order *Order) error {
304 return fmt.Errorf("已取消订单不能进行收货") 360 return fmt.Errorf("已取消订单不能进行收货")
305 } 361 }
306 362
  363 +// 关闭订单
  364 +func (status *CanceledStatus) Close(order *Order) error {
  365 + order.IsDisable = true
  366 + order.CurrentStatus = &ClosedStatus{}
  367 + return nil
  368 +}
  369 +
307 // 已完成状态 370 // 已完成状态
308 type CompletedStatus struct{} 371 type CompletedStatus struct{}
309 372
  373 +// 编辑已完成订单分红
310 func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { 374 func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error {
  375 + if planBonus, ok := data["planBonus"]; ok {
  376 + order.OrderDividend.PlanBonus = planBonus.(float64)
  377 + }
  378 + if useBonus, ok := data["useBonus"]; ok {
  379 + order.OrderDividend.UseBonus = useBonus.(float64)
  380 + }
  381 + if bonusHas, ok := data["bonusHas"]; ok {
  382 + order.OrderDividend.BonusHas = bonusHas.(float64)
  383 + }
  384 + if bonusNot, ok := data["bonusNot"]; ok {
  385 + order.OrderDividend.BonusNot = bonusNot.(float64)
  386 + }
  387 + if bonusExpense, ok := data["bonusExpense"]; ok {
  388 + order.OrderDividend.BonusExpense = bonusExpense.(float64)
  389 + }
  390 + if bonusStatus, ok := data["bonusStatus"]; ok {
  391 + order.OrderDividend.BonusStatus = bonusStatus.(int)
  392 + }
  393 + if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
  394 + order.OrderDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
  395 + }
  396 + if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
  397 + order.OrderDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
  398 + }
  399 + if salesmanBonus, ok := data["salesmanBonus"]; ok {
  400 + order.OrderDividend.SalesmanBonus = salesmanBonus.(float64)
  401 + }
  402 + if orderDividendStatus, ok := data["orderDividendStatus"]; ok {
  403 + order.OrderDividendStatus = orderDividendStatus.(int)
  404 + }
311 return nil 405 return nil
312 } 406 }
313 407
314 -func (status *CompletedStatus) Checkout(order *Order) error { 408 +// 已完成的订单不能再次发货
  409 +func (status *CompletedStatus) Shipping(order *Order) error {
315 return fmt.Errorf("已完成订单不能发货") 410 return fmt.Errorf("已完成订单不能发货")
316 } 411 }
317 412
  413 +// 已完成订单不能退货
318 func (status *CompletedStatus) Return(order *Order) error { 414 func (status *CompletedStatus) Return(order *Order) error {
319 return fmt.Errorf("已完成订单不能退货") 415 return fmt.Errorf("已完成订单不能退货")
320 } 416 }
321 417
  418 +// 已完成订单不能取消
322 func (status *CompletedStatus) Cancel(order *Order) error { 419 func (status *CompletedStatus) Cancel(order *Order) error {
323 return fmt.Errorf("已完成订单不能取消") 420 return fmt.Errorf("已完成订单不能取消")
324 } 421 }
325 422
  423 +// 已完成订单不能收货
326 func (status *CompletedStatus) Receive(order *Order) error { 424 func (status *CompletedStatus) Receive(order *Order) error {
327 return fmt.Errorf("已完成订单不能收货") 425 return fmt.Errorf("已完成订单不能收货")
328 } 426 }
329 427
  428 +// 关闭已完成订单
  429 +func (status *CompletedStatus) Close(order *Order) error {
  430 + order.IsDisable = true
  431 + order.CurrentStatus = &ClosedStatus{}
  432 + return nil
  433 +}
  434 +
  435 +// 关闭状态
  436 +type ClosedStatus struct{}
  437 +
  438 +// 已关闭订单不能进行编辑
  439 +func (status *ClosedStatus) Update(order *Order, data map[string]interface{}) error {
  440 + return fmt.Errorf("已关闭订单不能进行编辑")
  441 +}
  442 +
  443 +// 已关闭订单不能发货
  444 +func (status *ClosedStatus) Shipping(order *Order) error {
  445 + return fmt.Errorf("已关闭订单不能发货")
  446 +}
  447 +
  448 +// 已关闭订单不能退货
  449 +func (status *ClosedStatus) Return(order *Order) error {
  450 + return fmt.Errorf("已关闭订单不能退货")
  451 +}
  452 +
  453 +// 已关闭订单不能取消
  454 +func (status *ClosedStatus) Cancel(order *Order) error {
  455 + return fmt.Errorf("已关闭订单不能取消")
  456 +}
  457 +
  458 +// 已关闭订单不能收货
  459 +func (status *ClosedStatus) Receive(order *Order) error {
  460 + return fmt.Errorf("已关闭订单不能收货")
  461 +}
  462 +
  463 +// 已关闭订单不能再次关闭
  464 +func (status *ClosedStatus) Close(order *Order) error {
  465 + return fmt.Errorf("已关闭订单不能再次关闭")
  466 +}
  467 +
330 // 订单仓储 468 // 订单仓储
331 type OrderRepository interface { 469 type OrderRepository interface {
332 Save(order *Order) (*Order, error) 470 Save(order *Order) (*Order, error)
@@ -348,8 +486,8 @@ func (order *Order) Update(data map[string]interface{}) error { @@ -348,8 +486,8 @@ func (order *Order) Update(data map[string]interface{}) error {
348 } 486 }
349 487
350 // 发货 488 // 发货
351 -func (order *Order) Checkout() error {  
352 - return order.CurrentStatus.Checkout(order) 489 +func (order *Order) Shipping() error {
  490 + return order.CurrentStatus.Shipping(order)
353 } 491 }
354 492
355 // 退货 493 // 退货
@@ -366,3 +504,75 @@ func (order *Order) Receive() error { @@ -366,3 +504,75 @@ func (order *Order) Receive() error {
366 func (order *Order) Cancel() error { 504 func (order *Order) Cancel() error {
367 return order.CurrentStatus.Cancel(order) 505 return order.CurrentStatus.Cancel(order)
368 } 506 }
  507 +
  508 +// 关闭订单
  509 +func (order *Order) Close() error {
  510 + return order.CurrentStatus.Close(order)
  511 +}
  512 +
  513 +func (order *Order) RefreshOrderDetail() {
  514 +
  515 +}
  516 +func (order *Order) ComputeDividend() {
  517 + order.computeGoodsDividend()
  518 + order.computeOrderDividend()
  519 +}
  520 +func (order *Order) computeOrderDividend() {
  521 + var totalPlanBonus float64
  522 + // 调整后分红
  523 + var totalUseBonus float64
  524 + // 已收分红
  525 + var totalBonusHas float64
  526 + // 未收分红
  527 + var totalBonusNot float64
  528 + // 分红支出
  529 + var totalBonusExpense float64
  530 + for _, v := range order.OrderGoods {
  531 + totalPlanBonus += v.GoodDividend.PlanBonus
  532 + totalUseBonus += v.GoodDividend.UseBonus
  533 + totalBonusHas += v.GoodDividend.BonusHas
  534 + totalBonusNot += v.GoodDividend.BonusNot
  535 + totalBonusExpense += v.GoodDividend.BonusExpense
  536 + }
  537 + order.OrderDividend.PlanBonus = totalPlanBonus
  538 + order.OrderDividend.UseBonus = totalUseBonus
  539 + order.OrderDividend.BonusHas = totalBonusHas
  540 + order.OrderDividend.BonusNot = totalBonusNot
  541 + order.OrderDividend.BonusExpense = totalBonusExpense
  542 +}
  543 +func (order *Order) computeGoodsDividend() {
  544 + for i := range order.OrderGoods {
  545 + good := order.OrderGoods[i]
  546 + bonus := good.GoodTotalPrice * float64(good.GoodNum) * (order.OrderDividend.PartnerBonusPercent / 100)
  547 + if good.GoodDividend == nil {
  548 + good.GoodDividend = &Dividend{
  549 + PlanBonus: bonus,
  550 + UseBonus: -1,
  551 + BonusHas: 0,
  552 + BonusNot: bonus,
  553 + BonusExpense: 0,
  554 + BonusStatus: Dividend_Unpaid,
  555 + }
  556 + } else {
  557 + /* 计算预计分红、调整后分红 */
  558 + if bonus != good.GoodDividend.PlanBonus {
  559 + if order.OrderStatus == ORDER_STATUS_UNSHIPPED {
  560 + good.GoodDividend.PlanBonus = bonus
  561 + good.GoodDividend.BonusNot = bonus
  562 + } else {
  563 + expense := good.GoodDividend.PlanBonus - bonus
  564 + if expense <= 0 {
  565 + expense = 0
  566 + }
  567 + good.GoodDividend.UseBonus = bonus
  568 + good.GoodDividend.BonusNot = bonus
  569 + good.GoodDividend.BonusExpense = expense
  570 + }
  571 + }
  572 + /*计算未支付分红*/
  573 + if good.GoodDividend.BonusHas > 0 {
  574 + good.GoodDividend.BonusNot = good.GoodDividend.PlanBonus - good.GoodDividend.BonusHas
  575 + }
  576 + }
  577 + }
  578 +}
@@ -15,7 +15,7 @@ type PartnerInfo struct { @@ -15,7 +15,7 @@ type PartnerInfo struct {
15 // 合伙时间 15 // 合伙时间
16 CooperateTime time.Time `json:"cooperateTime"` 16 CooperateTime time.Time `json:"cooperateTime"`
17 // 业务员 17 // 业务员
18 - Salesmans []*Salesman `json:"salesmans"` 18 + Salesmen []*Salesman `json:"salesmen"`
19 // 合伙人类型 19 // 合伙人类型
20 - PartnerCategorys []*PartnerCategory `json:"partnerCategorys"` 20 + PartnerCategories []*PartnerCategory `json:"partnerCategories"`
21 } 21 }
  1 +package service
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  6 +)
  7 +
  8 +type CreateOrderService interface {
  9 + coreDomain.DomainEventPublisher
  10 + Create(newOrder *domain.Order) (*domain.Order, error)
  11 +}
@@ -141,10 +141,10 @@ func CheckPartnerUserType(dm *User) (*User, error) { @@ -141,10 +141,10 @@ func CheckPartnerUserType(dm *User) (*User, error) {
141 if dm.PartnerInfo.PartnerName == "" { 141 if dm.PartnerInfo.PartnerName == "" {
142 return nil, fmt.Errorf("合伙人姓名不能为空") 142 return nil, fmt.Errorf("合伙人姓名不能为空")
143 } 143 }
144 - if len(dm.PartnerInfo.PartnerCategorys) == 0 { 144 + if len(dm.PartnerInfo.PartnerCategories) == 0 {
145 return nil, fmt.Errorf("合伙人类别不能为空") 145 return nil, fmt.Errorf("合伙人类别不能为空")
146 } 146 }
147 - if len(dm.PartnerInfo.Salesmans) == 0 { 147 + if len(dm.PartnerInfo.Salesmen) == 0 {
148 return nil, fmt.Errorf("合伙人查看合伙人账号不能为空") 148 return nil, fmt.Errorf("合伙人查看合伙人账号不能为空")
149 } 149 }
150 return dm, nil 150 return dm, nil
@@ -2,8 +2,10 @@ package domainService @@ -2,8 +2,10 @@ package domainService
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 6 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
7 9
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 10 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
9 ) 11 )
@@ -14,6 +16,24 @@ type CancelOrderService struct { @@ -14,6 +16,24 @@ type CancelOrderService struct {
14 } 16 }
15 17
16 func (service *CancelOrderService) Cancel(orderId int64) (*domain.Order, error) { 18 func (service *CancelOrderService) Cancel(orderId int64) (*domain.Order, error) {
  19 + var orderRepository domain.OrderRepository
  20 + if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
  21 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  22 + } else {
  23 + orderRepository = value
  24 + }
  25 + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
  26 + if err != nil {
  27 + return nil, err
  28 + }
  29 + if err := order.Cancel(); err != nil {
  30 + return nil, err
  31 + }
  32 + if order, err := orderRepository.Save(order); err != nil {
  33 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  34 + } else {
  35 + return order, nil
  36 + }
17 return nil, nil 37 return nil, nil
18 } 38 }
19 39
  1 +package domainService
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
  10 +)
  11 +
  12 +type CreateOrderService struct {
  13 + coreDomain.BaseEventPublisher
  14 + transactionContext *pgTransaction.TransactionContext
  15 +}
  16 +
  17 +func (service *CreateOrderService) Create(newOrder *domain.Order) (*domain.Order, error) {
  18 + var orderRepository domain.OrderRepository
  19 + if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
  20 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  21 + } else {
  22 + orderRepository = value
  23 + }
  24 + if err := newOrder.Update(nil); err != nil {
  25 + return nil, err
  26 + }
  27 + if order, err := orderRepository.Save(newOrder); err != nil {
  28 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  29 + } else {
  30 + return order, nil
  31 + }
  32 + return nil, nil
  33 +}
  34 +
  35 +func NewCreateOrderService(transactionContext *pgTransaction.TransactionContext) (*CreateOrderService, error) {
  36 + if transactionContext == nil {
  37 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  38 + } else {
  39 + return &CreateOrderService{
  40 + transactionContext: transactionContext,
  41 + }, nil
  42 + }
  43 +}
@@ -2,8 +2,10 @@ package domainService @@ -2,8 +2,10 @@ package domainService
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 6 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
7 9
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 10 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
9 ) 11 )
@@ -14,6 +16,24 @@ type ReceivingGoodsService struct { @@ -14,6 +16,24 @@ type ReceivingGoodsService struct {
14 } 16 }
15 17
16 func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) { 18 func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) {
  19 + var orderRepository domain.OrderRepository
  20 + if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
  21 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  22 + } else {
  23 + orderRepository = value
  24 + }
  25 + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
  26 + if err != nil {
  27 + return nil, err
  28 + }
  29 + if err := order.Receive(); err != nil {
  30 + return nil, err
  31 + }
  32 + if order, err := orderRepository.Save(order); err != nil {
  33 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  34 + } else {
  35 + return order, nil
  36 + }
17 return nil, nil 37 return nil, nil
18 } 38 }
19 39
@@ -2,8 +2,10 @@ package domainService @@ -2,8 +2,10 @@ package domainService
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 6 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
7 9
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 10 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
9 ) 11 )
@@ -14,7 +16,25 @@ type ReturnGoodsService struct { @@ -14,7 +16,25 @@ type ReturnGoodsService struct {
14 } 16 }
15 17
16 func (service *ReturnGoodsService) Return(orderId int64) (*domain.Order, error) { 18 func (service *ReturnGoodsService) Return(orderId int64) (*domain.Order, error) {
17 - panic("implement me") 19 + var orderRepository domain.OrderRepository
  20 + if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
  21 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  22 + } else {
  23 + orderRepository = value
  24 + }
  25 + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
  26 + if err != nil {
  27 + return nil, err
  28 + }
  29 + if err := order.Return(); err != nil {
  30 + return nil, err
  31 + }
  32 + if order, err := orderRepository.Save(order); err != nil {
  33 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  34 + } else {
  35 + return order, nil
  36 + }
  37 + return nil, nil
18 } 38 }
19 39
20 func NewReturnGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReturnGoodsService, error) { 40 func NewReturnGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReturnGoodsService, error) {
@@ -2,8 +2,10 @@ package domainService @@ -2,8 +2,10 @@ package domainService
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 6 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
7 9
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 10 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
9 ) 11 )
@@ -14,6 +16,24 @@ type ShippingGoodsService struct { @@ -14,6 +16,24 @@ type ShippingGoodsService struct {
14 } 16 }
15 17
16 func (service *ShippingGoodsService) Shipping(orderId int64) (*domain.Order, error) { 18 func (service *ShippingGoodsService) Shipping(orderId int64) (*domain.Order, error) {
  19 + var orderRepository domain.OrderRepository
  20 + if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
  21 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  22 + } else {
  23 + orderRepository = value
  24 + }
  25 + order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
  26 + if err != nil {
  27 + return nil, err
  28 + }
  29 + if err := order.Shipping(); err != nil {
  30 + return nil, err
  31 + }
  32 + if order, err := orderRepository.Save(order); err != nil {
  33 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  34 + } else {
  35 + return order, nil
  36 + }
17 return nil, nil 37 return nil, nil
18 } 38 }
19 39
@@ -29,7 +29,7 @@ func init() { @@ -29,7 +29,7 @@ func init() {
29 &models.Permission{}, 29 &models.Permission{},
30 &models.PartnerCategory{}, 30 &models.PartnerCategory{},
31 &models.UserAuth{}, 31 &models.UserAuth{},
32 - &models.Goods{}, 32 + &models.Good{},
33 &models.Order{}, 33 &models.Order{},
34 &models.User{}, 34 &models.User{},
35 &models.Company{}, 35 &models.Company{},
@@ -5,30 +5,30 @@ import ( @@ -5,30 +5,30 @@ import (
5 "time" 5 "time"
6 ) 6 )
7 7
8 -type Goods struct {  
9 - tableName string `pg:"goodss,alias:goods"` 8 +type Good struct {
  9 + tableName string `pg:"goods,alias:good"`
10 // 商品id 10 // 商品id
11 - GoodsId int64 11 + GoodId int64 `pg:",pk"`
12 // 预定的货品数量 12 // 预定的货品数量
13 - GoodsNum int 13 + GoodNum int
14 // 商品分红支付信息 14 // 商品分红支付信息
15 - GoodsDividend *domain.Dividend 15 + GoodDividend *domain.Dividend
16 // 商品分红支付状态 16 // 商品分红支付状态
17 - GoodsDividendStatus int 17 + GoodDividendStatus int
18 // 商品名称 18 // 商品名称
19 - GoodsName string 19 + GoodName string
20 // 商品单价 20 // 商品单价
21 - GoodsTotalPrice float64 21 + GoodTotalPrice float64
22 // 备注 22 // 备注
23 Remarks string 23 Remarks string
24 // 订单编号 24 // 订单编号
25 - OrderNo string 25 + OrderNo string
26 // 商品详情 26 // 商品详情
27 - GoodsDetail string 27 + GoodDetail string
28 // 创建时间 28 // 创建时间
29 CreateAt time.Time 29 CreateAt time.Time
30 // 更新时间 30 // 更新时间
31 UpdateAt time.Time 31 UpdateAt time.Time
32 // 删除时间 32 // 删除时间
33 - DeleteAt time.Time 33 + DeleteAt time.Time `pg:",soft_delete"`
34 } 34 }
@@ -6,9 +6,9 @@ import ( @@ -6,9 +6,9 @@ import (
6 ) 6 )
7 7
8 type Order struct { 8 type Order struct {
9 - tableName string `pg:"orders,alias:order"` 9 + tableName string `pg:"orders,alias:orders"`
10 // 订单id 10 // 订单id
11 - OrderId int64 11 + OrderId int64 `pg:",pk"`
12 // 买家信息 12 // 买家信息
13 Buyer *domain.BuyerInfo 13 Buyer *domain.BuyerInfo
14 // 公司Id 14 // 公司Id
@@ -18,7 +18,7 @@ type Order struct { @@ -18,7 +18,7 @@ type Order struct {
18 // 发货单号 18 // 发货单号
19 DeliveryCode string 19 DeliveryCode string
20 // 是否关闭订单标志 20 // 是否关闭订单标志
21 - IsDisable int 21 + IsDisable bool
22 // 订单编号 22 // 订单编号
23 OrderNo string 23 OrderNo string
24 // 订单详情 24 // 订单详情
@@ -28,7 +28,7 @@ type Order struct { @@ -28,7 +28,7 @@ type Order struct {
28 // 订单分红支付状态 28 // 订单分红支付状态
29 OrderDividendStatus int 29 OrderDividendStatus int
30 // 订单货品 30 // 订单货品
31 - OrderGoods []*domain.Goods 31 + OrderGoods []*domain.Good
32 // 订单数据来源 32 // 订单数据来源
33 OrderSource *domain.OrderSource 33 OrderSource *domain.OrderSource
34 // 订单类型(1.实际订单;2.意向订单) 34 // 订单类型(1.实际订单;2.意向订单)
@@ -46,5 +46,5 @@ type Order struct { @@ -46,5 +46,5 @@ type Order struct {
46 // 更新时间 46 // 更新时间
47 UpdateAt time.Time 47 UpdateAt time.Time
48 // 软删 48 // 软删
49 - DeleteAt time.Time 49 + DeleteAt time.Time `pg:",soft_delete"`
50 } 50 }
@@ -32,5 +32,5 @@ type User struct { @@ -32,5 +32,5 @@ type User struct {
32 // 更新时间 32 // 更新时间
33 UpdateAt time.Time 33 UpdateAt time.Time
34 // 删除时间 34 // 删除时间
35 - DeleteAt time.Time 35 + DeleteAt time.Time `pg:",soft_delete"`
36 } 36 }
  1 +package transform
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
  6 +)
  7 +
  8 +func TransformToGoodDomainModelFromPgModels(goodModel *models.Good) (*domain.Good, error) {
  9 + return &domain.Good{
  10 + GoodId: goodModel.GoodId,
  11 + GoodNum: goodModel.GoodNum,
  12 + GoodDividend: goodModel.GoodDividend,
  13 + GoodDividendStatus: goodModel.GoodDividendStatus,
  14 + GoodName: goodModel.GoodName,
  15 + GoodTotalPrice: goodModel.GoodTotalPrice,
  16 + Remarks: goodModel.Remarks,
  17 + OrderNo: goodModel.OrderNo,
  18 + GoodDetail: goodModel.GoodDetail,
  19 + CreateAt: goodModel.CreateAt,
  20 + UpdateAt: goodModel.UpdateAt,
  21 + DeleteAt: goodModel.DeleteAt,
  22 + }, nil
  23 +}
1 -package transform  
2 -  
3 -import (  
4 - "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"  
5 - "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"  
6 -)  
7 -  
8 -func TransformToGoodsDomainModelFromPgModels(goodsModel *models.Goods) (*domain.Goods, error) {  
9 - return &domain.Goods{  
10 - GoodsId: goodsModel.GoodsId,  
11 - GoodsNum: goodsModel.GoodsNum,  
12 - GoodsDividend: goodsModel.GoodsDividend,  
13 - GoodsDividendStatus: goodsModel.GoodsDividendStatus,  
14 - GoodsName: goodsModel.GoodsName,  
15 - GoodsTotalPrice: goodsModel.GoodsTotalPrice,  
16 - Remarks: goodsModel.Remarks,  
17 - OrderNo: goodsModel.OrderNo,  
18 - GoodsDetail: goodsModel.GoodsDetail,  
19 - CreateAt: goodsModel.CreateAt,  
20 - UpdateAt: goodsModel.UpdateAt,  
21 - DeleteAt: goodsModel.DeleteAt,  
22 - }, nil  
23 -}  
@@ -6,6 +6,15 @@ import ( @@ -6,6 +6,15 @@ import (
6 ) 6 )
7 7
8 func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.Order, error) { 8 func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.Order, error) {
  9 + var currentStatus domain.OrderStatus
  10 + switch orderModel.OrderStatus {
  11 + case domain.ORDER_STATUS_UNSHIPPED:
  12 + currentStatus = &domain.UnShippedStatus{}
  13 + case domain.ORDER_STATUS_SHIPPING:
  14 + currentStatus = &domain.TransitStatus{}
  15 + default:
  16 + currentStatus = &domain.UnShippedStatus{}
  17 + }
9 return &domain.Order{ 18 return &domain.Order{
10 OrderId: orderModel.OrderId, 19 OrderId: orderModel.OrderId,
11 Buyer: orderModel.Buyer, 20 Buyer: orderModel.Buyer,
@@ -27,5 +36,6 @@ func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain. @@ -27,5 +36,6 @@ func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.
27 CreateAt: orderModel.CreateAt, 36 CreateAt: orderModel.CreateAt,
28 UpdateAt: orderModel.UpdateAt, 37 UpdateAt: orderModel.UpdateAt,
29 DeleteAt: orderModel.DeleteAt, 38 DeleteAt: orderModel.DeleteAt,
  39 + CurrentStatus: currentStatus,
30 }, nil 40 }, nil
31 } 41 }
@@ -12,11 +12,11 @@ import ( @@ -12,11 +12,11 @@ import (
12 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/transform" 12 "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/transform"
13 ) 13 )
14 14
15 -type GoodsRepository struct { 15 +type GoodRepository struct {
16 transactionContext *pgTransaction.TransactionContext 16 transactionContext *pgTransaction.TransactionContext
17 } 17 }
18 18
19 -func (repository *GoodsRepository) nextIdentify() (int64, error) { 19 +func (repository *GoodRepository) nextIdentify() (int64, error) {
20 IdWorker, err := snowflake.NewIdWorker(1) 20 IdWorker, err := snowflake.NewIdWorker(1)
21 if err != nil { 21 if err != nil {
22 return 0, err 22 return 0, err
@@ -24,17 +24,17 @@ func (repository *GoodsRepository) nextIdentify() (int64, error) { @@ -24,17 +24,17 @@ func (repository *GoodsRepository) nextIdentify() (int64, error) {
24 id, err := IdWorker.NextId() 24 id, err := IdWorker.NextId()
25 return id, err 25 return id, err
26 } 26 }
27 -func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, error) { 27 +func (repository *GoodRepository) Save(good *domain.Good) (*domain.Good, error) {
28 sqlBuildFields := []string{ 28 sqlBuildFields := []string{
29 - "goods_id",  
30 - "goods_num",  
31 - "goods_dividend",  
32 - "goods_dividend_status",  
33 - "goods_name",  
34 - "goods_total_price", 29 + "good_id",
  30 + "good_num",
  31 + "good_dividend",
  32 + "good_dividend_status",
  33 + "good_name",
  34 + "good_total_price",
35 "remarks", 35 "remarks",
36 "order_no", 36 "order_no",
37 - "goods_detail", 37 + "good_detail",
38 "create_at", 38 "create_at",
39 "update_at", 39 "update_at",
40 "delete_at", 40 "delete_at",
@@ -45,94 +45,94 @@ func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, err @@ -45,94 +45,94 @@ func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, err
45 updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "goods_id") 45 updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "goods_id")
46 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 46 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
47 tx := repository.transactionContext.PgTx 47 tx := repository.transactionContext.PgTx
48 - if goods.Identify() == nil {  
49 - goodsId, err := repository.nextIdentify() 48 + if good.Identify() == nil {
  49 + goodId, err := repository.nextIdentify()
50 if err != nil { 50 if err != nil {
51 - return goods, err 51 + return good, err
52 } else { 52 } else {
53 - goods.GoodsId = goodsId 53 + good.GoodId = goodId
54 } 54 }
55 if _, err := tx.QueryOne( 55 if _, err := tx.QueryOne(
56 pg.Scan( 56 pg.Scan(
57 - &goods.GoodsId,  
58 - &goods.GoodsNum,  
59 - &goods.GoodsDividend,  
60 - &goods.GoodsDividendStatus,  
61 - &goods.GoodsName,  
62 - &goods.GoodsTotalPrice,  
63 - &goods.Remarks,  
64 - &goods.OrderNo,  
65 - &goods.GoodsDetail,  
66 - &goods.CreateAt,  
67 - &goods.UpdateAt,  
68 - &goods.DeleteAt, 57 + &good.GoodId,
  58 + &good.GoodNum,
  59 + &good.GoodDividend,
  60 + &good.GoodDividendStatus,
  61 + &good.GoodName,
  62 + &good.GoodTotalPrice,
  63 + &good.Remarks,
  64 + &good.OrderNo,
  65 + &good.GoodDetail,
  66 + &good.CreateAt,
  67 + &good.UpdateAt,
  68 + &good.DeleteAt,
69 ), 69 ),
70 - fmt.Sprintf("INSERT INTO goodss (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),  
71 - goods.GoodsId,  
72 - goods.GoodsNum,  
73 - goods.GoodsDividend,  
74 - goods.GoodsDividendStatus,  
75 - goods.GoodsName,  
76 - goods.GoodsTotalPrice,  
77 - goods.Remarks,  
78 - goods.OrderNo,  
79 - goods.GoodsDetail,  
80 - goods.CreateAt,  
81 - goods.UpdateAt,  
82 - goods.DeleteAt, 70 + fmt.Sprintf("INSERT INTO good (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  71 + good.GoodId,
  72 + good.GoodNum,
  73 + good.GoodDividend,
  74 + good.GoodDividendStatus,
  75 + good.GoodName,
  76 + good.GoodTotalPrice,
  77 + good.Remarks,
  78 + good.OrderNo,
  79 + good.GoodDetail,
  80 + good.CreateAt,
  81 + good.UpdateAt,
  82 + good.DeleteAt,
83 ); err != nil { 83 ); err != nil {
84 - return goods, err 84 + return good, err
85 } 85 }
86 } else { 86 } else {
87 if _, err := tx.QueryOne( 87 if _, err := tx.QueryOne(
88 pg.Scan( 88 pg.Scan(
89 - &goods.GoodsId,  
90 - &goods.GoodsNum,  
91 - &goods.GoodsDividend,  
92 - &goods.GoodsDividendStatus,  
93 - &goods.GoodsName,  
94 - &goods.GoodsTotalPrice,  
95 - &goods.Remarks,  
96 - &goods.OrderNo,  
97 - &goods.GoodsDetail,  
98 - &goods.CreateAt,  
99 - &goods.UpdateAt,  
100 - &goods.DeleteAt, 89 + &good.GoodId,
  90 + &good.GoodNum,
  91 + &good.GoodDividend,
  92 + &good.GoodDividendStatus,
  93 + &good.GoodName,
  94 + &good.GoodTotalPrice,
  95 + &good.Remarks,
  96 + &good.OrderNo,
  97 + &good.GoodDetail,
  98 + &good.CreateAt,
  99 + &good.UpdateAt,
  100 + &good.DeleteAt,
101 ), 101 ),
102 - fmt.Sprintf("UPDATE goodss SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),  
103 - goods.GoodsId,  
104 - goods.GoodsNum,  
105 - goods.GoodsDividend,  
106 - goods.GoodsDividendStatus,  
107 - goods.GoodsName,  
108 - goods.GoodsTotalPrice,  
109 - goods.Remarks,  
110 - goods.OrderNo,  
111 - goods.GoodsDetail,  
112 - goods.CreateAt,  
113 - goods.UpdateAt,  
114 - goods.DeleteAt,  
115 - goods.Identify(), 102 + fmt.Sprintf("UPDATE good SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  103 + good.GoodId,
  104 + good.GoodNum,
  105 + good.GoodDividend,
  106 + good.GoodDividendStatus,
  107 + good.GoodName,
  108 + good.GoodTotalPrice,
  109 + good.Remarks,
  110 + good.OrderNo,
  111 + good.GoodDetail,
  112 + good.CreateAt,
  113 + good.UpdateAt,
  114 + good.DeleteAt,
  115 + good.Identify(),
116 ); err != nil { 116 ); err != nil {
117 - return goods, err 117 + return good, err
118 } 118 }
119 } 119 }
120 - return goods, nil 120 + return good, nil
121 } 121 }
122 -func (repository *GoodsRepository) Remove(goods *domain.Goods) (*domain.Goods, error) { 122 +func (repository *GoodRepository) Remove(good *domain.Good) (*domain.Good, error) {
123 tx := repository.transactionContext.PgTx 123 tx := repository.transactionContext.PgTx
124 - goodsModel := new(models.Goods)  
125 - goodsModel.GoodsId = goods.Identify().(int64)  
126 - if _, err := tx.Model(goodsModel).WherePK().Delete(); err != nil {  
127 - return goods, err 124 + goodModel := new(models.Good)
  125 + goodModel.GoodId = good.Identify().(int64)
  126 + if _, err := tx.Model(goodModel).WherePK().Delete(); err != nil {
  127 + return good, err
128 } 128 }
129 - return goods, nil 129 + return good, nil
130 } 130 }
131 -func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) (*domain.Goods, error) { 131 +func (repository *GoodRepository) FindOne(queryOptions map[string]interface{}) (*domain.Good, error) {
132 tx := repository.transactionContext.PgTx 132 tx := repository.transactionContext.PgTx
133 - goodsModel := new(models.Goods)  
134 - query := sqlbuilder.BuildQuery(tx.Model(goodsModel), queryOptions)  
135 - query.SetWhereByQueryOption("goods.goods_id = ?", "goodsId") 133 + goodModel := new(models.Good)
  134 + query := sqlbuilder.BuildQuery(tx.Model(goodModel), queryOptions)
  135 + query.SetWhereByQueryOption("good.goods_id = ?", "goodsId")
136 if err := query.First(); err != nil { 136 if err := query.First(); err != nil {
137 if err.Error() == "pg: no rows in result set" { 137 if err.Error() == "pg: no rows in result set" {
138 return nil, fmt.Errorf("没有此资源") 138 return nil, fmt.Errorf("没有此资源")
@@ -140,37 +140,37 @@ func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) @@ -140,37 +140,37 @@ func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{})
140 return nil, err 140 return nil, err
141 } 141 }
142 } 142 }
143 - if goodsModel.GoodsId == 0 { 143 + if goodModel.GoodId == 0 {
144 return nil, nil 144 return nil, nil
145 } else { 145 } else {
146 - return transform.TransformToGoodsDomainModelFromPgModels(goodsModel) 146 + return transform.TransformToGoodDomainModelFromPgModels(goodModel)
147 } 147 }
148 } 148 }
149 -func (repository *GoodsRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Goods, error) { 149 +func (repository *GoodRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Good, error) {
150 tx := repository.transactionContext.PgTx 150 tx := repository.transactionContext.PgTx
151 - var goodsModels []*models.Goods  
152 - goodss := make([]*domain.Goods, 0)  
153 - query := sqlbuilder.BuildQuery(tx.Model(&goodsModels), queryOptions) 151 + var goodModels []*models.Good
  152 + goods := make([]*domain.Good, 0)
  153 + query := sqlbuilder.BuildQuery(tx.Model(&goodModels), queryOptions)
154 query.SetOffsetAndLimit(20) 154 query.SetOffsetAndLimit(20)
155 query.SetOrderDirect("goods_id", "DESC") 155 query.SetOrderDirect("goods_id", "DESC")
156 if count, err := query.SelectAndCount(); err != nil { 156 if count, err := query.SelectAndCount(); err != nil {
157 - return 0, goodss, err 157 + return 0, goods, err
158 } else { 158 } else {
159 - for _, goodsModel := range goodsModels {  
160 - if goods, err := transform.TransformToGoodsDomainModelFromPgModels(goodsModel); err != nil {  
161 - return 0, goodss, err 159 + for _, goodModel := range goodModels {
  160 + if good, err := transform.TransformToGoodDomainModelFromPgModels(goodModel); err != nil {
  161 + return 0, goods, err
162 } else { 162 } else {
163 - goodss = append(goodss, goods) 163 + goods = append(goods, good)
164 } 164 }
165 } 165 }
166 - return int64(count), goodss, nil 166 + return int64(count), goods, nil
167 } 167 }
168 } 168 }
169 -func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodsRepository, error) { 169 +func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodRepository, error) {
170 if transactionContext == nil { 170 if transactionContext == nil {
171 return nil, fmt.Errorf("transactionContext参数不能为nil") 171 return nil, fmt.Errorf("transactionContext参数不能为nil")
172 } else { 172 } else {
173 - return &GoodsRepository{ 173 + return &GoodRepository{
174 transactionContext: transactionContext, 174 transactionContext: transactionContext,
175 }, nil 175 }, nil
176 } 176 }
@@ -72,7 +72,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err @@ -72,7 +72,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
72 &order.OrderDetail, 72 &order.OrderDetail,
73 &order.OrderDividend, 73 &order.OrderDividend,
74 &order.OrderDividendStatus, 74 &order.OrderDividendStatus,
75 - pg.Array(&order.OrderGoods), 75 + &order.OrderGoods,
76 &order.OrderSource, 76 &order.OrderSource,
77 &order.OrderType, 77 &order.OrderType,
78 &order.OrderStatus, 78 &order.OrderStatus,
@@ -94,7 +94,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err @@ -94,7 +94,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
94 order.OrderDetail, 94 order.OrderDetail,
95 order.OrderDividend, 95 order.OrderDividend,
96 order.OrderDividendStatus, 96 order.OrderDividendStatus,
97 - pg.Array(order.OrderGoods), 97 + order.OrderGoods,
98 order.OrderSource, 98 order.OrderSource,
99 order.OrderType, 99 order.OrderType,
100 order.OrderStatus, 100 order.OrderStatus,
@@ -120,7 +120,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err @@ -120,7 +120,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
120 &order.OrderDetail, 120 &order.OrderDetail,
121 &order.OrderDividend, 121 &order.OrderDividend,
122 &order.OrderDividendStatus, 122 &order.OrderDividendStatus,
123 - pg.Array(&order.OrderGoods), 123 + &order.OrderGoods,
124 &order.OrderSource, 124 &order.OrderSource,
125 &order.OrderType, 125 &order.OrderType,
126 &order.OrderStatus, 126 &order.OrderStatus,
@@ -132,7 +132,6 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err @@ -132,7 +132,6 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
132 &order.DeleteAt, 132 &order.DeleteAt,
133 ), 133 ),
134 fmt.Sprintf("UPDATE orders SET %s WHERE order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 134 fmt.Sprintf("UPDATE orders SET %s WHERE order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
135 - order.OrderId,  
136 order.Buyer, 135 order.Buyer,
137 order.CompanyId, 136 order.CompanyId,
138 order.PartnerId, 137 order.PartnerId,
@@ -142,7 +141,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err @@ -142,7 +141,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
142 order.OrderDetail, 141 order.OrderDetail,
143 order.OrderDividend, 142 order.OrderDividend,
144 order.OrderDividendStatus, 143 order.OrderDividendStatus,
145 - pg.Array(order.OrderGoods), 144 + order.OrderGoods,
146 order.OrderSource, 145 order.OrderSource,
147 order.OrderType, 146 order.OrderType,
148 order.OrderStatus, 147 order.OrderStatus,
@@ -172,7 +171,7 @@ func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) @@ -172,7 +171,7 @@ func (repository *OrderRepository) FindOne(queryOptions map[string]interface{})
172 tx := repository.transactionContext.PgTx 171 tx := repository.transactionContext.PgTx
173 orderModel := new(models.Order) 172 orderModel := new(models.Order)
174 query := sqlbuilder.BuildQuery(tx.Model(orderModel), queryOptions) 173 query := sqlbuilder.BuildQuery(tx.Model(orderModel), queryOptions)
175 - query.SetWhereByQueryOption("order.order_id = ?", "orderId") 174 + query.SetWhereByQueryOption("orders.order_id = ?", "orderId")
176 if err := query.First(); err != nil { 175 if err := query.First(); err != nil {
177 if err.Error() == "pg: no rows in result set" { 176 if err.Error() == "pg: no rows in result set" {
178 return nil, fmt.Errorf("没有此资源") 177 return nil, fmt.Errorf("没有此资源")
@@ -14,7 +14,7 @@ type OrderController struct { @@ -14,7 +14,7 @@ type OrderController struct {
14 func (controller *OrderController) CreateOrder() { 14 func (controller *OrderController) CreateOrder() {
15 orderService := service.NewOrderService(nil) 15 orderService := service.NewOrderService(nil)
16 createOrderCommand := &command.CreateOrderCommand{} 16 createOrderCommand := &command.CreateOrderCommand{}
17 - controller.Unmarshal(createOrderCommand) 17 + _ = controller.Unmarshal(createOrderCommand)
18 data, err := orderService.CreateOrder(createOrderCommand) 18 data, err := orderService.CreateOrder(createOrderCommand)
19 controller.Response(data, err) 19 controller.Response(data, err)
20 } 20 }
1 package order 1 package order
2 2
3 import ( 3 import (
  4 + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
4 "net/http" 5 "net/http"
5 6
6 "github.com/gavv/httpexpect" 7 "github.com/gavv/httpexpect"
7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/ginkgo"
8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega"
9 - pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"  
10 ) 10 )
11 11
12 -var _ = FDescribe("创建订单增删改查", func() { 12 +var _ = Describe("创建订单增删改查", func() {
13 Describe("提交数据创建订单增删改查", func() { 13 Describe("提交数据创建订单增删改查", func() {
14 Context("提交正确的新订单实体数据", func() { 14 Context("提交正确的新订单实体数据", func() {
15 It("返回订单实体数据", func() { 15 It("返回订单实体数据", func() {
16 httpExpect := httpexpect.New(GinkgoT(), server.URL) 16 httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + orderGoods := []map[string]interface{}{
  18 + {"goodNum": 10, "goodName": "banana", "goodTotalPrice": 3.5, "remarks": "单位:斤"},
  19 + {"goodNum": 20, "goodName": "apple", "goodTotalPrice": 5.5, "remarks": "单位:斤"},
  20 + }
17 body := map[string]interface{}{ 21 body := map[string]interface{}{
18 - "orderNo": "string",  
19 - "companyId": "int64",  
20 - "buyerName": "string",  
21 - "contactInfo": "string",  
22 - "shippingAddress": "string",  
23 - "orderNum": "int64",  
24 - "totalPrice": "float64", 22 + "orderNo": "string",
  23 + "companyId": 1,
  24 + "buyerName": "string",
  25 + "contactInfo": "string",
  26 + "shippingAddress": "string",
  27 + "orderNum": 10,
  28 + "totalPrice": 10,
  29 + "partnerId": "1213",
  30 + "partnerBonusPercent": 15,
  31 + "orderGoods": orderGoods,
25 } 32 }
26 httpExpect.POST("/orders/"). 33 httpExpect.POST("/orders/").
27 WithJSON(body). 34 WithJSON(body).
@@ -13,17 +13,18 @@ import ( @@ -13,17 +13,18 @@ import (
13 var _ = Describe("返回订单增删改查", func() { 13 var _ = Describe("返回订单增删改查", func() {
14 var orderId int64 14 var orderId int64
15 BeforeEach(func() { 15 BeforeEach(func() {
16 - _, err := pG.DB.QueryOne( 16 + // 新增订单测试数据
  17 + _, err2 := pG.DB.QueryOne(
17 pg.Scan(&orderId), 18 pg.Scan(&orderId),
18 - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id",  
19 - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")  
20 - Expect(err).NotTo(HaveOccurred()) 19 + "INSERT INTO orders (order_id) VALUES (?) RETURNING order_id",
  20 + 1)
  21 + Expect(err2).NotTo(HaveOccurred())
21 }) 22 })
22 Describe("根据orderId参数返回订单实体", func() { 23 Describe("根据orderId参数返回订单实体", func() {
23 Context("传入有效的orderId", func() { 24 Context("传入有效的orderId", func() {
24 It("返回订单实体数据", func() { 25 It("返回订单实体数据", func() {
25 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
26 - httpExpect.GET("/orders/{orderId}"). 27 + httpExpect.GET("/orders/1").
27 Expect(). 28 Expect().
28 Status(http.StatusOK). 29 Status(http.StatusOK).
29 JSON(). 30 JSON().
@@ -13,19 +13,20 @@ import ( @@ -13,19 +13,20 @@ import (
13 var _ = Describe("返回订单增删改查列表", func() { 13 var _ = Describe("返回订单增删改查列表", func() {
14 var orderId int64 14 var orderId int64
15 BeforeEach(func() { 15 BeforeEach(func() {
16 - _, err := pG.DB.QueryOne( 16 + // 新增订单测试数据
  17 + _, err2 := pG.DB.QueryOne(
17 pg.Scan(&orderId), 18 pg.Scan(&orderId),
18 - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id",  
19 - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")  
20 - Expect(err).NotTo(HaveOccurred()) 19 + "INSERT INTO orders (order_id) VALUES (?) RETURNING order_id",
  20 + 1)
  21 + Expect(err2).NotTo(HaveOccurred())
21 }) 22 })
22 Describe("根据参数返回订单实体列表", func() { 23 Describe("根据参数返回订单实体列表", func() {
23 Context("传入有效的参数", func() { 24 Context("传入有效的参数", func() {
24 It("返回订单实体数据列表", func() { 25 It("返回订单实体数据列表", func() {
25 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
26 httpExpect.GET("/orders/"). 27 httpExpect.GET("/orders/").
27 - WithQuery("offset", "int").  
28 - WithQuery("limit", "int"). 28 + WithQuery("offset", 0).
  29 + WithQuery("limit", 10).
29 Expect(). 30 Expect().
30 Status(http.StatusOK). 31 Status(http.StatusOK).
31 JSON(). 32 JSON().
@@ -13,24 +13,24 @@ import ( @@ -13,24 +13,24 @@ import (
13 var _ = Describe("移除订单增删改查", func() { 13 var _ = Describe("移除订单增删改查", func() {
14 var orderId int64 14 var orderId int64
15 BeforeEach(func() { 15 BeforeEach(func() {
16 - _, err := pG.DB.QueryOne( 16 + // 新增订单测试数据
  17 + _, err2 := pG.DB.QueryOne(
17 pg.Scan(&orderId), 18 pg.Scan(&orderId),
18 - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id",  
19 - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")  
20 - Expect(err).NotTo(HaveOccurred()) 19 + "INSERT INTO orders (order_id) VALUES (?) RETURNING order_id",
  20 + 1)
  21 + Expect(err2).NotTo(HaveOccurred())
21 }) 22 })
22 Describe("根据参数移除订单增删改查", func() { 23 Describe("根据参数移除订单增删改查", func() {
23 Context("传入有效的orderId", func() { 24 Context("传入有效的orderId", func() {
24 It("返回被移除订单实体的数据", func() { 25 It("返回被移除订单实体的数据", func() {
25 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
26 - httpExpect.DELETE("/orders/{orderId}"). 27 + httpExpect.DELETE("/orders/1").
27 Expect(). 28 Expect().
28 Status(http.StatusOK). 29 Status(http.StatusOK).
29 JSON(). 30 JSON().
30 Object(). 31 Object().
31 ContainsKey("code").ValueEqual("code", 0). 32 ContainsKey("code").ValueEqual("code", 0).
32 - ContainsKey("msg").ValueEqual("msg", "ok").  
33 - ContainsKey("data").Value("data").Object() 33 + ContainsKey("msg").ValueEqual("msg", "ok")
34 }) 34 })
35 }) 35 })
36 }) 36 })
@@ -13,18 +13,21 @@ import ( @@ -13,18 +13,21 @@ import (
13 var _ = Describe("更新订单增删改查", func() { 13 var _ = Describe("更新订单增删改查", func() {
14 var orderId int64 14 var orderId int64
15 BeforeEach(func() { 15 BeforeEach(func() {
16 - _, err := pG.DB.QueryOne( 16 + // 新增订单测试数据
  17 + _, err2 := pG.DB.QueryOne(
17 pg.Scan(&orderId), 18 pg.Scan(&orderId),
18 - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id",  
19 - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")  
20 - Expect(err).NotTo(HaveOccurred()) 19 + "INSERT INTO orders (order_id,company_id,partner_id,buyer,order_dividend,order_detail) VALUES (?,?,?,?,?,?) RETURNING order_id",
  20 + 1, 1, 1, "{}", "{}", "{}")
  21 + Expect(err2).NotTo(HaveOccurred())
21 }) 22 })
22 Describe("提交数据更新订单增删改查", func() { 23 Describe("提交数据更新订单增删改查", func() {
23 Context("提交正确的订单实体数据", func() { 24 Context("提交正确的订单实体数据", func() {
24 It("返回更新后的订单实体数据", func() { 25 It("返回更新后的订单实体数据", func() {
25 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
26 - body := map[string]interface{}{}  
27 - httpExpect.PUT("/orders/{orderId}"). 27 + body := map[string]interface{}{
  28 + "shippingAddress": "fuzhou",
  29 + }
  30 + httpExpect.PUT("/orders/1").
28 WithJSON(body). 31 WithJSON(body).
29 Expect(). 32 Expect().
30 Status(http.StatusOK). 33 Status(http.StatusOK).