作者 yangfu

分红编辑修改

... ... @@ -28,3 +28,11 @@ func CreateOrderDao(options map[string]interface{}) (*dao.OrderDao, error) {
}
return dao.NewOrderDao(transactionContext)
}
func CreateOrderPaymentDao(options map[string]interface{}) (*dao.OrderPayment, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return dao.NewOrderPayment(transactionContext)
}
... ...
... ... @@ -14,6 +14,8 @@ type DivdendPyamentItem struct {
StateOfPayment int `json:"stateOfPayment,omitempty"`
//支付批次
PaymentSn int `json:"paymentSn,omitempty"`
//支付编号
PaymentId int `json:"id,omitempty"`
}
func (command CreateOrderPaymentCommand) ValidateCommand() error {
... ...
... ... @@ -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(),
OrderId: command.OrderId,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
//检查货款 已存在 / 未存在
if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentSn: paymentItem.PaymentSn}); e == nil {
if findDm.BonusStatus == domain.BonusPaid {
continue
if paymentItem.PaymentId > 0 && paymentItem.StateOfPayment == domain.BonusPaid {
continue
}
if paymentItem.PaymentId > 0 {
//检查货款 已存在 / 未存在
if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentId: paymentItem.PaymentId}); e == nil {
if findDm.BonusStatus == domain.BonusPaid {
continue
}
dm = findDm
}
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
}
... ...
... ... @@ -14,8 +14,6 @@ type OrderPayment struct {
OrderId int64 `json:"orderId"`
//合伙人编号
PartnerId int64 `json:"partnerId"`
//支付序号
PaymentSn int `json:"paymentSn"`
//支付货款
PaymentAmount float64 `json:"paymentAmount"`
//分红金额
... ... @@ -58,7 +56,7 @@ func (m *OrderPayment) Update(data map[string]interface{}) error {
type OrderPaymentFindOneQuery struct {
Id int64
OrderId int64
PaymentSn int
PaymentId int
}
type OrderPaymentQuery struct {
Offset int
... ...
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type OrderPayment struct {
transactionContext *transaction.TransactionContext
}
//删除数据
func (o *OrderPayment) Remove(orderId int64, status int, idList []int) error {
if len(idList) == 0 {
return nil
}
tx := o.transactionContext.PgTx
m := new(models.OrderPayment)
q := tx.Model(m).Where("order_id=?", orderId).
Where("bonus_status=?", status).
WhereIn("id not in(?)", idList)
_, err := q.Delete()
return err
}
func NewOrderPayment(transactionContext *transaction.TransactionContext) (*OrderPayment, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderPayment{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -10,8 +10,6 @@ type OrderPayment struct {
OrderId int64
//合伙人编号
PartnerId int64
//支付序号
PaymentSn int
//支付货款
PaymentAmount float64 `pg:",notnull,default:0"`
//分红金额
... ...
... ... @@ -24,7 +24,6 @@ func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain
BonusAmount: dm.BonusAmount,
BonusStatus: dm.BonusStatus,
CreateAt: dm.CreateAt,
PaymentSn: dm.PaymentSn,
UpdateAt: dm.UpdateAt,
}
if m.Id == 0 {
... ... @@ -61,8 +60,8 @@ func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPayme
if queryOptions.OrderId > 0 {
query.Where("order_payment.order_id = ?", queryOptions.OrderId)
}
if queryOptions.PaymentSn > 0 {
query.Where("order_payment.payment_sn = ?", queryOptions.PaymentSn)
if queryOptions.PaymentId > 0 {
query.Where("order_payment.id = ?", queryOptions.PaymentId)
}
if err := query.First(); err != nil {
return nil, err
... ... @@ -78,6 +77,7 @@ func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQ
var OrderPaymentModels []*models.OrderPayment
query := tx.Model(&OrderPaymentModels)
query.Where("order_payment.order_id = ?", queryOptions.OrderId)
query.Order("id ASC")
var (
err error
rsp = make([]*domain.OrderPayment, 0)
... ... @@ -121,7 +121,6 @@ func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *mode
PaymentAmount: dm.PaymentAmount,
BonusAmount: dm.BonusAmount,
BonusStatus: dm.BonusStatus,
PaymentSn: dm.PaymentSn,
CreateAt: dm.CreateAt,
UpdateAt: dm.UpdateAt,
}
... ...
... ... @@ -39,6 +39,7 @@ func (c *DividendsController) Edit() {
type DividendPaymentItem struct {
PaymentForGoods float64 `json:"paymentForGoods"`
StateOfPayment int `json:"stateOfPayment"`
Id int `json:"id"`
}
type Parameter struct {
Id string `json:"id"` //订单编号
... ... @@ -70,7 +71,7 @@ func (c *DividendsController) Edit() {
paymentItem.PaymentForGoods = item.PaymentForGoods
paymentItem.StateOfPayment = item.StateOfPayment
paymentItem.PaymentSn = i + 1
paymentItem.PaymentId = item.Id
if paymentItem.StateOfPayment == domain.BonusPaid {
cmd.TotalPaymentAmount += paymentItem.PaymentForGoods
}
... ... @@ -132,6 +133,7 @@ func (c *DividendsController) Detail() {
StateOfPayment int `json:"stateOfPayment"`
Dividend float64 `json:"dividend"`
DividendProportion float64 `json:"dividendProportion"`
Id int64 `json:"id"`
}
type Order struct {
OrderNumber string `json:"orderNumber"` //订单号
... ... @@ -171,6 +173,7 @@ func (c *DividendsController) Detail() {
StateOfPayment: item.BonusStatus,
Dividend: item.BonusAmount,
DividendProportion: order.PartnerBonusPercent,
Id: item.Id,
}
rsp.DividendPayment = append(rsp.DividendPayment, payment)
}
... ...