...
|
...
|
@@ -47,6 +47,8 @@ const ( |
|
|
CreditAccountStatistics = "CreditAccountStatistics"
|
|
|
// 公司/个人 - 支付历史统计直方图
|
|
|
PaymentHistoryHistogramStatistics = "PaymentHistoryHistogramStatistics"
|
|
|
// 用户相关的项目合约编号列表查询
|
|
|
RelevantCooperationContractNumbers = "RelevantCooperationContractNumbers"
|
|
|
)
|
|
|
|
|
|
// CooperationStatisticsService 共创统计服务
|
...
|
...
|
@@ -181,7 +183,6 @@ func (ptr *CooperationStatisticsService) getRelevantContracts(queryOptions map[s |
|
|
if len(numbers) == 0 {
|
|
|
return []string{}, nil
|
|
|
}
|
|
|
queryOptions["cooperationContractNumbers"] = numbers
|
|
|
return numbers, err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -348,6 +349,7 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st |
|
|
//企业
|
|
|
CompanyId int64 `json:"companyId"`
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
UserId int64 `json:"userId"`
|
|
|
//个人
|
|
|
UserBaseId int64 `json:"userBaseId"`
|
|
|
}{}
|
...
|
...
|
@@ -363,14 +365,32 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st |
|
|
Paid float64 `json:"paid"`
|
|
|
}
|
|
|
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
|
|
|
var contractNumbers []string
|
|
|
var err error
|
|
|
if request.OrgId > 0 && request.UserId > 0 {
|
|
|
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userId": request.UserId})
|
|
|
if err != nil {
|
|
|
return struct{}{}, err
|
|
|
}
|
|
|
} else if request.UserBaseId > 0 {
|
|
|
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId})
|
|
|
if err != nil {
|
|
|
return struct{}{}, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
queryOptions["cooperationContractNumbers"] = contractNumbers
|
|
|
|
|
|
var allDividends = &CreditAccountStatisticsResponse{}
|
|
|
var annualDividends = &CreditAccountStatisticsResponse{}
|
|
|
var quarterDividends = &CreditAccountStatisticsResponse{}
|
|
|
|
|
|
if len(contractNumbers) > 0 {
|
|
|
if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
allDividends.Accounting = allDividends.Total - allDividends.Accounted
|
|
|
|
|
|
var annualDividends = &CreditAccountStatisticsResponse{}
|
|
|
queryOptions["beginTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local)
|
|
|
queryOptions["endTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
|
|
|
if err := creditAccountDao.DividendsStatistics(queryOptions, annualDividends); err != nil {
|
...
|
...
|
@@ -378,12 +398,12 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st |
|
|
}
|
|
|
annualDividends.Accounting = annualDividends.Total - annualDividends.Accounted
|
|
|
|
|
|
var quarterDividends = &CreditAccountStatisticsResponse{}
|
|
|
queryOptions["beginTime"], queryOptions["endTime"] = quarterBeginEnd()
|
|
|
if err := creditAccountDao.DividendsStatistics(queryOptions, quarterDividends); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
quarterDividends.Accounting = quarterDividends.Total - quarterDividends.Accounted
|
|
|
}
|
|
|
|
|
|
ret := map[string]interface{}{
|
|
|
"allDividends": allDividends,
|
...
|
...
|
@@ -423,6 +443,8 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m |
|
|
var request = struct {
|
|
|
CompanyId int64 `json:"companyId"`
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
|
|
UserBaseId int64 `json:"userBaseId"`
|
|
|
DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态
|
|
|
Offset int64 `json:"offset"`
|
...
|
...
|
@@ -433,10 +455,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m |
|
|
}
|
|
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
|
|
|
|
|
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
|
|
|
_, estimates, err := dividendsEstimateRepository.Find(queryOptions)
|
|
|
var contractNumbers []string
|
|
|
var err error
|
|
|
if request.OrgId > 0 && request.UserId > 0 {
|
|
|
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userId": request.UserId})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
return struct{}{}, err
|
|
|
}
|
|
|
} else if request.UserBaseId > 0 {
|
|
|
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId})
|
|
|
if err != nil {
|
|
|
return struct{}{}, err
|
|
|
}
|
|
|
}
|
|
|
type response struct {
|
|
|
// 承接人分红预算记录ID
|
...
|
...
|
@@ -457,6 +487,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m |
|
|
CustomerName string `json:"customerName"`
|
|
|
}
|
|
|
var results = make([]response, 0)
|
|
|
if len(contractNumbers) == 0 {
|
|
|
return results, nil
|
|
|
}
|
|
|
|
|
|
queryOptions["cooperationContractNumbers"] = contractNumbers
|
|
|
|
|
|
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
|
|
|
_, estimates, err := dividendsEstimateRepository.Find(queryOptions)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
dividendsOrderRepository, _ := repository.NewDividendsOrderRepository(ptr.transactionContext)
|
|
|
dividendsReturnedOrderRepository, _ := repository.NewDividendsReturnedOrderRepository(ptr.transactionContext)
|
|
|
for i := range estimates {
|
...
|
...
|
@@ -469,6 +511,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m |
|
|
DividendsType: item.DividendsType,
|
|
|
DividendsUser: item.DividendsUser,
|
|
|
}
|
|
|
// TODO:优化查询 统一查询到map里面
|
|
|
if item.DividendsType == 1 {
|
|
|
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
|
|
|
"dividendsOrderNumber": item.OrderOrReturnedOrderNum,
|
...
|
...
|
@@ -499,6 +542,8 @@ func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions ma |
|
|
UserBaseId int64 `json:"userBaseId"`
|
|
|
BeginTime time.Time `json:"beginTime"`
|
|
|
EndTime time.Time `json:"endTime"`
|
|
|
// 合约编号列表
|
|
|
CooperationContractNumbers []string `json:"cooperationContractNumbers"`
|
|
|
}{}
|
|
|
if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -522,3 +567,24 @@ type CreditAccountStatisticsResponse struct { |
|
|
Paid float64 `json:"paid"`
|
|
|
Unpaid float64 `json:"unpaid"`
|
|
|
}
|
|
|
|
|
|
//getRelevantContracts 获取相关人的合约
|
|
|
func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var request = struct {
|
|
|
//企业
|
|
|
CompanyId int64 `json:"companyId" valid:"Required"`
|
|
|
OrgId int64 `json:"orgId" valid:"Required"`
|
|
|
UserId int64 `json:"userId" valid:"Required"`
|
|
|
//个人
|
|
|
//UserBaseId int64 `json:"userBaseId"`
|
|
|
//Offset int `json:"offset"`
|
|
|
//Limit int `json:"limit"`
|
|
|
}{}
|
|
|
if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
|
|
|
|
|
contractNumbers, err := ptr.getRelevantContracts(queryOptions)
|
|
|
return contractNumbers, err
|
|
|
} |
...
|
...
|
|