|
@@ -317,6 +317,7 @@ func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(queryOp |
|
@@ -317,6 +317,7 @@ func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(queryOp |
317
|
Limit int `json:"limit" valid:"Required"`
|
317
|
Limit int `json:"limit" valid:"Required"`
|
318
|
Offset int `json:"offset"`
|
318
|
Offset int `json:"offset"`
|
319
|
OrgId int64 `json:"orgId" valid:"Required"`
|
319
|
OrgId int64 `json:"orgId" valid:"Required"`
|
|
|
320
|
+ UserId int64 `json:"userId" valid:"Required"`
|
320
|
SortByActuallyPaidAmount int `json:"sortByActuallyPaidAmount" valid:"Required"`
|
321
|
SortByActuallyPaidAmount int `json:"sortByActuallyPaidAmount" valid:"Required"`
|
321
|
BeginTime time.Time `json:"beginTime"`
|
322
|
BeginTime time.Time `json:"beginTime"`
|
322
|
EndTime time.Time `json:"endTime"`
|
323
|
EndTime time.Time `json:"endTime"`
|
|
@@ -326,13 +327,23 @@ func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(queryOp |
|
@@ -326,13 +327,23 @@ func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(queryOp |
326
|
}
|
327
|
}
|
327
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
328
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
328
|
|
329
|
|
|
|
330
|
+ // 按关联相关人过滤
|
|
|
331
|
+ var retMap = make([]interface{}, 0)
|
|
|
332
|
+ contractNumbers, err := ptr.getRelevantContracts(map[string]interface{}{"userId": request.UserId})
|
|
|
333
|
+ if len(contractNumbers) == 0 {
|
|
|
334
|
+ return retMap, nil
|
|
|
335
|
+ }
|
|
|
336
|
+ if err != nil {
|
|
|
337
|
+ return retMap, err
|
|
|
338
|
+ }
|
|
|
339
|
+ queryOptions["cooperationContractNumbers"] = contractNumbers
|
|
|
340
|
+
|
329
|
var responses []usersStatisticsResponse
|
341
|
var responses []usersStatisticsResponse
|
330
|
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
|
342
|
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
|
331
|
if err := creditAccountDao.CooperationUsersDividendsStatistics(queryOptions, &responses); err != nil {
|
343
|
if err := creditAccountDao.CooperationUsersDividendsStatistics(queryOptions, &responses); err != nil {
|
332
|
return nil, err
|
344
|
return nil, err
|
333
|
}
|
345
|
}
|
334
|
|
346
|
|
335
|
- var retMap = make([]interface{}, 0)
|
|
|
336
|
for i := range responses {
|
347
|
for i := range responses {
|
337
|
retMap = append(retMap, map[string]interface{}{
|
348
|
retMap = append(retMap, map[string]interface{}{
|
338
|
"paymentAmount": responses[i].ActuallyPaidAmount,
|
349
|
"paymentAmount": responses[i].ActuallyPaidAmount,
|
|
@@ -354,21 +365,75 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query |
|
@@ -354,21 +365,75 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query |
354
|
|
365
|
|
355
|
var request = struct {
|
366
|
var request = struct {
|
356
|
OrgId int64 `json:"orgId"`
|
367
|
OrgId int64 `json:"orgId"`
|
|
|
368
|
+ UserId int64 `json:"userId"`
|
357
|
UserBaseId int64 `json:"userBaseId"`
|
369
|
UserBaseId int64 `json:"userBaseId"`
|
|
|
370
|
+ BeginTime time.Time `json:"beginTime"`
|
|
|
371
|
+ EndTime time.Time `json:"endTime"`
|
358
|
}{}
|
372
|
}{}
|
359
|
if err := LoadQueryObject(queryOptions, &request); err != nil {
|
373
|
if err := LoadQueryObject(queryOptions, &request); err != nil {
|
360
|
return nil, err
|
374
|
return nil, err
|
361
|
}
|
375
|
}
|
362
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
376
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
363
|
|
377
|
|
|
|
378
|
+ // 按关联相关人过滤
|
|
|
379
|
+ var contractNumbers []string
|
|
|
380
|
+ var err error
|
|
|
381
|
+ if request.UserId > 0 {
|
|
|
382
|
+ var retMap = make([]interface{}, 0)
|
|
|
383
|
+ contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"userId": request.UserId})
|
|
|
384
|
+ if len(contractNumbers) == 0 {
|
|
|
385
|
+ return retMap, nil
|
|
|
386
|
+ }
|
|
|
387
|
+ if err != nil {
|
|
|
388
|
+ return retMap, err
|
|
|
389
|
+ }
|
|
|
390
|
+ queryOptions["cooperationContractNumbers"] = contractNumbers
|
|
|
391
|
+ }
|
|
|
392
|
+
|
364
|
var dividends = &CreditAccountStatisticsResponse{}
|
393
|
var dividends = &CreditAccountStatisticsResponse{}
|
|
|
394
|
+ var xAxisData []string
|
|
|
395
|
+ var values []float64
|
|
|
396
|
+ var queryItems []queryItem
|
|
|
397
|
+ if !request.BeginTime.IsZero() && request.BeginTime.AddDate(0, 3, 0).Before(request.EndTime) {
|
|
|
398
|
+ queryItems, xAxisData = histogramStatisticsByYear()
|
|
|
399
|
+ } else {
|
|
|
400
|
+ queryItems, xAxisData = histogramStatisticsByMonth()
|
|
|
401
|
+ }
|
|
|
402
|
+ for i := range queryItems {
|
|
|
403
|
+ item := queryItems[i]
|
|
|
404
|
+ if len(contractNumbers) == 0 && request.UserId > 0 { //没有相关的合约 查看分红预算单为空
|
|
|
405
|
+ continue
|
|
|
406
|
+ }
|
|
|
407
|
+ queryOptions["beginTime"] = item.BeginTime
|
|
|
408
|
+ queryOptions["endTime"] = item.EndTime
|
|
|
409
|
+ if err := creditAccountDao.DividendsStatistics(queryOptions, dividends); err != nil {
|
|
|
410
|
+ return nil, err
|
|
|
411
|
+ }
|
|
|
412
|
+ values = append(values, dividends.Paid)
|
|
|
413
|
+ }
|
|
|
414
|
+ return map[string]interface{}{
|
|
|
415
|
+ "xAxis": map[string]interface{}{
|
|
|
416
|
+ "data": xAxisData,
|
|
|
417
|
+ },
|
|
|
418
|
+ "source": map[string]interface{}{
|
|
|
419
|
+ "value": values,
|
|
|
420
|
+ },
|
|
|
421
|
+ }, nil
|
|
|
422
|
+}
|
|
|
423
|
+
|
|
|
424
|
+type queryItem struct {
|
|
|
425
|
+ BeginTime time.Time
|
|
|
426
|
+ EndTime time.Time
|
|
|
427
|
+}
|
|
|
428
|
+
|
|
|
429
|
+func histogramStatisticsByMonth() ([]queryItem, []string) {
|
|
|
430
|
+ ret := make([]queryItem, 0)
|
365
|
year, month := time.Now().Year(), time.Now().Month()
|
431
|
year, month := time.Now().Year(), time.Now().Month()
|
366
|
var beginTime = time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
|
432
|
var beginTime = time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
|
367
|
var endTime time.Time
|
433
|
var endTime time.Time
|
368
|
var increaseDay = 5
|
434
|
var increaseDay = 5
|
369
|
var monthEnd = time.Date(year, month+1, 1, 0, 0, 0, 0, time.Local).Add(-time.Second)
|
435
|
var monthEnd = time.Date(year, month+1, 1, 0, 0, 0, 0, time.Local).Add(-time.Second)
|
370
|
var xAxisData []string
|
436
|
var xAxisData []string
|
371
|
- var values []float64
|
|
|
372
|
for {
|
437
|
for {
|
373
|
if beginTime.AddDate(0, 0, increaseDay).After(monthEnd) {
|
438
|
if beginTime.AddDate(0, 0, increaseDay).After(monthEnd) {
|
374
|
endTime = monthEnd
|
439
|
endTime = monthEnd
|
|
@@ -376,25 +441,30 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query |
|
@@ -376,25 +441,30 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query |
376
|
} else {
|
441
|
} else {
|
377
|
endTime = beginTime.AddDate(0, 0, increaseDay).Add(-time.Second)
|
442
|
endTime = beginTime.AddDate(0, 0, increaseDay).Add(-time.Second)
|
378
|
}
|
443
|
}
|
379
|
- xAxisData = append(xAxisData, endTime.Format("01-02"))
|
|
|
380
|
- queryOptions["beginTime"] = beginTime
|
|
|
381
|
- queryOptions["endTime"] = beginTime.AddDate(0, 0, increaseDay)
|
|
|
382
|
- if err := creditAccountDao.DividendsStatistics(queryOptions, dividends); err != nil {
|
|
|
383
|
- return nil, err
|
444
|
+ item := queryItem{
|
|
|
445
|
+ BeginTime: beginTime,
|
|
|
446
|
+ EndTime: beginTime.AddDate(0, 0, increaseDay).Add(-time.Second),
|
384
|
}
|
447
|
}
|
385
|
- dividends.Accounting = dividends.Total - dividends.Accounted
|
|
|
386
|
- values = append(values, dividends.Paid)
|
448
|
+ xAxisData = append(xAxisData, item.EndTime.Format("01-02"))
|
387
|
beginTime = endTime
|
449
|
beginTime = endTime
|
388
|
if endTime == monthEnd {
|
450
|
if endTime == monthEnd {
|
389
|
break
|
451
|
break
|
390
|
}
|
452
|
}
|
|
|
453
|
+ ret = append(ret, item)
|
391
|
}
|
454
|
}
|
392
|
- return map[string]interface{}{
|
|
|
393
|
- "xAxis": map[string]interface{}{
|
|
|
394
|
- "data": xAxisData,
|
|
|
395
|
- },
|
|
|
396
|
- "source": map[string]interface{}{
|
|
|
397
|
- "value": values,
|
|
|
398
|
- },
|
|
|
399
|
- }, nil
|
455
|
+ return ret, xAxisData
|
|
|
456
|
+}
|
|
|
457
|
+
|
|
|
458
|
+func histogramStatisticsByYear() ([]queryItem, []string) {
|
|
|
459
|
+ ret := make([]queryItem, 0)
|
|
|
460
|
+ var xAxisData = []string{"3月", "6月", "9月", "12月"}
|
|
|
461
|
+ year, _ := time.Now().Year(), time.Now().Month()
|
|
|
462
|
+ var increase = 3
|
|
|
463
|
+ for i := 0; i < 4; i++ {
|
|
|
464
|
+ ret = append(ret, queryItem{
|
|
|
465
|
+ BeginTime: time.Date(year, time.Month(1+i*increase), 1, 0, 0, 0, 0, time.Local),
|
|
|
466
|
+ EndTime: time.Date(year, time.Month(1+(i+1)*increase), 1, 0, 0, 0, 0, time.Local),
|
|
|
467
|
+ })
|
|
|
468
|
+ }
|
|
|
469
|
+ return ret, xAxisData
|
400
|
} |
470
|
} |