作者 唐旭辉

日常更新报存

@@ -14,7 +14,7 @@ import ( @@ -14,7 +14,7 @@ import (
14 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 14 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
15 ) 15 )
16 16
17 -//OrderService 管理员相关服务 17 +//OrderService 自建订单,意向单,实发订单
18 type OrderInfoService struct { 18 type OrderInfoService struct {
19 } 19 }
20 20
@@ -151,6 +151,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery @@ -151,6 +151,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
151 return order, nil 151 return order, nil
152 } 152 }
153 153
  154 +//CreateNewOrder 创建订单
154 func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (*domain.OrderBase, error) { 155 func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (*domain.OrderBase, error) {
155 var ( 156 var (
156 transactionContext, _ = factory.CreateTransactionContext(nil) 157 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -436,10 +437,12 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -436,10 +437,12 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
436 oldOrderData.Goods = newOrderGoods 437 oldOrderData.Goods = newOrderGoods
437 //删不需要的订单总不需要的商品 438 //删不需要的订单总不需要的商品
438 delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods) 439 delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods)
  440 + if len(delGoods) > 0 {
439 err = orderGoodRepository.Remove(oldOrderData.Id, cmd.CompanyId, delGoods...) 441 err = orderGoodRepository.Remove(oldOrderData.Id, cmd.CompanyId, delGoods...)
440 if err != nil { 442 if err != nil {
441 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err)) 443 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
442 } 444 }
  445 + }
