作者 陈志颖

fix:订单产品更新修复

... ... @@ -8,6 +8,8 @@ import (
)
type OrderGoods struct {
// 订单产品ID
OrderGoodId string `json:"orderGoodId"`
// 订单产品金额
OrderGoodAmount float64 `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 UpdateDividendsOrderCommand struct {
... ... @@ -19,7 +17,9 @@ type UpdateDividendsOrderCommand struct {
// 分红订单原单号
DividendsOriginalOrderNum string `cname:"分红订单原单号" json:"dividendsOriginalOrderNum" valid:"Required"`
// 订单产生时间
OrderTime time.Time `cname:"订单产生时间" json:"orderTime" valid:"Required"`
OrderTime string `cname:"订单产生时间" json:"orderTime" valid:"Required"`
// 订单产品列表
OrderGoods []*OrderGoods `cname:"订单产品列表" json:"orderGoods,omitempty"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 业务员uid
... ... @@ -37,7 +37,15 @@ type UpdateDividendsOrderCommand struct {
}
func (updateDividendsOrderCommand *UpdateDividendsOrderCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
if len(updateDividendsOrderCommand.OrderGoods) <= 0 {
validation.Error("激励规则不能为空")
} else {
for i, _ := range updateDividendsOrderCommand.OrderGoods {
if updateDividendsOrderCommand.OrderGoods[i].OrderGoodId == "" {
updateDividendsOrderCommand.OrderGoods[i].OrderGoodId = "0"
}
}
}
}
func (updateDividendsOrderCommand *UpdateDividendsOrderCommand) ValidateCommand() error {
... ...
... ... @@ -608,6 +608,8 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 分红订单仓储初始化
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -616,23 +618,67 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
} else {
dividendsOrderRepository = value
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(updateDividendsOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 获取分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": updateDividendsOrderCommand.DividendsOrderId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
for _, orderGood := range updateDividendsOrderCommand.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: dividendsOrder.DividendsOrderNumber,
DividendsReturnedOrderNumber: "",
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: orderGood.OrderGoodExpense,
OrgId: updateDividendsOrderCommand.OrgId,
CompanyId: updateDividendsOrderCommand.CompanyId,
CreatedAt: time.Time{},
UpdatedAt: time.Now(),
})
// 计算分红订单金额
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())
}
if dividendsOrder, err := dividendsOrderRepository.Save(dividendsOrder); err != nil {
dividendsOrder.OrderTime = orderTime
dividendsOrder.DividendsOrderAmount = dividendsOrderAmount
dividendsOrder.Goods = orderGoods
// 保存订单更新
if dividendsOrderSaved, err := dividendsOrderRepository.Save(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 dividendsOrderSaved, nil
}
}
... ...
package domain
import "time"
import (
"time"
)
const (
TO_BE_DIVIDEND = iota + 1
... ... @@ -74,9 +76,6 @@ func (dividendsOrder *DividendsOrder) Update(data map[string]interface{}) error
if dividendsOrderAmount, ok := data["dividendsOrderAmount"]; ok {
dividendsOrder.DividendsOrderAmount = dividendsOrderAmount.(float64)
}
if orderTime, ok := data["orderTime"]; ok {
dividendsOrder.OrderTime = orderTime.(time.Time)
}
if dividendTime, ok := data["dividendTime"]; ok {
dividendsOrder.DividendTime = dividendTime.(time.Time)
}
... ...
... ... @@ -169,7 +169,7 @@ func (repository *CooperationProjectRepository) UpdateMany(cooperationProjects [
CooperationProjectPublishTime: cooperationProject.CooperationProjectPublishTime,
CooperationProjectPublisher: cooperationProject.CooperationProjectPublisher,
CooperationProjectSponsor: cooperationProject.CooperationProjectSponsor,
CooperationModeNumber: cooperationProject.CooperationProjectNumber,
CooperationModeNumber: cooperationProject.CooperationMode.CooperationModeNumber,
Department: cooperationProject.Department,
CooperationProjectUndertakerTypes: cooperationProject.CooperationProjectUndertakerTypes,
Attachment: cooperationProject.Attachment,
... ...