作者 陈志颖

fix:修复编辑分红退货单

... ... @@ -629,10 +629,13 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
// 获取分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": updateDividendsOrderCommand.DividendsOrderId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId)))
}
// 新增订单产品
// 获取订单产品
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
for _, orderGood := range updateDividendsOrderCommand.OrderGoods {
... ... @@ -660,9 +663,6 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId)))
}
if err := dividendsOrder.Update(tool_funs.SimpleStructToMap(updateDividendsOrderCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
... ...
... ... @@ -9,6 +9,8 @@ import (
)
type OrderGoods struct {
// 退货单产品ID
OrderGoodId string `json:"orderGoodId"`
// 订单产品金额
OrderGoodAmount float64 `cname:"订单产品金额" json:"orderGoodAmount"`
// 订单产品名称
... ...
... ... @@ -2,11 +2,9 @@ package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type UpdateDividendsReturnedOrderCommand struct {
... ... @@ -21,7 +19,7 @@ type UpdateDividendsReturnedOrderCommand struct {
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 退货日期
DividendsReturnedDate time.Time `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
// 退货区域
RegionName string `cname:"退货区域" json:"regionName,omitempty"`
// 订单产品列表
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"strconv"
"time"
)
... ... @@ -543,6 +544,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 分红退货单仓储初始化
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -551,6 +554,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
} else {
dividendsReturnedOrderRepository = value
}
// 退货单时间转换
dividendsReturnedDateInt, err := strconv.ParseInt(updateDividendsReturnedOrderCommand.DividendsReturnedDate, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
dividendsReturnedDate := utils.TransformTimestampToTime(dividendsReturnedDateInt)
// 获取分红退货单
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -558,16 +570,51 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
if dividendsReturnedOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsReturnedOrderCommand.DividendsReturnedOrderId)))
}
// 获取订单产品
var orderGoods []*domain.OrderGood
var dividendsReturnedOrderAmount float64
for _, orderGood := range updateDividendsReturnedOrderCommand.OrderGoods {
// 产品ID类型转换
orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: orderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodName: orderGood.OrderGoodName,
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
DividendsOrderNumber: "",
DividendsReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: orderGood.OrderGoodExpense,
OrgId: updateDividendsReturnedOrderCommand.OrgId,
CompanyId: updateDividendsReturnedOrderCommand.CompanyId,
CreatedAt: time.Time{},
UpdatedAt: time.Now(),
})
// 计算分红退货单金额
dividendsReturnedOrderAmount = dividendsReturnedOrderAmount + orderGood.OrderGoodAmount
}
if err := dividendsReturnedOrder.Update(tool_funs.SimpleStructToMap(updateDividendsReturnedOrderCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if dividendsReturnedOrder, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); err != nil {
dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate
dividendsReturnedOrder.DividendsReturnedOrderRefund = dividendsReturnedOrderAmount
dividendsReturnedOrder.Goods = orderGoods
// 保存分红退货单更新
if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); 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 dividendsReturnedOrder, nil
return dividendsReturnedOrderSaved, nil
}
}
... ...
... ... @@ -72,9 +72,6 @@ func (dividendsReturnedOrder *DividendsReturnedOrder) Update(data map[string]int
if dividendsReturnedCustomerName, ok := data["dividendsReturnedCustomerName"]; ok {
dividendsReturnedOrder.DividendsReturnedCustomerName = dividendsReturnedCustomerName.(string)
}
if dividendsReturnedDate, ok := data["dividendsReturnedDate"]; ok {
dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate.(time.Time)
}
if regionNumber, ok := data["regionNumber"]; ok {
dividendsReturnedOrder.Region.RegionNumber = regionNumber.(string)
}
... ...
... ... @@ -181,7 +181,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
// 获取分红退货订单产品
var orderGoodsFetched []*models.OrderGood
orderGoodsQuery := tx.Model(&orderGoodsFetched)
if err := orderGoodsQuery.Where("dividends_return_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Select(); err != nil {
if err := orderGoodsQuery.Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Select(); err != nil {
return nil, err
}
... ...