正在显示
7 个修改的文件
包含
170 行增加
和
30 行删除
| @@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS | @@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS | ||
| 47 | res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions) | 47 | res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions) |
| 48 | case domain_service.SearchDividendsEstimates: | 48 | case domain_service.SearchDividendsEstimates: |
| 49 | res, err = statisticsService.SearchDividendsEstimates(contractStatisticsQuery.QueryOptions) | 49 | res, err = statisticsService.SearchDividendsEstimates(contractStatisticsQuery.QueryOptions) |
| 50 | + case domain_service.CooperationCompanyStatistics: | ||
| 51 | + res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions) | ||
| 50 | } | 52 | } |
| 51 | if err != nil { | 53 | if err != nil { |
| 52 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 54 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| @@ -55,24 +55,43 @@ func (dao *CreditAccountDao) CheckCreditAccountNumberAvailable(queryOptions map[ | @@ -55,24 +55,43 @@ 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 | -` | 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) | ||
| 80 | + query := dao.transactionContext.PgTx.Model(creditAccount) | ||
| 81 | + query.ColumnExpr(`sum(settlement_amount) total`) | ||
| 82 | + query.ColumnExpr(`sum((case when payment_status = 1 then actually_paid_amount else 0 end)) paid`) | ||
| 83 | + query.ColumnExpr(`sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted `) | ||
| 66 | if _, ok := queryOptions["beginTime"]; ok { | 84 | if _, ok := queryOptions["beginTime"]; ok { |
| 67 | - sql += `created_at>? and created_at<? and ` | 85 | + query.Where(`created_at>? `, queryOptions["beginTime"]) |
| 86 | + query.Where(`created_at<? `, queryOptions["endTime"]) | ||
| 68 | } | 87 | } |
| 69 | if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 { | 88 | if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 { |
| 70 | - sql += fmt.Sprintf(`participator->>'userBaseId'='%v'`, v) | 89 | + query.Where(fmt.Sprintf(`participator->>'userBaseId'='%v' `, v)) |
| 71 | } | 90 | } |
| 72 | if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 { | 91 | if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 { |
| 73 | - sql += fmt.Sprintf(`org->>'orgId'= '%v'`, v) | 92 | + query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v)) |
| 74 | } | 93 | } |
| 75 | - _, err := dao.transactionContext.PgDd.Query(v, sql, queryOptions["beginTime"], queryOptions["endTime"]) | 94 | + err := query.Select(v) |
| 76 | return err | 95 | return err |
| 77 | } | 96 | } |
| 78 | 97 |
| 1 | +package domain_service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "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/repository" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +// 共创公司统计 | ||
| 11 | +func (ptr *CooperationStatisticsService) CooperationCompanyStatistics(queryOptions map[string]interface{}) (interface{}, error) { | ||
| 12 | + // 参数验证 | ||
| 13 | + var request = struct { | ||
| 14 | + UserBaseId int64 `json:"userBaseId" valid:"Required"` | ||
| 15 | + CompanyList []int64 `json:"companyList" valid:"Required"` //公司列表 待统计的公司列表 | ||
| 16 | + }{} | ||
| 17 | + if err := LoadQueryObject(queryOptions, &request); err != nil { | ||
| 18 | + return nil, err | ||
| 19 | + } | ||
| 20 | + queryOptions = tool_funs.SimpleStructToMap(&request) | ||
| 21 | + | ||
| 22 | + var response = make([]*cooperationCompanyStatisticsResponse, 0) | ||
| 23 | + var totalDividend float64 | ||
| 24 | + for i := range request.CompanyList { | ||
| 25 | + orgId := request.CompanyList[i] | ||
| 26 | + item, err := ptr.cooperationCompanyStatistics(request.UserBaseId, orgId) | ||
| 27 | + if err != nil { | ||
| 28 | + return response, err | ||
| 29 | + } | ||
| 30 | + totalDividend += item.DividendsIncome | ||
| 31 | + response = append(response, item) | ||
| 32 | + } | ||
| 33 | + if totalDividend > 0 { | ||
| 34 | + for i := range response { | ||
| 35 | + response[i].DividendsRatio = utils.Round(response[i].DividendsIncome/totalDividend*100, 2) | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + return response, nil | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId int64, orgId int64) (*cooperationCompanyStatisticsResponse, error) { | ||
| 42 | + // 1.相关项目统计 | ||
| 43 | + cooperationApplicationRepository, _ := repository.NewCooperationApplicationRepository(ptr.transactionContext) | ||
| 44 | + cooperationProjectCount, _, err := cooperationApplicationRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId, | ||
| 45 | + "limit": 1, "cooperationApplicationStatus": int32(2)}) | ||
| 46 | + if err != nil { | ||
| 47 | + return nil, err | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + // 2.相关合约统计 | ||
| 51 | + cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext) | ||
| 52 | + cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, | ||
| 53 | + "limit": 1}) | ||
| 54 | + if err != nil { | ||
| 55 | + return nil, err | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + // 3.个人分红统计 | ||
| 59 | + type response struct { | ||
| 60 | + Total float64 `json:"total"` | ||
| 61 | + Accounting float64 `json:"accounting"` | ||
| 62 | + Accounted float64 `json:"accounted"` | ||
| 63 | + Paid float64 `json:"paid"` | ||
| 64 | + } | ||
| 65 | + creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext) | ||
| 66 | + var allDividends = &response{} | ||
| 67 | + if err := creditAccountDao.DividendsStatistics(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId}, allDividends); err != nil { | ||
| 68 | + return nil, err | ||
| 69 | + } | ||
| 70 | + allDividends.Accounting = allDividends.Total - allDividends.Accounted | ||
| 71 | + | ||
| 72 | + var ret = &cooperationCompanyStatisticsResponse{ | ||
| 73 | + OrgId: orgId, | ||
| 74 | + CooperationProjectCount: cooperationProjectCount, | ||
| 75 | + CooperationContractCount: cooperationContractCount, | ||
| 76 | + DividendsIncome: utils.Round(allDividends.Total, 2), | ||
| 77 | + } | ||
| 78 | + return ret, nil | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +type cooperationCompanyStatisticsResponse struct { | ||
| 82 | + // 当天统计的企业id | ||
| 83 | + OrgId int64 `json:"orgId"` | ||
| 84 | + // 共创项目数 | ||
| 85 | + CooperationProjectCount int64 `json:"cooperationProjectCount"` | ||
| 86 | + // 共创合约数 | ||
| 87 | + CooperationContractCount int64 `json:"cooperationContractCount"` | ||
| 88 | + // 分红占比 | ||
| 89 | + DividendsRatio float64 `json:"dividendsRatio"` | ||
| 90 | + // 分红支出 | ||
| 91 | + DividendsIncome float64 `json:"dividendsIncome"` | ||
| 92 | +} |
| @@ -29,6 +29,9 @@ const ( | @@ -29,6 +29,9 @@ const ( | ||
| 29 | CompanyDividendsStatistics = "CompanyDividendsStatistics" | 29 | CompanyDividendsStatistics = "CompanyDividendsStatistics" |
| 30 | // 企业、个人 - 分红预算列表 | 30 | // 企业、个人 - 分红预算列表 |
| 31 | SearchDividendsEstimates = "SearchDividendsEstimates" | 31 | SearchDividendsEstimates = "SearchDividendsEstimates" |
| 32 | + | ||
| 33 | + // 个人 - 共创企业统计 | ||
| 34 | + CooperationCompanyStatistics = "CooperationCompanyStatistics" | ||
| 32 | ) | 35 | ) |
| 33 | 36 | ||
| 34 | // CooperationStatisticsService 共创统计服务 | 37 | // CooperationStatisticsService 共创统计服务 |
| @@ -54,6 +57,20 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti | @@ -54,6 +57,20 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti | ||
| 54 | // | 57 | // |
| 55 | // queryOptions 查询参数 | 58 | // queryOptions 查询参数 |
| 56 | func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) { | 59 | func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) { |
| 60 | + var request = struct { | ||
| 61 | + //企业 | ||
| 62 | + CompanyId int64 `json:"companyId"` | ||
| 63 | + OrgId int64 `json:"orgId"` | ||
| 64 | + //个人 | ||
| 65 | + UserBaseId int64 `json:"userBaseId"` | ||
| 66 | + Offset int `json:"offset"` | ||
| 67 | + Limit int `json:"limit"` | ||
| 68 | + }{} | ||
| 69 | + if err := LoadQueryObject(queryOptions, &request); err != nil { | ||
| 70 | + return nil, err | ||
| 71 | + } | ||
| 72 | + queryOptions = tool_funs.SimpleStructToMap(&request) | ||
| 73 | + | ||
| 57 | // 1.根据个人、企业查询合约列表 | 74 | // 1.根据个人、企业查询合约列表 |
| 58 | var contracts []*domain.CooperationContract | 75 | var contracts []*domain.CooperationContract |
| 59 | var err error | 76 | var err error |
| @@ -115,7 +132,6 @@ func (ptr *CooperationStatisticsService) getUserContracts(queryOptions map[strin | @@ -115,7 +132,6 @@ func (ptr *CooperationStatisticsService) getUserContracts(queryOptions map[strin | ||
| 115 | } | 132 | } |
| 116 | queryOptions["inCooperationContractNumber"] = numbers | 133 | queryOptions["inCooperationContractNumber"] = numbers |
| 117 | contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext) | 134 | contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext) |
| 118 | - // TODO: 参数查询条件 | ||
| 119 | _, contracts, err := contractRepository.Find(queryOptions) | 135 | _, contracts, err := contractRepository.Find(queryOptions) |
| 120 | return contracts, err | 136 | return contracts, err |
| 121 | } | 137 | } |
| @@ -203,22 +219,27 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s | @@ -203,22 +219,27 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s | ||
| 203 | var dividends = make([]interface{}, 0) | 219 | var dividends = make([]interface{}, 0) |
| 204 | for i := range creditAccounts { | 220 | for i := range creditAccounts { |
| 205 | a := creditAccounts[i] | 221 | a := creditAccounts[i] |
| 206 | - participateType, _ := strconv.Atoi(a.ParticipateType) | ||
| 207 | - dividends = append(dividends, map[string]interface{}{ | ||
| 208 | - "creditAccountId": a.CreditAccountId, | ||
| 209 | - "orderGoodName": "", | ||
| 210 | - //"dividendsType": a.AccountDetail.DividendsType, | ||
| 211 | - "dividendsRatio": 0, | ||
| 212 | - //"dividendsAmount": a.AccountDetail.DividendsAmount, | ||
| 213 | - "dividendsUser": map[string]interface{}{ | ||
| 214 | - "userInfo": a.Participator.UserInfo, | ||
| 215 | - "userId": a.Participator.UserId, | ||
| 216 | - }, | ||
| 217 | - "dividendsParticipateType": participateType, | ||
| 218 | - "dividendsAccountStatus": a.PaymentStatus, | ||
| 219 | - "dividendsEstimateTime": a.CreatedAt.Unix() * 1000, | ||
| 220 | - "orderOrReturnedOrderNum": a.CreditAccountOrderNum, | ||
| 221 | - }) | 222 | + for j := range a.AccountDetail { |
| 223 | + participateType, _ := strconv.Atoi(a.ParticipateType) | ||
| 224 | + item := map[string]interface{}{ | ||
| 225 | + "creditAccountId": a.CreditAccountId, | ||
| 226 | + "orderGoodName": "", | ||
| 227 | + "dividendsType": 0, | ||
| 228 | + "dividendsRatio": 0, | ||
| 229 | + "dividendsAmount": a.AccountDetail[j].DividendsAmount, | ||
| 230 | + "dividendsUser": map[string]interface{}{ | ||
| 231 | + "userInfo": a.Participator.UserInfo, | ||
| 232 | + "userId": a.Participator.UserId, | ||
| 233 | + }, | ||
| 234 | + "dividendsParticipateType": participateType, | ||
| 235 | + "dividendsAccountStatus": a.PaymentStatus, | ||
| 236 | + "dividendsEstimateTime": a.CreatedAt.Unix() * 1000, | ||
| 237 | + "orderOrReturnedOrderNum": a.CreditAccountOrderNum, | ||
| 238 | + } | ||
| 239 | + item["dividendsType"] = a.AccountDetail[j].DividendsType | ||
| 240 | + dividends = append(dividends, item) | ||
| 241 | + } | ||
| 242 | + | ||
| 222 | } | 243 | } |
| 223 | res["dividends"] = dividends | 244 | res["dividends"] = dividends |
| 224 | return res, nil | 245 | return res, nil |
| @@ -179,6 +179,9 @@ func (repository *CooperationContractRelevantRepository) Find(queryOptions map[s | @@ -179,6 +179,9 @@ func (repository *CooperationContractRelevantRepository) Find(queryOptions map[s | ||
| 179 | if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 { | 179 | if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 { |
| 180 | query.Where("org->>'orgId' in (?)", pg.In(orgIds)) | 180 | query.Where("org->>'orgId' in (?)", pg.In(orgIds)) |
| 181 | } | 181 | } |
| 182 | + if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { | ||
| 183 | + query.Where("user_base_id = ?", userBaseId) | ||
| 184 | + } | ||
| 182 | offsetLimitFlag := true | 185 | offsetLimitFlag := true |
| 183 | if offsetLimit, ok := queryOptions["offsetLimit"]; ok { | 186 | if offsetLimit, ok := queryOptions["offsetLimit"]; ok { |
| 184 | offsetLimitFlag = offsetLimit.(bool) | 187 | offsetLimitFlag = offsetLimit.(bool) |
| @@ -190,6 +190,9 @@ func (repository *CooperationContractUndertakerRepository) Find(queryOptions map | @@ -190,6 +190,9 @@ func (repository *CooperationContractUndertakerRepository) Find(queryOptions map | ||
| 190 | if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 { | 190 | if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 { |
| 191 | query.Where("org->>'orgId' in (?)", pg.In(orgIds)) | 191 | query.Where("org->>'orgId' in (?)", pg.In(orgIds)) |
| 192 | } | 192 | } |
| 193 | + if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { | ||
| 194 | + query.Where("user_base_id = ? ", userBaseId) | ||
| 195 | + } | ||
| 193 | offsetLimitFlag := true | 196 | offsetLimitFlag := true |
| 194 | if offsetLimit, ok := queryOptions["offsetLimit"]; ok { | 197 | if offsetLimit, ok := queryOptions["offsetLimit"]; ok { |
| 195 | offsetLimitFlag = offsetLimit.(bool) | 198 | offsetLimitFlag = offsetLimit.(bool) |
| @@ -202,7 +202,7 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac | @@ -202,7 +202,7 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac | ||
| 202 | query.Where(`(credit_account.participator->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", participatorName)) | 202 | query.Where(`(credit_account.participator->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", participatorName)) |
| 203 | } | 203 | } |
| 204 | if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" { | 204 | if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" { |
| 205 | - query.Where(`cooperation_contract_number = ?`, fmt.Sprintf("%%%s%%", cooperationContractNumber)) | 205 | + query.Where(`cooperation_contract_number = ?`, fmt.Sprintf("%s", cooperationContractNumber)) |
| 206 | } | 206 | } |
| 207 | if paymentStatus, ok := queryOptions["paymentStatus"]; ok && paymentStatus.(int32) != 0 { | 207 | if paymentStatus, ok := queryOptions["paymentStatus"]; ok && paymentStatus.(int32) != 0 { |
| 208 | query.Where("payment_status = ?", paymentStatus) | 208 | query.Where("payment_status = ?", paymentStatus) |
-
请 注册 或 登录 后发表评论