443 err = transactionContext.CommitTransaction() 446 err = transactionContext.CommitTransaction()
444 if err != nil { 447 if err != nil {
445 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 448 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
@@ -41,8 +41,6 @@ type Company struct { @@ -41,8 +41,6 @@ type Company struct {
41 UpdateAt time.Time `json:"updateAt"` 41 UpdateAt time.Time `json:"updateAt"`
42 // 删除时间 42 // 删除时间
43 DeleteAt time.Time `json:"deleteAt"` 43 DeleteAt time.Time `json:"deleteAt"`
44 - //模块授权  
45 - // Permission map[string]bool `json:"permission"`  
46 } 44 }
47 45
48 func (c Company) EnableIsOk() bool { 46 func (c Company) EnableIsOk() bool {
@@ -4,7 +4,8 @@ const ( @@ -4,7 +4,8 @@ const (
4 PAY_ORDER_GOOD_BONUS_EVENT string = "pay-order-good-bonus-event" 4 PAY_ORDER_GOOD_BONUS_EVENT string = "pay-order-good-bonus-event"
5 ) 5 )
6 6
7 -//PayOrderGoodBonus 事件:支付订单中货品的分红 7 +//WxPayOrderGoodBonus
  8 +//事件:支付来自微信小程序的订单中货品的分红
8 type PayOrderGoodBonus struct { 9 type PayOrderGoodBonus struct {
9 //订单id 10 //订单id
10 OrderId int64 11 OrderId int64
@@ -4,21 +4,35 @@ const ( @@ -4,21 +4,35 @@ const (
4 ORDER_GOOD_MODIFY_EVENT string = "order-good-modify-event" 4 ORDER_GOOD_MODIFY_EVENT string = "order-good-modify-event"
5 ) 5 )
6 6
7 -//OrderGoodModify 事件:修改订单中货品的数据  
8 -type OrderGoodModify struct {  
9 - //订单id  
10 - OrderId int64 7 +type WxOrderGoodModify struct {
11 //订单id 8 //订单id
12 GoodId int64 9 GoodId int64
13 - //货品名称  
14 - GoodName string 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
15 //管理员id 27 //管理员id
16 AdminId int64 28 AdminId int64
17 //更改的订单基础数据 29 //更改的订单基础数据
18 - UpdateGoodData map[string]string 30 + GoodModify []WxOrderGoodModify
  31 + //订单备注 [0]旧值,[1]新值
  32 + Remark [2]string
19 } 33 }
20 34
21 //EventType 事件名称 35 //EventType 事件名称
22 -func (m OrderGoodModify) EventType() string { 36 +func (m WxOrderModify) EventType() string {
23 return ORDER_GOOD_MODIFY_EVENT 37 return ORDER_GOOD_MODIFY_EVENT
24 } 38 }
@@ -26,6 +26,42 @@ type Buyer struct { @@ -26,6 +26,42 @@ type Buyer struct {
26 ShippingAddress string `json:"shippingAddress"` 26 ShippingAddress string `json:"shippingAddress"`
27 } 27 }
28 28
  29 +//OrderDataFrom 订单数据来源
  30 +type OrderDataFrom struct {
  31 + Platform string `json:"platform"` //订单数据来源平台
  32 + PlatformId string `json:"platformId"` //平台唯一标识
  33 + DataId int64 `json:"dataId"` //订单数据id标识
  34 +}
  35 +
  36 +type OrderCompute struct {
  37 + //合伙人应收分红
  38 + PlanPartnerBonus float64 `json:"planPartnerBonus"`
  39 + //调整后的合伙人应收分红 (初始值=-1);
  40 + //业务判定时0是有效值,
  41 + //所以用空串表示无值,转换到数据库中为负值
  42 + UsePartnerBonus float64 `json:"usePartnerBonus"`
  43 + //合伙人已收分红
  44 + PartnerBonusHas float64 `json:"partnerBonusHas"`
  45 + //合伙人未收分红
  46 + PartnerBonusNot float64 `json:"partnerBonusNot"`
  47 + //合伙人分红支出
  48 + PartnerBonusExpense float64 `json:"partnerBonusExpense"`
  49 + //业务员抽成
  50 + SalesmanBonus float64 `json:"salesmanBonus"`
  51 + //预计的订单内货品总数
  52 + PlanOrderCount int `json:"planOrderCount"`
  53 + //预计的订单的总金额
  54 + PlanOrderAmount float64 `json:"planOrderAmount"`
  55 + //按需使用的订单内货品总数 (初始值=-1)
  56 + //业务判定时0是有效值,
  57 + //所以用空串表示无值,转换到数据库中为负值
  58 + UseOrderCount int `json:"useOrderCount"`
  59 + //按需使用的订单内货总金额 (初始值=-1)
  60 + //业务判定时0是有效值,
  61 + //所以用空串表示无值,转换到数据库中为负值
  62 + UseOrderAmount float64 `json:"useOrderAmount"`
  63 +}
  64 +
29 //OrderBase 订单基础 65 //OrderBase 订单基础
30 type OrderBase struct { 66 type OrderBase struct {
31 //表id 67 //表id
@@ -61,35 +97,61 @@ type OrderBase struct { @@ -61,35 +97,61 @@ type OrderBase struct {
61 BonusStatus int `json:"bonusStatus"` 97 BonusStatus int `json:"bonusStatus"`
62 //公司 98 //公司
63 CompanyId int64 `json:"companyId"` 99 CompanyId int64 `json:"companyId"`
  100 + //数据来源
  101 + DataFrom OrderDataFrom `json:"dataFrom"`
64 } 102 }
65 103
66 -type OrderCompute struct {  
67 - //合伙人应收分红  
68 - PlanPartnerBonus float64 `json:"planPartnerBonus"`  
69 - //调整后的合伙人应收分红 (初始值=-1);  
70 - //业务判定时0是有效值,  
71 - //所以用空串表示无值,转换到数据库中为负值  
72 - UsePartnerBonus float64 `json:"usePartnerBonus"`  
73 - //合伙人已收分红  
74 - PartnerBonusHas float64 `json:"partnerBonusHas"`  
75 - //合伙人未收分红  
76 - PartnerBonusNot float64 `json:"partnerBonusNot"`  
77 - //合伙人分红支出  
78 - PartnerBonusExpense float64 `json:"partnerBonusExpense"`  
79 - //业务员抽成  
80 - SalesmanBonus float64 `json:"salesmanBonus"`  
81 - //预计的订单内货品总数  
82 - PlanOrderCount int `json:"planOrderCount"`  
83 - //预计的订单的总金额  
84 - PlanOrderAmount float64 `json:"planOrderAmount"`  
85 - //按需使用的订单内货品总数 (初始值=-1)  
86 - //业务判定时0是有效值,  
87 - //所以用空串表示无值,转换到数据库中为负值  
88 - UseOrderCount int `json:"useOrderCount"`  
89 - //按需使用的订单内货总金额 (初始值=-1)  
90 - //业务判定时0是有效值,  
91 - //所以用空串表示无值,转换到数据库中为负值  
92 - UseOrderAmount float64 `json:"useOrderAmount"` 104 +//Update 更新订单数据
  105 +//orderData 订单数据
  106 +//goodsMap 货品的数据,以货品的id做键,map[id]map[string]interface{}
  107 +func (order *OrderBase) Update(orderData map[string]interface{}, goodsMap map[int64]map[string]interface{}) error {
  108 + if v, ok := orderData["OrderCode"]; ok {
  109 + order.OrderCode = v.(string)
  110 + }
  111 + if v, ok := orderData["DeliveryCode"]; ok {
  112 + order.DeliveryCode = v.(string)
  113 + }
  114 + if v, ok := orderData["Buyer"]; ok {
  115 + order.Buyer = v.(Buyer)
  116 + }
  117 + if v, ok := orderData["SalesmanBonusPercent"]; ok {
  118 + order.SalesmanBonusPercent = v.(float64)
  119 + }
  120 + if v, ok := orderData["DeliveryTime"]; ok {
  121 + order.DeliveryTime = v.(time.Time)
  122 + }
  123 + if v, ok := orderData["IsDisable"]; ok {
  124 + order.IsDisable = v.(int)
  125 + }
  126 + for i := range order.Goods {
  127 + goodId := order.Goods[i].Id
  128 + if _, ok := goodsMap[goodId]; !ok {
  129 + continue
  130 + }
  131 + if err := order.Goods[i].Update(goodsMap[goodId]); err != nil {
  132 + return err
  133 + }
  134 + }
  135 + err := order.Compute()
  136 + return err
  137 +}
  138 +
  139 +func (order *OrderBase) AddGoods(goods []OrderGood) {
  140 + order.Goods = append(order.Goods, goods...)
  141 + order.Compute()
  142 +}
  143 +
  144 +func (order *OrderBase) DeleteGoods(goodIds []int64) {
  145 + var newGoods []OrderGood
  146 + for i := range order.Goods {
  147 + for _, goodId := range goodIds {
  148 + order.Goods[i].Id = goodId
  149 + continue
  150 + }
  151 + newGoods = append(newGoods, order.Goods[i])
  152 + }
  153 + order.Goods = newGoods
  154 + order.Compute()
93 } 155 }
94 156
95 //Compute 数据汇总核算 157 //Compute 数据汇总核算
@@ -22,6 +22,28 @@ const ( @@ -22,6 +22,28 @@ const (
22 OrderGoodHasPay int = 2 22 OrderGoodHasPay int = 2
23 ) 23 )
24 24
  25 +//GoodCompute 货品中计算值
  26 +type GoodCompute struct {
  27 + //预计的货品总额
  28 + PlanAmount float64 `json:"planAmount"`
  29 + //调整后的货品总额 (初始值=-1)
  30 + //业务判定时0是有效值,
  31 + //所以用空串表示无值,转换到数据库中为负值
  32 + UseAmount float64 `json:"useAmount"`
  33 + //预计的合伙人分红
  34 + PlanPartnerBonus float64 `json:"planPartnerBonus"`
  35 + //合伙人应收分红调整 (初始值=-1),
  36 + //业务判定时0是有效值,
  37 + //所以用空串表示无值,转换到数据库中为负值
  38 + UsePartnerBonus float64 `json:"usePartnerBonus"`
  39 + //合伙人已收分红
  40 + PartnerBonusHas float64 `json:"partnerBonusHas"`
  41 + //合伙人未收分红
  42 + PartnerBonusNot float64 `json:"partnerBonusNot"`
  43 + //合伙人分红支出
  44 + PartnerBonusExpense float64 `json:"partnerBonusExpense"`
  45 +}
  46 +
25 //OrderGood 订单中的货品 47 //OrderGood 订单中的货品
26 type OrderGood struct { 48 type OrderGood struct {
27 //货品id 49 //货品id
@@ -52,25 +74,28 @@ type OrderGood struct { @@ -52,25 +74,28 @@ type OrderGood struct {
52 CompanyId int64 74 CompanyId int64
53 } 75 }
54 76
55 -type GoodCompute struct {  
56 - //预计的货品总额  
57 - PlanAmount float64 `json:"planAmount"`  
58 - //调整后的货品总额 (初始值=-1)  
59 - //业务判定时0是有效值,  
60 - //所以用空串表示无值,转换到数据库中为负值  
61 - UseAmount float64 `json:"useAmount"`  
62 - //预计的合伙人分红  
63 - PlanPartnerBonus float64 `json:"planPartnerBonus"`  
64 - //合伙人应收分红调整 (初始值=-1),  
65 - //业务判定时0是有效值,  
66 - //所以用空串表示无值,转换到数据库中为负值  
67 - UsePartnerBonus float64 `json:"usePartnerBonus"`  
68 - //合伙人已收分红  
69 - PartnerBonusHas float64 `json:"partnerBonusHas"`  
70 - //合伙人未收分红  
71 - PartnerBonusNot float64 `json:"partnerBonusNot"`  
72 - //合伙人分红支出  
73 - PartnerBonusExpense float64 `json:"partnerBonusExpense"` 77 +//Update 更新商品相关的数据
  78 +func (good *OrderGood) Update(m map[string]interface{}) error {
  79 + if v, ok := m["GoodName"]; ok {
  80 + good.GoodName = v.(string)
  81 + }
  82 + if v, ok := m["PlanGoodNumber"]; ok {
  83 + good.PlanGoodNumber = v.(int)
  84 + }
  85 + if v, ok := m["UseGoodNumber"]; ok {
  86 + good.UseGoodNumber = v.(int)
  87 + }
  88 + if v, ok := m["Price"]; ok {
  89 + good.Price = v.(float64)
  90 + }
  91 + if v, ok := m["PartnerBonusPercent"]; ok {
  92 + good.PartnerBonusPercent = v.(float64)
  93 + }
  94 + if v, ok := m["Remark"]; ok {
  95 + good.Remark = v.(string)
  96 + }
  97 + err := good.Compute()
  98 + return err
74 } 99 }
75 100
76 //OrderGoodBonusWaitPay 货品分红待支付 101 //OrderGoodBonusWaitPay 货品分红待支付
@@ -177,9 +202,12 @@ type OrderGoodFindQuery struct { @@ -177,9 +202,12 @@ type OrderGoodFindQuery struct {
177 Limit int 202 Limit int
178 CompanyId int64 203 CompanyId int64
179 } 204 }
180 - 205 +type OrderGoodFindOneQuery struct {
  206 + GoodId int64
  207 +}
181 type OrderGoodRepository interface { 208 type OrderGoodRepository interface {
182 Save(order []OrderGood) error 209 Save(order []OrderGood) error
183 Find(queryOptions OrderGoodFindQuery) ([]OrderGood, int, error) 210 Find(queryOptions OrderGoodFindQuery) ([]OrderGood, int, error)
  211 + FindOne(queryOptions OrderGoodFindOneQuery) (OrderGood, error)
184 Remove(orderid int64, companyId int64, ids ...int64) error 212 Remove(orderid int64, companyId int64, ids ...int64) error
185 } 213 }
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 日志数据来源
  6 +const (
  7 + //管理后台
  8 + ORDER_LOG_FROM string = "web_admin"
  9 +)
  10 +
  11 +//操作人员的类型
  12 +const (
  13 + //操作人类型
  14 + ORDER_LOG_OPERATOR_ADMIN string = "admin"
  15 +)
  16 +
  17 +//OrderLogDescript 描述日志内容
  18 +type OrderLogDescript struct {
  19 + Title string `json:"title"` //标题
  20 + Action string `json:"action"` //执行的动作描述
  21 + Modifyitem []string `json:"modifyItem"` //动作执行结果
  22 +}
  23 +
  24 +//OrderLogContentItem 记录订单的相关属性值的修改
  25 +type OrderLogContentItem struct {
  26 + Table string `json:"table"` //修改的表数据主体,"order_good","order_base"
  27 + TableId string `json:"tableId"` //表id
  28 + Title string `json:"title"` //名称标题
  29 + Item string `json:"item"` //修改的项目
  30 + FormerValue string `json:"formerValue"` //旧值
  31 + NewValue string `json:"newValue"` //新值
  32 +}
  33 +
  34 +//OrderLog 订单修改记录
  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"
  44 +}
1 package domainService 1 package domainService
2 2
3 import ( 3 import (
  4 + "fmt"
  5 +
4 coreDomain "github.com/linmadan/egglib-go/core/domain" 6 coreDomain "github.com/linmadan/egglib-go/core/domain"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/event" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/event"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/repository"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
7 ) 12 )
8 13
9 -type OrderServices struct { 14 +//WxOrderServices 处理来自微信小程序(海鲜干货)的订单
  15 +type WxOrderServices struct {
10 coreDomain.BaseEventPublisher 16 coreDomain.BaseEventPublisher
11 transactionContext *transaction.TransactionContext 17 transactionContext *transaction.TransactionContext
12 } 18 }
13 19
14 -//UpdateOrderGoodData 修改订单中的货品数据  
15 -func (serve OrderServices) UpdateOrderGoodData(orderId int64, goodId int64, adminId int64, updateData map[string]string) error {  
16 - var err error 20 +//ModifyOrderGoodData 修改订单中的单个货品的数量
  21 +func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int) error {
  22 + var (
  23 + userRepository domain.UsersRepository
  24 + orderBaseReponsitory domain.OrderBaseRepository
  25 + orderGoodRepository domain.OrderGoodRepository
  26 + oldOrderGoods domain.OrderGood
  27 + oldOrder *domain.OrderBase
  28 + adminUser domain.Users
  29 + err error
  30 + )
  31 + if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
  32 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  33 + }
  34 + if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
  35 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  36 + }
  37 + if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
  38 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  39 + }
  40 + oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
  41 + if err != nil {
  42 + e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
  43 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  44 + }
  45 + oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
  46 + if err != nil {
  47 + e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err)
  48 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  49 + }
  50 + adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
  51 + if err != nil {
  52 + e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
  53 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  54 + }
  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 + }
17 //TODO数据更新操作 59 //TODO数据更新操作
18 //事件发布 60 //事件发布
19 - modifyEvent := event.OrderGoodModify{  
20 - OrderId: orderId,  
21 - GoodId: goodId,  
22 - AdminId: adminId,  
23 - UpdateGoodData: updateData, 61 + // modifyEvent := event.OrderModify{
  62 + // OrderId: oldOrderGoods.OrderId,
  63 + // AdminId: adminId,
  64 + // //
  65 + // }
  66 + // if err = serve.Publish(modifyEvent); err != nil {
  67 + // return err
  68 + // }
  69 + return nil
  70 +}
  71 +
  72 +//ModifyOrderGoodData 修改订单中的单个货品的合伙人分成比例
  73 +func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, goodId int64, adminId int64, goodNumber int) error {
  74 + var (
  75 + userRepository domain.UsersRepository
  76 + orderBaseReponsitory domain.OrderBaseRepository
  77 + orderGoodRepository domain.OrderGoodRepository
  78 + oldOrderGoods domain.OrderGood
  79 + oldOrder *domain.OrderBase
  80 + adminUser domain.Users
  81 + err error
  82 + )
  83 + if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
  84 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
24 } 85 }
25 - if err = serve.Publish(modifyEvent); err != nil {  
26 - return err 86 + if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
  87 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  88 + }
  89 + if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
  90 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  91 + }
  92 + oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
  93 + if err != nil {
  94 + e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
  95 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
27 } 96 }
  97 + oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
  98 + if err != nil {
  99 + e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err)
  100 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  101 + }
  102 + adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
  103 + if err != nil {
  104 + e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
  105 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  106 + }
  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 + }
  111 + //TODO数据更新操作
  112 + //事件发布
  113 + // modifyEvent := event.OrderModify{
  114 + // OrderId: oldOrderGoods.OrderId,
  115 + // AdminId: adminId,
  116 + // //
  117 + // }
  118 + // if err = serve.Publish(modifyEvent); err != nil {
  119 + // return err
  120 + // }
