作者 yangfu

账期结算修改

... ... @@ -225,6 +225,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
// 变更分红预算单结算状态
for i, _ := range dividendsEstimates {
dividendsEstimates[i].DividendsAccountStatus = 2
dividendsEstimates[i].CreditAccountId = creditAccount.CreditAccountId
}
_, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimates)
if err3 != nil {
... ...
... ... @@ -47,6 +47,8 @@ type ContractParticipant struct {
DividendsAmount float64 `json:"dividendsAmount"`
// 合同内容
ContractContent string `json:"contractContent"`
// 支付凭证
PaymentDocument string `json:"paymentDocument"`
// 敏感标识
SensitiveFlag bool `json:"sensitiveFlag"`
// 共创合约编号
... ...
... ... @@ -71,6 +71,8 @@ type DividendsEstimate struct {
OrderGoodId int64 `json:"orderGoodId"`
// 订单产品金额
OrderGoodAmount float64 `json:"orderGoodAmount"`
// 账期结算Id
CreditAccountId int64 `json:"creditAccountId"`
}
type DividendsEstimateRepository interface {
... ...
... ... @@ -289,14 +289,47 @@ func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfo(quer
})
// 3.计算合约用户的分红预算金额
var mapCreditAccount = make(map[string]*domain.CreditAccount)
var creditAccountIds = make([]int64, 0)
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
_, dividends, err := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId, "dividendsAccountStatus": int32(1), "offsetLimit": false})
_, dividends, err := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId, "isCanceled": false, "offsetLimit": false})
if err != nil {
return nil, err
}
for i := range dividends {
d := dividends[i]
key := keyfun(d.CooperationContractNumber, d.DividendsUser.UserBaseId)
if v, ok := mapUser[key]; ok {
v.DividendsAmount += d.DividendsAmount
}
if d.PaymentStatus == 2 && d.CreditAccountId != 0 {
creditAccountIds = append(creditAccountIds, d.CreditAccountId)
}
}
// 3.1 用户账期结算记录 - 查询是否有支付凭证
if len(creditAccountIds) > 0 {
creditAccountRepository, _ := repository.NewCreditAccountRepository(ptr.transactionContext)
_, creditAccounts, err := creditAccountRepository.Find(map[string]interface{}{
"creditAccountIds": creditAccountIds,
})
if err != nil {
return nil, err
}
for i := range creditAccounts {
if len(creditAccounts[i].PaymentDocumentAttachments) == 0 {
continue
}
for j := range creditAccounts[i].AccountDetail {
detail := creditAccounts[i].AccountDetail[j]
key := keyfun(detail.CooperationContractNumber, creditAccounts[i].Participator.UserBaseId)
mapCreditAccount[key] = creditAccounts[i]
if v, ok := mapUser[key]; ok && len(v.PaymentDocument) == 0 {
if len(mapCreditAccount[key].PaymentDocumentAttachments) > 0 {
v.PaymentDocument = "查看"
}
}
}
}
}
for _, v := range mapUser {
... ...
... ... @@ -55,4 +55,6 @@ type DividendsEstimate struct {
DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 账期结算Id
CreditAccountId int64 `comment:"creditAccountId"`
}
... ...
... ... @@ -33,5 +33,6 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel
CreatedAt: dividendsEstimateModel.CreatedAt,
DeletedAt: dividendsEstimateModel.DeletedAt,
UpdatedAt: dividendsEstimateModel.UpdatedAt,
CreditAccountId: dividendsEstimateModel.CreditAccountId,
}, nil
}
... ...
... ... @@ -199,8 +199,12 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac
var creditAccountModels []*models.CreditAccount
creditAccounts := make([]*domain.CreditAccount, 0)
query := sqlbuilder.BuildQuery(tx.Model(&creditAccountModels), queryOptions)
if creditAccountIds, ok := queryOptions["creditAccountIds"]; ok && len(creditAccountIds.([]int64)) > 0 {
newCreditAccountIds := utils.SliceItoa(creditAccountIds.([]int64))
query.Where("credit_account_id in (?)", pg.In(newCreditAccountIds))
}
if creditAccountOrderNum, ok := queryOptions["creditAccountOrderNum"]; ok && creditAccountOrderNum != "" {
query.Where("credit_account_order_num ilike ?", fmt.Sprintf("%%%s%%", creditAccountOrderNum))
query.Where("credit_account_order_num like ?", fmt.Sprintf("%%%s%%", creditAccountOrderNum))
}
if participatorName, ok := queryOptions["participatorName"]; ok && participatorName != "" {
query.Where(`(credit_account.participator->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", participatorName))
... ...
... ... @@ -50,6 +50,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
"deleted_at",
"updated_at",
"cooperation_contract_undertaker_id",
"credit_account_id",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -90,6 +91,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
&dividendsEstimate.CooperationContractUndertakerId,
&dividendsEstimate.CreditAccountId,
),
fmt.Sprintf("INSERT INTO dividends_estimates (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
... ... @@ -116,6 +118,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
nil,
dividendsEstimate.UpdatedAt,
dividendsEstimate.CooperationContractUndertakerId,
dividendsEstimate.CreditAccountId,
); err != nil {
return dividendsEstimate, err
}
... ... @@ -146,6 +149,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
&dividendsEstimate.CooperationContractUndertakerId,
dividendsEstimate.CreditAccountId,
),
fmt.Sprintf("UPDATE dividends_estimates SET %s WHERE dividends_estimate_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
... ... @@ -172,6 +176,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
nil,
dividendsEstimate.UpdatedAt,
dividendsEstimate.CooperationContractUndertakerId,
dividendsEstimate.CreditAccountId,
dividendsEstimate.Identify(),
); err != nil {
return dividendsEstimate, err
... ... @@ -266,6 +271,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: time.Now(),
CooperationContractUndertakerId: dividendsEstimate.CooperationContractUndertakerId,
CreditAccountId: dividendsEstimate.CreditAccountId,
})
}
if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil {
... ...