✨ Init
This commit is contained in:
		
							
								
								
									
										16
									
								
								model/common/constant/login.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								model/common/constant/login.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
package constant
 | 
			
		||||
 | 
			
		||||
// LoginType 自定义登录类型
 | 
			
		||||
type LoginType string
 | 
			
		||||
 | 
			
		||||
// 登录类型
 | 
			
		||||
const (
 | 
			
		||||
	LoginTypeWeChatMiniApp LoginType = "wechat_mini_app" // 微信小程序登录
 | 
			
		||||
	LoginTypeSms           LoginType = "sms"             // 短信验证码登录
 | 
			
		||||
	LoginTypePassword      LoginType = "password"        // 密码登录
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// String 转换为字符串
 | 
			
		||||
func (t LoginType) String() string {
 | 
			
		||||
	return string(t)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										133
									
								
								model/common/constant/order.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								model/common/constant/order.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,133 @@
 | 
			
		||||
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
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								model/common/constant/rds_key.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								model/common/constant/rds_key.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
package constant
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	OAuth2RedisKey     = "oauth:token:"    // Token缓存前缀
 | 
			
		||||
	OAuth2UserCacheKey = "oauth:user:"     // 用户缓存前缀
 | 
			
		||||
	ApiAntiShakeKey    = "api:antishake:"  // 防抖锁
 | 
			
		||||
	WeChatSessionKey   = "wechat:session:" // 小程序用户SessionKey前缀
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										88
									
								
								model/common/constant/user.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								model/common/constant/user.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
			
		||||
package constant
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// UserStatus 用户状态
 | 
			
		||||
type UserStatus string
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	UserStatusActive   UserStatus = "NORMAL"  // 用户状态正常
 | 
			
		||||
	UserStatusDisabled UserStatus = "DISABLE" // 已禁用用户
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 状态对应的描述
 | 
			
		||||
var userStatusMap = map[UserStatus]string{
 | 
			
		||||
	UserStatusActive:   "正常",
 | 
			
		||||
	UserStatusDisabled: "已禁用",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 处理为看得懂的状态
 | 
			
		||||
func (s UserStatus) String() string {
 | 
			
		||||
	if str, ok := userStatusMap[s]; ok {
 | 
			
		||||
		return str
 | 
			
		||||
	}
 | 
			
		||||
	return string(s)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// =====================================================================================================================
 | 
			
		||||
 | 
			
		||||
// UserSex 性别
 | 
			
		||||
type UserSex int
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	UserSexNone   UserSex = iota // 不知道是啥
 | 
			
		||||
	UserSexMale                  // 男
 | 
			
		||||
	UserSexFemale                // 女
 | 
			
		||||
	UserSexOther                 // 其他性别
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 状态对应的描述
 | 
			
		||||
var userSexMap = map[UserSex]string{
 | 
			
		||||
	UserSexNone:   "无性别",
 | 
			
		||||
	UserSexMale:   "男",
 | 
			
		||||
	UserSexFemale: "女",
 | 
			
		||||
	UserSexOther:  "其他",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FromString 中文取性别
 | 
			
		||||
func (s UserSex) FromString(sex string) UserSex {
 | 
			
		||||
	result := UserSexNone
 | 
			
		||||
	for key, value := range userSexMap {
 | 
			
		||||
		if sex == value {
 | 
			
		||||
			result = key
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return result
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 处理为看得懂的状态
 | 
			
		||||
func (s UserSex) String() string {
 | 
			
		||||
	if str, ok := userSexMap[s]; ok {
 | 
			
		||||
		return str
 | 
			
		||||
	}
 | 
			
		||||
	//return strconv.Itoa(int(s))
 | 
			
		||||
	return fmt.Sprintf("UserSex(%d)", int(s))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// MarshalJSON JSON序列化的时候转换为中文
 | 
			
		||||
func (s UserSex) MarshalJSON() ([]byte, error) {
 | 
			
		||||
	return []byte(`"` + s.String() + `"`), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// =====================================================================================================================
 | 
			
		||||
 | 
			
		||||
// UserIdentity 用户身份
 | 
			
		||||
type UserIdentity string
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	UserIdentityAdmin UserIdentity = "admin" // 管理员
 | 
			
		||||
	UserIdentityUser  UserIdentity = "user"  // 普通用户
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// String implements the Stringer interface.
 | 
			
		||||
func (t UserIdentity) String() string {
 | 
			
		||||
	return string(t)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user