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

166 lines
4.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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package client
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/ouxuanserver/osmanthuswine/src/core"
  6. "hudongzhuanjia/controllers"
  7. "hudongzhuanjia/models"
  8. ws_send_service "hudongzhuanjia/services/ws_send"
  9. "hudongzhuanjia/utils/code"
  10. "hudongzhuanjia/utils/define"
  11. "strings"
  12. "time"
  13. )
  14. //签到
  15. type SignCtl struct {
  16. controllers.AuthorCtl
  17. }
  18. //签到动作
  19. func (t *SignCtl) Sign() {
  20. uid := t.MustGetUID()
  21. activityId := t.MustGetInt64("activity_id")
  22. customerId := t.MustGetInt64("customer_id")
  23. //根据activity_id查找主活动的信息
  24. activity := new(models.Activity)
  25. exist, err := models.GetById(activity, activityId)
  26. t.CheckErr(err)
  27. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  28. t.CheckRunning(activity.Status)
  29. customer := new(models.Customer)
  30. exist, err = models.GetById(customer, customerId)
  31. t.CheckErr(err)
  32. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  33. user := new(models.User)
  34. exist, err = models.GetById(user, uid)
  35. t.CheckErr(err)
  36. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  37. //根据activity_id查找副活动的规则信息
  38. signUp := new(models.SignUp)
  39. exist, err = signUp.GetByActivityId(activityId)
  40. t.CheckErr(err)
  41. t.Assert(exist, code.MSG_DATA_NOT_EXIST, "签到规则不存在")
  42. if signUp.OnlyInvitation == 1 { //
  43. // 邀请函才能签到
  44. letter := new(models.InvitationLetter)
  45. exist, err := letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
  46. t.CheckErr(err)
  47. t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您没收到邀请函")
  48. }
  49. //检查是否已经签到了
  50. signHistory := new(models.SignHistory)
  51. exist, err = signHistory.GetByUserId(activityId, uid, activity.RehearsalId, t.MustGetAreaId())
  52. t.CheckErr(err)
  53. t.Assert(!exist, code.MSG_SIGN_HISTORY_EXIST, "您已经签到过了") // 存在判断
  54. // 签到人数
  55. signTotal, err := core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?",
  56. signUp.Id, activity.RehearsalId, activity.Id).Count(signHistory)
  57. t.CheckErr(err)
  58. signUpTotal, err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activity.Id).Count(new(models.InvitationLetter))
  59. t.CheckErr(err)
  60. if activity.RehearsalId != 0 && signTotal >= 10 {
  61. t.ERROR("彩排人数不能超过10人", code.MSG_SIGN_UP_REHEARSAL_LIMIT)
  62. }
  63. signHistory = new(models.SignHistory)
  64. signHistory.UserId = uid
  65. signHistory.RehearsalId = activity.RehearsalId
  66. signHistory.ActivityId = activityId
  67. signHistory.SignRuleId = signUp.Id
  68. signHistory.AreaId = user.AreaId
  69. signHistory.IsDelete = false
  70. signHistory.UpdatedAt = time.Now()
  71. signHistory.CreatedAt = time.Now()
  72. _, err = core.GetXormAuto().InsertOne(signHistory)
  73. t.CheckErr(err)
  74. go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
  75. define.TYPE_CUSTOMER, customerId, map[string]interface{}{
  76. "type": "sign_up",
  77. "customer_id": customer.Id,
  78. "data": map[string]interface{}{
  79. "avatar": user.Avatar,
  80. "sign_total": signTotal + 1,
  81. "sign_up_total": signUpTotal,
  82. },
  83. })
  84. t.SUCCESS("签到成功")
  85. }
  86. func (t *SignCtl) RealSign() {
  87. aid := t.MustGetActivityId()
  88. uid := t.MustGetUID()
  89. rid := t.MustGetInt64("rehearsal_id")
  90. sign := new(models.SignUp)
  91. exist, err := sign.GetByActivityId(aid)
  92. t.CheckErr(err)
  93. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
  94. history := new(models.RealSignHistory)
  95. isSign, err := history.Info(uid, aid, rid)
  96. t.CheckErr(err)
  97. if isSign && history.Status == 1 {
  98. t.SUCCESS("已通过实名签到")
  99. return
  100. } else if sign.RealSignJsonForm != "" && sign.RealSignJsonForm != "[]" {
  101. form := sign.RealSignJsonForm[1 : len(sign.RealSignJsonForm)-1]
  102. var extSql = ""
  103. var params = make(map[string]string, 0)
  104. for _, v := range strings.Split(form, ",") {
  105. name := strings.Trim(v, "\"")
  106. if value, ok := t.Get(name); ok {
  107. extSql += "and json_list like \"%" + value + "%\" "
  108. params[name] = value
  109. }
  110. }
  111. if len(extSql) > 0 {
  112. exist, err = new(models.RealSignList).CheckSignIn(aid, extSql)
  113. var body []byte
  114. body, err = json.Marshal(params)
  115. t.CheckErr(err)
  116. history.ActivityId = aid
  117. history.UserId = uid
  118. history.Nickname = t.MustGetName()
  119. history.RehearsalId = rid
  120. history.Content = string(body)
  121. if exist { // 存在 直接通过
  122. history.Status = 1
  123. } else {
  124. history.Status = 0
  125. }
  126. history.IsDelete = 0
  127. history.CreatedAt = time.Now()
  128. history.UpdatedAt = time.Now()
  129. if isSign {
  130. err = history.UpdateById(history.Id)
  131. } else {
  132. err = history.Insert()
  133. }
  134. t.CheckErr(err)
  135. if !exist { // 找不到导入的签名信息
  136. t.ERROR("您的信息不在名单之内", code.MSG_ERR)
  137. return
  138. }
  139. } else {
  140. t.ERROR("填写内容不能为空", code.MSG_ERR)
  141. return
  142. }
  143. t.SUCCESS("实名签到成功")
  144. return
  145. } else {
  146. t.ERROR("实名签到活动不存在", code.MSG_SIGN_REAL_NOT_EXIST)
  147. return
  148. }
  149. }