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

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