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

114 lines
2.8 KiB

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
  1. package pc
  2. import (
  3. "hudongzhuanjia/controllers"
  4. "hudongzhuanjia/models"
  5. "hudongzhuanjia/utils"
  6. "hudongzhuanjia/utils/code"
  7. "hudongzhuanjia/utils/define"
  8. "strings"
  9. "github.com/ouxuanserver/osmanthuswine/src/core"
  10. )
  11. //签到
  12. type SignCtl struct {
  13. controllers.AuthorCtl
  14. }
  15. //获取二维码
  16. func (t *SignCtl) Qrcode() {
  17. activityId := t.MustGetInt64("activity_id")
  18. uid := t.MustGetUID()
  19. signUpId := t.MustGetInt64("sign_rule_id")
  20. //将服务器得地址和activity_id,动态生成二维码
  21. qrcode, err := utils.GenH5Qrcode(define.H5SignIn, map[string]interface{}{
  22. "activity_id": activityId,
  23. "customer_id": uid,
  24. "sign_rule_id": signUpId,
  25. })
  26. t.CheckErr(err)
  27. t.JSON(map[string]interface{}{
  28. "qrcode": qrcode,
  29. "logo": "",
  30. })
  31. }
  32. //获取签到模式
  33. func (t *SignCtl) Mode() {
  34. activityId := t.MustGetInt64("activity_id")
  35. //通过activity_id查询ox_sign_rule的id
  36. signUp := new(models.SignUp)
  37. exist, err := signUp.GetByActivityId(activityId)
  38. t.CheckErr(err)
  39. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到规则不存在")
  40. t.RAW(signUp.MaxModel)
  41. }
  42. func (t *SignCtl) List() {
  43. activityId := t.MustGetInt64("activity_id")
  44. signUps := make([]*models.SignUp, 0)
  45. err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).Asc("created_at").Find(&signUps)
  46. t.CheckErr(err)
  47. t.JSON(map[string]interface{}{
  48. "total": len(signUps),
  49. "list": signUps,
  50. })
  51. }
  52. type SignResult struct {
  53. models.SignHistory `xorm:"extends"`
  54. User *models.User `json:"user" xorm:"extends"`
  55. }
  56. //处理签到信息
  57. func (t *SignCtl) SignInfo() {
  58. aid := t.MustGetActivityId()
  59. //activityId := t.MustGetInt64("activity_id")
  60. rehearsalId := t.MustGetInt64("rehearsal_id")
  61. result := make([]*SignResult, 0)
  62. session := core.GetXormAuto().Table(new(models.SignHistory)).Alias("h").
  63. Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0").
  64. Where("h.is_delete=0 and h.activity_id=? and rehearsal_id=?", aid, rehearsalId)
  65. if t.PageSize > 0 { // 增加分页
  66. session.Limit(t.PageSize, t.Page*t.PageSize)
  67. }
  68. count, err := session.FindAndCount(&result)
  69. t.CheckErr(err)
  70. t.JSON(map[string]interface{}{
  71. "list": result,
  72. "sign_up_total": count,
  73. })
  74. }
  75. // 实名签到信息
  76. func (t *SignCtl) RealSignInfo() {
  77. aid := t.MustGetActivityId()
  78. rid := t.MustGetInt64("rehearsal_id")
  79. results, err := models.GetRealSignHistories(aid, rid)
  80. t.CheckErr(err)
  81. t.JSON(map[string]interface{}{
  82. "result": results,
  83. "count": len(results),
  84. })
  85. }
  86. func (t *SignCtl) RealSignVerify() {
  87. ids := strings.Split(t.MustGet("real_sign_history_ids"), ",")
  88. idList := make([]interface{}, len(ids))
  89. for _, id := range ids {
  90. idList = append(idList, id)
  91. }
  92. history := new(models.RealSignHistory)
  93. history.Status = 1
  94. err := history.UpdateById(idList, "status")
  95. t.CheckErr(err)
  96. t.SUCCESS("审核成功")
  97. }