activity_signup.go 21 KB

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