97 lines
5.0 KiB
Go
97 lines
5.0 KiB
Go
package models
|
||
|
||
import "time"
|
||
|
||
// =============================================================
|
||
// 平台端推广佣金模型(表结构见 docs/sql/create_platform_commission.sql)
|
||
// 业务约定:
|
||
// 1. 佣金由平台自有资金支出,与租户收款资金流解耦;
|
||
// 2. 佣金在「业务订单支付成功」事件上按启用中的规则生成,初始状态 payable;
|
||
// 3. 一笔支付单 + 同一推广方只生成一张佣金单(uk_pay_promoter,业务层再按 pay_no 查重)。
|
||
// =============================================================
|
||
|
||
// PlatformCommissionRule 佣金规则 yz_platform_commission_rule
|
||
type PlatformCommissionRule struct {
|
||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||
RuleName string `orm:"column(rule_name);size(128)" json:"rule_name"`
|
||
CalcType string `orm:"column(calc_type);size(20)" json:"calc_type"`
|
||
Value int64 `orm:"column(value);default(0)" json:"value"`
|
||
TierJSON *string `orm:"column(tier_json);type(text);null" json:"-"`
|
||
OrderType string `orm:"column(order_type);size(32)" json:"order_type"`
|
||
Status int8 `orm:"column(status);default(1)" json:"status"`
|
||
Remark string `orm:"column(remark);size(255)" json:"remark"`
|
||
CreateUserID string `orm:"column(create_user_id);size(64)" json:"create_user_id"`
|
||
CreateUserName string `orm:"column(create_user_name);size(128)" json:"create_user_name"`
|
||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
||
UpdateTime time.Time `orm:"column(update_time);auto_now;type(datetime)" json:"update_time"`
|
||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||
}
|
||
|
||
func (m *PlatformCommissionRule) TableName() string { return "yz_platform_commission_rule" }
|
||
|
||
// 计算方式
|
||
const (
|
||
CommissionCalcPercent = "percent" // 按比例:value = 百分比 × 100(5% 存 500)
|
||
CommissionCalcFixed = "fixed" // 固定金额:value = 分
|
||
CommissionCalcTiered = "tiered" // 阶梯:value 忽略,明细见 tier_json
|
||
)
|
||
|
||
// 适用订单类型
|
||
const (
|
||
CommissionOrderTypeAll = "all"
|
||
CommissionOrderTypePlatformUsage = "platform_usage"
|
||
CommissionOrderTypeModuleShop = "module_shop"
|
||
CommissionOrderTypeServiceFee = "service_fee"
|
||
)
|
||
|
||
// CommissionTier 阶梯档位(tier_json 数组元素)
|
||
type CommissionTier struct {
|
||
Min int64 `json:"min"` // 起始金额(分,含)
|
||
Max *int64 `json:"max"` // 结束金额(分,不含);null 表示不限
|
||
Rate int64 `json:"rate"` // 比例:百分比 × 100
|
||
}
|
||
|
||
// PlatformCommissionOrder 佣金单(台账) yz_platform_commission_order
|
||
type PlatformCommissionOrder struct {
|
||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||
CommissionNo string `orm:"column(commission_no);size(40)" json:"commission_no"`
|
||
PayNo string `orm:"column(pay_no);size(40)" json:"pay_no"`
|
||
OutTradeNo string `orm:"column(out_trade_no);size(64)" json:"out_trade_no"`
|
||
RuleID uint64 `orm:"column(rule_id);default(0)" json:"rule_id"`
|
||
RuleName string `orm:"column(rule_name);size(128)" json:"rule_name"`
|
||
CalcType string `orm:"column(calc_type);size(20)" json:"calc_type"`
|
||
PromoterID string `orm:"column(promoter_id);size(64)" json:"promoter_id"`
|
||
PromoterName string `orm:"column(promoter_name);size(128)" json:"promoter_name"`
|
||
PromoterType string `orm:"column(promoter_type);size(32)" json:"promoter_type"`
|
||
BaseAmount int64 `orm:"column(base_amount);default(0)" json:"base_amount"`
|
||
Amount int64 `orm:"column(amount);default(0)" json:"amount"`
|
||
Status string `orm:"column(status);size(20)" json:"status"`
|
||
PayMethod string `orm:"column(pay_method);size(20)" json:"pay_method"`
|
||
PayVoucher string `orm:"column(pay_voucher);size(255)" json:"pay_voucher"`
|
||
PaidAt *time.Time `orm:"column(paid_at);type(datetime);null" json:"paid_at"`
|
||
PaidUserID string `orm:"column(paid_user_id);size(64)" json:"paid_user_id"`
|
||
PaidUserName string `orm:"column(paid_user_name);size(128)" json:"paid_user_name"`
|
||
Remark string `orm:"column(remark);size(255)" json:"remark"`
|
||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
||
UpdateTime time.Time `orm:"column(update_time);auto_now;type(datetime)" json:"update_time"`
|
||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||
}
|
||
|
||
func (m *PlatformCommissionOrder) TableName() string { return "yz_platform_commission_order" }
|
||
|
||
// 佣金状态
|
||
const (
|
||
CommissionStatusPayable = "payable" // 应付
|
||
CommissionStatusSettled = "settled" // 已付
|
||
CommissionStatusTaxProcessing = "tax_processing" // 税务处理中
|
||
CommissionStatusCanceled = "canceled" // 已作废
|
||
)
|
||
|
||
// 发放方式
|
||
const (
|
||
CommissionPayBank = "bank" // 银行转账
|
||
CommissionPayBalance = "balance" // 余额抵扣
|
||
CommissionPayManual = "manual" // 人工发放
|
||
CommissionPayOffset = "offset" // 下期抵扣
|
||
)
|