...
|
...
|
@@ -29,6 +29,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm |
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
OrderPaymentDao, _ = factory.CreateOrderPaymentDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
)
|
|
|
if err = command.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -57,43 +58,45 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm |
|
|
err = e
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var excludeIdList []int
|
|
|
excludeIdList = append(excludeIdList, 0)
|
|
|
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(),
|
|
|
}
|
|
|
|
|
|
if paymentItem.PaymentId > 0 && paymentItem.StateOfPayment == domain.BonusPaid {
|
|
|
continue
|
|
|
}
|
|
|
if paymentItem.PaymentId > 0 {
|
|
|
//检查货款 已存在 / 未存在
|
|
|
if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentSn: paymentItem.PaymentSn}); e == nil {
|
|
|
if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentId: paymentItem.PaymentId}); e == nil {
|
|
|
if findDm.BonusStatus == domain.BonusPaid {
|
|
|
continue
|
|
|
}
|
|
|
dm = findDm
|
|
|
}
|
|
|
|
|
|
}
|
|
|
dm.PartnerId = orderBase["PartnerId"].(int64)
|
|
|
bonousPercent := orderBase["PartnerBonusPercent"].(float64)
|
|
|
dm.BonusAmount = paymentItem.PaymentForGoods * (bonousPercent / 100.0)
|
|
|
bonusPercent := orderBase["PartnerBonusPercent"].(float64)
|
|
|
dm.BonusAmount = paymentItem.PaymentForGoods * (bonusPercent / 100.0)
|
|
|
dm.PaymentAmount = paymentItem.PaymentForGoods
|
|
|
dm.BonusStatus = paymentItem.StateOfPayment
|
|
|
|
|
|
dm.UpdateAt = time.Now()
|
|
|
if data, err = OrderPaymentRepository.Save(dm); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
excludeIdList = append(excludeIdList, int(dm.Id))
|
|
|
}
|
|
|
var bonusStatus int = 1
|
|
|
if len(command.DivdendPaymentItem) > 0 {
|
|
|
bonusStatus = command.DivdendPaymentItem[len(command.DivdendPaymentItem)-1].StateOfPayment
|
|
|
}
|
|
|
|
|
|
if err = OrderPaymentDao.Remove(command.OrderId, domain.BonusWaitPay, excludeIdList); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount, "bonusStatus": bonusStatus}); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
|