|
@@ -9,6 +9,7 @@ import ( |
|
@@ -9,6 +9,7 @@ import ( |
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
|
|
|
12
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
12
|
"strconv"
|
13
|
"strconv"
|
13
|
"time"
|
14
|
"time"
|
14
|
)
|
15
|
)
|
|
@@ -103,21 +104,16 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
|
@@ -103,21 +104,16 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
103
|
results = append(results, resultItem)
|
104
|
results = append(results, resultItem)
|
104
|
numbers = append(numbers, item.CooperationContractNumber)
|
105
|
numbers = append(numbers, item.CooperationContractNumber)
|
105
|
}
|
106
|
}
|
106
|
- mapEstimate, err := ptr.getContractsDividendsEstimate(numbers)
|
107
|
+ mapCreditAccount, err := ptr.getContractsCreditAccount(numbers)
|
107
|
if err != nil {
|
108
|
if err != nil {
|
108
|
return nil, err
|
109
|
return nil, err
|
109
|
}
|
110
|
}
|
110
|
for i := range results {
|
111
|
for i := range results {
|
111
|
- if v, ok := mapEstimate[results[i].CooperationContractNumber]; ok {
|
|
|
112
|
- results[i].DividendsAmount = v.DividendsAmount
|
112
|
+ if v, ok := mapCreditAccount[results[i].CooperationContractNumber]; ok {
|
|
|
113
|
+ results[i].DividendsAmount = v.SettlementAmount
|
|
|
114
|
+ results[i].DividendsOrderAmount = v.GoodAmountCount
|
113
|
}
|
115
|
}
|
114
|
}
|
116
|
}
|
115
|
-
|
|
|
116
|
- // TODO: 3.根据合约查询订单金额
|
|
|
117
|
- //for i:=range results{
|
|
|
118
|
- // queryOptions["cooperationContractNumber"] =results[i].CooperationContractNumber
|
|
|
119
|
- // results[i].DividendsOrderAmount = ptr.CalculateOrderAmount(queryOptions)
|
|
|
120
|
- //}
|
|
|
121
|
return results, nil
|
117
|
return results, nil
|
122
|
}
|
118
|
}
|
123
|
|
119
|
|
|
@@ -171,6 +167,33 @@ group by cooperation_contract_number |
|
@@ -171,6 +167,33 @@ group by cooperation_contract_number |
171
|
return resMap, nil
|
167
|
return resMap, nil
|
172
|
}
|
168
|
}
|
173
|
|
169
|
|
|
|
170
|
+// getContractsDividendsEstimate 合约分红预算
|
|
|
171
|
+func (ptr *CooperationStatisticsService) getContractsCreditAccount(numbers []string) (map[string]*domain.CreditAccount, error) {
|
|
|
172
|
+ var creditAccounts []*domain.CreditAccount
|
|
|
173
|
+ var resMap = make(map[string]*domain.CreditAccount)
|
|
|
174
|
+ if len(numbers) == 0 {
|
|
|
175
|
+ return resMap, nil
|
|
|
176
|
+ }
|
|
|
177
|
+ var creditAccount = new(domain.CreditAccount)
|
|
|
178
|
+
|
|
|
179
|
+ query := ptr.transactionContext.PgDd.Model(creditAccount)
|
|
|
180
|
+ query.Column("cooperation_contract_number")
|
|
|
181
|
+ query.ColumnExpr("sum(good_amount_count) good_amount_count")
|
|
|
182
|
+ query.ColumnExpr("sum(settlement_amount) settlement_amount")
|
|
|
183
|
+ query.Where("cooperation_contract_number in (?)", pg.In(numbers))
|
|
|
184
|
+ query.Where("deleted_at is null")
|
|
|
185
|
+ query.Group("cooperation_contract_number")
|
|
|
186
|
+ err := query.Select(&creditAccounts)
|
|
|
187
|
+ if err != nil {
|
|
|
188
|
+ return nil, err
|
|
|
189
|
+ }
|
|
|
190
|
+
|
|
|
191
|
+ for i := range creditAccounts {
|
|
|
192
|
+ resMap[creditAccounts[i].CooperationContractNumber] = creditAccounts[i]
|
|
|
193
|
+ }
|
|
|
194
|
+ return resMap, nil
|
|
|
195
|
+}
|
|
|
196
|
+
|
174
|
type searchContractDividendsResult struct {
|
197
|
type searchContractDividendsResult struct {
|
175
|
// 共创合约ID
|
198
|
// 共创合约ID
|
176
|
CooperationContractId int64 `json:"cooperationContractId,string"`
|
199
|
CooperationContractId int64 `json:"cooperationContractId,string"`
|
|
@@ -220,17 +243,40 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s |
|
@@ -220,17 +243,40 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s |
220
|
if err != nil {
|
243
|
if err != nil {
|
221
|
return res, err
|
244
|
return res, err
|
222
|
}
|
245
|
}
|
|
|
246
|
+
|
|
|
247
|
+ // 3.取订单商品列表
|
|
|
248
|
+ var orderGoodIds []int64
|
|
|
249
|
+ for i := range creditAccounts {
|
|
|
250
|
+ a := creditAccounts[i]
|
|
|
251
|
+ for j := range a.AccountDetail {
|
|
|
252
|
+ if a.AccountDetail[j].OrderGoodId > 0 {
|
|
|
253
|
+ orderGoodIds = append(orderGoodIds, a.AccountDetail[j].OrderGoodId)
|
|
|
254
|
+ }
|
|
|
255
|
+ }
|
|
|
256
|
+ }
|
|
|
257
|
+
|
|
|
258
|
+ orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext)
|
|
|
259
|
+ _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds})
|
|
|
260
|
+ if err != nil {
|
|
|
261
|
+ return res, err
|
|
|
262
|
+ }
|
|
|
263
|
+ var mapOrderGoods = make(map[int64]*domain.OrderGood)
|
|
|
264
|
+ for i := range orderGoods {
|
|
|
265
|
+ mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i]
|
|
|
266
|
+ }
|
|
|
267
|
+
|
223
|
var dividends = make([]interface{}, 0)
|
268
|
var dividends = make([]interface{}, 0)
|
224
|
for i := range creditAccounts {
|
269
|
for i := range creditAccounts {
|
225
|
a := creditAccounts[i]
|
270
|
a := creditAccounts[i]
|
226
|
for j := range a.AccountDetail {
|
271
|
for j := range a.AccountDetail {
|
227
|
participateType, _ := strconv.Atoi(a.ParticipateType)
|
272
|
participateType, _ := strconv.Atoi(a.ParticipateType)
|
|
|
273
|
+ detail := a.AccountDetail[j]
|
228
|
item := map[string]interface{}{
|
274
|
item := map[string]interface{}{
|
229
|
"creditAccountId": a.CreditAccountId,
|
275
|
"creditAccountId": a.CreditAccountId,
|
230
|
"orderGoodName": "",
|
276
|
"orderGoodName": "",
|
231
|
"dividendsType": 0,
|
277
|
"dividendsType": 0,
|
232
|
"dividendsRatio": 0,
|
278
|
"dividendsRatio": 0,
|
233
|
- "dividendsAmount": a.AccountDetail[j].DividendsAmount,
|
279
|
+ "dividendsAmount": detail.DividendsAmount,
|
234
|
"dividendsUser": map[string]interface{}{
|
280
|
"dividendsUser": map[string]interface{}{
|
235
|
"userInfo": a.Participator.UserInfo,
|
281
|
"userInfo": a.Participator.UserInfo,
|
236
|
"userId": a.Participator.UserId,
|
282
|
"userId": a.Participator.UserId,
|
|
@@ -240,7 +286,14 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s |
|
@@ -240,7 +286,14 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s |
240
|
"dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
|
286
|
"dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
|
241
|
"orderOrReturnedOrderNum": a.CreditAccountOrderNum,
|
287
|
"orderOrReturnedOrderNum": a.CreditAccountOrderNum,
|
242
|
}
|
288
|
}
|
|
|
289
|
+ if detail.OrderGoodAmount > 0 {
|
|
|
290
|
+ item["dividendsRatio"] = utils.Round(detail.DividendsAmount/detail.OrderGoodAmount*100, 2)
|
|
|
291
|
+ }
|
243
|
item["dividendsType"] = a.AccountDetail[j].DividendsType
|
292
|
item["dividendsType"] = a.AccountDetail[j].DividendsType
|
|
|
293
|
+ if v, ok := mapOrderGoods[detail.OrderGoodId]; ok {
|
|
|
294
|
+ item["orderGoodName"] = v.OrderGoodName
|
|
|
295
|
+ }
|
|
|
296
|
+
|
244
|
dividends = append(dividends, item)
|
297
|
dividends = append(dividends, item)
|
245
|
}
|
298
|
}
|
246
|
|
299
|
|