activity_attendance_detail.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // 报名
  8. type CygxActivityAttendanceDetail struct {
  9. AttendanceId int `orm:"column(attendance_id);pk;"description:"主键ID"`
  10. ActivityId int `description:"活动ID"`
  11. RealName string `description:"姓名"`
  12. Mobile string `description:"手机号"`
  13. CompanyName string `description:"公司名称"`
  14. CompanyId int `description:"公司id 不在数据库的用户为0"`
  15. SellerName string `description:"销售姓名"`
  16. //IsMeetingStr string `description:"是否到会"`
  17. FirstMeetingTime string `description:"首次入会时间"`
  18. LastMeetingTime string `description:"最后退出时间"`
  19. Duration string `description:"参会时长"`
  20. MeetingTypeStr string `description:"参会方式"`
  21. MeetingAuthentication string `description:"参会权鉴"`
  22. MeetingStatusStr string `description:"参会状态"`
  23. CreateTime time.Time `description:"创建时间"`
  24. Position string `description:"职位"`
  25. IsMeetingStr int `description:"是否到会,1到会,0未到会"`
  26. UseridEntity int `description:"参会者身份. 1:主讲人, 2:主持人, 3:嘉宾, 4:普通参会者, 5:联席主讲人, 6:会议助理"`
  27. CrmCompanyMapStatusId int `description:"转换后的对应状态信息:1=正式客户, 2=曾使用客户, 3=其他"`
  28. ActivityTime string `description:"活动时间"`
  29. }
  30. // 报名
  31. type AttendanceDetail struct {
  32. ActivityId int `description:"活动ID"`
  33. RealName string `description:"姓名"`
  34. Mobile string `description:"手机号"`
  35. CompanyName string `description:"公司名称"`
  36. CompanyId int `description:"公司ID"`
  37. SellerName string `orm:"column(pseller_name);"description:"销售姓名"`
  38. IsMeeting int `description:"是否到会"`
  39. FirstMeetingTime string `description:"首次入会时间"`
  40. LastMeetingTime string `description:"最后退出时间"`
  41. Duration string `description:"参会时长"`
  42. MeetingTypeStr string `description:"参会方式"`
  43. MeetingAuthentication string `description:"参会权鉴"`
  44. MeetingStatusStr string `description:"参会状态"`
  45. Position string `description:"职位"`
  46. OutboundMobile string `description:"外呼手机号"`
  47. CountryCode string `description:"手机国家区号"`
  48. UseridEntity int `description:"参会者身份. 1:主讲人, 2:主持人, 3:嘉宾, 4:普通参会者, 5:联席主讲人, 6:会议助理"`
  49. Content string `description:"备注信息"`
  50. ActivityTimeText string `description:"活动时间带文字"`
  51. ActivityName string `description:"活动名称"`
  52. }
  53. func AddAttendancDetail(items []*CygxActivityAttendanceDetail, activityId int, mobileStr string) (err error) {
  54. o := orm.NewOrmUsingDB("hz_cygx")
  55. to, err := o.Begin()
  56. if err != nil {
  57. return
  58. }
  59. defer func() {
  60. if err != nil {
  61. fmt.Println(err)
  62. _ = to.Rollback()
  63. } else {
  64. _ = to.Commit()
  65. }
  66. }()
  67. //修改活动是否上传到会信息字段
  68. sql := `UPDATE cygx_activity SET is_submit_meeting=1 WHERE activity_id=? `
  69. _, err = to.Raw(sql, activityId).Exec()
  70. if err != nil {
  71. return
  72. }
  73. //修改单个报名信息是否到会
  74. sql = `UPDATE cygx_activity_signup SET is_meeting=0 WHERE activity_id=? `
  75. _, err = to.Raw(sql, activityId).Exec()
  76. if err != nil {
  77. return
  78. }
  79. sql = `UPDATE cygx_activity_signup SET is_meeting=1 WHERE activity_id=? AND outbound_mobile IN (` + mobileStr + `)`
  80. _, err = to.Raw(sql, activityId).Exec()
  81. if err != nil {
  82. return
  83. }
  84. sql = `UPDATE cygx_activity_signup SET is_meeting=1 WHERE activity_id=? AND mobile IN (` + mobileStr + `)`
  85. _, err = to.Raw(sql, activityId).Exec()
  86. if err != nil {
  87. return
  88. }
  89. //二次上传时删除原有数据
  90. sql = ` DELETE FROM cygx_activity_attendance_detail WHERE activity_id = ?`
  91. _, err = to.Raw(sql, activityId).Exec()
  92. if err != nil {
  93. return
  94. }
  95. //插入提交信息
  96. for _, v := range items {
  97. _, err = to.Insert(v)
  98. if err != nil {
  99. return
  100. }
  101. }
  102. return
  103. }
  104. func GetAttendanceDetailList(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  105. o := orm.NewOrmUsingDB("hz_cygx")
  106. sql := `SELECT s.id,s.activity_id,p.company_name,s.mobile,s.is_meeting,s.outbound_mobile,s.country_code,u.real_name,d.first_meeting_time,d.last_meeting_time,d.meeting_type_str,d.meeting_authentication,d.meeting_status_str,d.duration,d.userid_entity,
  107. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
  108. FROM
  109. cygx_activity_signup AS s
  110. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  111. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  112. INNER JOIN company_product AS p ON p.company_id = s.company_id
  113. LEFT JOIN cygx_activity_attendance_detail AS d ON d.mobile = s.outbound_mobile AND s.activity_id = d.activity_id
  114. WHERE 1 = 1
  115. AND s.fail_type = 0
  116. AND s.is_cancel = 0
  117. AND d.userid_entity != 3
  118. AND s.activity_id = ?` + sqlStr + ` GROUP BY s.id ORDER BY s.is_meeting DESC`
  119. _, err = o.Raw(sql, activityId).QueryRows(&item)
  120. return
  121. }
  122. func GetAttendanceDetailListGroup(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  123. o := orm.NewOrmUsingDB("hz_cygx")
  124. sql := `SELECT s.*,d.first_meeting_time,d.last_meeting_time,d.meeting_type_str,d.meeting_authentication,d.meeting_status_str,d.duration,d.userid_entity,d.userid_entity
  125. FROM
  126. cygx_activity_signup AS s
  127. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  128. LEFT JOIN cygx_activity_attendance_detail AS d ON ( d.mobile = s.outbound_mobile OR d.mobile = s.mobile ) AND s.activity_id = d.activity_id
  129. WHERE 1 = 1
  130. AND s.do_fail_type = 0
  131. AND s.is_cancel = 0
  132. AND s.activity_id = ?` + sqlStr + ` ORDER BY s.is_meeting DESC`
  133. _, err = o.Raw(sql, activityId).QueryRows(&item)
  134. return
  135. }
  136. func GetAttendanceDetailListGroupByUser(mobile, sqlStr string) (item []*AttendanceDetail, err error) {
  137. o := orm.NewOrmUsingDB("hz_cygx")
  138. sql := `SELECT s.id,s.activity_id,s.company_name,s.mobile,s.is_meeting,s.outbound_mobile,s.country_code,s.real_name,s.first_meeting_time,s.last_meeting_time,s.meeting_type_str,s.meeting_authentication,s.meeting_status_str,s.duration,s.userid_entity,s.userid_entity,a.activity_name,a.activity_time_text
  139. FROM
  140. cygx_activity_signup_detail AS s
  141. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  142. WHERE 1 = 1
  143. AND s.do_fail_type = 0
  144. AND s.is_cancel = 0
  145. AND s.mobile = ?` + sqlStr + ` ORDER BY a.activity_time ASC `
  146. _, err = o.Raw(sql, mobile).QueryRows(&item)
  147. return
  148. }
  149. func GetAttendanceDetailList2(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  150. o := orm.NewOrmUsingDB("hz_cygx")
  151. sql := `SELECT d.activity_id,d.real_name,d.company_id,d.first_meeting_time,d.last_meeting_time,d.meeting_type_str,d.meeting_authentication,d.meeting_status_str,d.mobile,d.duration,d.company_name,d.position,d.userid_entity
  152. FROM
  153. cygx_activity_attendance_detail AS d
  154. WHERE 1 = 1 AND d.activity_id = ? AND is_meeting_str = 1 AND d.userid_entity != 3 ` + sqlStr + ` GROUP BY d.mobile`
  155. _, err = o.Raw(sql, activityId).QueryRows(&item)
  156. return
  157. }
  158. func GetAttendanceDetailList3(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  159. o := orm.NewOrmUsingDB("hz_cygx")
  160. sql := `SELECT d.activity_id,d.real_name,d.company_id,d.first_meeting_time,d.last_meeting_time,d.meeting_type_str,d.meeting_authentication,d.meeting_status_str,d.mobile,d.duration,d.company_name,d.position,d.userid_entity
  161. FROM
  162. cygx_activity_attendance_detail AS d
  163. WHERE 1 = 1 AND d.activity_id = ? AND d.userid_entity != 3 AND d.crm_company_map_status_id != 1 ` + sqlStr + ` GROUP BY d.mobile`
  164. _, err = o.Raw(sql, activityId).QueryRows(&item)
  165. return
  166. }
  167. type AttendanceDetailList struct {
  168. List1 []*AttendanceDetail `description:"预约客户"`
  169. List2 []*AttendanceDetail `description:"未预约客户"`
  170. List3 []*AttendanceDetail `description:"潜在客户"`
  171. }
  172. type WxUserOutboundMobile struct {
  173. RealName string `description:"姓名"`
  174. Mobile string `description:"手机号"`
  175. OutboundMobile string `description:"外呼手机号"`
  176. CompanyId int `description:"公司ID"`
  177. CompanyName string `description:"公司名称"`
  178. SellerName string `description:"所属销售"`
  179. UserId int `description:"用户ID"`
  180. }
  181. func GetWxUserOutboundMobile(mobileStr string) (item []*WxUserOutboundMobile, err error) {
  182. o := orm.NewOrm()
  183. sql := `SELECT u.real_name,u.mobile,u.outbound_mobile,u.company_id,p.company_name ,GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS seller_name
  184. FROM wx_user as u
  185. INNER JOIN company_product AS p ON p.company_id = u.company_id
  186. WHERE outbound_mobile IN (` + mobileStr + `) GROUP BY u.user_id`
  187. _, err = o.Raw(sql).QueryRows(&item)
  188. return
  189. }
  190. func GetWxUserMobile(mobileStr string) (item []*WxUserOutboundMobile, err error) {
  191. o := orm.NewOrm()
  192. sql := `SELECT u.real_name,u.mobile,u.outbound_mobile,u.company_id,p.company_name ,GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS seller_name
  193. FROM wx_user as u
  194. INNER JOIN company_product AS p ON p.company_id = u.company_id
  195. WHERE mobile IN (` + mobileStr + `) GROUP BY u.user_id`
  196. _, err = o.Raw(sql).QueryRows(&item)
  197. return
  198. }
  199. type RoadshowData struct {
  200. Id int `orm:"column(id);pk;"description:"主键ID"`
  201. Company string `description:"公司名称"`
  202. UserName string `description:"用户名"`
  203. UserPhone string `description:"手机号"`
  204. UserinfoUource string `description:"用户来源"`
  205. AuthInfo string `description:"用户参会鉴权"`
  206. GuestUsername string `description:"嘉宾名称, 多个用,隔开"`
  207. FirstWatchTime string `description:"首次观看时间"`
  208. LastWatchTime string `description:"最后观看时间"`
  209. RoadshowId string `description:"路演ID"`
  210. RoadshowTitle string `description:"路演标题"`
  211. RoadshowBeginTime time.Time `description:"路演开始时间"`
  212. RoadshowEndTime time.Time `description:"路演结束时间"`
  213. JoinTime int `description:"参与时长"`
  214. JoinType int `description:"参与方式, 1网络, 2电话"`
  215. DataType int `description:"数据类型: 1直播, 2回放"`
  216. Occupation string `description:"职位"`
  217. UseridEntity int `description:"参会者身份. 1:主讲人, 2:主持人, 3:嘉宾, 4:普通参会者, 5:联席主讲人, 6:会议助理"`
  218. CrmCompanyMapStatusId int `description:"转换后的对应状态信息:1=正式客户, 2=曾使用客户, 3=其他"`
  219. }
  220. type RoadshowDataTitle struct {
  221. RoadshowTitle string `description:"路演标题"`
  222. ActivityTime string `description:"活动时间"`
  223. }
  224. type RoadshowDataTitleList struct {
  225. List []*RoadshowDataTitle
  226. }
  227. type RoadshowDataTitleResp struct {
  228. KeyWord string `description:"关键词"`
  229. ActivityId int `description:"活动ID"`
  230. }
  231. func GetRoadshowDataTitleList(title string) (list []*RoadshowDataTitle, err error) {
  232. o := orm.NewOrmUsingDB("comein_data")
  233. sql := `SELECT roadshow_title, roadshow_begin_time as activity_time FROM roadshow_data WHERE roadshow_title LIKE '%` + title + `%' GROUP BY roadshow_id `
  234. _, err = o.Raw(sql).QueryRows(&list)
  235. return
  236. }
  237. func GetRoadshowDataList(title, condition string) (list []*RoadshowData, err error) {
  238. o := orm.NewOrmUsingDB("comein_data")
  239. sql := `SELECT * FROM roadshow_data WHERE roadshow_title LIKE '%` + title + `%'` + condition
  240. _, err = o.Raw(sql).QueryRows(&list)
  241. return
  242. }
  243. // 客户参会记录
  244. type CompanyMeetRep struct {
  245. ActivityId int `description:"活动Id"`
  246. RealName string `description:"姓名"`
  247. Mobile string `description:"手机号"`
  248. Email string `description:"邮箱"`
  249. ActivityName string `description:"活动名称"`
  250. ChartPermissionName string `description:"行业名称"`
  251. ActivityTypeName string `description:"活动类型名称"`
  252. Label string `description:"标签"`
  253. ActivityTime string `description:"活动时间"`
  254. FirstMeetingTime string `description:"首次入会时间"`
  255. LastMeetingTime string `description:"最后退出时间"`
  256. Duration string `description:"参会时长"`
  257. MeetingTypeStr string `description:"参会方式"`
  258. MeetingAuthentication string `description:"参会权鉴"`
  259. MeetingStatusStr string `description:"参会状态"`
  260. }
  261. func GetCygxActivityAttendanceDetailByCompanyId(mobiles string) (list []*CompanyMeetRep, err error) {
  262. o := orm.NewOrmUsingDB("hz_cygx")
  263. sql := `SELECT
  264. a.*,
  265. s.mobile,
  266. s.real_name,
  267. d.first_meeting_time,
  268. d.last_meeting_time,
  269. d.duration,
  270. d.meeting_type_str,
  271. d.meeting_authentication,
  272. d.meeting_status_str
  273. FROM
  274. cygx_activity_signup AS s
  275. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  276. INNER JOIN cygx_activity_attendance_detail AS d ON d.activity_id = s.activity_id
  277. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  278. WHERE
  279. 1 = 1
  280. AND s.do_fail_type = 0
  281. AND s.is_cancel = 0
  282. AND s.is_meeting = 1
  283. AND s.mobile IN (` + mobiles + `)
  284. AND a.is_submit_meeting = 1
  285. AND t.activity_type = 1
  286. GROUP BY
  287. s.id
  288. ORDER BY
  289. a.activity_time DESC `
  290. _, err = o.Raw(sql).QueryRows(&list)
  291. return
  292. }
  293. func GetCygxActivityOfflineMeetingDetailByCompanyId(mobiles string) (list []*CompanyMeetRep, err error) {
  294. o := orm.NewOrmUsingDB("hz_cygx")
  295. sql := `SELECT
  296. a.*,s.mobile,s.email,s.real_name
  297. FROM
  298. cygx_activity_signup AS s
  299. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  300. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  301. WHERE
  302. 1 = 1
  303. AND s.do_fail_type = 0
  304. AND s.is_cancel = 0
  305. AND s.is_meeting = 1
  306. AND s.mobile IN (` + mobiles + `)
  307. AND a.is_submit_meeting = 1
  308. AND t.activity_type = 0
  309. GROUP BY
  310. s.id
  311. ORDER BY
  312. a.activity_time DESC `
  313. _, err = o.Raw(sql).QueryRows(&list)
  314. return
  315. }
  316. func GetCompanyActivityCount(companyId int) (list []*CompanyMeetRep, err error) {
  317. o := orm.NewOrmUsingDB("hz_cygx")
  318. sql := `SELECT
  319. a.chart_permission_name,
  320. date_format( a.activity_time, '%Y-%m' ) AS activity_time
  321. FROM
  322. cygx_activity_attendance_detail AS r
  323. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  324. WHERE
  325. r.company_id = ?
  326. AND is_meeting_str = 1
  327. ORDER BY
  328. a.activity_time DESC`
  329. _, err = o.Raw(sql, companyId).QueryRows(&list)
  330. return
  331. }
  332. func GetCygxActivityOfflineMeetingCoount(companyId int) (list []*CompanyMeetRep, err error) {
  333. o := orm.NewOrmUsingDB("hz_cygx")
  334. sql := `SELECT
  335. a.chart_permission_name,
  336. date_format( a.activity_time, '%Y-%m' ) AS activity_time
  337. FROM
  338. cygx_activity_offline_meeting_detail as r
  339. INNER JOIN cygx_activity as a On a.activity_id = r.activity_id
  340. WHERE
  341. r.company_id =? AND r.is_meeting = 1 ORDER BY a.activity_time DESC`
  342. _, err = o.Raw(sql, companyId).QueryRows(&list)
  343. return
  344. }
  345. // 列表
  346. func GetCygxActivityAttendanceDetailList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityAttendanceDetail, err error) {
  347. o := orm.NewOrmUsingDB("hz_cygx")
  348. sql := `SELECT * FROM cygx_activity_attendance_detail as a WHERE 1= 1 `
  349. if condition != "" {
  350. sql += condition
  351. }
  352. sql += ` LIMIT ?,? `
  353. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  354. return
  355. }