- 审批核心在实例进入提交失败的同一事务内写 submission_failed 决策投递与终态事件,消费入口单独放行 - 核销(4)、退款(7)、扫码注册(3)、资料资格(4)、线下充值(7)、佣金提现(5)新增“审批提交失败”终态并释放预占/冻结 - 三处恢复入口不再重放提交失败;退款关闭类终态按审批尝试定位退款单(M13) - 核销列表与详情批量返回审批提交状态;筛选、字段说明、状态名称、退款导出加入新状态 - 迁移 000239 放宽五张业务表状态约束与决策投递取值约束(测试库已执行 up/down/up) - OpenSpec Change fix-approval-submission-failure-terminal:18/26,测试部署后端到端验证与存量补数据待完成
91 lines
8.0 KiB
Go
91 lines
8.0 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/datatypes"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// CommissionWithdrawalRequest 佣金提现申请模型
|
||
// 代理佣金提现申请、审批流程、提现记录查询
|
||
type CommissionWithdrawalRequest struct {
|
||
gorm.Model
|
||
BaseModel `gorm:"embedded"`
|
||
WithdrawalNo string `gorm:"column:withdrawal_no;type:varchar(50);uniqueIndex:uk_commission_withdrawal_no,where:deleted_at IS NULL AND withdrawal_no IS NOT NULL;comment:提现单号(唯一,格式:W + 时间戳 + 随机数)" json:"withdrawal_no"`
|
||
AgentID uint `gorm:"column:agent_id;index;not null;comment:代理用户ID" json:"agent_id"`
|
||
ApplicantID uint `gorm:"column:applicant_id;index;comment:申请人账号ID" json:"applicant_id"`
|
||
ShopID uint `gorm:"column:shop_id;index;comment:店铺ID(冗余字段)" json:"shop_id"`
|
||
Amount int64 `gorm:"column:amount;type:bigint;not null;comment:提现金额(分为单位)" json:"amount"`
|
||
Fee int64 `gorm:"column:fee;type:bigint;default:0;comment:手续费(分为单位)" json:"fee"`
|
||
FeeRate int64 `gorm:"column:fee_rate;type:bigint;default:0;comment:手续费比率(基点,100=1%,快照)" json:"fee_rate"`
|
||
ActualAmount int64 `gorm:"column:actual_amount;type:bigint;comment:实际到账金额(分为单位)" json:"actual_amount"`
|
||
WithdrawalMethod string `gorm:"column:withdrawal_method;type:varchar(20);comment:提现方式 alipay-支付宝 wechat-微信 bank-银行卡" json:"withdrawal_method"`
|
||
PaymentType string `gorm:"column:payment_type;type:varchar(20);default:'manual';comment:放款类型(manual=人工打款)" json:"payment_type"`
|
||
AccountInfo datatypes.JSON `gorm:"column:account_info;type:jsonb;comment:收款账户信息(姓名、账号等)" json:"account_info"`
|
||
Status int `gorm:"column:status;type:int;default:1;comment:状态 1-待审核 2-已通过 3-已拒绝 4-已到账 5-审批提交失败" json:"status"`
|
||
ProcessorID uint `gorm:"column:processor_id;index;comment:处理人ID" json:"processor_id"`
|
||
ProcessedAt *time.Time `gorm:"column:processed_at;comment:处理时间" json:"processed_at"`
|
||
PaidAt *time.Time `gorm:"column:paid_at;comment:到账时间" json:"paid_at"`
|
||
RejectReason string `gorm:"column:reject_reason;type:text;comment:拒绝原因" json:"reject_reason"`
|
||
Remark string `gorm:"column:remark;type:text;comment:备注" json:"remark"`
|
||
// LatestAttemptID 与 LatestApprovalInstanceID 仅用于列表投影,不是历史事实来源。
|
||
LatestAttemptID uint `gorm:"column:latest_attempt_id;type:bigint;not null;default:0;comment:最新审批尝试记录ID" json:"latest_attempt_id"`
|
||
LatestApprovalInstanceID uint `gorm:"column:latest_approval_instance_id;type:bigint;not null;default:0;comment:最新通用审批实例ID" json:"latest_approval_instance_id"`
|
||
// ApprovalInstanceID 为空表示从未关联审批实例的存量申请,仍走既有本地人工终审。
|
||
ApprovalInstanceID *uint `gorm:"column:approval_instance_id;type:bigint;comment:首次接入企业微信审批的审批实例ID" json:"approval_instance_id,omitempty"`
|
||
AnomalyFlag int `gorm:"column:anomaly_flag;type:smallint;not null;default:0;comment:正交异常标记 0-无异常 1-通过后撤销" json:"anomaly_flag"`
|
||
AnomalyReason string `gorm:"column:anomaly_reason;type:varchar(500);not null;default:'';comment:异常原因" json:"anomaly_reason"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (CommissionWithdrawalRequest) TableName() string {
|
||
return "tb_commission_withdrawal_request"
|
||
}
|
||
|
||
// CommissionWithdrawalRequestAttempt 是提现申请每次提交或重提对应的不可变审批材料与冻结事实。
|
||
// 冻结与释放金额一律取本记录事实;released_at 是回溯可重放的幂等依据。
|
||
type CommissionWithdrawalRequestAttempt struct {
|
||
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||
RequestID uint `gorm:"column:request_id;type:bigint;not null;comment:所属提现申请ID" json:"request_id"`
|
||
AttemptNo int `gorm:"column:attempt_no;type:int;not null;comment:第几次提交,从 1 递增" json:"attempt_no"`
|
||
Amount int64 `gorm:"column:amount;type:bigint;not null;comment:本次冻结提现金额(分)" json:"amount"`
|
||
Fee int64 `gorm:"column:fee;type:bigint;not null;default:0;comment:本次手续费(分)" json:"fee"`
|
||
FeeRate int64 `gorm:"column:fee_rate;type:bigint;not null;default:0;comment:本次手续费率(基点)" json:"fee_rate"`
|
||
ActualAmount int64 `gorm:"column:actual_amount;type:bigint;not null;default:0;comment:本次实际到账金额(分)" json:"actual_amount"`
|
||
WithdrawalMethod string `gorm:"column:withdrawal_method;type:varchar(20);not null;comment:本次收款方式快照" json:"withdrawal_method"`
|
||
AccountInfo datatypes.JSON `gorm:"column:account_info;type:jsonb;not null;comment:本次收款账户信息快照" json:"account_info"`
|
||
InvoiceKeys datatypes.JSON `gorm:"column:invoice_keys;type:jsonb;not null;default:'[]';comment:本次申请级发票对象存储Key列表" json:"invoice_keys"`
|
||
SubmittedByAccountID uint `gorm:"column:submitted_by_account_id;type:bigint;not null;comment:本次实际提交账号ID" json:"submitted_by_account_id"`
|
||
ApprovalInstanceID *uint `gorm:"column:approval_instance_id;type:bigint;comment:本次尝试关联的通用审批实例ID" json:"approval_instance_id,omitempty"`
|
||
// 资料资格校验留痕:本次提交依据的有效资格版本与当次校验结果,随尝试冻结,历史尝试不被改写。
|
||
QualificationVersionID uint `gorm:"column:qualification_version_id;type:bigint;not null;default:0;comment:本次依据的有效提现资料资格版本ID,0-资格不存在或历史尝试" json:"qualification_version_id"`
|
||
QualificationCheckedAt *time.Time `gorm:"column:qualification_checked_at;comment:本次资料资格校验时间" json:"qualification_checked_at,omitempty"`
|
||
QualificationPassed int `gorm:"column:qualification_passed;type:smallint;not null;default:0;comment:本次资料资格校验是否通过 0-未通过 1-通过" json:"qualification_passed"`
|
||
QualificationFailureReason string `gorm:"column:qualification_failure_reason;type:varchar(64);not null;default:'';comment:未通过时的稳定原因编码" json:"qualification_failure_reason"`
|
||
ReleasedAt *time.Time `gorm:"column:released_at;comment:本次冻结释放时间,空表示未结算" json:"released_at,omitempty"`
|
||
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz;not null;autoCreateTime" json:"created_at"`
|
||
}
|
||
|
||
// TableName 指定提现审批尝试记录表名。
|
||
func (CommissionWithdrawalRequestAttempt) TableName() string {
|
||
return "tb_commission_withdrawal_request_attempt"
|
||
}
|
||
|
||
// CommissionWithdrawalSetting 佣金提现设置模型
|
||
// 提现参数配置(最低金额、手续费率、到账时间等)
|
||
type CommissionWithdrawalSetting struct {
|
||
gorm.Model
|
||
BaseModel `gorm:"embedded"`
|
||
MinWithdrawalAmount int64 `gorm:"column:min_withdrawal_amount;type:bigint;comment:最低提现金额(分为单位)" json:"min_withdrawal_amount"`
|
||
FeeRate int64 `gorm:"column:fee_rate;type:bigint;comment:手续费率(万分比,如100表示1%)" json:"fee_rate"`
|
||
ArrivalDays int `gorm:"column:arrival_days;type:int;comment:到账天数" json:"arrival_days"`
|
||
DailyWithdrawalLimit int `gorm:"column:daily_withdrawal_limit;type:int;default:3;comment:每日提现次数限制" json:"daily_withdrawal_limit"`
|
||
IsActive bool `gorm:"column:is_active;type:boolean;default:true;comment:是否生效(最新一条)" json:"is_active"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (CommissionWithdrawalSetting) TableName() string {
|
||
return "tb_commission_withdrawal_setting"
|
||
}
|