互动
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.

81 lines
3.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. )
  5. const SignHistoryTN = TableNamePrefix + "sign_history"
  6. //签到历史表
  7. type SignHistory struct {
  8. Model `xorm:"extends"`
  9. //Id int `json:"id" xorm:"pk autoincr comment('主键') INT(11)"`
  10. //IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)"`
  11. //CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  12. //UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
  13. AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
  14. ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
  15. ActivityId int `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
  16. RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0正式') INT(11)"`
  17. SignRuleId int `json:"sign_rule_id" xorm:"not null default 0 comment('sign_up表id') INT(11)"`
  18. RealSignListId int `json:"real_sign_list_id" xorm:"not null default 0 comment('实名签到认证信息ID') INT(11)"`
  19. // Type int `json:"type" xorm:"not null default 0 comment('普通签到') TINYINT(1)"`
  20. UserId int `json:"user_id" xorm:"not null default 0 comment('用户表id') TINYINT(11)"`
  21. SignMethod int `json:"sign_method" xorm:"not null default 0 comment('1扫码签到2实名签到3人脸签到') TINYINT(1)"`
  22. Content string `json:"content" xorm:"json comment('提交审核的内容') TEXT"`
  23. Nickname string `json:"nickname" xorm:"not null default('') comment('微信昵称') VARCHAR(128)"`
  24. Status int `json:"status" xorm:"not null default 0 comment('是否通过审核[0未通过审核1申请审核2通过审核]') TINYINT(1)"`
  25. }
  26. func (t *SignHistory) TableName() string {
  27. return SignHistoryTN
  28. }
  29. func (t *SignHistory) GetByUserId(activityId, archId, userId, rehearsalId, areaId interface{}) (bool, error) {
  30. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and arch_id=? and user_id=? and "+
  31. "rehearsal_id=? and area_id=?", activityId, archId, userId, rehearsalId, areaId).Get(t)
  32. }
  33. func (t *SignHistory) Count(activityId, archId, rehearsalId, status interface{}) (int64, error) {
  34. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and arch_id=? and "+
  35. " rehearsal_id=? and status=?", activityId, archId, rehearsalId, status).Count(t)
  36. }
  37. func (t *SignHistory) UpdateByIds(ids interface{}, fields ...string) (err error) {
  38. if len(fields) > 0 {
  39. _, err = core.GetXormAuto().In("id", ids).Cols(fields...).Update(t)
  40. } else {
  41. _, err = core.GetXormAuto().In("id", ids).Update(t)
  42. }
  43. return err
  44. }
  45. func GetApplyRealSigns(activityId, archId, rehearsalId interface{}) ([]*SignHistory, error) {
  46. results := make([]*SignHistory, 0)
  47. err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and arch_id=? and rehearsal_id=? "+
  48. " and status=1", activityId, archId, rehearsalId).Asc("updated_at").Find(&results)
  49. return results, err
  50. }
  51. type SignHistoryAndUser struct {
  52. SignHistory `xorm:"extends"`
  53. User *User `json:"user" xorm:"extends"`
  54. }
  55. func GetSignHistories(activityId, rehearsalId, archId, page, size int) (total int64, result []*SignHistoryAndUser, err error) {
  56. session := core.GetXormAuto().Table(new(SignHistory)).Alias("h").
  57. Join("LEFT", new(User).Alias("u"), "h.user_id=u.id and u.is_delete=0").
  58. Where("h.is_delete=0 and h.activity_id=? and rehearsal_id=? and arch_id=?",
  59. activityId, rehearsalId, archId)
  60. if size > 0 { // 增加分页
  61. session.Limit(size, page*size)
  62. }
  63. total, err = session.FindAndCount(&result)
  64. return
  65. }
  66. func ExistReviewedSignInfo(activityId, archId, rehearsalId, realSignListId interface{}) (bool, error) {
  67. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and arch_id=? and rehearsal_id=? and "+
  68. " real_sign_list_id=? and status=2", activityId, archId, rehearsalId, realSignListId).Exist(&SignHistory{})
  69. }