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