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

354 lines
10 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
4 years ago
5 years ago
4 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
4 years ago
5 years ago
4 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
4 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
4 years ago
5 years ago
4 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
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 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. )
  11. //签到
  12. type SignCtl struct {
  13. controllers.AuthorCtl
  14. }
  15. func (t *SignCtl) CheckSign() {
  16. activityId := t.MustGetInt("activity_id")
  17. areaId := t.MustGetInt("area_id")
  18. uid := t.GetAccountId()
  19. _type := t.MustGetInt("type")
  20. activity := &models.Activity{}
  21. exist, err := models.Get(activity, activityId)
  22. t.CheckErr(err)
  23. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  24. area := &models.AreaStore{}
  25. exist, err = models.Get(area, areaId)
  26. t.CheckErr(err)
  27. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "此直播间已被删除")
  28. if activity.MoreAreaMode == define.StatusClose && area.IsMainArea != 1 {
  29. t.ERROR("多地区功能关闭,链接失效,请打开后再试", code.MSG_AREASTORE_CLOSED)
  30. }
  31. if _type == 1 {
  32. live := new(models.LiveConfig)
  33. exist, err := live.GetByActivityId(activity.Id)
  34. t.CheckErr(err)
  35. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在")
  36. if live.LiveMode == 2 {
  37. var num = 0
  38. if live.LimitType == 1 { // 累计人数->可以重复进入
  39. viewer := new(models.LiveViewer)
  40. exist, err := viewer.ExistByUserId(uid, live.Id)
  41. t.CheckErr(err)
  42. if !exist {
  43. count, err := models.CountLiveViewerByLiveConfigId(live.Id)
  44. t.CheckErr(err)
  45. num = int(count)
  46. }
  47. } else if live.LimitType == 2 {
  48. num = live.WatchNum + 1
  49. }
  50. if num >= live.Limit {
  51. t.ERROR("直播人数已满", code.MSG_LIVE_LIMIT_ENOUGH)
  52. return
  53. }
  54. }
  55. err = new(models.LiveViewer).Record(uid, activityId, live.Id)
  56. t.CheckErr(err)
  57. if live.AdaptationFunc != nil && len(live.AdaptationFunc) != 0 {
  58. exist, err = new(models.ModuleServiceHistory).ExistSignModule(live.AdaptationFunc)
  59. t.CheckErr(err)
  60. if !exist {
  61. t.JSON(true)
  62. }
  63. } else {
  64. t.JSON(true)
  65. }
  66. }
  67. history := new(models.SignHistory)
  68. signExist, err := history.GetByUserId(activityId, activity.ArchId, uid, activity.RehearsalId, area.Id)
  69. t.CheckErr(err)
  70. if !signExist || history.Status != 2 {
  71. t.JSON(false)
  72. } else {
  73. t.JSON(true)
  74. }
  75. }
  76. func (t *SignCtl) Setting() {
  77. activityId := t.MustGetInt("activity_id")
  78. areaId := t.MustGetInt("area_id")
  79. activity := &models.Activity{}
  80. exist, err := models.Get(activity, activityId)
  81. t.CheckErr(err)
  82. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  83. area := &models.AreaStore{}
  84. exist, err = models.Get(area, areaId)
  85. t.CheckErr(err)
  86. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "此直播间已被删除")
  87. if activity.MoreAreaMode == define.StatusClose && area.IsMainArea != 1 {
  88. t.ERROR("多地区功能关闭,链接失效,请打开后再试", code.MSG_AREASTORE_CLOSED)
  89. }
  90. service := new(models.ModuleService)
  91. exist, err = service.GetByName(define.MODULE_SIGNIN)
  92. t.CheckErr(err)
  93. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
  94. historyIds, err := models.GetModuleServiceHistoryIdsByIdAndName(service.Id, service.Name)
  95. t.CheckErr(err)
  96. module := new(models.ActivityModuleService)
  97. exist, err = module.GetByActivityIdAndHistoryIds(activityId, historyIds)
  98. t.CheckErr(err)
  99. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
  100. phoneBg := ""
  101. if module.PhoneBgSwitch == define.StatusOpen {
  102. phoneBg = module.PhoneBgUrl
  103. }
  104. sign := new(models.SignUp)
  105. exist, err = sign.GetByActivityId(activityId)
  106. t.JSON(map[string]interface{}{
  107. "phone_bg": phoneBg,
  108. "setting": sign,
  109. })
  110. }
  111. //签到动作
  112. func (t *SignCtl) Sign() {
  113. uid := t.GetAccountId()
  114. activityId := t.MustGetInt("activity_id")
  115. _type := t.DefaultInt("type", 0) // 默认 0
  116. areaId := t.MustGetInt("area_id")
  117. //根据activity_id查找主活动的信息
  118. activity := new(models.Activity)
  119. exist, err := models.Get(activity, activityId)
  120. t.CheckErr(err)
  121. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  122. area := new(models.AreaStore)
  123. exist, err = models.Get(area, areaId)
  124. t.CheckErr(err)
  125. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  126. user := new(models.User)
  127. exist, err = models.Get(user, uid)
  128. t.CheckErr(err)
  129. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  130. //根据activity_id查找副活动的规则信息
  131. signUp := new(models.SignUp)
  132. exist, err = signUp.GetByActivityId(activityId)
  133. t.CheckErr(err)
  134. t.Assert(exist, code.MSG_DATA_NOT_EXIST, "签到规则不存在")
  135. if signUp.SignMethod != 1 {
  136. t.ERROR("非扫码签到", code.MSG_ERR_Param)
  137. return
  138. }
  139. if signUp.OnlyInvitation == 1 && _type == 0 { // 直播不需要进行邀请函
  140. // 邀请函才能签到
  141. letter := new(models.InvitationLetter)
  142. exist, err := letter.GetByUserIdAndActivityId(uid, activity.Id, activity.ArchId, activity.RehearsalId)
  143. t.CheckErr(err)
  144. t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您没收到邀请函")
  145. }
  146. //检查是否已经签到了
  147. history := new(models.SignHistory)
  148. exist, err = history.GetByUserId(activity.Id, activity.ArchId, uid, activity.RehearsalId, area.Id)
  149. t.CheckErr(err)
  150. if exist || history.Status == 2 {
  151. t.ERROR("您已经签到过了", code.MSG_SIGN_HISTORY_EXIST)
  152. }
  153. // 签到人数
  154. signTotal, err := history.Count(activity.Id, activity.ArchId, activity.RehearsalId, 2)
  155. t.CheckErr(err)
  156. signUpTotal, err := new(models.InvitationLetter).Count(activity.Id, activity.ArchId, activity.RehearsalId)
  157. t.CheckErr(err)
  158. if activity.RehearsalId != 0 && signTotal >= 10 {
  159. t.ERROR("彩排人数不能超过10人", code.MSG_SIGN_UP_REHEARSAL_LIMIT)
  160. }
  161. history = new(models.SignHistory)
  162. history.UserId = uid
  163. history.RehearsalId = activity.RehearsalId
  164. history.ActivityId = activityId
  165. history.SignRuleId = signUp.Id
  166. history.AreaId = areaId
  167. history.ArchId = activity.ArchId
  168. history.Status = 2
  169. _, err = models.Add(history)
  170. t.CheckErr(err)
  171. go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
  172. define.TYPE_CUSTOMER, activity.CustomerId, map[string]interface{}{
  173. "type": "sign_up",
  174. "customer_id": area.CustomerId,
  175. "data": map[string]interface{}{
  176. "avatar": user.Avatar,
  177. "sign_total": signTotal + 1,
  178. "sign_up_total": signUpTotal,
  179. },
  180. })
  181. t.SUCCESS("签到成功")
  182. }
  183. // 实名签到
  184. func (t *SignCtl) RealSign() {
  185. activityId := t.MustGetInt("activity_id")
  186. userId := t.GetAccountId()
  187. areaId := t.MustGetInt("area_id")
  188. user := new(models.User)
  189. exist, err := models.Get(user, userId)
  190. t.CheckErr(err)
  191. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  192. activity := new(models.Activity)
  193. exist, err = models.Get(activity, activityId)
  194. t.CheckErr(err)
  195. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  196. sign := new(models.SignUp)
  197. exist, err = sign.GetByActivityId(activityId)
  198. t.CheckErr(err)
  199. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
  200. t.Assert(sign.SignMethod == 2, code.MSG_ERR_Param, "非实名签到")
  201. history := new(models.SignHistory)
  202. isSign, err := history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  203. t.CheckErr(err)
  204. if isSign && history.Status == 2 {
  205. t.SUCCESS("已通过实名签到")
  206. return
  207. } else if sign.RealSignJsonForm != nil && len(sign.RealSignJsonForm) != 0 {
  208. var params = make(map[string]string, 0)
  209. var extSql string
  210. for _, v := range sign.RealSignJsonForm {
  211. m, ok := v.(map[string]interface{})
  212. if !ok {
  213. continue
  214. }
  215. name, _ := m["name"].(string)
  216. val, _ := m["val"].(string)
  217. if value, ok := t.Get(name); ok {
  218. params[val] = value
  219. //extSql += " json_list like '%\"" + val + "\"" + ":" + "\"" + value + "\"%' and "
  220. extSql += " json_list like '%" + value + "%' and "
  221. } else {
  222. t.ERROR(fmt.Sprintf("%s不能为空", val), code.MSG_ERR_Param)
  223. }
  224. }
  225. if len(extSql) == 0 || len(params) == 0 {
  226. t.ERROR("提交内容不能为空", code.MSG_ERR_Param)
  227. return
  228. }
  229. realSignList := new(models.RealSignList)
  230. exist, err = realSignList.CheckSignIn(activityId, extSql)
  231. t.CheckErr(err)
  232. if exist {
  233. existRsi, err := models.ExistReviewedSignInfo(activity.Id, activity.ArchId,
  234. activity.RehearsalId, realSignList.Id)
  235. t.CheckErr(err)
  236. if existRsi {
  237. t.ERROR("实名签到名单已被认证", code.MSG_SIGN_REAL_NOT_EXIST)
  238. return
  239. }
  240. }
  241. var body []byte
  242. body, err = json.Marshal(params)
  243. t.CheckErr(err)
  244. history.SignRuleId = sign.Id
  245. history.SignMethod = 2
  246. history.ActivityId = activityId
  247. history.UserId = userId
  248. history.Nickname = user.Nickname
  249. history.ArchId = activity.ArchId
  250. history.RehearsalId = activity.RehearsalId
  251. history.AreaId = areaId
  252. history.Content = string(body)
  253. history.RealSignListId = realSignList.Id
  254. if exist { // 存在 直接通过
  255. history.Status = 2
  256. } else {
  257. history.Status = 0
  258. }
  259. if isSign {
  260. _, err = models.Update(history.Id, history)
  261. } else {
  262. _, err = models.Add(history)
  263. }
  264. t.CheckErr(err)
  265. if !exist { // 找不到导入的签名信息
  266. t.ERROR("您的信息不在名单之内", code.MSG_ERR)
  267. return
  268. }
  269. t.SUCCESS("实名签到成功")
  270. return
  271. } else {
  272. t.ERROR("实名签到活动未上传名单", code.MSG_SIGN_REAL_NOT_EXIST)
  273. return
  274. }
  275. }
  276. func (t *SignCtl) ApplySign() {
  277. userId := t.GetAccountId()
  278. areaId := t.MustGetInt("area_id")
  279. activityId := t.MustGetInt("activity_id")
  280. activity := new(models.Activity)
  281. exist, err := models.Get(activity, activityId)
  282. t.CheckErr(err)
  283. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  284. history := new(models.SignHistory)
  285. exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  286. t.CheckErr(err)
  287. t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到不存在")
  288. if history.Status == 2 {
  289. t.SUCCESS("你已经通过实名签到")
  290. return
  291. }
  292. history.Status = 1
  293. _, err = models.Update(history.Id, history, "status")
  294. t.CheckErr(err)
  295. t.SUCCESS("申请成功")
  296. }
  297. func (t *SignCtl) CheckRealSign() {
  298. userId := t.GetAccountId()
  299. areaId := t.MustGetInt("area_id")
  300. activityId := t.MustGetInt("activity_id")
  301. activity := new(models.Activity)
  302. exist, err := models.Get(activity, activityId)
  303. t.CheckErr(err)
  304. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  305. history := new(models.SignHistory)
  306. exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  307. t.CheckErr(err)
  308. t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到信息不存在")
  309. if history.Status == 2 {
  310. t.SUCCESS("签到成功")
  311. }
  312. t.ERROR("签到尚未审核", code.MSG_SIGN_HISTORY_NOT_EXIST)
  313. }