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

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