正在显示
5 个修改的文件
包含
160 行增加
和
7 行删除
@@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS | @@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS | ||
47 | res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions) | 47 | res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions) |
48 | case domain_service.CompanyPaymentHistoryStatistics: | 48 | case domain_service.CompanyPaymentHistoryStatistics: |
49 | res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions) | 49 | res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions) |
50 | + case domain_service.PaymentHistoryHistogramStatistics: | ||
51 | + res, err = statisticsService.PaymentHistoryHistogramStatistics(contractStatisticsQuery.QueryOptions) | ||
50 | case domain_service.CooperationUserModeStatistics: | 52 | case domain_service.CooperationUserModeStatistics: |
51 | res, err = statisticsService.CooperationUserModeStatistics(contractStatisticsQuery.QueryOptions) | 53 | res, err = statisticsService.CooperationUserModeStatistics(contractStatisticsQuery.QueryOptions) |
52 | case domain_service.DividendsStatistics: | 54 | case domain_service.DividendsStatistics: |
@@ -57,6 +59,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS | @@ -57,6 +59,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS | ||
57 | res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions) | 59 | res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions) |
58 | case domain_service.PersonCooperationContractStatistics: | 60 | case domain_service.PersonCooperationContractStatistics: |
59 | res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions) | 61 | res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions) |
62 | + case domain_service.PersonCompanyPaymentHistoryStatistics: | ||
63 | + res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions) | ||
60 | case domain_service.CreditAccountStatistics: | 64 | case domain_service.CreditAccountStatistics: |
61 | res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions) | 65 | res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions) |
62 | } | 66 | } |
@@ -119,6 +119,51 @@ func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions ma | @@ -119,6 +119,51 @@ func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions ma | ||
119 | return err | 119 | return err |
120 | } | 120 | } |
121 | 121 | ||
122 | +// 共创企业分红统计 | ||
123 | +func (dao *CreditAccountDao) CooperationCompanyDividendsStatistics(queryOptions map[string]interface{}, v interface{}) error { | ||
124 | + creditAccount := new(models.CreditAccount) | ||
125 | + query := dao.transactionContext.PgTx.Model(creditAccount) | ||
126 | + query.ColumnExpr(`0 cooperation_time`) | ||
127 | + query.ColumnExpr(`sum(good_amount_count) dividends_order_amount`) | ||
128 | + query.ColumnExpr(`sum(settlement_amount) divides_amount`) | ||
129 | + query.ColumnExpr(`sum((case when payment_status = 1 then actually_paid_amount else 0 end)) actually_paid_amount`) | ||
130 | + query.ColumnExpr(`max(org->>'orgId') org_id`) | ||
131 | + query.ColumnExpr(`max(org->>'orgName') org_name`) | ||
132 | + if _, ok := queryOptions["beginTime"]; ok { | ||
133 | + query.Where(`created_at>? `, queryOptions["beginTime"]) | ||
134 | + query.Where(`created_at<? `, queryOptions["endTime"]) | ||
135 | + } | ||
136 | + if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 { | ||
137 | + query.Where(fmt.Sprintf(`participator->>'userBaseId'='%v' `, v)) | ||
138 | + } | ||
139 | + if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 { | ||
140 | + query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v)) | ||
141 | + } | ||
142 | + if v, ok := queryOptions["paymentStatus"]; ok && v.(int32) > 0 { | ||
143 | + query.Where("paymentStatus = ?", v) | ||
144 | + } | ||
145 | + if v, ok := queryOptions["beginTime"]; ok && !v.(time.Time).IsZero() { | ||
146 | + query.Where("created_at >= ?", v) | ||
147 | + } | ||
148 | + if v, ok := queryOptions["endTime"]; ok && !v.(time.Time).IsZero() { | ||
149 | + query.Where("created_at < ?", v) | ||
150 | + } | ||
151 | + query.Where("deleted_at is null") | ||
152 | + if v, ok := queryOptions["sortByActuallyPaidAmount"]; ok { | ||
153 | + vInt := v.(int) | ||
154 | + if vInt == 1 { | ||
155 | + query.Order("actually_paid_amount asc") | ||
156 | + } else { | ||
157 | + query.Order("actually_paid_amount desc") | ||
158 | + } | ||
159 | + } | ||
160 | + query.GroupExpr("org->>'orgId'") | ||
161 | + query.Limit(queryOptions["limit"].(int)) | ||
162 | + query.Offset(queryOptions["offset"].(int)) | ||
163 | + err := query.Select(v) | ||
164 | + return err | ||
165 | +} | ||
166 | + | ||
122 | func NewCreditAccountDao(transactionContext *pgTransaction.TransactionContext) (*CreditAccountDao, error) { | 167 | func NewCreditAccountDao(transactionContext *pgTransaction.TransactionContext) (*CreditAccountDao, error) { |
123 | if transactionContext == nil { | 168 | if transactionContext == nil { |
124 | return nil, fmt.Errorf("transactionContext参数不能为空") | 169 | return nil, fmt.Errorf("transactionContext参数不能为空") |
@@ -347,3 +347,52 @@ func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(queryOp | @@ -347,3 +347,52 @@ func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(queryOp | ||
347 | 347 | ||
348 | return retMap, nil | 348 | return retMap, nil |
349 | } | 349 | } |
350 | + | ||
351 | +// 公司/个人 - 支付历史统计直方图 | ||
352 | +func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(queryOptions map[string]interface{}) (interface{}, error) { | ||
353 | + creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext) | ||
354 | + | ||
355 | + var request = struct { | ||
356 | + OrgId int64 `json:"orgId"` | ||
357 | + UserBaseId int64 `json:"userBaseId"` | ||
358 | + }{} | ||
359 | + if err := LoadQueryObject(queryOptions, &request); err != nil { | ||
360 | + return nil, err | ||
361 | + } | ||
362 | + queryOptions = tool_funs.SimpleStructToMap(&request) | ||
363 | + | ||
364 | + var dividends = &CreditAccountStatisticsResponse{} | ||
365 | + var beginTime, endTime time.Time | ||
366 | + var increaseDay = 5 | ||
367 | + var monthEnd = utils.GetFirstDateOfMonth(time.Now()).Add(-time.Second) | ||
368 | + var xAxisData []string | ||
369 | + var values []float64 | ||
370 | + for { | ||
371 | + if beginTime.AddDate(0, 0, increaseDay).After(monthEnd) { | ||
372 | + endTime = monthEnd | ||
373 | + } | ||
374 | + if endTime.After(monthEnd) { | ||
375 | + break | ||
376 | + } | ||
377 | + | ||
378 | + xAxisData = append(xAxisData, endTime.Format("01-02")) | ||
379 | + queryOptions["beginTime"] = beginTime | ||
380 | + queryOptions["endTime"] = endTime | ||
381 | + if err := creditAccountDao.DividendsStatistics(queryOptions, dividends); err != nil { | ||
382 | + return nil, err | ||
383 | + } | ||
384 | + dividends.Accounting = dividends.Total - dividends.Accounted | ||
385 | + values = append(values, dividends.Paid) | ||
386 | + | ||
387 | + beginTime = endTime.AddDate(0, 0, increaseDay) | ||
388 | + endTime = endTime.AddDate(0, 0, increaseDay) | ||
389 | + } | ||
390 | + return map[string]interface{}{ | ||
391 | + "xAxis": map[string]interface{}{ | ||
392 | + "data": xAxisData, | ||
393 | + }, | ||
394 | + "source": map[string]interface{}{ | ||
395 | + "value": values, | ||
396 | + }, | ||
397 | + }, nil | ||
398 | +} |
@@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" |
10 | + "time" | ||
10 | ) | 11 | ) |
11 | 12 | ||
12 | // 共创公司统计 | 13 | // 共创公司统计 |
@@ -138,3 +139,52 @@ func (ptr *CooperationStatisticsService) cooperationContractCount(numbers []stri | @@ -138,3 +139,52 @@ func (ptr *CooperationStatisticsService) cooperationContractCount(numbers []stri | ||
138 | query.Select(&total) | 139 | query.Select(&total) |
139 | return total | 140 | return total |
140 | } | 141 | } |
142 | + | ||
143 | +// 个人 - 企业支付统计 | ||
144 | +func (ptr *CooperationStatisticsService) PersonCompanyPaymentHistoryStatistics(queryOptions map[string]interface{}) (interface{}, error) { | ||
145 | + // 参数验证 | ||
146 | + var request = struct { | ||
147 | + Limit int `json:"limit" valid:"Required"` | ||
148 | + Offset int `json:"offset"` | ||
149 | + UserBaseId int64 `json:"userBaseId" valid:"Required"` | ||
150 | + OrgId int64 `json:"orgId" valid:"Required"` | ||
151 | + SortByActuallyPaidAmount int `json:"sortByActuallyPaidAmount" valid:"Required"` | ||
152 | + BeginTime time.Time `json:"beginTime"` | ||
153 | + EndTime time.Time `json:"endTime"` | ||
154 | + }{} | ||
155 | + if err := LoadQueryObject(queryOptions, &request); err != nil { | ||
156 | + return nil, err | ||
157 | + } | ||
158 | + queryOptions = tool_funs.SimpleStructToMap(&request) | ||
159 | + | ||
160 | + type companyStatisticsResponse struct { | ||
161 | + CooperationTime int64 `json:"cooperationTime"` | ||
162 | + DividendsOrderAmount float64 `json:"dividendsOrderAmount"` | ||
163 | + DividesAmount float64 `json:"dividesAmount"` // 分红金额 | ||
164 | + ActuallyPaidAmount float64 `json:"actuallyPaidAmount"` // 已支付金额 | ||
165 | + UnPaidAmount float64 `json:"unPaidAmount"` // 未支付金额 | ||
166 | + OrgId int64 `json:"orgId,string"` | ||
167 | + OrgName string `json:"orgName"` | ||
168 | + | ||
169 | + Participator interface{} `json:"participator"` | ||
170 | + } | ||
171 | + | ||
172 | + var responses []companyStatisticsResponse | ||
173 | + creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext) | ||
174 | + if err := creditAccountDao.CooperationCompanyDividendsStatistics(queryOptions, &responses); err != nil { | ||
175 | + return nil, err | ||
176 | + } | ||
177 | + | ||
178 | + var retMap = make([]interface{}, 0) | ||
179 | + for i := range responses { | ||
180 | + retMap = append(retMap, map[string]interface{}{ | ||
181 | + "paymentAmount": responses[i].ActuallyPaidAmount, | ||
182 | + "org": map[string]interface{}{ | ||
183 | + "orgId": responses[i].OrgId, | ||
184 | + "orgName": responses[i].OrgName, | ||
185 | + }, | ||
186 | + }) | ||
187 | + } | ||
188 | + | ||
189 | + return retMap, nil | ||
190 | +} |
@@ -41,9 +41,13 @@ const ( | @@ -41,9 +41,13 @@ const ( | ||
41 | CooperationCompanyStatistics = "CooperationCompanyStatistics" | 41 | CooperationCompanyStatistics = "CooperationCompanyStatistics" |
42 | // 个人 - 用户合约统计 | 42 | // 个人 - 用户合约统计 |
43 | PersonCooperationContractStatistics = "PersonCooperationContractStatistics" | 43 | PersonCooperationContractStatistics = "PersonCooperationContractStatistics" |
44 | + // 个人 - 企业支付统计 | ||
45 | + PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics" | ||
44 | 46 | ||
45 | // 账期结算单统计 | 47 | // 账期结算单统计 |
46 | CreditAccountStatistics = "CreditAccountStatistics" | 48 | CreditAccountStatistics = "CreditAccountStatistics" |
49 | + // 公司/个人 - 支付历史统计直方图 | ||
50 | + PaymentHistoryHistogramStatistics = "PaymentHistoryHistogramStatistics" | ||
47 | ) | 51 | ) |
48 | 52 | ||
49 | // CooperationStatisticsService 共创统计服务 | 53 | // CooperationStatisticsService 共创统计服务 |
@@ -471,18 +475,19 @@ func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions ma | @@ -471,18 +475,19 @@ func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions ma | ||
471 | } | 475 | } |
472 | queryOptions = tool_funs.SimpleStructToMap(&request) | 476 | queryOptions = tool_funs.SimpleStructToMap(&request) |
473 | 477 | ||
474 | - type response struct { | ||
475 | - Total float64 `json:"total"` | ||
476 | - Accounting float64 `json:"accounting"` | ||
477 | - Accounted float64 `json:"accounted"` | ||
478 | - Paid float64 `json:"paid"` | ||
479 | - } | ||
480 | creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext) | 478 | creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext) |
481 | 479 | ||
482 | - var allDividends = &response{} | 480 | + var allDividends = &CreditAccountStatisticsResponse{} |
483 | if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil { | 481 | if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil { |
484 | return nil, err | 482 | return nil, err |
485 | } | 483 | } |
486 | allDividends.Accounting = allDividends.Total - allDividends.Accounted | 484 | allDividends.Accounting = allDividends.Total - allDividends.Accounted |
487 | return allDividends, nil | 485 | return allDividends, nil |
488 | } | 486 | } |
487 | + | ||
488 | +type CreditAccountStatisticsResponse struct { | ||
489 | + Total float64 `json:"total"` | ||
490 | + Accounting float64 `json:"accounting"` | ||
491 | + Accounted float64 `json:"accounted"` | ||
492 | + Paid float64 `json:"paid"` | ||
493 | +} |
-
请 注册 或 登录 后发表评论