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

342 lines
9.8 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
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 := 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(activity.Id, activity.ArchId, activity.RehearsalId, 2)
  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.UserId = uid
  152. history.RehearsalId = activity.RehearsalId
  153. history.ActivityId = activityId
  154. history.SignRuleId = signUp.Id
  155. history.AreaId = areaId
  156. history.ArchId = activity.ArchId
  157. history.Status = 2
  158. _, err = models.Add(history)
  159. t.CheckErr(err)
  160. go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
  161. define.TYPE_CUSTOMER, activity.CustomerId, map[string]interface{}{
  162. "type": "sign_up",
  163. "customer_id": area.CustomerId,
  164. "data": map[string]interface{}{
  165. "avatar": user.Avatar,
  166. "sign_total": signTotal + 1,
  167. "sign_up_total": signUpTotal,
  168. },
  169. })
  170. t.SUCCESS("签到成功")
  171. }
  172. // 实名签到
  173. func (t *SignCtl) RealSign() {
  174. activityId := t.MustGetInt("activity_id")
  175. userId := t.GetAccountId()
  176. areaId := t.MustGetInt("area_id")
  177. user := new(models.User)
  178. exist, err := models.Get(user, userId)
  179. t.CheckErr(err)
  180. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  181. activity := new(models.Activity)
  182. exist, err = models.Get(activity, activityId)
  183. t.CheckErr(err)
  184. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  185. sign := new(models.SignUp)
  186. exist, err = sign.GetByActivityId(activityId)
  187. t.CheckErr(err)
  188. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
  189. t.Assert(sign.SignMethod == 2, code.MSG_ERR_Param, "非实名签到")
  190. history := new(models.SignHistory)
  191. isSign, err := history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  192. t.CheckErr(err)
  193. if isSign && history.Status == 2 {
  194. t.SUCCESS("已通过实名签到")
  195. return
  196. } else if sign.RealSignJsonForm != nil && len(sign.RealSignJsonForm) != 0 {
  197. var params = make(map[string]string, 0)
  198. var extSql string
  199. for _, v := range sign.RealSignJsonForm {
  200. m, ok := v.(map[string]interface{})
  201. if !ok {
  202. continue
  203. }
  204. name, _ := m["name"].(string)
  205. val, _ := m["val"].(string)
  206. if value, ok := t.Get(name); ok {
  207. params[val] = value
  208. //extSql += " json_list like '%\"" + val + "\"" + ":" + "\"" + value + "\"%' and "
  209. extSql += " json_list like '%" + value + "%' and "
  210. } else {
  211. t.ERROR(fmt.Sprintf("%s不能为空", val), code.MSG_ERR_Param)
  212. }
  213. }
  214. if len(extSql) == 0 || len(params) == 0 {
  215. t.ERROR("提交内容不能为空", code.MSG_ERR_Param)
  216. return
  217. }
  218. realSignList := new(models.RealSignList)
  219. exist, err = realSignList.CheckSignIn(activityId, extSql)
  220. t.CheckErr(err)
  221. if exist {
  222. existRsi, err := models.ExistReviewedSignInfo(activity.Id, activity.ArchId,
  223. activity.RehearsalId, realSignList.Id)
  224. t.CheckErr(err)
  225. if existRsi {
  226. t.ERROR("实名签到名单已被认证", code.MSG_SIGN_REAL_NOT_EXIST)
  227. return
  228. }
  229. }
  230. var body []byte
  231. body, err = json.Marshal(params)
  232. t.CheckErr(err)
  233. history.SignRuleId = sign.Id
  234. history.SignMethod = 2
  235. history.ActivityId = activityId
  236. history.UserId = userId
  237. history.Nickname = user.Nickname
  238. history.ArchId = activity.ArchId
  239. history.RehearsalId = activity.RehearsalId
  240. history.AreaId = areaId
  241. history.Content = string(body)
  242. history.RealSignListId = realSignList.Id
  243. if exist { // 存在 直接通过
  244. history.Status = 2
  245. } else {
  246. history.Status = 0
  247. }
  248. if isSign {
  249. _, err = models.Update(history.Id, history)
  250. } else {
  251. _, err = models.Add(history)
  252. }
  253. t.CheckErr(err)
  254. if !exist { // 找不到导入的签名信息
  255. t.ERROR("您的信息不在名单之内", code.MSG_ERR)
  256. return
  257. }
  258. t.SUCCESS("实名签到成功")
  259. return
  260. } else {
  261. t.ERROR("实名签到活动未上传名单", code.MSG_SIGN_REAL_NOT_EXIST)
  262. return
  263. }
  264. }
  265. func (t *SignCtl) ApplySign() {
  266. userId := t.GetAccountId()
  267. areaId := t.MustGetInt("area_id")
  268. activityId := t.MustGetInt("activity_id")
  269. activity := new(models.Activity)
  270. exist, err := models.Get(activity, activityId)
  271. t.CheckErr(err)
  272. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  273. history := new(models.SignHistory)
  274. exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  275. t.CheckErr(err)
  276. t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到不存在")
  277. if history.Status == 2 {
  278. t.SUCCESS("你已经通过实名签到")
  279. return
  280. }
  281. history.Status = 1
  282. _, err = models.Update(history.Id, history, "status")
  283. t.CheckErr(err)
  284. t.SUCCESS("申请成功")
  285. }
  286. func (t *SignCtl) CheckRealSign() {
  287. userId := t.GetAccountId()
  288. areaId := t.MustGetInt("area_id")
  289. activityId := t.MustGetInt("activity_id")
  290. activity := new(models.Activity)
  291. exist, err := models.Get(activity, activityId)
  292. t.CheckErr(err)
  293. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  294. history := new(models.SignHistory)
  295. exist, err = history.GetByUserId(activityId, activity.ArchId, userId, activity.RehearsalId, areaId)
  296. t.CheckErr(err)
  297. t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到信息不存在")
  298. if history.Status == 2 {
  299. t.SUCCESS("签到成功")
  300. }
  301. t.ERROR("签到尚未审核", code.MSG_SIGN_HISTORY_NOT_EXIST)
  302. }