作者 yangfu

合约 分红明细修改

@@ -76,7 +76,7 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa @@ -76,7 +76,7 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa
76 query.ColumnExpr(`sum((case when payment_status = 1 then settlement_amount else 0 end)) unpaid`) 76 query.ColumnExpr(`sum((case when payment_status = 1 then settlement_amount else 0 end)) unpaid`)
77 query.ColumnExpr(`sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted `) 77 query.ColumnExpr(`sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted `)
78 if v, ok := queryOptions["beginTime"]; ok && !(v.(time.Time).IsZero()) { 78 if v, ok := queryOptions["beginTime"]; ok && !(v.(time.Time).IsZero()) {
79 - query.Where(`created_at>? `, queryOptions["beginTime"]) 79 + query.Where(`created_at>=? `, queryOptions["beginTime"])
80 query.Where(`created_at<? `, queryOptions["endTime"]) 80 query.Where(`created_at<? `, queryOptions["endTime"])
81 } 81 }
82 if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 { 82 if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 {
@@ -506,7 +506,7 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query @@ -506,7 +506,7 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query
506 var values []float64 506 var values []float64
507 var queryItems []queryItem 507 var queryItems []queryItem
508 if !request.BeginTime.IsZero() && request.BeginTime.AddDate(0, 3, 0).Before(request.EndTime) { 508 if !request.BeginTime.IsZero() && request.BeginTime.AddDate(0, 3, 0).Before(request.EndTime) {
509 - queryItems, xAxisData = histogramStatisticsByYear() 509 + queryItems, xAxisData = histogramStatisticsByYear(request.BeginTime)
510 } else { 510 } else {
511 queryItems, xAxisData = histogramStatisticsByMonth() 511 queryItems, xAxisData = histogramStatisticsByMonth()
512 } 512 }
@@ -566,10 +566,10 @@ func histogramStatisticsByMonth() ([]queryItem, []string) { @@ -566,10 +566,10 @@ func histogramStatisticsByMonth() ([]queryItem, []string) {
566 return ret, xAxisData 566 return ret, xAxisData
567 } 567 }
568 568
569 -func histogramStatisticsByYear() ([]queryItem, []string) { 569 +func histogramStatisticsByYear(beginTime time.Time) ([]queryItem, []string) {
570 ret := make([]queryItem, 0) 570 ret := make([]queryItem, 0)
571 var xAxisData = []string{"3月", "6月", "9月", "12月"} 571 var xAxisData = []string{"3月", "6月", "9月", "12月"}
572 - year, _ := time.Now().Year(), time.Now().Month() 572 + year := beginTime.Year()
573 var increase = 3 573 var increase = 3
574 for i := 0; i < 4; i++ { 574 for i := 0; i < 4; i++ {
575 ret = append(ret, queryItem{ 575 ret = append(ret, queryItem{
@@ -9,7 +9,6 @@ import ( @@ -9,7 +9,6 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
12 - "strconv"  
13 "time" 12 "time"
14 ) 13 )
15 14
@@ -297,7 +296,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -297,7 +296,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
297 } 296 }
298 297
299 // 2.合约分红列表 298 // 2.合约分红列表
300 - creditAccountRepository, _ := repository.NewCreditAccountRepository(ptr.transactionContext) 299 + creditAccountRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
301 queryOptions["cooperationContractNumber"] = contract.CooperationContractNumber 300 queryOptions["cooperationContractNumber"] = contract.CooperationContractNumber
302 _, creditAccounts, err := creditAccountRepository.Find(queryOptions) 301 _, creditAccounts, err := creditAccountRepository.Find(queryOptions)
303 if err != nil { 302 if err != nil {
@@ -308,11 +307,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -308,11 +307,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
308 var orderGoodIds []int64 307 var orderGoodIds []int64
309 for i := range creditAccounts { 308 for i := range creditAccounts {
310 a := creditAccounts[i] 309 a := creditAccounts[i]
311 - for j := range a.AccountDetail {  
312 - if a.AccountDetail[j].OrderGoodId > 0 {  
313 - orderGoodIds = append(orderGoodIds, a.AccountDetail[j].OrderGoodId)  
314 - }  
315 - } 310 + orderGoodIds = append(orderGoodIds, a.OrderGoodId)
316 } 311 }
317 var mapOrderGoods = make(map[int64]*domain.OrderGood) 312 var mapOrderGoods = make(map[int64]*domain.OrderGood)
318 if len(orderGoodIds) > 0 { 313 if len(orderGoodIds) > 0 {
@@ -329,35 +324,30 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -329,35 +324,30 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
329 var dividends = make([]interface{}, 0) 324 var dividends = make([]interface{}, 0)
330 for i := range creditAccounts { 325 for i := range creditAccounts {
331 a := creditAccounts[i] 326 a := creditAccounts[i]
332 - for j := range a.AccountDetail {  
333 - participateType, _ := strconv.Atoi(a.ParticipateType)  
334 - detail := a.AccountDetail[j]  
335 - item := map[string]interface{}{  
336 - "creditAccountId": a.CreditAccountId,  
337 - "orderGoodName": "",  
338 - "dividendsType": 0,  
339 - "dividendsRatio": 0,  
340 - "dividendsAmount": detail.DividendsAmount,  
341 - "dividendsUser": map[string]interface{}{  
342 - "userInfo": a.Participator.UserInfo,  
343 - "userId": a.Participator.UserId,  
344 - },  
345 - "dividendsParticipateType": participateType,  
346 - "dividendsAccountStatus": a.PaymentStatus,  
347 - "dividendsEstimateTime": a.CreatedAt.Unix() * 1000,  
348 - "orderOrReturnedOrderNum": a.CreditAccountOrderNum,  
349 - }  
350 - if detail.OrderGoodAmount > 0 {  
351 - item["dividendsRatio"] = utils.Round(detail.DividendsAmount/detail.OrderGoodAmount*100, 2)  
352 - }  
353 - item["dividendsType"] = a.AccountDetail[j].DividendsType  
354 - if v, ok := mapOrderGoods[detail.OrderGoodId]; ok {  
355 - item["orderGoodName"] = v.OrderGoodName  
356 - }  
357 327
358 - dividends = append(dividends, item) 328 + participateType := a.DividendsParticipateType
  329 + item := map[string]interface{}{
  330 + "creditAccountId": a.DividendsEstimateId,
  331 + "orderGoodName": "",
  332 + "dividendsType": a.DividendsType,
  333 + "dividendsRatio": 0,
  334 + "dividendsAmount": a.DividendsAmount,
  335 + "dividendsUser": map[string]interface{}{
  336 + "userInfo": a.DividendsUser.UserInfo,
  337 + "userId": a.DividendsUser.UserId,
  338 + },
  339 + "dividendsParticipateType": participateType,
  340 + "dividendsAccountStatus": 0, //TODO:分红状态
  341 + "dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
  342 + "orderOrReturnedOrderNum": a.DividendsEstimateOrderNumber,
359 } 343 }
360 - 344 + if v, ok := mapOrderGoods[a.OrderGoodId]; ok {
  345 + item["orderGoodName"] = v.OrderGoodName
  346 + if v.OrderGoodAmount > 0 {
  347 + item["dividendsRatio"] = utils.Round(a.DividendsAmount/v.OrderGoodAmount*100, 2)
  348 + }
  349 + }
  350 + dividends = append(dividends, item)
361 } 351 }
362 res["dividends"] = dividends 352 res["dividends"] = dividends
363 return res, nil 353 return res, nil