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

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