2025-12-13 17:44:18 +08:00
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var ErrNotFound = sqlx.ErrNotFound
|
|
|
|
|
|
var ErrNoRowsUpdate = errors.New("update db no rows change")
|
|
|
|
|
|
|
2026-06-06 17:03:08 +08:00
|
|
|
|
// 平台(请求头 X-Platform / JWT platform)
|
2025-12-13 17:44:18 +08:00
|
|
|
|
var PlatformWxMini string = "wxmini"
|
|
|
|
|
|
var PlatformWxH5 string = "wxh5"
|
|
|
|
|
|
var PlatformApp string = "app"
|
|
|
|
|
|
var PlatformH5 string = "h5"
|
|
|
|
|
|
var PlatformAdmin string = "admin"
|
|
|
|
|
|
|
2026-06-06 17:03:08 +08:00
|
|
|
|
// 订单支付场景 order.payment_scene(MySQL ENUM)
|
|
|
|
|
|
const (
|
|
|
|
|
|
PaymentSceneApp = "app"
|
|
|
|
|
|
PaymentSceneH5 = "h5"
|
|
|
|
|
|
PaymentSceneMiniProgram = "mini_program"
|
|
|
|
|
|
PaymentScenePublicAccount = "public_account"
|
|
|
|
|
|
PaymentSceneTest = "test"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// PaymentSceneFromPlatform 将运行时平台标识映射为 order.payment_scene 枚举值
|
|
|
|
|
|
func PaymentSceneFromPlatform(platform string) string {
|
|
|
|
|
|
switch platform {
|
|
|
|
|
|
case PlatformWxMini:
|
|
|
|
|
|
return PaymentSceneMiniProgram
|
|
|
|
|
|
case PlatformWxH5:
|
|
|
|
|
|
return PaymentScenePublicAccount
|
|
|
|
|
|
case PlatformH5:
|
|
|
|
|
|
return PaymentSceneH5
|
|
|
|
|
|
case PlatformApp:
|
|
|
|
|
|
return PaymentSceneApp
|
|
|
|
|
|
default:
|
|
|
|
|
|
return PaymentSceneApp
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-13 17:44:18 +08:00
|
|
|
|
// 用户授权类型
|
|
|
|
|
|
var UserAuthTypeMobile string = "mobile"
|
|
|
|
|
|
var UserAuthTypeWxMiniOpenID string = "wxmini_openid"
|
|
|
|
|
|
var UserAuthTypeWxh5OpenID string = "wxh5_openid"
|
|
|
|
|
|
var UserAuthTypeUUID string = "uuid"
|
|
|
|
|
|
|
|
|
|
|
|
// 代理扣除类型
|
|
|
|
|
|
var AgentDeductionTypeCost string = "cost"
|
|
|
|
|
|
var AgentDeductionTypePricing string = "pricing"
|
|
|
|
|
|
|
|
|
|
|
|
var AgentRewardsTypeDescendantPromotion string = "descendant_promotion"
|
|
|
|
|
|
var AgentRewardsTypeDescendantUpgradeVip string = "descendant_upgrade_vip"
|
|
|
|
|
|
var AgentRewardsTypeDescendantUpgradeSvip string = "descendant_upgrade_svip"
|
|
|
|
|
|
var AgentRewardsTypeDescendantStayActive string = "descendant_stay_active"
|
|
|
|
|
|
var AgentRewardsTypeDescendantNewActive string = "descendant_new_active"
|
|
|
|
|
|
var AgentRewardsTypeDescendantWithdraw string = "descendant_withdraw"
|
|
|
|
|
|
|
|
|
|
|
|
var AgentLeveNameNormal string = "normal"
|
|
|
|
|
|
var AgentLeveNameVIP string = "VIP"
|
|
|
|
|
|
var AgentLeveNameSVIP string = "SVIP"
|
|
|
|
|
|
|
2026-06-06 17:03:08 +08:00
|
|
|
|
// 订单支付平台 order.payment_platform(varchar,非 ENUM)
|
|
|
|
|
|
const (
|
|
|
|
|
|
PaymentPlatformAlipay = "alipay"
|
|
|
|
|
|
PaymentPlatformWechat = "wechat" // 普通微信支付(JSAPI/H5/APP)
|
|
|
|
|
|
PaymentPlatformWechatXpay = "wechat_xpay" // 小程序虚拟支付
|
|
|
|
|
|
PaymentPlatformAppleIAP = "appleiap"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// IsXpayOrder 是否为小程序虚拟支付订单(含历史 wechat+mini_program 查询单)
|
|
|
|
|
|
func IsXpayOrder(order *Order) bool {
|
|
|
|
|
|
if order == nil {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
if order.PaymentPlatform == PaymentPlatformWechatXpay {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
// 兼容改造前:查询单 Q_ 前缀 + 小程序场景 + pay_method=wechat
|
|
|
|
|
|
return order.PaymentPlatform == PaymentPlatformWechat &&
|
|
|
|
|
|
order.PaymentScene == PaymentSceneMiniProgram &&
|
|
|
|
|
|
len(order.OrderNo) > 2 && order.OrderNo[:2] == "Q_"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-13 17:44:18 +08:00
|
|
|
|
const (
|
|
|
|
|
|
OrderStatusPending = "pending"
|
|
|
|
|
|
OrderStatusPaid = "paid"
|
|
|
|
|
|
OrderStatusFailed = "failed"
|
|
|
|
|
|
OrderStatusRefunding = "refunding"
|
|
|
|
|
|
OrderStatusRefunded = "refunded"
|
|
|
|
|
|
OrderStatusClosed = "closed"
|
|
|
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
|
|
|
OrderRefundStatusPending = "pending"
|
|
|
|
|
|
OrderRefundStatusSuccess = "success"
|
|
|
|
|
|
OrderRefundStatusFailed = "failed"
|
|
|
|
|
|
OrderRefundStatusClosed = "closed"
|
|
|
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
|
|
|
QueryStatePending = "pending"
|
|
|
|
|
|
QueryStateFailed = "failed"
|
|
|
|
|
|
QueryStateSuccess = "success"
|
|
|
|
|
|
QueryStateProcessing = "processing"
|
|
|
|
|
|
QueryStateCleaned = "cleaned"
|
|
|
|
|
|
QueryStateRefunded = "refunded"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
GrantTypeFace string = "face"
|
|
|
|
|
|
AuthorizationGrantTypeSms = "sms"
|
|
|
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
|
|
|
AuthorizationStatusPending = "pending"
|
|
|
|
|
|
AuthorizationStatusSuccess = "success"
|
|
|
|
|
|
AuthorizationStatusFailed = "failed"
|
|
|
|
|
|
AuthorizationStatusExpired = "expired"
|
|
|
|
|
|
AuthorizationStatusRevoked = "revoked"
|
|
|
|
|
|
AuthorizationStatusRejected = "rejected"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
AuthorizationFaceStatusPending = "pending"
|
|
|
|
|
|
AuthorizationFaceStatusSuccess = "success"
|
|
|
|
|
|
AuthorizationFaceStatusFailed = "failed"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
AgentRealNameStatusPending = "pending"
|
|
|
|
|
|
AgentRealNameStatusApproved = "approved"
|
|
|
|
|
|
AgentRealNameStatusRejected = "rejected"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 用户身份类型
|
|
|
|
|
|
const (
|
|
|
|
|
|
UserTypeTemp = 0 // 临时用户
|
|
|
|
|
|
UserTypeNormal = 1 // 正式用户
|
|
|
|
|
|
UserTypeAdmin = 2 // 管理员
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 管理员角色编码
|
|
|
|
|
|
const (
|
|
|
|
|
|
AdminRoleCodeSuper = "SUPER" // 超级管理员
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 代理状态
|
|
|
|
|
|
const (
|
|
|
|
|
|
AgentStatusNo = 0 // 非代理
|
|
|
|
|
|
AgentStatusYes = 1 // 是代理
|
|
|
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
|
|
|
TaxStatusPending = 0 // 待扣税
|
|
|
|
|
|
TaxStatusSuccess = 1 // 已扣税
|
|
|
|
|
|
TaxStatusExempt = 2 // 免税
|
|
|
|
|
|
TaxStatusFailed = 3 // 扣税失败
|
|
|
|
|
|
)
|