wx_user.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygx/utils"
  5. "time"
  6. )
  7. type WxUser struct {
  8. UserId int `orm:"column(user_id);pk"`
  9. OpenId string `description:"open_id"`
  10. UnionId string `description:"union_id"`
  11. Subscribe string `description:"是否关注"`
  12. CompanyId int `description:"客户id"`
  13. NickName string `description:"用户昵称"`
  14. RealName string `description:"用户实际名称"`
  15. UserCode string `description:"用户编码"`
  16. Mobile string `description:"手机号码"`
  17. BindAccount string `description:"绑定时的账号"`
  18. WxCode string `description:"微信号"`
  19. Profession string `description:"职业"`
  20. Email string `description:"邮箱"`
  21. Telephone string `description:"座机"`
  22. Sex int `description:"普通用户性别,1为男性,2为女性"`
  23. Province string `description:"普通用户个人资料填写的省份"`
  24. City string `description:"普通用户个人资料填写的城市"`
  25. Country string `description:"国家,如中国为CN"`
  26. SubscribeTime int `description:"关注时间"`
  27. Remark string `description:"备注"`
  28. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  29. Privilege string `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
  30. Unionid string `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
  31. FirstLogin int `description:"是否第一次登陆"`
  32. Enabled int `description:"是否可用"`
  33. CreatedTime time.Time `description:"创建时间"`
  34. LastUpdatedTime time.Time `description:"最新一次修改时间"`
  35. Seller string `description:"销售员"`
  36. Note string `description:"客户备份信息"`
  37. IsNote int `description:"是否备注过信息"`
  38. FromType string `description:"report' COMMENT 'report:研报,teleconference:电话会"`
  39. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  40. RegisterTime time.Time `description:"注册时间"`
  41. RegisterPlatform int `description:"注册平台,1:微信端,2:PC网页端"`
  42. IsFreeLogin bool `description:"是否免登陆,true:免登陆,false:非免登陆"`
  43. LoginTime time.Time `description:"最近一次登录时间"`
  44. SessionKey string `description:"微信小程序会话密钥"`
  45. IsRegister int `description:"是否注册:1:已注册,0:未注册"`
  46. Source int `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
  47. CountryCode string `description:"区号"`
  48. OutboundMobile string `description:"外呼手机号"`
  49. OutboundCountryCode string `description:"外呼手机号区号"`
  50. TripartiteCode string `description:"第三方给过来的用户编码,判断用户是否存在"`
  51. }
  52. // 添加用户信息
  53. func AddWxUser(item *WxUser) (lastId int64, err error) {
  54. o := orm.NewOrm()
  55. lastId, err = o.Insert(item)
  56. return
  57. }
  58. type WxUserItem struct {
  59. UserId int `description:"用户id"`
  60. OpenId string `description:"open_id"`
  61. UnionId string `description:"union_id"`
  62. CompanyId int `description:"客户id"`
  63. NickName string `description:"用户昵称"`
  64. RealName string `description:"用户实际名称"`
  65. Mobile string `description:"手机号码"`
  66. BindAccount string `description:"绑定时的账号"`
  67. Email string `description:"邮箱"`
  68. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  69. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  70. FirstLogin int `description:"是否第一次登陆"`
  71. IsFreeLogin int `description:"是否免登陆,true:免登陆,false:非免登陆"`
  72. LoginTime time.Time `description:"登录时间"`
  73. CreatedTime time.Time `description:"创建时间"`
  74. LastUpdatedTime time.Time `description:"最近一次修改时间"`
  75. SessionKey string `description:"微信小程序会话密钥"`
  76. CompanyName string `description:"公司名称"`
  77. IsRegister int `description:"是否注册:1:已注册,0:未注册"`
  78. CountryCode string `description:"手机国家区号"`
  79. OutboundMobile string `description:"外呼手机号"`
  80. OutboundCountryCode string `description:"外呼手机号区号"`
  81. IsMsgOutboundMobile int `description:"是否弹窗过绑定外呼手机号区号"`
  82. IsMaker int `description:"是否是决策人"`
  83. Position string `description:"职务"`
  84. InviteCompany string `description:"邀请机构 ,LUODING:络町"`
  85. Source int
  86. }
  87. func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
  88. sql := `SELECT * FROM wx_user WHERE union_id=? `
  89. err = orm.NewOrm().Raw(sql, unionid).QueryRow(&item)
  90. return
  91. }
  92. // 根据用户ID获取相关信息
  93. func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
  94. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  95. LEFT JOIN company AS b on a.company_id=b.company_id
  96. WHERE a.user_id=? `
  97. err = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
  98. return
  99. }
  100. func GetWxUserItemByOpenId(openId string) (item *WxUserItem, err error) {
  101. sql := `SELECT * FROM wx_user WHERE open_id=? `
  102. err = orm.NewOrm().Raw(sql, openId).QueryRow(&item)
  103. return
  104. }
  105. type WxLoginResp struct {
  106. Authorization string
  107. UserId int
  108. FirstLogin int
  109. Headimgurl string `description:"用户头像"`
  110. Mobile string `description:"手机号"`
  111. Email string `description:"邮箱"`
  112. CompanyName string `description:"客户名称"`
  113. Status string `description:"状态"`
  114. EndDate string `description:"到期日期"`
  115. ProductName string `description:"客户类型名称"`
  116. }
  117. type WxGetUserInfoReq struct {
  118. RawData string `description:"rawData"`
  119. Signature string `description:"signature"`
  120. EncryptedData string `description:"encryptedData"`
  121. Iv string `description:"iv"`
  122. }
  123. // 修改用户会话key
  124. func ModifyWxUserSessionKey(sessionKey string, userId int) (err error) {
  125. o := orm.NewOrm()
  126. sql := `UPDATE wx_user SET session_key=? WHERE user_id=? `
  127. _, err = o.Raw(sql, sessionKey, userId).Exec()
  128. return
  129. }
  130. // 添加用户信息
  131. func ModifyWxUserInfo(unionId, nickName, province, city, country, avatar string, gender, userId int) (err error) {
  132. o := orm.NewOrm()
  133. sql := `UPDATE wx_user SET union_id=?,unionid=?,nick_name=?,sex=?,province=?,city=?,country=?,headimgurl=? WHERE user_id=? `
  134. _, err = o.Raw(sql, unionId, unionId, nickName, gender, province, city, country, avatar, userId).Exec()
  135. return
  136. }
  137. // 修改用户会话key
  138. func DeleteWxUserByUserId(userId int) (err error) {
  139. o := orm.NewOrm()
  140. sql := `DELETE FROM wx_user WHERE user_id=? `
  141. _, err = o.Raw(sql, userId).Exec()
  142. return
  143. }
  144. type WxGetUserInfoResp struct {
  145. //UsersId int `orm:"column(id);pk"`
  146. //Mobile string `description:"手机号"`
  147. //NickName string `description:"昵称"`
  148. //Gender int `description:"用户性别 1:男性,2:女性,0:未知(默认)"`
  149. //CreateTime time.Time `description:"注册时间"`
  150. //ModifyTime time.Time `description:"修改时间"`
  151. //AvatarUrl string `description:"头像地址"`
  152. //City string `description:"城市"`
  153. //Province string `description:"省"`
  154. //Country string `description:"国家"`
  155. //Language string `description:"语言"`
  156. //Appid string `description:"Appid"`
  157. //Timestamp int64 `description:"时间戳"`
  158. Authorization string `description:"登陆凭证,后续接口调用时,带在请求头里面Key:Authorization"`
  159. }
  160. type WxGetPhoneNumberReq struct {
  161. EncryptedData string `description:"encryptedData"`
  162. Iv string `description:"iv"`
  163. }
  164. func ModifyUsersMobile(usersId int, phoneNumber string) (err error) {
  165. o := orm.NewOrm()
  166. sql := `UPDATE wx_user SET mobile=? WHERE user_id=? `
  167. _, err = o.Raw(sql, phoneNumber, usersId).Exec()
  168. return
  169. }
  170. type WxGetPhoneNumberResp struct {
  171. PhoneNumber string `description:"用户绑定的手机号(国外手机号会有区号)"`
  172. PurePhoneNumber string `description:"没有区号的手机号"`
  173. CountryCode string `description:"区号"`
  174. }
  175. // 根据用户手机号获取相关信息
  176. func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
  177. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  178. LEFT JOIN company AS b on a.company_id=b.company_id
  179. WHERE a.mobile= '` + mobile + `' ORDER BY a.company_id DESC LIMIT 1 `
  180. err = orm.NewOrm().Raw(sql).QueryRow(&item)
  181. return
  182. }
  183. // 根据用户手机号获取相关信息
  184. func GetWxUserAouthByMobile(mobile string) (item *WxUserItem, err error) {
  185. sql := `SELECT
  186. a.*,
  187. s.mobile,
  188. b.company_name
  189. FROM
  190. cygx_session_mobile AS s
  191. LEFT JOIN wx_user AS a ON a.mobile = s.mobile
  192. LEFT JOIN company AS b ON a.company_id = b.company_id
  193. WHERE
  194. s.mobile = ?
  195. ORDER BY
  196. a.company_id DESC
  197. LIMIT 1`
  198. err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
  199. return
  200. }
  201. func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
  202. sql := `SELECT * FROM wx_user WHERE email=? `
  203. err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
  204. return
  205. }
  206. func ModifyReportLastViewTime(uid int) (err error) {
  207. sql := ` UPDATE wx_user SET report_last_view_time=NOW()
  208. WHERE user_id=? `
  209. _, err = orm.NewOrm().Raw(sql, uid).Exec()
  210. return
  211. }
  212. // 变更联系人是否已注册状态
  213. func ModifyWxUserRegisterStatus(userId int) (err error) {
  214. o := orm.NewOrm()
  215. sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
  216. _, err = o.Raw(sql, 1, userId).Exec()
  217. return
  218. }
  219. // 修改用户是否绑定外呼手机号弹窗
  220. func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
  221. o := orm.NewOrm()
  222. sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
  223. _, err = o.Raw(sql, userId).Exec()
  224. return
  225. }
  226. // 列表
  227. func GetUserListAll() (items []*WxUserItem, err error) {
  228. o := orm.NewOrm()
  229. sql := `SELECT * FROM wx_user WHERE mobile <>'' AND outbound_mobile = ''`
  230. _, err = o.Raw(sql).QueryRows(&items)
  231. return
  232. }
  233. // 修改手机号区号 8位号码+852,9位号码+886,10位号码+1,11位及以上号码+86
  234. func UPdateUserCountryCode(item *WxUserItem) (err error) {
  235. o := orm.NewOrm()
  236. if item.CountryCode == "" && len(item.Mobile) >= 11 {
  237. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=86 , country_code=86 WHERE user_id = ?`
  238. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  239. } else if item.CountryCode == "" && len(item.Mobile) == 8 {
  240. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=852 , country_code=852 WHERE user_id = ?`
  241. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  242. } else if item.CountryCode == "" && len(item.Mobile) == 9 {
  243. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=886 , country_code=886 WHERE user_id = ?`
  244. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  245. } else if item.CountryCode == "" && len(item.Mobile) == 10 {
  246. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=1 , country_code=1 WHERE user_id = ?`
  247. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  248. } else {
  249. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=? WHERE user_id = ?`
  250. _, err = o.Raw(sql, item.Mobile, item.CountryCode, item.UserId).Exec()
  251. }
  252. return
  253. }
  254. // 判断公司下用户名称是否存在
  255. func GetUserCountByName(companyId int, name string) (count int, err error) {
  256. sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND real_name = ?`
  257. err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
  258. return
  259. }
  260. // 判断这个用户是否被设置消息提醒
  261. func GetUserRemind(uid int) (count int, err error) {
  262. sql := `SELECT COUNT(1) AS count FROM cygx_user_remind WHERE user_id = ? `
  263. err = orm.NewOrm().Raw(sql, uid).QueryRow(&count)
  264. return
  265. }
  266. // 判断公司下用户名称是否存在
  267. func GetUserCountByThirdName(companyId int, name string) (count int, err error) {
  268. sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND tripartite_code = ?`
  269. err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
  270. return
  271. }
  272. // 获取公司下一共有多少用户
  273. func GetUserCountByCompanyId(companyId int) (count int, err error) {
  274. sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? `
  275. err = orm.NewOrm().Raw(sql, companyId).QueryRow(&count)
  276. return
  277. }
  278. func UpdateUserMobile(uid int, mobile string) (err error) {
  279. sql := ` UPDATE wx_user SET mobile=?
  280. WHERE user_id=? `
  281. _, err = orm.NewOrm().Raw(sql, mobile, uid).Exec()
  282. return
  283. }
  284. // 获取公司下用户详情详情详情
  285. func GetUserByName(companyId int, name string) (item *WxUser, err error) {
  286. o := orm.NewOrm()
  287. sql := `SELECT * FROM wx_user WHERE company_id = ? AND real_name = ? `
  288. err = o.Raw(sql, companyId, name).QueryRow(&item)
  289. return
  290. }
  291. // 获取公司下用户详情详情详情
  292. func GetUserByThirdName(companyId int, name string) (item *WxUser, err error) {
  293. o := orm.NewOrm()
  294. sql := `SELECT * FROM wx_user WHERE company_id = ? AND tripartite_code = ? `
  295. err = o.Raw(sql, companyId, name).QueryRow(&item)
  296. return
  297. }
  298. // 获取所有注册的权益用户
  299. func GetUserRegisterList() (items []*WxUser, err error) {
  300. o := orm.NewOrm()
  301. sql := `SELECT
  302. u.user_id,
  303. u.company_id,
  304. u.mobile,
  305. u.email,
  306. u.real_name,
  307. u.is_register,
  308. u.is_maker,
  309. u.register_time
  310. FROM
  311. wx_user AS u
  312. INNER JOIN company AS c ON c.company_id = u.company_id
  313. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  314. WHERE
  315. u.company_id IN (
  316. SELECT
  317. a.company_id
  318. FROM
  319. company AS a
  320. INNER JOIN company_product AS b ON a.company_id = b.company_id
  321. WHERE
  322. a.enabled = 1
  323. AND b.STATUS IN ( '正式', '试用', '冻结' )
  324. AND cp.product_id = 2
  325. )
  326. AND cp.product_id = 2
  327. GROUP BY
  328. u.user_id `
  329. _, err = o.Raw(sql).QueryRows(&items)
  330. //AND u.register_time IS NOT NULL OR u.report_last_view_time <>'' 统计阅读时间与注册时间不为空的用户
  331. return
  332. }
  333. type CygxCompanyUser struct {
  334. Labels string `description:"标签,用英文,隔开"`
  335. }
  336. type UserLabel struct {
  337. Label string `description:"标签 多个用 , 隔开"`
  338. }
  339. // 对获取关注的产业
  340. func GetCygxCompanyUserListSplit(userIds string) (labels string, err error) {
  341. o := orm.NewOrm()
  342. sql := `SELECT
  343. (
  344. SELECT
  345. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR ',' )
  346. FROM
  347. cygx_industrial_management AS man
  348. WHERE
  349. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industry_fllow AS f WHERE f.user_id = u.user_id AND f.type = 1 )
  350. ) AS labels
  351. FROM
  352. wx_user AS u WHERE u.user_id = ? `
  353. err = o.Raw(sql, userIds).QueryRow(&labels)
  354. return
  355. }
  356. // 阅读记录
  357. type ArticlePvCountResp struct {
  358. ArticleId int `description:"文章ID"`
  359. Pv int `description:"Pv"`
  360. }
  361. func GetArticlePvCount(mobile, email, dateTime string) (item []*ArticlePvCountResp, err error) {
  362. o := orm.NewOrm()
  363. sql := `SELECT
  364. article_id,
  365. COUNT(article_id) as pv
  366. FROM
  367. cygx_article_history_record_newpv as h
  368. WHERE
  369. mobile = ?
  370. AND email = ?
  371. AND create_time >= ?
  372. GROUP BY article_id `
  373. _, err = o.Raw(sql, mobile, email, dateTime).QueryRows(&item)
  374. return
  375. }
  376. //产业名称
  377. type ArticleIndustryNameResp struct {
  378. ArticleId int `description:"文章ID"`
  379. IndustryName string `description:"产业名称"`
  380. SubjectName string `description:"标的名称"`
  381. }
  382. func GetArticleGroupyIndustryName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  383. o := orm.NewOrm()
  384. sql := `SELECT
  385. art.article_id,
  386. (
  387. SELECT
  388. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  389. FROM
  390. cygx_industrial_subject AS s
  391. WHERE
  392. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  393. ) AS subject_name,
  394. (
  395. SELECT
  396. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  397. FROM
  398. cygx_industrial_management AS man
  399. WHERE
  400. 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 )
  401. ) AS industry_name
  402. FROM
  403. cygx_article_history_record_newpv AS r
  404. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  405. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  406. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  407. WHERE
  408. art.article_id IN ( ` + articleIds + `) GROUP BY art.article_id `
  409. _, err = o.Raw(sql).QueryRows(&item)
  410. return
  411. }
  412. func GetCygxArticleCollectId(uid int, dateTime string) (articleIds string, err error) {
  413. sql := `SELECT
  414. GROUP_CONCAT( DISTINCT article_id SEPARATOR ',' ) AS permission
  415. FROM
  416. cygx_article_collect
  417. WHERE
  418. user_id = ?
  419. AND create_time >= ? `
  420. o := orm.NewOrm()
  421. err = o.Raw(sql, uid, dateTime).QueryRow(&articleIds)
  422. return
  423. }
  424. // 活动标签记录
  425. type ActivityLabelCountResp struct {
  426. Label string `description:"标签"`
  427. Pv int `description:"Pv"`
  428. }
  429. func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  430. o := orm.NewOrm()
  431. sql := `SELECT
  432. label ,
  433. COUNT( label ) AS pv
  434. FROM
  435. cygx_activity
  436. WHERE
  437. activity_id IN ( SELECT activity_id FROM cygx_activity_signup WHERE mobile = ? )
  438. AND label != ''
  439. AND activity_time >= ?
  440. AND is_submit_meeting = 1
  441. GROUP BY
  442. label`
  443. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  444. return
  445. }
  446. type CygxUserInteractionNumDetail struct {
  447. UserId int64 `orm:"column(user_id);pk"`
  448. Mobile string `description:"手机号"`
  449. Email string `description:"邮箱"`
  450. CompanyId int `description:"公司id"`
  451. CompanyName string `description:"公司名称"`
  452. RealName string `description:"姓名"`
  453. CreatedTime string `description:"创建时间"`
  454. IsMaker int `description:"是否决策人,1:是,0:否"`
  455. IsRegister bool `description:"是否注册,true:已注册,false:未注册"`
  456. Status string `description:"客户状态"`
  457. RegisterTime string `description:"注册时间"`
  458. SellerName string `description:"销售名称"`
  459. InteractionNum int `description:"互动量"`
  460. Labels string `description:"标签,用英文,隔开"`
  461. ActivityLabel string `description:"活动标签,用英文,隔开"`
  462. IsShowSee bool `description:"是否展示查看"`
  463. IsShowSeeNum int `description:"是否展示查看"`
  464. HistoryNum int `description:"报告阅读"`
  465. CountNum int `description:"报告收藏"`
  466. ChartCountNum int `description:"图表收藏"`
  467. IndustryFllowNum int `description:"产业关注"`
  468. DepartmentFollowNum int `description:"作者关注"`
  469. KeyWordNum int `description:"搜索关键词"`
  470. OnLineNum int `description:"线上互动活动"`
  471. OfficeNum int `description:"线下互动活动"`
  472. TripNum int `description:"专项产业调研数量"`
  473. RoadshowVideoNum int `description:"产业视频播放量"`
  474. ActivityVideoNum int `description:"活动视频播放量"`
  475. ActivityVoiceNum int `description:"活动音频播放量"`
  476. TagNum int `description:"标签点击次数"`
  477. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  478. TryStage int `description:"试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"`
  479. }
  480. // 获取用户的互动量
  481. func GetCygxCompanyUserUserInteraction(userIds string) (items []*CygxUserInteractionNumDetail, err error) {
  482. o := orm.NewOrm()
  483. sql := `SELECT
  484. u.user_id,
  485. u.company_id,
  486. ( 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,
  487. ( SELECT COUNT( 1 ) FROM cygx_article_collect AS h WHERE h.user_id = u.user_id ) AS count_num,
  488. ( SELECT COUNT( 1 ) FROM cygx_chart_collect AS h WHERE h.user_id = u.user_id ) AS chart_count_num,
  489. ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS h WHERE h.user_id = u.user_id ) AS industry_fllow_num,
  490. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS h WHERE h.user_id = u.user_id ) AS department_follow_num,
  491. ( SELECT COUNT( 1 ) FROM cygx_search_key_word_log AS h WHERE h.user_id = u.user_id ) AS key_word_num,
  492. ( 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
  493. AND t.activity_type = 1 AND h.do_fail_type = 0 ) AS on_line_num,
  494. ( 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
  495. AND t.activity_type = 0 AND h.do_fail_type = 0 ) AS office_num,
  496. ( SELECT COUNT( 1 ) FROM cygx_activity_special_trip AS h INNER JOIN cygx_activity_special AS a ON a.activity_id = h.activity_id WHERE h.mobile = u.mobile AND h.is_cancel = 0 ) AS trip_num,
  497. ( 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,
  498. ( 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,
  499. ( 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,
  500. (
  501. SELECT
  502. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR ',' )
  503. FROM
  504. cygx_industrial_management AS man
  505. WHERE
  506. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industry_fllow AS f WHERE f.user_id = u.user_id AND f.type = 1 )
  507. ) AS labels,
  508. ( SELECT COUNT( 1 ) FROM cygx_tag_history AS h WHERE h.user_id = u.user_id ) AS tag_num,
  509. (
  510. SELECT
  511. GROUP_CONCAT( DISTINCT man.label SEPARATOR ',' )
  512. FROM
  513. cygx_activity AS man
  514. WHERE
  515. man.activity_id IN ( SELECT activity_id FROM cygx_activity_signup AS f WHERE f.user_id = u.user_id AND label != '')
  516. ) AS activity_label
  517. FROM
  518. wx_user AS u WHERE u.user_id IN( ` + userIds + `) `
  519. _, err = o.Raw(sql).QueryRows(&items)
  520. return
  521. }
  522. // GetWxUserListByUserIds 根据用户ID集合获取用户
  523. func GetWxUserListByUserIds(userIds string) (list []*WxUserItem, err error) {
  524. o := orm.NewOrm()
  525. sql := ` SELECT u.*, c.company_name FROM wx_user AS u
  526. INNER JOIN company AS c ON c.company_id = u.company_id
  527. WHERE user_id IN (` + userIds + `) `
  528. _, err = o.Raw(sql).QueryRows(&list)
  529. return
  530. }
  531. // GetWxUserByMobiles 根据用户手机号获取用户详情
  532. func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
  533. lenmobiles := len(mobiles)
  534. if lenmobiles == 0 {
  535. return
  536. }
  537. sql := `SELECT* FROM wx_user WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
  538. o := orm.NewOrm()
  539. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  540. return
  541. }
  542. // GetWxUserByMobiles 根据用户手机号获取用户详情
  543. func GetWxUserByOutboundMobiles(mobiles []string) (items []*WxUser, err error) {
  544. lenmobiles := len(mobiles)
  545. if lenmobiles == 0 {
  546. return
  547. }
  548. sql := `SELECT* FROM wx_user WHERE outbound_mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
  549. o := orm.NewOrm()
  550. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  551. return
  552. }
  553. func UserSubscribe(subscribeTime string, userId int) (err error) {
  554. o := orm.NewOrm()
  555. sql := `UPDATE wx_user SET cygx_subscribe=1,cygx_subscribe_time=? WHERE user_id = ? `
  556. _, err = o.Raw(sql, subscribeTime, userId).Exec()
  557. return
  558. }
  559. func GetWxUserOutboundMobiles(mobiles []string) (item []*WxUserOutboundMobile, err error) {
  560. lenmobiles := len(mobiles)
  561. if lenmobiles == 0 {
  562. return
  563. }
  564. o := orm.NewOrm()
  565. 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
  566. FROM wx_user as u
  567. INNER JOIN company_product AS p ON p.company_id = u.company_id
  568. WHERE outbound_mobile IN(` + utils.GetOrmInReplace(lenmobiles) + `) OR mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) GROUP BY u.user_id`
  569. _, err = o.Raw(sql, mobiles, mobiles).QueryRows(&item)
  570. return
  571. }