wx_user.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mfyx/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.NewOrmUsingDB("weekly_report")
  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. o := orm.NewOrmUsingDB("weekly_report")
  89. sql := `SELECT * FROM wx_user WHERE union_id=? `
  90. err = o.Raw(sql, unionid).QueryRow(&item)
  91. return
  92. }
  93. // 根据用户ID获取相关信息
  94. func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
  95. o := orm.NewOrmUsingDB("weekly_report")
  96. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  97. LEFT JOIN company AS b on a.company_id=b.company_id
  98. WHERE a.user_id=? `
  99. err = o.Raw(sql, userId).QueryRow(&item)
  100. return
  101. }
  102. type WxLoginResp struct {
  103. Authorization string
  104. UserId int
  105. FirstLogin int
  106. Headimgurl string `description:"用户头像"`
  107. Mobile string `description:"手机号"`
  108. Email string `description:"邮箱"`
  109. CompanyName string `description:"客户名称"`
  110. Status string `description:"状态"`
  111. EndDate string `description:"到期日期"`
  112. ProductName string `description:"客户类型名称"`
  113. }
  114. type WxGetUserInfoReq struct {
  115. RawData string `description:"rawData"`
  116. Signature string `description:"signature"`
  117. EncryptedData string `description:"encryptedData"`
  118. Iv string `description:"iv"`
  119. }
  120. // 修改用户会话key
  121. func ModifyWxUserSessionKey(sessionKey string, userId int) (err error) {
  122. o := orm.NewOrmUsingDB("weekly_report")
  123. sql := `UPDATE wx_user SET session_key=? WHERE user_id=? `
  124. _, err = o.Raw(sql, sessionKey, userId).Exec()
  125. return
  126. }
  127. // 添加用户信息
  128. func ModifyWxUserInfo(unionId, nickName, province, city, country, avatar string, gender, userId int) (err error) {
  129. o := orm.NewOrmUsingDB("weekly_report")
  130. sql := `UPDATE wx_user SET union_id=?,unionid=?,nick_name=?,sex=?,province=?,city=?,country=?,headimgurl=? WHERE user_id=? `
  131. _, err = o.Raw(sql, unionId, unionId, nickName, gender, province, city, country, avatar, userId).Exec()
  132. return
  133. }
  134. // 修改用户会话key
  135. func DeleteWxUserByUserId(userId int) (err error) {
  136. o := orm.NewOrmUsingDB("weekly_report")
  137. sql := `DELETE FROM wx_user WHERE user_id=? `
  138. _, err = o.Raw(sql, userId).Exec()
  139. return
  140. }
  141. type WxGetUserInfoResp struct {
  142. //UsersId int `orm:"column(id);pk"`
  143. //Mobile string `description:"手机号"`
  144. //NickName string `description:"昵称"`
  145. //Gender int `description:"用户性别 1:男性,2:女性,0:未知(默认)"`
  146. //CreateTime time.Time `description:"注册时间"`
  147. //ModifyTime time.Time `description:"修改时间"`
  148. //AvatarUrl string `description:"头像地址"`
  149. //City string `description:"城市"`
  150. //Province string `description:"省"`
  151. //Country string `description:"国家"`
  152. //Language string `description:"语言"`
  153. //Appid string `description:"Appid"`
  154. //Timestamp int64 `description:"时间戳"`
  155. Authorization string `description:"登陆凭证,后续接口调用时,带在请求头里面Key:Authorization"`
  156. }
  157. type WxGetPhoneNumberReq struct {
  158. EncryptedData string `description:"encryptedData"`
  159. Iv string `description:"iv"`
  160. }
  161. func ModifyUsersMobile(usersId int, phoneNumber string) (err error) {
  162. o := orm.NewOrmUsingDB("weekly_report")
  163. sql := `UPDATE wx_user SET mobile=? WHERE user_id=? `
  164. _, err = o.Raw(sql, phoneNumber, usersId).Exec()
  165. return
  166. }
  167. type WxGetPhoneNumberResp struct {
  168. PhoneNumber string `description:"用户绑定的手机号(国外手机号会有区号)"`
  169. PurePhoneNumber string `description:"没有区号的手机号"`
  170. CountryCode string `description:"区号"`
  171. }
  172. // 根据用户手机号获取相关信息
  173. func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
  174. o := orm.NewOrmUsingDB("weekly_report")
  175. sql := `SELECT a.*,b.company_name FROM wx_user AS a
  176. LEFT JOIN company AS b on a.company_id=b.company_id
  177. WHERE a.mobile= '` + mobile + `' ORDER BY a.company_id DESC LIMIT 1 `
  178. err = o.Raw(sql).QueryRow(&item)
  179. return
  180. }
  181. // 根据用户手机号获取相关信息
  182. func GetWxUserAouthByMobile(mobile string) (item *WxUserItem, err error) {
  183. o := orm.NewOrmUsingDB("weekly_report")
  184. sql := `SELECT
  185. a.*,
  186. b.company_name
  187. FROM
  188. wx_user AS a
  189. LEFT JOIN company AS b ON a.company_id = b.company_id
  190. WHERE
  191. a.mobile = ?
  192. ORDER BY
  193. a.company_id DESC
  194. LIMIT 1`
  195. err = o.Raw(sql, mobile).QueryRow(&item)
  196. return
  197. }
  198. func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
  199. o := orm.NewOrmUsingDB("weekly_report")
  200. sql := `SELECT * FROM wx_user WHERE email=? `
  201. err = o.Raw(sql, email).QueryRow(&item)
  202. return
  203. }
  204. func ModifyReportLastViewTime(uid int) (err error) {
  205. o := orm.NewOrmUsingDB("weekly_report")
  206. sql := ` UPDATE wx_user SET report_last_view_time=NOW()
  207. WHERE user_id=? `
  208. _, err = o.Raw(sql, uid).Exec()
  209. return
  210. }
  211. // 变更联系人是否已注册状态
  212. func ModifyWxUserRegisterStatus(userId int) (err error) {
  213. o := orm.NewOrmUsingDB("weekly_report")
  214. sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
  215. _, err = o.Raw(sql, 1, userId).Exec()
  216. return
  217. }
  218. // 修改用户是否绑定外呼手机号弹窗
  219. func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
  220. o := orm.NewOrmUsingDB("weekly_report")
  221. sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
  222. _, err = o.Raw(sql, userId).Exec()
  223. return
  224. }
  225. // 列表
  226. func GetUserListAll() (items []*WxUserItem, err error) {
  227. o := orm.NewOrmUsingDB("weekly_report")
  228. sql := `SELECT * FROM wx_user WHERE mobile <>'' AND outbound_mobile = ''`
  229. _, err = o.Raw(sql).QueryRows(&items)
  230. return
  231. }
  232. // 修改手机号区号 8位号码+852,9位号码+886,10位号码+1,11位及以上号码+86
  233. func UPdateUserCountryCode(item *WxUserItem) (err error) {
  234. o := orm.NewOrmUsingDB("weekly_report")
  235. if item.CountryCode == "" && len(item.Mobile) >= 11 {
  236. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=86 , country_code=86 WHERE user_id = ?`
  237. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  238. } else if item.CountryCode == "" && len(item.Mobile) == 8 {
  239. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=852 , country_code=852 WHERE user_id = ?`
  240. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  241. } else if item.CountryCode == "" && len(item.Mobile) == 9 {
  242. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=886 , country_code=886 WHERE user_id = ?`
  243. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  244. } else if item.CountryCode == "" && len(item.Mobile) == 10 {
  245. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=1 , country_code=1 WHERE user_id = ?`
  246. _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
  247. } else {
  248. sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=? WHERE user_id = ?`
  249. _, err = o.Raw(sql, item.Mobile, item.CountryCode, item.UserId).Exec()
  250. }
  251. return
  252. }
  253. // 判断公司下用户名称是否存在
  254. func GetUserCountByName(companyId int, name string) (count int, err error) {
  255. o := orm.NewOrmUsingDB("weekly_report")
  256. sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND real_name = ?`
  257. err = o.Raw(sql, companyId, name).QueryRow(&count)
  258. return
  259. }
  260. // 判断这个用户是否被设置消息提醒
  261. func GetUserRemind(uid int) (count int, err error) {
  262. o := orm.NewOrm()
  263. sql := `SELECT COUNT(1) AS count FROM cygx_user_remind WHERE user_id = ? `
  264. err = o.Raw(sql, uid).QueryRow(&count)
  265. return
  266. }
  267. // 判断公司下用户名称是否存在
  268. func GetUserCountByThirdName(companyId int, name string) (count int, err error) {
  269. o := orm.NewOrmUsingDB("weekly_report")
  270. sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND tripartite_code = ?`
  271. err = o.Raw(sql, companyId, name).QueryRow(&count)
  272. return
  273. }
  274. // 获取公司下一共有多少用户
  275. func GetUserCountByCompanyId(companyId int) (count int, err error) {
  276. o := orm.NewOrmUsingDB("weekly_report")
  277. sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? `
  278. err = o.Raw(sql, companyId).QueryRow(&count)
  279. return
  280. }
  281. func UpdateUserMobile(uid int, mobile string) (err error) {
  282. o := orm.NewOrmUsingDB("weekly_report")
  283. sql := ` UPDATE wx_user SET mobile=?
  284. WHERE user_id=? `
  285. _, err = o.Raw(sql, mobile, uid).Exec()
  286. return
  287. }
  288. // 获取公司下用户详情详情详情
  289. func GetUserByName(companyId int, name string) (item *WxUser, err error) {
  290. o := orm.NewOrmUsingDB("weekly_report")
  291. sql := `SELECT * FROM wx_user WHERE company_id = ? AND real_name = ? `
  292. err = o.Raw(sql, companyId, name).QueryRow(&item)
  293. return
  294. }
  295. // 获取公司下用户详情详情详情
  296. func GetUserByThirdName(companyId int, name string) (item *WxUser, err error) {
  297. o := orm.NewOrmUsingDB("weekly_report")
  298. sql := `SELECT * FROM wx_user WHERE company_id = ? AND tripartite_code = ? `
  299. err = o.Raw(sql, companyId, name).QueryRow(&item)
  300. return
  301. }
  302. // 获取所有注册的权益用户
  303. //func GetUserRegisterList() (items []*WxUser, err error) {
  304. // o := orm.NewOrmUsingDB("weekly_report")
  305. // sql := `SELECT
  306. // u.user_id,
  307. // u.company_id,
  308. // u.mobile,
  309. // u.email,
  310. // u.real_name,
  311. // u.is_register,
  312. // u.is_maker,
  313. // u.register_time
  314. // FROM
  315. // wx_user AS u
  316. // INNER JOIN company AS c ON c.company_id = u.company_id
  317. // INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  318. // WHERE
  319. // u.company_id IN (
  320. // SELECT
  321. // a.company_id
  322. // FROM
  323. // company AS a
  324. // INNER JOIN company_product AS b ON a.company_id = b.company_id
  325. // WHERE
  326. // a.enabled = 1
  327. // AND b.STATUS IN ( '正式', '试用', '冻结' )
  328. // AND cp.product_id = 2
  329. // )
  330. // AND cp.product_id = 2
  331. // GROUP BY
  332. // u.user_id `
  333. // _, err = o.Raw(sql).QueryRows(&items)
  334. // //AND u.register_time IS NOT NULL OR u.report_last_view_time <>'' 统计阅读时间与注册时间不为空的用户
  335. // return
  336. //}
  337. // 获取所有注册的权益用户
  338. func GetUserRegisterList() (items []*WxUser, err error) {
  339. o := orm.NewOrm()
  340. sql := `SELECT
  341. *
  342. FROM
  343. cygx_page_history_record
  344. WHERE
  345. user_id > 0
  346. AND company_id > 0
  347. AND create_time > DATE_SUB( DATE( NOW()), INTERVAL 1 DAY ) OR mobile = 18767183922
  348. GROUP BY user_id `
  349. _, err = o.Raw(sql).QueryRows(&items)
  350. return
  351. }
  352. type CygxCompanyUser struct {
  353. Labels string `description:"标签,用英文,隔开"`
  354. }
  355. type UserLabel struct {
  356. Label string `description:"标签 多个用 , 隔开"`
  357. }
  358. // 阅读记录
  359. type ArticlePvCountResp struct {
  360. ArticleId int `description:"文章ID"`
  361. Pv int `description:"Pv"`
  362. }
  363. func GetArticlePvCount(mobile, email, dateTime string) (item []*ArticlePvCountResp, err error) {
  364. o := orm.NewOrm()
  365. sql := `SELECT
  366. article_id,
  367. COUNT(article_id) as pv
  368. FROM
  369. cygx_article_history_record_newpv as h
  370. WHERE
  371. mobile = ?
  372. AND email = ?
  373. AND create_time >= ?
  374. GROUP BY article_id `
  375. _, err = o.Raw(sql, mobile, email, dateTime).QueryRows(&item)
  376. return
  377. }
  378. //产业名称
  379. type ArticleIndustryNameResp struct {
  380. ArticleId int `description:"文章ID"`
  381. IndustryName string `description:"产业名称"`
  382. SubjectName string `description:"标的名称"`
  383. }
  384. func GetArticleGroupyIndustryName(articleIds string) (item []*ArticleIndustryNameResp, err error) {
  385. o := orm.NewOrm()
  386. sql := `SELECT
  387. art.article_id,
  388. (
  389. SELECT
  390. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  391. FROM
  392. cygx_industrial_subject AS s
  393. WHERE
  394. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  395. ) AS subject_name,
  396. (
  397. SELECT
  398. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  399. FROM
  400. cygx_industrial_management AS man
  401. WHERE
  402. 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 )
  403. ) AS industry_name
  404. FROM
  405. cygx_article_history_record_newpv AS r
  406. INNER JOIN cygx_article AS art ON art.article_id = r.article_id
  407. LEFT JOIN cygx_report_mapping AS re ON re.category_id = art.category_id_two
  408. LEFT JOIN cygx_industrial_article_group_management AS man ON man.article_id = art.article_id
  409. WHERE
  410. art.article_id IN ( ` + articleIds + `) GROUP BY art.article_id `
  411. _, err = o.Raw(sql).QueryRows(&item)
  412. return
  413. }
  414. func GetCygxArticleCollectId(uid int, dateTime string) (articleIds string, err error) {
  415. sql := `SELECT
  416. GROUP_CONCAT( DISTINCT article_id SEPARATOR ',' ) AS permission
  417. FROM
  418. cygx_article_collect
  419. WHERE
  420. user_id = ?
  421. AND create_time >= ? `
  422. o := orm.NewOrm()
  423. err = o.Raw(sql, uid, dateTime).QueryRow(&articleIds)
  424. return
  425. }
  426. // 活动标签记录
  427. type ActivityLabelCountResp struct {
  428. Label string `description:"标签"`
  429. Pv int `description:"Pv"`
  430. }
  431. func GetActivitySignCount(mobile, dateTime string) (item []*ActivityLabelCountResp, err error) {
  432. o := orm.NewOrm()
  433. sql := `SELECT
  434. label ,
  435. COUNT( label ) AS pv
  436. FROM
  437. cygx_activity
  438. WHERE
  439. activity_id IN ( SELECT activity_id FROM cygx_activity_signup WHERE mobile = ? )
  440. AND label != ''
  441. AND activity_time >= ?
  442. AND is_submit_meeting = 1
  443. GROUP BY
  444. label`
  445. _, err = o.Raw(sql, mobile, dateTime).QueryRows(&item)
  446. return
  447. }
  448. type CygxUserInteractionNumDetail struct {
  449. UserId int64 `orm:"column(user_id);pk"`
  450. Mobile string `description:"手机号"`
  451. Email string `description:"邮箱"`
  452. CompanyId int `description:"公司id"`
  453. CompanyName string `description:"公司名称"`
  454. RealName string `description:"姓名"`
  455. CreatedTime string `description:"创建时间"`
  456. IsMaker int `description:"是否决策人,1:是,0:否"`
  457. IsRegister bool `description:"是否注册,true:已注册,false:未注册"`
  458. Status string `description:"客户状态"`
  459. RegisterTime string `description:"注册时间"`
  460. SellerName string `description:"销售名称"`
  461. InteractionNum int `description:"互动量"`
  462. Labels string `description:"标签,用英文,隔开"`
  463. ActivityLabel string `description:"活动标签,用英文,隔开"`
  464. IsShowSee bool `description:"是否展示查看"`
  465. IsShowSeeNum int `description:"是否展示查看"`
  466. HistoryNum int `description:"报告阅读"`
  467. CountNum int `description:"报告收藏"`
  468. ChartCountNum int `description:"图表收藏"`
  469. IndustryFllowNum int `description:"产业关注"`
  470. DepartmentFollowNum int `description:"作者关注"`
  471. KeyWordNum int `description:"搜索关键词"`
  472. OnLineNum int `description:"线上互动活动"`
  473. OfficeNum int `description:"线下互动活动"`
  474. TripNum int `description:"专项产业调研数量"`
  475. RoadshowVideoNum int `description:"产业视频播放量"`
  476. ActivityVideoNum int `description:"活动视频播放量"`
  477. ActivityVoiceNum int `description:"活动音频播放量"`
  478. TagNum int `description:"标签点击次数"`
  479. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  480. TryStage int `description:"试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"`
  481. }
  482. // GetWxUserListByUserIds 根据用户ID集合获取用户
  483. func GetWxUserListByUserIds(userIds string) (list []*WxUserItem, err error) {
  484. o := orm.NewOrmUsingDB("weekly_report")
  485. sql := ` SELECT u.*, c.company_name FROM wx_user AS u
  486. INNER JOIN company AS c ON c.company_id = u.company_id
  487. WHERE user_id IN (` + userIds + `) `
  488. _, err = o.Raw(sql).QueryRows(&list)
  489. return
  490. }
  491. // GetWxUserByMobiles 根据用户手机号获取用户详情
  492. func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
  493. lenmobiles := len(mobiles)
  494. if lenmobiles == 0 {
  495. return
  496. }
  497. sql := `SELECT* FROM wx_user WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
  498. o := orm.NewOrmUsingDB("weekly_report")
  499. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  500. return
  501. }
  502. // GetWxUserByMobiles 根据用户手机号获取用户详情
  503. func GetWxUserByOutboundMobiles(mobiles []string) (items []*WxUser, err error) {
  504. lenmobiles := len(mobiles)
  505. if lenmobiles == 0 {
  506. return
  507. }
  508. sql := `SELECT* FROM wx_user WHERE outbound_mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
  509. o := orm.NewOrmUsingDB("weekly_report")
  510. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  511. return
  512. }
  513. func UserSubscribe(subscribeTime string, userId int) (err error) {
  514. o := orm.NewOrmUsingDB("weekly_report")
  515. sql := `UPDATE wx_user SET cygx_subscribe=1,cygx_subscribe_time=? WHERE user_id = ? `
  516. _, err = o.Raw(sql, subscribeTime, userId).Exec()
  517. return
  518. }
  519. func GetWxUserOutboundMobiles(mobiles []string) (item []*WxUserOutboundMobile, err error) {
  520. lenmobiles := len(mobiles)
  521. if lenmobiles == 0 {
  522. return
  523. }
  524. o := orm.NewOrmUsingDB("weekly_report")
  525. 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
  526. FROM wx_user as u
  527. INNER JOIN company_product AS p ON p.company_id = u.company_id
  528. WHERE outbound_mobile IN(` + utils.GetOrmInReplace(lenmobiles) + `) OR mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) GROUP BY u.user_id`
  529. _, err = o.Raw(sql, mobiles, mobiles).QueryRows(&item)
  530. return
  531. }
  532. // GetWxUserListByUserIdsArr 根据用户ID集合获取用户
  533. func GetWxUserListByUserIdsArr(userIds []int) (list []*WxUserItem, err error) {
  534. lenArr := len(userIds)
  535. if lenArr == 0 {
  536. return
  537. }
  538. o := orm.NewOrmUsingDB("weekly_report")
  539. sql := ` SELECT u.*, c.company_name FROM wx_user AS u
  540. INNER JOIN company AS c ON c.company_id = u.company_id
  541. WHERE user_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  542. _, err = o.Raw(sql, userIds).QueryRows(&list)
  543. return
  544. }