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

345 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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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. service := new(models.ModuleService)
  83. exist, err := service.GetByName(define.MODULE_SIGNIN)
  84. t.CheckErr(err)
  85. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
  86. historyIds, err := models.GetModuleServiceHistoryIdsByIdAndName(service.Id, service.Name)
  87. t.CheckErr(err)
  88. module := new(models.ActivityModuleService)
  89. exist, err = module.GetByActivityIdAndHistoryIds(activityId, historyIds)
  90. t.CheckErr(err)
  91. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
  92. phoneBg := ""
  93. if module.PhoneBgSwitch == define.StatusOpen {
  94. phoneBg = module.PhoneBgUrl
  95. }
  96. sign := new(models.SignUp)
  97. exist, err = sign.GetByActivityId(activityId)
  98. t.JSON(map[string]interface{}{
  99. "phone_bg": phoneBg,
  100. "setting": sign,
  101. })
  102. }
  103. //签到动作
  104. func (t *SignCtl) Sign() {
  105. uid := t.GetAccountId()
  106. activityId := t.MustGetInt("activity_id")
  107. _type := t.DefaultInt("type", 0) // 默认 0
  108. areaId := t.MustGetInt("area_id")
  109. //根据activity_id查找主活动的信息
  110. activity := new(models.Activity)
  111. exist, err := models.Get(activity, activityId)
  112. t.CheckErr(err)
  113. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  114. area := new(models.AreaStore)
  115. exist, err = models.Get(area, areaId)
  116. t.CheckErr(err)
  117. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  118. user := new(models.User)
  119. exist, err = models.Get(user, uid)
  120. t.CheckErr(err)
  121. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  122. //根据activity_id查找副活动的规则信息
  123. signUp := new(models.SignUp)
  124. exist, err = signUp.GetByActivityId(activityId)
  125. t.CheckErr(err)
  126. t.Assert(exist, code.MSG_DATA_NOT_EXIST, "签到规则不存在")
  127. if signUp.SignMethod != 1 {
  128. t.ERROR("非扫码签到", code.MSG_ERR_Param)
  129. return
  130. }
  131. if signUp.OnlyInvitation == 1 && _type == 0 { // 直播不需要进行邀请函
  132. // 邀请函才能签到
  133. letter := new(models.InvitationLetter)
  134. exist, err := letter.GetByUserIdAndActivityId(uid, activity.Id, activity.ArchId, activity.RehearsalId)
  135. t.CheckErr(err)
  136. t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您没收到邀请函")
  137. }
  138. //检查是否已经签到了
  139. history := new(models.SignHistory)
  140. exist, err = history.GetByUserId(activity.Id, activity.ArchId, uid, activity.RehearsalId, area.Id)
  141. t.CheckErr(err)
  142. if exist || history.Status == 2 {
  143. t.ERROR("您已经签到过了", code.MSG_SIGN_HISTORY_EXIST)
  144. }
  145. // 签到人数
  146. signTotal, err := history.Count(activity.Id, activity.ArchId, activity.RehearsalId, 2)
  147. t.CheckErr(err)
  148. signUpTotal, err := new(models.InvitationLetter).Count(activity.Id, activity.ArchId, activity.RehearsalId)
  149. t.CheckErr(err)
  150. if activity.RehearsalId != 0 && signTotal >= 10 {
  151. t.ERROR("彩排人数不能超过10人", code.MSG_SIGN_UP_REHEARSAL_LIMIT)
  152. }
  153. history = new(models.SignHistory)
  154. history.UserId = uid
  155. history.RehearsalId = activity.RehearsalId
  156. history.ActivityId = activityId
  157. history.SignRuleId = signUp.Id
  158. history.AreaId = areaId
  159. history.ArchId = activity.ArchId
  160. history.Status = 2
  161. _, err = models.Add(history)
  162. t.CheckErr(err)
  163. go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
  164. define.TYPE_CUSTOMER, activity.CustomerId, map[string]interface{}{
  165. "type": "sign_up",
  166. "customer_id": area.CustomerId,
  167. "data": map[string]interface{}{
  168. "avatar": user.Avatar,
  169. "sign_total": signTotal + 1,
  170. "sign_up_total": signUpTotal,
  171. },
  172. })
  173. t.SUCCESS("签到成功")
  174. }
  175. // 实名签到
  176. func (t *SignCtl) RealSign() {
  177. activityId := t.MustGetInt("activity_id")
  178. userId := t.GetAccountId()
  179. areaId := t.MustGetInt("area_id")
  180. user := new(models.User)
  181. exist, err := models.Get(user, userId)
  182. t.CheckErr(err)
  183. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  184. activity := new(models.Activity)
  185. exist, err = models.Get(activity, activityId)
  186. t.CheckErr(err)
  187. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  188. sign := new(models.SignUp)
  189. exist, err = sign.GetByActivityId(activityId)
  190. t.CheckErr(err)
  191. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
  192. t.Assert(sign.SignMethod == 2, code.MSG_ERR_Param, "非实名签到")
  193. history := new(models.SignHistory)
  194. isSign, err := history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  195. t.CheckErr(err)
  196. if isSign && history.Status == 2 {
  197. t.SUCCESS("已通过实名签到")
  198. return
  199. } else if sign.RealSignJsonForm != nil && len(sign.RealSignJsonForm) != 0 {
  200. var params = make(map[string]string, 0)
  201. var extSql string
  202. for _, v := range sign.RealSignJsonForm {
  203. m, ok := v.(map[string]interface{})
  204. if !ok {
  205. continue
  206. }
  207. name, _ := m["name"].(string)
  208. val, _ := m["val"].(string)
  209. if value, ok := t.Get(name); ok {
  210. params[val] = value
  211. //extSql += " json_list like '%\"" + val + "\"" + ":" + "\"" + value + "\"%' and "
  212. extSql += " json_list like '%" + value + "%' and "
  213. } else {
  214. t.ERROR(fmt.Sprintf("%s不能为空", val), code.MSG_ERR_Param)
  215. }
  216. }
  217. if len(extSql) == 0 || len(params) == 0 {
  218. t.ERROR("提交内容不能为空", code.MSG_ERR_Param)
  219. return
  220. }
  221. realSignList := new(models.RealSignList)
  222. exist, err = realSignList.CheckSignIn(activityId, extSql)
  223. t.CheckErr(err)
  224. if exist {
  225. existRsi, err := models.ExistReviewedSignInfo(activity.Id, activity.ArchId,
  226. activity.RehearsalId, realSignList.Id)
  227. t.CheckErr(err)
  228. if existRsi {
  229. t.ERROR("实名签到名单已被认证", code.MSG_SIGN_REAL_NOT_EXIST)
  230. return
  231. }
  232. }
  233. var body []byte
  234. body, err = json.Marshal(params)
  235. t.CheckErr(err)
  236. history.SignRuleId = sign.Id
  237. history.SignMethod = 2
  238. history.ActivityId = activityId
  239. history.UserId = userId
  240. history.Nickname = user.Nickname
  241. history.ArchId = activity.ArchId
  242. history.RehearsalId = activity.RehearsalId
  243. history.AreaId = areaId
  244. history.Content = string(body)
  245. history.RealSignListId = realSignList.Id
  246. if exist { // 存在 直接通过
  247. history.Status = 2
  248. } else {
  249. history.Status = 0
  250. }
  251. if isSign {
  252. _, err = models.Update(history.Id, history)
  253. } else {
  254. _, err = models.Add(history)
  255. }
  256. t.CheckErr(err)
  257. if !exist { // 找不到导入的签名信息
  258. t.ERROR("您的信息不在名单之内", code.MSG_ERR)
  259. return
  260. }
  261. t.SUCCESS("实名签到成功")
  262. return
  263. } else {
  264. t.ERROR("实名签到活动未上传名单", code.MSG_SIGN_REAL_NOT_EXIST)
  265. return
  266. }
  267. }
  268. func (t *SignCtl) ApplySign() {
  269. userId := t.GetAccountId()
  270. areaId := t.MustGetInt("area_id")
  271. activityId := t.MustGetInt("activity_id")
  272. activity := new(models.Activity)
  273. exist, err := models.Get(activity, activityId)
  274. t.CheckErr(err)
  275. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  276. history := new(models.SignHistory)
  277. exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  278. t.CheckErr(err)
  279. t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到不存在")
  280. if history.Status == 2 {
  281. t.SUCCESS("你已经通过实名签到")
  282. return
  283. }
  284. history.Status = 1
  285. _, err = models.Update(history.Id, history, "status")
  286. t.CheckErr(err)
  287. t.SUCCESS("申请成功")
  288. }
  289. func (t *SignCtl) CheckRealSign() {
  290. userId := t.GetAccountId()
  291. areaId := t.MustGetInt("area_id")
  292. activityId := t.MustGetInt("activity_id")
  293. activity := new(models.Activity)
  294. exist, err := models.Get(activity, activityId)
  295. t.CheckErr(err)
  296. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  297. history := new(models.SignHistory)
  298. exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  299. t.CheckErr(err)
  300. t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到信息不存在")
  301. if history.Status == 2 {
  302. t.SUCCESS("签到成功")
  303. }
  304. t.ERROR("签到尚未审核", code.MSG_SIGN_HISTORY_NOT_EXIST)
  305. }