作者 tangxuhui
@@ -35,7 +35,7 @@ type CreditAccountItem struct { @@ -35,7 +35,7 @@ type CreditAccountItem struct {
35 Company domain.CompanyData `json:"company"` // 公司 35 Company domain.CompanyData `json:"company"` // 公司
36 CreatedAt int64 `json:"createdAt"` // 创建时间 36 CreatedAt int64 `json:"createdAt"` // 创建时间
37 UpdatedAt int64 `json:"updatedAt"` // 更新时间 37 UpdatedAt int64 `json:"updatedAt"` // 更新时间
38 - AccountDetail struct { 38 + AccountDetail []struct {
39 DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"` 39 DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"`
40 DividendsType int `json:"dividendsType"` 40 DividendsType int `json:"dividendsType"`
41 DividendsAmount float64 `json:"dividendsAmount"` 41 DividendsAmount float64 `json:"dividendsAmount"`
@@ -39,7 +39,7 @@ func (srv CompanyStatisticsService) SearchDividendContracts(cmd *command.SearchD @@ -39,7 +39,7 @@ func (srv CompanyStatisticsService) SearchDividendContracts(cmd *command.SearchD
39 return 0, result, nil 39 return 0, result, nil
40 } 40 }
41 41
42 -// DividendsStatistics TODO:企业的合约统计(分红统计) 42 +// DividendsStatistics 企业的合约统计(分红统计)
43 func (srv CompanyStatisticsService) DividendsStatistics(cmd *command.DividendsStatisticsCommand) (interface{}, error) { 43 func (srv CompanyStatisticsService) DividendsStatistics(cmd *command.DividendsStatisticsCommand) (interface{}, error) {
44 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( 44 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
45 cmd.Operator) 45 cmd.Operator)
@@ -35,18 +35,17 @@ func (srv CompanyCreditAccountService) CreditAccountSearch(cmd *command.CreditAc @@ -35,18 +35,17 @@ func (srv CompanyCreditAccountService) CreditAccountSearch(cmd *command.CreditAc
35 func (srv CompanyCreditAccountService) CreditAccountGet(cmd *command.CreditAccountGetCommand) (interface{}, error) { 35 func (srv CompanyCreditAccountService) CreditAccountGet(cmd *command.CreditAccountGetCommand) (interface{}, error) {
36 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( 36 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
37 cmd.Operator) 37 cmd.Operator)
38 - resultMenu, err := gateway.CreditAccountGet(allied_creation_cooperation.ReqCreditAccountGet{ 38 + credit, err := gateway.CreditAccountGet(allied_creation_cooperation.ReqCreditAccountGet{
39 CreditAccountId: cmd.CreditAccountId, 39 CreditAccountId: cmd.CreditAccountId,
40 }) 40 })
41 if err != nil { 41 if err != nil {
42 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 42 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
43 } 43 }
44 - result := map[string]interface{}{  
45 - "creditAccount": dto.ToCreditAccountItem(&resultMenu.CreditAccount),  
46 - //TODO:dividendsEstimate 结算明细  
47 - "dividendsEstimate": []struct{}{}, 44 + ret := map[string]interface{}{
  45 + "creditAccount": dto.ToCreditAccountItem(&credit.CreditAccount),
  46 + "dividendsEstimate": credit.CreditAccount.AccountDetail,
48 } 47 }
49 - return result, nil 48 + return ret, nil
50 } 49 }
51 50
52 // CreditAccountDelete 企业的账期结算删除 51 // CreditAccountDelete 企业的账期结算删除
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "github.com/linmadan/egglib-go/core/application" 4 "github.com/linmadan/egglib-go/core/application"
  5 + "github.com/linmadan/egglib-go/utils/json"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
@@ -12,11 +13,12 @@ import ( @@ -12,11 +13,12 @@ import (
12 type PersonStatisticsService struct { 13 type PersonStatisticsService struct {
13 } 14 }
14 15
15 -// IndexStatistics TODO:个人端 - 首页统计 (入口页面统计数据) 16 +// IndexStatistics 个人端 - 首页统计 (入口页面统计数据)
16 func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsCommand) (interface{}, error) { 17 func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsCommand) (interface{}, error) {
17 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation( 18 gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
18 cmd.Operator) 19 cmd.Operator)
19 - // 项目概览统计 20 +
  21 + // 1.项目概览统计
20 contracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{ 22 contracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
21 PageNumber: 1, 23 PageNumber: 1,
22 PageSize: 1, 24 PageSize: 1,
@@ -25,7 +27,6 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC @@ -25,7 +27,6 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC
25 if err != nil { 27 if err != nil {
26 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 28 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
27 } 29 }
28 - // 项目概览统计  
29 stoppedContracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{ 30 stoppedContracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
30 PageNumber: 1, 31 PageNumber: 1,
31 PageSize: 1, 32 PageSize: 1,
@@ -47,56 +48,70 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC @@ -47,56 +48,70 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC
47 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 48 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
48 } 49 }
49 var overview = map[string]interface{}{ 50 var overview = map[string]interface{}{
50 - "contractSum": contracts.Grid.Total,  
51 - "contractStoppedSum": stoppedContracts.Grid.Total,  
52 - "companySum": users.Count, 51 + "contractSum": contracts.Grid.Total, //总合约数
  52 + "contractStoppedSum": stoppedContracts.Grid.Total, //停止的合约数
  53 + "companySum": users.Count, //共创企业数
  54 + }
  55 +
  56 + // 2.本月分红统计 - 个人
  57 + dividendStatisticsResult, err := gateway.CooperationStatistics(allied_creation_cooperation.DividendsStatistics, map[string]interface{}{
  58 + "userBaseId": cmd.Operator.UserBaseId,
  59 + })
  60 + if err != nil {
  61 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
53 } 62 }
  63 + type AnnualDividend struct {
  64 + AnnualDividends struct {
  65 + Accounted int `json:"accounted"`
  66 + Accounting int `json:"accounting"`
  67 + Paid int `json:"paid"`
  68 + Total int `json:"total"`
  69 + } `json:"annualDividends"`
  70 + }
  71 + var annualDividend = &AnnualDividend{}
  72 + if err := json.UnmarshalFromString(json.MarshalToString(dividendStatisticsResult), annualDividend); err != nil {
  73 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  74 + }
  75 + dividendStatistics := map[string]interface{}{
  76 + "dividendAmount": annualDividend.AnnualDividends.Total, // 分红金额
  77 + "paidAmount": annualDividend.AnnualDividends.Paid, // 已支付
  78 + "unPaidAmount": annualDividend.AnnualDividends.Accounting, // 未支付
  79 + }
  80 +
54 return map[string]interface{}{ 81 return map[string]interface{}{
55 "overview": overview, 82 "overview": overview,
56 - "dividendStatistics": map[string]interface{}{  
57 - "dividendAmount": 9000,  
58 - "paidAmount": 2000,  
59 - "unPaidAmount": 7000,  
60 - }, 83 + "dividendStatistics": dividendStatistics,
61 }, nil 84 }, nil
62 -  
63 - //return map[string]interface{}{  
64 - // "overview": map[string]interface{}{  
65 - // "contractSum": 60,  
66 - // "contractStoppedSum": 70,  
67 - // "companySum": 6,  
68 - // },  
69 - // "dividendStatistics": map[string]interface{}{  
70 - // "dividendAmount": 9000,  
71 - // "paidAmount": 2000,  
72 - // "unPaidAmount": 7000,  
73 - // },  
74 - //}, nil  
75 } 85 }
76 86
77 // CompanyStatistics 共创用户-共创企业统计 87 // CompanyStatistics 共创用户-共创企业统计
78 -func (srv PersonStatisticsService) CompanyStatistics(userMenusCommand *command.CooperationPersonStatisticsCommand) (interface{}, error) {  
79 - var values []interface{}  
80 - values = append(values, map[string]interface{}{  
81 - "company": map[string]interface{}{  
82 - "companyId": 5,  
83 - "companyName": "机会平台",  
84 - },  
85 - "cooperationProjectCount": 10,  
86 - "cooperationContractCount": 5,  
87 - "dividendsRatio": 50,  
88 - "dividendsIncome": 10009965,  
89 - })  
90 - values = append(values, map[string]interface{}{  
91 - "company": map[string]interface{}{  
92 - "companyId": 6,  
93 - "companyName": "机会平台2",  
94 - },  
95 - "cooperationProjectCount": 10,  
96 - "cooperationContractCount": 5,  
97 - "dividendsRatio": 50,  
98 - "dividendsIncome": 10009965, 88 +func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPersonStatisticsCommand) (interface{}, error) {
  89 +
  90 + gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
  91 + cmd.Operator)
  92 + users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
  93 + Limit: 100,
  94 + Offset: 0,
  95 + UserBaseId: cmd.Operator.UserBaseId,
  96 + UserType: domain.UserTypeCooperation,
99 }) 97 })
  98 + if err != nil {
  99 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  100 + }
  101 +
  102 + var values []interface{}
  103 +
  104 + for i := range users.Users {
  105 + user := users.Users[i]
  106 + item := map[string]interface{}{
  107 + "company": user.Company,
  108 + "cooperationProjectCount": 0,
  109 + "cooperationContractCount": 0,
  110 + "dividendsRatio": 0,
  111 + "dividendsIncome": 0,
  112 + }
  113 + values = append(values, item)
  114 + }
100 return map[string]interface{}{ 115 return map[string]interface{}{
101 "list": values, 116 "list": values,
102 }, nil 117 }, nil