feat: analysis user status
CI / changes (push) Successful in 1m32s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / analysis (push) Successful in 3m45s
CI / bff (push) Successful in 31s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 1s
CI / product (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / record (push) Successful in 0s
CI / store (push) Successful in 0s
CI / support (push) Successful in 0s
CI / user (push) Successful in 1s
CI / task (push) Successful in 0s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
CI / changes (push) Successful in 1m32s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / analysis (push) Successful in 3m45s
CI / bff (push) Successful in 31s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 1s
CI / product (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / record (push) Successful in 0s
CI / store (push) Successful in 0s
CI / support (push) Successful in 0s
CI / user (push) Successful in 1s
CI / task (push) Successful in 0s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
)
|
||||
|
||||
func RequireLogin(ctx context.Context) (utils.UserInfo, *analysis.Response) {
|
||||
user := utils.GetUserFromCtx(ctx)
|
||||
if !user.Valid {
|
||||
return user, FailResponse(utils.ErrorNoLogin)
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func NotYoursResponse() *analysis.Response {
|
||||
return OutResponse(utils.ErrorNotFund, "该数据不属于您")
|
||||
}
|
||||
|
||||
func GetAuthUser(login utils.UserInfo, requestUserId int64) (int64, error) {
|
||||
if login.Type == dao.TypeUser {
|
||||
return login.BizId, nil
|
||||
}
|
||||
if login.Type == dao.TypeStore {
|
||||
return AuthUser(login.BizId, requestUserId)
|
||||
}
|
||||
return utils.NumberZero, nil
|
||||
}
|
||||
|
||||
func GetAuthUserID(login utils.UserInfo, recordUserId int64) (int64, error) {
|
||||
if login.Type == dao.TypeUser {
|
||||
if login.BizId != recordUserId {
|
||||
return utils.NumberZero, nil
|
||||
}
|
||||
return login.BizId, nil
|
||||
}
|
||||
if login.Type == dao.TypeStore {
|
||||
return AuthUser(login.BizId, recordUserId)
|
||||
}
|
||||
return utils.NumberZero, nil
|
||||
}
|
||||
|
||||
func AuthUser(storeId, userId int64) (int64, error) {
|
||||
return authUser(storeId, userId, true)
|
||||
}
|
||||
|
||||
func AuthUserNoExpiry(storeId, userId int64) (int64, error) {
|
||||
return authUser(storeId, userId, false)
|
||||
}
|
||||
|
||||
func authUser(storeId, userId int64, checkExpiry bool) (int64, error) {
|
||||
if storeId < utils.NumberOne || userId < utils.NumberOne {
|
||||
return utils.NumberZero, nil
|
||||
}
|
||||
params := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"user_id": strconv.FormatInt(userId, utils.NumberTen),
|
||||
"store_id": strconv.FormatInt(storeId, utils.NumberTen),
|
||||
"status": strconv.Itoa(utils.StatusOk),
|
||||
},
|
||||
}
|
||||
if checkExpiry {
|
||||
params.Other = map[string]string{
|
||||
"validity_time >= ?": utils.Now().String(),
|
||||
}
|
||||
}
|
||||
var auth dao.UserStoreAuth
|
||||
err := model.UserStoreAuthModel{}.Init().GetOne(params, &auth)
|
||||
if err != nil {
|
||||
return utils.NumberZero, err
|
||||
}
|
||||
if auth.Id < utils.NumberOne {
|
||||
return utils.NumberZero, nil
|
||||
}
|
||||
return userId, nil
|
||||
}
|
||||
Reference in New Issue
Block a user