...
|
...
|
@@ -6,6 +6,7 @@ import ( |
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
...
|
...
|
@@ -99,7 +100,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
}
|
|
|
|
|
|
// 生成分红订单号
|
|
|
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
|
|
|
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber(map[string]interface{}{
|
|
|
"companyId": createDividendsOrderCommand.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -107,7 +110,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
// 校验分红订单编号是否唯一
|
|
|
numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
|
|
|
"companyId": createDividendsOrderCommand.CompanyId,
|
|
|
"orgId": createDividendsOrderCommand.OrgId,
|
|
|
"dividendsOrderNumber": dividendsOrderNumber,
|
|
|
})
|
|
|
if err != nil {
|
...
|
...
|
@@ -117,13 +119,70 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
return nil, application.ThrowError(application.TRANSACTION_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
|
|
|
}
|
|
|
|
|
|
// 查找合约
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract)
|
|
|
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"offsetLimit": false,
|
|
|
"companyId": createDividendsOrderCommand.CompanyId,
|
|
|
"orgId": createDividendsOrderCommand.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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 订单时间转换
|
|
|
orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
|
|
|
}
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 新增订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsOrderAmount float64
|
|
|
for _, orderGood := range createDividendsOrderCommand.OrderGoods {
|
|
|
// 计算订单产品金额
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)).Float64()
|
|
|
|
|
|
// 校验合约
|
|
|
ruleMatchedFlag := false
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
// 校验共创合约激励类型是否正确
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则")
|
|
|
}
|
|
|
// 校验产品关联合约的激励规则是否匹配订单时间
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
|
|
|
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
|
|
|
if (orderTime.After(incentivesRule.DividendsIncentivesStageStart) || orderTime.Equal(incentivesRule.DividendsIncentivesStageStart)) && (orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) || orderTime.Equal(incentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
ruleMatchedFlag = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !ruleMatchedFlag {
|
|
|
return nil, 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,
|
...
|
...
|
@@ -139,19 +198,11 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD |
|
|
UpdatedAt: time.Time{},
|
|
|
})
|
|
|
// 计算分红订单金额
|
|
|
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
|
|
|
}
|
|
|
|
|
|
// 订单时间转换
|
|
|
orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
|
|
|
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
|
|
|
}
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 新增分红订单
|
|
|
newDividendsOrder := &domain.DividendsOrder{
|
|
|
DividendsOrderId: 0,
|
|
|
DividendsOrderNumber: dividendsOrderNumber,
|
|
|
DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
|
|
|
DividendsOrderAmount: dividendsOrderAmount,
|
...
|
...
|
@@ -257,6 +308,33 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
// 合约仓储初始化
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 查找合约
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract)
|
|
|
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"offsetLimit": false,
|
|
|
"companyId": importDividendsOrderCommand.CompanyId,
|
|
|
"orgId": importDividendsOrderCommand.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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 分红订单DAO初始化
|
|
|
var dividendsOrderDao *dao.DividendsOrderDao
|
|
|
if value, err := factory.CreateDividendsOrderDao(map[string]interface{}{
|
...
|
...
|
@@ -297,7 +375,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
|
|
|
// 必填项校验
|
|
|
nullCellError := make([]interface{}, 0)
|
|
|
nullCellError := make([]*domain.FailInfo, 0)
|
|
|
|
|
|
// 数据行计数
|
|
|
rowCnt := 0
|
...
|
...
|
@@ -308,7 +386,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
for i, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData {
|
|
|
rowCnt++
|
|
|
nullCell := make([]interface{}, 0)
|
|
|
//var myRow []string
|
|
|
t := reflect.TypeOf(dividendsOrder)
|
|
|
v := reflect.ValueOf(dividendsOrder)
|
|
|
for k := 0; k < t.NumField(); k++ {
|
...
|
...
|
@@ -323,7 +400,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
if nullFlag {
|
|
|
myRow := &domain.FailInfo{
|
|
|
FailReason: "订单日期格式错误,请输入正确的订单日期",
|
|
|
FailReason: "必填项为空",
|
|
|
}
|
|
|
myRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[i]
|
|
|
nullCellError = append(nullCellError, myRow)
|
...
|
...
|
@@ -459,7 +536,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
// 订单日期时间格式转换
|
|
|
timeValue, err := time.ParseInLocation("2006/01/02", dividendsOrder.OrderTime, time.Local)
|
|
|
if err != nil {
|
|
|
//s := strconv.Itoa(i + 1)
|
|
|
tmpRow := &domain.FailInfo{
|
|
|
FailReason: "无效的订单日期",
|
|
|
}
|
...
|
...
|
@@ -469,7 +545,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
|
|
|
// 产品相关:产品名称,产品数量、产品价格、费用
|
|
|
quantity, err := strconv.ParseInt(dividendsOrder.OrderGoodQuantity, 10, 64)
|
|
|
quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -477,9 +553,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
expense, err := strconv.ParseFloat(dividendsOrder.Expense, 64)
|
|
|
if err != nil {
|
|
|
var expense float64
|
|
|
if dividendsOrder.Expense != "" {
|
|
|
if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
} else {
|
|
|
expense = expenseParse
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 初始化新建分红订单命令集
|
...
|
...
|
@@ -510,7 +590,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
} else { // 聚合同一笔订单产品
|
|
|
// 产品相关:产品名称,产品数量、产品价格、费用
|
|
|
quantity, err := strconv.ParseInt(dividendsOrder.OrderGoodQuantity, 10, 64)
|
|
|
quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -518,9 +598,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
expense, err := strconv.ParseFloat(dividendsOrder.Expense, 64)
|
|
|
if err != nil {
|
|
|
var expense float64
|
|
|
if dividendsOrder.Expense != "" {
|
|
|
if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
} else {
|
|
|
expense = expenseParse
|
|
|
}
|
|
|
}
|
|
|
|
|
|
dividendsOrderCommands[hashString].OrderGoods = append(dividendsOrderCommands[hashString].OrderGoods, command.OrderGoods{
|
...
|
...
|
@@ -586,7 +670,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
for _, errorData := range errorDataList {
|
|
|
if len(errorData.GoodLine) == 0 { // 订单错误
|
|
|
for _, line := range errorData.LineNumbers {
|
|
|
//s := strconv.Itoa(line + 1)
|
|
|
tmpRow := &domain.FailInfo{
|
|
|
FailReason: "数据校验错误:" + errorData.Error.Error(),
|
|
|
}
|
...
|
...
|
@@ -595,7 +678,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
|
|
|
for line := range errorData.GoodLine {
|
|
|
//s := strconv.Itoa(line + 1)
|
|
|
tmpRow := &domain.FailInfo{
|
|
|
FailReason: "订单产品信息错误:" + errorData.Error.Error(),
|
|
|
}
|
...
|
...
|
@@ -613,36 +695,35 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 批量导入创建分红订单
|
|
|
for _, dividendsOrder := range createDividendsOrderCommands {
|
|
|
// 生成分红订单号
|
|
|
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
|
|
|
// 创建分红订单领域模型
|
|
|
var creatDividendsOrder []*domain.DividendsOrder
|
|
|
|
|
|
// 统计当前分红订单数
|
|
|
count, err := dividendsOrderDao.CountDividendsOrder(map[string]interface{}{})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 校验分红订单编号是否唯一
|
|
|
numberAvailable, err3 := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
|
|
|
"companyId": importDividendsOrderCommand.CompanyId,
|
|
|
"orgId": importDividendsOrderCommand.OrgId,
|
|
|
"dividendsOrderNumber": dividendsOrderNumber,
|
|
|
})
|
|
|
if err3 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
|
|
|
}
|
|
|
if !numberAvailable {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
|
|
|
// 批量创建分红订单
|
|
|
for i, dividendsOrder := range createDividendsOrderCommands {
|
|
|
// 生成分红订单号
|
|
|
dividendsOrderNumber, err := dividendsOrder.GenerateSpecificDividendsOrderNumber(int64(count), time.Time{}, int64(i))
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 共创合约DAO初始化
|
|
|
var cooperationContractDao *dao.CooperationContractDao
|
|
|
if value, err := factory.CreateCooperationContractDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractDao = value
|
|
|
// 订单时间转换
|
|
|
orderTimeInt, err := strconv.ParseInt(dividendsOrder.OrderTime, 10, 64)
|
|
|
if err != nil {
|
|
|
row := &domain.ImportInfo{
|
|
|
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
|
|
|
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
|
|
|
GoodLine: map[int]interface{}{},
|
|
|
}
|
|
|
errorDataList = append(errorDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 新增订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
...
|
...
|
@@ -650,20 +731,43 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
orderGoodErrMap := make(map[int]interface{}, 0)
|
|
|
for i, orderGood := range dividendsOrder.OrderGoods {
|
|
|
// 校验共创合约是否合法
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
contractNumberExist, _ := cooperationContractDao.CheckContractNumberExist(map[string]interface{}{
|
|
|
"companyId": importDividendsOrderCommand.CompanyId,
|
|
|
"orgId": importDividendsOrderCommand.OrgId,
|
|
|
"cooperationContractNumber": orderGood.CooperationContractNumber,
|
|
|
})
|
|
|
contractNumberExist := false
|
|
|
for _, cooperationContract := range cooperationContracts {
|
|
|
if orderGood.CooperationContractNumber == cooperationContract.CooperationContractNumber {
|
|
|
contractNumberExist = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !contractNumberExist {
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err))
|
|
|
}
|
|
|
|
|
|
// 计算产品金额
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)).Float64()
|
|
|
|
|
|
// 校验共创合约激励类型是否正确
|
|
|
ruleMatchedFlag := false
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
|
|
|
}
|
|
|
// 校验产品关联合约的激励规则是否匹配订单时间
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
|
|
|
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
|
|
|
if (orderTime.After(incentivesRule.DividendsIncentivesStageStart) || orderTime.Equal(incentivesRule.DividendsIncentivesStageStart)) && (orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) || orderTime.Equal(incentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
ruleMatchedFlag = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !ruleMatchedFlag {
|
|
|
orderGoodErrMap[dividendsOrder.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,
|
...
|
...
|
@@ -679,7 +783,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
})
|
|
|
|
|
|
// 计算分红订单金额
|
|
|
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
|
|
|
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
|
|
|
}
|
|
|
if len(orderGoodErrMap) > 0 {
|
|
|
row := &domain.ImportInfo{
|
...
|
...
|
@@ -691,19 +795,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 订单时间转换
|
|
|
orderTimeInt, err := strconv.ParseInt(dividendsOrder.OrderTime, 10, 64)
|
|
|
if err != nil {
|
|
|
row := &domain.ImportInfo{
|
|
|
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
|
|
|
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
|
|
|
GoodLine: map[int]interface{}{},
|
|
|
}
|
|
|
errorDataList = append(errorDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 新增分红订单
|
|
|
newDividendsOrder := &domain.DividendsOrder{
|
|
|
DividendsOrderId: 0,
|
...
|
...
|
@@ -728,19 +819,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
Operator: operator,
|
|
|
}
|
|
|
|
|
|
if _, err2 := dividendsOrderRepository.Save(newDividendsOrder); err2 != nil {
|
|
|
row := &domain.ImportInfo{
|
|
|
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err)),
|
|
|
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
|
|
|
GoodLine: map[int]interface{}{},
|
|
|
}
|
|
|
errorDataList = append(errorDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
creatDividendsOrder = append(creatDividendsOrder, newDividendsOrder)
|
|
|
}
|
|
|
|
|
|
// 错误报告处理
|
|
|
if len(errorDataList) <= 0 { // 成功返回
|
|
|
if _, err2 := dividendsOrderRepository.SaveMany(creatDividendsOrder); err2 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
|
|
}
|
|
|
if err3 := transactionContext.CommitTransaction(); err3 != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
|
|
|
}
|
...
|
...
|
@@ -757,7 +843,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
for _, errorData := range errorDataList {
|
|
|
if len(errorData.GoodLine) == 0 { // 订单错误
|
|
|
for _, line := range errorData.LineNumbers {
|
|
|
//s := strconv.Itoa(line + 1)
|
|
|
tmpRow := &domain.FailInfo{
|
|
|
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
|
|
|
}
|
...
|
...
|
@@ -766,7 +851,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD |
|
|
}
|
|
|
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
|
|
|
for line := range errorData.GoodLine {
|
|
|
//s := strconv.Itoa(line + 1)
|
|
|
tmpRow := &domain.FailInfo{
|
|
|
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
|
|
|
}
|
...
|
...
|
@@ -888,15 +972,15 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsOrder == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDividendsOrderCommand.DividendsOrderId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeDividendsOrderCommand.DividendsOrderId, 10)))
|
|
|
}
|
|
|
if dividendsOrder, err := dividendsOrderRepository.Remove(dividendsOrder); err != nil {
|
|
|
if dividendsOrderRemoved, err := dividendsOrderRepository.Remove(dividendsOrder); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsOrder, nil
|
|
|
return dividendsOrderRemoved, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -924,7 +1008,10 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba |
|
|
dividendsOrderRepository = value
|
|
|
}
|
|
|
|
|
|
dividendsOrderIds, _ := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
|
|
|
dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误")
|
|
|
}
|
|
|
if count, dividendsOrders, err := dividendsOrderRepository.Find(map[string]interface{}{
|
|
|
"dividendsOrderIds": dividendsOrderIds,
|
|
|
}); err != nil {
|
...
|
...
|
@@ -1055,8 +1142,14 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD |
|
|
}
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 分红订单ID类型转换
|
|
|
dividendsOrderId, err := strconv.ParseInt(updateDividendsOrderCommand.DividendsOrderId, 10, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 获取分红订单
|
|
|
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": updateDividendsOrderCommand.DividendsOrderId})
|
|
|
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": dividendsOrderId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
|
|
|
}
|
...
|
...
|
@@ -1064,18 +1157,68 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId)))
|
|
|
}
|
|
|
|
|
|
// 合约仓储初始化
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 查找合约
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract)
|
|
|
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"offsetLimit": false,
|
|
|
"companyId": updateDividendsOrderCommand.CompanyId,
|
|
|
"orgId": updateDividendsOrderCommand.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 orderGoods []*domain.OrderGood
|
|
|
var dividendsOrderAmount float64
|
|
|
for _, orderGood := range updateDividendsOrderCommand.OrderGoods {
|
|
|
// 计算订单产品金额
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)).Float64()
|
|
|
|
|
|
// 产品ID类型转换
|
|
|
orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
|
|
|
if err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
}
|
|
|
|
|
|
ruleMatchedFlag := false
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
// 校验共创合约激励类型是否正确
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则")
|
|
|
}
|
|
|
// 校验产品关联合约的激励规则是否匹配订单时间
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
|
|
|
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
|
|
|
if (orderTime.After(incentivesRule.DividendsIncentivesStageStart) || orderTime.Equal(incentivesRule.DividendsIncentivesStageStart)) && (orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) || orderTime.Equal(incentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
ruleMatchedFlag = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !ruleMatchedFlag {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
OrderGoodId: orderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodAmount: orderGoodAmount,
|
|
|
OrderGoodName: orderGood.OrderGoodName,
|
|
|
OrderGoodPrice: orderGood.OrderGoodPrice,
|
|
|
OrderGoodQuantity: orderGood.OrderGoodQuantity,
|
...
|
...
|
@@ -1083,13 +1226,14 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD |
|
|
DividendsReturnedOrderNumber: "",
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderGoodExpense: orderGood.OrderGoodExpense,
|
|
|
OrderGoodDividendsStatus: 0,
|
|
|
OrgId: updateDividendsOrderCommand.OrgId,
|
|
|
CompanyId: updateDividendsOrderCommand.CompanyId,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Now(),
|
|
|
})
|
|
|
// 计算分红订单金额
|
|
|
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
|
|
|
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
|
|
|
}
|
|
|
|
|
|
if err := dividendsOrder.Update(tool_funs.SimpleStructToMap(updateDividendsOrderCommand)); err != nil {
|
...
|
...
|
|