user.go 20 KB

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