审查视图

pkg/domain/business_bonus.go 4.8 KB
唐旭辉 authored
1 2 3 4
package domain

import "time"
唐旭辉 authored
5
// 业务分红信息 是否有效【0;无效】【1:有效】
唐旭辉 authored
6
const (
唐旭辉 authored
7 8
	BUSINESS_BONUS_ENABLE  int8 = 1
	BUSINESS_BONUS_DISABLE int8 = 0
唐旭辉 authored
9 10 11 12
)

// 分红状态 1:待支付分红 2:已支付分红
const (
唐旭辉 authored
13
	//空状态
14
	BUSINESS_BONUS_NULL_PAY int8 = 0
唐旭辉 authored
15
	//待支付
唐旭辉 authored
16
	BUSINESS_BONUS_WAIT_PAY int8 = 1
唐旭辉 authored
17
	//已支付
唐旭辉 authored
18
	BUSINESS_BONUS_HAS_PAY int8 = 2
唐旭辉 authored
19 20
)
唐旭辉 authored
21 22
func DescribeBusinessBonusStatus(i int8) string {
	m := map[int8]string{
唐旭辉 authored
23
		BUSINESS_BONUS_WAIT_PAY: "等待支付分红",
唐旭辉 authored
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
		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
}
唐旭辉 authored
42 43 44 45 46 47 48 49 50 51 52 53
// 业务分红信息
type BusinessBonus struct {
	// 唯一标识
	Id int64 `json:"id"`
	// 公司编号
	CompanyId int64 `json:"companyId"`
	// 合伙人信息Id
	PartnerInfoId int64 `json:"partnerInfoId"`
	// 应收分红
	Bonus float64 `json:"bonus"`
	// 未收分红
	BonusNot float64 `json:"bonusNot"`
唐旭辉 authored
54 55
	//已收分红
	BonusHas float64 `json:"bonusHas"`
唐旭辉 authored
56 57 58 59 60 61 62 63 64 65 66 67
	// 分红支出
	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"`
唐旭辉 authored
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

	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
唐旭辉 authored
89 90 91 92
	bonus.BonusExpense = 0
	bonus.BonusHas = 0
	bonus.BonusNot = 0
	bonus.Bonus = 0
唐旭辉 authored
93
	bonus.BusinessBonusPayStatus = &BusinessBonusNullPay{}
唐旭辉 authored
94 95 96 97 98 99 100
	return nil
}

//状态变更为待支付
func (pay BusinessBonusNullPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
唐旭辉 authored
101
	bonus.BonusHas = 0
唐旭辉 authored
102
	bonus.BusinessBonusPayStatus = &BusinessBonusWaitPay{}
唐旭辉 authored
103 104 105 106 107 108 109 110
	return nil
}

//状态变更为已支付
func (pay BusinessBonusNullPay) PayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = 0
	bonus.BonusHas = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
唐旭辉 authored
111
	bonus.BusinessBonusPayStatus = &BusinessBonusHasPay{}
唐旭辉 authored
112 113 114 115 116 117 118
	return nil
}

// -----待支付状态-----
//状态变更为空
func (pay BusinessBonusWaitPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusStatus = 0
唐旭辉 authored
119 120 121 122
	bonus.BonusExpense = 0
	bonus.BonusHas = 0
	bonus.BonusNot = 0
	bonus.Bonus = 0
唐旭辉 authored
123
	bonus.BusinessBonusPayStatus = &BusinessBonusNullPay{}
唐旭辉 authored
124 125 126 127 128 129 130
	return nil
}

//状态变更为待支付
func (pay BusinessBonusWaitPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
唐旭辉 authored
131
	bonus.BonusHas = 0
唐旭辉 authored
132
	bonus.BusinessBonusPayStatus = &BusinessBonusWaitPay{}
唐旭辉 authored
133 134 135 136 137 138 139 140
	return nil
}

//状态变更为已支付
func (pay BusinessBonusWaitPay) PayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = 0
	bonus.BonusHas = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
唐旭辉 authored
141
	bonus.BusinessBonusPayStatus = &BusinessBonusHasPay{}
唐旭辉 authored
142 143 144 145 146 147 148
	return nil
}

// -----已经支付状态-----
//状态变更为空
func (pay BusinessBonusHasPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusStatus = 0
唐旭辉 authored
149 150 151 152
	bonus.BonusExpense = 0
	bonus.BonusHas = 0
	bonus.BonusNot = 0
	bonus.Bonus = 0
唐旭辉 authored
153
	bonus.BusinessBonusPayStatus = &BusinessBonusNullPay{}
唐旭辉 authored
154 155 156 157 158 159 160
	return nil
}

//状态变更为待支付
func (pay BusinessBonusHasPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
唐旭辉 authored
161
	bonus.BonusHas = 0
唐旭辉 authored
162
	bonus.BusinessBonusPayStatus = &BusinessBonusWaitPay{}
唐旭辉 authored
163 164 165 166 167 168 169 170
	return nil
}

//状态变更为已支付
func (pay BusinessBonusHasPay) PayPartnerBonus(bonus *BusinessBonus) error {
	bonus.BonusNot = 0
	bonus.BonusHas = bonus.Bonus
	bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
唐旭辉 authored
171
	bonus.BusinessBonusPayStatus = &BusinessBonusHasPay{}
唐旭辉 authored
172
	return nil
唐旭辉 authored
173 174 175 176 177
}

type BusinessBonusFindOneQuery struct {
	Id        int64
	PartnerId int64
唐旭辉 authored
178
	CompanyId int64
唐旭辉 authored
179 180 181 182 183 184 185 186 187 188 189 190
}
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)
}