user.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_web_mfyx/utils"
  6. "time"
  7. )
  8. type UserDetail struct {
  9. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  10. Mobile string `description:"手机号码"`
  11. Email string `description:"邮箱"`
  12. NickName string `description:"用户昵称"`
  13. RealName string `description:"用户实际名称"`
  14. CompanyName string `description:"公司名称"`
  15. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  16. HasPermission int `description:"1:无该行业权限,不存在权益客户下,2:潜在客户,未提交过申请,3:潜在客户,已提交过申请"`
  17. SellerMobile string `description:"销售手机号"`
  18. SellerName string `description:"销售名称"`
  19. Note string `json:"-" description:"申请提交时,公司名称"`
  20. CountryCode string `description:"区号"`
  21. OutboundMobile string `description:"外呼手机号"`
  22. OutboundCountryCode string `description:"外呼手机号区号"`
  23. }
  24. func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
  25. o := orm.NewOrmUsingDB("weekly_report")
  26. sql := `SELECT * FROM wx_user WHERE user_id = ? `
  27. err = o.Raw(sql, userId).QueryRow(&item)
  28. return
  29. }
  30. func GetUserDetailByMobile(mobile string) (item *UserDetail, err error) {
  31. o := orm.NewOrmUsingDB("weekly_report")
  32. sql := `SELECT * FROM wx_user WHERE mobile = ? `
  33. err = o.Raw(sql, mobile).QueryRow(&item)
  34. return
  35. }
  36. type UserPermission struct {
  37. CompanyName string `description:"公司名称"`
  38. ChartPermissionName string `description:"权限"`
  39. }
  40. type LoginReq struct {
  41. Mobile string `description:"手机号"`
  42. VCode string `description:"验证码"`
  43. Token string `description:"微信扫码登录之后返回的Token"`
  44. InviteShareCode string `description:"销售账号邀请码"`
  45. Password string `comment:"密码"`
  46. LoginType string `comment:"登录方式 2 密码登录,其他不用传"`
  47. }
  48. type WxBindMobileReq struct {
  49. Mobile string `description:"手机号"`
  50. VCode string `description:"验证码"`
  51. //Token string `description:"Token"`
  52. }
  53. func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {
  54. //loginType 登录方式:1:手机,2:邮箱
  55. sql := ``
  56. if loginType == 1 {
  57. sql = `SELECT * FROM wx_user WHERE mobile = ? `
  58. } else {
  59. sql = "SELECT * FROM wx_user WHERE email = ? "
  60. }
  61. user := new(WxUser)
  62. o := orm.NewOrmUsingDB("weekly_report")
  63. err = o.Raw(sql, mobile).QueryRow(&user)
  64. if err != nil && err.Error() != utils.ErrNoRow() {
  65. return
  66. }
  67. if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  68. msql := ``
  69. if loginType == 1 {
  70. msql = "UPDATE wx_user SET mobile = ?,bind_account = ? WHERE union_id = ? "
  71. } else {
  72. msql = "UPDATE wx_user SET email = ?,bind_account = ? WHERE union_id = ? "
  73. }
  74. _, err = o.Raw(msql, mobile, mobile, unionId).Exec()
  75. wxUserId = userId
  76. } else {
  77. if user.UnionId == "" {
  78. sql = `SELECT * FROM wx_user WHERE union_id = ? `
  79. userInfo := new(WxUser)
  80. o := orm.NewOrm()
  81. err = o.Raw(sql, unionId).QueryRow(&userInfo)
  82. if err != nil {
  83. return
  84. }
  85. var maxRegisterTime time.Time
  86. if user.RegisterTime.Before(userInfo.RegisterTime) {
  87. maxRegisterTime = user.RegisterTime
  88. } else {
  89. maxRegisterTime = userInfo.RegisterTime
  90. }
  91. wxUserId = user.UserId
  92. dsql := ` DELETE FROM wx_user WHERE union_id = ? `
  93. _, err = o.Raw(dsql, unionId).Exec()
  94. if err != nil {
  95. return wxUserId, err
  96. }
  97. msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  98. _, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  99. wxUserId = user.UserId
  100. } else {
  101. sql = `SELECT * FROM wx_user WHERE user_id = ? `
  102. userInfo := new(WxUser)
  103. o := orm.NewOrm()
  104. err = o.Raw(sql, userId).QueryRow(&userInfo)
  105. if err != nil && err.Error() != utils.ErrNoRow() {
  106. return
  107. }
  108. if user.UserId != userId {
  109. dsql := ` DELETE FROM wx_user WHERE user_id = ? `
  110. _, err = o.Raw(dsql, userId).Exec()
  111. if err != nil {
  112. return user.UserId, err
  113. }
  114. }
  115. msql := ` UPDATE wx_user SET union_id=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  116. _, err = o.Raw(msql, unionId, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  117. wxUserId = userId
  118. }
  119. }
  120. return
  121. }
  122. type LoginResp struct {
  123. UserId int `description:"用户id"`
  124. Authorization string `description:"Token"`
  125. Headimgurl string `description:"用户头像"`
  126. Mobile string `description:"手机号"`
  127. Email string `description:"邮箱"`
  128. CompanyName string `description:"客户名称"`
  129. LoginErrCode int `description:"错误状态自定义,1:是专栏作者,但是还没设置登录密码"`
  130. }
  131. type UserDetailResp struct {
  132. UserId int `description:"用户id"`
  133. UserName string `description:"用户名称"`
  134. Headimgurl string `description:"用户头像"`
  135. Mobile string `description:"手机号"`
  136. Email string `description:"邮箱"`
  137. CompanyName string `description:"客户名称"`
  138. OutboundMobile string `description:"外呼手机号"`
  139. OutboundCountryCode string `description:"外呼手机号区号"`
  140. PermissionName []string `description:"拥有权限分类"`
  141. PermissionStatus string `description:"状态"`
  142. StartDate string `description:"开始日期"`
  143. EndDate string `description:"结束日期"`
  144. CompanyPointsNum float64 `description:"公司剩余点数"`
  145. HasPermission int `description:"1:有该行业权限,正常展示"`
  146. IsAuthor bool `description:"是否开通了研选专栏"`
  147. SpecialColumnId int // 专栏栏目ID
  148. IsImproveInformation bool `description:"作者信息是否完善"`
  149. InviteShareCode string `description:"销售账号邀请码"`
  150. UserCardType int `description:"权益卡类型,0:未开通、1日卡、2月卡"`
  151. UserCardEndDate string `description:"权益卡有效期"`
  152. IsShowWxPaySet bool `description:"是否展示微信支付全局设置"` // 配合前端支付进入详情页使用
  153. IsSetPassword bool `description:"是否设置了登录密码"`
  154. }
  155. type CheckStatusResp struct {
  156. IsBind bool `description:"true:需要绑定手机号或邮箱,false:不需要绑定手机号或邮箱"`
  157. IsAuth bool `description:"true:需要授权,false:不需要授权"`
  158. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  159. }
  160. type ApplyTryReq struct {
  161. BusinessCardUrl string `description:"名片地址"`
  162. RealName string `description:"姓名"`
  163. CompanyName string `description:"公司名称"`
  164. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
  165. TryType string `description:"提交类型,Article:文章、Activity:活动、MicroAudio:微路演音频、MicroVideo:微路演视频、Researchsummary:本周研究汇总、Minutessummary:上周纪要汇总、ReportSelection:报告精选、ProductInterior:产品内测"`
  166. DetailId int `description:"详情ID"`
  167. }
  168. type CountryCode struct {
  169. IsNeedAddCountryCode bool `description:"是否需要填写区号:需要填写,false:不需要填写"`
  170. }
  171. type OutboundMobile struct {
  172. IsNeedAddOutboundMobile bool `description:"是否需要填写外呼手机号:需要填写,false:不需要填写"`
  173. }
  174. type CountryCodeItem struct {
  175. CountryCode string `description:"区号"`
  176. }
  177. // 修改外呼手机号
  178. type OutboundMobileItem struct {
  179. OutboundMobile string `description:"外呼手机号"`
  180. OutboundCountryCode string `description:"外呼手机号区号"`
  181. }
  182. type UserWhiteList struct {
  183. Mobile string `description:"手机号码"`
  184. RealName string `description:"用户实际名称"`
  185. CompanyName string `description:"公司名称"`
  186. Permission string `description:"拥有权限分类,多个用英文逗号分隔"`
  187. CountryCode string `description:"区号"`
  188. SellerName string `description:"销售姓名"`
  189. CreatedTime time.Time
  190. Status string `description:"客户状态'试用','永续','冻结','流失','正式','潜在'"`
  191. }
  192. type UserWhiteListRep struct {
  193. List []*UserWhiteList
  194. }
  195. type UserDetailByUserLogin struct {
  196. Headimgurl string `description:"头像"`
  197. Mobile string `description:"手机号码"`
  198. RealName string `description:"用户实际名称"`
  199. CompanyName string `description:"公司名称"`
  200. Permission string `description:"拥有权限分类,多个用英文逗号分隔"`
  201. HasPermission int `description:"1:有该行业权限,正常展示,2:无权限,非潜在客户,3:潜在客户"`
  202. Token string `description:"Token"`
  203. }
  204. func GetCompanyPermission(companyId int) (permission string, err error) {
  205. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  206. FROM company_report_permission AS a
  207. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  208. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  209. WHERE a.company_id=?
  210. AND c.is_suspend=0
  211. AND b.cygx_auth=1
  212. AND c.status IN('正式','试用','永续')
  213. AND a.status IN('正式','试用','永续') `
  214. o := orm.NewOrmUsingDB("weekly_report")
  215. err = o.Raw(sql, companyId).QueryRow(&permission)
  216. return
  217. }
  218. func GetCompanyPermissionName(companyId int) (permission string, err error) {
  219. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',') AS permission
  220. FROM company_report_permission AS a
  221. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  222. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  223. WHERE a.company_id=?
  224. AND c.is_suspend=0
  225. AND b.cygx_auth=1
  226. AND c.status IN('正式','试用','永续')
  227. AND a.status IN('正式','试用','永续') `
  228. o := orm.NewOrmUsingDB("weekly_report")
  229. err = o.Raw(sql, companyId).QueryRow(&permission)
  230. return
  231. }
  232. func GetCompanyPermissionId(companyId int) (permissionId string, err error) {
  233. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_id ORDER BY b.sort ASC SEPARATOR ',') AS permissionId
  234. FROM company_report_permission AS a
  235. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  236. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  237. WHERE a.company_id=?
  238. AND c.is_suspend=0
  239. AND b.cygx_auth=1
  240. AND c.status IN('正式','试用','永续')
  241. AND a.status IN('正式','试用','永续') `
  242. o := orm.NewOrmUsingDB("weekly_report")
  243. err = o.Raw(sql, companyId).QueryRow(&permissionId)
  244. return
  245. }
  246. // 用户绑定手机号时同时绑定外呼手机号
  247. func BindUserOutboundMobile(mobile, countryCode string, userId int) (err error) {
  248. o := orm.NewOrmUsingDB("weekly_report")
  249. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, country_code= ? WHERE user_id=? `
  250. _, err = o.Raw(sql, mobile, countryCode, countryCode, userId).Exec()
  251. return
  252. }
  253. type UserPermissionAuthInfo struct {
  254. HasPermission int `description:"是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限"`
  255. SellerMobile string `description:"销售手机号"`
  256. SellerName string `description:"销售名称"`
  257. OperationMode string `description:"操作方式:Apply-立即申请; Call-拨号"`
  258. PopupMsg string `description:"权限弹窗信息"`
  259. }
  260. // 修改用户是否绑定外呼手机号弹窗
  261. func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
  262. o := orm.NewOrmUsingDB("weekly_report")
  263. sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
  264. _, err = o.Raw(sql, userId).Exec()
  265. return
  266. }
  267. // 已经绑定手机号,没有绑定外呼手机号的的用户,预约外呼的时候,将外呼手机号同步成手机号
  268. func BindUserOutboundMobileByMobile(mobile, countryCode string, userId int) (err error) {
  269. o := orm.NewOrmUsingDB("weekly_report")
  270. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? WHERE user_id=? `
  271. _, err = o.Raw(sql, mobile, countryCode, userId).Exec()
  272. return
  273. }
  274. // GetWxUserByMobiles 根据用户手机号获取用户详情
  275. func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
  276. lenmobiles := len(mobiles)
  277. if lenmobiles == 0 {
  278. return
  279. }
  280. sql := `SELECT* FROM wx_user WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
  281. o := orm.NewOrmUsingDB("weekly_report")
  282. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  283. return
  284. }
  285. func GetUserCompanyPermissionSand(companyId int) (items []*ChartPermissionResp, err error) {
  286. sql := ` SELECT b.*
  287. FROM company_report_permission AS a
  288. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  289. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  290. WHERE a.company_id=?
  291. AND a.product_id=2
  292. AND c.is_suspend=0
  293. AND b.cygx_auth=1
  294. AND b.is_other=0
  295. AND c.status IN('正式','试用','永续')
  296. AND a.status IN('正式','试用','永续')
  297. AND b.chart_permission_name != '专家'
  298. GROUP BY b.chart_permission_name
  299. ORDER BY b.sort ASC `
  300. o := orm.NewOrmUsingDB("weekly_report")
  301. _, err = o.Raw(sql, companyId).QueryRows(&items)
  302. return
  303. }
  304. func AddOutboundMobile(item *OutboundMobileItem, userId int) (err error) {
  305. o, err := orm.NewOrmUsingDB("weekly_report").Begin()
  306. if err != nil {
  307. return
  308. }
  309. defer func() {
  310. fmt.Println(err)
  311. if err == nil {
  312. o.Commit()
  313. } else {
  314. o.Rollback()
  315. }
  316. }()
  317. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, is_msg_outbound_mobile= 1 WHERE user_id=? `
  318. _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId).Exec()
  319. if err != nil {
  320. return
  321. }
  322. //if item.ActivityId > 0 {
  323. // sql = `UPDATE cygx_activity_signup SET outbound_mobile=? ,country_code = ? WHERE user_id=? AND activity_id = ?`
  324. // _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId, item.ActivityId).Exec()
  325. //}
  326. return
  327. }
  328. type Headimgurl struct {
  329. Headimgurl string `description:"用户头像"`
  330. }
  331. // 更改用户头像
  332. func UpdateUserHeadimgurl(headimgurl string, userId int) (err error) {
  333. o := orm.NewOrmUsingDB("weekly_report")
  334. sql := `UPDATE wx_user SET headimgurl = ? WHERE user_id=? `
  335. _, err = o.Raw(sql, headimgurl, userId).Exec()
  336. return
  337. }
  338. // 更改用户邮箱号
  339. func UpdateUserEmail(email string, userId int) (err error) {
  340. o := orm.NewOrmUsingDB("weekly_report")
  341. sql := `UPDATE wx_user SET email = ? WHERE user_id=? `
  342. _, err = o.Raw(sql, email, userId).Exec()
  343. return
  344. }
  345. func GetArticleUserCollectCount(userId int) (count int, err error) {
  346. sql := `SELECT SUM(count) AS count FROM (
  347. SELECT COUNT(1) AS count FROM cygx_article_collect AS a
  348. INNER JOIN cygx_article as art ON art.article_id = a.article_id
  349. WHERE a.user_id=? AND art.publish_status = 1 AND art.article_type_id > 0
  350. UNION ALL
  351. SELECT COUNT(1) AS count FROM cygx_yanxuan_special_collect AS a
  352. INNER JOIN cygx_yanxuan_special as b ON b.id = a.yanxuan_special_id
  353. WHERE a.user_id=? AND b.status = 3) AS c
  354. `
  355. err = orm.NewOrm().Raw(sql, userId, userId).QueryRow(&count)
  356. return
  357. }
  358. //art.article_id,
  359. //art.article_type_id,
  360. //art.title,
  361. //art.publish_date,
  362. //'' AS company_tags,
  363. //'' AS industry_tags,
  364. //art.department_id,
  365. //d.nick_name,
  366. //0 AS is_special,
  367. //0 as pv,
  368. //0 as collect_num,
  369. //a.create_time
  370. //FROM
  371. //cygx_article AS art
  372. //INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id
  373. //INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id
  374. //WHERE
  375. //a.user_id = ?
  376. //AND a.create_time >= ?
  377. //AND art.article_type_id > 0
  378. //GROUP BY
  379. //art.article_id UNION ALL
  380. //SELECT
  381. //art.id AS article_id,
  382. //- 1 AS article_type_id,
  383. //art.title,
  384. //art.publish_time AS publish_date,
  385. //art.company_tags AS company_tags,
  386. //art.industry_tags AS industry_tags,
  387. //d.id AS department_id,
  388. //d.nick_name,
  389. //1 AS is_special,
  390. //art.pv,
  391. //art.article_collect_num as collect_num,
  392. //a.create_time
  393. func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
  394. sql := `SELECT
  395. art.article_id,
  396. art.article_type_id,
  397. art.title,
  398. art.publish_date,
  399. '' AS company_tags,
  400. '' AS industry_tags,
  401. art.department_id,
  402. d.nick_name,
  403. 0 AS is_special,
  404. 0 as pv,
  405. 0 as collect_num,
  406. a.create_time
  407. FROM
  408. cygx_article AS art
  409. INNER JOIN cygx_article_collect as a ON art.article_id = a.article_id
  410. INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id
  411. WHERE a.user_id=?
  412. AND art.article_type_id > 0
  413. UNION ALL
  414. SELECT
  415. art.id AS article_id,
  416. - 1 AS article_type_id,
  417. art.title,
  418. art.publish_time AS publish_date,
  419. art.company_tags AS company_tags,
  420. art.industry_tags AS industry_tags,
  421. b.id AS department_id,
  422. b.nick_name,
  423. 1 AS is_special,
  424. art.pv,
  425. art.article_collect_num as collect_num,
  426. c.create_time
  427. FROM
  428. cygx_yanxuan_special AS art
  429. JOIN cygx_yanxuan_special_author AS b ON art.user_id = b.user_id
  430. JOIN cygx_yanxuan_special_collect AS c ON art.id = c.yanxuan_special_id
  431. WHERE
  432. 1 = 1 AND art.status = 3 AND c.user_id=?
  433. ORDER BY create_time DESC
  434. LIMIT ?,? `
  435. _, err = orm.NewOrm().Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
  436. return
  437. }
  438. func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) {
  439. sql := `SELECT COUNT( 1 ) as count
  440. FROM
  441. ( SELECT count(*) FROM cygx_article as art INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id AND article_type_id > 0 WHERE a.user_id = ? AND a.create_time >= ? GROUP BY a.article_id ) b `
  442. err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count)
  443. return
  444. }
  445. //func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleReportBillboardResp, err error) {
  446. // sql := `SELECT a.* , MAX( a.id ) AS mid FROM cygx_article as art INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id AND article_type_id > 0
  447. // WHERE a.user_id=? AND a.create_time>=? GROUP BY a.article_id
  448. // ORDER BY mid DESC LIMIT ?,? `
  449. // _, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items)
  450. // return
  451. //}
  452. func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleListResp, err error) {
  453. sql := `SELECT
  454. art.article_id,
  455. art.article_type_id,
  456. art.title,
  457. art.publish_date,
  458. '' AS company_tags,
  459. '' AS industry_tags,
  460. art.department_id,
  461. d.nick_name,
  462. 0 AS is_special,
  463. 0 as pv,
  464. 0 as collect_num,
  465. a.create_time
  466. FROM
  467. cygx_article AS art
  468. INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id
  469. INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id
  470. WHERE
  471. a.user_id = ?
  472. AND a.create_time >= ?
  473. AND art.article_type_id > 0
  474. GROUP BY
  475. art.article_id UNION ALL
  476. SELECT
  477. art.id AS article_id,
  478. - 1 AS article_type_id,
  479. art.title,
  480. art.publish_time AS publish_date,
  481. art.company_tags AS company_tags,
  482. art.industry_tags AS industry_tags,
  483. d.id AS department_id,
  484. d.nick_name,
  485. 1 AS is_special,
  486. art.pv,
  487. art.article_collect_num as collect_num,
  488. a.create_time
  489. FROM
  490. cygx_yanxuan_special AS art
  491. INNER JOIN cygx_yanxuan_special_record AS a ON art.id = a.yanxuan_special_id
  492. INNER JOIN cygx_yanxuan_special_author AS d ON d.user_id = art.user_id
  493. WHERE
  494. a.user_id = ?
  495. AND a.create_time >= ?
  496. GROUP BY
  497. art.id
  498. ORDER BY
  499. create_time DESC
  500. LIMIT ?,? `
  501. _, err = orm.NewOrm().Raw(sql, userId, endDate, userId, endDate, startSize, pageSize).QueryRows(&items)
  502. return
  503. }
  504. func GetUserMicroRoadshowCollectList(userId int) (items []*CygxArticleCollect, err error) {
  505. sql := `SELECT a.* FROM cygx_article_collect AS a
  506. WHERE a.user_id=?
  507. AND a.article_id =0
  508. ORDER BY a.create_time DESC `
  509. _, err = orm.NewOrm().Raw(sql, userId).QueryRows(&items)
  510. return
  511. }
  512. type UserEmail struct {
  513. Email string `description:"邮箱号"`
  514. }