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

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