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

225 lines
6.5 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
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
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. func (t *SignCtl) CheckSign() {
  19. activityId := t.MustGetInt64("activity_id")
  20. uid := t.MustGetUID()
  21. live := new(models.LiveConfig)
  22. exist, err := live.GetByActivityId(activityId)
  23. t.CheckErr(err)
  24. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在")
  25. if live.AdaptationFunc != nil && len(live.AdaptationFunc) != 0 {
  26. exist, err = new(models.ModuleServiceHistory).ExistSignModule(live.AdaptationFunc)
  27. t.CheckErr(err)
  28. if !exist {
  29. t.JSON(!exist)
  30. }
  31. } else {
  32. t.JSON(true)
  33. }
  34. activity := models.Activity{}
  35. exist, err = models.GetById(&activity, activityId)
  36. t.CheckErr(err)
  37. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "主活动不存在")
  38. customer := models.Customer{}
  39. exist, err = models.GetById(&customer, activity.CustomerId)
  40. t.CheckErr(err)
  41. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  42. area := new(models.AreaStore)
  43. if customer.AreaId == 0 {
  44. exist, err = area.GetMainAreaById(activityId)
  45. } else {
  46. exist, err = area.GetAreaStoreById(customer.AreaId)
  47. }
  48. t.CheckErr(err)
  49. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  50. history := new(models.SignHistory)
  51. signExist, err := history.GetByUserId(activityId, uid, activity.RehearsalId, area.Id)
  52. t.CheckErr(err)
  53. t.JSON(signExist)
  54. }
  55. //签到动作
  56. func (t *SignCtl) Sign() {
  57. uid := t.MustGetUID()
  58. activityId := t.MustGetInt64("activity_id")
  59. _type, _ := t.GetInt("_type")
  60. //根据activity_id查找主活动的信息
  61. activity := new(models.Activity)
  62. exist, err := models.GetById(activity, activityId)
  63. t.CheckErr(err)
  64. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  65. t.CheckRunning(activity.Status)
  66. user := new(models.User)
  67. exist, err = models.GetById(user, uid)
  68. t.CheckErr(err)
  69. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  70. customer := models.Customer{}
  71. exist, err = models.GetById(&customer, activity.CustomerId)
  72. t.CheckErr(err)
  73. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  74. var area = new(models.AreaStore)
  75. if customer.AreaId == 0 {
  76. exist, err = area.GetMainAreaById(activityId)
  77. } else {
  78. exist, err = area.GetAreaStoreById(customer.AreaId)
  79. }
  80. t.CheckErr(err)
  81. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  82. //根据activity_id查找副活动的规则信息
  83. signUp := new(models.SignUp)
  84. exist, err = signUp.GetByActivityId(activityId)
  85. t.CheckErr(err)
  86. t.Assert(exist, code.MSG_DATA_NOT_EXIST, "签到规则不存在")
  87. if signUp.OnlyInvitation == 1 { //
  88. // 邀请函才能签到
  89. letter := new(models.InvitationLetter)
  90. exist, err := letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
  91. t.CheckErr(err)
  92. t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您没收到邀请函")
  93. }
  94. //检查是否已经签到了
  95. signHistory := new(models.SignHistory)
  96. exist, err = signHistory.GetByUserId(activityId, uid, activity.RehearsalId, t.MustGetAreaId())
  97. t.CheckErr(err)
  98. t.Assert(!exist, code.MSG_SIGN_HISTORY_EXIST, "您已经签到过了") // 存在判断
  99. // 签到人数
  100. signTotal, err := core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?",
  101. signUp.Id, activity.RehearsalId, activity.Id).Count(signHistory)
  102. t.CheckErr(err)
  103. signUpTotal, err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activity.Id).Count(new(models.InvitationLetter))
  104. t.CheckErr(err)
  105. if activity.RehearsalId != 0 && signTotal >= 10 {
  106. t.ERROR("彩排人数不能超过10人", code.MSG_SIGN_UP_REHEARSAL_LIMIT)
  107. }
  108. signHistory = new(models.SignHistory)
  109. signHistory.Type = _type
  110. signHistory.UserId = uid
  111. signHistory.RehearsalId = activity.RehearsalId
  112. signHistory.ActivityId = activityId
  113. signHistory.SignRuleId = signUp.Id
  114. signHistory.AreaId = area.Id
  115. signHistory.IsDelete = false
  116. signHistory.UpdatedAt = time.Now()
  117. signHistory.CreatedAt = time.Now()
  118. _, err = core.GetXormAuto().InsertOne(signHistory)
  119. t.CheckErr(err)
  120. go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
  121. define.TYPE_CUSTOMER, activity.CustomerId, map[string]interface{}{
  122. "type": "sign_up",
  123. "customer_id": activity.CustomerId,
  124. "data": map[string]interface{}{
  125. "avatar": user.Avatar,
  126. "sign_total": signTotal + 1,
  127. "sign_up_total": signUpTotal,
  128. },
  129. })
  130. t.SUCCESS("签到成功")
  131. }
  132. func (t *SignCtl) RealSign() {
  133. aid := t.MustGetInt64("activity_id")
  134. uid := t.MustGetInt64("user_id")
  135. rid := t.MustGetInt64("rehearsal_id")
  136. user := new(models.User)
  137. exist, err := user.GetById(uid)
  138. t.CheckErr(err)
  139. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  140. sign := new(models.SignUp)
  141. exist, err = sign.GetByActivityId(aid)
  142. t.CheckErr(err)
  143. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
  144. history := new(models.RealSignHistory)
  145. isSign, err := history.Info(uid, aid, rid)
  146. t.CheckErr(err)
  147. if isSign && history.Status == 1 {
  148. t.SUCCESS("已通过实名签到")
  149. return
  150. } else if sign.RealSignJsonForm != "" && sign.RealSignJsonForm != "[]" {
  151. form := sign.RealSignJsonForm[1 : len(sign.RealSignJsonForm)-1]
  152. var extSql = ""
  153. var params = make(map[string]string, 0)
  154. for _, v := range strings.Split(form, ",") {
  155. name := strings.Trim(v, "\"")
  156. if value, ok := t.Get(name); ok {
  157. extSql += "and json_list like \"%" + value + "%\" "
  158. params[name] = value
  159. }
  160. }
  161. if len(extSql) > 0 {
  162. exist, err = new(models.RealSignList).CheckSignIn(aid, extSql)
  163. var body []byte
  164. body, err = json.Marshal(params)
  165. t.CheckErr(err)
  166. history.ActivityId = aid
  167. history.UserId = uid
  168. history.Nickname = user.Nickname
  169. history.RehearsalId = rid
  170. history.Content = string(body)
  171. if exist { // 存在 直接通过
  172. history.Status = 1
  173. } else {
  174. history.Status = 0
  175. }
  176. history.IsDelete = 0
  177. history.CreatedAt = time.Now()
  178. history.UpdatedAt = time.Now()
  179. if isSign {
  180. err = history.UpdateById([]interface{}{history.Id})
  181. } else {
  182. err = history.Insert()
  183. }
  184. t.CheckErr(err)
  185. if !exist { // 找不到导入的签名信息
  186. t.ERROR("您的信息不在名单之内", code.MSG_ERR)
  187. return
  188. }
  189. } else {
  190. t.ERROR("填写内容不能为空", code.MSG_ERR)
  191. return
  192. }
  193. t.SUCCESS("实名签到成功")
  194. return
  195. } else {
  196. t.ERROR("实名签到活动不存在", code.MSG_SIGN_REAL_NOT_EXIST)
  197. return
  198. }
  199. }