作者 唐旭辉

日常保存

1 package subscriber 1 package subscriber
2 2
3 import ( 3 import (
  4 + "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/event"
4 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
5 ) 7 )
6 8
@@ -9,6 +11,24 @@ type OrderLogSubscriber struct { @@ -9,6 +11,24 @@ type OrderLogSubscriber struct {
9 transactionContext *transaction.TransactionContext 11 transactionContext *transaction.TransactionContext
10 } 12 }
11 13
12 -func (subscriber OrderLogSubscriber) AddLog() error { 14 +var _ domain.DomainEventSubscriber = (*OrderLogSubscriber)(nil)
  15 +
  16 +func (subscriber *OrderLogSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
  17 + switch domainEvent.EventType() {
  18 + case event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT:
  19 +
  20 + case event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT:
  21 + case event.UPDATE_ORDER_REMARK:
  22 + case event.PAY_ORDER_GOOD_BONUS_EVENT:
  23 + }
13 return nil 24 return nil
14 } 25 }
  26 +
  27 +func (subscriber *OrderLogSubscriber) SubscribedToEventTypes() []string {
  28 + return []string{
  29 + event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT,
  30 + event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT,
  31 + event.UPDATE_ORDER_REMARK,
  32 + event.PAY_ORDER_GOOD_BONUS_EVENT,
  33 + }
  34 +}
1 package command 1 package command
2 2
  3 +//创建订单
