cygx_user.go 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. type CygxCompanyUser struct {
  13. UserId int64 `orm:"column(user_id);pk"`
  14. Mobile string `description:"手机号"`
  15. Email string `description:"邮箱"`
  16. CompanyId int `description:"公司id"`
  17. CompanyName string `description:"公司名称"`
  18. RealName string `description:"姓名"`
  19. CreatedTime string `description:"创建时间"`
  20. IsMaker int `description:"是否决策人,1:是,0:否"`
  21. IsRegister bool `description:"是否注册,true:已注册,false:未注册"`
  22. Status string `description:"客户状态"`
  23. RegisterTime string `description:"注册时间"`
  24. SellerName string `description:"销售名称"`
  25. InteractionNum int `description:"互动量"`
  26. CompanyInteractionNum int `description:"企业互动量"`
  27. CompanyInteractionNumSeller int `description:"销售可见企业互动量"`
  28. Labels string `description:"标签,用英文,隔开"`
  29. ActivityLabel string `description:"活动标签,用英文,隔开"`
  30. IsShowSee bool `description:"是否展示查看"`
  31. IsShowSeeNum int `description:"是否展示查看"`
  32. HistoryNum int `description:"报告阅读"`
  33. CountNum int `description:"报告收藏"`
  34. IndustryFllowNum int `description:"产业关注"`
  35. DepartmentFollowNum int `description:"作者关注"`
  36. KeyWordNum int `description:"搜索关键词"`
  37. OnLineNum int `description:"线上互动活动"`
  38. OfficeNum int `description:"线下互动活动"`
  39. ChartNum int `description:"图表收藏数量"`
  40. TripNum int `description:"图表数量"`
  41. RoadshowVideoNum int `description:"产业视频播放量"`
  42. ActivityVideoNum int `description:"活动视频播放量"`
  43. ActivityVoiceNum int `description:"活动音频播放量"`
  44. YanxuanspecialNum int `description:"研选专栏查看数量"`
  45. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  46. TryStage int `description:"试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"`
  47. Content string `description:"备注信息"`
  48. IsRemind bool `description:"是否添加互动提醒"`
  49. IsSubscribeCygx int `description:"是否关注了查研观向微信公众号: 0-未关注; 1-已关注"`
  50. }
  51. type CompanyUserListResp struct {
  52. Paging *paging.PagingItem
  53. List []*CygxCompanyUser
  54. }
  55. // 获取数量
  56. func GetCompanyListCount(userCondition, keyWord, kwywordcondition, condition, roleTypeCode string, pars []interface{}) (count int, err error) {
  57. o := orm.NewOrm()
  58. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  59. kwywordcondition = companyCondition + kwywordcondition
  60. if condition != "" {
  61. companyCondition += condition
  62. }
  63. sql := `SELECT COUNT(DISTINCT u.user_id) AS count
  64. FROM
  65. wx_user AS u
  66. INNER JOIN company AS c ON c.company_id = u.company_id
  67. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  68. INNER JOIN admin AS m ON m.admin_id = cp.seller_id
  69. INNER JOIN user_seller_relation AS sr ON sr.user_id = u.user_id
  70. WHERE u.company_id IN (` + companyCondition + `)`
  71. if userCondition != "" {
  72. sql += userCondition
  73. }
  74. if keyWord != "" {
  75. if strings.Count(roleTypeCode, "admin") > 0 {
  76. sql += ` OR ( cp.product_id = 2 AND cp.status IN ('正式','试用','冻结','永续') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  77. } else {
  78. sql += ` OR ( cp.product_id = 2 AND u.company_id IN (` + kwywordcondition + `) AND cp.status IN ('正式','试用','冻结','永续') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  79. }
  80. }
  81. err = o.Raw(sql, pars).QueryRow(&count)
  82. return
  83. }
  84. // 列表
  85. func GetCygxCompanyUserList(userCondition, keyWord, kwywordcondition, condition, roleTypeCode, sqlOrder string, pars []interface{}, startSize, pageSize int) (items []*CygxCompanyUser, err error) {
  86. o := orm.NewOrm()
  87. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  88. kwywordcondition = companyCondition + kwywordcondition
  89. if condition != "" {
  90. companyCondition += condition
  91. }
  92. sql := `SELECT
  93. u.user_id,
  94. u.mobile,
  95. u.email,
  96. date_format(u.register_time,'%Y-%m-%d') as register_time,
  97. u.real_name,
  98. u.is_register,
  99. u.is_maker,
  100. u.user_label as labels,
  101. u.cygx_subscribe as is_subscribe_cygx,
  102. c.company_name,
  103. c.company_id,
  104. c.interaction_num as company_interaction_num,
  105. c.interaction_num_seller as company_interaction_num_seller,
  106. cp.status,
  107. cp.try_stage,
  108. cp.package_type,
  109. m.real_name as seller_name ,
  110. ( SELECT COUNT( 1 ) FROM user_remarks AS rm WHERE rm.user_id = u.user_id ) AS is_show_see_num
  111. FROM
  112. wx_user AS u
  113. INNER JOIN company AS c ON c.company_id = u.company_id
  114. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  115. INNER JOIN admin AS m ON m.admin_id = cp.seller_id
  116. INNER JOIN user_seller_relation AS sr ON sr.user_id = u.user_id
  117. WHERE u.company_id IN (` + companyCondition + `)`
  118. if userCondition != "" {
  119. sql += userCondition
  120. }
  121. if keyWord != "" {
  122. if strings.Count(roleTypeCode, "admin") > 0 {
  123. sql += ` OR ( cp.product_id = 2 AND cp.status IN ('正式','试用','冻结','永续') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  124. } else {
  125. sql += ` OR ( cp.product_id = 2 AND u.company_id IN (` + kwywordcondition + `) AND cp.status IN ('正式','试用','冻结','永续') AND ( u.real_name LIKE '%` + keyWord + `%' OR u.mobile LIKE '%` + keyWord + `%' OR u.email LIKE '%` + keyWord + `%' ) ` + userCondition + ` )`
  126. }
  127. }
  128. if sqlOrder != "" {
  129. sql += sqlOrder + ` LIMIT ?,? `
  130. } else {
  131. sql += ` GROUP by u.user_id ORDER BY c.created_time DESC, u.register_time DESC LIMIT ?,? `
  132. }
  133. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  134. return
  135. }
  136. type CygxCompanyUserAndSellerResp struct {
  137. UserId int `description:"用户ID"`
  138. Mobile string `description:"手机号"`
  139. Email string `description:"邮箱"`
  140. CompanyId int `description:"公司id"`
  141. CompanyName string `description:"公司名称"`
  142. RealName string `description:"姓名"`
  143. SellerName string `description:"销售名称"`
  144. }
  145. // 给所有已绑定手机号的客户(除流失)列表
  146. func GetCygxCompanyUserListByNoLoss() (items []*CygxCompanyUserAndSellerResp, err error) {
  147. o := orm.NewOrm()
  148. sql := `SELECT
  149. u.user_id,
  150. u.mobile,
  151. u.email,
  152. u.real_name,
  153. c.company_name,
  154. c.company_id,
  155. m.real_name AS seller_name
  156. FROM
  157. wx_user AS u
  158. INNER JOIN company AS c ON c.company_id = u.company_id
  159. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  160. INNER JOIN admin AS m ON m.admin_id = cp.seller_id
  161. INNER JOIN user_seller_relation AS sr ON sr.user_id = u.user_id
  162. WHERE
  163. 1 = 1
  164. AND c.enabled = 1
  165. AND cp.STATUS != '流失'
  166. AND cp.product_id = 2
  167. AND sr.product_id = 2
  168. GROUP BY
  169. u.user_id `
  170. _, err = o.Raw(sql).QueryRows(&items)
  171. return
  172. }
  173. // 对于上面的SQL的拆分优化查询速度
  174. func GetCygxCompanyUserListSplit(userIds string) (items []*CygxCompanyUser, err error) {
  175. databaseName := utils.GetWeeklyDatabase()
  176. o := orm.NewOrmUsingDB("hz_cygx")
  177. sql := `SELECT
  178. u.user_id,
  179. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.mobile = u.mobile AND h.is_del = 0 AND h.mobile <>'' ) AS history_num,
  180. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.user_id = u.user_id ) AS count_num,
  181. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.user_id = u.user_id ) AS chart_num,
  182. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.user_id = u.user_id AND h.type = 1 AND h.source IN (0,1,2) ) AS industry_fllow_num,
  183. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = u.user_id AND h.type = 1 ) AS department_follow_num,
  184. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = u.user_id ) AS key_word_num,
  185. ( SELECT COUNT(DISTINCT h.activity_id) FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  186. AND t.activity_type = 1 AND h.do_fail_type = 0 ) AS on_line_num,
  187. ( SELECT COUNT( 1 ) FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  188. AND t.activity_type = 0 AND h.do_fail_type = 0 ) AS office_num,
  189. ( SELECT COUNT( 1 ) FROM cygx_activity_special_meeting_detail AS h INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id WHERE h.mobile = u.mobile AND a.publish_status = 1 AND a.activity_time_end < NOW()) AS trip_num,
  190. ( SELECT COUNT( 1 ) FROM cygx_micro_roadshow_video_history AS h INNER JOIN cygx_micro_roadshow_video as v ON v.video_id = h.video_id WHERE h.mobile = u.mobile ) AS roadshow_video_num,
  191. ( SELECT COUNT( 1 ) FROM cygx_activity_video_history AS h INNER JOIN cygx_activity_video as v ON v.video_id = h.video_id WHERE h.mobile = u.mobile ) AS activity_video_num,
  192. ( SELECT COUNT( 1 ) FROM cygx_activity_voice_history AS h INNER JOIN cygx_activity_voice as v ON v.activity_voice_id = h.activity_voice_id WHERE h.mobile = u.mobile ) AS activity_voice_num,
  193. ( SELECT COUNT( 1 ) FROM cygx_yanxuan_special_record AS h INNER JOIN cygx_yanxuan_special as v ON v.id = h.yanxuan_special_id WHERE h.mobile = u.mobile ) AS yanxuanspecial_num
  194. FROM ` + databaseName + `.wx_user AS u WHERE u.user_id IN (` + userIds + `) AND u.mobile != '' GROUP BY u.user_id `
  195. _, err = o.Raw(sql).QueryRows(&items)
  196. return
  197. }
  198. type UserRemarks struct {
  199. Id int `orm:"column(id);pk"`
  200. UserId int `description:"用户ID"`
  201. AdminId int `description:"销售/管理员ID"`
  202. Content string `description:"备注信息"`
  203. CreateTime time.Time `description:"创建时间"`
  204. }
  205. type UserRemarksResp struct {
  206. Id int `orm:"column(id);pk"`
  207. UserId int `description:"用户ID"`
  208. AdminId int `description:"销售/管理员ID"`
  209. Content string `description:"备注信息"`
  210. CreateTime string `description:"创建时间"`
  211. }
  212. type UserRemarAddReq struct {
  213. UserId int `description:"用户ID"`
  214. Content string `description:"备注信息"`
  215. SourceType int `description:"操作类型,1:对联系人单独设置,2:对机构批量设置"`
  216. DoType int `description:"操作方式,1:添加,2:取消"`
  217. }
  218. // 添加UserRemarks
  219. func AddUserRemarks(item *UserRemarks) (err error) {
  220. o := orm.NewOrm()
  221. _, err = o.Insert(item)
  222. return
  223. }
  224. // 获取备注列表
  225. func GetUserRemarksList(userId int) (items []*UserRemarksResp, err error) {
  226. o := orm.NewOrm()
  227. sql := ` SELECT * FROM user_remarks WHERE user_id=? ORDER BY create_time DESC`
  228. _, err = o.Raw(sql, userId).QueryRows(&items)
  229. return
  230. }
  231. // 获取备注列表(多用户)
  232. func GetUserRemarksListByUserIds(uids string) (items []*UserRemarksResp, err error) {
  233. o := orm.NewOrm()
  234. sql := ` SELECT * FROM user_remarks WHERE user_id IN(` + uids + `) ORDER BY create_time DESC`
  235. _, err = o.Raw(sql).QueryRows(&items)
  236. return
  237. }
  238. type UserRemarksListResp struct {
  239. List []*UserRemarksResp
  240. }
  241. // 切换列表
  242. type CygxUserTableRep struct {
  243. PermissionName string `description:"名称"`
  244. Source int `description:"类型"`
  245. TotalNum int `description:"总数"`
  246. }
  247. type CygxUserTableListRep struct {
  248. List []*CygxUserTableRep
  249. UserName string `description:"用户名称"`
  250. ComapnyName string `description:"公司名称"`
  251. Mobile string `description:"手机号"`
  252. }
  253. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
  254. // 状态搜索列表
  255. type CygxTryStageRep struct {
  256. Name string `description:"试用客户子标签"`
  257. TryStage int `description:"试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"`
  258. }
  259. type CygxUserTableStatusRep struct {
  260. List []*CygxTryStageRep
  261. Name string `description:"状态"`
  262. TryStage string `description:"状态"`
  263. }
  264. type CygxUserTableStatusListRep struct {
  265. List []*CygxUserTableStatusRep
  266. }
  267. type UserInteractionListResp struct {
  268. Paging *paging.PagingItem
  269. List []*UserInteraction
  270. MeetingNum int `description:"已到会"`
  271. NoMeetingNum int `description:"未到会"`
  272. }
  273. type UserInteraction struct {
  274. ArticleId int `description:"文章id"`
  275. ActivityId int `description:"活动ID"`
  276. ArticleType int `description:"文章类型 1:查研观向, 2:策略平台"`
  277. ArticleIdMd5 string `description:"文章MD5id"`
  278. Title string `description:"标题"`
  279. MediaTitle string `description:"音视频标题"`
  280. CategoryName string `description:"行业2"`
  281. PublishDate string `description:"发布时间"`
  282. CreateTime string `description:"创建时间"`
  283. CreateDate string `orm:"column(create_time);" description:"创建时间"`
  284. PermissionName string `orm:"column(chart_permission_name);" description:"行业"`
  285. ChartPermissionId int `description:"行业id"`
  286. IndustryName string `description:"产业名称"`
  287. SubjectNameStr string `description:"关联标的"`
  288. MatchTypeName string `description:"匹配类型"`
  289. StopTime string `description:"阅读停留时间"`
  290. NickName string `description:"作者昵称"`
  291. DepartmentId int `description:"作者ID "`
  292. KeyWord string `description:"关键词"`
  293. Source int `description:"关键词来源;1:纪要、2:图表、3:纪要/图表、4:产业资源包、5:报告、6:活动、7:搜索关键词、8:专项产业调研、9音视频播放"`
  294. ActivityName string `description:"活动名称"`
  295. ActivityType int `description:"1 线上,0、2线下"`
  296. IsMeeting int `description:"是否到会, 1是,0否"`
  297. ActivityTypeName string `description:"活动类型名称"`
  298. Label string `description:"标签"`
  299. ActivityTime string `description:"活动时间"`
  300. ActivityTimeText string `description:"活动时间"`
  301. FirstMeetingTime string `description:"首次入会时间"`
  302. LastMeetingTime string `description:"最后退出时间"`
  303. Duration string `description:"参会时长"`
  304. MeetingTypeStr string `description:"参会方式"`
  305. MeetingAuthentication string `description:"参会权鉴"`
  306. MeetingStatusStr string `description:"参会状态"`
  307. SignupType string `description:"参会方式 "`
  308. InteractionType string `description:"互动类型 "`
  309. ReminderNum int `description:"预约外呼数量 "`
  310. TitleEn string `description:"英文标题 "`
  311. PtagName string `description:"父类名称"`
  312. CtagName string `description:"子类名称"`
  313. PtagNameTwo string `description:"父类名称"`
  314. CtagNameTwo string `description:"子类名称"`
  315. CtagNamePc string `description:"Pc端所有的分类名称"`
  316. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  317. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  318. ChartId int `description:"图表id"`
  319. RealName string `description:"姓名"`
  320. CompanyName string `description:"公司名称"`
  321. CompanyId int `description:"公司ID"`
  322. SellerName string `description:"所属销售"`
  323. Mobile string `description:"手机号"`
  324. UserId int `description:"用户ID"`
  325. City string `description:"城市"`
  326. FileType string `description:"文件类型"`
  327. ListChart []*HomeChartListResp
  328. Paging *paging.PagingItem
  329. IsEnd bool `description:"是否最后一页,配合前端分页添加的参数"`
  330. CurrentIndex int `description:"当前页页码,配合前端分页添加的参数"`
  331. RegisterPlatform int `description:"来源 1小程序,2:网页 ,3:策略平台"`
  332. SourcePlatform string `description:"来源 'MOBILE:移动端小程序','PC:PC端小程序','CELUE:上海策略平台','WEB:查研观向网页版'"`
  333. TagId int
  334. TagName string // 标签名
  335. ArticleTypes string // 报告系列
  336. ActivityTypes string // 活动类型
  337. Industries string // 产业
  338. SubjectNames string // 标的
  339. SpecialType int `description:"专栏类型 1:笔记,2:观点"`
  340. ArticleNum int // 已发布的文章数量
  341. FansNum int // 粉丝数量
  342. }
  343. // 查研观向图表
  344. type CygxChartResp struct {
  345. Title string `description:"标题"`
  346. PublishDate string `description:"发布时间"`
  347. CreateTime string `description:"创建时间"`
  348. TitleEn string `description:"英文标题 "`
  349. PtagName string `description:"父类名称"`
  350. CtagName string `description:"子类名称"`
  351. PtagNameTwo string `description:"父类名称"`
  352. CtagNameTwo string `description:"子类名称"`
  353. CtagNamePc string `description:"Pc端所有的分类名称"`
  354. BodyHtml string `orm:"column(cover)";description:"图片链接"`
  355. HttpUrl string `orm:"column(iframe)";description:"文章链接跳转地址"`
  356. ChartId int `description:"图表id"`
  357. RealyName string `description:"姓名"`
  358. Mobile string `description:"手机号"`
  359. }
  360. // 获取阅读记录数量
  361. func GetCygxArticleHistoryCount(mobile, email, condition string) (count int, err error) {
  362. o := orm.NewOrmUsingDB("hz_cygx")
  363. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_history_record_all as r INNER JOIN cygx_article as art ON art.article_id = r.article_id WHERE r.mobile = '` + mobile + `' AND is_del = 0 ` + condition
  364. err = o.Raw(sqlCount).QueryRow(&count)
  365. return
  366. }
  367. // 阅读记录列表
  368. func GetCygxArticleHistoryRecordByUser(mobile, email, condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
  369. o := orm.NewOrmUsingDB("hz_cygx")
  370. sql := ` SELECT
  371. art.title,
  372. art.article_id,
  373. art.article_id_md5,
  374. art.publish_date,
  375. art.category_name,
  376. re.chart_permission_name,
  377. re.chart_permission_id,
  378. r.create_time,
  379. r.stop_time,
  380. r.source as source_platform,
  381. (
  382. SELECT
  383. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  384. FROM
  385. cygx_industrial_subject AS s
  386. WHERE
  387. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  388. ) AS subject_name_str,
  389. (
  390. SELECT
  391. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  392. FROM
  393. cygx_industrial_management AS man
  394. WHERE
  395. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
  396. ) AS industry_name
  397. FROM
  398. cygx_article_history_record_all AS r
  399. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  400. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  401. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  402. WHERE
  403. r.mobile = ? AND is_del = 0 ` + condition + ` OR ( email = ? AND email <>'' AND is_del = 0 ` + condition + ` )
  404. GROUP BY r.id ORDER BY r.create_time DESC `
  405. if startSize > 0 || pageSize > 0 {
  406. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  407. }
  408. _, err = o.Raw(sql, mobile, email).QueryRows(&items)
  409. return
  410. }
  411. // 用户阅读记录列表 2023-08-02 优化拆分
  412. func GetCygxArticleHistoryRecordByUserNew(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  413. o := orm.NewOrmUsingDB("hz_cygx")
  414. var sql string
  415. sql += `SELECT
  416. art.title,
  417. art.article_id,
  418. art.article_id_md5,
  419. art.publish_date,
  420. art.category_name,
  421. r.create_time,
  422. r.stop_time,
  423. r.source AS source_platform,
  424. '' AS register_platform,
  425. '' AS special_type
  426. FROM
  427. cygx_article_history_record_all AS r
  428. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  429. WHERE
  430. 1= 1
  431. AND is_del = 0 ` + condition
  432. //sql += ` UNION ALL `
  433. //sql += ` SELECT
  434. // art.title,
  435. // art.id AS article_id,
  436. // '' AS article_id_md5,
  437. // art.publish_time AS publish_date,
  438. // '' AS category_name,
  439. // r.create_time,
  440. // r.stop_time,
  441. // r.register_platform AS source_platform,
  442. // r.register_platform,
  443. // art.type AS special_type
  444. // FROM
  445. // cygx_yanxuan_special_record AS r
  446. // INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  447. // WHERE 1 = 1 ` + condition
  448. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  449. err = o.Raw(totalSql).QueryRow(&total)
  450. if err != nil {
  451. return
  452. }
  453. sql += ` ORDER BY create_time DESC, article_id DESC `
  454. if startSize > 0 || pageSize > 0 {
  455. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  456. }
  457. _, err = o.Raw(sql).QueryRows(&items)
  458. return
  459. }
  460. // 用户阅读记录列表
  461. func GetCygxYanxuaSspecialHistoryRecordByUser(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  462. o := orm.NewOrmUsingDB("hz_cygx")
  463. var sql string
  464. sql += ` SELECT
  465. art.title,
  466. art.id AS article_id,
  467. art.publish_time AS publish_date,
  468. r.create_time,
  469. r.stop_time,
  470. r.user_id,
  471. r.mobile,
  472. r.company_id,
  473. r.company_name,
  474. r.real_name,
  475. r.register_platform AS source_platform,
  476. art.type AS special_type,
  477. art.industry_tags as industry_name
  478. FROM
  479. cygx_yanxuan_special_record AS r
  480. INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  481. WHERE 1 = 1 ` + condition
  482. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  483. err = o.Raw(totalSql).QueryRow(&total)
  484. if err != nil {
  485. return
  486. }
  487. sql += ` ORDER BY create_time DESC, article_id DESC `
  488. if startSize > 0 || pageSize > 0 {
  489. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  490. }
  491. _, err = o.Raw(sql).QueryRows(&items)
  492. return
  493. }
  494. // 用户阅读记录列表
  495. func GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  496. o := orm.NewOrmUsingDB("hz_cygx")
  497. var sql string
  498. sql += ` SELECT
  499. art.title,
  500. art.id AS article_id,
  501. art.publish_time AS publish_date,
  502. r.create_time,
  503. r.stop_time,
  504. r.user_id,
  505. r.mobile,
  506. r.company_id,
  507. r.company_name,
  508. r.real_name,
  509. r.register_platform AS source_platform,
  510. art.type AS special_type,
  511. art.industry_tags as industry_name
  512. FROM
  513. cygx_yanxuan_special_record AS r
  514. INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  515. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  516. WHERE 1 = 1 ` + condition
  517. databaseName := utils.GetWeeklyDatabase()
  518. sql = fmt.Sprintf(sql, databaseName)
  519. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  520. err = o.Raw(totalSql).QueryRow(&total)
  521. if err != nil {
  522. return
  523. }
  524. sql += ` ORDER BY create_time DESC, article_id DESC `
  525. if startSize > 0 || pageSize > 0 {
  526. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  527. }
  528. _, err = o.Raw(sql).QueryRows(&items)
  529. return
  530. }
  531. // 用户阅读记录列表
  532. func GetCygxYanxuanSpecialCollectByUser(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  533. o := orm.NewOrmUsingDB("hz_cygx")
  534. var sql string
  535. sql += ` SELECT
  536. art.title,
  537. art.id AS article_id,
  538. art.publish_time AS publish_date,
  539. r.create_time,
  540. r.register_platform AS source_platform,
  541. art.type AS special_type,
  542. art.industry_tags as industry_name
  543. FROM
  544. cygx_yanxuan_special_collect AS r
  545. INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  546. WHERE 1 = 1 ` + condition
  547. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  548. err = o.Raw(totalSql).QueryRow(&total)
  549. if err != nil {
  550. return
  551. }
  552. sql += ` ORDER BY create_time DESC, article_id DESC `
  553. if startSize > 0 || pageSize > 0 {
  554. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  555. }
  556. _, err = o.Raw(sql).QueryRows(&items)
  557. return
  558. }
  559. // 用户阅读记录列表
  560. func GetCygxYanxuanSpecialCollectByUserWeekly(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  561. o := orm.NewOrmUsingDB("hz_cygx")
  562. var sql string
  563. sql += ` SELECT
  564. art.title,
  565. art.id AS article_id,
  566. art.publish_time AS publish_date,
  567. r.create_time,
  568. r.register_platform AS source_platform,
  569. art.type AS special_type,
  570. art.industry_tags as industry_name
  571. FROM
  572. cygx_yanxuan_special_collect AS r
  573. INNER JOIN cygx_yanxuan_special AS art ON art.id = r.yanxuan_special_id
  574. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  575. WHERE 1 = 1 ` + condition
  576. databaseName := utils.GetWeeklyDatabase()
  577. sql = fmt.Sprintf(sql, databaseName)
  578. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  579. err = o.Raw(totalSql).QueryRow(&total)
  580. if err != nil {
  581. return
  582. }
  583. sql += ` ORDER BY create_time DESC, article_id DESC `
  584. if startSize > 0 || pageSize > 0 {
  585. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  586. }
  587. _, err = o.Raw(sql).QueryRows(&items)
  588. return
  589. }
  590. // 用户阅读记录列表
  591. func GetCygxYanxuanSpecialAuthorByUser(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  592. o := orm.NewOrmUsingDB("hz_cygx")
  593. var sql string
  594. sql += ` SELECT
  595. art.special_name as title,
  596. art.id AS department_id,
  597. art.nick_name,
  598. art.article_num,
  599. art.fans_num,
  600. art.company_id,
  601. art.company_name,
  602. art.mobile_init as mobile,
  603. r.create_time,
  604. r.register_platform AS source_platform
  605. FROM
  606. cygx_yanxuan_special_follow AS r
  607. INNER JOIN cygx_yanxuan_special_author AS art ON art.user_id = r.follow_user_id
  608. WHERE 1 = 1 ` + condition
  609. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  610. err = o.Raw(totalSql).QueryRow(&total)
  611. if err != nil {
  612. return
  613. }
  614. sql += ` ORDER BY create_time DESC, department_id DESC `
  615. if startSize > 0 || pageSize > 0 {
  616. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  617. }
  618. _, err = o.Raw(sql).QueryRows(&items)
  619. return
  620. }
  621. // 用户阅读记录列表
  622. func GetCygxYanxuanSpecialAuthorByUserWeekly(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
  623. o := orm.NewOrmUsingDB("hz_cygx")
  624. var sql string
  625. sql += ` SELECT
  626. art.special_name as title,
  627. art.id AS department_id,
  628. art.nick_name,
  629. art.article_num,
  630. art.fans_num,
  631. art.company_id,
  632. art.company_name,
  633. art.mobile_init as mobile,
  634. r.create_time,
  635. r.register_platform AS source_platform
  636. FROM
  637. cygx_yanxuan_special_follow AS r
  638. INNER JOIN cygx_yanxuan_special_author AS art ON art.user_id = r.follow_user_id
  639. INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  640. WHERE 1 = 1 ` + condition
  641. databaseName := utils.GetWeeklyDatabase()
  642. sql = fmt.Sprintf(sql, databaseName)
  643. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  644. err = o.Raw(totalSql).QueryRow(&total)
  645. if err != nil {
  646. return
  647. }
  648. sql += ` ORDER BY create_time DESC, department_id DESC `
  649. if startSize > 0 || pageSize > 0 {
  650. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  651. }
  652. _, err = o.Raw(sql).QueryRows(&items)
  653. return
  654. }
  655. // 收藏列表数量
  656. func GetCygxArticleCollectCount(uid int, condition string) (count int, err error) {
  657. o := orm.NewOrmUsingDB("hz_cygx")
  658. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_collect as r INNER JOIN cygx_article AS art ON art.article_id = r.article_id WHERE user_id = ? ` + condition
  659. err = o.Raw(sqlCount, uid).QueryRow(&count)
  660. return
  661. }
  662. // 收藏列表
  663. func GetCygxArticleCollectByUser(uid, startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  664. o := orm.NewOrmUsingDB("hz_cygx")
  665. sql := ` SELECT
  666. art.title,
  667. art.article_id,
  668. art.article_id_md5,
  669. art.publish_date,
  670. re.chart_permission_name,
  671. re.chart_permission_id,
  672. r.create_time,
  673. re.match_type_name,
  674. (
  675. SELECT
  676. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  677. FROM
  678. cygx_industrial_subject AS s
  679. WHERE
  680. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  681. ) AS subject_name_str,
  682. (
  683. SELECT
  684. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  685. FROM
  686. cygx_industrial_management AS man
  687. WHERE
  688. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
  689. ) AS industry_name
  690. FROM
  691. cygx_article_collect AS r
  692. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  693. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  694. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  695. WHERE
  696. user_id = ? ` + condition + ` GROUP BY r.article_id
  697. ORDER BY r.create_time DESC `
  698. if startSize > 0 || pageSize > 0 {
  699. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  700. }
  701. _, err = o.Raw(sql, uid).QueryRows(&items)
  702. return
  703. }
  704. // 关注作者数量
  705. func GetCygArticleDepartmentFollowCount(uid int) (count int, err error) {
  706. o := orm.NewOrmUsingDB("hz_cygx")
  707. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department_follow WHERE user_id = ? AND type = 1 `
  708. err = o.Raw(sqlCount, uid).QueryRow(&count)
  709. return
  710. }
  711. // 关注作者列表
  712. func GetCygArticleDepartmentFollowByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  713. o := orm.NewOrmUsingDB("hz_cygx")
  714. sql := `SELECT
  715. m.department_id,
  716. m.nick_name,
  717. f.modify_time as create_time,
  718. m.department_id,
  719. i.industry_name,
  720. a.title,
  721. a.article_id,
  722. ( SELECT GROUP_CONCAT( DISTINCT i.industry_name SEPARATOR '/' ) FROM cygx_industrial_management AS i WHERE i.industrial_management_id = mg.industrial_management_id ) AS industry_name,
  723. ( SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = i.industrial_management_id ) AS subject_name_str
  724. FROM
  725. cygx_article_department_follow AS f
  726. INNER JOIN cygx_article_department AS m ON m.department_id = f.department_id
  727. LEFT JOIN cygx_article AS a ON a.department_id = m.department_id
  728. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  729. LEFT JOIN cygx_industrial_management AS i ON i.industrial_management_id = mg.industrial_management_id
  730. WHERE f.user_id = ? AND f.type = 1 GROUP BY m.department_id
  731. ORDER BY f.create_time DESC LIMIT ?,? `
  732. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  733. return
  734. }
  735. // 用户搜索关键词统计
  736. func GetCygxSearchKeyWordCount(uid int) (count int, err error) {
  737. o := orm.NewOrmUsingDB("hz_cygx")
  738. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_search_key_word WHERE user_id = ? `
  739. err = o.Raw(sqlCount, uid).QueryRow(&count)
  740. return
  741. }
  742. // 用户搜索关键词列表
  743. func GetCygxSearchKeyWordByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  744. o := orm.NewOrmUsingDB("hz_cygx")
  745. sql := `SELECT
  746. key_word,create_time
  747. FROM
  748. cygx_search_key_word as k
  749. WHERE user_id = ?
  750. ORDER BY k.create_time DESC LIMIT ?,? `
  751. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  752. return
  753. }
  754. // 用户专项产业调研统计
  755. func GetCygxActivitySpecialTripCount(condition string, pars []interface{}) (count int, err error) {
  756. o := orm.NewOrmUsingDB("hz_cygx")
  757. sqlCount := `SELECT
  758. COUNT( 1 )
  759. FROM
  760. cygx_activity_special_meeting_detail AS h
  761. INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id
  762. WHERE
  763. 1 = 1
  764. AND a.publish_status = 1 AND a.activity_time_end < NOW() ` + condition
  765. err = o.Raw(sqlCount, pars).QueryRow(&count)
  766. return
  767. }
  768. // 用户专项产业调研列表
  769. func GetCygxActivitySpecialTripByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  770. o := orm.NewOrmUsingDB("hz_cygx")
  771. sql := `SELECT
  772. a.research_theme AS activity_name,
  773. a.chart_permission_name,
  774. a.activity_time_text_by_day AS activity_time_text,
  775. a.city,
  776. a.activity_id,
  777. a.special_type AS activity_type,
  778. h.is_meeting
  779. FROM
  780. cygx_activity_special_meeting_detail AS h
  781. INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id
  782. WHERE
  783. 1 = 1
  784. AND a.publish_status = 1 AND a.activity_time_end < NOW()
  785. AND h.user_id = ?
  786. ORDER BY a.activity_time DESC LIMIT ?,? `
  787. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  788. return
  789. }
  790. // 用户音视频浏览统计
  791. func GetCygxRoadshowCount(uid int) (count int, err error) {
  792. o := orm.NewOrmUsingDB("hz_cygx")
  793. sqlCount := `SELECT
  794. COUNT( 1 ) total
  795. FROM
  796. (
  797. SELECT
  798. ""
  799. FROM
  800. cygx_micro_roadshow_video_history AS r
  801. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  802. WHERE
  803. r.user_id = ? UNION ALL
  804. SELECT
  805. ""
  806. FROM
  807. cygx_activity_video_history AS r
  808. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  809. WHERE
  810. r.user_id = ? UNION ALL
  811. SELECT
  812. ""
  813. FROM
  814. cygx_activity_voice_history AS r
  815. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  816. WHERE
  817. r.user_id = ?
  818. )z `
  819. err = o.Raw(sqlCount, uid, uid, uid).QueryRow(&count)
  820. return
  821. }
  822. // 用户专项产业调研列表
  823. func GetCygxRoadshowByUser(uid, startSize, pageSize int) (items []*UserInteraction, err error) {
  824. o := orm.NewOrmUsingDB("hz_cygx")
  825. sql := `SELECT
  826. v.video_name AS media_title,
  827. r.create_time,
  828. "逻辑解析" AS file_type
  829. FROM
  830. cygx_micro_roadshow_video_history AS r
  831. INNER JOIN cygx_micro_roadshow_video AS v ON r.video_id = v.video_id
  832. WHERE
  833. r.user_id = ? UNION ALL
  834. SELECT
  835. v.video_name AS media_title,
  836. r.create_time,
  837. "路演回放" AS file_type
  838. FROM
  839. cygx_activity_video_history AS r
  840. INNER JOIN cygx_activity_video AS v ON r.video_id = v.video_id
  841. WHERE
  842. r.user_id = ? UNION ALL
  843. SELECT
  844. v.voice_name AS media_title,
  845. r.create_time,
  846. "路演回放" AS file_type
  847. FROM
  848. cygx_activity_voice_history AS r
  849. INNER JOIN cygx_activity_voice AS v ON r.activity_id = v.activity_id
  850. WHERE
  851. r.user_id = ?
  852. ORDER BY create_time DESC LIMIT ?,? `
  853. _, err = o.Raw(sql, uid, uid, uid, startSize, pageSize).QueryRows(&items)
  854. return
  855. }
  856. // 线上已到会列表
  857. func GetAttendanceDetailListByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  858. o := orm.NewOrmUsingDB("hz_cygx")
  859. sql := `SELECT
  860. s.signup_type,
  861. a.activity_name,
  862. a.chart_permission_name,
  863. a.activity_type_name,
  864. a.label,
  865. a.activity_time,
  866. d.first_meeting_time,
  867. d.last_meeting_time,
  868. d.meeting_type_str,
  869. d.meeting_authentication,
  870. d.meeting_status_str,
  871. d.duration
  872. FROM
  873. cygx_activity_signup AS s
  874. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  875. INNER JOIN cygx_activity_attendance_detail AS d ON d.activity_id = s.activity_id
  876. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  877. WHERE
  878. 1 = 1
  879. AND s.do_fail_type = 0
  880. AND s.is_cancel = 0
  881. AND s.is_meeting = ?
  882. AND s.mobile = ?
  883. AND a.is_submit_meeting = 1
  884. AND t.activity_type = 1
  885. GROUP BY
  886. a.activity_id
  887. ORDER BY
  888. a.activity_time DESC
  889. LIMIT ?,?`
  890. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  891. return
  892. }
  893. // 线上未来到会列表
  894. func GetAttendanceDetailListNoMeetingByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  895. o := orm.NewOrmUsingDB("hz_cygx")
  896. sql := `SELECT
  897. s.signup_type,
  898. a.activity_name,
  899. a.chart_permission_name,
  900. a.activity_type_name,
  901. a.label,
  902. a.activity_time,
  903. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS rm WHERE rm.activity_id = s.activity_id AND rm.mobile = s.mobile ) AS reminder_num
  904. FROM
  905. cygx_activity_signup AS s
  906. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  907. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  908. WHERE
  909. 1 = 1
  910. AND s.do_fail_type = 0
  911. AND s.is_cancel = 0
  912. AND s.is_meeting = ?
  913. AND s.mobile = ?
  914. AND a.is_submit_meeting = 1
  915. AND t.activity_type = 1
  916. GROUP BY
  917. a.activity_id
  918. ORDER BY
  919. a.activity_time DESC
  920. LIMIT ?,?`
  921. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  922. return
  923. }
  924. // 用户参会统计
  925. func GetAttendanceDetaiCount(mobile string, meetType, isMeeting int) (count int, err error) {
  926. o := orm.NewOrmUsingDB("hz_cygx")
  927. sqlCount := ` SELECT
  928. COUNT( DISTINCT a.activity_id ) as count
  929. FROM
  930. cygx_activity_signup AS s
  931. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  932. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  933. WHERE
  934. mobile = ?
  935. AND is_meeting =?
  936. AND s.do_fail_type = 0
  937. AND a.is_submit_meeting = 1 `
  938. if meetType == 1 {
  939. sqlCount += ` AND t.activity_type = 1 `
  940. } else {
  941. sqlCount += ` AND t.activity_type = 0 `
  942. }
  943. err = o.Raw(sqlCount, mobile, isMeeting).QueryRow(&count)
  944. return
  945. }
  946. // 线下已到会列表
  947. func GetAttendanceOfflineListByUser(isMeeting int, mobile string, startSize, pageSize int) (item []*UserInteraction, err error) {
  948. o := orm.NewOrmUsingDB("hz_cygx")
  949. sql := `SELECT
  950. a.activity_name,
  951. a.chart_permission_name,
  952. a.activity_type_name,
  953. a.label,
  954. a.activity_time
  955. FROM
  956. cygx_activity_signup AS s
  957. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  958. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  959. WHERE
  960. 1 = 1
  961. AND s.do_fail_type = 0
  962. AND s.is_cancel = 0
  963. AND s.is_meeting = ?
  964. AND s.mobile = ?
  965. AND a.is_submit_meeting = 1
  966. AND t.activity_type = 0
  967. GROUP BY
  968. a.activity_id
  969. ORDER BY
  970. a.activity_time DESC
  971. LIMIT ?,?`
  972. _, err = o.Raw(sql, isMeeting, mobile, startSize, pageSize).QueryRows(&item)
  973. return
  974. }
  975. // 获取用户参会记录数量
  976. func GetActivityMeetByUserCount(condition string) (count int, err error) {
  977. o := orm.NewOrmUsingDB("hz_cygx")
  978. sqlCount := ` SELECT
  979. COUNT( DISTINCT a.activity_id ) as count
  980. FROM
  981. cygx_activity_signup_detail AS s
  982. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  983. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  984. WHERE
  985. 1=1
  986. AND s.do_fail_type = 0 `
  987. if condition != "" {
  988. sqlCount += condition
  989. }
  990. err = o.Raw(sqlCount).QueryRow(&count)
  991. return
  992. }
  993. // 获取用户参会记录
  994. func GetActivityMeetByUser(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  995. o := orm.NewOrmUsingDB("hz_cygx")
  996. sql := `SELECT
  997. t.activity_type,
  998. s.signup_type,
  999. s.is_meeting,
  1000. a.activity_name,
  1001. a.chart_permission_name,
  1002. a.activity_type_name,
  1003. a.label,
  1004. a.activity_time,
  1005. s.first_meeting_time,
  1006. s.last_meeting_time,
  1007. s.meeting_type_str,
  1008. s.meeting_authentication,
  1009. s.meeting_status_str,
  1010. s.duration
  1011. FROM
  1012. cygx_activity_signup_detail AS s
  1013. INNER JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  1014. INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id
  1015. WHERE
  1016. 1 = 1
  1017. AND s.do_fail_type = 0 ` + condition + `
  1018. GROUP BY
  1019. s.activity_id,s.outbound_mobile
  1020. ORDER BY
  1021. a.activity_time DESC `
  1022. if startSize > 0 || pageSize > 0 {
  1023. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  1024. }
  1025. _, err = o.Raw(sql).QueryRows(&item)
  1026. return
  1027. }
  1028. // 获取用户参会记录
  1029. func GetActivitySpecialMeetByUser(condition string, startSize, pageSize int) (item []*UserInteraction, err error) {
  1030. o := orm.NewOrmUsingDB("hz_cygx")
  1031. sql := `SELECT
  1032. a.activity_id,
  1033. a.research_theme AS activity_name,
  1034. a.chart_permission_name,
  1035. special_type AS activity_type,
  1036. a.activity_time,
  1037. a.activity_time_text_by_day AS activity_time_text
  1038. FROM
  1039. cygx_activity_special_meeting_detail AS s
  1040. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  1041. WHERE
  1042. 1 = 1 ` + condition + `
  1043. GROUP BY
  1044. s.activity_id,
  1045. s.mobile
  1046. ORDER BY
  1047. a.activity_time DESC `
  1048. if startSize > 0 || pageSize > 0 {
  1049. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  1050. }
  1051. _, err = o.Raw(sql).QueryRows(&item)
  1052. return
  1053. }
  1054. type GetUserInteractionTableCountResp struct {
  1055. HistoryNum int `description:"报告阅读"`
  1056. CountNum int `description:"报告收藏"`
  1057. IndustryFllowNum int `description:"产业关注"`
  1058. DepartmentFollowNum int `description:"作者关注"`
  1059. KeyWordNum int `description:"搜索关键词"`
  1060. OnLineNum int `description:"线上互动活动"`
  1061. OfficeNum int `description:"线下互动活动"`
  1062. ActivityNum int `description:"活动数量"`
  1063. ChartNum int `description:"图表数量"`
  1064. TripNum int `description:"图表数量"`
  1065. RoadshowVideoNum int `description:"产业视频播放量"`
  1066. ActivityVideoNum int `description:"活动视频播放量"`
  1067. ActivityVoiceNum int `description:"活动音频播放量"`
  1068. TagNum int `description:"首页标签点击量"`
  1069. YanxuanSpecialNum int `description:"研选专栏阅读数量"`
  1070. YanxuanSpecialCollectNum int `description:"研选专栏收藏数量"`
  1071. YanxuanSpecialFollowNum int `description:"研选专栏作者关注数量"`
  1072. }
  1073. // 用户互动总数统计
  1074. func GetUserInteractionTableCount(uid int) (item *GetUserInteractionTableCountResp, err error) {
  1075. o := orm.NewOrmUsingDB("hz_cygx")
  1076. sql := `SELECT
  1077. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.user_id = ? AND h.is_del = 0 AND art.article_type_id = 0 ) AS history_num,
  1078. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.user_id = ? AND art.article_type_id = 0 ) AS count_num,
  1079. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h INNER JOIN cygx_chart_all AS a ON h.chart_id = a.chart_id WHERE h.user_id = ? ) AS chart_num,
  1080. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h INNER JOIN cygx_industrial_management as a ON a.industrial_management_id = h.industrial_management_id WHERE h.user_id = ? AND h.type = 1 AND h.source IN (0,1,2) AND a.chart_permission_id != 31 ) AS industry_fllow_num,
  1081. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = ? AND h.register_platform IN(1,2) ) AS key_word_num,
  1082. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.user_id = ?
  1083. AND t.activity_type=1 AND h.do_fail_type = 0 AND a.chart_permission_id != 31 ) AS on_line_num,
  1084. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.user_id = ?
  1085. AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.chart_permission_id != 31 ) AS office_num,
  1086. ( SELECT COUNT( 1 ) FROM cygx_activity_special_meeting_detail AS h INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id WHERE h.user_id = ? AND a.publish_status = 1 AND a.activity_time_end < NOW()) AS trip_num,
  1087. ( SELECT COUNT( 1 ) FROM cygx_micro_roadshow_video_history AS h INNER JOIN cygx_micro_roadshow_video as v ON v.video_id = h.video_id WHERE h.user_id = ? ) AS roadshow_video_num,
  1088. ( SELECT COUNT( 1 ) FROM cygx_activity_video_history AS h INNER JOIN cygx_activity_video as v ON v.video_id = h.video_id WHERE h.user_id = ? ) AS activity_video_num,
  1089. ( SELECT COUNT( 1 ) FROM cygx_activity_voice_history AS h INNER JOIN cygx_activity_voice as v ON v.activity_id = h.activity_id WHERE h.user_id = ? ) AS activity_voice_num,
  1090. ( SELECT COUNT(1) FROM cygx_tag_history as h INNER JOIN cygx_tag AS b ON h.tag_id = b.tag_id WHERE h.user_id = ? ) AS tag_num
  1091. FROM dual `
  1092. err = o.Raw(sql, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid).QueryRow(&item)
  1093. return
  1094. }
  1095. // 用户互动总数统计
  1096. func GetUserInteractionTableCountByYanXuan(uid int) (item *GetUserInteractionTableCountResp, err error) {
  1097. o := orm.NewOrmUsingDB("hz_cygx")
  1098. sql := `SELECT
  1099. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.user_id = ? AND h.is_del = 0 AND art.article_type_id > 0 ) AS history_num,
  1100. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.user_id = ? AND art.article_type_id > 0 ) AS count_num,
  1101. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h INNER JOIN cygx_industrial_management as a ON a.industrial_management_id = h.industrial_management_id WHERE h.user_id = ? AND h.type = 1 AND h.source IN (0,1,2) AND a.chart_permission_id = 31 ) AS industry_fllow_num,
  1102. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = ? AND h.type = 1 ) AS department_follow_num,
  1103. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = ? AND h.register_platform IN(1,2) ) AS key_word_num,
  1104. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.user_id = ?
  1105. AND t.activity_type=1 AND h.do_fail_type = 0 AND a.chart_permission_id = 31 ) AS on_line_num,
  1106. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup_detail AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.user_id = ?
  1107. AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.chart_permission_id = 31 ) AS office_num,
  1108. ( SELECT COUNT(1) FROM cygx_yanxuan_special_collect as h INNER JOIN cygx_yanxuan_special AS b ON h.yanxuan_special_id = b.id WHERE h.user_id = ? ) AS yanxuan_special_collect_num,
  1109. ( SELECT COUNT(1) FROM cygx_yanxuan_special_follow as h WHERE h.user_id = ? ) AS yanxuan_special_follow_num,
  1110. ( SELECT COUNT(1) FROM cygx_yanxuan_special_record as h INNER JOIN cygx_yanxuan_special AS b ON h.yanxuan_special_id = b.id WHERE h.user_id = ? ) AS yanxuan_special_num
  1111. FROM dual `
  1112. err = o.Raw(sql, uid, uid, uid, uid, uid, uid, uid, uid, uid, uid).QueryRow(&item)
  1113. return
  1114. }
  1115. // 根据时间获取用户互动总数统计
  1116. func GetUserInteractionTableCountBytime(uid int, startDate, endDate string) (item *GetUserInteractionTableCountResp, err error) {
  1117. o := orm.NewOrm()
  1118. sql := `SELECT
  1119. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_all AS h INNER JOIN cygx_article as art ON art.article_id = h.article_id WHERE h.mobile = u.mobile AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' OR ( h.email = u.email AND h.email <>'' AND h.is_del = 0 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) ) AS history_num,
  1120. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.user_id = u.user_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS count_num,
  1121. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.user_id = u.user_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS chart_num,
  1122. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.user_id = u.user_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS industry_fllow_num,
  1123. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = u.user_id AND h.type = 1 AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS department_follow_num,
  1124. ( SELECT COUNT( 1 ) FROM cygx_search_key_word AS h WHERE h.user_id = u.user_id AND create_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS key_word_num,
  1125. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  1126. AND a.is_submit_meeting = 1 AND t.activity_type=1 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `' ) AS on_line_num,
  1127. ( SELECT COUNT( DISTINCT a.activity_id ) as count FROM cygx_activity_signup AS h INNER JOIN cygx_activity as a ON a.activity_id = h.activity_id INNER JOIN cygx_activity_type as t ON t.activity_type_id = a.activity_type_id WHERE h.mobile = u.mobile
  1128. AND a.is_submit_meeting = 1 AND t.activity_type = 0 AND h.do_fail_type = 0 AND a.activity_time BETWEEN '` + startDate + `'AND '` + endDate + `') AS office_num
  1129. FROM
  1130. wx_user as u
  1131. WHERE
  1132. u.user_id = ?`
  1133. err = o.Raw(sql, uid).QueryRow(&item)
  1134. return
  1135. }
  1136. type ArticlePvCountResp struct {
  1137. ArticleId int `description:"文章ID"`
  1138. Pv int `description:"Pv"`
  1139. }
  1140. // 阅读记录
  1141. func GetArticlePvCount(mobile, email, dateTime string) (item []*ArticlePvCountResp, err error) {
  1142. o := orm.NewOrmUsingDB("hz_cygx")
  1143. sql := `SELECT
  1144. article_id,
  1145. COUNT(article_id) as pv
  1146. FROM
  1147. cygx_article_history_record_all as h
  1148. WHERE
  1149. mobile = ?
  1150. AND create_time >= ?
  1151. AND is_del = 0
  1152. OR ( email = ? AND email <>'' AND create_time >= ? AND is_del = 0 )
  1153. GROUP BY article_id `
  1154. _, err = o.Raw(sql, mobile, dateTime, email, dateTime).QueryRows(&item)
  1155. return
  1156. }
  1157. type ArticleIndustryNameResp struct {
  1158. ArticleId int `description:"文章ID"`
  1159. IndustryName string `description:"产业名称"`
  1160. SubjectName string `description:"标的名称"`
  1161. }
  1162. // 产业名称
  1163. func GetArticleGroupyIndustryName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  1164. o := orm.NewOrmUsingDB("hz_cygx")
  1165. sql := `SELECT
  1166. art.article_id,
  1167. (
  1168. SELECT
  1169. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  1170. FROM
  1171. cygx_industrial_subject AS s
  1172. WHERE
  1173. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  1174. ) AS subject_name,
  1175. (
  1176. SELECT
  1177. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  1178. FROM
  1179. cygx_industrial_management AS man
  1180. WHERE
  1181. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
  1182. ) AS industry_name
  1183. FROM
  1184. cygx_article_history_record_all AS r
  1185. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  1186. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  1187. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  1188. WHERE
  1189. art.article_id IN ( ` + articleIds + `) GROUP BY art.article_id `
  1190. _, err = o.Raw(sql).QueryRows(&item)
  1191. return
  1192. }
  1193. // 标的名称
  1194. func GetArticleGroupySubjectName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  1195. o := orm.NewOrmUsingDB("hz_cygx")
  1196. sql := `SELECT
  1197. article_id,
  1198. subject_name
  1199. FROM
  1200. cygx_industrial_article_group_subject AS mg
  1201. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  1202. WHERE
  1203. article_id IN ( ` + articleIds + `)`
  1204. _, err = o.Raw(sql).QueryRows(&item)
  1205. return
  1206. }
  1207. type UserLabel struct {
  1208. Label string `description:"标签 多个用 , 隔开"`
  1209. }
  1210. type ActivityLabelCountResp struct {
  1211. Label string `description:"标签"`
  1212. Pv int `description:"Pv"`
  1213. }
  1214. // 活动标签记录(我的日程)
  1215. func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  1216. o := orm.NewOrmUsingDB("hz_cygx")
  1217. sql := `SELECT
  1218. label ,
  1219. COUNT( label ) AS pv
  1220. FROM
  1221. cygx_activity
  1222. WHERE
  1223. activity_id IN ( SELECT activity_id FROM cygx_my_schedule WHERE mobile = ? )
  1224. AND label != ''
  1225. AND activity_time >= ?
  1226. GROUP BY
  1227. label`
  1228. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  1229. return
  1230. }
  1231. // 活动标签记录(会议提醒)
  1232. func GetActivityMeetingReminder(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  1233. o := orm.NewOrmUsingDB("hz_cygx")
  1234. sql := `SELECT
  1235. label ,
  1236. COUNT( label ) AS pv
  1237. FROM
  1238. cygx_activity
  1239. WHERE
  1240. activity_id IN ( SELECT activity_id FROM cygx_activity_meeting_reminder WHERE mobile = ? )
  1241. AND label != ''
  1242. AND activity_time >= ?
  1243. GROUP BY
  1244. label`
  1245. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  1246. return
  1247. }
  1248. func GetCygxArticleCollectId(uid int, dateTime string) (articleIds string, err error) {
  1249. sql := `SELECT
  1250. GROUP_CONCAT( DISTINCT article_id SEPARATOR ',' ) AS permission
  1251. FROM
  1252. cygx_article_collect
  1253. WHERE
  1254. user_id = ?
  1255. AND create_time >= ? `
  1256. o := orm.NewOrmUsingDB("hz_cygx")
  1257. err = o.Raw(sql, uid, dateTime).QueryRow(&articleIds)
  1258. return
  1259. }
  1260. // 用户互动量
  1261. type CygxInteractionNumResp struct {
  1262. DateTime string `description:"时间"`
  1263. InteractionNum int `description:"互动量"`
  1264. }
  1265. type CygxCygxInteractionNumRespListResp struct {
  1266. List []*CygxInteractionNumResp
  1267. }
  1268. // 用户互动详情
  1269. type UserInteractionrelevantListResp struct {
  1270. IndustryName string `description:"产业名称"`
  1271. IsFllow bool `description:"是否关注"`
  1272. List []*UserInteraction
  1273. }
  1274. type EsUserInteraction struct {
  1275. Id int `description:"主键ID"`
  1276. ArticleId int `description:"文章id"`
  1277. ArticleType int `description:"文章类型 1:查研观向, 2:策略平台"`
  1278. Title string `description:"标题"`
  1279. PublishDate string `description:"发布时间"`
  1280. CreateTime string `description:"创建时间"`
  1281. StopTime string `description:"阅读停留时间"`
  1282. RealName string `description:"姓名"`
  1283. CompanyName string `description:"公司名称"`
  1284. CompanyId int `description:"公司ID"`
  1285. SellerName string `description:"所属销售"`
  1286. SellerId int `description:"所属销售ID"`
  1287. Mobile string `description:"手机号"`
  1288. Email string `description:"邮箱"`
  1289. UserId int `description:"用户ID"`
  1290. UserArticleHistoryNum int `description:"用户阅读数量"`
  1291. CompanyArticleHistoryNum int `description:"机构阅读数量"`
  1292. }
  1293. func GetCompanyIdsCondition(ondition string) (companyIds string, err error) {
  1294. sql := ondition
  1295. o := orm.NewOrm()
  1296. err = o.Raw(sql).QueryRow(&companyIds)
  1297. return
  1298. }
  1299. type InteractiveList struct {
  1300. TotalMap map[int]int
  1301. EsList []*EsUserInteraction
  1302. ActivityList []*company.CompanyReportRecordGroup
  1303. CollectList []*company.CompanyReportRecordGroup
  1304. IndustryFllowList []*company.CompanyReportRecordGroup
  1305. DepartmentFollowList []*company.CompanyReportRecordGroup
  1306. KeyWordList []*company.CompanyReportRecordGroup
  1307. Chartist []*company.CompanyReportRecordGroup
  1308. }
  1309. func GetAllOverseasRaiEmail() (emails []string, err error) {
  1310. sql := `
  1311. SELECT
  1312. *
  1313. FROM
  1314. (
  1315. SELECT
  1316. wu.email
  1317. FROM
  1318. wx_user AS wu
  1319. INNER JOIN company AS c
  1320. WHERE
  1321. wu.company_id = c.company_id
  1322. AND wu.email <> ""
  1323. AND c.region_type = "海外"
  1324. ) AS a UNION
  1325. (
  1326. SELECT
  1327. wu.email
  1328. FROM
  1329. company_product AS cp
  1330. INNER JOIN wx_user AS wu
  1331. WHERE
  1332. cp.industry_id = 10
  1333. AND cp.product_id = 2
  1334. AND wu.email <> ""
  1335. AND cp.status IN ( "正式", "试用" )
  1336. )`
  1337. o := orm.NewOrm()
  1338. _, err = o.Raw(sql).QueryRows(&emails)
  1339. return
  1340. }