activity_attendance_detail.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. _, err = o.InsertMulti(len(items), items)
  103. if err != nil {
  104. return err
  105. }
  106. return
  107. }
  108. func GetAttendanceDetailList(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  109. o := orm.NewOrmUsingDB("hz_cygx")
  110. 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,
  111. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
  112. FROM
  113. cygx_activity_signup AS s
  114. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  115. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  116. INNER JOIN company_product AS p ON p.company_id = s.company_id
  117. LEFT JOIN cygx_activity_attendance_detail AS d ON d.mobile = s.outbound_mobile AND s.activity_id = d.activity_id
  118. WHERE 1 = 1
  119. AND s.fail_type = 0
  120. AND s.is_cancel = 0
  121. AND d.userid_entity != 3
  122. AND s.activity_id = ?` + sqlStr + ` GROUP BY s.id ORDER BY s.is_meeting DESC`
  123. _, err = o.Raw(sql, activityId).QueryRows(&item)
  124. return
  125. }
  126. func GetAttendanceDetailListGroup(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  127. o := orm.NewOrmUsingDB("hz_cygx")
  128. 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
  129. FROM
  130. cygx_activity_signup AS s
  131. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  132. 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
  133. WHERE 1 = 1
  134. AND s.do_fail_type = 0
  135. AND s.is_cancel = 0
  136. AND s.activity_id = ?` + sqlStr + ` ORDER BY s.is_meeting DESC`
  137. _, err = o.Raw(sql, activityId).QueryRows(&item)
  138. return
  139. }
  140. func GetAttendanceDetailListGroupByUser(mobile, sqlStr string) (item []*AttendanceDetail, err error) {
  141. o := orm.NewOrmUsingDB("hz_cygx")
  142. 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
  143. FROM
  144. cygx_activity_signup_detail AS s
  145. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  146. WHERE 1 = 1
  147. AND s.do_fail_type = 0
  148. AND s.is_cancel = 0
  149. AND s.mobile = ?` + sqlStr + ` ORDER BY a.activity_time ASC `
  150. _, err = o.Raw(sql, mobile).QueryRows(&item)
  151. return
  152. }
  153. func GetAttendanceDetailList2(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  154. o := orm.NewOrmUsingDB("hz_cygx")
  155. 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
  156. FROM
  157. cygx_activity_attendance_detail AS d
  158. WHERE 1 = 1 AND d.activity_id = ? AND is_meeting_str = 1 AND d.userid_entity != 3 ` + sqlStr + ` GROUP BY d.mobile`
  159. _, err = o.Raw(sql, activityId).QueryRows(&item)
  160. return
  161. }
  162. func GetAttendanceDetailList3(activityId int, sqlStr string) (item []*AttendanceDetail, err error) {
  163. o := orm.NewOrmUsingDB("hz_cygx")
  164. 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
  165. FROM
  166. cygx_activity_attendance_detail AS d
  167. 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`
  168. _, err = o.Raw(sql, activityId).QueryRows(&item)
  169. return
  170. }
  171. type AttendanceDetailList struct {
  172. List1 []*AttendanceDetail `description:"预约客户"`
  173. List2 []*AttendanceDetail `description:"未预约客户"`
  174. List3 []*AttendanceDetail `description:"潜在客户"`
  175. }
  176. type WxUserOutboundMobile struct {
  177. RealName string `description:"姓名"`
  178. Mobile string `description:"手机号"`
  179. OutboundMobile string `description:"外呼手机号"`
  180. CompanyId int `description:"公司ID"`
  181. CompanyName string `description:"公司名称"`
  182. SellerName string `description:"所属销售"`
  183. UserId int `description:"用户ID"`
  184. }
  185. func GetWxUserOutboundMobile(mobileStr string) (item []*WxUserOutboundMobile, err error) {
  186. o := orm.NewOrm()
  187. 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
  188. FROM wx_user as u
  189. INNER JOIN company_product AS p ON p.company_id = u.company_id
  190. WHERE outbound_mobile IN (` + mobileStr + `) GROUP BY u.user_id`
  191. _, err = o.Raw(sql).QueryRows(&item)
  192. return
  193. }
  194. func GetWxUserMobile(mobileStr string) (item []*WxUserOutboundMobile, err error) {
  195. o := orm.NewOrm()
  196. 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
  197. FROM wx_user as u
  198. INNER JOIN company_product AS p ON p.company_id = u.company_id
  199. WHERE mobile IN (` + mobileStr + `) GROUP BY u.user_id`
  200. _, err = o.Raw(sql).QueryRows(&item)
  201. return
  202. }
  203. type RoadshowData struct {
  204. Id int `orm:"column(id);pk;"description:"主键ID"`
  205. Company string `description:"公司名称"`
  206. UserName string `description:"用户名"`
  207. UserPhone string `description:"手机号"`
  208. UserinfoUource string `description:"用户来源"`
  209. AuthInfo string `description:"用户参会鉴权"`
  210. GuestUsername string `description:"嘉宾名称, 多个用,隔开"`
  211. FirstWatchTime string `description:"首次观看时间"`
  212. LastWatchTime string `description:"最后观看时间"`
  213. RoadshowId string `description:"路演ID"`
  214. RoadshowTitle string `description:"路演标题"`
  215. RoadshowBeginTime time.Time `description:"路演开始时间"`
  216. RoadshowEndTime time.Time `description:"路演结束时间"`
  217. JoinTime int `description:"参与时长"`
  218. JoinType int `description:"参与方式, 1网络, 2电话"`
  219. DataType int `description:"数据类型: 1直播, 2回放"`
  220. Occupation string `description:"职位"`
  221. UseridEntity int `description:"参会者身份. 1:主讲人, 2:主持人, 3:嘉宾, 4:普通参会者, 5:联席主讲人, 6:会议助理"`
  222. CrmCompanyMapStatusId int `description:"转换后的对应状态信息:1=正式客户, 2=曾使用客户, 3=其他"`
  223. }
  224. type RoadshowDataTitle struct {
  225. RoadshowTitle string `description:"路演标题"`
  226. ActivityTime string `description:"活动时间"`
  227. }
  228. type RoadshowDataTitleList struct {
  229. List []*RoadshowDataTitle
  230. }
  231. type RoadshowDataTitleResp struct {
  232. KeyWord string `description:"关键词"`
  233. ActivityId int `description:"活动ID"`
  234. }
  235. func GetRoadshowDataTitleList(startTime, endTime, title string) (list []*RoadshowDataTitle, err error) {
  236. o := orm.NewOrmUsingDB("comein_data")
  237. sql := `SELECT roadshow_title, roadshow_begin_time as activity_time FROM roadshow_data WHERE roadshow_begin_time > ? AND roadshow_end_time < ? AND roadshow_title LIKE '%` + title + `%' GROUP BY roadshow_id `
  238. _, err = o.Raw(sql, startTime, endTime).QueryRows(&list)
  239. return
  240. }
  241. func GetRoadshowDataList(title, condition string) (list []*RoadshowData, err error) {
  242. o := orm.NewOrmUsingDB("comein_data")
  243. sql := `SELECT * FROM roadshow_data WHERE roadshow_title LIKE '%` + title + `%'` + condition
  244. _, err = o.Raw(sql).QueryRows(&list)
  245. return
  246. }
  247. // 客户参会记录
  248. type CompanyMeetRep struct {
  249. ActivityId int `description:"活动Id"`
  250. RealName string `description:"姓名"`
  251. Mobile string `description:"手机号"`
  252. Email string `description:"邮箱"`
  253. ActivityName string `description:"活动名称"`
  254. ChartPermissionName string `description:"行业名称"`
  255. ActivityTypeName string `description:"活动类型名称"`
  256. Label string `description:"标签"`
  257. ActivityTime string `description:"活动时间"`
  258. FirstMeetingTime string `description:"首次入会时间"`
  259. LastMeetingTime string `description:"最后退出时间"`
  260. Duration string `description:"参会时长"`
  261. MeetingTypeStr string `description:"参会方式"`
  262. MeetingAuthentication string `description:"参会权鉴"`
  263. MeetingStatusStr string `description:"参会状态"`
  264. }
  265. func GetCygxActivityAttendanceDetailByCompanyId(mobiles string) (list []*CompanyMeetRep, err error) {
  266. o := orm.NewOrmUsingDB("hz_cygx")
  267. sql := `SELECT
  268. a.*,
  269. s.mobile,
  270. s.real_name,
  271. d.first_meeting_time,
  272. d.last_meeting_time,
  273. d.duration,
  274. d.meeting_type_str,
  275. d.meeting_authentication,
  276. d.meeting_status_str
  277. FROM
  278. cygx_activity_signup AS s
  279. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  280. INNER JOIN cygx_activity_attendance_detail AS d ON d.activity_id = s.activity_id
  281. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  282. WHERE
  283. 1 = 1
  284. AND s.do_fail_type = 0
  285. AND s.is_cancel = 0
  286. AND s.is_meeting = 1
  287. AND s.mobile IN (` + mobiles + `)
  288. AND a.is_submit_meeting = 1
  289. AND t.activity_type = 1
  290. GROUP BY
  291. s.id
  292. ORDER BY
  293. a.activity_time DESC `
  294. _, err = o.Raw(sql).QueryRows(&list)
  295. return
  296. }
  297. func GetCygxActivityOfflineMeetingDetailByCompanyId(mobiles string) (list []*CompanyMeetRep, err error) {
  298. o := orm.NewOrmUsingDB("hz_cygx")
  299. sql := `SELECT
  300. a.*,s.mobile,s.email,s.real_name
  301. FROM
  302. cygx_activity_signup AS s
  303. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  304. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  305. WHERE
  306. 1 = 1
  307. AND s.do_fail_type = 0
  308. AND s.is_cancel = 0
  309. AND s.is_meeting = 1
  310. AND s.mobile IN (` + mobiles + `)
  311. AND a.is_submit_meeting = 1
  312. AND t.activity_type = 0
  313. GROUP BY
  314. s.id
  315. ORDER BY
  316. a.activity_time DESC `
  317. _, err = o.Raw(sql).QueryRows(&list)
  318. return
  319. }
  320. func GetCompanyActivityCount(companyId int) (list []*CompanyMeetRep, err error) {
  321. o := orm.NewOrmUsingDB("hz_cygx")
  322. sql := `SELECT
  323. a.chart_permission_name,
  324. date_format( a.activity_time, '%Y-%m' ) AS activity_time
  325. FROM
  326. cygx_activity_attendance_detail AS r
  327. INNER JOIN cygx_activity AS a ON a.activity_id = r.activity_id
  328. WHERE
  329. r.company_id = ?
  330. AND is_meeting_str = 1
  331. ORDER BY
  332. a.activity_time DESC`
  333. _, err = o.Raw(sql, companyId).QueryRows(&list)
  334. return
  335. }
  336. func GetCygxActivityOfflineMeetingCoount(companyId int) (list []*CompanyMeetRep, err error) {
  337. o := orm.NewOrmUsingDB("hz_cygx")
  338. sql := `SELECT
  339. a.chart_permission_name,
  340. date_format( a.activity_time, '%Y-%m' ) AS activity_time
  341. FROM
  342. cygx_activity_offline_meeting_detail as r
  343. INNER JOIN cygx_activity as a On a.activity_id = r.activity_id
  344. WHERE
  345. r.company_id =? AND r.is_meeting = 1 ORDER BY a.activity_time DESC`
  346. _, err = o.Raw(sql, companyId).QueryRows(&list)
  347. return
  348. }
  349. // 列表
  350. func GetCygxActivityAttendanceDetailList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityAttendanceDetail, err error) {
  351. o := orm.NewOrmUsingDB("hz_cygx")
  352. sql := `SELECT * FROM cygx_activity_attendance_detail as a WHERE 1= 1 `
  353. if condition != "" {
  354. sql += condition
  355. }
  356. sql += ` LIMIT ?,? `
  357. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  358. return
  359. }