作者 yangfu

账期结算单统计

... ... @@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyPaymentHistoryStatistics:
res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.PaymentHistoryHistogramStatistics:
res, err = statisticsService.PaymentHistoryHistogramStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CooperationUserModeStatistics:
res, err = statisticsService.CooperationUserModeStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.DividendsStatistics:
... ... @@ -57,6 +59,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.CooperationCompanyStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCooperationContractStatistics:
res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCompanyPaymentHistoryStatistics:
res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CreditAccountStatistics:
res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
}
... ...
... ... @@ -119,6 +119,51 @@ func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions ma
return err
}
// 共创企业分红统计
func (dao *CreditAccountDao) CooperationCompanyDividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
creditAccount := new(models.CreditAccount)
query := dao.transactionContext.PgTx.Model(creditAccount)
query.ColumnExpr(`0 cooperation_time`)
query.ColumnExpr(`sum(good_amount_count) 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(org->>'orgId') org_id`)
query.ColumnExpr(`max(org->>'orgName') org_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))
}
if v, ok := queryOptions["paymentStatus"]; ok && v.(int32) > 0 {
query.Where("paymentStatus = ?", v)
}
if v, ok := queryOptions["beginTime"]; ok && !v.(time.Time).IsZero() {
query.Where("created_at >= ?", v)
}
if v, ok := queryOptions["endTime"]; ok && !v.(time.Time).IsZero() {
query.Where("created_at < ?", v)
}
query.Where("deleted_at is null")
if v, ok := queryOptions["sortByActuallyPaidAmount"]; ok {
vInt := v.(int)
if vInt == 1 {
query.Order("actually_paid_amount asc")
} else {
query.Order("actually_paid_amount desc")
}
}
query.GroupExpr("org->>'orgId'")
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参数不能为空")
... ...
... ... @@ -347,3 +347,52 @@ func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(queryOp
return retMap, nil
}
// 公司/个人 - 支付历史统计直方图
func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(queryOptions map[string]interface{}) (interface{}, error) {
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
var request = struct {
OrgId int64 `json:"orgId"`
UserBaseId int64 `json:"userBaseId"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
var dividends = &CreditAccountStatisticsResponse{}
var beginTime, endTime time.Time
var increaseDay = 5
var monthEnd = utils.GetFirstDateOfMonth(time.Now()).Add(-time.Second)
var xAxisData []string
var values []float64
for {
if beginTime.AddDate(0, 0, increaseDay).After(monthEnd) {
endTime = monthEnd
}
if endTime.After(monthEnd) {
break
}
xAxisData = append(xAxisData, endTime.Format("01-02"))
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
if err := creditAccountDao.DividendsStatistics(queryOptions, dividends); err != nil {
return nil, err
}
dividends.Accounting = dividends.Total - dividends.Accounted
values = append(values, dividends.Paid)
beginTime = endTime.AddDate(0, 0, increaseDay)
endTime = endTime.AddDate(0, 0, increaseDay)
}
return map[string]interface{}{
"xAxis": map[string]interface{}{
"data": xAxisData,
},
"source": map[string]interface{}{
"value": values,
},
}, nil
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"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"
"time"
)
// 共创公司统计
... ... @@ -138,3 +139,52 @@ func (ptr *CooperationStatisticsService) cooperationContractCount(numbers []stri
query.Select(&total)
return total
}
// 个人 - 企业支付统计
func (ptr *CooperationStatisticsService) PersonCompanyPaymentHistoryStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
Limit int `json:"limit" valid:"Required"`
Offset int `json:"offset"`
UserBaseId int64 `json:"userBaseId" valid:"Required"`
OrgId int64 `json:"orgId" valid:"Required"`
SortByActuallyPaidAmount int `json:"sortByActuallyPaidAmount" valid:"Required"`
BeginTime time.Time `json:"beginTime"`
EndTime time.Time `json:"endTime"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
type companyStatisticsResponse struct {
CooperationTime int64 `json:"cooperationTime"`
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
DividesAmount float64 `json:"dividesAmount"` // 分红金额
ActuallyPaidAmount float64 `json:"actuallyPaidAmount"` // 已支付金额
UnPaidAmount float64 `json:"unPaidAmount"` // 未支付金额
OrgId int64 `json:"orgId,string"`
OrgName string `json:"orgName"`
Participator interface{} `json:"participator"`
}
var responses []companyStatisticsResponse
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
if err := creditAccountDao.CooperationCompanyDividendsStatistics(queryOptions, &responses); err != nil {
return nil, err
}
var retMap = make([]interface{}, 0)
for i := range responses {
retMap = append(retMap, map[string]interface{}{
"paymentAmount": responses[i].ActuallyPaidAmount,
"org": map[string]interface{}{
"orgId": responses[i].OrgId,
"orgName": responses[i].OrgName,
},
})
}
return retMap, nil
}
... ...
... ... @@ -41,9 +41,13 @@ const (
CooperationCompanyStatistics = "CooperationCompanyStatistics"
// 个人 - 用户合约统计
PersonCooperationContractStatistics = "PersonCooperationContractStatistics"
// 个人 - 企业支付统计
PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics"
// 账期结算单统计
CreditAccountStatistics = "CreditAccountStatistics"
// 公司/个人 - 支付历史统计直方图
PaymentHistoryHistogramStatistics = "PaymentHistoryHistogramStatistics"
)
// CooperationStatisticsService 共创统计服务
... ... @@ -471,18 +475,19 @@ func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions ma
}
queryOptions = tool_funs.SimpleStructToMap(&request)
type response struct {
Total float64 `json:"total"`
Accounting float64 `json:"accounting"`
Accounted float64 `json:"accounted"`
Paid float64 `json:"paid"`
}
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
var allDividends = &response{}
var allDividends = &CreditAccountStatisticsResponse{}
if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
return nil, err
}
allDividends.Accounting = allDividends.Total - allDividends.Accounted
return allDividends, nil
}
type CreditAccountStatisticsResponse struct {
Total float64 `json:"total"`
Accounting float64 `json:"accounting"`
Accounted float64 `json:"accounted"`
Paid float64 `json:"paid"`
}
... ...