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.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. Avatar string `xorm:"-"`
  14. Name string `xorm:"-"`
  15. InvitationUserNum int `xorm:"-"`
  16. IsActive bool `xorm:"-"`
  17. CreatedUnix timeutil.TimeStamp `xorm:"created"`
  18. }
  19. func QueryInvitaionByPhone(phone string) []*Invitation {
  20. statictisSess := xStatistic.NewSession()
  21. defer statictisSess.Close()
  22. cond := "phone ='" + phone + "'"
  23. invitationList := make([]*Invitation, 0)
  24. if err := statictisSess.Table(new(Invitation)).Where(cond).
  25. Find(&invitationList); err != nil {
  26. return nil
  27. } else {
  28. return invitationList
  29. }
  30. }
  31. func GetAllUserName() map[int64]string {
  32. sess := x.NewSession()
  33. defer sess.Close()
  34. sess.Select("id,name").Table("user")
  35. userList := make([]*User, 0)
  36. reMap := make(map[int64]string)
  37. sess.Find(&userList)
  38. for _, user := range userList {
  39. reMap[user.ID] = user.Name
  40. }
  41. return reMap
  42. }
  43. func QueryInvitaionPage(start int, pageSize int) ([]*Invitation, int64) {
  44. statictisSess := xStatistic.NewSession()
  45. defer statictisSess.Close()
  46. //cond := "created_unix >=" + fmt.Sprint(startTime) + " and created_unix <=" + fmt.Sprint(endTime)
  47. allCount, err := statictisSess.Count(new(Invitation))
  48. if err != nil {
  49. log.Info("query error." + err.Error())
  50. return nil, 0
  51. }
  52. invitationList := make([]*Invitation, 0)
  53. if err := statictisSess.Table(new(Invitation)).OrderBy("created_unix desc").Limit(pageSize, start).
  54. Find(&invitationList); err != nil {
  55. return nil, 0
  56. }
  57. return invitationList, allCount
  58. }
  59. func QueryInvitaionByTime(startTime int64, endTime int64) []*Invitation {
  60. statictisSess := xStatistic.NewSession()
  61. defer statictisSess.Close()
  62. cond := "created_unix >=" + fmt.Sprint(startTime) + " and created_unix <=" + fmt.Sprint(endTime)
  63. invitationList := make([]*Invitation, 0)
  64. if err := statictisSess.Table(new(Invitation)).Where(cond).OrderBy("created_unix desc").
  65. Find(&invitationList); err != nil {
  66. return nil
  67. }
  68. return invitationList
  69. }
  70. func InsertInvitaion(invitationUser *Invitation) error {
  71. statictisSess := xStatistic.NewSession()
  72. defer statictisSess.Close()
  73. _, err := statictisSess.Insert(invitationUser)
  74. return err
  75. }
  76. func QueryInvitaionBySrcUserId(srcUserId int64, start int, pageSize int) ([]*Invitation, int64) {
  77. statictisSess := xStatistic.NewSession()
  78. defer statictisSess.Close()
  79. cond := "src_user_id =" + fmt.Sprint(srcUserId)
  80. allCount, err := statictisSess.Where(cond).Count(new(Invitation))
  81. if err != nil {
  82. log.Info("query error." + err.Error())
  83. return nil, 0
  84. }
  85. invitationList := make([]*Invitation, 0)
  86. if err := statictisSess.Table(new(Invitation)).Where(cond).OrderBy("created_unix desc").Limit(pageSize, start).
  87. Find(&invitationList); err != nil {
  88. return nil, 0
  89. }
  90. return invitationList, allCount
  91. }