...
|
...
|
@@ -295,6 +295,80 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend |
|
|
return dividendsOrder, nil
|
|
|
}
|
|
|
|
|
|
func (repository *DividendsOrderRepository) SaveMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
var dividendsOrderModels []*models.DividendsOrder
|
|
|
var orderGoodsModel []*models.OrderGood
|
|
|
for _, dividendsOrder := range dividendsOrders {
|
|
|
dividendsOrderModels = append(dividendsOrderModels, &models.DividendsOrder{
|
|
|
DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
DividendsOriginalOrderNum: dividendsOrder.DividendsOriginalOrderNum,
|
|
|
DividendsOrderAmount: dividendsOrder.DividendsOrderAmount,
|
|
|
OrderTime: dividendsOrder.OrderTime,
|
|
|
DividendTime: dividendsOrder.DividendTime,
|
|
|
DividendStatus: dividendsOrder.DividendStatus,
|
|
|
Region: dividendsOrder.Region,
|
|
|
CustomerName: dividendsOrder.CustomerName,
|
|
|
Org: dividendsOrder.Org,
|
|
|
Company: dividendsOrder.Company,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: dividendsOrder.DeletedAt,
|
|
|
UpdatedAt: dividendsOrder.UpdatedAt,
|
|
|
OperateTime: time.Now(),
|
|
|
Operator: dividendsOrder.Operator,
|
|
|
Remarks: dividendsOrder.Remarks,
|
|
|
})
|
|
|
for _, good := range dividendsOrder.Goods {
|
|
|
orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
|
|
|
OrderGoodAmount: good.OrderGoodAmount,
|
|
|
OrderGoodName: good.OrderGoodName,
|
|
|
OrderGoodPrice: good.OrderGoodPrice,
|
|
|
OrderGoodQuantity: good.OrderGoodQuantity,
|
|
|
DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
DividendsReturnedOrderNumber: "",
|
|
|
CooperationContractNumber: good.CooperationContractNumber,
|
|
|
CompanyId: good.CompanyId,
|
|
|
OrgId: good.OrgId,
|
|
|
OrderGoodExpense: good.OrderGoodExpense,
|
|
|
OrderGoodDividendsStatus: good.OrderGoodDividendsStatus,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(÷ndsOrderModels).Insert(); err != nil { // 新增分红订单
|
|
|
return nil, err
|
|
|
} else { // 新增分红订单产品
|
|
|
if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
var dividendsOrdersSaved []*domain.DividendsOrder
|
|
|
for _, dividendsOrderModel := range dividendsOrderModels {
|
|
|
//获取订单产品
|
|
|
var orderGoodModels []*models.OrderGood
|
|
|
orderGoodModelQuery := tx.Model(&orderGoodModels)
|
|
|
if err := orderGoodModelQuery.
|
|
|
Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
|
|
|
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
|
|
|
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
|
|
|
Select(); err != nil {
|
|
|
log.Logger.Error("分红订单关联的产品不存在", map[string]interface{}{
|
|
|
"dividendsOrderModel": dividendsOrderModel,
|
|
|
})
|
|
|
return nil, fmt.Errorf("分红订单关联的产品不存在")
|
|
|
}
|
|
|
// 聚合分红订单
|
|
|
if dividendsOrder, err := transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel, orderGoodModels); err != nil {
|
|
|
return dividendsOrders, err
|
|
|
} else {
|
|
|
dividendsOrders = append(dividendsOrders, dividendsOrder)
|
|
|
}
|
|
|
}
|
|
|
return dividendsOrdersSaved, nil
|
|
|
}
|
|
|
|
|
|
func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
var dividendsOrderModels []*models.DividendsOrder
|
...
|
...
|
@@ -379,7 +453,7 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte |
|
|
}
|
|
|
if err := query.First(); err != nil {
|
|
|
if err.Error() == "pg: no rows in result set" {
|
|
|
return nil, fmt.Errorf("没有此资源")
|
|
|
return nil, fmt.Errorf("分红订单不存在")
|
|
|
} else {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -394,7 +468,7 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte |
|
|
Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
|
|
|
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
|
|
|
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
return nil, fmt.Errorf("分红订单关联的产品不存在")
|
|
|
}
|
|
|
// 聚合分红订单
|
|
|
return transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel, orderGoodModels)
|
...
|
...
|
@@ -446,7 +520,10 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa |
|
|
Where("org_id = ?", dividendsOrderModel.Org.OrgId).
|
|
|
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
|
|
|
Select(); err != nil {
|
|
|
return 0, nil, err
|
|
|
log.Logger.Error("分红订单关联的产品不存在", map[string]interface{}{
|
|
|
"dividendsOrderModel": dividendsOrderModel,
|
|
|
})
|
|
|
return 0, nil, fmt.Errorf("分红订单关联的产品不存在")
|
|
|
}
|
|
|
// 聚合分红订单
|
|
|
if dividendsOrder, err := transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel, orderGoodModels); err != nil {
|
...
|
...
|
|