...
|
...
|
@@ -99,7 +99,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide |
|
|
}
|
|
|
|
|
|
// 生成分红订单号
|
|
|
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
|
|
|
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
|
|
|
"companyId": createDividendsReturnedOrderCommand.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -121,7 +123,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide |
|
|
// 校验分红退货单编号是否唯一
|
|
|
numberAvailable, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
|
|
|
"companyId": createDividendsReturnedOrderCommand.CompanyId,
|
|
|
"orgId": createDividendsReturnedOrderCommand.OrgId,
|
|
|
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
|
|
|
})
|
|
|
if err != nil {
|
...
|
...
|
@@ -131,13 +132,46 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在")
|
|
|
}
|
|
|
|
|
|
// 合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
|
|
|
// 查找合约
|
|
|
var cooperationContractsMap map[string]*domain.CooperationContract
|
|
|
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"companyId": createDividendsReturnedOrderCommand.CompanyId,
|
|
|
"orgId": createDividendsReturnedOrderCommand.OrgId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, cooperationContract := range cooperationContracts {
|
|
|
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 退货金额
|
|
|
var dividendsReturnedOrderRefund float64
|
|
|
|
|
|
// 获取分红退货单产品
|
|
|
// 新增分红退货单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods {
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
|
|
|
// 退货产品金额计算
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
|
|
|
|
|
|
// 校验合约激励类型是否正确
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
|
|
|
}
|
|
|
}
|
|
|
orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
OrderGoodId: 0,
|
|
|
OrderGoodAmount: orderGoodAmount,
|
...
|
...
|
@@ -321,6 +355,33 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide |
|
|
dividendsReturnedOrderRepository = value
|
|
|
}
|
|
|
|
|
|
// 合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
|
|
|
// 查找合约
|
|
|
var cooperationContractsMap map[string]*domain.CooperationContract
|
|
|
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"offsetLimit": false,
|
|
|
"companyId": importDividendsReturnedOrderCommand.CompanyId,
|
|
|
"orgId": importDividendsReturnedOrderCommand.OrgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if countContracts > 0 {
|
|
|
for _, cooperationContract := range cooperationContracts {
|
|
|
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回信息表头定义
|
|
|
var tableHeader = map[string]interface{}{
|
|
|
"failReason": "错误详情",
|
...
|
...
|
@@ -664,7 +725,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide |
|
|
// 批量导入创建退货单
|
|
|
for _, dividendsReturnedOrder := range createDividendsReturnedOrderCommands {
|
|
|
// 生成退货订单号
|
|
|
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
|
|
|
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
|
|
|
"companyId": importDividendsReturnedOrderCommand.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -672,7 +735,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide |
|
|
// 校验退货订单编号是否唯一
|
|
|
numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
|
|
|
"companyId": importDividendsReturnedOrderCommand.CompanyId,
|
|
|
"orgId": importDividendsReturnedOrderCommand.OrgId,
|
|
|
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
|
|
|
})
|
|
|
if err3 != nil {
|
...
|
...
|
@@ -685,10 +747,32 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide |
|
|
// 新增订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsReturnedOrderAmount float64
|
|
|
for _, orderGood := range dividendsReturnedOrder.OrderGoods {
|
|
|
orderGoodErrMap := make(map[int]interface{}, 0)
|
|
|
for i, orderGood := range dividendsReturnedOrder.OrderGoods {
|
|
|
// 校验共创合约是否合法
|
|
|
contractNumberExist := false
|
|
|
for _, cooperationContract := range cooperationContracts {
|
|
|
if orderGood.CooperationContractNumber == cooperationContract.CooperationContractNumber {
|
|
|
contractNumberExist = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !contractNumberExist {
|
|
|
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err))
|
|
|
}
|
|
|
|
|
|
// 计算产品金额
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
|
|
|
|
|
|
// 校验合约激励类型是否正确
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
|
|
|
}
|
|
|
}
|
|
|
orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
OrderGoodId: 0,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodAmount: orderGoodAmount,
|
|
|
OrderGoodName: orderGood.OrderGoodName,
|
|
|
OrderGoodPrice: orderGood.OrderGoodPrice,
|
|
|
OrderGoodQuantity: orderGood.OrderGoodQuantity,
|
...
|
...
|
|