activity_meet.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. package cygx
  2. import (
  3. "hongze/hz_crm_api/utils"
  4. //"hongze/hz_crm_api/models"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "time"
  8. )
  9. // 活动详情
  10. type CygxMeetList struct {
  11. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  12. ActivityName string `description:"活动名称"`
  13. ActivityTypeName string `description:"活动类型名称"`
  14. ActivityTypeId int `description:"活动类型ID"`
  15. ChartPermissionName string `description:"行业名称"`
  16. ChartPermissionNames string `description:"行业名称"`
  17. ActivityTime string `description:"活动时间"`
  18. ActivityTimeText string `description:"活动时间带文字"`
  19. SignupPeopleNum int `description:"报名人数/预约外呼人数"`
  20. MeetPeopleNum int `description:"实际参会人数"`
  21. PotentialPeopleNum int `description:"潜在参会人数"`
  22. OmeetPeopleNum int `description:"实际参会人数(辅助字段不使用)"`
  23. IsSubmitMeeting int `description:"是否提交过到会信息 ,1是,0否"`
  24. OperationStyle int `description:"操作方式,1提交到会情况/上传参会表格,2修改到会详情/重新上传"`
  25. UpdateTime string `description:"更新时间"`
  26. IsCClassMeeting bool `description:"是否是c类电话会"`
  27. SubmitMeetingType int `description:"操作展示类型 ,1修改到会详情"`
  28. IsShowAttendanceDetails bool `description:"是否展示到会详情"`
  29. IsShowHandMovement bool `description:"是否展示手动匹配"`
  30. IsShowSubmitMeeting bool `description:"是否展示提交到会情况"`
  31. IsShowUpdateMeeting bool `description:"是否展示修改到会情况"`
  32. YidongActivityId string `description:"易董的活动ID"`
  33. ActivityJoinType string `description:"易董活动入会类型01报名审核后可入会 02预约即可入会 03仅定向邀请人员可入会"`
  34. IsYidongConduct int `description:"是否属于易董办会 1:是 、0:否"`
  35. IsShowSigninButton bool `description:"是否展示签到码按钮"`
  36. SigninImg string `description:"签到码图片"`
  37. ChartPermissionNameDeputy string `description:"副行业名称"`
  38. }
  39. type GetCygxMeetListRep struct {
  40. Paging *paging.PagingItem `description:"分页数据"`
  41. List []*CygxMeetList
  42. }
  43. // 获取数量
  44. func GetCygxMeetCount(condition string, pars []interface{}) (count int, err error) {
  45. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity as a WHERE 1= 1 `
  46. if condition != "" {
  47. sqlCount += condition
  48. }
  49. o := orm.NewOrmUsingDB("hz_cygx")
  50. err = o.Raw(sqlCount, pars).QueryRow(&count)
  51. return
  52. }
  53. // 列表
  54. func GetCygxMeetListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxMeetList, err error) {
  55. o := orm.NewOrmUsingDB("hz_cygx")
  56. sql := `SELECT
  57. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = a.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0 AND s.company_id != 16 ) AS signup_people_num,
  58. ( SELECT COUNT( 1 ) FROM cygx_activity_signin AS s WHERE s.activity_id = a.activity_id AND s.company_id <= 1 ) AS potential_people_num,
  59. ( SELECT COUNT( DISTINCT d.mobile ) FROM cygx_activity_attendance_detail AS d WHERE d.activity_id = a.activity_id AND( is_meeting_str = 1 or d.company_id <= 1) ) AS meet_people_num,
  60. ( SELECT COUNT( 1 ) FROM cygx_activity_offline_meeting_detail AS o WHERE o.activity_id = a.activity_id AND is_meeting = 1 ) AS omeet_people_num,
  61. a.*
  62. FROM cygx_activity as a
  63. WHERE 1= 1 `
  64. if condition != "" {
  65. sql += condition
  66. }
  67. sql += ` LIMIT ?,?`
  68. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  69. return
  70. }
  71. type CygxActivityMeet struct {
  72. Id int `orm:"column(id);pk"description:"ID"`
  73. UserId int `description:"用户id,多个用,隔开"`
  74. ActivityId int `description:"活动ID"`
  75. CreateTime time.Time `description:"创建时间"`
  76. Mobile string `description:"手机号"`
  77. Email string `description:"邮箱号"`
  78. CompanyId int `description:"公司ID"`
  79. CompanyName string `description:"公司名称"`
  80. Source int `description:"来源,1小程序,2后台添加"`
  81. }
  82. // 报名信息Excel下载
  83. type MeetExportRep struct {
  84. Mobile string `description:"手机号"`
  85. CompanyName string `description:"公司名称"`
  86. RealName string `description:"姓名"`
  87. CountryCode string `description:"区号"`
  88. }
  89. type MeetingDoRep struct {
  90. Ids string `description:"报名ID,多个ID用 , 隔开"`
  91. ActivityId int `description:"活动ID"`
  92. }
  93. type SignUpRestrictUid struct {
  94. UserId int `description:"用户ID"`
  95. }
  96. // 到会操作
  97. func MeetingDo(meetingUids, noMeetingUids string, ActivityId int, items []*CygxActivityOfflineMeetingDetail) (err error) {
  98. o := orm.NewOrmUsingDB("hz_cygx")
  99. to, err := o.Begin()
  100. if err != nil {
  101. return
  102. }
  103. defer func() {
  104. if err != nil {
  105. _ = to.Rollback()
  106. } else {
  107. _ = to.Commit()
  108. }
  109. }()
  110. //修改报名表的参会记录
  111. sql := `UPDATE cygx_activity_signup SET is_meeting = 0 WHERE activity_id =? `
  112. _, err = to.Raw(sql, ActivityId).Exec()
  113. if err != nil {
  114. return
  115. }
  116. sql = `UPDATE cygx_activity_signup SET is_meeting = 1 WHERE activity_id =? AND user_id IN (` + meetingUids + `)`
  117. _, err = to.Raw(sql, ActivityId).Exec()
  118. if err != nil {
  119. return
  120. }
  121. sql = `UPDATE cygx_activity SET is_submit_meeting = 1 , submit_meeting_type = 1 WHERE activity_id = ? `
  122. _, err = to.Raw(sql, ActivityId).Exec()
  123. if err != nil {
  124. return
  125. }
  126. //删除老的记录并插入新的记录
  127. sql = `DELETE FROM cygx_activity_offline_meeting_detail WHERE activity_id = ? `
  128. _, err = to.Raw(sql, ActivityId).Exec()
  129. if err != nil {
  130. return
  131. }
  132. if len(items) > 0 {
  133. //批量添加记录
  134. _, err = to.InsertMulti(len(items), items)
  135. if err != nil {
  136. return
  137. }
  138. }
  139. if len(noMeetingUids) > 0 {
  140. sql = `UPDATE cygx_activity_offline_meeting_detail SET is_meeting = 0 WHERE activity_id =? AND user_id IN (` + noMeetingUids + `)`
  141. _, err = to.Raw(sql, ActivityId).Exec()
  142. if err != nil {
  143. return
  144. }
  145. }
  146. //添加记录表的到会信息
  147. sql = `UPDATE cygx_activity_signup_detail SET is_meeting = 1 WHERE activity_id =? AND user_id IN (` + meetingUids + `)`
  148. _, err = to.Raw(sql, ActivityId).Exec()
  149. if err != nil {
  150. return
  151. }
  152. return
  153. }
  154. // 获取数量
  155. func GetCygxBreakAppointmentCount(condition string, pars []interface{}) (count int, err error) {
  156. sqlCount := ` SELECT COUNT(1) count FROM ( SELECT u.user_id
  157. FROM
  158. cygx_activity_signup_break AS s
  159. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  160. WHERE 1 = 1 ` + condition + ` GROUP BY s.user_id) AS c `
  161. o := orm.NewOrmUsingDB("hz_cygx")
  162. err = o.Raw(sqlCount, pars).QueryRow(&count)
  163. return
  164. }
  165. // 爽约记录列表
  166. type CygxBreakAppointmentList struct {
  167. UserId int `description:"用户ID"`
  168. CompanyId int `description:"公司ID"`
  169. RealName string `description:"姓名"`
  170. Mobile string `description:"手机号"`
  171. CompanyName string `description:"公司名称"`
  172. SellerName string `description:"销售姓名"`
  173. BreakAppointmentNum int `description:"爽约次数"`
  174. IsRestrict int `description:"是否被限制报名"`
  175. Operation bool `description:"是否被限制报名操作,true限制,false不限制"`
  176. }
  177. type GetCygxBreakAppointmentListRep struct {
  178. Paging *paging.PagingItem `description:"分页数据"`
  179. List []*CygxBreakAppointmentList
  180. }
  181. func GetCygxBreakAppointmentList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxBreakAppointmentList, err error) {
  182. o := orm.NewOrmUsingDB("hz_cygx")
  183. sql := `SELECT
  184. ( SELECT COUNT( 1 ) FROM cygx_activity_restrict_signup AS sig WHERE sig.is_restrict = 1 ) AS is_restrict,
  185. (
  186. SELECT
  187. COUNT( 1 ) count
  188. FROM
  189. cygx_activity_signup_break AS s
  190. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  191. ) AS break_appointment_num,
  192. s.real_name,
  193. s.mobile,
  194. s.user_id,
  195. s.company_id,
  196. s.company_name,
  197. s.activity_id
  198. FROM
  199. cygx_activity_signup_break AS s
  200. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  201. WHERE
  202. 1 = 1 `
  203. if condition != "" {
  204. sql += condition
  205. }
  206. sql += ` GROUP BY s.user_id ORDER BY break_appointment_num DESC,a.activity_time DESC LIMIT ?,?`
  207. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  208. return
  209. }
  210. // 获取爽约次数数量
  211. func GetCygxBreakAppointmentUserCount(uid int) (count int, err error) {
  212. sqlCount := ` SELECT COUNT(1) count
  213. FROM
  214. cygx_activity_signup AS s
  215. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  216. WHERE
  217. s.activity_id = a.activity_id
  218. AND s.is_meeting = 0
  219. AND a.is_submit_meeting = 1
  220. AND s.user_id = ? `
  221. o := orm.NewOrmUsingDB("hz_cygx")
  222. err = o.Raw(sqlCount, uid).QueryRow(&count)
  223. return
  224. }
  225. func GetCompanySellerName(companyId int) (sellerName string, err error) {
  226. sql := `SELECT
  227. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS sellerName
  228. FROM
  229. company_product AS p
  230. WHERE
  231. p.company_id = ?`
  232. o := orm.NewOrm()
  233. err = o.Raw(sql, companyId).QueryRow(&sellerName)
  234. return
  235. }
  236. //end
  237. // 销售名称
  238. type CygxSellerNameList struct {
  239. SellerName string `orm:"column(real_name);"description:"销售姓名"`
  240. }
  241. type GetCygxSellerNameListRep struct {
  242. List []*CygxSellerNameList
  243. }
  244. func GetCygxSellerNameList() (items []*CygxSellerNameList, err error) {
  245. o := orm.NewOrm()
  246. sql := `SELECT real_name FROM admin WHERE role = 'sales' `
  247. _, err = o.Raw(sql).QueryRows(&items)
  248. return
  249. }
  250. //end
  251. // 活动详情
  252. type CygxActivityBreakAppointment struct {
  253. ActivityName string `description:"活动名称"`
  254. ActivityTypeName string `description:"活动类型名称"`
  255. ChartPermissionName string `description:"行业名称"`
  256. ActivityTimeText string `description:"活动时间带文字"`
  257. }
  258. type GetCygxActivityBreakAppointmentRep struct {
  259. List []*CygxActivityBreakAppointment
  260. }
  261. func GetCygxActivityBreakAppointmentList(mobile string) (items []*CygxActivityBreakAppointment, err error) {
  262. o := orm.NewOrmUsingDB("hz_cygx")
  263. sql := `SELECT a.activity_name,a.activity_type_name,a.chart_permission_name,a.activity_time_text
  264. FROM cygx_activity AS a
  265. INNER JOIN cygx_activity_signup_break AS s ON s.activity_id = a.activity_id
  266. WHERE 1 = 1
  267. AND s.mobile = ? `
  268. _, err = o.Raw(sql, mobile).QueryRows(&items)
  269. return
  270. } //end
  271. // 报名限制
  272. func AddSignUpRestrict(uid int) (err error) {
  273. o := orm.NewOrmUsingDB("hz_cygx")
  274. to, err := o.Begin()
  275. if err != nil {
  276. return
  277. }
  278. defer func() {
  279. if err != nil {
  280. _ = to.Rollback()
  281. } else {
  282. _ = to.Commit()
  283. }
  284. }()
  285. var count int
  286. sql := `SELECT COUNT(1) AS count FROM cygx_activity_restrict_signup WHERE user_id=? `
  287. err = to.Raw(sql, uid).QueryRow(&count)
  288. if err != nil {
  289. return
  290. }
  291. sql = `UPDATE cygx_activity SET is_submit_meeting = 1 WHERE activity_id = ? `
  292. _, err = to.Raw(sql, uid).Exec()
  293. return
  294. }
  295. // 获取爽约次数
  296. func GetUserBreakAppointmentCount(uid int) (count int, err error) {
  297. sqlCount := `SELECT COUNT(1) count FROM (
  298. SELECT
  299. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = a.activity_id AND s.is_meeting = 0 AND a.is_submit_meeting = 1 ) AS break_appointment_num
  300. FROM
  301. cygx_activity_signup AS s
  302. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  303. WHERE
  304. 1 = 1
  305. AND s.is_meeting = 0
  306. AND a.is_submit_meeting = 1
  307. AND s.user_id = ?
  308. GROUP BY
  309. s.user_id ) as cn `
  310. o := orm.NewOrmUsingDB("hz_cygx")
  311. err = o.Raw(sqlCount, uid).QueryRow(&count)
  312. return
  313. }
  314. func GetCygxActivityRestrictSignupCount(uid int) (count int, err error) {
  315. o := orm.NewOrmUsingDB("hz_cygx")
  316. sql := `SELECT COUNT(1) AS count FROM cygx_activity_restrict_signup WHERE user_id=? `
  317. err = o.Raw(sql, uid).QueryRow(&count)
  318. return
  319. }
  320. // 获取限制报名详情
  321. func GetCygxActivityRestrictSignupInfo(uid int) (item *CygxActivityRestrictSignup, err error) {
  322. o := orm.NewOrmUsingDB("hz_cygx")
  323. sql := `SELECT * FROM cygx_activity_restrict_signup WHERE user_id=?`
  324. err = o.Raw(sql, uid).QueryRow(&item)
  325. return
  326. }
  327. // 修改报名限制状态
  328. func UpdateCygxActivityRestrictSignup(newIsRestrict, uid int) (err error) {
  329. sql := `UPDATE cygx_activity_restrict_signup SET is_restrict=? WHERE user_id=? `
  330. o := orm.NewOrmUsingDB("hz_cygx")
  331. _, err = o.Raw(sql, newIsRestrict, uid).Exec()
  332. return
  333. }
  334. type MeetingExportRep struct {
  335. CompanyName string `description:"公司名称"`
  336. CompanyId int `description:"公司ID"`
  337. Status string `description:"状态"`
  338. RealName string `description:"姓名"`
  339. Mobile string `description:"手机号"`
  340. PsellerName string `description:"所属销售"`
  341. ActivityName string `description:"活动名称"`
  342. ChartPermissionName string `description:"行业名称"`
  343. ActivityTypeName string `description:"活动类型名称"`
  344. ActivityTimeText string `description:"活动时间带文字"`
  345. Permission string `description:"开通权限"`
  346. }
  347. // 获取报名了的用户IDs
  348. func GetSignupUserIds(activityId int, uIds string) (signupUids string, err error) {
  349. sql := ` SELECT
  350. GROUP_CONCAT( DISTINCT s.user_id SEPARATOR ',' ) AS signupUids
  351. FROM cygx_activity_signup AS s
  352. WHERE s.activity_id = ? AND s.do_fail_type = 0 AND s.user_id not IN (` + uIds + `)`
  353. o := orm.NewOrmUsingDB("hz_cygx")
  354. err = o.Raw(sql, activityId).QueryRow(&signupUids)
  355. return
  356. }
  357. // 到会数据
  358. func GetMeetingExportAll(condition string) (items []*MeetingExportRep, err error) {
  359. o := orm.NewOrmUsingDB("hz_cygx")
  360. sql := `SELECT
  361. s.attendance_id,
  362. s.company_name,
  363. s.company_id,
  364. s.mobile,
  365. s.real_name,
  366. a.activity_name,
  367. a.chart_permission_name,
  368. a.activity_type_name,
  369. a.activity_time_text,
  370. s.seller_name
  371. FROM
  372. cygx_activity_meet_detail_log AS s
  373. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  374. WHERE
  375. 1 = 1
  376. AND s.company_name != ''
  377. AND a.active_state = 3 `
  378. if condition != "" {
  379. sql += condition
  380. }
  381. sql += ` GROUP BY s.attendance_id ORDER BY s.company_meet_num DESC, s.user_meet_num DESC, a.activity_time DESC `
  382. _, err = o.Raw(sql).QueryRows(&items)
  383. return
  384. }
  385. func GetCompanyAciviytyGroupDate() (item []*CreateTimesResp, err error) {
  386. o := orm.NewOrmUsingDB("hz_cygx")
  387. sql := ` SELECT date_format(activity_time,'%Y-%m') as create_times FROM cygx_activity WHERE 1=1 AND activity_time <= NOW() GROUP BY create_times ORDER BY create_times DESC `
  388. _, err = o.Raw(sql).QueryRows(&item)
  389. return
  390. }
  391. type CygxYidongActivityMeetingApiLog struct {
  392. Id int `orm:"column(id);pk"`
  393. Data string `description:"返回结果数据"`
  394. YidongActivityId string `description:"易董活动ID"`
  395. CreateTime string `description:"本地创建时间"`
  396. }
  397. // 获取限制报名详情
  398. func GetCygxActivityYiDongUpdateTime(yidongActivityId string) (item *CygxYidongActivityMeetingApiLog, err error) {
  399. o := orm.NewOrmUsingDB("hz_cygx")
  400. sql := `SELECT * FROM cygx_yidong_activity_meeting_api_log WHERE yidong_activity_id = ? ORDER BY id DESC LIMIT 1`
  401. err = o.Raw(sql, yidongActivityId).QueryRow(&item)
  402. return
  403. }
  404. type CygxAtivityIdMeetNum struct {
  405. ActivityId int `description:"活动ID"`
  406. Num int `description:"数量"`
  407. }
  408. // GetCygxActivityYiDongMeetNum 根据活动ID获取到会数量的列表
  409. func GetCygxActivityYiDongMeetNum(activityId []int) (items []*CygxAtivityIdMeetNum, err error) {
  410. lenactivityId := len(activityId)
  411. if lenactivityId == 0 {
  412. return
  413. }
  414. sql := `SELECT
  415. activity_id,
  416. ( SELECT count( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = a.activity_id AND is_meeting = 1 AND yidong_examine_status = 1 ) AS num
  417. FROM
  418. cygx_activity AS a
  419. WHERE
  420. a.activity_id IN (` + utils.GetOrmInReplace(lenactivityId) + `) `
  421. o := orm.NewOrmUsingDB("hz_cygx")
  422. _, err = o.Raw(sql, activityId).QueryRows(&items)
  423. return
  424. }
  425. type GetSellerUserMobileResp struct {
  426. Mobile string `description:"手机号"`
  427. }
  428. // 获取销售所能查看到的手机号
  429. func GetSellerUserMobile(condition string) (items []*GetSellerUserMobileResp, err error) {
  430. o := orm.NewOrm()
  431. _, err = o.Raw(condition).QueryRows(&items)
  432. return
  433. }