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

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