|
|
package service
|
|
|
|
|
|
import (
|
|
|
"github.com/linmadan/egglib-go/utils/json"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// CompanyCreditAccountService 企业端账期结算
|
...
|
...
|
@@ -16,16 +18,30 @@ type CompanyCreditAccountService struct { |
|
|
func (srv CompanyCreditAccountService) CreditAccountSearch(cmd *command.CreditAccountSearchCommand) (int64, interface{}, error) {
|
|
|
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
|
|
|
cmd.Operator)
|
|
|
|
|
|
cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{
|
|
|
"companyId": cmd.Operator.CompanyId,
|
|
|
"orgId": cmd.Operator.OrgId,
|
|
|
"userId": cmd.Operator.UserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
var items = make([]*dto.CreditAccountItem, 0)
|
|
|
if len(cooperationContractNumbers) == 0 {
|
|
|
return 0, items, nil
|
|
|
}
|
|
|
resultMenu, err := gateway.CreditAccountsSearch(allied_creation_cooperation.ReqCreditAccountsSearch{
|
|
|
PageNumber: cmd.PageNumber,
|
|
|
PageSize: cmd.PageSize,
|
|
|
PaymentStatus: cmd.PaymentStatus,
|
|
|
OrgId: cmd.Operator.OrgId,
|
|
|
PageNumber: cmd.PageNumber + 1, //手机序号从0开始的
|
|
|
PageSize: cmd.PageSize,
|
|
|
PaymentStatus: cmd.PaymentStatus,
|
|
|
OrgId: cmd.Operator.OrgId,
|
|
|
CooperationContractNumbers: cooperationContractNumbers,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
var items []*dto.CreditAccountItem
|
|
|
|
|
|
for i := 0; i < len(resultMenu.Grid.List); i++ {
|
|
|
items = append(items, dto.ToCreditAccountItem(&resultMenu.Grid.List[i]))
|
|
|
}
|
...
|
...
|
@@ -67,10 +83,10 @@ func (srv CompanyCreditAccountService) CreditAccountPay(cmd *command.CreditAccou |
|
|
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
|
|
|
cmd.Operator)
|
|
|
resultMenu, err := gateway.CreditAccountsPay(allied_creation_cooperation.ReqCreditAccountsPay{
|
|
|
CreditAccountId: cmd.CreditAccountId,
|
|
|
ActuallyPaidAmount: cmd.ActuallyPaidAmount,
|
|
|
Remarks: cmd.Remarks,
|
|
|
Attachment: cmd.Attachment,
|
|
|
CreditAccountId: cmd.CreditAccountId,
|
|
|
ActuallyPaidAmount: cmd.ActuallyPaidAmount,
|
|
|
Remarks: cmd.Remarks,
|
|
|
PaymentDocumentAttachment: cmd.Attachment,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
...
|
...
|
@@ -82,24 +98,75 @@ func (srv CompanyCreditAccountService) CreditAccountPay(cmd *command.CreditAccou |
|
|
func (srv CompanyCreditAccountService) CreditAccountPaySearch(cmd *command.CreditAccountPaySearchCommand) (interface{}, error) {
|
|
|
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
|
|
|
cmd.Operator)
|
|
|
resultMenu, err := gateway.CreditAccountsSearch(allied_creation_cooperation.ReqCreditAccountsSearch{
|
|
|
PageNumber: cmd.PageNumber,
|
|
|
PageSize: cmd.PageSize,
|
|
|
PaymentStatus: 2,
|
|
|
//TODO:时间段过滤
|
|
|
|
|
|
cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{
|
|
|
"companyId": cmd.Operator.CompanyId,
|
|
|
"orgId": cmd.Operator.OrgId,
|
|
|
"userId": cmd.Operator.UserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
var items []*dto.CreditAccountItem
|
|
|
var items = make([]*dto.CreditAccountItem, 0)
|
|
|
if len(cooperationContractNumbers) == 0 {
|
|
|
return items, nil
|
|
|
}
|
|
|
|
|
|
var beginTime, endTime time.Time
|
|
|
if cmd.BeginTime > 0 {
|
|
|
beginTime = time.Unix(cmd.BeginTime/1000, 0)
|
|
|
}
|
|
|
if cmd.EndTime > 0 {
|
|
|
endTime = time.Unix(cmd.EndTime/1000, 0)
|
|
|
}
|
|
|
req := allied_creation_cooperation.ReqCreditAccountsSearch{
|
|
|
PageNumber: cmd.PageNumber + 1, //手机序号从0开始的
|
|
|
PageSize: cmd.PageSize,
|
|
|
PaymentStatus: 2,
|
|
|
OrgId: cmd.Operator.OrgId,
|
|
|
BeginTime: beginTime,
|
|
|
EndTime: endTime,
|
|
|
CooperationContractNumbers: cooperationContractNumbers,
|
|
|
}
|
|
|
resultMenu, err := gateway.CreditAccountsSearch(req)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
queryOptions := map[string]interface{}{
|
|
|
"orgId": cmd.Operator.OrgId,
|
|
|
"cooperationContractNumbers": cooperationContractNumbers,
|
|
|
}
|
|
|
if cmd.BeginTime > 0 {
|
|
|
queryOptions["beginTime"] = beginTime
|
|
|
}
|
|
|
if cmd.EndTime > 0 {
|
|
|
queryOptions["endTime"] = endTime
|
|
|
}
|
|
|
// 2.分红统计
|
|
|
dividendStatisticsResult, err := gateway.CooperationStatistics(allied_creation_cooperation.CreditAccountStatistics, queryOptions)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
type AnnualDividend struct {
|
|
|
Total float64 `json:"total"`
|
|
|
Accounting float64 `json:"accounting"`
|
|
|
Accounted float64 `json:"accounted"`
|
|
|
Paid float64 `json:"paid"`
|
|
|
Unpaid float64 `json:"unpaid"`
|
|
|
}
|
|
|
var annualDividend = &AnnualDividend{}
|
|
|
if err := json.UnmarshalFromString(json.MarshalToString(dividendStatisticsResult), annualDividend); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
//var items = make([]*dto.CreditAccountItem, 0)
|
|
|
for i := 0; i < len(resultMenu.Grid.List); i++ {
|
|
|
items = append(items, dto.ToCreditAccountItem(&resultMenu.Grid.List[i]))
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"grid": map[string]interface{}{
|
|
|
"list": items,
|
|
|
//TODO:sum 时间段支付金额
|
|
|
"sum": 6000,
|
|
|
"sum": annualDividend.Paid,
|
|
|
},
|
|
|
}, nil
|
|
|
}
|
...
|
...
|
@@ -108,7 +175,25 @@ func (srv CompanyCreditAccountService) CreditAccountPaySearch(cmd *command.Credi |
|
|
func (srv CompanyCreditAccountService) PaymentHistoryStatistics(cmd *command.CreditAccountPaySearchCommand) (interface{}, error) {
|
|
|
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
|
|
|
cmd.Operator)
|
|
|
|
|
|
var response = struct {
|
|
|
rankItems interface{} `json:"rankItems"`
|
|
|
TotalPaymentAmount interface{} `json:"totalPaymentAmount"`
|
|
|
}{}
|
|
|
cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{
|
|
|
"companyId": cmd.Operator.CompanyId,
|
|
|
"orgId": cmd.Operator.OrgId,
|
|
|
"userId": cmd.Operator.UserId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cooperationContractNumbers) == 0 {
|
|
|
return response, nil
|
|
|
}
|
|
|
|
|
|
queryOptions := map[string]interface{}{
|
|
|
"userId": cmd.Operator.UserId,
|
|
|
"orgId": cmd.Operator.OrgId,
|
|
|
"offset": cmd.PageNumber * cmd.PageSize,
|
|
|
"limit": cmd.PageSize,
|
...
|
...
|
@@ -125,15 +210,15 @@ func (srv CompanyCreditAccountService) PaymentHistoryStatistics(cmd *command.Cre |
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
queryOptions["cooperationContractNumbers"] = cooperationContractNumbers
|
|
|
creditAccountStatistics, err := gateway.CreditAccountStatistics(allied_creation_cooperation.CreditAccountStatistics, queryOptions)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
response.rankItems = cooperationUsersStatistics
|
|
|
response.TotalPaymentAmount = creditAccountStatistics.Paid
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"rankItems": cooperationUsersStatistics,
|
|
|
"totalPaymentAmount": creditAccountStatistics.Paid,
|
|
|
}, nil
|
|
|
return response, nil
|
|
|
}
|
|
|
|
|
|
// PaymentHistoryHistogramStatistics 支付历史统计-直方图
|
...
|
...
|
@@ -141,7 +226,10 @@ func (srv CompanyCreditAccountService) PaymentHistoryHistogramStatistics(cmd *co |
|
|
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
|
|
|
cmd.Operator)
|
|
|
paymentHistoryHistogramStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.PaymentHistoryHistogramStatistics, map[string]interface{}{
|
|
|
"orgId": cmd.Operator.OrgId,
|
|
|
"orgId": cmd.Operator.OrgId,
|
|
|
"userId": cmd.Operator.UserId,
|
|
|
"beginTime": time.Unix(cmd.BeginTime/1000, 0),
|
|
|
"endTime": time.Unix(cmd.EndTime/1000, 0),
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
...
|
...
|
|