作者 yangfu

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

Resolve "order-domain-service"
正在显示 56 个修改的文件 包含 718 行增加332 行删除
version: v1
kind: Attribute
metadata:
name: goodsDetail
name: goodDetail
description: 商品详情
type:
schema: goodsDetail
schema: goodDetail
... ...
version: v1
kind: Attribute
metadata:
name: goodsDividend
name: goodDividend
description: 商品分红支付信息
type:
schema: dividend
... ...
version: v1
kind: Attribute
metadata:
name: goodsDividendStatus
name: goodDividendStatus
description: 商品分红支付状态
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: goodsId
name: goodId
description: 商品id
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: goodsName
name: goodName
description: 商品名称
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: goodsNum
name: goodNum
description: 预定的货品数量
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: goodsTotalPrice
name: goodTotalPrice
description: 商品单价
type:
primitive: float64
... ...
version: v1
kind: Attribute
metadata:
name: actualNumber
name: actualNum
description: 调整后的实际货品数量
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: goodsDetailId
name: goodDetailId
description: 商品详情id
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: deliveryTime
description: 发货时间
type:
primitive: datetime
... ...
... ... @@ -4,4 +4,4 @@ metadata:
name: orderGoods
description: 订单货品
type:
array: goods
array: good
... ...
version: v1
kind: Schema
metadata:
name: goods
name: good
description: 订单商品实体
attributes:
- ref: goodsId
- ref: goodId
required: true
- ref: goodsNum
- ref: goodNum
required: true
- ref: goodsDividend
- ref: goodDividend
required: true
- ref: goodsDividendStatus
- ref: goodDividendStatus
required: true
- ref: goodsName
- ref: goodName
required: true
- ref: goodsTotalPrice
- ref: goodTotalPrice
required: true
- ref: remarks
required: true
- ref: orderNo
required: true
- name: goodsDetail
- name: goodDetail
required: true
- ref: createAt
required: true
... ...
version: v1
kind: Schema
metadata:
name: goodsDetail
name: goodDetail
description: 商品详情值对象
attributes:
- ref: goodsDetailId
- ref: goodDetailId
required: true
- ref: adjustedNum
required: true
... ...
... ... @@ -10,10 +10,12 @@ metadata:
required: true
- ref: companyId
required: true
- ref: partnerId
- ref: userId
required: true
- ref: deliveryCode
required: true
- ref: delieveryTime
required: true
- ref: isDisable
required: true
- ref: orderNo
... ...
version: v1
kind: Schema
metadata:
name: partner
description: 合伙人实体
attributes:
- ref: partnerId
required: true
- ref: cooperateTime
required: true
- ref: partnerCategory
required: true
- ref: partnerCategoryInfos
required: true
- ref: partnerInfo
required: true
- ref: salesman
required: true
- ref: status
required: true
... ... @@ -22,6 +22,14 @@ func CreateReceivingService(options map[string]interface{}) (service.ReceivingGo
return domainService.NewReceivingGoodsService(transactionContext)
}
func CreateCreateOrderService(options map[string]interface{}) (service.CreateOrderService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewCreateOrderService(transactionContext)
}
func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ...
... ... @@ -38,7 +38,7 @@ func CreateOrderRepository(options map[string]interface{}) (domain.OrderReposito
return repository.NewOrderRepository(transactionContext)
}
func CreateGoodsRepository(options map[string]interface{}) (domain.GoodsRepository, error) {
func CreateGoodsRepository(options map[string]interface{}) (domain.GoodRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
... ...
... ... @@ -2,11 +2,14 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type CreateOrderCommand struct {
// 订单ID
OrderId int64 `json:"orderId"`
// 订单编号
OrderNo string `json:"orderNo" valid:"Required"`
// 公司Id
... ... @@ -15,16 +18,30 @@ type CreateOrderCommand struct {
BuyerName string `json:"buyerName,omitempty"`
// 联系信息
ContactInfo string `json:"contactInfo,omitempty"`
// 货地址
// 货地址
ShippingAddress string `json:"shippingAddress,omitempty"`
// 买家备注
Remarks string `json:"remarks,omitempty"`
// 订单商品总数
OrderNum int64 `json:"orderNum" valid:"Required"`
// 订单总价
TotalPrice float64 `json:"totalPrice" valid:"Required"`
// 订单合伙人ID
PartnerId int64 `json:"partnerId"`
// 订单状态
OrderStatus int `json:"orderStatus"`
// 订单类型
OrderType int `json:"orderType"`
// 订单商品
OrderGoods []*domain.Good `json:"orderGoods"`
// 合伙人分红比例
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
// 业务员抽成比例
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
}
func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createOrderCommand *CreateOrderCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type DrawDividendsCommand struct {
}
func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error {
... ...
... ... @@ -12,7 +12,7 @@ type RemoveOrderCommand struct {
}
func (removeOrderCommand *RemoveOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeOrderCommand *RemoveOrderCommand) ValidateCommand() error {
... ...
... ... @@ -2,40 +2,16 @@ package command
import (
"fmt"
"time"
"github.com/beego/beego/v2/core/validation"
)
type ReturnGoodsCommand struct {
// 订单ID
OrderId int64 `json:"orderId" valid:"Required"`
// 订单号
OrderNo string `json:"orderNo" valid:"Required"`
// 是否是公司负责人
IsPrincipal bool `json:"isPrincipal" valid:"Required"`
// 统一用户id
Uid int64 `json:"uid" valid:"Required"`
// 用户账号
UserAccount string `json:"userAccount" valid:"Required"`
// 用户头像URL
UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`
// 用户名称
UserName string `json:"userName" valid:"Required"`
// 邮件地址
Email string `json:"email" valid:"Required"`
// 性别
Gender int `json:"gender" valid:"Required"`
// 入职时间
EntryTime time.Time `json:"entryTime" valid:"Required"`
// 分机
Extension string `json:"extension" valid:"Required"`
// 工作地
Workplace string `json:"workplace" valid:"Required"`
// 私人电话
PrivateNumber string `json:"privateNumber" valid:"Required"`
// 工号
JobNumber string `json:"jobNumber" valid:"Required"`
// 公司id
CompanyId int64 `json:"companyId" valid:"Required"`
}
func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -9,10 +9,18 @@ import (
type UpdateOrderCommand struct {
// 订单id
OrderId int64 `json:"orderId" valid:"Required"`
// 发货地址
BuyerName string `json:"buyerName"`
// 订单商品总数
OrderNum int `json:"orderNum"`
// 订单总价
TotalPrice float64 `json:"totalPrice"`
// 收货地址
ShippingAddress string `json:"shippingAddress,omitempty"`
}
func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error {
... ...
... ... @@ -12,7 +12,7 @@ type GetOrderQuery struct {
}
func (getOrderQuery *GetOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getOrderQuery *GetOrderQuery) ValidateQuery() error {
... ...
... ... @@ -8,13 +8,13 @@ import (
type ListOrderQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
Offset int `json:"offset"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
func (listOrderQuery *ListOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listOrderQuery *ListOrderQuery) ValidateQuery() error {
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"strconv"
"time"
)
// 订单基础服务
... ... @@ -54,21 +55,34 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create
newOrder := &domain.Order{
OrderNo: createOrderCommand.OrderNo,
CompanyId: createOrderCommand.CompanyId,
PartnerId: createOrderCommand.PartnerId,
IsDisable: false,
OrderGoods: createOrderCommand.OrderGoods,
OrderDividend: &domain.Dividend{
PartnerBonusPercent: createOrderCommand.PartnerBonusPercent,
SalesmanBonusPercent: createOrderCommand.SalesmanBonusPercent,
},
Buyer: &domain.BuyerInfo{
BuyerName: createOrderCommand.BuyerName,
ContactInfo: createOrderCommand.ContactInfo,
ShippingAddress: createOrderCommand.ShippingAddress,
Remarks: createOrderCommand.Remarks,
},
TotalPrice: createOrderCommand.TotalPrice,
CreateAt: time.Now(),
OrderStatus: domain.ORDER_STATUS_UNSHIPPED,
OrderType: createOrderCommand.OrderType,
CurrentStatus: &domain.UnShippedStatus{},
}
var orderRepository domain.OrderRepository
if value, err := factory.CreateOrderRepository(map[string]interface{}{
createOrderService, err := factory.CreateCreateOrderService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if order, err := orderRepository.Save(newOrder); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
order, err := createOrderService.Create(newOrder)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -8,4 +8,6 @@ type BuyerInfo struct {
ContactInfo string `json:"contactInfo"`
// 发货地址
ShippingAddress string `json:"shippingAddress"`
// 买家备注
Remarks string `json:"remarks"`
}
... ...
package domain
const (
Dividend_Unpaid = iota + 1
Dividend_Payed
)
// 分红值对象
type Dividend struct {
// 计划分红
... ...
... ... @@ -3,24 +3,25 @@ package domain
import "time"
// 订单商品实体
type Goods struct {
type Good struct {
// 商品id
GoodsId int64 `json:"goodsId"`
GoodId int64 `json:"goodId"`
// 预定的货品数量
GoodsNum int `json:"goodsNum"`
GoodNum int `json:"goodNum"`
// 商品分红支付信息
GoodsDividend *Dividend `json:"goodsDividend"`
GoodDividend *Dividend `json:"goodDividend"`
// 商品分红支付状态
GoodsDividendStatus int `json:"goodsDividendStatus"`
GoodDividendStatus int `json:"goodDividendStatus"`
// 商品名称
GoodsName string `json:"goodsName"`
GoodName string `json:"goodName"`
// 商品单价
GoodsTotalPrice float64 `json:"goodsTotalPrice"`
GoodTotalPrice float64 `json:"goodTotalPrice"`
// 备注
Remarks string `json:"remarks"`
// 订单编号
OrderNo string `json:"orderNo"`
GoodsDetail string `json:"goodsDetail"`
// 商品详情
GoodDetail string `json:"goodDetail"`
// 创建时间
CreateAt time.Time `json:"createAt"`
// 更新时间
... ... @@ -29,80 +30,80 @@ type Goods struct {
DeleteAt time.Time `json:"deleteAt"`
}
type GoodsRepository interface {
Save(goods *Goods) (*Goods, error)
Remove(goods *Goods) (*Goods, error)
FindOne(queryOptions map[string]interface{}) (*Goods, error)
Find(queryOptions map[string]interface{}) (int64, []*Goods, error)
type GoodRepository interface {
Save(good *Good) (*Good, error)
Remove(good *Good) (*Good, error)
FindOne(queryOptions map[string]interface{}) (*Good, error)
Find(queryOptions map[string]interface{}) (int64, []*Good, error)
}
func (goods *Goods) Identify() interface{} {
if goods.GoodsId == 0 {
func (good *Good) Identify() interface{} {
if good.GoodId == 0 {
return nil
}
return goods.GoodsId
return good.GoodId
}
func (goods *Goods) Update(data map[string]interface{}) error {
if goodsId, ok := data["goodsId"]; ok {
goods.GoodsId = goodsId.(int64)
func (good *Good) Update(data map[string]interface{}) error {
if goodId, ok := data["goodId"]; ok {
good.GoodId = goodId.(int64)
}
if goodsNum, ok := data["goodsNum"]; ok {
goods.GoodsNum = goodsNum.(int)
if goodNum, ok := data["goodNum"]; ok {
good.GoodNum = goodNum.(int)
}
if planBonus, ok := data["planBonus"]; ok {
goods.GoodsDividend.PlanBonus = planBonus.(float64)
good.GoodDividend.PlanBonus = planBonus.(float64)
}
if useBonus, ok := data["useBonus"]; ok {
goods.GoodsDividend.UseBonus = useBonus.(float64)
good.GoodDividend.UseBonus = useBonus.(float64)
}
if bonusHas, ok := data["bonusHas"]; ok {
goods.GoodsDividend.BonusHas = bonusHas.(float64)
good.GoodDividend.BonusHas = bonusHas.(float64)
}
if bonusNot, ok := data["bonusNot"]; ok {
goods.GoodsDividend.BonusNot = bonusNot.(float64)
good.GoodDividend.BonusNot = bonusNot.(float64)
}
if bonusExpense, ok := data["bonusExpense"]; ok {
goods.GoodsDividend.BonusExpense = bonusExpense.(float64)
good.GoodDividend.BonusExpense = bonusExpense.(float64)
}
if bonusStatus, ok := data["bonusStatus"]; ok {
goods.GoodsDividend.BonusStatus = bonusStatus.(int)
good.GoodDividend.BonusStatus = bonusStatus.(int)
}
if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
goods.GoodsDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
good.GoodDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
}
if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
goods.GoodsDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
good.GoodDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
}
if salesmanBonus, ok := data["salesmanBonus"]; ok {
goods.GoodsDividend.SalesmanBonus = salesmanBonus.(float64)
good.GoodDividend.SalesmanBonus = salesmanBonus.(float64)
}
if goodsDividendStatus, ok := data["goodsDividendStatus"]; ok {
goods.GoodsDividendStatus = goodsDividendStatus.(int)
if goodDividendStatus, ok := data["goodDividendStatus"]; ok {
good.GoodDividendStatus = goodDividendStatus.(int)
}
if goodsName, ok := data["goodsName"]; ok {
goods.GoodsName = goodsName.(string)
if goodName, ok := data["goodName"]; ok {
good.GoodName = goodName.(string)
}
if goodsTotalPrice, ok := data["goodsTotalPrice"]; ok {
goods.GoodsTotalPrice = goodsTotalPrice.(float64)
if goodTotalPrice, ok := data["goodTotalPrice"]; ok {
good.GoodTotalPrice = goodTotalPrice.(float64)
}
if remarks, ok := data["remarks"]; ok {
goods.Remarks = remarks.(string)
good.Remarks = remarks.(string)
}
if orderNo, ok := data["orderNo"]; ok {
goods.OrderNo = orderNo.(string)
good.OrderNo = orderNo.(string)
}
if goodsDetail, ok := data["goodsDetail"]; ok {
goods.GoodsDetail = goodsDetail.(string)
if goodDetail, ok := data["goodDetail"]; ok {
good.GoodDetail = goodDetail.(string)
}
if createAt, ok := data["createAt"]; ok {
goods.CreateAt = createAt.(time.Time)
good.CreateAt = createAt.(time.Time)
}
if updateAt, ok := data["updateAt"]; ok {
goods.UpdateAt = updateAt.(time.Time)
good.UpdateAt = updateAt.(time.Time)
}
if deleteAt, ok := data["deleteAt"]; ok {
goods.DeleteAt = deleteAt.(time.Time)
good.DeleteAt = deleteAt.(time.Time)
}
return nil
}
... ...
... ... @@ -14,11 +14,13 @@ const (
// 订单状态
const (
ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
ORDER_STATUS_TRANSIT // 待收货(运输中)
ORDER_STATUS_SHIPPING // 已发货
ORDER_STATUS_PART_SHIPPING // 部分发货
ORDER_STATUS_RECEIVED // 已收货
ORDER_STATUS_RETURN // 退换货
ORDER_STATUS_CANCELED // 已取消(关闭)
ORDER_STATUS_CANCELED // 已取消
ORDER_STATUS_COMPLETED // 已完成
ORDER_STATUS_CLOSED // 已关闭
)
// 订单实体
... ... @@ -33,8 +35,10 @@ type Order struct {
PartnerId int64 `json:"partnerId"`
// 发货单号
DeliveryCode string `json:"deliveryCode"`
// 发货时间
DeliveryTime time.Time `json:"deliveryTime"`
// 是否关闭订单标志
IsDisable int `json:"isDisable"`
IsDisable bool `json:"isDisable"`
// 订单编号
OrderNo string `json:"orderNo"`
// 订单详情
... ... @@ -44,7 +48,7 @@ type Order struct {
// 订单分红支付状态
OrderDividendStatus int `json:"orderDividendStatus"`
// 订单货品
OrderGoods []*Goods `json:"orderGoods"`
OrderGoods []*Good `json:"orderGoods"`
// 订单数据来源
OrderSource *OrderSource `json:"orderSource"`
// 订单类型(1.实际订单;2.意向订单)
... ... @@ -70,13 +74,14 @@ type Order struct {
// 订单状态机
type OrderStatus interface {
Update(order *Order, data map[string]interface{}) error // 更新订单
Checkout(order *Order) error // 下单
Shipping(order *Order) error // 发货(全部发货,部分发货)
Return(order *Order) error // 退换货
Cancel(order *Order) error // 取消订单
Receive(order *Order) error // 收货
Close(order *Order) error // 关闭订单
}
// 发货状态
// 发货状态
type UnShippedStatus struct{}
// 编辑待发货订单
... ... @@ -103,7 +108,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
order.DeliveryCode = deliveryCode.(string)
}
if isDisable, ok := data["isDisable"]; ok {
order.IsDisable = isDisable.(int)
order.IsDisable = isDisable.(bool)
}
if orderNo, ok := data["orderNo"]; ok {
order.OrderNo = orderNo.(string)
... ... @@ -157,7 +162,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
order.OrderDividendStatus = orderDividendStatus.(int)
}
if orderGoods, ok := data["orderGoods"]; ok {
order.OrderGoods = orderGoods.([]*Goods)
order.OrderGoods = orderGoods.([]*Good)
}
if dataSourceId, ok := data["dataSourceId"]; ok {
order.OrderSource.DataSourceId = dataSourceId.(int64)
... ... @@ -183,150 +188,283 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
if remarks, ok := data["remarks"]; ok {
order.Remarks = remarks.(string)
}
if createAt, ok := data["createAt"]; ok {
order.CreateAt = createAt.(time.Time)
}
if updateAt, ok := data["updateAt"]; ok {
order.UpdateAt = updateAt.(time.Time)
}
if deleteAt, ok := data["deleteAt"]; ok {
order.DeleteAt = deleteAt.(time.Time)
}
order.UpdateAt = time.Now()
order.ComputeDividend()
return nil
}
func (status *UnShippedStatus) Checkout(order *Order) error {
// 发货
func (status *UnShippedStatus) Shipping(order *Order) error {
currentTime := time.Now()
order.DeliveryTime = currentTime
if order.OrderType == ORDER_TYPE_INTENTION {
order.OrderStatus = ORDER_STATUS_SHIPPING
order.CurrentStatus = &TransitStatus{}
}
return nil
}
// 待发货订单不能退货
func (status *UnShippedStatus) Return(order *Order) error {
return fmt.Errorf("待发货订单不能退货")
}
// 取消订单
func (status *UnShippedStatus) Cancel(order *Order) error {
order.CurrentStatus = &CanceledStatus{}
return nil
}
// 待发货订单不能收货
func (status *UnShippedStatus) Receive(order *Order) error {
return fmt.Errorf("待发货订单不能收货")
}
// 待收货订单不能关闭
func (status *UnShippedStatus) Close(order *Order) error {
return fmt.Errorf("待收货订单不能关闭")
}
// 待收货状态
type TransitStatus struct{}
// 待收货订单不能再次发货
func (status *TransitStatus) Shipping(order *Order) error {
return fmt.Errorf("待收货订单不能重复发货")
}
// 待收货订单不允许编辑
func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已发货订单不允许编辑")
}
func (status *TransitStatus) Checkout(order *Order) error {
return fmt.Errorf("待收货订单不能重复发货")
}
// 退货
func (status *TransitStatus) Return(order *Order) error {
order.CurrentStatus = &ReturnedStatus{}
return nil
}
// 待收货订单不能取消
func (status *TransitStatus) Cancel(order *Order) error {
return fmt.Errorf("待收货订单不能取消")
}
// 收货
func (status *TransitStatus) Receive(order *Order) error {
order.CurrentStatus = &ReceivedStatus{}
return nil
}
// 待收货订单不能关闭
func (status *TransitStatus) Close(order *Order) error {
return fmt.Errorf("待收货订单不能关闭")
}
// 收货状态
type ReceivedStatus struct{}
// 已收货订单不能编辑
func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已收货订单不能编辑")
}
func (status *ReceivedStatus) Checkout(order *Order) error {
return fmt.Errorf("已收货订单不能重复发货")
// 已收货订单不能再次收货
func (status *ReceivedStatus) Shipping(order *Order) error {
return fmt.Errorf("已收货订单不能再次发货")
}
// 退货
func (status *ReceivedStatus) Return(order *Order) error {
order.CurrentStatus = &ReturnedStatus{}
return nil
}
// 已取消订单不能再次取消
func (status *ReceivedStatus) Cancel(order *Order) error {
return fmt.Errorf("已收货订单不能取消")
}
// 已收货订单不能重复收货
func (status *ReceivedStatus) Receive(order *Order) error {
return fmt.Errorf("已收货订单不能重复收货")
}
// 关闭订单
func (status *ReceivedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
// 退货状态
type ReturnedStatus struct{}
// 已退货订单不能编辑
func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已退货订单不允许编辑")
}
func (status *ReturnedStatus) Checkout(order *Order) error {
return fmt.Errorf("已退货订单不允许发货")
// 已收货订单不能再次收货
func (status *ReturnedStatus) Shipping(order *Order) error {
return fmt.Errorf("已收货订单不能再次发货")
}
// 已退货订单不能再次发货
func (status *ReturnedStatus) Return(order *Order) error {
return fmt.Errorf("已退货订单不允许再次退货")
}
// 已退货订单不能取消
func (status *ReturnedStatus) Cancel(order *Order) error {
return fmt.Errorf("已退货订单不能取消")
}
// 已退货订单不能重复守护
func (status *ReturnedStatus) Receive(order *Order) error {
return fmt.Errorf("已退货订单不能收货")
}
// 关闭已退货订单
func (status *ReturnedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
// 取消状态
type CanceledStatus struct{}
// 已取消订单不能编辑
func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error {
return fmt.Errorf("已取消订单不能编辑")
}
func (status *CanceledStatus) Checkout(order *Order) error {
return fmt.Errorf("已取消订单不能发货")
// 已取消订单不能发货
func (status *CanceledStatus) Shipping(order *Order) error {
return fmt.Errorf("已取消订单不能再次发货")
}
// 已取消的订单不能退货
func (status *CanceledStatus) Return(order *Order) error {
return fmt.Errorf("已取消订单不能退货")
}
// 已取消定案不能再次取消
func (status *CanceledStatus) Cancel(order *Order) error {
return fmt.Errorf("已取消订单不能再次取消")
}
// 已取消订单不能收货
func (status *CanceledStatus) Receive(order *Order) error {
return fmt.Errorf("已取消订单不能进行收货")
}
// 关闭订单
func (status *CanceledStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
// 已完成状态
type CompletedStatus struct{}
// 编辑已完成订单分红
func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error {
if planBonus, ok := data["planBonus"]; ok {
order.OrderDividend.PlanBonus = planBonus.(float64)
}
if useBonus, ok := data["useBonus"]; ok {
order.OrderDividend.UseBonus = useBonus.(float64)
}
if bonusHas, ok := data["bonusHas"]; ok {
order.OrderDividend.BonusHas = bonusHas.(float64)
}
if bonusNot, ok := data["bonusNot"]; ok {
order.OrderDividend.BonusNot = bonusNot.(float64)
}
if bonusExpense, ok := data["bonusExpense"]; ok {
order.OrderDividend.BonusExpense = bonusExpense.(float64)
}
if bonusStatus, ok := data["bonusStatus"]; ok {
order.OrderDividend.BonusStatus = bonusStatus.(int)
}
if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
order.OrderDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
}
if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
order.OrderDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
}
if salesmanBonus, ok := data["salesmanBonus"]; ok {
order.OrderDividend.SalesmanBonus = salesmanBonus.(float64)
}
if orderDividendStatus, ok := data["orderDividendStatus"]; ok {
order.OrderDividendStatus = orderDividendStatus.(int)
}
return nil
}
func (status *CompletedStatus) Checkout(order *Order) error {
// 已完成的订单不能再次发货
func (status *CompletedStatus) Shipping(order *Order) error {
return fmt.Errorf("已完成订单不能发货")
}
// 已完成订单不能退货
func (status *CompletedStatus) Return(order *Order) error {
return fmt.Errorf("已完成订单不能退货")
}
// 已完成订单不能取消
func (status *CompletedStatus) Cancel(order *Order) error {
return fmt.Errorf("已完成订单不能取消")
}
// 已完成订单不能收货
func (status *CompletedStatus) Receive(order *Order) error {
return fmt.Errorf("已完成订单不能收货")
}
// 关闭已完成订单
func (status *CompletedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
// 关闭状态
type ClosedStatus struct{}
// 已关闭订单不能进行编辑
func (status *ClosedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已关闭订单不能进行编辑")
}
// 已关闭订单不能发货
func (status *ClosedStatus) Shipping(order *Order) error {
return fmt.Errorf("已关闭订单不能发货")
}
// 已关闭订单不能退货
func (status *ClosedStatus) Return(order *Order) error {
return fmt.Errorf("已关闭订单不能退货")
}
// 已关闭订单不能取消
func (status *ClosedStatus) Cancel(order *Order) error {
return fmt.Errorf("已关闭订单不能取消")
}
// 已关闭订单不能收货
func (status *ClosedStatus) Receive(order *Order) error {
return fmt.Errorf("已关闭订单不能收货")
}
// 已关闭订单不能再次关闭
func (status *ClosedStatus) Close(order *Order) error {
return fmt.Errorf("已关闭订单不能再次关闭")
}
// 订单仓储
type OrderRepository interface {
Save(order *Order) (*Order, error)
... ... @@ -348,8 +486,8 @@ func (order *Order) Update(data map[string]interface{}) error {
}
// 发货
func (order *Order) Checkout() error {
return order.CurrentStatus.Checkout(order)
func (order *Order) Shipping() error {
return order.CurrentStatus.Shipping(order)
}
// 退货
... ... @@ -366,3 +504,75 @@ func (order *Order) Receive() error {
func (order *Order) Cancel() error {
return order.CurrentStatus.Cancel(order)
}
// 关闭订单
func (order *Order) Close() error {
return order.CurrentStatus.Close(order)
}
func (order *Order) RefreshOrderDetail() {
}
func (order *Order) ComputeDividend() {
order.computeGoodsDividend()
order.computeOrderDividend()
}
func (order *Order) computeOrderDividend() {
var totalPlanBonus float64
// 调整后分红
var totalUseBonus float64
// 已收分红
var totalBonusHas float64
// 未收分红
var totalBonusNot float64
// 分红支出
var totalBonusExpense float64
for _, v := range order.OrderGoods {
totalPlanBonus += v.GoodDividend.PlanBonus
totalUseBonus += v.GoodDividend.UseBonus
totalBonusHas += v.GoodDividend.BonusHas
totalBonusNot += v.GoodDividend.BonusNot
totalBonusExpense += v.GoodDividend.BonusExpense
}
order.OrderDividend.PlanBonus = totalPlanBonus
order.OrderDividend.UseBonus = totalUseBonus
order.OrderDividend.BonusHas = totalBonusHas
order.OrderDividend.BonusNot = totalBonusNot
order.OrderDividend.BonusExpense = totalBonusExpense
}
func (order *Order) computeGoodsDividend() {
for i := range order.OrderGoods {
good := order.OrderGoods[i]
bonus := good.GoodTotalPrice * float64(good.GoodNum) * (order.OrderDividend.PartnerBonusPercent / 100)
if good.GoodDividend == nil {
good.GoodDividend = &Dividend{
PlanBonus: bonus,
UseBonus: -1,
BonusHas: 0,
BonusNot: bonus,
BonusExpense: 0,
BonusStatus: Dividend_Unpaid,
}
} else {
/* 计算预计分红、调整后分红 */
if bonus != good.GoodDividend.PlanBonus {
if order.OrderStatus == ORDER_STATUS_UNSHIPPED {
good.GoodDividend.PlanBonus = bonus
good.GoodDividend.BonusNot = bonus
} else {
expense := good.GoodDividend.PlanBonus - bonus
if expense <= 0 {
expense = 0
}
good.GoodDividend.UseBonus = bonus
good.GoodDividend.BonusNot = bonus
good.GoodDividend.BonusExpense = expense
}
}
/*计算未支付分红*/
if good.GoodDividend.BonusHas > 0 {
good.GoodDividend.BonusNot = good.GoodDividend.PlanBonus - good.GoodDividend.BonusHas
}
}
}
}
... ...
... ... @@ -15,7 +15,7 @@ type PartnerInfo struct {
// 合伙时间
CooperateTime time.Time `json:"cooperateTime"`
// 业务员
Salesmans []*Salesman `json:"salesmans"`
Salesmen []*Salesman `json:"salesmen"`
// 合伙人类型
PartnerCategorys []*PartnerCategory `json:"partnerCategorys"`
PartnerCategories []*PartnerCategory `json:"partnerCategories"`
}
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
)
type CreateOrderService interface {
coreDomain.DomainEventPublisher
Create(newOrder *domain.Order) (*domain.Order, error)
}
... ...
... ... @@ -141,10 +141,10 @@ func CheckPartnerUserType(dm *User) (*User, error) {
if dm.PartnerInfo.PartnerName == "" {
return nil, fmt.Errorf("合伙人姓名不能为空")
}
if len(dm.PartnerInfo.PartnerCategorys) == 0 {
if len(dm.PartnerInfo.PartnerCategories) == 0 {
return nil, fmt.Errorf("合伙人类别不能为空")
}
if len(dm.PartnerInfo.Salesmans) == 0 {
if len(dm.PartnerInfo.Salesmen) == 0 {
return nil, fmt.Errorf("合伙人查看合伙人账号不能为空")
}
return dm, nil
... ...
... ... @@ -2,8 +2,10 @@ package domainService
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
... ... @@ -14,6 +16,24 @@ type CancelOrderService struct {
}
func (service *CancelOrderService) Cancel(orderId int64) (*domain.Order, error) {
var orderRepository domain.OrderRepository
if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
if err != nil {
return nil, err
}
if err := order.Cancel(); err != nil {
return nil, err
}
if order, err := orderRepository.Save(order); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
return order, nil
}
return nil, nil
}
... ...
package domainService
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
)
type CreateOrderService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *CreateOrderService) Create(newOrder *domain.Order) (*domain.Order, error) {
var orderRepository domain.OrderRepository
if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
if err := newOrder.Update(nil); err != nil {
return nil, err
}
if order, err := orderRepository.Save(newOrder); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
return order, nil
}
return nil, nil
}
func NewCreateOrderService(transactionContext *pgTransaction.TransactionContext) (*CreateOrderService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CreateOrderService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -2,8 +2,10 @@ package domainService
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
... ... @@ -14,6 +16,24 @@ type ReceivingGoodsService struct {
}
func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) {
var orderRepository domain.OrderRepository
if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
if err != nil {
return nil, err
}
if err := order.Receive(); err != nil {
return nil, err
}
if order, err := orderRepository.Save(order); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
return order, nil
}
return nil, nil
}
... ...
... ... @@ -2,8 +2,10 @@ package domainService
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
... ... @@ -14,7 +16,25 @@ type ReturnGoodsService struct {
}
func (service *ReturnGoodsService) Return(orderId int64) (*domain.Order, error) {
panic("implement me")
var orderRepository domain.OrderRepository
if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
if err != nil {
return nil, err
}
if err := order.Return(); err != nil {
return nil, err
}
if order, err := orderRepository.Save(order); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
return order, nil
}
return nil, nil
}
func NewReturnGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReturnGoodsService, error) {
... ...
... ... @@ -2,8 +2,10 @@ package domainService
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
... ... @@ -14,6 +16,24 @@ type ShippingGoodsService struct {
}
func (service *ShippingGoodsService) Shipping(orderId int64) (*domain.Order, error) {
var orderRepository domain.OrderRepository
if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err := orderRepository.FindOne(map[string]interface{}{"orderId": orderId})
if err != nil {
return nil, err
}
if err := order.Shipping(); err != nil {
return nil, err
}
if order, err := orderRepository.Save(order); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
return order, nil
}
return nil, nil
}
... ...
... ... @@ -29,7 +29,7 @@ func init() {
&models.Permission{},
&models.PartnerCategory{},
&models.UserAuth{},
&models.Goods{},
&models.Good{},
&models.Order{},
&models.User{},
&models.Company{},
... ...
... ... @@ -5,30 +5,30 @@ import (
"time"
)
type Goods struct {
tableName string `pg:"goodss,alias:goods"`
type Good struct {
tableName string `pg:"goods,alias:good"`
// 商品id
GoodsId int64
GoodId int64 `pg:",pk"`
// 预定的货品数量
GoodsNum int
GoodNum int
// 商品分红支付信息
GoodsDividend *domain.Dividend
GoodDividend *domain.Dividend
// 商品分红支付状态
GoodsDividendStatus int
GoodDividendStatus int
// 商品名称
GoodsName string
GoodName string
// 商品单价
GoodsTotalPrice float64
GoodTotalPrice float64
// 备注
Remarks string
// 订单编号
OrderNo string
// 商品详情
GoodsDetail string
GoodDetail string
// 创建时间
CreateAt time.Time
// 更新时间
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
DeleteAt time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -6,9 +6,9 @@ import (
)
type Order struct {
tableName string `pg:"orders,alias:order"`
tableName string `pg:"orders,alias:orders"`
// 订单id
OrderId int64
OrderId int64 `pg:",pk"`
// 买家信息
Buyer *domain.BuyerInfo
// 公司Id
... ... @@ -18,7 +18,7 @@ type Order struct {
// 发货单号
DeliveryCode string
// 是否关闭订单标志
IsDisable int
IsDisable bool
// 订单编号
OrderNo string
// 订单详情
... ... @@ -28,7 +28,7 @@ type Order struct {
// 订单分红支付状态
OrderDividendStatus int
// 订单货品
OrderGoods []*domain.Goods
OrderGoods []*domain.Good
// 订单数据来源
OrderSource *domain.OrderSource
// 订单类型(1.实际订单;2.意向订单)
... ... @@ -46,5 +46,5 @@ type Order struct {
// 更新时间
UpdateAt time.Time
// 软删
DeleteAt time.Time
DeleteAt time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -32,5 +32,5 @@ type User struct {
// 更新时间
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
DeleteAt time.Time `pg:",soft_delete"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
)
func TransformToGoodDomainModelFromPgModels(goodModel *models.Good) (*domain.Good, error) {
return &domain.Good{
GoodId: goodModel.GoodId,
GoodNum: goodModel.GoodNum,
GoodDividend: goodModel.GoodDividend,
GoodDividendStatus: goodModel.GoodDividendStatus,
GoodName: goodModel.GoodName,
GoodTotalPrice: goodModel.GoodTotalPrice,
Remarks: goodModel.Remarks,
OrderNo: goodModel.OrderNo,
GoodDetail: goodModel.GoodDetail,
CreateAt: goodModel.CreateAt,
UpdateAt: goodModel.UpdateAt,
DeleteAt: goodModel.DeleteAt,
}, nil
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
)
func TransformToGoodsDomainModelFromPgModels(goodsModel *models.Goods) (*domain.Goods, error) {
return &domain.Goods{
GoodsId: goodsModel.GoodsId,
GoodsNum: goodsModel.GoodsNum,
GoodsDividend: goodsModel.GoodsDividend,
GoodsDividendStatus: goodsModel.GoodsDividendStatus,
GoodsName: goodsModel.GoodsName,
GoodsTotalPrice: goodsModel.GoodsTotalPrice,
Remarks: goodsModel.Remarks,
OrderNo: goodsModel.OrderNo,
GoodsDetail: goodsModel.GoodsDetail,
CreateAt: goodsModel.CreateAt,
UpdateAt: goodsModel.UpdateAt,
DeleteAt: goodsModel.DeleteAt,
}, nil
}
... ... @@ -6,6 +6,15 @@ import (
)
func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.Order, error) {
var currentStatus domain.OrderStatus
switch orderModel.OrderStatus {
case domain.ORDER_STATUS_UNSHIPPED:
currentStatus = &domain.UnShippedStatus{}
case domain.ORDER_STATUS_SHIPPING:
currentStatus = &domain.TransitStatus{}
default:
currentStatus = &domain.UnShippedStatus{}
}
return &domain.Order{
OrderId: orderModel.OrderId,
Buyer: orderModel.Buyer,
... ... @@ -27,5 +36,6 @@ func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.
CreateAt: orderModel.CreateAt,
UpdateAt: orderModel.UpdateAt,
DeleteAt: orderModel.DeleteAt,
CurrentStatus: currentStatus,
}, nil
}
... ...
... ... @@ -12,11 +12,11 @@ import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/transform"
)
type GoodsRepository struct {
type GoodRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *GoodsRepository) nextIdentify() (int64, error) {
func (repository *GoodRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
... ... @@ -24,17 +24,17 @@ func (repository *GoodsRepository) nextIdentify() (int64, error) {
id, err := IdWorker.NextId()
return id, err
}
func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, error) {
func (repository *GoodRepository) Save(good *domain.Good) (*domain.Good, error) {
sqlBuildFields := []string{
"goods_id",
"goods_num",
"goods_dividend",
"goods_dividend_status",
"goods_name",
"goods_total_price",
"good_id",
"good_num",
"good_dividend",
"good_dividend_status",
"good_name",
"good_total_price",
"remarks",
"order_no",
"goods_detail",
"good_detail",
"create_at",
"update_at",
"delete_at",
... ... @@ -45,94 +45,94 @@ func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, err
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "goods_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if goods.Identify() == nil {
goodsId, err := repository.nextIdentify()
if good.Identify() == nil {
goodId, err := repository.nextIdentify()
if err != nil {
return goods, err
return good, err
} else {
goods.GoodsId = goodsId
good.GoodId = goodId
}
if _, err := tx.QueryOne(
pg.Scan(
&goods.GoodsId,
&goods.GoodsNum,
&goods.GoodsDividend,
&goods.GoodsDividendStatus,
&goods.GoodsName,
&goods.GoodsTotalPrice,
&goods.Remarks,
&goods.OrderNo,
&goods.GoodsDetail,
&goods.CreateAt,
&goods.UpdateAt,
&goods.DeleteAt,
&good.GoodId,
&good.GoodNum,
&good.GoodDividend,
&good.GoodDividendStatus,
&good.GoodName,
&good.GoodTotalPrice,
&good.Remarks,
&good.OrderNo,
&good.GoodDetail,
&good.CreateAt,
&good.UpdateAt,
&good.DeleteAt,
),
fmt.Sprintf("INSERT INTO goodss (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
goods.GoodsId,
goods.GoodsNum,
goods.GoodsDividend,
goods.GoodsDividendStatus,
goods.GoodsName,
goods.GoodsTotalPrice,
goods.Remarks,
goods.OrderNo,
goods.GoodsDetail,
goods.CreateAt,
goods.UpdateAt,
goods.DeleteAt,
fmt.Sprintf("INSERT INTO good (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
good.GoodId,
good.GoodNum,
good.GoodDividend,
good.GoodDividendStatus,
good.GoodName,
good.GoodTotalPrice,
good.Remarks,
good.OrderNo,
good.GoodDetail,
good.CreateAt,
good.UpdateAt,
good.DeleteAt,
); err != nil {
return goods, err
return good, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&goods.GoodsId,
&goods.GoodsNum,
&goods.GoodsDividend,
&goods.GoodsDividendStatus,
&goods.GoodsName,
&goods.GoodsTotalPrice,
&goods.Remarks,
&goods.OrderNo,
&goods.GoodsDetail,
&goods.CreateAt,
&goods.UpdateAt,
&goods.DeleteAt,
&good.GoodId,
&good.GoodNum,
&good.GoodDividend,
&good.GoodDividendStatus,
&good.GoodName,
&good.GoodTotalPrice,
&good.Remarks,
&good.OrderNo,
&good.GoodDetail,
&good.CreateAt,
&good.UpdateAt,
&good.DeleteAt,
),
fmt.Sprintf("UPDATE goodss SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
goods.GoodsId,
goods.GoodsNum,
goods.GoodsDividend,
goods.GoodsDividendStatus,
goods.GoodsName,
goods.GoodsTotalPrice,
goods.Remarks,
goods.OrderNo,
goods.GoodsDetail,
goods.CreateAt,
goods.UpdateAt,
goods.DeleteAt,
goods.Identify(),
fmt.Sprintf("UPDATE good SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
good.GoodId,
good.GoodNum,
good.GoodDividend,
good.GoodDividendStatus,
good.GoodName,
good.GoodTotalPrice,
good.Remarks,
good.OrderNo,
good.GoodDetail,
good.CreateAt,
good.UpdateAt,
good.DeleteAt,
good.Identify(),
); err != nil {
return goods, err
return good, err
}
}
return goods, nil
return good, nil
}
func (repository *GoodsRepository) Remove(goods *domain.Goods) (*domain.Goods, error) {
func (repository *GoodRepository) Remove(good *domain.Good) (*domain.Good, error) {
tx := repository.transactionContext.PgTx
goodsModel := new(models.Goods)
goodsModel.GoodsId = goods.Identify().(int64)
if _, err := tx.Model(goodsModel).WherePK().Delete(); err != nil {
return goods, err
goodModel := new(models.Good)
goodModel.GoodId = good.Identify().(int64)
if _, err := tx.Model(goodModel).WherePK().Delete(); err != nil {
return good, err
}
return goods, nil
return good, nil
}
func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) (*domain.Goods, error) {
func (repository *GoodRepository) FindOne(queryOptions map[string]interface{}) (*domain.Good, error) {
tx := repository.transactionContext.PgTx
goodsModel := new(models.Goods)
query := sqlbuilder.BuildQuery(tx.Model(goodsModel), queryOptions)
query.SetWhereByQueryOption("goods.goods_id = ?", "goodsId")
goodModel := new(models.Good)
query := sqlbuilder.BuildQuery(tx.Model(goodModel), queryOptions)
query.SetWhereByQueryOption("good.goods_id = ?", "goodsId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ... @@ -140,37 +140,37 @@ func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{})
return nil, err
}
}
if goodsModel.GoodsId == 0 {
if goodModel.GoodId == 0 {
return nil, nil
} else {
return transform.TransformToGoodsDomainModelFromPgModels(goodsModel)
return transform.TransformToGoodDomainModelFromPgModels(goodModel)
}
}
func (repository *GoodsRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Goods, error) {
func (repository *GoodRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Good, error) {
tx := repository.transactionContext.PgTx
var goodsModels []*models.Goods
goodss := make([]*domain.Goods, 0)
query := sqlbuilder.BuildQuery(tx.Model(&goodsModels), queryOptions)
var goodModels []*models.Good
goods := make([]*domain.Good, 0)
query := sqlbuilder.BuildQuery(tx.Model(&goodModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("goods_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, goodss, err
return 0, goods, err
} else {
for _, goodsModel := range goodsModels {
if goods, err := transform.TransformToGoodsDomainModelFromPgModels(goodsModel); err != nil {
return 0, goodss, err
for _, goodModel := range goodModels {
if good, err := transform.TransformToGoodDomainModelFromPgModels(goodModel); err != nil {
return 0, goods, err
} else {
goodss = append(goodss, goods)
goods = append(goods, good)
}
}
return int64(count), goodss, nil
return int64(count), goods, nil
}
}
func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodsRepository, error) {
func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &GoodsRepository{
return &GoodRepository{
transactionContext: transactionContext,
}, nil
}
... ...
... ... @@ -72,7 +72,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
&order.OrderDetail,
&order.OrderDividend,
&order.OrderDividendStatus,
pg.Array(&order.OrderGoods),
&order.OrderGoods,
&order.OrderSource,
&order.OrderType,
&order.OrderStatus,
... ... @@ -94,7 +94,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
order.OrderDetail,
order.OrderDividend,
order.OrderDividendStatus,
pg.Array(order.OrderGoods),
order.OrderGoods,
order.OrderSource,
order.OrderType,
order.OrderStatus,
... ... @@ -120,7 +120,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
&order.OrderDetail,
&order.OrderDividend,
&order.OrderDividendStatus,
pg.Array(&order.OrderGoods),
&order.OrderGoods,
&order.OrderSource,
&order.OrderType,
&order.OrderStatus,
... ... @@ -132,7 +132,6 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
&order.DeleteAt,
),
fmt.Sprintf("UPDATE orders SET %s WHERE order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
order.OrderId,
order.Buyer,
order.CompanyId,
order.PartnerId,
... ... @@ -142,7 +141,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err
order.OrderDetail,
order.OrderDividend,
order.OrderDividendStatus,
pg.Array(order.OrderGoods),
order.OrderGoods,
order.OrderSource,
order.OrderType,
order.OrderStatus,
... ... @@ -172,7 +171,7 @@ func (repository *OrderRepository) FindOne(queryOptions map[string]interface{})
tx := repository.transactionContext.PgTx
orderModel := new(models.Order)
query := sqlbuilder.BuildQuery(tx.Model(orderModel), queryOptions)
query.SetWhereByQueryOption("order.order_id = ?", "orderId")
query.SetWhereByQueryOption("orders.order_id = ?", "orderId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...
... ... @@ -14,7 +14,7 @@ type OrderController struct {
func (controller *OrderController) CreateOrder() {
orderService := service.NewOrderService(nil)
createOrderCommand := &command.CreateOrderCommand{}
controller.Unmarshal(createOrderCommand)
_ = controller.Unmarshal(createOrderCommand)
data, err := orderService.CreateOrder(createOrderCommand)
controller.Response(data, err)
}
... ...
package order
import (
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = FDescribe("创建订单增删改查", func() {
var _ = Describe("创建订单增删改查", func() {
Describe("提交数据创建订单增删改查", func() {
Context("提交正确的新订单实体数据", func() {
It("返回订单实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
orderGoods := []map[string]interface{}{
{"goodNum": 10, "goodName": "banana", "goodTotalPrice": 3.5, "remarks": "单位:斤"},
{"goodNum": 20, "goodName": "apple", "goodTotalPrice": 5.5, "remarks": "单位:斤"},
}
body := map[string]interface{}{
"orderNo": "string",
"companyId": "int64",
"companyId": 1,
"buyerName": "string",
"contactInfo": "string",
"shippingAddress": "string",
"orderNum": "int64",
"totalPrice": "float64",
"orderNum": 10,
"totalPrice": 10,
"partnerId": "1213",
"partnerBonusPercent": 15,
"orderGoods": orderGoods,
}
httpExpect.POST("/orders/").
WithJSON(body).
... ...
... ... @@ -13,17 +13,18 @@ import (
var _ = Describe("返回订单增删改查", func() {
var orderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
// 新增订单测试数据
_, err2 := pG.DB.QueryOne(
pg.Scan(&orderId),
"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",
"testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
"INSERT INTO orders (order_id) VALUES (?) RETURNING order_id",
1)
Expect(err2).NotTo(HaveOccurred())
})
Describe("根据orderId参数返回订单实体", func() {
Context("传入有效的orderId", func() {
It("返回订单实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/orders/{orderId}").
httpExpect.GET("/orders/1").
Expect().
Status(http.StatusOK).
JSON().
... ...
... ... @@ -13,19 +13,20 @@ import (
var _ = Describe("返回订单增删改查列表", func() {
var orderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
// 新增订单测试数据
_, err2 := pG.DB.QueryOne(
pg.Scan(&orderId),
"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",
"testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
"INSERT INTO orders (order_id) VALUES (?) RETURNING order_id",
1)
Expect(err2).NotTo(HaveOccurred())
})
Describe("根据参数返回订单实体列表", func() {
Context("传入有效的参数", func() {
It("返回订单实体数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/orders/").
WithQuery("offset", "int").
WithQuery("limit", "int").
WithQuery("offset", 0).
WithQuery("limit", 10).
Expect().
Status(http.StatusOK).
JSON().
... ...
... ... @@ -13,24 +13,24 @@ import (
var _ = Describe("移除订单增删改查", func() {
var orderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
// 新增订单测试数据
_, err2 := pG.DB.QueryOne(
pg.Scan(&orderId),
"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",
"testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
"INSERT INTO orders (order_id) VALUES (?) RETURNING order_id",
1)
Expect(err2).NotTo(HaveOccurred())
})
Describe("根据参数移除订单增删改查", func() {
Context("传入有效的orderId", func() {
It("返回被移除订单实体的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/orders/{orderId}").
httpExpect.DELETE("/orders/1").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
ContainsKey("msg").ValueEqual("msg", "ok")
})
})
})
... ...
... ... @@ -13,18 +13,21 @@ import (
var _ = Describe("更新订单增删改查", func() {
var orderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
// 新增订单测试数据
_, err2 := pG.DB.QueryOne(
pg.Scan(&orderId),
"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",
"testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
"INSERT INTO orders (order_id,company_id,partner_id,buyer,order_dividend,order_detail) VALUES (?,?,?,?,?,?) RETURNING order_id",
1, 1, 1, "{}", "{}", "{}")
Expect(err2).NotTo(HaveOccurred())
})
Describe("提交数据更新订单增删改查", func() {
Context("提交正确的订单实体数据", func() {
It("返回更新后的订单实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{}
httpExpect.PUT("/orders/{orderId}").
body := map[string]interface{}{
"shippingAddress": "fuzhou",
}
httpExpect.PUT("/orders/1").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ...