作者 yangfu

共创用户列表修改

@@ -43,12 +43,16 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS @@ -43,12 +43,16 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
43 res, err = statisticsService.CooperationModeStatistics(contractStatisticsQuery.QueryOptions) 43 res, err = statisticsService.CooperationModeStatistics(contractStatisticsQuery.QueryOptions)
44 case domain_service.CompanyDividendsStatistics: 44 case domain_service.CompanyDividendsStatistics:
45 res, err = statisticsService.CompanyDividendsStatistics(contractStatisticsQuery.QueryOptions) 45 res, err = statisticsService.CompanyDividendsStatistics(contractStatisticsQuery.QueryOptions)
  46 + case domain_service.CompanyCooperationUsersStatistics:
  47 + res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions)
46 case domain_service.DividendsStatistics: 48 case domain_service.DividendsStatistics:
47 res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions) 49 res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions)
48 case domain_service.SearchDividendsEstimates: 50 case domain_service.SearchDividendsEstimates:
49 res, err = statisticsService.SearchDividendsEstimates(contractStatisticsQuery.QueryOptions) 51 res, err = statisticsService.SearchDividendsEstimates(contractStatisticsQuery.QueryOptions)
50 case domain_service.CooperationCompanyStatistics: 52 case domain_service.CooperationCompanyStatistics:
51 res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions) 53 res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions)
  54 + case domain_service.PersonCooperationContractStatistics:
  55 + res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions)
52 } 56 }
53 if err != nil { 57 if err != nil {
54 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 58 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -55,27 +55,6 @@ func (dao *CreditAccountDao) CheckCreditAccountNumberAvailable(queryOptions map[ @@ -55,27 +55,6 @@ func (dao *CreditAccountDao) CheckCreditAccountNumberAvailable(queryOptions map[
55 55
56 // 分红统计(分红明细) 56 // 分红统计(分红明细)
57 func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interface{}, v interface{}) error { 57 func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
58 - // sql := `  
59 - //select  
60 - //sum(settlement_amount) total,  
61 - //sum((case when payment_status = 1 then actually_paid_amount else 0 end)) paid,  
62 - //sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted  
63 - //from credit_accounts  
64 - //where  
65 - //`  
66 - //  
67 - //  
68 - // if _, ok := queryOptions["beginTime"]; ok {  
69 - // sql += `created_at>? and created_at<? and `  
70 - // }  
71 - // if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 {  
72 - // sql += fmt.Sprintf(`participator->>'userBaseId'='%v' `, v)  
73 - // }  
74 - // if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {  
75 - // sql += fmt.Sprintf(` org->>'orgId'= '%v'`, v)  
76 - // }  
77 - // _, err := dao.transactionContext.PgDd.Query(v, sql, queryOptions["beginTime"], queryOptions["endTime"])  
78 -  
79 creditAccount := new(models.CreditAccount) 58 creditAccount := new(models.CreditAccount)
80 query := dao.transactionContext.PgTx.Model(creditAccount) 59 query := dao.transactionContext.PgTx.Model(creditAccount)
81 query.ColumnExpr(`sum(settlement_amount) total`) 60 query.ColumnExpr(`sum(settlement_amount) total`)
@@ -95,6 +74,42 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa @@ -95,6 +74,42 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa
95 return err 74 return err
96 } 75 }
97 76
  77 +// 分红统计(分红明细)
  78 +func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
  79 + creditAccount := new(models.CreditAccount)
  80 + query := dao.transactionContext.PgTx.Model(creditAccount)
  81 + query.ColumnExpr(`0 cooperation_time`)
  82 + query.ColumnExpr(`0 dividends_order_amount`)
  83 + query.ColumnExpr(`sum(settlement_amount) divides_amount`)
  84 + query.ColumnExpr(`sum((case when payment_status = 1 then actually_paid_amount else 0 end)) actually_paid_amount`)
  85 + query.ColumnExpr(`max(participator->>'userId') user_id`)
  86 + query.ColumnExpr(`max(participator#>>'{userInfo,userName}') user_name`)
  87 + if _, ok := queryOptions["beginTime"]; ok {
  88 + query.Where(`created_at>? `, queryOptions["beginTime"])
  89 + query.Where(`created_at<? `, queryOptions["endTime"])
  90 + }
  91 + if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 {
  92 + query.Where(fmt.Sprintf(`participator->>'userBaseId'='%v' `, v))
  93 + }
  94 + if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
  95 + query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v))
  96 + }
  97 + query.Where("deleted_at is null")
  98 + if v, ok := queryOptions["sortByActuallyPaidAmount"]; ok {
  99 + vInt := v.(int)
  100 + if vInt == 1 {
  101 + query.Order("divides_amount asc")
  102 + } else {
  103 + query.Order("divides_amount desc")
  104 + }
  105 + }
  106 + query.GroupExpr("participator->>'userBaseId'")
  107 + query.Limit(queryOptions["limit"].(int))
  108 + query.Offset(queryOptions["offset"].(int))
  109 + err := query.Select(v)
  110 + return err
  111 +}
  112 +
98 func NewCreditAccountDao(transactionContext *pgTransaction.TransactionContext) (*CreditAccountDao, error) { 113 func NewCreditAccountDao(transactionContext *pgTransaction.TransactionContext) (*CreditAccountDao, error) {
99 if transactionContext == nil { 114 if transactionContext == nil {
100 return nil, fmt.Errorf("transactionContext参数不能为空") 115 return nil, fmt.Errorf("transactionContext参数不能为空")
@@ -186,3 +186,61 @@ type item struct { @@ -186,3 +186,61 @@ type item struct {
186 key string 186 key string
187 val interface{} 187 val interface{}
188 } 188 }
  189 +
  190 +// 公司 - 共创用户统计
  191 +func (ptr *CooperationStatisticsService) CompanyCooperationUsersStatistics(queryOptions map[string]interface{}) (interface{}, error) {
  192 + // 参数验证
  193 + var request = struct {
  194 + Limit int `json:"limit" valid:"Required"`
  195 + Offset int `json:"offset"`
  196 + OrgId int64 `json:"orgId" valid:"Required"`
  197 + SortByActuallyPaidAmount int `json:"sortByActuallyPaidAmount" valid:"Required"`
  198 + }{}
  199 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  200 + return nil, err
  201 + }
  202 + queryOptions = tool_funs.SimpleStructToMap(&request)
  203 +
  204 + type response struct {
  205 + CooperationTime int64 `json:"cooperationTime"`
  206 + DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
  207 + DividesAmount float64 `json:"dividesAmount"` // 分红金额
  208 + ActuallyPaidAmount float64 `json:"actuallyPaidAmount"` // 已支付金额
  209 + UnPaidAmount float64 `json:"unPaidAmount"` // 未支付金额
  210 + UserId int64 `json:"userId,string"`
  211 + UserName string `json:"userName"`
  212 +
  213 + Participator interface{} `json:"participator"`
  214 + }
  215 + var responses []response
  216 + creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
  217 + if err := creditAccountDao.CooperationUsersDividendsStatistics(queryOptions, &responses); err != nil {
  218 + return nil, err
  219 + }
  220 +
  221 + var retMap = make([]interface{}, 0)
  222 + for i := range responses {
  223 + responses[i].CooperationTime = time.Now().Unix() * 1000
  224 + unPaidAmount := responses[i].DividesAmount - responses[i].ActuallyPaidAmount
  225 + responses[i].Participator = map[string]interface{}{
  226 + "userId": responses[i].UserId,
  227 + "userInfo": map[string]interface{}{
  228 + "userName": responses[i].UserName,
  229 + },
  230 + }
  231 + retMap = append(retMap, map[string]interface{}{
  232 + "dividendsOrderAmount": 0,
  233 + "dividesAmount": responses[i].DividesAmount,
  234 + "unPaidAmount": unPaidAmount,
  235 + "cooperationTime": time.Now().Unix() * 1000,
  236 + "participator": map[string]interface{}{
  237 + "userId": responses[i].UserId,
  238 + "userInfo": map[string]interface{}{
  239 + "userName": responses[i].UserName,
  240 + },
  241 + },
  242 + })
  243 + }
  244 +
  245 + return retMap, nil
  246 +}
1 package domain_service 1 package domain_service
2 2
3 import ( 3 import (
  4 + "github.com/go-pg/pg/v10"
4 "github.com/linmadan/egglib-go/utils/tool_funs" 5 "github.com/linmadan/egglib-go/utils/tool_funs"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
8 ) 10 )
@@ -90,3 +92,49 @@ type cooperationCompanyStatisticsResponse struct { @@ -90,3 +92,49 @@ type cooperationCompanyStatisticsResponse struct {
90 // 分红支出 92 // 分红支出
91 DividendsIncome float64 `json:"dividendsIncome"` 93 DividendsIncome float64 `json:"dividendsIncome"`
92 } 94 }
  95 +
  96 +// 个人-用户合约统计
  97 +func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(queryOptions map[string]interface{}) (interface{}, error) {
  98 + // 参数验证
  99 + var request = struct {
  100 + UserBaseId int64 `json:"userBaseId" valid:"Required"`
  101 + }{}
  102 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  103 + return nil, err
  104 + }
  105 + queryOptions = tool_funs.SimpleStructToMap(&request)
  106 +
  107 + cooperationContractUndertaker, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
  108 + _, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions)
  109 + if err != nil {
  110 + return nil, nil
  111 + }
  112 +
  113 + var response = struct {
  114 + ContractSum int `json:"contractSum"`
  115 + ContractStoppedSum int `json:"contractStoppedSum"`
  116 + }{}
  117 + if len(contractUndertakers) == 0 {
  118 + return response, nil
  119 + }
  120 + var numbers []string
  121 + for i := range contractUndertakers {
  122 + numbers = append(numbers, contractUndertakers[i].CooperationContractNumber)
  123 + }
  124 + response.ContractSum = ptr.cooperationContractCount(numbers, 0)
  125 + response.ContractStoppedSum = ptr.cooperationContractCount(numbers, 2)
  126 + return response, nil
  127 +}
  128 +
  129 +func (ptr *CooperationStatisticsService) cooperationContractCount(numbers []string, status int) int {
  130 + var total int
  131 + var contract = new(models.CooperationContract)
  132 + query := ptr.transactionContext.PgDd.Model(contract)
  133 + query.ColumnExpr("count(*) total")
  134 + query.Where("cooperation_contract_number in (?)", pg.In(numbers))
  135 + if status > 0 {
  136 + query.Where("status =? ")
  137 + }
  138 + query.Select(&total)
  139 + return total
  140 +}
@@ -29,9 +29,13 @@ const ( @@ -29,9 +29,13 @@ const (
29 CompanyDividendsStatistics = "CompanyDividendsStatistics" 29 CompanyDividendsStatistics = "CompanyDividendsStatistics"
30 // 企业、个人 - 分红预算列表 30 // 企业、个人 - 分红预算列表
31 SearchDividendsEstimates = "SearchDividendsEstimates" 31 SearchDividendsEstimates = "SearchDividendsEstimates"
  32 + // 公司 - 共创用户统计
  33 + CompanyCooperationUsersStatistics = "CompanyCooperationUsersStatistics"
32 34
33 // 个人 - 共创企业统计 35 // 个人 - 共创企业统计
34 CooperationCompanyStatistics = "CooperationCompanyStatistics" 36 CooperationCompanyStatistics = "CooperationCompanyStatistics"
  37 + // 个人 - 用户合约统计
  38 + PersonCooperationContractStatistics = "PersonCooperationContractStatistics"
35 ) 39 )
36 40
37 // CooperationStatisticsService 共创统计服务 41 // CooperationStatisticsService 共创统计服务
@@ -234,6 +234,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string @@ -234,6 +234,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
234 if cooperationApplicationIds, ok := queryOptions["cooperationApplicationIds"]; ok && len(cooperationApplicationIds.([]int64)) > 0 { 234 if cooperationApplicationIds, ok := queryOptions["cooperationApplicationIds"]; ok && len(cooperationApplicationIds.([]int64)) > 0 {
235 query.Where("cooperation_application_id IN (?)", pg.In(cooperationApplicationIds)) 235 query.Where("cooperation_application_id IN (?)", pg.In(cooperationApplicationIds))
236 } 236 }
  237 + if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
  238 + query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId)
  239 + }
237 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 240 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
238 query.Where("company->>'companyId' = '?'", companyId) 241 query.Where("company->>'companyId' = '?'", companyId)
239 } 242 }