作者 yangfu

共创用户列表修改

... ... @@ -43,12 +43,16 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.CooperationModeStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyDividendsStatistics:
res, err = statisticsService.CompanyDividendsStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyCooperationUsersStatistics:
res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.DividendsStatistics:
res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.SearchDividendsEstimates:
res, err = statisticsService.SearchDividendsEstimates(contractStatisticsQuery.QueryOptions)
case domain_service.CooperationCompanyStatistics:
res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCooperationContractStatistics:
res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions)
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -55,27 +55,6 @@ func (dao *CreditAccountDao) CheckCreditAccountNumberAvailable(queryOptions map[
// 分红统计(分红明细)
func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
// sql := `
//select
//sum(settlement_amount) total,
//sum((case when payment_status = 1 then actually_paid_amount else 0 end)) paid,
//sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted
//from credit_accounts
//where
//`
//
//
// if _, ok := queryOptions["beginTime"]; ok {
// sql += `created_at>? and created_at<? and `
// }
// if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 {
// sql += fmt.Sprintf(`participator->>'userBaseId'='%v' `, v)
// }
// if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
// sql += fmt.Sprintf(` org->>'orgId'= '%v'`, v)
// }
// _, err := dao.transactionContext.PgDd.Query(v, sql, queryOptions["beginTime"], queryOptions["endTime"])
creditAccount := new(models.CreditAccount)
query := dao.transactionContext.PgTx.Model(creditAccount)
query.ColumnExpr(`sum(settlement_amount) total`)
... ... @@ -95,6 +74,42 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa
return err
}
// 分红统计(分红明细)
func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
creditAccount := new(models.CreditAccount)
query := dao.transactionContext.PgTx.Model(creditAccount)
query.ColumnExpr(`0 cooperation_time`)
query.ColumnExpr(`0 dividends_order_amount`)
query.ColumnExpr(`sum(settlement_amount) divides_amount`)
query.ColumnExpr(`sum((case when payment_status = 1 then actually_paid_amount else 0 end)) actually_paid_amount`)
query.ColumnExpr(`max(participator->>'userId') user_id`)
query.ColumnExpr(`max(participator#>>'{userInfo,userName}') user_name`)
if _, ok := queryOptions["beginTime"]; ok {
query.Where(`created_at>? `, queryOptions["beginTime"])
query.Where(`created_at<? `, queryOptions["endTime"])
}
if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 {
query.Where(fmt.Sprintf(`participator->>'userBaseId'='%v' `, v))
}
if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v))
}
query.Where("deleted_at is null")
if v, ok := queryOptions["sortByActuallyPaidAmount"]; ok {
vInt := v.(int)
if vInt == 1 {
query.Order("divides_amount asc")
} else {
query.Order("divides_amount desc")
}
}
query.GroupExpr("participator->>'userBaseId'")
query.Limit(queryOptions["limit"].(int))
query.Offset(queryOptions["offset"].(int))
err := query.Select(v)
return err
}
func NewCreditAccountDao(transactionContext *pgTransaction.TransactionContext) (*CreditAccountDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -186,3 +186,61 @@ type item struct {
key string
val interface{}
}
// 公司 - 共创用户统计
func (ptr *CooperationStatisticsService) CompanyCooperationUsersStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
Limit int `json:"limit" valid:"Required"`
Offset int `json:"offset"`
OrgId int64 `json:"orgId" valid:"Required"`
SortByActuallyPaidAmount int `json:"sortByActuallyPaidAmount" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
type response struct {
CooperationTime int64 `json:"cooperationTime"`
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
DividesAmount float64 `json:"dividesAmount"` // 分红金额
ActuallyPaidAmount float64 `json:"actuallyPaidAmount"` // 已支付金额
UnPaidAmount float64 `json:"unPaidAmount"` // 未支付金额
UserId int64 `json:"userId,string"`
UserName string `json:"userName"`
Participator interface{} `json:"participator"`
}
var responses []response
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
if err := creditAccountDao.CooperationUsersDividendsStatistics(queryOptions, &responses); err != nil {
return nil, err
}
var retMap = make([]interface{}, 0)
for i := range responses {
responses[i].CooperationTime = time.Now().Unix() * 1000
unPaidAmount := responses[i].DividesAmount - responses[i].ActuallyPaidAmount
responses[i].Participator = map[string]interface{}{
"userId": responses[i].UserId,
"userInfo": map[string]interface{}{
"userName": responses[i].UserName,
},
}
retMap = append(retMap, map[string]interface{}{
"dividendsOrderAmount": 0,
"dividesAmount": responses[i].DividesAmount,
"unPaidAmount": unPaidAmount,
"cooperationTime": time.Now().Unix() * 1000,
"participator": map[string]interface{}{
"userId": responses[i].UserId,
"userInfo": map[string]interface{}{
"userName": responses[i].UserName,
},
},
})
}
return retMap, nil
}
... ...
package domain_service
import (
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
... ... @@ -90,3 +92,49 @@ type cooperationCompanyStatisticsResponse struct {
// 分红支出
DividendsIncome float64 `json:"dividendsIncome"`
}
// 个人-用户合约统计
func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
UserBaseId int64 `json:"userBaseId" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
cooperationContractUndertaker, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
_, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions)
if err != nil {
return nil, nil
}
var response = struct {
ContractSum int `json:"contractSum"`
ContractStoppedSum int `json:"contractStoppedSum"`
}{}
if len(contractUndertakers) == 0 {
return response, nil
}
var numbers []string
for i := range contractUndertakers {
numbers = append(numbers, contractUndertakers[i].CooperationContractNumber)
}
response.ContractSum = ptr.cooperationContractCount(numbers, 0)
response.ContractStoppedSum = ptr.cooperationContractCount(numbers, 2)
return response, nil
}
func (ptr *CooperationStatisticsService) cooperationContractCount(numbers []string, status int) int {
var total int
var contract = new(models.CooperationContract)
query := ptr.transactionContext.PgDd.Model(contract)
query.ColumnExpr("count(*) total")
query.Where("cooperation_contract_number in (?)", pg.In(numbers))
if status > 0 {
query.Where("status =? ")
}
query.Select(&total)
return total
}
... ...
... ... @@ -29,9 +29,13 @@ const (
CompanyDividendsStatistics = "CompanyDividendsStatistics"
// 企业、个人 - 分红预算列表
SearchDividendsEstimates = "SearchDividendsEstimates"
// 公司 - 共创用户统计
CompanyCooperationUsersStatistics = "CompanyCooperationUsersStatistics"
// 个人 - 共创企业统计
CooperationCompanyStatistics = "CooperationCompanyStatistics"
// 个人 - 用户合约统计
PersonCooperationContractStatistics = "PersonCooperationContractStatistics"
)
// CooperationStatisticsService 共创统计服务
... ...
... ... @@ -234,6 +234,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if cooperationApplicationIds, ok := queryOptions["cooperationApplicationIds"]; ok && len(cooperationApplicationIds.([]int64)) > 0 {
query.Where("cooperation_application_id IN (?)", pg.In(cooperationApplicationIds))
}
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...