order_payment.go 1.8 KB
package domain

import "time"

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

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"`

	//扩展
	PartnerBonusPercent float64 `json:"-"`
}

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
}

type OrderPaymentFindOneQuery struct {
	Id        int64
	OrderId   int64
	PaymentId int
}
type OrderPaymentQuery struct {
	Offset int
	Limit  int

	OrderId int64
	//PartnerCategory []int       //合伙人类型
	//RegionInfo      *RegionInfo //区域
	//PartnerName     string      //合伙人姓名
}

type OrderPaymentRepository interface {
	Save(dm *OrderPayment) (*OrderPayment, error)
	FindOne(queryOptions OrderPaymentFindOneQuery) (*OrderPayment, error)
	Find(queryOptions OrderPaymentQuery) ([]*OrderPayment, error)
	CountAll(queryOptions OrderPaymentQuery) (int, error)
}