陈少旭 4 months ago
parent
commit
362eb2ebdd

+ 38 - 86
controllers/admin_api_controllers/analysis_api_controller.go View File

1
 package admin_api_controllers
1
 package admin_api_controllers
2
 
2
 
3
 import (
3
 import (
4
-	"XT_Admin_Api/models/admin_models"
5
 	"XT_Admin_Api/service"
4
 	"XT_Admin_Api/service"
6
-	"XT_Admin_Api/utils"
7
-	"time"
8
 )
5
 )
9
 
6
 
10
 type AnalysisAPIController struct {
7
 type AnalysisAPIController struct {
12
 }
9
 }
13
 
10
 
14
 func (this *AnalysisAPIController) HomeStatistics() {
11
 func (this *AnalysisAPIController) HomeStatistics() {
15
-	range_data := this.GetString("range_data")
16
-	range_type, _ := this.GetInt64("range_type")
17
-	var rangeDate *time.Time
18
-	var parseDateErr error
19
-	var rangeTimeStamp int64
12
+	customCount, _ := service.GetCustomCount()
13
+	curYearCustomCount, _ := service.GetCurYearCustomCount()
14
+	curYearStandCustomCount, _ := service.GetCurYearStandCustomCount()
20
 
15
 
21
-	if len(range_data) > 0 {
22
-		rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
23
-		if parseDateErr != nil {
24
-			this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
25
-			return
26
-		}
27
-		rangeTimeStamp = rangeDate.Unix()
28
-	} else {
29
-		rangeTimeStamp = 0
30
-	}
31
-	now := time.Now().Unix()
16
+	curYearDeluxeCustomCount, _ := service.GetCurYearDeluxeCustomCount()
17
+	curYearProfessionalCustomCount, _ := service.GetCurYearProfessionalCustomCount()
32
 
18
 
33
-	newOrgCount, _ := service.GetRegistedOrgCount(rangeTimeStamp, now)
34
-	totalOrg, _ := service.GetTotalOrgCount()
35
-	activeOrgCount, _ := service.GetActiveOrgCount(rangeTimeStamp, now)
36
-	totalActiveOrg, _ := service.GetActiveOrgTotalCount()
37
-	activeAdminCount, _ := service.GetActiveAdminUserCount(rangeTimeStamp, now)
38
-	adminTotalCount, _ := service.GetAdminUserTotalCount()
39
-	patientCount, _ := service.GetNewPatientCount(rangeTimeStamp, now)
40
-	patientTotalCount, _ := service.GetPatientTotalCount()
19
+	curYearOtherCustomCount, _ := service.GetCurYearOtherCustomCount()
20
+	curYearContractPriceCount, _ := service.GetCurYearContractPriceCount()
21
+	curYearSoftwarePriceCount, _ := service.GetCurYearSoftwarePriceCount()
41
 
22
 
42
-	var orgRegisterStatistics []*admin_models.Statistics
43
-	var newPatientStatistics []*admin_models.Statistics
44
-	var orgActiveAdminStatistics []*admin_models.Statistics
45
-	var orgActiveStatistics []*admin_models.Statistics
23
+	curYearHardwarePriceCount, _ := service.GetCurYearHardwarePriceCount()
46
 
24
 
47
-	switch range_type {
48
-	case 1:
25
+	curYearPaymentCollectionSumamtPriceCount, _ := service.GetCurYearPaymentCollectionSumamtPriceCount()
26
+	curYearPaymentCollectionSoftwarePriceCount, _ := service.GetCurYearPaymentCollectionSoftwarePriceCount()
49
 
27
 
50
-		break
28
+	curYearPaymentCollectionHardwarePriceCount, _ := service.GetCurYearPaymentCollectionHardwarePriceCount()
29
+	oneMonthCount := service.GetOneMonthEndDate()
30
+	threeMontheCount := service.GetThreeMonthEndDate()
51
 
31
 
52
-	case 2:
53
-		orgRegisterStatistics, _ = service.GetYesterDayRegistedOrgCount()
54
-		newPatientStatistics, _ = service.GetYesterDayNewPatientCount()
55
-		orgActiveAdminStatistics, _ = service.GetYesterDayActiveAdminUserCount()
56
-		orgActiveStatistics, _ = service.GetYesterDayActiveOrgCount()
32
+	_, curYearRenewalCount := service.GetCurYearRenewal()
33
+	_, curYearPaymentCollectionCount := service.GetCurYearPaymentCollection()
57
 
34
 
58
-		break
59
-	case 3:
60
-		orgRegisterStatistics, _ = service.GetWeekRegistedOrgCount()
61
-		newPatientStatistics, _ = service.GetWeekNewPatientCount()
62
-		orgActiveAdminStatistics, _ = service.GetWeekActiveAdminUserCount()
63
-		orgActiveStatistics, _ = service.GetWeekActiveOrgCount()
35
+	curYearWaitPutIntoEffectCount, _ := service.GetCurYearWaitPutIntoEffect()
36
+	curYearWaitAbutmentCount, _ := service.GetCurYearWaitAbutment()
64
 
37
 
65
-		break
66
-	case 4:
67
-		orgRegisterStatistics, _ = service.GetMonthRegistedOrgCount()
68
-		newPatientStatistics, _ = service.GetMonthNewPatientCount()
69
-		orgActiveAdminStatistics, _ = service.GetMonthActiveAdminUserCount()
70
-		orgActiveStatistics, _ = service.GetMonthActiveOrgCount()
71
-
72
-		break
73
-	case 5:
74
-		orgRegisterStatistics, _ = service.GetThreeMonthRegistedOrgCount()
75
-		newPatientStatistics, _ = service.GetThreeMonthNewPatientCount()
76
-		orgActiveAdminStatistics, _ = service.GetThreeMonthActiveAdminUserCount()
77
-		orgActiveStatistics, _ = service.GetThreeMonthActiveOrgCount()
78
-
79
-		break
80
-	case 6:
81
-		orgRegisterStatistics, _ = service.GetSixMonthRegistedOrgCount()
82
-		newPatientStatistics, _ = service.GetSixMonthNewPatientCount()
83
-		orgActiveAdminStatistics, _ = service.GetSixMonthActiveAdminUserCount()
84
-		orgActiveStatistics, _ = service.GetSixMonthActiveOrgCount()
85
-
86
-		break
87
-	case 7:
88
-		orgRegisterStatistics, _ = service.GetYearRegistedOrgCount()
89
-		newPatientStatistics, _ = service.GetYearNewPatientCount()
90
-		orgActiveAdminStatistics, _ = service.GetYearActiveAdminUserCount()
91
-		orgActiveStatistics, _ = service.GetYearActiveOrgCount()
92
-		break
93
-	}
38
+	cure := service.GetCurePrice()
94
 
39
 
95
 	this.ServeSuccessJSON(map[string]interface{}{
40
 	this.ServeSuccessJSON(map[string]interface{}{
96
-		"org_count":                newOrgCount,
97
-		"org_total_count":          totalOrg,
98
-		"active_org_count":         activeOrgCount,
99
-		"active_org_total_count":   totalActiveOrg,
100
-		"active_admin_count":       activeAdminCount,
101
-		"active_admin_total_count": adminTotalCount,
102
-		"patient_count":            patientCount,
103
-		"patient_total_count":      patientTotalCount,
104
-		"org_count_list":           orgRegisterStatistics,
105
-		"patient_count_list":       newPatientStatistics,
106
-		"active_count_list":        orgActiveAdminStatistics,
107
-		"active_org_list":          orgActiveStatistics,
41
+		"customCount":                                customCount,
42
+		"curYearCustomCount":                         curYearCustomCount,
43
+		"curYearStandCustomCount":                    curYearStandCustomCount,
44
+		"curYearDeluxeCustomCount":                   curYearDeluxeCustomCount,
45
+		"curYearProfessionalCustomCount":             curYearProfessionalCustomCount,
46
+		"curYearOtherCustomCount":                    curYearOtherCustomCount,
47
+		"curYearContractPriceCount":                  curYearContractPriceCount,
48
+		"curYearSoftwarePriceCount":                  curYearSoftwarePriceCount,
49
+		"curYearHardwarePriceCount":                  curYearHardwarePriceCount,
50
+		"curYearPaymentCollectionSumamtPriceCount":   curYearPaymentCollectionSumamtPriceCount,
51
+		"curYearPaymentCollectionSoftwarePriceCount": curYearPaymentCollectionSoftwarePriceCount,
52
+		"curYearPaymentCollectionHardwarePriceCount": curYearPaymentCollectionHardwarePriceCount,
53
+		"oneMonthCount":                              oneMonthCount,
54
+		"threeMontheCount":                           threeMontheCount,
55
+		"curYearRenewalCount":                        curYearRenewalCount,
56
+		"curYearPaymentCollectionCount":              curYearPaymentCollectionCount,
57
+		"curYearWaitPutIntoEffectCount":              curYearWaitPutIntoEffectCount,
58
+		"curYearWaitAbutmentCount":                   curYearWaitAbutmentCount,
59
+		"cure":                                       cure,
108
 	})
60
 	})
109
 
61
 
110
 }
62
 }

