劲创营---任务项目
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.
 
 
 

47 line
1.1 KiB

  1. package svc
  2. import (
  3. "applet/app/comm/db"
  4. "applet/app/comm/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. // Token 不为空时拿对应的用户数据
  13. if token != "" && strings.Contains(token, "Bearer") {
  14. user, err := CheckUser(c)
  15. if user == nil {
  16. return nil, errors.New("token is expired")
  17. }
  18. if err != nil {
  19. // 有报错自己拿默认用户
  20. goto DEFALUT
  21. }
  22. return user, nil
  23. }
  24. DEFALUT:
  25. // 默认拿uid 等于0的用户数据
  26. profile, err := db.UserProfileFindByID(db.DBs[c.GetString("mid")], 0)
  27. if err != nil {
  28. return nil, err
  29. }
  30. info, err := db.UserFindByID(db.DBs[c.GetString("mid")], 0)
  31. if err != nil {
  32. return nil, err
  33. }
  34. ul, err := db.UserLevelInIDescByWeightLowWithOne(db.DBs[c.GetString("mid")])
  35. if err != nil {
  36. return nil, err
  37. }
  38. user.Info = info
  39. user.Profile = profile
  40. user.Level = ul
  41. return user, nil
  42. }