|
@@ -5,6 +5,8 @@ import ( |
|
@@ -5,6 +5,8 @@ import ( |
5
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
5
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
6
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
|
6
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
|
8
|
"time"
|
10
|
"time"
|
9
|
|
11
|
|
10
|
//"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
|
12
|
//"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
|
|
@@ -86,92 +88,31 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm |
|
@@ -86,92 +88,31 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm |
86
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
88
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
87
|
}
|
89
|
}
|
88
|
}
|
90
|
}
|
|
|
91
|
+ var bonusStatus int = 1
|
|
|
92
|
+ if len(command.DivdendPaymentItem) > 0 {
|
|
|
93
|
+ bonusStatus = command.DivdendPaymentItem[len(command.DivdendPaymentItem)-1].StateOfPayment
|
|
|
94
|
+ }
|
89
|
|
95
|
|
90
|
- if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount}); err != nil {
|
96
|
+ if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount, "bonusStatus": bonusStatus}); err != nil {
|
91
|
return
|
97
|
return
|
92
|
}
|
98
|
}
|
93
|
|
99
|
|
94
|
return
|
100
|
return
|
95
|
}
|
101
|
}
|
96
|
|
102
|
|
97
|
-//// GetOrderPayment 返回合伙人
|
|
|
98
|
-//func (OrderPaymentService *OrderPaymentService) GetOrderPayment(command query.GetOrderPaymentQuery) (data *domain.OrderPayment, err error) {
|
|
|
99
|
-// var (
|
|
|
100
|
-// transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
101
|
-// )
|
|
|
102
|
-// if err = command.ValidateQuery(); err != nil {
|
|
|
103
|
-// return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
|
|
|
104
|
-// }
|
|
|
105
|
-// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
106
|
-// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
107
|
-// }
|
|
|
108
|
-// defer func() {
|
|
|
109
|
-// transactionContext.RollbackTransaction()
|
|
|
110
|
-// }()
|
|
|
111
|
-// var OrderPaymentRepository domain.OrderPaymentRepository
|
|
|
112
|
-// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
|
|
|
113
|
-// "transactionContext": transactionContext,
|
|
|
114
|
-// }); err != nil {
|
|
|
115
|
-// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
116
|
-// }
|
|
|
117
|
-// data, err = OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.Id})
|
|
|
118
|
-// if err != nil {
|
|
|
119
|
-// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
120
|
-// }
|
|
|
121
|
-// err = transactionContext.CommitTransaction()
|
|
|
122
|
-// return
|
|
|
123
|
-//}
|
|
|
124
|
-//
|
|
|
125
|
-//// 更新客户价值
|
|
|
126
|
-//func (OrderPaymentService *OrderPaymentService) UpdateOrderPayment(updateOrderPaymentCommand *command.UpdateOrderPaymentCommand) (err error) {
|
|
|
127
|
-// var (
|
|
|
128
|
-// transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
129
|
-// )
|
|
|
130
|
-// if err = updateOrderPaymentCommand.ValidateCommand(); err != nil {
|
|
|
131
|
-// return application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
132
|
-// }
|
|
|
133
|
-// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
134
|
-// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
135
|
-// }
|
|
|
136
|
-// defer func() {
|
|
|
137
|
-// transactionContext.RollbackTransaction()
|
|
|
138
|
-// }()
|
|
|
139
|
-// var OrderPaymentRepository domain.OrderPaymentRepository
|
|
|
140
|
-// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
|
|
|
141
|
-// "transactionContext": transactionContext,
|
|
|
142
|
-// }); err != nil {
|
|
|
143
|
-// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
144
|
-// }
|
|
|
145
|
-// OrderPayment, err := OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{
|
|
|
146
|
-// UserId: updateOrderPaymentCommand.Id,
|
|
|
147
|
-// })
|
|
|
148
|
-// if err != nil {
|
|
|
149
|
-// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
150
|
-// }
|
|
|
151
|
-// OrderPayment.PartnerCategory = updateOrderPaymentCommand.PartnerCategory
|
|
|
152
|
-// OrderPayment.Salesman = updateOrderPaymentCommand.Salesman
|
|
|
153
|
-// OrderPayment.Status = updateOrderPaymentCommand.Status
|
|
|
154
|
-// OrderPayment.RegionInfo = updateOrderPaymentCommand.RegionInfo
|
|
|
155
|
-// if _, err = OrderPaymentRepository.Save(OrderPayment); err != nil {
|
|
|
156
|
-// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
157
|
-// }
|
|
|
158
|
-// transactionContext.CommitTransaction()
|
|
|
159
|
-// return
|
|
|
160
|
-//}
|
|
|
161
|
-//
|
|
|
162
|
// 返回订单支付列表
|
103
|
// 返回订单支付列表
|
163
|
-func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.ListOrderPaymentQuery) (int, []*domain.OrderPayment, error) {
|
104
|
+func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) (map[string]interface{}, []*domain.OrderPayment, error) {
|
164
|
var (
|
105
|
var (
|
165
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
106
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
107
|
+ OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
|
166
|
OrderPayments []*domain.OrderPayment
|
108
|
OrderPayments []*domain.OrderPayment
|
167
|
- count int
|
|
|
168
|
err error
|
109
|
err error
|
169
|
)
|
110
|
)
|
170
|
if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
|
111
|
if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
|
171
|
- return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
|
112
|
+ return nil, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
|
172
|
}
|
113
|
}
|
173
|
if err := transactionContext.StartTransaction(); err != nil {
|
114
|
if err := transactionContext.StartTransaction(); err != nil {
|
174
|
- return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
115
|
+ return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
175
|
}
|
116
|
}
|
176
|
defer func() {
|
117
|
defer func() {
|
177
|
if err != nil {
|
118
|
if err != nil {
|
|
@@ -182,19 +123,99 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen |
|
@@ -182,19 +123,99 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen |
182
|
if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
|
123
|
if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
|
183
|
"transactionContext": transactionContext,
|
124
|
"transactionContext": transactionContext,
|
184
|
}); err != nil {
|
125
|
}); err != nil {
|
185
|
- return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
126
|
+ return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
186
|
}
|
127
|
}
|
187
|
queryOption := domain.OrderPaymentQuery{
|
128
|
queryOption := domain.OrderPaymentQuery{
|
188
|
OrderId: listOrderPaymentQuery.OrderId,
|
129
|
OrderId: listOrderPaymentQuery.OrderId,
|
189
|
}
|
130
|
}
|
|
|
131
|
+ orderBase, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId)
|
|
|
132
|
+ if e != nil {
|
|
|
133
|
+ return nil, nil, e
|
|
|
134
|
+ }
|
190
|
if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil {
|
135
|
if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil {
|
191
|
- return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
136
|
+ return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
137
|
+ }
|
|
|
138
|
+ //if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil {
|
|
|
139
|
+ // return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
140
|
+ //}
|
|
|
141
|
+
|
|
|
142
|
+ if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
143
|
+ return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
192
|
}
|
144
|
}
|
193
|
- if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil {
|
145
|
+ return orderBase, OrderPayments, nil
|
|
|
146
|
+}
|
|
|
147
|
+
|
|
|
148
|
+// 返回分红管理列表
|
|
|
149
|
+func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaymentQuery *query.ListDividendOrdersQuery) (int, interface{}, error) {
|
|
|
150
|
+ var (
|
|
|
151
|
+ transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
152
|
+ //OrderPayments []*domain.OrderPayment
|
|
|
153
|
+ count int
|
|
|
154
|
+ err error
|
|
|
155
|
+ OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
156
|
+ orders []*models.Order
|
|
|
157
|
+ )
|
|
|
158
|
+ if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
|
|
|
159
|
+ return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
|
|
|
160
|
+ }
|
|
|
161
|
+ if err := transactionContext.StartTransaction(); err != nil {
|
|
|
162
|
+ return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
163
|
+ }
|
|
|
164
|
+ defer func() {
|
|
|
165
|
+ if err != nil {
|
|
|
166
|
+ transactionContext.RollbackTransaction()
|
|
|
167
|
+ }
|
|
|
168
|
+ }()
|
|
|
169
|
+ if count, orders, err = OrderDao.GetDividendOrders(map[string]interface{}{
|
|
|
170
|
+ "orderCode": listOrderPaymentQuery.OrderNumber,
|
|
|
171
|
+ "partnerName": listOrderPaymentQuery.PartnerName,
|
|
|
172
|
+ "orderType": 1,
|
|
|
173
|
+ "offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize,
|
|
|
174
|
+ "limit": listOrderPaymentQuery.PageSize,
|
|
|
175
|
+ }); err != nil {
|
194
|
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
176
|
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
195
|
}
|
177
|
}
|
|
|
178
|
+
|
|
|
179
|
+ type DividendOrderItem struct {
|
|
|
180
|
+ OrderNumber string `json:"orderNumber"` //订单号
|
|
|
181
|
+ OrderState int `json:"orderState"` //订单状态
|
|
|
182
|
+ StateOfPayment string `json:"stateOfPayment"` //支付状态
|
|
|
183
|
+ CreateTime string `json:"createTime"` //订单创建时间
|
|
|
184
|
+ PartnerName string `json:"partnerName"` //合伙人姓名
|
|
|
185
|
+ DividendProportion float64 `json:"dividendProportion"` //分红比例
|
|
|
186
|
+ DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红
|
|
|
187
|
+ DividendSpending float64 `json:"dividendSpending"` //分红支出
|
|
|
188
|
+ ReceiveDividends float64 `json:"receiveDividends"` //实收分红
|
|
|
189
|
+ CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例
|
|
|
190
|
+ }
|
|
|
191
|
+ var list = make([]DividendOrderItem, 0)
|
|
|
192
|
+ for i := range orders {
|
|
|
193
|
+ order := orders[i]
|
|
|
194
|
+ item := DividendOrderItem{
|
|
|
195
|
+ OrderNumber: order.OrderCode,
|
|
|
196
|
+ OrderState: order.OrderStatus,
|
|
|
197
|
+ StateOfPayment: "",
|
|
|
198
|
+ CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"),
|
|
|
199
|
+ PartnerName: order.PartnerInfo.PartnerName,
|
|
|
200
|
+ DividendProportion: order.PartnerBonusPercent,
|
|
|
201
|
+ DividendsReceivable: utils.Decimal(order.OrderActualAmount * (order.PartnerBonusPercent / 100.0)),
|
|
|
202
|
+ DividendSpending: 0,
|
|
|
203
|
+ ReceiveDividends: utils.Decimal(order.OrderPaymentAmount * (order.PartnerBonusPercent / 100.0)),
|
|
|
204
|
+ CommissionProportion: order.SalesmanBonusPercent,
|
|
|
205
|
+ }
|
|
|
206
|
+ if order.BonusStatus == domain.BonusPaid {
|
|
|
207
|
+ item.StateOfPayment = "已支付分红"
|
|
|
208
|
+ } else {
|
|
|
209
|
+ item.StateOfPayment = "等待支付分红"
|
|
|
210
|
+ }
|
|
|
211
|
+ if order.OrderActualAmount < order.OrderAmount {
|
|
|
212
|
+ item.DividendSpending = utils.Decimal(order.OrderAmount - order.OrderActualAmount)
|
|
|
213
|
+ }
|
|
|
214
|
+ list = append(list, item)
|
|
|
215
|
+ }
|
|
|
216
|
+
|
196
|
if err = transactionContext.CommitTransaction(); err != nil {
|
217
|
if err = transactionContext.CommitTransaction(); err != nil {
|
197
|
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
218
|
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
198
|
}
|
219
|
}
|
199
|
- return count, OrderPayments, nil
|
220
|
+ return count, list, nil
|
200
|
} |
221
|
} |