+ 1 - 1
controllers/admin_api_controllers/custom_api_controller.go View File

1125
 	defer redisClient.Close()
1125
 	defer redisClient.Close()
1126
 
1126
 
1127
 	token, err := redisClient.Get("qn_token").Result()
1127
 	token, err := redisClient.Get("qn_token").Result()
1128
-
1128
+	fmt.Println(token)
1129
 	if err != nil {
1129
 	if err != nil {
1130
 		defer fmt.Println(err)
1130
 		defer fmt.Println(err)
1131
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGetQiniuUpToken)
1131
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGetQiniuUpToken)

+ 1 - 0
models/custom.go View File

319
 	Remark          string `gorm:"column:remark" json:"remark" form:"remark"`
319
 	Remark          string `gorm:"column:remark" json:"remark" form:"remark"`
320
 	IsCheck         int64  `gorm:"column:is_check" json:"is_check" form:"is_check"`
320
 	IsCheck         int64  `gorm:"column:is_check" json:"is_check" form:"is_check"`
321
 	CheckPerson     string `gorm:"column:check_person" json:"check_person" form:"check_person"`
321
 	CheckPerson     string `gorm:"column:check_person" json:"check_person" form:"check_person"`
322
+	RenewalPrice    string `gorm:"column:renewal_price" json:"renewal_price" form:"renewal_price"`
322
 }
