|
@@ -8,7 +8,9 @@ import (
|
8
|
8
|
"database/sql"
|
9
|
9
|
"fmt"
|
10
|
10
|
"github.com/jinzhu/gorm"
|
|
11
|
+ "strconv"
|
11
|
12
|
"strings"
|
|
13
|
+ "time"
|
12
|
14
|
)
|
13
|
15
|
|
14
|
16
|
func GetAdminAccount(account string, password string) (*admin_models.AdminAccount, error) {
|
|
@@ -502,7 +504,7 @@ func FindAllFollowOrg(keyword string, page int64, limit int64, admin_id int64) (
|
502
|
504
|
// 获取累积客户数
|
503
|
505
|
func GetCustomCount() (int64, error) {
|
504
|
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
|
508
|
if err != nil {
|
507
|
509
|
return 0, err
|
508
|
510
|
}
|
|
@@ -512,7 +514,7 @@ func GetCustomCount() (int64, error) {
|
512
|
514
|
// 本年新增收费客户
|
513
|
515
|
func GetCurYearCustomCount() (int64, error) {
|
514
|
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
|
518
|
if err != nil {
|
517
|
519
|
return 0, err
|
518
|
520
|
}
|
|
@@ -522,7 +524,7 @@ func GetCurYearCustomCount() (int64, error) {
|
522
|
524
|
// 统计本年新增标准版客户
|
523
|
525
|
func GetCurYearStandCustomCount() (int64, error) {
|
524
|
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
|
528
|
if err != nil {
|
527
|
529
|
return 0, err
|
528
|
530
|
}
|
|
@@ -532,7 +534,7 @@ func GetCurYearStandCustomCount() (int64, error) {
|
532
|
534
|
// 统计本年新增尊享版客户
|
533
|
535
|
func GetCurYearDeluxeCustomCount() (int64, error) {
|
534
|
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
|
538
|
if err != nil {
|
537
|
539
|
return 0, err
|
538
|
540
|
}
|
|
@@ -542,7 +544,7 @@ func GetCurYearDeluxeCustomCount() (int64, error) {
|
542
|
544
|
// 统计本年新增专业版客户
|
543
|
545
|
func GetCurYearProfessionalCustomCount() (int64, error) {
|
544
|
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
|
548
|
if err != nil {
|
547
|
549
|
return 0, err
|
548
|
550
|
}
|
|
@@ -552,7 +554,7 @@ func GetCurYearProfessionalCustomCount() (int64, error) {
|
552
|
554
|
// 统计本年新增其他版客户
|
553
|
555
|
func GetCurYearOtherCustomCount() (int64, error) {
|
554
|
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
|
558
|
if err != nil {
|
557
|
559
|
return 0, err
|
558
|
560
|
}
|
|
@@ -560,55 +562,277 @@ func GetCurYearOtherCustomCount() (int64, error) {
|
560
|
562
|
}
|
561
|
563
|
|
562
|
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
|
570
|
if err != nil {
|
566
|
571
|
return 0, err
|
567
|
572
|
}
|
568
|
|
- return count, nil
|
|
573
|
+ return count.Count, nil
|
569
|
574
|
}
|
570
|
575
|
|
571
|
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
|
582
|
if err != nil {
|
575
|
583
|
return 0, err
|
576
|
584
|
}
|
577
|
|
- return count, nil
|
|
585
|
+ return count.Count, nil
|
578
|
586
|
}
|
579
|
587
|
|
580
|
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
|
594
|
if err != nil {
|
584
|
595
|
return 0, err
|
585
|
596
|
}
|
586
|
|
- return count, nil
|
|
597
|
+ return count.Count, nil
|
587
|
598
|
}
|
588
|
599
|
|
589
|
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
|
606
|
if err != nil {
|
593
|
607
|
return 0, err
|
594
|
608
|
}
|
595
|
|
- return count, nil
|
|
609
|
+ return count.Count, nil
|
596
|
610
|
}
|
597
|
611
|
|
598
|
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
|
618
|
if err != nil {
|
602
|
619
|
return 0, err
|
603
|
620
|
}
|
604
|
|
- return count, nil
|
|
621
|
+ return count.Count, nil
|
605
|
622
|
}
|
606
|
623
|
|
607
|
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
|
630
|
if err != nil {
|
611
|
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
|
}
|