activity_signup.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CygxActivitySignup struct {
  8. Id int `orm:"column(id);pk"`
  9. ActivityId int `description:"活动ID"`
  10. UserId int `description:"用户ID"`
  11. CreateTime time.Time `description:"创建时间"`
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱"`
  14. CompanyId int `description:"公司id"`
  15. CompanyName string `description:"公司名称"`
  16. FailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  17. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  18. DoFailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  19. OutboundMobile string `description:"外呼手机号"`
  20. CountryCode string `description:"手机国家区号"`
  21. RealName string `description:"用户实际名称"`
  22. SellerName string `description:"所属销售"`
  23. }
  24. type SignupStatus struct {
  25. SignupStatus string `description:"返回状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  26. GoFollow bool `description:"是否去关注"`
  27. SignupType int `description:"报名方式,1预约外呼,2我要报名"`
  28. ActivityId int `description:"活动ID"`
  29. HaqveJurisdiction bool `description:"是否有权限"`
  30. OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  31. HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  32. PopupMsg string `description:"权限弹窗信息"`
  33. SellerMobile string `description:"销售电话"`
  34. MsgType string `description:"Type : 类型 , Industry : 行业"`
  35. SellerName string `description:"销售姓名"`
  36. Mobile string `description:"外呼手机号"`
  37. CountryCode string `description:"外呼手机号区号"`
  38. GoOutboundMobile bool `description:"是否去绑定手机号"`
  39. GoBindEmail bool `description:"是否去绑定邮箱"`
  40. IsResearch bool `description:"是否属于研选"`
  41. IsResearchSpecial bool `description:"是否属于特殊的研选"`
  42. ActivityTypeName string `description:"活动类型名称"`
  43. ActivityTime string `description:"活动时间"`
  44. ActivityType int `description:"活动线上线下类型 1线上,0 线下"`
  45. }
  46. // 我的日程
  47. type CygxMySchedule struct {
  48. Id int `orm:"column(id);pk"`
  49. ActivityId int `description:"活动ID"`
  50. UserId int `description:"用户ID"`
  51. CreateTime time.Time `description:"创建时间"`
  52. Mobile string `description:"手机号"`
  53. Email string `description:"邮箱"`
  54. CompanyId int `description:"公司id"`
  55. CompanyName string `description:"公司名称"`
  56. }
  57. // 报名记录日志
  58. type CygxActivitySignupLog struct {
  59. Id int `orm:"column(id);pk"`
  60. ActivityId int `description:"活动ID"`
  61. UserId int `description:"用户ID"`
  62. CreateTime time.Time `description:"创建时间"`
  63. Mobile string `description:"手机号"`
  64. Email string `description:"邮箱"`
  65. CompanyId int `description:"公司id"`
  66. CompanyName string `description:"公司名称"`
  67. Type int `description:"操作方式,1报名,2取消报名"`
  68. }
  69. // 添加报名信息
  70. func AddActivitySignup(item *CygxActivitySignup) (lastId int64, err error) {
  71. o, err := orm.NewOrm().Begin()
  72. if err != nil {
  73. return
  74. }
  75. defer func() {
  76. fmt.Println(err)
  77. if err == nil {
  78. o.Commit()
  79. } else {
  80. o.Rollback()
  81. }
  82. }()
  83. var count int
  84. var countMySchedule int
  85. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  86. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
  87. if err != nil {
  88. return
  89. }
  90. if countMySchedule == 0 {
  91. itemMy := new(CygxMySchedule)
  92. itemMy.UserId = item.UserId
  93. itemMy.ActivityId = item.ActivityId
  94. itemMy.CreateTime = time.Now()
  95. itemMy.Mobile = item.Mobile
  96. itemMy.Email = item.Email
  97. itemMy.CompanyId = item.CompanyId
  98. itemMy.CompanyName = item.CompanyName
  99. lastId, err = o.Insert(itemMy)
  100. if err != nil {
  101. return
  102. }
  103. }
  104. sql = `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
  105. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  106. if err != nil {
  107. return
  108. }
  109. if count > 0 {
  110. sql := `UPDATE cygx_activity_signup SET is_cancel = 0 ,do_fail_type = 0, signup_type=? WHERE user_id=? AND activity_id=? `
  111. _, err = o.Raw(sql, item.SignupType, item.UserId, item.ActivityId).Exec()
  112. } else {
  113. lastId, err = o.Insert(item)
  114. }
  115. if err != nil {
  116. return
  117. }
  118. itemLog := new(CygxActivitySignupLog)
  119. itemLog.UserId = item.UserId
  120. itemLog.ActivityId = item.ActivityId
  121. itemLog.CreateTime = time.Now()
  122. itemLog.Mobile = item.Mobile
  123. itemLog.Email = item.Email
  124. itemLog.CompanyId = item.CompanyId
  125. itemLog.CompanyName = item.CompanyName
  126. itemLog.Type = 1
  127. lastId, err = o.Insert(itemLog)
  128. return
  129. }
  130. // 仅绑定邮箱的用户修改报名后,添加报名信息
  131. func AddActivitySignupFromEmail(item *CygxActivitySignup) (lastId int64, err error) {
  132. o, err := orm.NewOrm().Begin()
  133. if err != nil {
  134. return
  135. }
  136. defer func() {
  137. fmt.Println(err)
  138. if err == nil {
  139. o.Commit()
  140. } else {
  141. o.Rollback()
  142. }
  143. }()
  144. var count int
  145. var countMySchedule int
  146. ow := orm.NewOrmUsingDB("weekly_report")
  147. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? ,is_msg_outbound_mobile = 1 WHERE user_id=? `
  148. _, err = ow.Raw(sql, item.OutboundMobile, item.CountryCode, item.UserId).Exec()
  149. if err != nil {
  150. return
  151. }
  152. sql = `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  153. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
  154. if err != nil {
  155. return
  156. }
  157. if countMySchedule == 0 {
  158. itemMy := new(CygxMySchedule)
  159. itemMy.UserId = item.UserId
  160. itemMy.ActivityId = item.ActivityId
  161. itemMy.CreateTime = time.Now()
  162. itemMy.Mobile = item.Mobile
  163. itemMy.Email = item.Email
  164. itemMy.CompanyId = item.CompanyId
  165. itemMy.CompanyName = item.CompanyName
  166. lastId, err = o.Insert(itemMy)
  167. if err != nil {
  168. return
  169. }
  170. }
  171. sql = `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
  172. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  173. if err != nil {
  174. return
  175. }
  176. if count > 0 {
  177. sql := `UPDATE cygx_activity_signup SET is_cancel = 0 ,do_fail_type = 0, signup_type=? WHERE user_id=? AND activity_id=? `
  178. _, err = o.Raw(sql, item.SignupType, item.UserId, item.ActivityId).Exec()
  179. } else {
  180. lastId, err = o.Insert(item)
  181. }
  182. if err != nil {
  183. return
  184. }
  185. itemLog := new(CygxActivitySignupLog)
  186. itemLog.UserId = item.UserId
  187. itemLog.ActivityId = item.ActivityId
  188. itemLog.CreateTime = time.Now()
  189. itemLog.Mobile = item.Mobile
  190. itemLog.Email = item.Email
  191. itemLog.CompanyId = item.CompanyId
  192. itemLog.CompanyName = item.CompanyName
  193. itemLog.Type = 1
  194. lastId, err = o.Insert(itemLog)
  195. return
  196. }
  197. // 添加报名信息
  198. func AddActivitySignupNoSchedule(item *CygxActivitySignup) (lastId int64, err error) {
  199. o, err := orm.NewOrm().Begin()
  200. if err != nil {
  201. return
  202. }
  203. defer func() {
  204. fmt.Println(err)
  205. if err == nil {
  206. o.Commit()
  207. } else {
  208. o.Rollback()
  209. }
  210. }()
  211. lastId, err = o.Insert(item)
  212. if err != nil {
  213. return
  214. }
  215. itemLog := new(CygxActivitySignupLog)
  216. itemLog.UserId = item.UserId
  217. itemLog.ActivityId = item.ActivityId
  218. itemLog.CreateTime = time.Now()
  219. itemLog.Mobile = item.Mobile
  220. itemLog.Email = item.Email
  221. itemLog.CompanyId = item.CompanyId
  222. itemLog.CompanyName = item.CompanyName
  223. itemLog.Type = 1
  224. lastId, err = o.Insert(itemLog)
  225. return
  226. }
  227. // 获取用户报名成功数量
  228. func GetActivitySignupCount(uid, activityId int) (count int, err error) {
  229. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel=0 AND do_fail_type = 0 AND user_id=? AND activity_id=? `
  230. o := orm.NewOrm()
  231. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  232. return
  233. }
  234. // 获取用户报名数量
  235. func GetActivitySignupByUserCount(uid, activityId int) (count int, err error) {
  236. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel=0 AND user_id=? AND activity_id=? `
  237. o := orm.NewOrm()
  238. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  239. return
  240. }
  241. // 获取除弘则以外所有成功报名的用户数量
  242. func GetActivitySignupSuccessByUserCountNoHz(activityId int) (count int, err error) {
  243. sqlCount := `SELECT
  244. COUNT( 1 ) AS count
  245. FROM
  246. cygx_activity_signup
  247. WHERE
  248. is_cancel = 0
  249. AND company_id != 16
  250. AND do_fail_type = 0
  251. AND activity_id = ? `
  252. o := orm.NewOrm()
  253. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  254. return
  255. }
  256. // 获取用户报名禁止数量
  257. func GetActivitySignupByUserRestrictCount(uid, activityId int) (count int, err error) {
  258. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE do_fail_type=3 AND user_id=? AND activity_id=? `
  259. o := orm.NewOrm()
  260. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  261. return
  262. }
  263. // 获取某一活动已经报名的数量
  264. func GetActivitySignupSuccessCount(activityId int) (count int, err error) {
  265. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel=0 AND do_fail_type = 0 AND activity_id=? `
  266. o := orm.NewOrm()
  267. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  268. return
  269. }
  270. // 获取某一活动某个机构已经报名的数量
  271. func GetActivitySignupCompanyCount(activityId, companyId int) (count int, err error) {
  272. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel=0 AND fail_type = 0 AND activity_id=? AND company_id=? `
  273. o := orm.NewOrm()
  274. err = o.Raw(sqlCount, activityId, companyId).QueryRow(&count)
  275. return
  276. }
  277. // 获取某一用户是否被限制报名
  278. func GetUserRestrictCount(mobile string) (count int, err error) {
  279. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_restrict_signup WHERE is_restrict=1 AND mobile=? `
  280. o := orm.NewOrm()
  281. err = o.Raw(sqlCount, mobile).QueryRow(&count)
  282. return
  283. }
  284. // 获取某一用户的日程数量
  285. func GetUserMeetingReminderCount(uid int) (count int, err error) {
  286. sqlCount := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? `
  287. o := orm.NewOrm()
  288. err = o.Raw(sqlCount, uid).QueryRow(&count)
  289. return
  290. }
  291. // 获取某一用户的报名的数量
  292. func GetUserSignupCount(uid int) (count int, err error) {
  293. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup_log WHERE user_id=? `
  294. o := orm.NewOrm()
  295. err = o.Raw(sqlCount, uid).QueryRow(&count)
  296. return
  297. }
  298. // 取消报名
  299. func CancelActivitySignup(item *CygxActivitySignup) (lastId int64, err error) {
  300. o, err := orm.NewOrm().Begin()
  301. if err != nil {
  302. return
  303. }
  304. defer func() {
  305. fmt.Println(err)
  306. if err == nil {
  307. o.Commit()
  308. } else {
  309. o.Rollback()
  310. }
  311. }()
  312. //判断是否删除我的日程
  313. var countReminder int
  314. var countAppointment int
  315. sql := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
  316. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countReminder)
  317. sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  318. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countAppointment)
  319. if err != nil {
  320. return
  321. }
  322. if countReminder == 0 && countAppointment == 0 {
  323. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  324. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  325. if err != nil {
  326. return
  327. }
  328. }
  329. sql = `DELETE FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
  330. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  331. if err != nil {
  332. return
  333. }
  334. itemLog := new(CygxActivitySignupLog)
  335. itemLog.UserId = item.UserId
  336. itemLog.ActivityId = item.ActivityId
  337. itemLog.CreateTime = time.Now()
  338. itemLog.Mobile = item.Mobile
  339. itemLog.Email = item.Email
  340. itemLog.CompanyId = item.CompanyId
  341. itemLog.CompanyName = item.CompanyName
  342. itemLog.Type = 2
  343. lastId, err = o.Insert(itemLog)
  344. return
  345. }
  346. // 详情
  347. func GetActivitySignupDetail(activityId, uid int) (item *CygxActivitySignup, err error) {
  348. o := orm.NewOrm()
  349. sql := `SELECT * FROM cygx_activity_signup WHERE activity_id = ? AND user_id =? `
  350. err = o.Raw(sql, activityId, uid).QueryRow(&item)
  351. return
  352. }
  353. func GetActivitySignuListByUser(condition string, pars []interface{}) (item []*CygxActivitySignup, err error) {
  354. o := orm.NewOrm()
  355. sql := `SELECT *
  356. FROM
  357. cygx_activity_signup
  358. WHERE 1 = 1 ` + condition
  359. _, err = o.Raw(sql, pars).QueryRows(&item)
  360. return
  361. }
  362. // 解除报名限制之后二次报名
  363. func AddActivitySignupByRestrict(item *CygxActivitySignup) (lastId int64, err error) {
  364. o, err := orm.NewOrm().Begin()
  365. if err != nil {
  366. return
  367. }
  368. defer func() {
  369. fmt.Println(err)
  370. if err == nil {
  371. o.Commit()
  372. } else {
  373. o.Rollback()
  374. }
  375. }()
  376. itemMy := new(CygxMySchedule)
  377. itemMy.UserId = item.UserId
  378. itemMy.ActivityId = item.ActivityId
  379. itemMy.CreateTime = time.Now()
  380. itemMy.Mobile = item.Mobile
  381. itemMy.Email = item.Email
  382. itemMy.CompanyId = item.CompanyId
  383. itemMy.CompanyName = item.CompanyName
  384. lastId, err = o.Insert(itemMy)
  385. if err != nil {
  386. return
  387. }
  388. sql := `UPDATE cygx_activity_signup SET do_fail_type = 0 , fail_type=0 WHERE user_id=? AND activity_id=? `
  389. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  390. itemLog := new(CygxActivitySignupLog)
  391. itemLog.UserId = item.UserId
  392. itemLog.ActivityId = item.ActivityId
  393. itemLog.CreateTime = time.Now()
  394. itemLog.Mobile = item.Mobile
  395. itemLog.Email = item.Email
  396. itemLog.CompanyId = item.CompanyId
  397. itemLog.CompanyName = item.CompanyName
  398. itemLog.Type = 1
  399. lastId, err = o.Insert(itemLog)
  400. return
  401. }
  402. // 列表
  403. func GetActivitySignupListAll() (items []*CygxActivitySignup, err error) {
  404. o := orm.NewOrm()
  405. sql := `SELECT * FROM cygx_activity_signup `
  406. _, err = o.Raw(sql).QueryRows(&items)
  407. return
  408. }
  409. // 修改是否推送消息状态
  410. func UPdateSignup(item *CygxActivitySignup) (err error) {
  411. sql := ` UPDATE cygx_activity_signup SET outbound_mobile= ? , country_code=86 WHERE id = ?`
  412. o := orm.NewOrm()
  413. _, err = o.Raw(sql, item.Mobile, item.Id).Exec()
  414. return
  415. }
  416. // 获取数量
  417. func GetActivityCountByIdWithUid(activityId, Uid int) (count int, err error) {
  418. o := orm.NewOrm()
  419. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE activity_id = ? AND user_id = ?`
  420. err = o.Raw(sqlCount, activityId, Uid).QueryRow(&count)
  421. return
  422. }
  423. // 获取用户报名数量
  424. func GetActivitySignupNomeetingCount(activityId int) (count int, err error) {
  425. sqlCount := `SELECT
  426. COUNT( 1 ) count
  427. FROM
  428. cygx_activity_signup AS s
  429. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  430. WHERE
  431. 1 = 1
  432. AND a.is_limit_people > 0
  433. AND s.is_meeting = 0
  434. AND a.is_submit_meeting = 1
  435. AND a.activity_id = ?`
  436. o := orm.NewOrm()
  437. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  438. return
  439. }
  440. func GetUserMeetingMobile(activityId int) (items []*CygxActivitySignup, err error) {
  441. o := orm.NewOrm()
  442. sql := `SELECT *
  443. FROM
  444. cygx_activity_signup AS s
  445. WHERE
  446. s.is_meeting = 1
  447. AND s.activity_id = ?`
  448. _, err = o.Raw(sql, activityId).QueryRows(&items)
  449. return
  450. }
  451. // 获取用户是否被限制报名
  452. func GetRestrictSignupCountByUid(uid int) (count int, err error) {
  453. sqlCount := `SELECT COUNT( 1 ) count FROM cygx_activity_restrict_signup WHERE user_id = ?`
  454. o := orm.NewOrm()
  455. err = o.Raw(sqlCount, uid).QueryRow(&count)
  456. return
  457. }
  458. // 获取用户爽约次数
  459. func GetActivitySignupNomeetingCountByUid(uid int) (count int, err error) {
  460. sqlCount := `SELECT
  461. COUNT( 1 ) count
  462. FROM
  463. cygx_activity_signup AS s
  464. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  465. WHERE
  466. 1 = 1
  467. AND a.is_limit_people > 0
  468. AND s.is_meeting = 0
  469. AND a.is_submit_meeting = 1
  470. AND s.do_fail_type = 0
  471. AND s.user_id = ?`
  472. o := orm.NewOrm()
  473. err = o.Raw(sqlCount, uid).QueryRow(&count)
  474. return
  475. }
  476. // 删除
  477. func DeleteCygxActivityRestrictSignup(uid int) (err error) {
  478. o := orm.NewOrm()
  479. sql := ` DELETE FROM cygx_activity_restrict_signup WHERE user_id=?`
  480. _, err = o.Raw(sql, uid).Exec()
  481. return
  482. }
  483. type CygxActivitySignupList struct {
  484. Id int `orm:"column(id);pk"`
  485. UserId int `description:"用户id"`
  486. ActivityId int `description:"活动ID"`
  487. CompanyName string `description:"公司名称"`
  488. RealName string `description:"姓名"`
  489. CreateTime string `description:"创建时间"`
  490. IsMeeting int `description:"是否到会 ,1是, 0否"`
  491. Operation bool `description:"操作按钮,true,到会,false 未到会"`
  492. Channel int `description:"报名渠道,0 空降、 1小程序报名"`
  493. SellerName string `description:"所属销售"`
  494. Mobile string `description:"手机号"`
  495. Email string `description:"邮箱"`
  496. CompanyId int `description:"公司id"`
  497. SigninTime string `description:"签到时间"`
  498. }
  499. type CygxActivitySignupResp struct {
  500. CompanyName string `description:"公司名称"`
  501. RealName string `description:"姓名"`
  502. IsMeeting int `description:"是否到会 ,1是, 0否"`
  503. SigninTime string `description:"签到时间"`
  504. }
  505. // 获取用户报名列表
  506. func GetActivitySignupNomeetingCountList(activityId int) (items []*CygxActivitySignupList, err error) {
  507. o := orm.NewOrm()
  508. sql := `SELECT
  509. s.*
  510. FROM
  511. cygx_activity_signup AS s
  512. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  513. WHERE
  514. 1 = 1
  515. AND s.is_meeting = 0
  516. AND a.is_submit_meeting = 1
  517. AND a.activity_id = ?`
  518. _, err = o.Raw(sql, activityId).QueryRows(&items)
  519. return
  520. }
  521. type UserAndCompanyName struct {
  522. UserId int `orm:"column(user_id);pk"`
  523. Mobile string
  524. Email string
  525. CompanyId int
  526. CompanyName string `description:"公司名称"`
  527. CountryCode string `description:"手机国家区号"`
  528. OutboundMobile string `description:"外呼手机号"`
  529. OutboundCountryCode string `description:"外呼手机号区号"`
  530. }
  531. func GetUserAndCompanyNameList(uid int) (item *UserAndCompanyName, err error) {
  532. o := orm.NewOrm()
  533. sql := ` SELECT u.*,c.company_name
  534. FROM wx_user AS u
  535. INNER JOIN company AS c ON c.company_id = u.company_id
  536. WHERE user_id =?`
  537. err = o.Raw(sql, uid).QueryRow(&item)
  538. return
  539. }
  540. type CygxActivityRestrictSignup struct {
  541. Id int `orm:"column(id);pk"`
  542. UserId int `description:"用户id,多个用,隔开"`
  543. CreateTime time.Time `description:"创建时间"`
  544. Mobile string `description:"手机号"`
  545. Email string `description:"邮箱号"`
  546. CompanyId int `description:"公司ID"`
  547. CompanyName string `description:"公司名称"`
  548. IsRestrict int `description:"是否限制报名,1是,0否"`
  549. }
  550. // 添加
  551. func AddCygxActivityRestrictSignup(item *CygxActivityRestrictSignup) (err error) {
  552. o := orm.NewOrm()
  553. _, err = o.Insert(item)
  554. return
  555. }
  556. // 获取列表信息根据手机号分组
  557. func GetCygxActivitySignupByMobileList(condition string) (items []*CygxActivitySignup, err error) {
  558. o := orm.NewOrm()
  559. sql := `SELECT * FROM cygx_activity_signup_detail WHERE 1= 1 ` + condition + ` GROUP BY mobile `
  560. _, err = o.Raw(sql).QueryRows(&items)
  561. return
  562. }
  563. // 修改用户报名的相关信息
  564. func UpdateCygxActivitySignup(wxUser *WxUserItem) (err error) {
  565. o := orm.NewOrm()
  566. sql := `UPDATE cygx_activity_signup_detail SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  567. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  568. return
  569. }
  570. // UpdateCygxActivitySignupisMeet 修改易董的活动,用户已到会
  571. func UpdateCygxActivitySignupisMeet(activityId int, mobile string) (err error) {
  572. o := orm.NewOrm()
  573. sql := `UPDATE cygx_activity_signup SET is_meeting=1 WHERE activity_id=? AND mobile = ? `
  574. _, err = o.Raw(sql, activityId, mobile).Exec()
  575. return
  576. }
  577. // UpdateCygxActivitySignupisMeetList 批量修改易董的活动,用户已到会
  578. func UpdateCygxActivitySignupisMeetList(condition string, pars []interface{}) (err error) {
  579. if condition == "" {
  580. return
  581. }
  582. o := orm.NewOrm()
  583. sql := `UPDATE cygx_activity_signup SET is_meeting=1 WHERE 1= 1 ` + condition
  584. _, err = o.Raw(sql, pars).Exec()
  585. return
  586. }
  587. // GetCygxCygxActivitySignupList 获取报名列表信息
  588. func GetActivitySignupList(condition string, pars []interface{}) (items []*CygxActivitySignup, err error) {
  589. sql := `SELECT
  590. *
  591. FROM
  592. cygx_activity_signup AS v
  593. WHERE
  594. 1 = 1 ` + condition
  595. o := orm.NewOrm()
  596. _, err = o.Raw(sql, pars).QueryRows(&items)
  597. return
  598. }
  599. // GetCygxCygxActivitySignupList 获取报名列表信息
  600. func GetActivitySignupInnerActivityList(condition string, pars []interface{}) (items []*CygxActivitySignup, err error) {
  601. sql := `SELECT
  602. *
  603. FROM
  604. cygx_activity_signup AS v
  605. INNER JOIN cygx_activity as a ON a.activity_id = v.activity_id
  606. WHERE
  607. 1 = 1 ` + condition
  608. o := orm.NewOrm()
  609. _, err = o.Raw(sql, pars).QueryRows(&items)
  610. return
  611. }
  612. // UpdateCygxActivitySignupIsMeeting 批量标记用户的到会信息
  613. func UpdateCygxActivitySignupIsMeeting(items []*CygxActivityAttendanceDetail) (err error) {
  614. o := orm.NewOrm()
  615. p, err := o.Raw(` UPDATE cygx_activity_signup SET
  616. is_meeting = 1
  617. WHERE outbound_mobile = ? AND activity_id = ? `).Prepare()
  618. if err != nil {
  619. return
  620. }
  621. defer func() {
  622. _ = p.Close() // 别忘记关闭 statement
  623. }()
  624. for _, v := range items {
  625. _, err = p.Exec(
  626. v.Mobile,
  627. v.ActivityId)
  628. if err != nil {
  629. return
  630. }
  631. }
  632. return
  633. }