pg_order_bonus_service.go
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package domainService
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/event"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
//OrderBonusServices 处理订单分红的相关操作
type OrderBonusServices struct {
coreDomain.BaseEventPublisher
transactionContext *transaction.TransactionContext
}
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
func (serve OrderBonusServices) UpdateBounsByGoodNumber(orderId int64, adminId int64, goodWithNumber map[int64]int) error {
var (
userRepository domain.UsersRepository
orderBaseReponsitory domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrder *domain.OrderBase
adminUser domain.Users
err error
)
if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)中的货品数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
if err != nil {
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
_ = adminUser
//TODO数据更新操作
//事件发布
// modifyEvent := event.OrderModify{
// OrderId: oldOrderGoods.OrderId,
// AdminId: adminId,
// //
// }
// if err = serve.Publish(modifyEvent); err != nil {
// return err
// }
return nil
}
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
func (serve OrderBonusServices) UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodWithPercent map[int]float64) error {
var (
userRepository domain.UsersRepository
orderBaseReponsitory domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrder *domain.OrderBase
adminUser domain.Users
err error
)
if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
if err != nil {
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
_ = adminUser
//TODO数据更新操作
//事件发布
// modifyEvent := event.OrderModify{
// OrderId: oldOrderGoods.OrderId,
// AdminId: adminId,
// //
// }
// if err = serve.Publish(modifyEvent); err != nil {
// return err
// }
return nil
}
//PayOrderGoodBonus 支付订单中货品的分红
func (serve OrderBonusServices) PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error {
var (
userRepository domain.UsersRepository
orderBaseReponsitory domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
oldOrder *domain.OrderBase
adminUser domain.Users
err error
)
if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
if err != nil {
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
_ = adminUser
//TODO
payEvent := event.PayOrderGoodBonus{
GoodId: goodId,
AdminId: adminId,
}
if err = serve.Publish(payEvent); err != nil {
return err
}
return nil
}