activity_signup_detail.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_mfyx/utils"
  6. "time"
  7. )
  8. type CygxActivitySignupDetail struct {
  9. Id int `orm:"column(id);pk"`
  10. ActivityId int `description:"活动ID"`
  11. UserId int `description:"用户ID"`
  12. CreateTime time.Time `description:"创建时间"`
  13. Mobile string `description:"手机号"`
  14. Email string `description:"邮箱"`
  15. CompanyId int `description:"公司id"`
  16. CompanyName string `description:"公司名称"`
  17. FailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  18. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  19. DoFailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  20. OutboundMobile string `description:"外呼手机号"`
  21. CountryCode string `description:"手机国家区号"`
  22. RealName string `description:"用户实际名称"`
  23. SellerName string `description:"所属销售"`
  24. FirstMeetingTime string `description:"首次入会时间"`
  25. LastMeetingTime string `description:"最后退出时间"`
  26. Duration string `description:"参会时长"`
  27. MeetingTypeStr string `description:"参会方式"`
  28. MeetingAuthentication string `description:"参会权鉴"`
  29. MeetingStatusStr string `description:"参会状态"`
  30. Position string `description:"职位"`
  31. IsMeeting int `description:"是否到会,1到会,0未到会"`
  32. UseridEntity int `description:"参会者身份. 1:主讲人, 2:主持人, 3:嘉宾, 4:普通参会者, 5:联席主讲人, 6:会议助理"`
  33. ActivityTime string `description:"活动时间"`
  34. CrmCompanyMapStatusId int `description:"转换后的对应状态信息:1=正式客户, 2=曾使用客户, 3=其他"`
  35. }
  36. // 获取当天已结束的活动
  37. func GetActivitySattusToComplete() (items []*CygxActivity, err error) {
  38. defer func() {
  39. if err != nil {
  40. go utils.SendAlarmMsg("修改活动状态至已结束"+err.Error(), 2)
  41. }
  42. }()
  43. o := orm.NewOrm()
  44. //resultTime_30 := time.Now().Add(-time.Minute * 30).Format(utils.FormatDateTime)
  45. //resultTime_60 := time.Now().Add(-time.Minute * 60).Format(utils.FormatDateTime)
  46. startTime := time.Now().Format(utils.FormatDate)
  47. var condition string
  48. condition += ` AND activity_time > '` + startTime + `'`
  49. //condition += ` AND (activity_type_id IN ( 1, 2, 3, 7 ) AND activity_time < '` + resultTime_30 + `')`
  50. //condition += ` OR(activity_type_id IN ( 4, 5, 6 ) AND activity_time < '` + resultTime_60 + `')`
  51. //condition += ` OR(activity_type_id IN ( 4, 5, 6 ) AND activity_time < '` + resultTime_60 + `' AND activity_time > '` + startTime + `')`
  52. sql := " SELECT * FROM cygx_activity WHERE 1 = 1 AND active_state = 3 " + condition
  53. _, err = o.Raw(sql).QueryRows(&items)
  54. return
  55. }
  56. // 获取今天报名的用户信息,存入到参会记录表中
  57. func GetSignupDetailBySignup(condition string, pars []interface{}) (list []*CygxActivitySignupDetail, err error) {
  58. sql := `SELECT * FROM cygx_activity_signup WHERE 1= 1 `
  59. if condition != "" {
  60. sql += condition
  61. }
  62. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  63. return
  64. }
  65. // 获取参会记录表列表
  66. func GetSignupDetailList(condition string, pars []interface{}) (list []*CygxActivitySignupDetail, err error) {
  67. sql := `SELECT * FROM cygx_activity_signup_detail WHERE 1= 1 `
  68. if condition != "" {
  69. sql += condition
  70. }
  71. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  72. return
  73. }
  74. // 添加
  75. func AddCygxActivitySignupDetail(items []*CygxActivitySignupDetail) (err error) {
  76. o, err := orm.NewOrm().Begin()
  77. if err != nil {
  78. return
  79. }
  80. defer func() {
  81. if err == nil {
  82. o.Commit()
  83. } else {
  84. o.Rollback()
  85. }
  86. }()
  87. if len(items) > 0 {
  88. //批量添加
  89. _, err = o.InsertMulti(len(items), items)
  90. if err != nil {
  91. return err
  92. }
  93. }
  94. return
  95. }
  96. // UpdateActivitySignupDetailMulti 批量修改用户报名信息且报名的人
  97. func UpdateActivitySignupDetailMulti(items []*CygxActivitySignupDetail) (err error) {
  98. o := orm.NewOrm()
  99. p, err := o.Raw(` UPDATE cygx_activity_signup_detail SET
  100. first_meeting_time = ?,
  101. last_meeting_time = ?,
  102. duration = ?,
  103. meeting_type_str = ?,
  104. meeting_authentication = ?,
  105. meeting_status_str = ?,
  106. position = ?,
  107. is_meeting = ?,
  108. userid_entity = ?,
  109. activity_time = ?,
  110. crm_company_map_status_id = ?
  111. WHERE mobile = ? AND activity_id = ? `).Prepare()
  112. if err != nil {
  113. return
  114. }
  115. defer func() {
  116. _ = p.Close() // 别忘记关闭 statement
  117. }()
  118. for _, v := range items {
  119. _, err = p.Exec(
  120. v.FirstMeetingTime,
  121. v.LastMeetingTime,
  122. v.Duration,
  123. v.MeetingTypeStr,
  124. v.MeetingAuthentication,
  125. v.MeetingStatusStr,
  126. v.Position,
  127. v.IsMeeting,
  128. v.UseridEntity,
  129. v.ActivityTime,
  130. v.CrmCompanyMapStatusId,
  131. v.Mobile, v.ActivityId)
  132. if err != nil {
  133. return
  134. }
  135. }
  136. return
  137. }
  138. // UpdateActivitySignupDetailMultiByYiDong 易董批量修改用户报名信息且报名的人
  139. func UpdateActivitySignupDetailMultiByYiDong(items []*CygxActivitySignupDetail) (err error) {
  140. o := orm.NewOrm()
  141. p, err := o.Raw(` UPDATE cygx_activity_signup_detail SET
  142. first_meeting_time = ?,
  143. last_meeting_time = ?,
  144. meeting_status_str = ?,
  145. position = ?,
  146. real_name = ?,
  147. duration = ?,
  148. is_meeting = ?
  149. WHERE mobile = ? AND activity_id = ? `).Prepare()
  150. if err != nil {
  151. return
  152. }
  153. defer func() {
  154. _ = p.Close() // 别忘记关闭 statement
  155. }()
  156. for _, v := range items {
  157. _, err = p.Exec(
  158. v.FirstMeetingTime,
  159. v.LastMeetingTime,
  160. v.MeetingStatusStr,
  161. v.Position,
  162. v.RealName,
  163. v.Duration,
  164. v.IsMeeting,
  165. v.Mobile, v.ActivityId)
  166. if err != nil {
  167. return
  168. }
  169. }
  170. return
  171. }
  172. // UpdateActivitySignupDetailMultiByYiDong 易董批量修改用户报名信息且报名的人
  173. func UpdateActivitySignupDetailMultiMobileAndUserId(items []*CygxActivitySignupDetail) (err error) {
  174. o := orm.NewOrm()
  175. p, err := o.Raw(` UPDATE cygx_activity_signup_detail SET
  176. user_id = ?
  177. WHERE mobile = ? AND user_id = 0 `).Prepare()
  178. if err != nil {
  179. return
  180. }
  181. defer func() {
  182. _ = p.Close() // 别忘记关闭 statement
  183. }()
  184. for _, v := range items {
  185. fmt.Println(v.Mobile)
  186. _, err = p.Exec(
  187. v.UserId,
  188. v.Mobile)
  189. if err != nil {
  190. return
  191. }
  192. }
  193. return
  194. }