feat: analysis user auth and ws

This commit is contained in:
zzw
2026-10-15 09:23:07 +08:00
parent 6fa185003d
commit a65b6d2803
102 changed files with 4966 additions and 786 deletions
+1 -2
View File
@@ -43,8 +43,7 @@ type Claims struct {
Birthday string `json:"birthday"`
Type uint8 `json:"type"` // 1销售 2门店 3普通用户
ClientCode string `json:"client_code"`
SaleId int64 `json:"sale_id,omitempty"`
StoreId int64 `json:"store_id,omitempty"`
BizId int64 `json:"biz_id,omitempty"`
TokenType string `json:"token_type"` // access | refresh
jwt.RegisteredClaims
}
+2
View File
@@ -29,6 +29,7 @@ type UserInfo struct {
GroupName string // 分组名称
Type uint8 // 用户类型
ClientCode string
BizId int64
Valid bool
}
@@ -72,6 +73,7 @@ func GetUserFromCtx(ctx context.Context) UserInfo {
GroupId: parseInt64MD(md, "x-group-id"),
GroupName: firstMD(md, "x-group-name"),
ClientCode: firstMD(md, "x-client-code"),
BizId: parseInt64MD(md, "x-biz-id"),
}
if typeRaw := firstMD(md, "x-user-type"); typeRaw != StringEmpty {
+3
View File
@@ -129,6 +129,9 @@ var (
// 参数类
ErrorReasonParams = Status{Code: 10012, Msg: "原因不能为空"}
ErrorMobileError = Status{Code: 10013, Msg: "手机号格式错误"}
ErrorQRcodeExp = Status{Code: 10015, Msg: "二维码已过期"}
ErrorNotFace = Status{Code: 10016, Msg: "未检测到人脸"}
ErrorFileUpFailed = Status{Code: 10017, Msg: "文件上传失败"}
// ErrorNotFund 数据类
ErrorFormatDataError = Status{Code: 11014, Msg: "格式化数据出错"}
+17 -7
View File
@@ -73,15 +73,12 @@ func (ct CustomTime) MarshalJSON() ([]byte, error) {
// UnmarshalJSON 实现 JSON 反序列化
func (ct *CustomTime) UnmarshalJSON(data []byte) error {
str := string(data)
if str == "null" || str == `""` {
str := strings.Trim(string(data), `"`)
if str == "" || str == "null" || isZeroDate(str) {
ct.Time = time.Time{}
return nil
}
// 去除引号
str = strings.Trim(str, `"`)
// 尝试解析多种格式
formats := []string{
"2006-01-02",
@@ -122,14 +119,27 @@ func (ct *CustomTime) Scan(value interface{}) error {
ct.Time = v
return nil
case []byte:
return ct.UnmarshalJSON(v)
return ct.scanString(string(v))
case string:
return ct.UnmarshalJSON([]byte(v))
return ct.scanString(v)
default:
return fmt.Errorf("unsupported type: %T", value)
}
}
func (ct *CustomTime) scanString(s string) error {
s = strings.TrimSpace(s)
if s == "" || isZeroDate(s) {
ct.Time = time.Time{}
return nil
}
return ct.UnmarshalJSON([]byte(`"` + s + `"`))
}
func isZeroDate(s string) bool {
return s == "0000-00-00" || s == "0000-00-00 00:00:00"
}
// GormDataType 定义 GORM 数据库类型
func (CustomTime) GormDataType() string {
return "datetime"