作者 陈志颖

fix:增加分红订单编号查询限制条件

... ... @@ -75,7 +75,11 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
for _, orderGood := range orderGoods {
dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -615,7 +619,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
for _, orderGood := range orderGoods {
dividendsEstimate := &domain.DividendsEstimate{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
}
... ... @@ -1098,7 +1106,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
for _, orderGood := range orderGoods {
dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -53,6 +53,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// 获取分红订单
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
... ...
... ... @@ -440,7 +440,11 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
DividendsUser: item.DividendsUser,
}
if item.DividendsType == 1 {
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": item.OrderOrReturnedOrderNum})
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": item.OrderOrReturnedOrderNum,
"companyId": item.Company.CompanyId,
"orgId": item.Org.OrgId,
})
if err != nil {
return nil, err
}
... ...
... ... @@ -178,7 +178,11 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
// 更新分红订单产品
var orderGoodsFetched []*models.OrderGood
orderGoodsQuery := tx.Model(&orderGoodsFetched)
if err := orderGoodsQuery.Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Select(); err != nil {
if err := orderGoodsQuery.
Where("company_id = ?", dividendsOrder.Company.CompanyId).
Where("org_id = ?", dividendsOrder.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).
Select(); err != nil {
return nil, err
}
... ... @@ -190,6 +194,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
// 待更新分红产品
var orderGoodsToUpdate []*domain.OrderGood
// 待添加分红产品
var orderGoodsToAdd []*domain.OrderGood
for _, good := range dividendsOrder.Goods {
... ... @@ -230,10 +235,10 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
})
}
// 添加分红订单产品
if len(orderGoodsToAddModels) > 0 {
log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
"orderGoodsToAddModels": orderGoodsToAddModels,
})
if len(orderGoodsToAddModels) > 0 {
if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil {
return nil, err
}
... ... @@ -491,6 +496,12 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("分红订单不存在")
... ...
... ... @@ -475,7 +475,8 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
if _, err := tx.Model(&orderGoodModels).
Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).
Delete(); err != nil {
return nil, err
}
}
... ... @@ -505,7 +506,8 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
if err := orderGoodModelQuery.
Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
Select(); err != nil {
return nil, fmt.Errorf("分红退货单关联的产品不存在")
}
// 聚合分红退货单
... ...
... ... @@ -15,14 +15,11 @@ import (
type MoneyIncentivesRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -202,8 +199,13 @@ func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.Transact
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &MoneyIncentivesRuleRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...