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

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