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

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