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

248 lines
7.4 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
  1. package client
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/ouxuanserver/osmanthuswine/src/core"
  6. "hudongzhuanjia/controllers"
  7. "hudongzhuanjia/logger"
  8. "hudongzhuanjia/models"
  9. ws_send_service "hudongzhuanjia/services/ws_send"
  10. "hudongzhuanjia/utils/code"
  11. "hudongzhuanjia/utils/define"
  12. "strings"
  13. "time"
  14. )
  15. //签到
  16. type SignCtl struct {
  17. controllers.AuthorCtl
  18. }
  19. func (t *SignCtl) CheckSign() {
  20. activityId := t.MustGetInt64("activity_id")
  21. uid := t.MustGetUID()
  22. live := new(models.LiveConfig)
  23. exist, err := live.GetByActivityId(activityId)
  24. t.CheckErr(err)
  25. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在")
  26. if live.AdaptationFunc != nil && len(live.AdaptationFunc) != 0 {
  27. exist, err = new(models.ModuleServiceHistory).ExistSignModule(live.AdaptationFunc)
  28. t.CheckErr(err)
  29. if !exist {
  30. t.JSON(!exist)
  31. }
  32. } else {
  33. t.JSON(true)
  34. }
  35. activity := models.Activity{}
  36. exist, err = models.Get(&activity, activityId)
  37. t.CheckErr(err)
  38. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "主活动不存在")
  39. customer := models.Customer{}
  40. exist, err = models.Get(&customer, activity.CustomerId)
  41. t.CheckErr(err)
  42. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  43. area := new(models.AreaStore)
  44. if customer.AreaId == 0 {
  45. exist, err = area.GetMainAreaById(activityId)
  46. } else {
  47. exist, err = area.GetAreaStoreById(customer.AreaId)
  48. }
  49. t.CheckErr(err)
  50. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  51. history := new(models.SignHistory)
  52. signExist, err := history.GetByUserId(activityId, uid, activity.RehearsalId, area.Id)
  53. t.CheckErr(err)
  54. t.JSON(signExist)
  55. }
  56. func (t *SignCtl) Setting() {
  57. activityId := t.MustGetInt64("activity_id")
  58. service := new(models.ModuleService)
  59. exist, err := service.GetByName(define.MODULE_SIGNIN)
  60. t.CheckErr(err)
  61. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
  62. histories := make([]*models.ModuleServiceHistory, 0)
  63. err = core.GetXormAuto().Where("is_delete=0 and service_module_id=? and name=?", service.Id, service.Name).Find(&histories)
  64. t.CheckErr(err)
  65. historyIds := make([]int64, 0)
  66. for _, history := range histories {
  67. historyIds = append(historyIds, history.Id)
  68. }
  69. module := new(models.ActivityModuleService)
  70. exist, err = core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).In("service_module_history_id", historyIds).Get(module)
  71. t.CheckErr(err)
  72. t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
  73. phoneBg := ""
  74. if module.PhoneBgSwitch == define.StatusOpen {
  75. phoneBg = module.PhoneBgUrl
  76. }
  77. t.JSON(map[string]interface{}{
  78. "phone_bg": phoneBg,
  79. })
  80. }
  81. //签到动作
  82. func (t *SignCtl) Sign() {
  83. uid := t.MustGetUID()
  84. activityId := t.MustGetInt64("activity_id")
  85. _type := t.DefaultInt("type", 0) // 默认 0
  86. areaId := t.MustGetAreaId()
  87. //根据activity_id查找主活动的信息
  88. activity := new(models.Activity)
  89. exist, err := models.Get(activity, activityId)
  90. t.CheckErr(err)
  91. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  92. area := new(models.AreaStore)
  93. exist, err = models.Get(area, areaId)
  94. t.CheckErr(err)
  95. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  96. user := new(models.User)
  97. exist, err = models.Get(user, uid)
  98. logger.Error("user:===>%+v", user)
  99. logger.Error("token:==>%v", t.MustGet("token"))
  100. logger.Error("user_id:===>%v", uid)
  101. t.CheckErr(err)
  102. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  103. //根据activity_id查找副活动的规则信息
  104. signUp := new(models.SignUp)
  105. exist, err = signUp.GetByActivityId(activityId)
  106. t.CheckErr(err)
  107. t.Assert(exist, code.MSG_DATA_NOT_EXIST, "签到规则不存在")
  108. if signUp.OnlyInvitation == 1 && _type == 0 { // 直播不需要进行邀请函
  109. // 邀请函才能签到
  110. letter := new(models.InvitationLetter)
  111. exist, err := letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
  112. t.CheckErr(err)
  113. t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您没收到邀请函")
  114. }
  115. //检查是否已经签到了
  116. signHistory := new(models.SignHistory)
  117. exist, err = signHistory.GetByUserId(activityId, uid, activity.RehearsalId, t.MustGetAreaId())
  118. t.CheckErr(err)
  119. t.Assert(!exist, code.MSG_SIGN_HISTORY_EXIST, "您已经签到过了") // 存在判断
  120. // 签到人数
  121. signTotal, err := core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?",
  122. signUp.Id, activity.RehearsalId, activity.Id).Count(signHistory)
  123. t.CheckErr(err)
  124. signUpTotal, err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activity.Id).Count(new(models.InvitationLetter))
  125. t.CheckErr(err)
  126. if activity.RehearsalId != 0 && signTotal >= 10 {
  127. t.ERROR("彩排人数不能超过10人", code.MSG_SIGN_UP_REHEARSAL_LIMIT)
  128. }
  129. signHistory = new(models.SignHistory)
  130. signHistory.Type = _type
  131. signHistory.UserId = uid
  132. signHistory.RehearsalId = activity.RehearsalId
  133. signHistory.ActivityId = activityId
  134. signHistory.SignRuleId = signUp.Id
  135. signHistory.AreaId = areaId
  136. signHistory.IsDelete = false
  137. signHistory.UpdatedAt = time.Now()
  138. signHistory.CreatedAt = time.Now()
  139. _, err = core.GetXormAuto().InsertOne(signHistory)
  140. t.CheckErr(err)
  141. go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
  142. define.TYPE_CUSTOMER, activity.CustomerId, map[string]interface{}{
  143. "type": "sign_up",
  144. "customer_id": area.CustomerId,
  145. "data": map[string]interface{}{
  146. "avatar": user.Avatar,
  147. "sign_total": signTotal + 1,
  148. "sign_up_total": signUpTotal,
  149. },
  150. })
  151. t.SUCCESS("签到成功")
  152. }
  153. func (t *SignCtl) RealSign() {
  154. aid := t.MustGetInt64("activity_id")
  155. uid := t.MustGetInt64("user_id")
  156. rid := t.MustGetInt64("rehearsal_id")
  157. user := new(models.User)
  158. exist, err := user.GetById(uid)
  159. t.CheckErr(err)
  160. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  161. sign := new(models.SignUp)
  162. exist, err = sign.GetByActivityId(aid)
  163. t.CheckErr(err)
  164. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
  165. history := new(models.RealSignHistory)
  166. isSign, err := history.Info(uid, aid, rid)
  167. t.CheckErr(err)
  168. if isSign && history.Status == 1 {
  169. t.SUCCESS("已通过实名签到")
  170. return
  171. } else if sign.RealSignJsonForm != "" && sign.RealSignJsonForm != "[]" {
  172. form := sign.RealSignJsonForm[1 : len(sign.RealSignJsonForm)-1]
  173. var extSql = ""
  174. var params = make(map[string]string, 0)
  175. for _, v := range strings.Split(form, ",") {
  176. name := strings.Trim(v, "\"")
  177. if value, ok := t.Get(name); ok {
  178. extSql += "and json_list like \"%" + value + "%\" "
  179. params[name] = value
  180. }
  181. }
  182. if len(extSql) > 0 {
  183. exist, err = new(models.RealSignList).CheckSignIn(aid, extSql)
  184. var body []byte
  185. body, err = json.Marshal(params)
  186. t.CheckErr(err)
  187. history.ActivityId = aid
  188. history.UserId = uid
  189. history.Nickname = user.Nickname
  190. history.RehearsalId = rid
  191. history.Content = string(body)
  192. if exist { // 存在 直接通过
  193. history.Status = 1
  194. } else {
  195. history.Status = 0
  196. }
  197. history.IsDelete = 0
  198. history.CreatedAt = time.Now()
  199. history.UpdatedAt = time.Now()
  200. if isSign {
  201. err = history.UpdateById([]interface{}{history.Id})
  202. } else {
  203. err = history.Insert()
  204. }
  205. t.CheckErr(err)
  206. if !exist { // 找不到导入的签名信息
  207. t.ERROR("您的信息不在名单之内", code.MSG_ERR)
  208. return
  209. }
  210. } else {
  211. t.ERROR("填写内容不能为空", code.MSG_ERR)
  212. return
  213. }
  214. t.SUCCESS("实名签到成功")
  215. return
  216. } else {
  217. t.ERROR("实名签到活动不存在", code.MSG_SIGN_REAL_NOT_EXIST)
  218. return
  219. }
  220. }