business_bonus.go 4.0 KB
package domain

import "time"

// 业务分红信息 是否关闭【0;否】【1:是】
const (
	BUSINESS_BONUS_ENABLE  int8 = 0
	BUSINESS_BONUS_DISABLE int8 = 1
)

// 分红状态 1:待支付分红 2:已支付分红
const (
	//待支付
	BUSINESS_BONUS_WAIT_PAY int8 = 1
	//已支付
	BUSINESS_BONUS_HAS_PAY int8 = 2
)

func DescribeBusinessBonusStatus(i int8) string {
	m := map[int8]string{
		BUSINESS_BONUS_WAIT_PAY: "待支付分红",
		BUSINESS_BONUS_HAS_PAY:  "已支付分红",
	}
	if v, ok := m[i]; ok {
		return v
	}
	return ""
}

//分红状态
type BusinessBonusBonusStatus interface {
	//状态变更为空
	NullPayPartnerBonus(*BusinessBonus) error
	//状态变更为待支付
	WartPayPartnerBonus(*BusinessBonus) error
	//状态变更为已支付
	PayPartnerBonus(*BusinessBonus) error
}

// 业务分红信息
type BusinessBonus struct {
	// 唯一标识
	Id int64 `json:"id"`
	// 公司编号
	CompanyId int64 `json:"companyId"`
	// 合伙人信息Id
	PartnerInfoId int64 `json:"partnerInfoId"`
	// 应收分红
	Bonus float64 `json:"bonus"`
	// 未收分红
	BonusNot float64 `json:"bonusNot"`
	//已收分红
	BonusHas float64 `json:"bonusHas"`
	// 分红支出
	BonusExpense float64 `json:"bonusExpense"`
	// 是否关闭【0;否】【1:是】
	IsDisable int8 `json:"isDisable"`
	// 分红状态 1:待支付分红 2:已支付分红
	BonusStatus int8 `json:"bonusStatus"`
	// 创建时间
	CreateAt time.Time `json:"createAt"`
	// 更新时间
	UpdateAt time.Time `json:"updateAt"`
	// 删除时间
	DeleteAt time.Time `json:"deleteAt"`

	BusinessBonusPayStatus BusinessBonusBonusStatus
}

type BusinessBonusNullPay struct{}

var _ BusinessBonusBonusStatus = (*BusinessBonusNullPay)(nil)

type BusinessBonusWaitPay struct{}

var _ BusinessBonusBonusStatus = (*BusinessBonusWaitPay)(nil)

//OrderGoodBonusHasPay 货品分红已支付
type BusinessBonusHasPay struct{}

var _ BusinessBonusBonusStatus = (*BusinessBonusHasPay)(nil)

// -----默认空状态-----
//状态变更为空
func (pay BusinessBonusNullPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusStatus = 0
	return nil
}

//状态变更为待支付
func (pay BusinessBonusNullPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
	return nil
}

//状态变更为已支付
func (pay BusinessBonusNullPay) PayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = 0
	bonus.BonusHas = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
	return nil
}

// -----待支付状态-----
//状态变更为空
func (pay BusinessBonusWaitPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusStatus = 0
	return nil
}

//状态变更为待支付
func (pay BusinessBonusWaitPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
	return nil
}

//状态变更为已支付
func (pay BusinessBonusWaitPay) PayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = 0
	bonus.BonusHas = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
	return nil
}

// -----已经支付状态-----
//状态变更为空
func (pay BusinessBonusHasPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusStatus = 0
	return nil
}

//状态变更为待支付
func (pay BusinessBonusHasPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
	return nil
}

//状态变更为已支付
func (pay BusinessBonusHasPay) PayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = 0
	bonus.BonusHas = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
	return nil
}

type BusinessBonusFindOneQuery struct {
	Id        int64
	PartnerId int64
	CompanyId int64
}
type BusinessBonusFindQuery struct {
	Offset int
	Limit  int
}

type BusinessBonusRepository interface {
	Add(dm *BusinessBonus) error
	Edit(dm *BusinessBonus) error
	FindOne(BusinessBonusFindOneQuery) (*BusinessBonus, error)
	Find(BusinessBonusFindQuery) (int, []BusinessBonus, error)
}