3 type CreateOrderCommand struct { 4 type CreateOrderCommand struct {
4 //订单类型 5 //订单类型
5 OrderType int `json:"orderType"` 6 OrderType int `json:"orderType"`
@@ -2,6 +2,7 @@ package command @@ -2,6 +2,7 @@ package command
2 2
3 import "time" 3 import "time"
4 4
  5 +//订单发货
5 type OrderDeliveryCommand struct { 6 type OrderDeliveryCommand struct {
6 OrderId int64 `json:"orderId"` 7 OrderId int64 `json:"orderId"`
7 DeliveryTime time.Time `json:"deliveryTime"` 8 DeliveryTime time.Time `json:"deliveryTime"`
1 package command 1 package command
2 2
3 -//更新订单的商品数字并更新分红的数据 3 +//UpdateGoodBouns 更新订单的商品数量,和支付状态 并更新分红的数据
4 type UpdateGoodBouns struct { 4 type UpdateGoodBouns struct {
5 Id int64 `json:"id"` //订单id 5 Id int64 `json:"id"` //订单id
6 GoodBouns []GoodBouns `json:"goodBouns"` 6 GoodBouns []GoodBouns `json:"goodBouns"`
1 package command 1 package command
2 2
3 -//UpdateOrderPurposeCommand 更新意向 3 +//UpdateOrderPurposeCommand 更新订单
4 type UpdateOrderCommand struct { 4 type UpdateOrderCommand struct {
5 Id int64 `json:"id"` 5 Id int64 `json:"id"`
6 //订单编号 6 //订单编号
@@ -615,7 +615,7 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) @@ -615,7 +615,7 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand)
615 return nil 615 return nil
616 } 616 }
617 617
618 -//UpdateGoodBouns 更新货品的分红相关的数值 618 +//UpdateGoodBouns 分红时,更新货品的分红相关的数值
619 func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error { 619 func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {
620 var ( 620 var (
621 transactionContext, _ = factory.CreateTransactionContext(nil) 621 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -690,7 +690,7 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err @@ -690,7 +690,7 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err
690 } 690 }
691 } 691 }
692 oldOrderData.Goods = oldOrderGoods 692 oldOrderData.Goods = oldOrderGoods
693 - //变更订单类型 693 +
694 err = oldOrderData.Compute() 694 err = oldOrderData.Compute()
695 if err != nil { 695 if err != nil {
696 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err)) 696 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
@@ -710,3 +710,43 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err @@ -710,3 +710,43 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err
710 return nil 710 return nil
711 711
712 } 712 }
  713 +
  714 +//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
  715 +func (service OrderInfoService) UpdateBounsByGoodNumber() error {
  716 + var (
  717 + transactionContext, _ = factory.CreateTransactionContext(nil)
  718 + err error
  719 + )
  720 + if err = transactionContext.StartTransaction(); err != nil {
  721 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  722 + }
  723 + defer func() {
  724 + transactionContext.RollbackTransaction()
  725 + }()
  726 + //TODO
  727 + err = transactionContext.CommitTransaction()
  728 + if err != nil {
  729 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  730 + }
  731 + return nil
  732 +}
  733 +
  734 +//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
  735 +func (service OrderInfoService) UpdateBounsByPartnerBonusPercent() error {
  736 + var (
  737 + transactionContext, _ = factory.CreateTransactionContext(nil)
  738 + err error
  739 + )
  740 + if err = transactionContext.StartTransaction(); err != nil {
  741 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  742 + }
  743 + defer func() {
  744 + transactionContext.RollbackTransaction()
  745 + }()
  746 + //TODO
  747 + err = transactionContext.CommitTransaction()
  748 + if err != nil {
  749 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  750 + }
  751 + return nil
  752 +}
  1 +package event
  2 +
  3 +const (
  4 + //订单分红因为货品的数量变动而发送改变
  5 + UPDATE_BONUS_BY_GOOD_NUMBER_EVENT string = "UpdateBonusByGoodNumber"
  6 + //订单分红因为合伙人分红比例变动而发送改变
  7 + UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT string = "UpdateBounsByPartnerBonusPercent"
  8 + //更新订单的备注
  9 + UPDATE_ORDER_REMARK string = "UpdateOrderRemark"
  10 +)
  11 +
  12 +//UpdateBonusByGoodNumber
  13 +//订单分红因为货品的数量变动而发送改变
  14 +type UpdateBonusByGoodNumber struct {
  15 + //订单id
  16 + OrderId int64
  17 + //管理员id
  18 + AdminId int64
  19 + //货品id
  20 + GoodId int64
  21 + //货品名称
  22 + GoodName string
  23 + //旧的货品数量
  24 + FormerNumber string
  25 + //新的货品数量
  26 + NewNumber string
  27 + //旧的货品总额
  28 + FormerAmount string
  29 + //新的货品总额
  30 + NewAmount string
  31 +}
  32 +
  33 +//EventType 事件名称
  34 +func (m UpdateBonusByGoodNumber) EventType() string {
  35 + return UPDATE_BONUS_BY_GOOD_NUMBER_EVENT
  36 +}
  37 +
  38 +//UpdateBounsByPartnerBonusPercent
  39 +//订单分红因为合伙人分红比例变动而发送改变
  40 +type UpdateBounsByPartnerBonusPercent struct {
  41 + //订单id
  42 + OrderId int64
  43 + //管理员id
  44 + AdminId int64
  45 + //货品id
  46 + GoodId int64
  47 + //货品名称
  48 + GoodName string
  49 + //旧的合伙人分红比例
  50 + FormerPartnerBonusPercent string
  51 + //新的合伙人分红比例
  52 + NewPartnerBonusPercent string
  53 + //旧的合伙人分红
  54 + FormerPartnerBonus string
  55 + //新的合伙人分红
  56 + NewPartnerBonus string
  57 +}
  58 +
  59 +//EventType 事件名称
  60 +func (m UpdateBounsByPartnerBonusPercent) EventType() string {
  61 + return UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT
  62 +}
  63 +
  64 +//UpdateOrderRemark 更新订单的备注
  65 +type UpdateOrderRemark struct {
  66 + //订单id
  67 + OrderId int64
  68 + //管理员id
  69 + AdminId int64
  70 + //旧的备注
  71 + FormerRemark string
  72 + //新的备注
  73 + NewRemark string
  74 +}
  75 +
  76 +//EventType 事件名称
  77 +func (m UpdateOrderRemark) EventType() string {
  78 + return UPDATE_ORDER_REMARK
  79 +}
1 package event 1 package event
2 2
3 const ( 3 const (
4 - PAY_ORDER_GOOD_BONUS_EVENT string = "pay-order-good-bonus-event" 4 + PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
5 ) 5 )
6 6
7 -//WxPayOrderGoodBonus  
8 -//事件:支付来自微信小程序的订单中货品的分红 7 +//PayOrderGoodBonus
  8 +//事件:支付订单中货品的分红
9 type PayOrderGoodBonus struct { 9 type PayOrderGoodBonus struct {
10 //订单id 10 //订单id
11 OrderId int64 11 OrderId int64
1 -package event  
2 -  
3 -const (  
4 - ORDER_GOOD_MODIFY_EVENT string = "order-good-modify-event"  
5 -)  
6 -  
7 -type WxOrderGoodModify struct {  
8 - //订单id  
9 - GoodId int64  
10 - //货品名称 [0]旧值,[1]新值  
11 - GoodName [2]string  
12 - //商品数量 [0]旧值,[1]新值  
13 - GoodNumber [2]string  
14 - //合伙人分红比例 [0]旧值,[1]新值  
15 - PartnerBonusPercent [2]string  
16 - //合伙人应收分红 [0]旧值,[1]新值  
17 - PartnerBonus [2]string  
18 - //总价  
19 - Amount [2]string  
20 -}  
21 -  
22 -//OrderModify  
23 -//事件:修改微信小程序的订单数据  
24 -type WxOrderModify struct {  
25 - //订单id  
26 - OrderId int64  
27 - //管理员id  
28 - AdminId int64  
29 - //更改的订单基础数据  
30 - GoodModify []WxOrderGoodModify  
31 - //订单备注 [0]旧值,[1]新值  
32 - Remark [2]string  
33 -}  
34 -  
35 -//EventType 事件名称  
36 -func (m WxOrderModify) EventType() string {  
37 - return ORDER_GOOD_MODIFY_EVENT  
38 -}  
@@ -17,28 +17,29 @@ const ( @@ -17,28 +17,29 @@ const (
17 //OrderLogDescript 描述日志内容 17 //OrderLogDescript 描述日志内容
18 type OrderLogDescript struct { 18 type OrderLogDescript struct {
19 Title string `json:"title"` //标题 19 Title string `json:"title"` //标题
20 - Action string `json:"action"` //执行的动作描述 20 + Item string `json:"item"` //修改的项目
21 Modifyitem []string `json:"modifyItem"` //动作执行结果 21 Modifyitem []string `json:"modifyItem"` //动作执行结果
22 } 22 }
23 23
24 //OrderLogContentItem 记录订单的相关属性值的修改 24 //OrderLogContentItem 记录订单的相关属性值的修改
25 -type OrderLogContentItem struct {  
26 - Table string `json:"table"` //修改的表数据主体,"order_good","order_base"  
27 - TableId string `json:"tableId"` //表id 25 +type OrderLogContent struct {
  26 + OrderId string `json:"orderId"` //订单id
  27 + GoodId string `json:"goodId"` //货品id
28 Title string `json:"title"` //名称标题 28 Title string `json:"title"` //名称标题
29 - Item string `json:"item"` //修改的项目 29 + Item string `json:"item"` //修改的数据字段
30 FormerValue string `json:"formerValue"` //旧值 30 FormerValue string `json:"formerValue"` //旧值
31 NewValue string `json:"newValue"` //新值 31 NewValue string `json:"newValue"` //新值
32 } 32 }
33 33
34 //OrderLog 订单修改记录 34 //OrderLog 订单修改记录
35 type OrderLog struct { 35 type OrderLog struct {
36 - OrderId int64 `json:"order_id"` //订单id  
37 - AlterTime time.Time `json:"alter_time"` //时间  
38 - Operator string `json:"operator"` //操作人员  
39 - OperatorType string `json:"operatorType"` //操作人员的类型  
40 - LogAction string `json:"logAction"` //执行动作  
41 - Descript []OrderLogDescript `json:"descript"` //描述日志内容  
42 - Content []OrderLogContentItem `json:"content"` //记录订单的操作动作  
43 - DataFrom string `json:"dataFrom"` //修改操作的来源:"web_admin" 36 + OrderId int64 `json:"order_id"` //订单id
  37 + AlterTime time.Time `json:"alter_time"` //时间
  38 + Operator string `json:"operator"` //操作人员
  39 + OperatorId int64 `json:"operatorId"` //操作人员Id
  40 + OperatorType string `json:"operatorType"` //操作人员的类型
  41 + LogAction string `json:"logAction"` //执行动作
  42 + Descript []OrderLogDescript `json:"descript"` //描述日志内容
  43 + Content []OrderLogContent `json:"content"` //记录订单的操作动作
  44 + DataFrom string `json:"dataFrom"` //修改操作的来源:"web_admin"
44 } 45 }
  1 +package service
  2 +
  3 +type OrderBonusService interface {
  4 + UpdateBounsByGoodNumber(orderId int64, adminId int64, goodWithNumber map[int64]int) error
  5 + UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodWithPercent map[int]float64) error
  6 + PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error
  7 +}
@@ -11,19 +11,18 @@ import ( @@ -11,19 +11,18 @@ import (
11 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 11 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
12 ) 12 )
13 13
14 -//WxOrderServices 处理来自微信小程序(海鲜干货)的订单  
15 -type WxOrderServices struct { 14 +//OrderBonusServices 处理订单分红的相关操作
  15 +type OrderBonusServices struct {
16 coreDomain.BaseEventPublisher 16 coreDomain.BaseEventPublisher
17 transactionContext *transaction.TransactionContext 17 transactionContext *transaction.TransactionContext
18 } 18 }
19 19
20 -//ModifyOrderGoodData 修改订单中的单个货品的数量  
21 -func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int) error { 20 +//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
  21 +func (serve OrderBonusServices) UpdateBounsByGoodNumber(orderId int64, adminId int64, goodWithNumber map[int64]int) error {
22 var ( 22 var (
23 userRepository domain.UsersRepository 23 userRepository domain.UsersRepository
24 orderBaseReponsitory domain.OrderBaseRepository 24 orderBaseReponsitory domain.OrderBaseRepository
25 orderGoodRepository domain.OrderGoodRepository 25 orderGoodRepository domain.OrderGoodRepository
26 - oldOrderGoods domain.OrderGood  
27 oldOrder *domain.OrderBase 26 oldOrder *domain.OrderBase
28 adminUser domain.Users 27 adminUser domain.Users
29 err error 28 err error
@@ -44,7 +43,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, @@ -44,7 +43,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64,
44 } 43 }
45 oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId}) 44 oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
46 if err != nil { 45 if err != nil {
47 - e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err) 46 + e := fmt.Sprintf("获取订单(id=%d)中的货品数据失败,%s", orderId, err)
48 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 47 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
49 } 48 }
50 adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId}) 49 adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
@@ -52,10 +51,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, @@ -52,10 +51,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64,
52 e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err) 51 e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
53 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 52 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
54 } 53 }
55 - if adminUser.CompanyId != oldOrderGoods.CompanyId {  
56 - e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)  
57 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)  
58 - } 54 + _ = adminUser
59 //TODO数据更新操作 55 //TODO数据更新操作
60 //事件发布 56 //事件发布
61 // modifyEvent := event.OrderModify{ 57 // modifyEvent := event.OrderModify{
@@ -69,13 +65,12 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, @@ -69,13 +65,12 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64,
69 return nil 65 return nil
70 } 66 }
71 67
72 -//ModifyOrderGoodData 修改订单中的单个货品的合伙人分成比例  
73 -func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, goodId int64, adminId int64, goodNumber int) error { 68 +//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
  69 +func (serve OrderBonusServices) UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodWithPercent map[int]float64) error {
74 var ( 70 var (
75 userRepository domain.UsersRepository 71 userRepository domain.UsersRepository
76 orderBaseReponsitory domain.OrderBaseRepository 72 orderBaseReponsitory domain.OrderBaseRepository
77 orderGoodRepository domain.OrderGoodRepository 73 orderGoodRepository domain.OrderGoodRepository
78 - oldOrderGoods domain.OrderGood  
79 oldOrder *domain.OrderBase 74 oldOrder *domain.OrderBase
80 adminUser domain.Users 75 adminUser domain.Users
81 err error 76 err error
@@ -96,7 +91,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g @@ -96,7 +91,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g
96 } 91 }
97 oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId}) 92 oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
98 if err != nil { 93 if err != nil {
99 - e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err) 94 + e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
100 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 95 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
101 } 96 }
102 adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId}) 97 adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
@@ -104,10 +99,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g @@ -104,10 +99,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g
104 e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err) 99 e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
105 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 100 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
106 } 101 }
107 - if adminUser.CompanyId != oldOrderGoods.CompanyId {  
108 - e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)  
109 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)  
110 - } 102 + _ = adminUser
111 //TODO数据更新操作 103 //TODO数据更新操作
112 //事件发布 104 //事件发布
113 // modifyEvent := event.OrderModify{ 105 // modifyEvent := event.OrderModify{
@@ -122,8 +114,40 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g @@ -122,8 +114,40 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g
122 } 114 }
123 115
124 //PayOrderGoodBonus 支付订单中货品的分红 116 //PayOrderGoodBonus 支付订单中货品的分红
125 -func (serve WxOrderServices) PayOrderGoodBonus(goodId int64, adminId int64) error {  
126 - var err error 117 +func (serve OrderBonusServices) PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error {
  118 + var (
  119 + userRepository domain.UsersRepository
  120 + orderBaseReponsitory domain.OrderBaseRepository
  121 + orderGoodRepository domain.OrderGoodRepository
  122 + oldOrder *domain.OrderBase
  123 + adminUser domain.Users
  124 + err error
  125 + )
  126 + if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
  127 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  128 + }
  129 + if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
  130 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  131 + }
  132 + if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
  133 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  134 + }
  135 + oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
  136 + if err != nil {
  137 + e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
  138 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  139 + }
  140 + oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
  141 + if err != nil {
  142 + e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
  143 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  144 + }
  145 + adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
  146 + if err != nil {
  147 + e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
  148 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  149 + }
  150 + _ = adminUser
