...
|
...
|
@@ -25,6 +25,7 @@ func NewOrderPaymentService(options map[string]interface{}) *OrderPaymentService |
|
|
func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *command.CreateOrderPaymentCommand) (data interface{}, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
)
|
|
|
if err = command.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -33,7 +34,12 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm |
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
if err == nil {
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
}
|
|
|
if err != nil {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}
|
|
|
}()
|
|
|
//检查订单是否存在
|
|
|
|
...
|
...
|
@@ -43,34 +49,48 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm |
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
dm := &domain.OrderPayment{
|
|
|
OrderId: command.OrderId,
|
|
|
PartnerId: 0,
|
|
|
PaymentAmount: 0,
|
|
|
BonusAmount: 0, //计算分红金额
|
|
|
BonusStatus: 0,
|
|
|
CreateAt: time.Now(),
|
|
|
PaymentSn: command.PaymentSn,
|
|
|
UpdateAt: time.Now(),
|
|
|
orderBase, e := OrderDao.GetOrderBaseInfo(command.OrderId)
|
|
|
if e != nil {
|
|
|
err = e
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//检查货款 已存在 / 未存在
|
|
|
if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentSn: command.PaymentSn}); e == nil {
|
|
|
if dm.BonusStatus == domain.BonusPaid {
|
|
|
return
|
|
|
for i := range command.DivdendPaymentItem {
|
|
|
paymentItem := command.DivdendPaymentItem[i]
|
|
|
dm := &domain.OrderPayment{
|
|
|
OrderId: command.OrderId,
|
|
|
PartnerId: 0,
|
|
|
PaymentAmount: 0,
|
|
|
BonusAmount: 0, //计算分红金额
|
|
|
BonusStatus: 0,
|
|
|
CreateAt: time.Now(),
|
|
|
PaymentSn: paymentItem.PaymentSn,
|
|
|
UpdateAt: time.Now(),
|
|
|
}
|
|
|
dm = findDm
|
|
|
}
|
|
|
|
|
|
dm.PaymentAmount = command.PaymentForGoods
|
|
|
dm.BonusStatus = command.StateOfPayment
|
|
|
dm.BonusAmount = 0
|
|
|
//检查货款 已存在 / 未存在
|
|
|
if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentSn: paymentItem.PaymentSn}); e == nil {
|
|
|
if findDm.BonusStatus == domain.BonusPaid {
|
|
|
continue
|
|
|
}
|
|
|
dm = findDm
|
|
|
}
|
|
|
|
|
|
if data, err = OrderPaymentRepository.Save(dm); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
dm.PartnerId = orderBase["PartnerId"].(int64)
|
|
|
bonousPercent := orderBase["PartnerBonusPercent"].(float64)
|
|
|
dm.BonusAmount = paymentItem.PaymentForGoods * (bonousPercent / 100.0)
|
|
|
dm.PaymentAmount = paymentItem.PaymentForGoods
|
|
|
dm.BonusStatus = paymentItem.StateOfPayment
|
|
|
|
|
|
if data, err = OrderPaymentRepository.Save(dm); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
|
|
|
if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
|