28 return nil 121 return nil
29 } 122 }
30 123
31 //PayOrderGoodBonus 支付订单中货品的分红 124 //PayOrderGoodBonus 支付订单中货品的分红
32 -func (serve OrderServices) PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error { 125 +func (serve WxOrderServices) PayOrderGoodBonus(goodId int64, adminId int64) error {
33 var err error 126 var err error
34 //TODO 127 //TODO
35 payEvent := event.PayOrderGoodBonus{ 128 payEvent := event.PayOrderGoodBonus{
36 - OrderId: orderId,  
37 GoodId: goodId, 129 GoodId: goodId,
38 AdminId: adminId, 130 AdminId: adminId,
39 } 131 }
@@ -63,6 +63,9 @@ type OrderBase struct { @@ -63,6 +63,9 @@ type OrderBase struct {
63 //分红支付状态 63 //分红支付状态
64 BonusStatus int 64 BonusStatus int
65 CompanyId int64 65 CompanyId int64
  66 +
  67 + //数据来源
  68 + DataFrom domain.OrderDataFrom ``
66 } 69 }
67 70
68 var _ pg.BeforeUpdateHook = (*OrderBase)(nil) 71 var _ pg.BeforeUpdateHook = (*OrderBase)(nil)
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  7 +)
  8 +
  9 +//OrderLog 订单修改记录
  10 +type OrderLog struct {
  11 + tableName struct{} `pg:"order_log"`
  12 + OrderId int64 `` //订单id
  13 + AlterTime time.Time `` //时间
  14 + Operator string `` //操作人员
  15 + OperatorType string `` //操作人员的类型
  16 + Action string `` //执行动作
  17 + Descript []domain.OrderLogDescript `` //描述日志内容
  18 + //Content []domain.OrderLogContent `` //记录订单的操作动作
  19 + DataFrom string `` //修改操作的来源:"web_admin"
  20 +}
1 package repository 1 package repository
2 2
3 import ( 3 import (
  4 + "errors"
4 "fmt" 5 "fmt"
5 6
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
@@ -138,3 +139,27 @@ func (repository OrderGoodRepository) Remove(orderId int64, companyId int64, goo @@ -138,3 +139,27 @@ func (repository OrderGoodRepository) Remove(orderId int64, companyId int64, goo
138 _, err = query.Delete() 139 _, err = query.Delete()
139 return err 140 return err
140 } 141 }
  142 +
  143 +func (repository OrderGoodRepository) FindOne(queryOption domain.OrderGoodFindOneQuery) (domain.OrderGood, error) {
  144 + var (
  145 + good domain.OrderGood
  146 + goodModel models.OrderGood
  147 + err error
  148 + hasCondition bool
  149 + )
  150 + tx := repository.transactionContext.GetDB()
  151 + query := tx.Model(&goodModel)
  152 + if queryOption.GoodId > 0 {
  153 + query = query.Where("id=?", queryOption.GoodId)
  154 + hasCondition = true
  155 + }
  156 + if !hasCondition {
  157 + return good, errors.New("OrderGoodRepository.FindOne 必须使用查询条件")
  158 + }
  159 + err = query.First()
  160 + if err != nil {
  161 + return good, fmt.Errorf("获取订单的货品数据失败,%s", err)
  162 + }
  163 + good, err = repository.transformPgModelToDomainModel(&goodModel)
  164 + return good, err
  165 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  8 +)
  9 +
  10 +//订单日志
  11 +type OrderLogRepository struct {
  12 + transactionContext *transaction.TransactionContext
  13 +}
  14 +
  15 +func NewOrderInfoRepository(transactionContext *transaction.TransactionContext) (*OrderLogRepository, error) {
  16 + if transactionContext == nil {
  17 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  18 + }
  19 + return &OrderLogRepository{transactionContext: transactionContext}, nil
  20 +}
  21 +
  22 +func (reponsitory OrderLogRepository) transformPgModelToDomainModel() (data domain.OrderLog, err error) {
  23 + return domain.OrderLog{}, nil
  24 +}
@@ -141,7 +141,7 @@ func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery @@ -141,7 +141,7 @@ func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery
141 query = query.Where("open_id=?", queryOptions.OpenId) 141 query = query.Where("open_id=?", queryOptions.OpenId)
142 } 142 }
143 if !hasCondition { 143 if !hasCondition {
144 - return domain.Users{}, errors.New("FindOne 必须要有查询条件") 144 + return domain.Users{}, errors.New("UsersRepository.FindOne 必须要有查询条件")
145 } 145 }
146 err = query.First() 146 err = query.First()
147 if err != nil { 147 if err != nil {