order_payment.go 1.5 KB
package domain

import "time"

const (
	BonusWaitPay = iota + 1 //等待支付分红
	BonusPaid               //已经支付分红
)

type OrderPaymentRepository interface {
	Save(dm *OrderPayment) (*OrderPayment, error)
	Remove(dm *OrderPayment) (*OrderPayment, error)
	FindOne(queryOptions map[string]interface{}) (*OrderPayment, error)
	Find(queryOptions map[string]interface{}) (int64, []*OrderPayment, error)
}

type OrderPayment struct {
	//编号
	Id int64 `json:"id"`
	//订单编号
	OrderId int64 `json:"orderId"`
	//合伙人编号
	PartnerId int64 `json:"partnerId"`
	//支付货款
	PaymentAmount float64 `json:"paymentAmount"`
	//分红金额
	BonusAmount float64 `json:"bonusAmount"`
	//分红状态  1.等待支付分红 2.已支付分红
	BonusStatus int `json:"bonusStatus"`
	//创建时间
	CreateAt time.Time `json:"createAt"`
	//更新时间
	UpdateAt time.Time `json:"updateAt"`
}

func (m *OrderPayment) Identify() interface{} {
	if m.Id == 0 {
		return nil
	}
	return m.Id
}

func (m *OrderPayment) Update(data map[string]interface{}) error {
	if m.BonusStatus != BonusWaitPay {
		return nil
	}
	if paymentAmount, ok := data["paymentAmount"]; ok && paymentAmount != 0 {
		m.PaymentAmount = paymentAmount.(float64)
	}
	if bonusAmount, ok := data["bonusAmount"]; ok && bonusAmount != 0 {
		m.BonusAmount = bonusAmount.(float64)
	}
	if bonusStatus, ok := data["bonusStatus"]; ok && bonusStatus != 0 {
		m.BonusStatus = bonusStatus.(int)
	}
	m.UpdateAt = time.Now()
	return nil
}