作者 yangfu

共创用户明细

... ... @@ -45,6 +45,10 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.CompanyDividendsStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyCooperationUsersStatistics:
res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyPaymentHistoryStatistics:
res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CooperationUserModeStatistics:
res, err = statisticsService.CooperationUserModeStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.DividendsStatistics:
res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.SearchDividendsEstimates:
... ... @@ -53,6 +57,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.CreditAccountStatistics:
res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -21,8 +21,8 @@ type CooperationModeStatisticsDto struct {
OrderAmount float64 `json:"orderAmount"`
// 共创模式编号
CooperationModeNumber string `json:"cooperationModeNumber"`
// 共创模式
// cooperationMode *CooperationMode
// 结算金额
SettlementAmount float64 `json:"settlementAmount"`
}
type DividendStatisticsDto struct {
... ...
... ... @@ -60,7 +60,7 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa
query.ColumnExpr(`sum(settlement_amount) total`)
query.ColumnExpr(`sum((case when payment_status = 1 then actually_paid_amount else 0 end)) paid`)
query.ColumnExpr(`sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted `)
if _, ok := queryOptions["beginTime"]; ok {
if v, ok := queryOptions["beginTime"]; ok && !(v.(time.Time).IsZero()) {
query.Where(`created_at>? `, queryOptions["beginTime"])
query.Where(`created_at<? `, queryOptions["endTime"])
}
... ... @@ -94,6 +94,15 @@ func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions ma
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)
... ... @@ -103,7 +112,7 @@ func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions ma
query.Order("divides_amount desc")
}
}
query.GroupExpr("participator->>'userBaseId'")
query.GroupExpr("participator->>'userId'")
query.Limit(queryOptions["limit"].(int))
query.Offset(queryOptions["offset"].(int))
err := query.Select(v)
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"time"
)
... ... @@ -38,12 +39,12 @@ order by good_amount desc
return goods, err
}
// CooperationModeStatistics 共创模式统计
// CooperationCompanyModeStatistics 共创模式统计
//
// queryOptions 查询参数
// - companyId 企业Id
// - orgId 组织Id
func (dao *OrderGoodDao) CooperationModeStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationModeStatisticsDto, error) {
func (dao *OrderGoodDao) CooperationCompanyModeStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationModeStatisticsDto, error) {
tx := dao.transactionContext.PgTx
var goods []*domain.CooperationModeStatisticsDto
sql := fmt.Sprintf(`select count(0) cooperation_people,sum(a.actually_paid_amount) dividends_estimate,b.cooperation_mode_number,sum(good_amount_count) order_amount
... ... @@ -55,6 +56,30 @@ group by b.cooperation_mode_number
return goods, err
}
// 共创用户模式统计
func (dao *OrderGoodDao) CooperationUserModeStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationModeStatisticsDto, error) {
tx := dao.transactionContext.PgTx
var goods []*domain.CooperationModeStatisticsDto
creditAccount := new(models.CreditAccount)
query := tx.Model(creditAccount)
query.ColumnExpr("count(0) cooperation_people")
query.ColumnExpr("sum(actually_paid_amount) dividends_estimate")
query.ColumnExpr("sum(good_amount_count) order_amount")
query.ColumnExpr("sum(actually_paid_amount) settlement_amount")
query.ColumnExpr("a.cooperation_mode_number cooperation_mode_number")
query.Join("inner join cooperation_contracts as a").JoinOn("a.cooperation_contract_number = credit_account.cooperation_contract_number")
if v, ok := queryOptions["userId"]; ok && v.(int64) > 0 {
query.Where(fmt.Sprintf(`credit_account.participator->>'userId'='%v' `, v))
}
if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v))
}
query.Where("credit_account.deleted_at is null")
query.Group("cooperation_mode_number")
err := query.Select(&goods)
return goods, err
}
// DividendsStatistics 企业分红统计
//
// queryOptions 查询参数
... ...
... ... @@ -7,6 +7,7 @@ import (
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"math"
... ... @@ -91,7 +92,7 @@ func (ptr *CooperationStatisticsService) CooperationModeStatistics(queryOptions
}
queryOptions = tool_funs.SimpleStructToMap(&request)
modeStatistics, err := orderGoodDao.CooperationModeStatistics(queryOptions)
modeStatistics, err := orderGoodDao.CooperationCompanyModeStatistics(queryOptions)
if err != nil {
return nil, err
}
... ... @@ -201,18 +202,7 @@ func (ptr *CooperationStatisticsService) CompanyCooperationUsersStatistics(query
}
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
var responses []usersStatisticsResponse
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
if err := creditAccountDao.CooperationUsersDividendsStatistics(queryOptions, &responses); err != nil {
return nil, err
... ... @@ -238,3 +228,122 @@ func (ptr *CooperationStatisticsService) CompanyCooperationUsersStatistics(query
return retMap, nil
}
type usersStatisticsResponse 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"`
}
// 公司 - 共创用户模式统计
func (ptr *CooperationStatisticsService) CooperationUserModeStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
UserId int64 `json:"offset" valid:"Required"`
//OrgId int64 `json:"orgId" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
modeStatistics, err := orderGoodDao.CooperationUserModeStatistics(queryOptions)
if err != nil {
return nil, err
}
if len(modeStatistics) == 0 {
return struct{}{}, nil
}
var modeNumbers []string
var mapModeStatistics = make(map[string]*domain.CooperationModeStatisticsDto)
for i := range modeStatistics {
mapModeStatistics[modeStatistics[i].CooperationModeNumber] = modeStatistics[i]
modeNumbers = append(modeNumbers, modeStatistics[i].CooperationModeNumber)
}
cooperationModeRepository, _ := repository.NewCooperationModeRepository(ptr.transactionContext)
_, cooperModes, err := cooperationModeRepository.Find(map[string]interface{}{"cooperationModeNumbers": modeNumbers})
if err != nil {
return nil, err
}
var cooperationTypes, dividendsExpenseByTypes, orderAmountByTypes []interface{}
var totalOrderAmount float64
var totalDividendAmount float64
for i := range cooperModes {
m := cooperModes[i]
if modeStatistics, ok := mapModeStatistics[m.CooperationModeNumber]; ok {
totalOrderAmount += modeStatistics.OrderAmount
totalDividendAmount += modeStatistics.SettlementAmount
dividendsExpenseByTypes = append(dividendsExpenseByTypes, map[string]interface{}{
"dividendsTypeName": m.CooperationModeName + "分红支出",
"dividendsExpense": modeStatistics.SettlementAmount,
})
orderAmountByTypes = append(orderAmountByTypes, map[string]interface{}{
"orderAmount": modeStatistics.OrderAmount,
"orderTypeName": m.CooperationModeName + "成交订单",
})
}
cooperationTypes = append(cooperationTypes, map[string]interface{}{
"cooperationModeId": m.CooperationModeId,
"cooperationModeName": m.CooperationModeName,
"cooperationModeNumber": m.CooperationModeNumber,
})
}
return map[string]interface{}{
"cooperationTypes": cooperationTypes,
"dividendsDetails": map[string]interface{}{
"dividendsExpense": totalDividendAmount,
"dividendsExpenseByTypes": dividendsExpenseByTypes,
},
"orderDetails": map[string]interface{}{
"orderAmount": totalOrderAmount,
"orderAmountByTypes": orderAmountByTypes,
},
}, nil
}
// 公司 - 共创用户分红支付统计
func (ptr *CooperationStatisticsService) CompanyPaymentHistoryStatistics(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"`
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)
var responses []usersStatisticsResponse
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 {
retMap = append(retMap, map[string]interface{}{
"paymentAmount": responses[i].ActuallyPaidAmount,
"user": map[string]interface{}{
"userId": responses[i].UserId,
"userInfo": map[string]interface{}{
"userName": responses[i].UserName,
},
},
})
}
return retMap, nil
}
... ...
... ... @@ -32,11 +32,18 @@ const (
SearchDividendsEstimates = "SearchDividendsEstimates"
// 公司 - 共创用户统计
CompanyCooperationUsersStatistics = "CompanyCooperationUsersStatistics"
//公司 - 共创用户模式统计
CooperationUserModeStatistics = "CooperationUserModeStatistics"
// 公司 - 共创用户分红支付统计
CompanyPaymentHistoryStatistics = "CompanyPaymentHistoryStatistics"
// 个人 - 共创企业统计
CooperationCompanyStatistics = "CooperationCompanyStatistics"
// 个人 - 用户合约统计
PersonCooperationContractStatistics = "PersonCooperationContractStatistics"
// 账期结算单统计
CreditAccountStatistics = "CreditAccountStatistics"
)
// CooperationStatisticsService 共创统计服务
... ... @@ -302,7 +309,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
return res, nil
}
// 分红统计(分红明细)
// 分红明细
func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
... ... @@ -449,3 +456,33 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
}
return results, nil
}
// 账期结算单统计
func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
OrgId int64 `json:"orgId"`
UserBaseId int64 `json:"userBaseId"`
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 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{}
if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
return nil, err
}
allDividends.Accounting = allDividends.Total - allDividends.Accounted
return allDividends, nil
}
... ...
... ... @@ -175,6 +175,9 @@ func (repository *CooperationModeRepository) Find(queryOptions map[string]interf
if cooperationModeIds, ok := queryOptions["cooperationModeIds"]; ok && len(cooperationModeIds.([]int64)) > 0 {
query.Where("cooperation_mode_id in (?)", pg.In(cooperationModeIds))
}
if cooperationModeNumbers, ok := queryOptions["cooperationModeNumbers"]; ok && len(cooperationModeNumbers.([]string)) > 0 {
query.Where("Cooperation_mode_number in (?)", pg.In(cooperationModeNumbers))
}
if cooperationModeName, ok := queryOptions["cooperationModeName"]; ok && cooperationModeName != "" {
query.Where("cooperation_mode_name like ?", fmt.Sprintf("%%%s%%", cooperationModeName))
}
... ... @@ -187,7 +190,7 @@ func (repository *CooperationModeRepository) Find(queryOptions map[string]interf
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]string)) > 0 {
if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 {
query.Where("org->>'orgId' in (?)", pg.In(orgIds))
}
offsetLimitFlag := true
... ...