activity_signup_detail.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_cygx/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. type CygxActivitySignupDetailServreBill struct {
  66. Id int `orm:"column(id);pk"`
  67. ActivityId int `description:"活动ID"`
  68. ActivityName string `description:"活动名称"`
  69. UserId int `description:"用户ID"`
  70. RealName string `description:"用户实际名称"`
  71. Mobile string `description:"手机号"`
  72. Email string `description:"邮箱"`
  73. CompanyId int `description:"公司id"`
  74. CompanyName string `description:"公司名称"`
  75. ActivityTime string `description:"活动时间"`
  76. ActivityType int `description:"1线上,其余线下"`
  77. ChartPermissionId int `description:"行业id"`
  78. ChartPermissionName string `description:"行业名称"`
  79. }
  80. // 获取今天报名的用户信息,存入到参会记录表中
  81. func GetSignupDetailBySignupjoinactivity(condition string, pars []interface{}) (list []*CygxActivitySignupDetailServreBill, err error) {
  82. sql := `SELECT
  83. art.activity_id,
  84. art.user_id,
  85. art.real_name,
  86. art.mobile,
  87. art.email,
  88. art.company_id,
  89. art.company_name,
  90. a.activity_time,
  91. a.activity_name,
  92. a.chart_permission_id,
  93. a.chart_permission_name,
  94. t.activity_type
  95. FROM
  96. cygx_activity_signup_detail AS art
  97. INNER JOIN cygx_activity AS a ON a.activity_id = art.activity_id
  98. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = a.activity_type_id
  99. WHERE
  100. 1 = 1 `
  101. if condition != "" {
  102. sql += condition
  103. }
  104. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  105. return
  106. }
  107. // 获取参会记录表列表
  108. func GetSignupDetailList(condition string, pars []interface{}) (list []*CygxActivitySignupDetail, err error) {
  109. sql := `SELECT * FROM cygx_activity_signup_detail WHERE 1= 1 `
  110. if condition != "" {
  111. sql += condition
  112. }
  113. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  114. return
  115. }
  116. // 添加
  117. func AddCygxActivitySignupDetail(items []*CygxActivitySignupDetail) (err error) {
  118. o, err := orm.NewOrm().Begin()
  119. if err != nil {
  120. return
  121. }
  122. defer func() {
  123. if err == nil {
  124. o.Commit()
  125. } else {
  126. o.Rollback()
  127. }
  128. }()
  129. if len(items) > 0 {
  130. //批量添加
  131. _, err = o.InsertMulti(len(items), items)
  132. if err != nil {
  133. return err
  134. }
  135. }
  136. return
  137. }
  138. // UpdateActivitySignupDetailMulti 批量修改用户报名信息且报名的人
  139. func UpdateActivitySignupDetailMulti(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. duration = ?,
  145. meeting_type_str = ?,
  146. meeting_authentication = ?,
  147. meeting_status_str = ?,
  148. position = ?,
  149. is_meeting = ?,
  150. userid_entity = ?,
  151. activity_time = ?,
  152. crm_company_map_status_id = ?
  153. WHERE mobile = ? AND activity_id = ? `).Prepare()
  154. if err != nil {
  155. return
  156. }
  157. defer func() {
  158. _ = p.Close() // 别忘记关闭 statement
  159. }()
  160. for _, v := range items {
  161. _, err = p.Exec(
  162. v.FirstMeetingTime,
  163. v.LastMeetingTime,
  164. v.Duration,
  165. v.MeetingTypeStr,
  166. v.MeetingAuthentication,
  167. v.MeetingStatusStr,
  168. v.Position,
  169. v.IsMeeting,
  170. v.UseridEntity,
  171. v.ActivityTime,
  172. v.CrmCompanyMapStatusId,
  173. v.Mobile, v.ActivityId)
  174. if err != nil {
  175. return
  176. }
  177. }
  178. return
  179. }
  180. // UpdateActivitySignupDetailMultiByYiDong 易董批量修改用户报名信息且报名的人
  181. func UpdateActivitySignupDetailMultiByYiDong(items []*CygxActivitySignupDetail) (err error) {
  182. o := orm.NewOrm()
  183. p, err := o.Raw(` UPDATE cygx_activity_signup_detail SET
  184. first_meeting_time = ?,
  185. last_meeting_time = ?,
  186. meeting_status_str = ?,
  187. position = ?,
  188. real_name = ?,
  189. duration = ?,
  190. is_meeting = ?
  191. WHERE mobile = ? AND activity_id = ? `).Prepare()
  192. if err != nil {
  193. return
  194. }
  195. defer func() {
  196. _ = p.Close() // 别忘记关闭 statement
  197. }()
  198. for _, v := range items {
  199. _, err = p.Exec(
  200. v.FirstMeetingTime,
  201. v.LastMeetingTime,
  202. v.MeetingStatusStr,
  203. v.Position,
  204. v.RealName,
  205. v.Duration,
  206. v.IsMeeting,
  207. v.Mobile, v.ActivityId)
  208. if err != nil {
  209. return
  210. }
  211. }
  212. return
  213. }
  214. // UpdateActivitySignupDetailMultiByYiDong 易董批量修改用户报名信息且报名的人
  215. func UpdateActivitySignupDetailMultiMobileAndUserId(items []*CygxActivitySignupDetail) (err error) {
  216. o := orm.NewOrm()
  217. p, err := o.Raw(` UPDATE cygx_activity_signup_detail SET
  218. user_id = ?
  219. WHERE mobile = ? AND user_id = 0 `).Prepare()
  220. if err != nil {
  221. return
  222. }
  223. defer func() {
  224. _ = p.Close() // 别忘记关闭 statement
  225. }()
  226. for _, v := range items {
  227. fmt.Println(v.Mobile)
  228. _, err = p.Exec(
  229. v.UserId,
  230. v.Mobile)
  231. if err != nil {
  232. return
  233. }
  234. }
  235. return
  236. }
  237. // UpdateActivitySignupDetailMulti 批量修改用户报名信息且报名的人
  238. func UpdateActivitySignupDetailMultiUserId(items []*CygxActivitySignupDetail) (err error) {
  239. o := orm.NewOrm()
  240. p, err := o.Raw(` UPDATE cygx_activity_signup_detail SET
  241. user_id = ?
  242. WHERE mobile = ? `).Prepare()
  243. if err != nil {
  244. return
  245. }
  246. defer func() {
  247. _ = p.Close() // 别忘记关闭 statement
  248. }()
  249. for _, v := range items {
  250. _, err = p.Exec(
  251. v.UserId,
  252. v.Mobile)
  253. if err != nil {
  254. return
  255. }
  256. }
  257. return
  258. }