134 lines
4.0 KiB
Go
134 lines
4.0 KiB
Go
|
package constant
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
// PaymentType 支付方式
|
||
|
type PaymentType int
|
||
|
|
||
|
const (
|
||
|
PaymentTypeNone PaymentType = iota // 未知 0
|
||
|
PaymentTypeWeChatMiniApp // 微信小程序 1
|
||
|
PaymentTypeWeChatH5 // 微信H5 2
|
||
|
PaymentTypeWeChatAPP // 微信APP 3
|
||
|
PaymentTypeExchangeCode // 兑换码白嫖 4
|
||
|
)
|
||
|
|
||
|
// 支付渠道描述
|
||
|
var paymentTypeMap = map[PaymentType]string{
|
||
|
PaymentTypeNone: "未知",
|
||
|
PaymentTypeWeChatMiniApp: "微信小程序",
|
||
|
PaymentTypeWeChatH5: "微信H5",
|
||
|
PaymentTypeWeChatAPP: "微信APP",
|
||
|
PaymentTypeExchangeCode: "兑换码",
|
||
|
}
|
||
|
|
||
|
// 处理为看得懂的状态
|
||
|
func (pt PaymentType) String() string {
|
||
|
if str, ok := paymentTypeMap[pt]; ok {
|
||
|
return str
|
||
|
}
|
||
|
return fmt.Sprintf("未知状态(%d)", pt)
|
||
|
}
|
||
|
|
||
|
// MarshalJSON JSON序列化的时候转换为中文
|
||
|
func (pt PaymentType) MarshalJSON() ([]byte, error) {
|
||
|
return []byte(`"` + pt.String() + `"`), nil
|
||
|
}
|
||
|
|
||
|
// =====================================================================================================================
|
||
|
|
||
|
type PayStatus int
|
||
|
|
||
|
const (
|
||
|
PayStatusNot PayStatus = iota // 未支付
|
||
|
PayStatusSuccess // 支付成功
|
||
|
PayStatusFail // 支付失败
|
||
|
PayStatusRefunded // 已退款
|
||
|
)
|
||
|
|
||
|
var payStatusMap = map[PayStatus]string{
|
||
|
PayStatusNot: "未支付",
|
||
|
PayStatusSuccess: "支付成功",
|
||
|
PayStatusFail: "支付失败",
|
||
|
PayStatusRefunded: "已退款",
|
||
|
}
|
||
|
|
||
|
// 处理为看得懂的状态
|
||
|
func (ps PayStatus) String() string {
|
||
|
if str, ok := payStatusMap[ps]; ok {
|
||
|
return str
|
||
|
}
|
||
|
return fmt.Sprintf("未知状态(%d)", ps)
|
||
|
}
|
||
|
|
||
|
// MarshalJSON JSON序列化的时候转换为中文
|
||
|
func (ps PayStatus) MarshalJSON() ([]byte, error) {
|
||
|
return []byte(fmt.Sprintf(`"%s"`, ps.String())), nil
|
||
|
}
|
||
|
|
||
|
// =====================================================================================================================
|
||
|
|
||
|
type OrderStatus int
|
||
|
|
||
|
const (
|
||
|
OrderStatusWait OrderStatus = iota // 待支付 0
|
||
|
OrderStatusUsing // 生效中 1
|
||
|
OrderStatusFailure // 已失效 2
|
||
|
OrderStatusApplicationRefund // 已申请退款 3
|
||
|
OrderStatusRefunding // 退款中 4
|
||
|
OrderStatusRefunded // 已退款 5
|
||
|
OrderStatusCanceled // 已取消 6
|
||
|
OrderStatusEnd // 已完成 7
|
||
|
)
|
||
|
|
||
|
var orderStatusMap = map[OrderStatus]string{
|
||
|
OrderStatusWait: "待支付",
|
||
|
OrderStatusUsing: "生效中",
|
||
|
OrderStatusFailure: "已失效",
|
||
|
OrderStatusApplicationRefund: "已申请退款",
|
||
|
OrderStatusRefunding: "退款中",
|
||
|
OrderStatusRefunded: "已退款",
|
||
|
OrderStatusCanceled: "已取消",
|
||
|
OrderStatusEnd: "已完成",
|
||
|
}
|
||
|
|
||
|
// 处理为看得懂的状态
|
||
|
func (os OrderStatus) String() string {
|
||
|
if str, ok := orderStatusMap[os]; ok {
|
||
|
return str
|
||
|
}
|
||
|
return fmt.Sprintf("未知状态(%d)", os)
|
||
|
}
|
||
|
|
||
|
// MarshalJSON JSON序列化的时候转换为中文
|
||
|
func (os OrderStatus) MarshalJSON() ([]byte, error) {
|
||
|
return []byte(fmt.Sprintf(`"%s"`, os.String())), nil
|
||
|
}
|
||
|
|
||
|
// =====================================================================================================================
|
||
|
|
||
|
type OrderServiceType int
|
||
|
|
||
|
const (
|
||
|
OrderServiceTypeProduct OrderServiceType = iota + 1 // 普通商品
|
||
|
OrderServiceTypeActivity // 活动
|
||
|
)
|
||
|
|
||
|
var orderServiceTypeMap = map[OrderServiceType]string{
|
||
|
OrderServiceTypeProduct: "服务",
|
||
|
OrderServiceTypeActivity: "活动",
|
||
|
}
|
||
|
|
||
|
// 处理为看得懂的状态
|
||
|
func (os OrderServiceType) String() string {
|
||
|
if str, ok := orderServiceTypeMap[os]; ok {
|
||
|
return str
|
||
|
}
|
||
|
return fmt.Sprintf("未知状态(%d)", os)
|
||
|
}
|
||
|
|
||
|
// MarshalJSON JSON序列化的时候转换为中文
|
||
|
func (os OrderServiceType) MarshalJSON() ([]byte, error) {
|
||
|
return []byte(fmt.Sprintf(`"%s"`, os.String())), nil
|
||
|
}
|