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

112 lines
2.8 KiB

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