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

user_invitation.go 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package models
  2. import (
  3. "fmt"
  4. "code.gitea.io/gitea/modules/log"
  5. "code.gitea.io/gitea/modules/timeutil"
  6. )
  7. // Follow represents relations of user and his/her followers.
  8. type Invitation struct {
  9. ID int64 `xorm:"pk autoincr"`
  10. SrcUserID int64 `xorm:"NOT NULL DEFAULT 0"`
  11. UserID int64 `xorm:"NOT NULL DEFAULT 0"`
  12. Phone string `xorm:"INDEX"`
  13. Email string `xorm:"-"`
  14. Avatar string `xorm:"-"`
  15. Name string `xorm:"-"`
  16. InvitationUserNum int `xorm:"-"`
  17. IsActive bool `xorm:"-"`
  18. CreatedUnix timeutil.TimeStamp `xorm:"created"`
  19. }
  20. func QueryInvitaionByPhone(phone string) []*Invitation {
  21. statictisSess := xStatistic.NewSession()
  22. defer statictisSess.Close()
  23. cond := "phone ='" + phone + "'"
  24. invitationList := make([]*Invitation, 0)
  25. if err := statictisSess.Table(new(Invitation)).Where(cond).
  26. Find(&invitationList); err != nil {
  27. return nil
  28. } else {
  29. return invitationList
  30. }
  31. }
  32. func GetAllUserName() map[int64]string {
  33. sess := x.NewSession()
  34. defer sess.Close()
  35. sess.Select("id,name").Table("user")
  36. userList := make([]*User, 0)
  37. reMap := make(map[int64]string)
  38. sess.Find(&userList)
  39. for _, user := range userList {
  40. reMap[user.ID] = user.Name
  41. }
  42. return reMap
  43. }
  44. func QueryInvitaionPage(start int, pageSize int) ([]*Invitation, int64) {
  45. statictisSess := xStatistic.NewSession()
  46. defer statictisSess.Close()
  47. //cond := "created_unix >=" + fmt.Sprint(startTime) + " and created_unix <=" + fmt.Sprint(endTime)
  48. allCount, err := statictisSess.Count(new(Invitation))
  49. if err != nil {
  50. log.Info("query error." + err.Error())
  51. return nil, 0
  52. }
  53. invitationList := make([]*Invitation, 0)
  54. if err := statictisSess.Table(new(Invitation)).OrderBy("created_unix desc").Limit(pageSize, start).
  55. Find(&invitationList); err != nil {
  56. return nil, 0
  57. }
  58. return invitationList, allCount
  59. }
  60. func QueryInvitaionByTime(startTime int64, endTime int64) []*Invitation {
  61. statictisSess := xStatistic.NewSession()
  62. defer statictisSess.Close()
  63. cond := "created_unix >=" + fmt.Sprint(startTime) + " and created_unix <=" + fmt.Sprint(endTime)
  64. invitationList := make([]*Invitation, 0)
  65. if err := statictisSess.Table(new(Invitation)).Where(cond).OrderBy("created_unix desc").
  66. Find(&invitationList); err != nil {
  67. return nil
  68. }
  69. return invitationList
  70. }
  71. func InsertInvitaion(invitationUser *Invitation) error {
  72. statictisSess := xStatistic.NewSession()
  73. defer statictisSess.Close()
  74. _, err := statictisSess.Insert(invitationUser)
  75. return err
  76. }
  77. func QueryInvitaionBySrcUserId(srcUserId int64, start int, pageSize int) ([]*Invitation, int64) {
  78. statictisSess := xStatistic.NewSession()
  79. defer statictisSess.Close()
  80. cond := "src_user_id =" + fmt.Sprint(srcUserId)
  81. allCount, err := statictisSess.Where(cond).Count(new(Invitation))
  82. if err != nil {
  83. log.Info("query error." + err.Error())
  84. return nil, 0
  85. }
  86. invitationList := make([]*Invitation, 0)
  87. if err := statictisSess.Table(new(Invitation)).Where(cond).OrderBy("created_unix desc").Limit(pageSize, start).
  88. Find(&invitationList); err != nil {
  89. return nil, 0
  90. }
  91. return invitationList, allCount
  92. }