323
 }
323
 
324
 
324
 func (KyyChargeRenewal) TableName() string {
325
 func (KyyChargeRenewal) TableName() string {

+ 2 - 2
routers/router.go View File

8
 
8
 
9
 func init() {
9
 func init() {
10
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
10
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
11
-		// AllowAllOrigins:  true,
12
-		AllowOrigins:     []string{"http://api.szjkhd.com", "http://admin.xt.test.szjkhd.com", "http://admin.xt.szjkhd.com", "http://localhost:9527"},
11
+		AllowAllOrigins:  true,
12
+		AllowOrigins:     []string{"http://xtsf.sgjyun.com", "http://api.szjkhd.com", "http://sf.sgjyun.com", "http://admin.xt.test.szjkhd.com", "http://admin.xt.szjkhd.com", "http://localhost:9527"},
13
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
13
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
14
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
14
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
15
 		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
15
 		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},

+ 248 - 24
service/admin_service.go View File

8
 	"database/sql"
8
 	"database/sql"
9
 	"fmt"
9
 	"fmt"
10
 	"github.com/jinzhu/gorm"
10
 	"github.com/jinzhu/gorm"
11
+	"strconv"
11
 	"strings"
12
 	"strings"
13
+	"time"
12
 )
14
 )
13
 
15
 
14
 func GetAdminAccount(account string, password string) (*admin_models.AdminAccount, error) {
16
 func GetAdminAccount(account string, password string) (*admin_models.AdminAccount, error) {
502
 // 获取累积客户数
504
 // 获取累积客户数
503
 func GetCustomCount() (int64, error) {
505
 func GetCustomCount() (int64, error) {
504
 	var count int64
506
 	var count int64
505
-	err := readUserDb.Model(&models.KyyChargeCustom{}).Where("status = 1").Count(&count).Error
507
+	err := ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("status = 1").Count(&count).Error
506
 	if err != nil {
508
 	if err != nil {
507
 		return 0, err
509
 		return 0, err
508
 	}
510
 	}
512
 // 本年新增收费客户
514
 // 本年新增收费客户
513
 func GetCurYearCustomCount() (int64, error) {
515
 func GetCurYearCustomCount() (int64, error) {
514
 	var count int64
516
 	var count int64
515
-	err := readUserDb.Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE())").Count(&count).Error
517
+	err := ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(sign_time) = YEAR(CURDATE())").Count(&count).Error
516
 	if err != nil {
518
 	if err != nil {
517
 		return 0, err
519
 		return 0, err
518
 	}
520
 	}
522
 // 统计本年新增标准版客户
524
 // 统计本年新增标准版客户
523
 func GetCurYearStandCustomCount() (int64, error) {
525
 func GetCurYearStandCustomCount() (int64, error) {
524
 	var count int64
526
 	var count int64
525
-	err := readUserDb.Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE()) and custom_type = 1").Count(&count).Error
527
+	err := ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(sign_time) = YEAR(CURDATE()) and custom_type = 1").Count(&count).Error
526
 	if err != nil {
528
 	if err != nil {
527
 		return 0, err
529
 		return 0, err
528
 	}
530
 	}
532
 // 统计本年新增尊享版客户
534
 // 统计本年新增尊享版客户
533
 func GetCurYearDeluxeCustomCount() (int64, error) {
535
 func GetCurYearDeluxeCustomCount() (int64, error) {
534
 	var count int64
536
 	var count int64
535
-	err := readUserDb.Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE()) and custom_type = 2").Count(&count).Error
537
+	err := ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(sign_time) = YEAR(CURDATE()) and custom_type = 2").Count(&count).Error
536
 	if err != nil {
538
 	if err != nil {
537
 		return 0, err
539
 		return 0, err
538
 	}
540
 	}
542
 // 统计本年新增专业版客户
544
 // 统计本年新增专业版客户
543
 func GetCurYearProfessionalCustomCount() (int64, error) {
545
 func GetCurYearProfessionalCustomCount() (int64, error) {
544
 	var count int64
546
 	var count int64
545
-	err := readUserDb.Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE()) and custom_type = 3").Count(&count).Error
547
+	err := ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(sign_time) = YEAR(CURDATE()) and custom_type = 3").Count(&count).Error
546
 	if err != nil {
548
 	if err != nil {
547
 		return 0, err
549
 		return 0, err
548
 	}
550
 	}
552
 // 统计本年新增其他版客户
554
 // 统计本年新增其他版客户
553
 func GetCurYearOtherCustomCount() (int64, error) {
555
 func GetCurYearOtherCustomCount() (int64, error) {
554
 	var count int64
556
 	var count int64
555
-	err := readUserDb.Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE()) and custom_type = 4").Count(&count).Error
557
+	err := ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("status = 1 and YEAR(sign_time) = YEAR(CURDATE()) and custom_type = 4").Count(&count).Error
556
 	if err != nil {
558
 	if err != nil {
557
 		return 0, err
559
 		return 0, err
558
 	}
560
 	}
560
 }
562
 }
561
 
563
 
562
 func GetCurYearContractPriceCount() (float64, error) {
564
 func GetCurYearContractPriceCount() (float64, error) {
563
-	var count float64
564
-	err := readUserDb.Model(&models.KyyChargeContract{}).Select("sum(sumamt) as count").Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE())").Find(&count).Error
565
+	type Count struct {
566
+		Count float64
567
+	}
568
+	var count Count
569
+	err := ChargeReadDB().Model(&models.KyyChargeContract{}).Select("sum(sumamt) as count").Where("status = 1 and YEAR(start_time) = YEAR(CURDATE())").Scan(&count).Error
565
 	if err != nil {
570
 	if err != nil {
566
 		return 0, err
571
 		return 0, err
567
 	}
572
 	}
568
-	return count, nil
573
+	return count.Count, nil
569
 }
574
 }
570
 
575
 
571
 func GetCurYearSoftwarePriceCount() (float64, error) {
576
 func GetCurYearSoftwarePriceCount() (float64, error) {
572
-	var count float64
573
-	err := readUserDb.Model(&models.KyyChargeContract{}).Select("sum(software_price) as count").Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE())").Find(&count).Error
577
+	type Count struct {
578
+		Count float64
579
+	}
580
+	var count Count
581
+	err := ChargeReadDB().Model(&models.KyyChargeContract{}).Select("sum(software_price) as count").Where("status = 1 and YEAR(start_time) = YEAR(CURDATE())").Scan(&count).Error
574
 	if err != nil {
582
 	if err != nil {
575
 		return 0, err
583
 		return 0, err
576
 	}
584
 	}
577
-	return count, nil
585
+	return count.Count, nil
578
 }
586
 }
579
 
587
 
580
 func GetCurYearHardwarePriceCount() (float64, error) {
588
 func GetCurYearHardwarePriceCount() (float64, error) {
581
-	var count float64
582
-	err := readUserDb.Model(&models.KyyChargeContract{}).Select("sum(hardware_price) as count").Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE())").Find(&count).Error
589
+	type Count struct {
590
+		Count float64
591
+	}
592
+	var count Count
593
+	err := ChargeReadDB().Model(&models.KyyChargeContract{}).Select("sum(hardware_price) as count").Where("status = 1 and YEAR(start_time) = YEAR(CURDATE())").Scan(&count).Error
583
 	if err != nil {
594
 	if err != nil {
584
 		return 0, err
595
 		return 0, err
585
 	}
596
 	}
586
-	return count, nil
597
+	return count.Count, nil
587
 }
598
 }
588
 
599
 
589
 func GetCurYearPaymentCollectionSumamtPriceCount() (float64, error) {
600
 func GetCurYearPaymentCollectionSumamtPriceCount() (float64, error) {
590
-	var count float64
591
-	err := readUserDb.Model(&models.KyyChargeContract{}).Select("sum(payment_collection_sumamt) as count").Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE())").Find(&count).Error
601
+	type Count struct {
602
+		Count float64
603
+	}
604
+	var count Count
605
+	err := ChargeReadDB().Model(&models.KyyChargePaymentCollection{}).Select("sum(payment_collection_sumamt) as count").Where("status = 1 and YEAR(payment_collection_date) = YEAR(CURDATE())").Scan(&count).Error
592
 	if err != nil {
606
 	if err != nil {
593
 		return 0, err
607
 		return 0, err
594
 	}
608
 	}
595
-	return count, nil
609
+	return count.Count, nil
596
 }
610
 }
597
 
611
 
598
 func GetCurYearPaymentCollectionSoftwarePriceCount() (float64, error) {
612
 func GetCurYearPaymentCollectionSoftwarePriceCount() (float64, error) {
599
-	var count float64
600
-	err := readUserDb.Model(&models.KyyChargeContract{}).Select("sum(software_sumamt) as count").Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE())").Find(&count).Error
613
+	type Count struct {
614
+		Count float64
615
+	}
616
+	var count Count
617
+	err := ChargeReadDB().Model(&models.KyyChargePaymentCollection{}).Select("sum(software_sumamt) as count").Where("status = 1 and YEAR(payment_collection_date) = YEAR(CURDATE())").Scan(&count).Error
601
 	if err != nil {
618
 	if err != nil {
602
 		return 0, err
619
 		return 0, err
603
 	}
620
 	}
604
-	return count, nil
621
+	return count.Count, nil
605
 }
622
 }
606
 
623
 
607
 func GetCurYearPaymentCollectionHardwarePriceCount() (float64, error) {
624
 func GetCurYearPaymentCollectionHardwarePriceCount() (float64, error) {
608
-	var count float64
609
-	err := readUserDb.Model(&models.KyyChargeContract{}).Select("sum(hardware_sumamt) as count").Where("status = 1 and YEAR(FROM_UNIXTIME(ctime)) = YEAR(CURDATE())").Find(&count).Error
625
+	type Count struct {
626
+		Count float64
627
+	}
628
+	var count Count
629
+	err := ChargeReadDB().Model(&models.KyyChargePaymentCollection{}).Select("sum(hardware_sumamt) as count").Where("status = 1 and YEAR(payment_collection_date) = YEAR(CURDATE())").Scan(&count).Error
610
 	if err != nil {
630
 	if err != nil {
611
 		return 0, err
631
 		return 0, err
612
 	}
632
 	}
613
-	return count, nil
633
+	return count.Count, nil
634
+}
635
+
636
+type ChargeCustom struct {
637
+	ID            uint
638
+	Name          string
639
+	SignTime      string
640
+	SignEndTime   string
641
+	ContractPrice string
642
+	SoftwarePrice string
643
+	HardwarePrice string
644
+	Address       string
645
+	IsImplement   int
646
+	Remark        string
647
+}
648
+
649
+type ChargeRenewal struct {
650
+	ID          uint
651
+	CustomID    uint
652
+	SignEndTime string
653
+}
654
+
655
+type Results struct {
656
+	ChargeCustom
657
+	SignEndTime string
658
+}
659
+
660
+func GetOneMonthEndDate() (results []Results) {
661
+	currentDate := time.Now()
662
+	//threeMonthsLater := currentDate.AddDate(0, 3, 0)
663
+	oneMonthLater := currentDate.AddDate(0, 1, 0)
664
+	ChargeReadDB().Table("kyy_charge_custom as kc").
665
+		Select("kc.*, COALESCE(kr.end_time, kc.sign_end_time) as sign_end_time").
666
+		Joins("LEFT JOIN kyy_charge_renewal as kr ON kc.id = kr.custom_id").
667
+		Where("(kr.end_time BETWEEN ? AND ?) OR (kr.end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kc.sign_end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kc.sign_end_time BETWEEN ? AND ?)",
668
+			currentDate, oneMonthLater,
669
+			currentDate, oneMonthLater,
670
+			currentDate, oneMonthLater,
671
+
672
+			currentDate, oneMonthLater).
673
+		Scan(&results)
674
+	return
675
+}
676
+
677
+func GetThreeMonthEndDate() (results []Results) {
678
+	currentDate := time.Now()
679
+	threeMonthsLater := currentDate.AddDate(0, 3, 0)
680
+	ChargeReadDB().Table("kyy_charge_custom as kc").
681
+		Select("kc.*, COALESCE(kr.end_time, kc.sign_end_time) as sign_end_time").
682
+		Joins("LEFT JOIN kyy_charge_renewal as kr ON kc.id = kr.custom_id").
683
+		Where("(kr.end_time BETWEEN ? AND ?) OR (kr.end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kc.sign_end_time BETWEEN ? AND ?) OR (kr.end_time IS NULL AND kc.sign_end_time BETWEEN ? AND ?)",
684
+			currentDate, threeMonthsLater,
685
+			currentDate, threeMonthsLater,
686
+			currentDate, threeMonthsLater,
687
+
688
+			currentDate, threeMonthsLater).
689
+		Scan(&results)
690
+	return
691
+
692
+}
693
+
694
+func GetCurYearRenewal() (err error, count int64) {
695
+	currentYear := time.Now().Year()
696
+	err = ChargeReadDB().Model(&models.KyyChargeRenewal{}).Where("YEAR(start_time) = ?", currentYear).Count(&count).Error
697
+	if err != nil {
698
+		fmt.Println(err)
699
+	}
700
+	return
701
+}
702
+
703
+func GetCurYearPaymentCollection() (err error, count int64) {
704
+	currentYear := time.Now().Year()
705
+	var kpc []models.KyyChargePaymentCollection
706
+	err = ChargeReadDB().Model(&models.KyyChargePaymentCollection{}).Where("YEAR(payment_collection_date) = ? and payment_collection_type = 1", currentYear).Find(&kpc).Error
707
+	if err != nil {
708
+		fmt.Println(err)
709
+	}
710
+	count = 0
711
+	for _, item := range kpc {
712
+		pcs, _ := strconv.ParseInt(item.PaymentCollectionSumamt, 10, 64)
713
+		count = count + pcs
714
+	}
715
+	return
716
+}
717
+
718
+func GetCurYearWaitPutIntoEffect() (count int64, err error) {
719
+	currentYear := time.Now().Year()
720
+	err = ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("YEAR(sign_time) = ? and is_implement = 0", currentYear).Count(&count).Error
721
+	if err != nil {
722
+		fmt.Println(err)
723
+	}
724
+	return
725
+}
726
+
727
+func GetCurYearWaitAbutment() (count int64, err error) {
728
+	currentYear := time.Now().Year()
729
+	err = ChargeReadDB().Model(&models.KyyChargeCustom{}).Where("(YEAR(sign_time) = ? and lis_status = 0) or (YEAR(sign_time) = ? and qc_status = 0) or (YEAR(sign_time) = ? and yb_status = 0)", currentYear, currentYear, currentYear).Count(&count).Error
730
+	if err != nil {
731
+		fmt.Println(err)
732
+	}
733
+	return
734
+}
735
+
736
+type ContractData struct {
737
+	Month                  int     `json:"month"`
738
+	TotalContractAmount    float64 `json:"total_contract_amount"`
739
+	SoftwareContractAmount float64 `json:"software_contract_amount"`
740
+	HardwareContractAmount float64 `json:"hardware_contract_amount"`
741
+}
742
+
743
+type PaymentData struct {
744
+	Month                 int     `json:"month"`
745
+	TotalPaymentAmount    float64 `json:"total_payment_amount"`
746
+	SoftwarePaymentAmount float64 `json:"software_payment_amount"`
747
+	HardwarePaymentAmount float64 `json:"hardware_payment_amount"`
748
+}
749
+
750
+type MonthlyData struct {
751
+	Month                  int     `json:"month"`
752
+	TotalContractAmount    float64 `json:"total_contract_amount"`
753
+	SoftwareContractAmount float64 `json:"software_contract_amount"`
754
+	HardwareContractAmount float64 `json:"hardware_contract_amount"`
755
+	TotalPaymentAmount     float64 `json:"total_payment_amount"`
756
+	SoftwarePaymentAmount  float64 `json:"software_payment_amount"`
757
+	HardwarePaymentAmount  float64 `json:"hardware_payment_amount"`
758
+
759
+	RenewalPrice float64 `json:"renewal_price"`
760
+}
761
+
762
+type MonthlyRenewalData struct {
763
+	Month        int     `json:"month"`
764
+	RenewalPrice float64 `json:"renewal_price"`
765
+}
766
+
767
+func GetCurePrice() (aa map[int]*MonthlyData) {
768
+	// 查询合同金额
769
+	var contractResults []ContractData
770
+	ChargeReadDB().Raw(`
771
+		SELECT
772
+			MONTH(sign_time) AS month,
773
+			SUM(CAST(contract_price AS DECIMAL(10, 2))) AS total_contract_amount,
774
+			SUM(CAST(software_price AS DECIMAL(10, 2))) AS software_contract_amount,
775
+			SUM(CAST(hardware_price AS DECIMAL(10, 2))) AS hardware_contract_amount
776
+		FROM kyy_charge_custom
777
+		GROUP BY MONTH((sign_time))
778
+		ORDER BY MONTH((sign_time));
779
+	`).Scan(&contractResults)
780
+
781
+	// 查询回款金额
782
+	var paymentResults []PaymentData
783
+	ChargeReadDB().Raw(`
784
+		SELECT
785
+			MONTH(payment_collection_date) AS month,
786
+			SUM(CAST(payment_collection_sumamt AS DECIMAL(10, 2))) AS total_payment_amount,
787
+			SUM(CAST(software_sumamt AS DECIMAL(10, 2))) AS software_payment_amount,
788
+			SUM(CAST(hardware_sumamt AS DECIMAL(10, 2))) AS hardware_payment_amount
789
+		FROM kyy_charge_payment_collection
790
+		GROUP BY MONTH(payment_collection_date)
791
+		ORDER BY MONTH(payment_collection_date);
792
+	`).Scan(&paymentResults)
793
+
794
+	// 查询续约总汇款金额
795
+	var paymentRenewalResults []MonthlyRenewalData
796
+	ChargeReadDB().Raw(`
797
+		SELECT
798
+			MONTH(sign_time) AS month,
799
+			SUM(CAST(renewal_price AS DECIMAL(10, 2))) AS renewal_price
800
+		FROM kyy_charge_renewal
801
+		GROUP BY MONTH(sign_time)
802
+		ORDER BY MONTH(sign_time)
803
+	`).Scan(&paymentRenewalResults)
804
+
805
+	// 合并结果
806
+	monthlyData := make(map[int]*MonthlyData)
807
+	for _, c := range contractResults {
808
+		monthlyData[c.Month] = &MonthlyData{
809
+			Month:                  c.Month,
810
+			TotalContractAmount:    c.TotalContractAmount,
811
+			SoftwareContractAmount: c.SoftwareContractAmount,
812
+			HardwareContractAmount: c.HardwareContractAmount,
813
+		}
814
+	}
815
+	for _, p := range paymentResults {
816
+		if md, ok := monthlyData[p.Month]; ok {
817
+			md.TotalPaymentAmount = p.TotalPaymentAmount
818
+			md.SoftwarePaymentAmount = p.SoftwarePaymentAmount
819
+			md.HardwarePaymentAmount = p.HardwarePaymentAmount
820
+		} else {
821
+			monthlyData[p.Month] = &MonthlyData{
822
+				Month:                 p.Month,
823
+				TotalPaymentAmount:    p.TotalPaymentAmount,
824
+				SoftwarePaymentAmount: p.SoftwarePaymentAmount,
825
+				HardwarePaymentAmount: p.HardwarePaymentAmount,
826
+			}
827
+		}
828
+	}
829
+
830
+	for _, c := range paymentRenewalResults {
831
+		monthlyData[c.Month] = &MonthlyData{
832
+			Month:        c.Month,
833
+			RenewalPrice: c.RenewalPrice,
834
+		}
835
+	}
836
+
837
+	return monthlyData
614
 }
838
 }