附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 месеца
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/md"
  5. "errors"
  6. "github.com/gin-gonic/gin"
  7. "strings"
  8. )
  9. // GetDefaultUser is 获取默认账号,uid =0 为系统默认账号,用于一些请求需要渠道id之类的东西
  10. func GetDefaultUser(c *gin.Context, token string) (*md.User, error) {
  11. user := new(md.User)
  12. if c.GetString("convert_url") == "1" { //转链接口
  13. goto DEFALUT
  14. } else {
  15. // Token 不为空时拿对应的用户数据
  16. if token != "" && strings.Contains(token, "Bearer") {
  17. user, err := CheckUser(c)
  18. if user == nil {
  19. return nil, errors.New("token is expired")
  20. }
  21. if err != nil {
  22. // 有报错自己拿默认用户
  23. goto DEFALUT
  24. }
  25. return user, nil
  26. }
  27. }
  28. DEFALUT:
  29. // 默认拿uid 等于0的用户数据
  30. profile, err := db.UserProfileFindByID(db.DBs[c.GetString("mid")], 0)
  31. if err != nil {
  32. return nil, err
  33. }
  34. info, err := db.UserFindByID(db.DBs[c.GetString("mid")], 0)
  35. if err != nil {
  36. return nil, err
  37. }
  38. ul, err := db.UserLevelInIDescByWeightLowWithOne(db.DBs[c.GetString("mid")])
  39. if err != nil {
  40. return nil, err
  41. }
  42. user.Info = info
  43. user.Profile = profile
  44. user.Level = ul
  45. return user, nil
  46. }