127 //TODO 151 //TODO
128 payEvent := event.PayOrderGoodBonus{ 152 payEvent := event.PayOrderGoodBonus{
129 GoodId: goodId, 153 GoodId: goodId,
1 package models 1 package models
2 2
3 import ( 3 import (
  4 + "context"
4 "time" 5 "time"
5 6
  7 + "github.com/go-pg/pg/v10"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
7 ) 9 )
8 10
@@ -12,9 +14,17 @@ type OrderLog struct { @@ -12,9 +14,17 @@ type OrderLog struct {
12 OrderId int64 `` //订单id 14 OrderId int64 `` //订单id
13 AlterTime time.Time `` //时间 15 AlterTime time.Time `` //时间
14 Operator string `` //操作人员 16 Operator string `` //操作人员
  17 + OperatorId int64 `` //操作人员Id
15 OperatorType string `` //操作人员的类型 18 OperatorType string `` //操作人员的类型
16 - Action string `` //执行动作 19 + LogAction string `` //执行动作
17 Descript []domain.OrderLogDescript `` //描述日志内容 20 Descript []domain.OrderLogDescript `` //描述日志内容
18 - //Content []domain.OrderLogContent `` //记录订单的操作动作  
19 - DataFrom string `` //修改操作的来源:"web_admin" 21 + Content []domain.OrderLogContent `` //记录订单的操作动作
  22 + DataFrom string `` //修改操作的来源:"web_admin"
  23 +}
  24 +
  25 +var _ pg.BeforeInsertHook = (*OrderBase)(nil)
  26 +
  27 +func (l *OrderLog) BeforeInsert(ctx context.Context) (context.Context, error) {
  28 + l.AlterTime = time.Now()
  29 + return ctx, nil
20 } 30 }
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 5
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
8 ) 9 )
9 10
@@ -19,6 +20,24 @@ func NewOrderInfoRepository(transactionContext *transaction.TransactionContext) @@ -19,6 +20,24 @@ func NewOrderInfoRepository(transactionContext *transaction.TransactionContext)
19 return &OrderLogRepository{transactionContext: transactionContext}, nil 20 return &OrderLogRepository{transactionContext: transactionContext}, nil
20 } 21 }
21 22
22 -func (reponsitory OrderLogRepository) transformPgModelToDomainModel() (data domain.OrderLog, err error) {  
23 - return domain.OrderLog{}, nil 23 +func (reponsitory OrderLogRepository) transformPgModelToDomainModel(m *models.OrderLog) (data domain.OrderLog, err error) {
  24 + return domain.OrderLog{
  25 + OrderId: m.OrderId,
  26 + Operator: m.Operator,
  27 + OperatorId: m.OperatorId,
  28 + OperatorType: m.OperatorType,
  29 + AlterTime: m.AlterTime,
  30 + LogAction: m.LogAction,
  31 + Descript: m.Descript,
  32 + DataFrom: m.DataFrom,
  33 + Content: m.Content,
  34 + }, nil
  35 +}
  36 +
  37 +func (reponsitory OrderLogRepository) Add(data domain.OrderLog) error {
  38 + return nil
  39 +}
  40 +
  41 +func (reponsitory OrderLogRepository) Find(data domain.OrderLog) ([]domain.OrderLog, int, error) {
  42 + return nil, 0, nil
24 } 43 }