187 lines
7.1 KiB
Go
187 lines
7.1 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// 退款状态常量
|
|
const (
|
|
RefundStatusPending = 1 // 待审核
|
|
RefundStatusApproved = 2 // 审核通过
|
|
RefundStatusRejected = 3 // 审核拒绝
|
|
RefundStatusProcessing = 4 // 退款中
|
|
RefundStatusSuccess = 5 // 退款成功
|
|
RefundStatusFailed = 6 // 退款失败
|
|
)
|
|
|
|
// 退款类型常量
|
|
const (
|
|
RefundTypeRefundOnly = 1 // 仅退款
|
|
RefundTypeReturn = 2 // 退货退款
|
|
)
|
|
|
|
// 微信退款状态常量
|
|
const (
|
|
WechatRefundStatusSuccess = "SUCCESS" // 退款成功
|
|
WechatRefundStatusClosed = "CLOSED" // 退款关闭
|
|
WechatRefundStatusProcessing = "PROCESSING" // 退款处理中
|
|
)
|
|
|
|
// Refund 退款记录
|
|
type Refund struct {
|
|
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
RefundNo string `json:"refund_no" gorm:"size:64;not null;uniqueIndex"`
|
|
OrderID uint `json:"order_id" gorm:"not null;index"`
|
|
OrderNo string `json:"order_no" gorm:"size:32;not null;index"`
|
|
UserID uint `json:"user_id" gorm:"not null;index"`
|
|
RefundType int `json:"refund_type" gorm:"not null;default:1"`
|
|
RefundReason string `json:"refund_reason" gorm:"size:255;not null"`
|
|
RefundDescription string `json:"refund_description" gorm:"type:text"`
|
|
RefundAmount float64 `json:"refund_amount" gorm:"type:decimal(10,2);not null"`
|
|
RefundFee float64 `json:"refund_fee" gorm:"type:decimal(10,2);default:0.00"`
|
|
ActualRefundAmount float64 `json:"actual_refund_amount" gorm:"type:decimal(10,2);not null"`
|
|
Status int `json:"status" gorm:"not null;default:1;index"`
|
|
ApplyTime time.Time `json:"apply_time" gorm:"not null;default:CURRENT_TIMESTAMP;index"`
|
|
AuditTime *time.Time `json:"audit_time"`
|
|
RefundTime *time.Time `json:"refund_time"`
|
|
AdminID *uint `json:"admin_id"`
|
|
AdminRemark string `json:"admin_remark" gorm:"type:text"`
|
|
RejectReason string `json:"reject_reason" gorm:"size:255"`
|
|
|
|
// 微信退款相关字段
|
|
WechatRefundID string `json:"wechat_refund_id" gorm:"size:64;index"`
|
|
WechatOutRefundNo string `json:"wechat_out_refund_no" gorm:"size:64;uniqueIndex"`
|
|
WechatTransactionID string `json:"wechat_transaction_id" gorm:"size:64;index"`
|
|
WechatRefundStatus string `json:"wechat_refund_status" gorm:"size:32"`
|
|
WechatRefundRecvAccount string `json:"wechat_refund_recv_account" gorm:"size:64"`
|
|
WechatSuccessTime *time.Time `json:"wechat_success_time"`
|
|
WechatUserReceivedAccount string `json:"wechat_user_received_account" gorm:"size:64"`
|
|
WechatRefundAccount string `json:"wechat_refund_account" gorm:"size:32"`
|
|
|
|
// 退货相关字段
|
|
ReturnLogisticsCompany string `json:"return_logistics_company" gorm:"size:50"`
|
|
ReturnLogisticsNo string `json:"return_logistics_no" gorm:"size:100"`
|
|
ReturnAddress string `json:"return_address" gorm:"size:255"`
|
|
GoodsReceivedTime *time.Time `json:"goods_received_time"`
|
|
|
|
// 图片证据
|
|
EvidenceImages JSONSlice `json:"evidence_images" gorm:"type:json"`
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联数据
|
|
Order Order `json:"order,omitempty" gorm:"foreignKey:OrderID"`
|
|
User User `json:"user,omitempty" gorm:"foreignKey:UserID"`
|
|
Admin User `json:"admin,omitempty" gorm:"foreignKey:AdminID"`
|
|
RefundItems []RefundItem `json:"refund_items,omitempty" gorm:"foreignKey:RefundID"`
|
|
RefundLogs []RefundLog `json:"refund_logs,omitempty" gorm:"foreignKey:RefundID"`
|
|
}
|
|
|
|
// RefundItem 退款项目
|
|
type RefundItem struct {
|
|
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
RefundID uint `json:"refund_id" gorm:"not null;index"`
|
|
OrderItemID uint `json:"order_item_id" gorm:"not null;index"`
|
|
ProductID uint `json:"product_id" gorm:"not null;index"`
|
|
SKUID *uint `json:"sku_id" gorm:"column:sku_id"`
|
|
ProductName string `json:"product_name" gorm:"size:100;not null"`
|
|
ProductImage string `json:"product_image" gorm:"size:255"`
|
|
SpecInfo JSONMap `json:"spec_info" gorm:"type:json"`
|
|
Quantity int `json:"quantity" gorm:"not null"`
|
|
UnitPrice float64 `json:"unit_price" gorm:"type:decimal(10,2);not null"`
|
|
TotalPrice float64 `json:"total_price" gorm:"type:decimal(10,2);not null"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联数据
|
|
Refund Refund `json:"refund,omitempty" gorm:"foreignKey:RefundID"`
|
|
OrderItem OrderItem `json:"order_item,omitempty" gorm:"foreignKey:OrderItemID"`
|
|
Product Product `json:"product,omitempty" gorm:"foreignKey:ProductID"`
|
|
SKU ProductSKU `json:"sku,omitempty" gorm:"foreignKey:SKUID"`
|
|
}
|
|
|
|
// RefundLog 退款操作日志
|
|
type RefundLog struct {
|
|
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
RefundID uint `json:"refund_id" gorm:"not null;index"`
|
|
Action string `json:"action" gorm:"size:50;not null;index"`
|
|
StatusFrom *int `json:"status_from"`
|
|
StatusTo *int `json:"status_to"`
|
|
OperatorType string `json:"operator_type" gorm:"size:20;not null"`
|
|
OperatorID *uint `json:"operator_id"`
|
|
Remark string `json:"remark" gorm:"type:text"`
|
|
ExtraData JSONMap `json:"extra_data" gorm:"type:json"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"index"`
|
|
|
|
// 关联数据
|
|
Refund Refund `json:"refund,omitempty" gorm:"foreignKey:RefundID"`
|
|
Operator User `json:"operator,omitempty" gorm:"foreignKey:OperatorID"`
|
|
}
|
|
|
|
// TableName 设置表名
|
|
func (Refund) TableName() string {
|
|
return "ai_refunds"
|
|
}
|
|
|
|
// TableName 设置表名
|
|
func (RefundItem) TableName() string {
|
|
return "ai_refund_items"
|
|
}
|
|
|
|
// TableName 设置表名
|
|
func (RefundLog) TableName() string {
|
|
return "ai_refund_logs"
|
|
}
|
|
|
|
// GetStatusText 获取退款状态文本
|
|
func (r *Refund) GetStatusText() string {
|
|
switch r.Status {
|
|
case RefundStatusPending:
|
|
return "待审核"
|
|
case RefundStatusApproved:
|
|
return "审核通过"
|
|
case RefundStatusRejected:
|
|
return "审核拒绝"
|
|
case RefundStatusProcessing:
|
|
return "退款中"
|
|
case RefundStatusSuccess:
|
|
return "退款成功"
|
|
case RefundStatusFailed:
|
|
return "退款失败"
|
|
default:
|
|
return "未知状态"
|
|
}
|
|
}
|
|
|
|
// GetRefundTypeText 获取退款类型文本
|
|
func (r *Refund) GetRefundTypeText() string {
|
|
switch r.RefundType {
|
|
case RefundTypeRefundOnly:
|
|
return "仅退款"
|
|
case RefundTypeReturn:
|
|
return "退货退款"
|
|
default:
|
|
return "未知类型"
|
|
}
|
|
}
|
|
|
|
// IsWechatRefundSuccess 判断微信退款是否成功
|
|
func (r *Refund) IsWechatRefundSuccess() bool {
|
|
return r.WechatRefundStatus == WechatRefundStatusSuccess
|
|
}
|
|
|
|
// CanCancel 判断是否可以取消退款申请
|
|
func (r *Refund) CanCancel() bool {
|
|
return r.Status == RefundStatusPending
|
|
}
|
|
|
|
// CanAudit 判断是否可以审核
|
|
func (r *Refund) CanAudit() bool {
|
|
return r.Status == RefundStatusPending
|
|
}
|
|
|
|
// CanRefund 判断是否可以执行退款
|
|
func (r *Refund) CanRefund() bool {
|
|
return r.Status == RefundStatusApproved
|
|
} |