作者 陈志颖

fix:修复订单产品编辑问题

... ... @@ -147,12 +147,14 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
// 预算明细
var creditAccounts []*domain.CreditAccount
var accountDetail []*domain.AccountDetail
var settlementAmount float64
for _, dividendsEstimate := range dividendsEstimates {
accountDetail = append(accountDetail, &domain.AccountDetail{
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsType: dividendsEstimate.DividendsType,
DividendsAmount: dividendsEstimate.DividendsAmount,
})
settlementAmount = settlementAmount + dividendsEstimate.DividendsAmount
}
// 生成账期结算单号
... ... @@ -167,7 +169,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
CreditAccountOrderNum: creditAccountNumber,
PaymentStatus: 1,
PaymentTime: time.Time{},
SettlementAmount: dividendsEstimates[0].DividendsAmount,
SettlementAmount: settlementAmount,
SettlementTime: time.Now(),
Participator: &domain.Participator{ // 共创参与
UserId: dividendsEstimates[0].DividendsUser.UserId,
... ... @@ -183,7 +185,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
Status: dividendsEstimates[0].DividendsUser.Status,
Company: dividendsEstimates[0].DividendsUser.Company,
},
AccountDetail: accountDetail,
AccountDetail: accountDetail, // 结算明细,多笔分红预算单
PaymentDocumentAttachment: nil,
Org: organization,
Company: company,
... ... @@ -318,8 +320,11 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 参数类型转换
creditAccountId, _ := strconv.ParseInt(payCreditAccountCommand.CreditAccountId, 10, 64)
// 账期结算仓储初始化
var creditAccountRepository domain.CreditAccountRepository
if value, err1 := factory.CreateCreditAccountRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -328,6 +333,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco
} else {
creditAccountRepository = value
}
// 获取待支付的账期结算单
creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": creditAccountId})
if err != nil {
... ... @@ -339,8 +345,11 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco
if err2 := creditAccount.Update(tool_funs.SimpleStructToMap(payCreditAccountCommand)); err2 != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err2.Error())
}
// 支付状态设置
// 支付更新设置
creditAccount.PaymentStatus = 2
creditAccount.PaymentTime = time.Now()
if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
} else {
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
... ... @@ -208,15 +209,20 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
OrgId: goodDomain.OrgId,
CompanyId: goodDomain.CompanyId,
OrderGoodDividendsStatus: goodDomain.OrderGoodDividendsStatus,
CreatedAt: time.Time{},
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Now(),
UpdatedAt: time.Time{},
})
}
// 添加分红订单产品
log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
"orderGoodsToAddModels": orderGoodsToAddModels,
})
if len(orderGoodsToAddModels) > 0 {
if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil {
return nil, err
}
}
// 待更新或者删除的ids
var orderGoodIdsToUpdateOrDelete []int64
... ... @@ -234,9 +240,14 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
}
}
}
log.Logger.Info("待更新的分红订单产品", map[string]interface{}{
"orderGoodModelsToUpdate": orderGoodModelsToUpdate,
})
if len(orderGoodModelsToUpdate) > 0 {
if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
}
// 待删除的分红订单产品id
orderGoodIdsToDelete := utils.Difference(orderGoodIdsFetched, orderGoodIdsToUpdateOrDelete)
... ... @@ -248,10 +259,15 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
}
}
}
if _, err := tx.Model(&orderGoodModelsToDelete).WherePK().Delete(); err != nil {
log.Logger.Info("待删除的订单产品", map[string]interface{}{
"orderGoodModelsToDelete": orderGoodModelsToDelete,
})
if len(orderGoodModelsToDelete) > 0 {
if _, err := tx.Model(&orderGoodModelsToDelete).Delete(); err != nil {
return nil, err
}
}
}
return dividendsOrder, nil
}
... ...
... ... @@ -224,9 +224,11 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
})
}
// 添加分红退货订单产品
if len(orderGoodsToAddModels) > 0 {
if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil {
return nil, err
}
}
// 待更新或者删除的ids
var orderGoodIdsToUpdateOrDelete []int64
... ... @@ -244,9 +246,11 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
}
}
}
if len(orderGoodModelsToUpdate) > 0 {
if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
}
// 待删除的分红退货订单产品id
orderGoodIdsToDelete := utils.Difference(orderGoodIdsFetched, orderGoodIdsToUpdateOrDelete)
... ... @@ -258,10 +262,12 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
}
}
}
if _, err := tx.Model(&orderGoodModelsToDelete).WherePK().Delete(); err != nil {
if len(orderGoodModelsToDelete) > 0 {
if _, err := tx.Model(&orderGoodModelsToDelete).Delete(); err != nil {
return nil, err
}
}
}
return dividendsReturnedOrder, nil
}
... ...