activity_meet.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 s.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. WHERE
  192. s.user_id = cs.user_id
  193. ) AS break_appointment_num,
  194. s.real_name,
  195. s.mobile,
  196. s.user_id,
  197. s.company_id,
  198. s.company_name,
  199. s.activity_id
  200. FROM
  201. cygx_activity_signup_break AS s
  202. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  203. INNER JOIN cygx_activity_signup AS cs ON cs.activity_id = s.activity_id
  204. WHERE
  205. 1 = 1 `
  206. if condition != "" {
  207. sql += condition
  208. }
  209. sql += ` GROUP BY s.user_id ORDER BY break_appointment_num DESC,a.activity_time DESC LIMIT ?,?`
  210. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  211. return
  212. }
  213. // 获取爽约次数数量
  214. func GetCygxBreakAppointmentUserCount(uid int) (count int, err error) {
  215. sqlCount := ` SELECT COUNT(1) count
  216. FROM
  217. cygx_activity_signup AS s
  218. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  219. WHERE
  220. s.activity_id = a.activity_id
  221. AND s.is_meeting = 0
  222. AND a.is_submit_meeting = 1
  223. AND s.user_id = ? `
  224. o := orm.NewOrmUsingDB("hz_cygx")
  225. err = o.Raw(sqlCount, uid).QueryRow(&count)
  226. return
  227. }
  228. func GetCompanySellerName(companyId int) (sellerName string, err error) {
  229. sql := `SELECT
  230. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS sellerName
  231. FROM
  232. company_product AS p
  233. WHERE
  234. p.company_id = ?`
  235. o := orm.NewOrm()
  236. err = o.Raw(sql, companyId).QueryRow(&sellerName)
  237. return
  238. }
  239. //end
  240. // 销售名称
  241. type CygxSellerNameList struct {
  242. SellerName string `orm:"column(real_name);"description:"销售姓名"`
  243. }
  244. type GetCygxSellerNameListRep struct {
  245. List []*CygxSellerNameList
  246. }
  247. func GetCygxSellerNameList() (items []*CygxSellerNameList, err error) {
  248. o := orm.NewOrm()
  249. sql := `SELECT real_name FROM admin WHERE role = 'sales' `
  250. _, err = o.Raw(sql).QueryRows(&items)
  251. return
  252. }
  253. //end
  254. // 活动详情
  255. type CygxActivityBreakAppointment struct {
  256. ActivityName string `description:"活动名称"`
  257. ActivityTypeName string `description:"活动类型名称"`
  258. ChartPermissionName string `description:"行业名称"`
  259. ActivityTimeText string `description:"活动时间带文字"`
  260. }
  261. type GetCygxActivityBreakAppointmentRep struct {
  262. List []*CygxActivityBreakAppointment
  263. }
  264. func GetCygxActivityBreakAppointmentList(mobile string) (items []*CygxActivityBreakAppointment, err error) {
  265. o := orm.NewOrmUsingDB("hz_cygx")
  266. sql := `SELECT a.activity_name,a.activity_type_name,a.chart_permission_name,a.activity_time_text
  267. FROM cygx_activity AS a
  268. INNER JOIN cygx_activity_signup_break AS s ON s.activity_id = a.activity_id
  269. WHERE 1 = 1
  270. AND s.mobile = ? `
  271. _, err = o.Raw(sql, mobile).QueryRows(&items)
  272. return
  273. } //end
  274. // 报名限制
  275. func AddSignUpRestrict(uid int) (err error) {
  276. o := orm.NewOrmUsingDB("hz_cygx")
  277. to, err := o.Begin()
  278. if err != nil {
  279. return
  280. }
  281. defer func() {
  282. if err != nil {
  283. _ = to.Rollback()
  284. } else {
  285. _ = to.Commit()
  286. }
  287. }()
  288. var count int
  289. sql := `SELECT COUNT(1) AS count FROM cygx_activity_restrict_signup WHERE user_id=? `
  290. err = to.Raw(sql, uid).QueryRow(&count)
  291. if err != nil {
  292. return
  293. }
  294. sql = `UPDATE cygx_activity SET is_submit_meeting = 1 WHERE activity_id = ? `
  295. _, err = to.Raw(sql, uid).Exec()
  296. return
  297. }
  298. // 获取爽约次数
  299. func GetUserBreakAppointmentCount(uid int) (count int, err error) {
  300. sqlCount := `SELECT COUNT(1) count FROM (
  301. SELECT
  302. ( 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
  303. FROM
  304. cygx_activity_signup AS s
  305. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  306. WHERE
  307. 1 = 1
  308. AND s.is_meeting = 0
  309. AND a.is_submit_meeting = 1
  310. AND s.user_id = ?
  311. GROUP BY
  312. s.user_id ) as cn `
  313. o := orm.NewOrmUsingDB("hz_cygx")
  314. err = o.Raw(sqlCount, uid).QueryRow(&count)
  315. return
  316. }
  317. func GetCygxActivityRestrictSignupCount(uid int) (count int, err error) {
  318. o := orm.NewOrmUsingDB("hz_cygx")
  319. sql := `SELECT COUNT(1) AS count FROM cygx_activity_restrict_signup WHERE user_id=? `
  320. err = o.Raw(sql, uid).QueryRow(&count)
  321. return
  322. }
  323. // 获取限制报名详情
  324. func GetCygxActivityRestrictSignupInfo(uid int) (item *CygxActivityRestrictSignup, err error) {
  325. o := orm.NewOrmUsingDB("hz_cygx")
  326. sql := `SELECT * FROM cygx_activity_restrict_signup WHERE user_id=?`
  327. err = o.Raw(sql, uid).QueryRow(&item)
  328. return
  329. }
  330. // 修改报名限制状态
  331. func UpdateCygxActivityRestrictSignup(newIsRestrict, uid int) (err error) {
  332. sql := `UPDATE cygx_activity_restrict_signup SET is_restrict=? WHERE user_id=? `
  333. o := orm.NewOrmUsingDB("hz_cygx")
  334. _, err = o.Raw(sql, newIsRestrict, uid).Exec()
  335. return
  336. }
  337. type MeetingExportRep struct {
  338. CompanyName string `description:"公司名称"`
  339. CompanyId int `description:"公司ID"`
  340. Status string `description:"状态"`
  341. RealName string `description:"姓名"`
  342. Mobile string `description:"手机号"`
  343. PsellerName string `description:"所属销售"`
  344. ActivityName string `description:"活动名称"`
  345. ChartPermissionName string `description:"行业名称"`
  346. ActivityTypeName string `description:"活动类型名称"`
  347. ActivityTimeText string `description:"活动时间带文字"`
  348. Permission string `description:"开通权限"`
  349. }
  350. // 获取报名了的用户IDs
  351. func GetSignupUserIds(activityId int, uIds string) (signupUids string, err error) {
  352. sql := ` SELECT
  353. GROUP_CONCAT( DISTINCT s.user_id SEPARATOR ',' ) AS signupUids
  354. FROM cygx_activity_signup AS s
  355. WHERE s.activity_id = ? AND s.do_fail_type = 0 AND s.user_id not IN (` + uIds + `)`
  356. o := orm.NewOrmUsingDB("hz_cygx")
  357. err = o.Raw(sql, activityId).QueryRow(&signupUids)
  358. return
  359. }
  360. // 到会数据
  361. func GetMeetingExportAll(condition string) (items []*MeetingExportRep, err error) {
  362. o := orm.NewOrmUsingDB("hz_cygx")
  363. sql := `SELECT
  364. s.attendance_id,
  365. s.company_name,
  366. s.company_id,
  367. s.mobile,
  368. s.real_name,
  369. a.activity_name,
  370. a.chart_permission_name,
  371. a.activity_type_name,
  372. a.activity_time_text,
  373. s.seller_name
  374. FROM
  375. cygx_activity_meet_detail_log AS s
  376. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  377. WHERE
  378. 1 = 1
  379. AND s.company_name != ''
  380. AND a.active_state = 3 `
  381. if condition != "" {
  382. sql += condition
  383. }
  384. sql += ` GROUP BY s.attendance_id ORDER BY s.company_meet_num DESC, s.user_meet_num DESC, a.activity_time DESC `
  385. _, err = o.Raw(sql).QueryRows(&items)
  386. return
  387. }
  388. func GetCompanyAciviytyGroupDate() (item []*CreateTimesResp, err error) {
  389. o := orm.NewOrmUsingDB("hz_cygx")
  390. 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 `
  391. _, err = o.Raw(sql).QueryRows(&item)
  392. return
  393. }
  394. type CygxYidongActivityMeetingApiLog struct {
  395. Id int `orm:"column(id);pk"`
  396. Data string `description:"返回结果数据"`
  397. YidongActivityId string `description:"易董活动ID"`
  398. CreateTime string `description:"本地创建时间"`
  399. }
  400. // 获取限制报名详情
  401. func GetCygxActivityYiDongUpdateTime(yidongActivityId string) (item *CygxYidongActivityMeetingApiLog, err error) {
  402. o := orm.NewOrmUsingDB("hz_cygx")
  403. sql := `SELECT * FROM cygx_yidong_activity_meeting_api_log WHERE yidong_activity_id = ? ORDER BY id DESC LIMIT 1`
  404. err = o.Raw(sql, yidongActivityId).QueryRow(&item)
  405. return
  406. }
  407. type CygxAtivityIdMeetNum struct {
  408. ActivityId int `description:"活动ID"`
  409. Num int `description:"数量"`
  410. }
  411. // GetCygxActivityYiDongMeetNum 根据活动ID获取到会数量的列表
  412. func GetCygxActivityYiDongMeetNum(activityId []int) (items []*CygxAtivityIdMeetNum, err error) {
  413. lenactivityId := len(activityId)
  414. if lenactivityId == 0 {
  415. return
  416. }
  417. sql := `SELECT
  418. activity_id,
  419. ( 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
  420. FROM
  421. cygx_activity AS a
  422. WHERE
  423. a.activity_id IN (` + utils.GetOrmInReplace(lenactivityId) + `) `
  424. o := orm.NewOrmUsingDB("hz_cygx")
  425. _, err = o.Raw(sql, activityId).QueryRows(&items)
  426. return
  427. }
  428. type GetSellerUserMobileResp struct {
  429. Mobile string `description:"手机号"`
  430. UserId int `description:"用户ID"`
  431. }
  432. // 获取销售所能查看到的手机号
  433. func GetSellerUserMobile(condition string) (items []*GetSellerUserMobileResp, err error) {
  434. o := orm.NewOrm()
  435. _, err = o.Raw(condition).QueryRows(&items)
  436. return
  437. }