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

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