user.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. }
  148. type CheckStatusResp struct {
  149. IsBind bool `description:"true:需要绑定手机号或邮箱,false:不需要绑定手机号或邮箱"`
  150. IsAuth bool `description:"true:需要授权,false:不需要授权"`
  151. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  152. }
  153. type ApplyTryReq struct {
  154. BusinessCardUrl string `description:"名片地址"`
  155. RealName string `description:"姓名"`
  156. CompanyName string `description:"公司名称"`
  157. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
  158. TryType string `description:"提交类型,Article:文章、Activity:活动、MicroAudio:微路演音频、MicroVideo:微路演视频、Researchsummary:本周研究汇总、Minutessummary:上周纪要汇总、ReportSelection:报告精选、ProductInterior:产品内测"`
  159. DetailId int `description:"详情ID"`
  160. }
  161. type CountryCode struct {
  162. IsNeedAddCountryCode bool `description:"是否需要填写区号:需要填写,false:不需要填写"`
  163. }
  164. type OutboundMobile struct {
  165. IsNeedAddOutboundMobile bool `description:"是否需要填写外呼手机号:需要填写,false:不需要填写"`
  166. }
  167. type CountryCodeItem struct {
  168. CountryCode string `description:"区号"`
  169. }
  170. // 修改外呼手机号
  171. type OutboundMobileItem struct {
  172. OutboundMobile string `description:"外呼手机号"`
  173. OutboundCountryCode string `description:"外呼手机号区号"`
  174. }
  175. type UserWhiteList struct {
  176. Mobile string `description:"手机号码"`
  177. RealName string `description:"用户实际名称"`
  178. CompanyName string `description:"公司名称"`
  179. Permission string `description:"拥有权限分类,多个用英文逗号分隔"`
  180. CountryCode string `description:"区号"`
  181. SellerName string `description:"销售姓名"`
  182. CreatedTime time.Time
  183. Status string `description:"客户状态'试用','永续','冻结','流失','正式','潜在'"`
  184. }
  185. type UserWhiteListRep struct {
  186. List []*UserWhiteList
  187. }
  188. type UserDetailByUserLogin struct {
  189. Headimgurl string `description:"头像"`
  190. Mobile string `description:"手机号码"`
  191. RealName string `description:"用户实际名称"`
  192. CompanyName string `description:"公司名称"`
  193. Permission string `description:"拥有权限分类,多个用英文逗号分隔"`
  194. HasPermission int `description:"1:有该行业权限,正常展示,2:无权限,非潜在客户,3:潜在客户"`
  195. Token string `description:"Token"`
  196. }
  197. func GetCompanyPermission(companyId int) (permission string, err error) {
  198. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  199. FROM company_report_permission AS a
  200. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  201. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  202. WHERE a.company_id=?
  203. AND c.is_suspend=0
  204. AND b.cygx_auth=1
  205. AND c.status IN('正式','试用','永续')
  206. AND a.status IN('正式','试用','永续') `
  207. o := orm.NewOrmUsingDB("weekly_report")
  208. err = o.Raw(sql, companyId).QueryRow(&permission)
  209. return
  210. }
  211. func GetCompanyPermissionName(companyId int) (permission string, err error) {
  212. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',') AS permission
  213. FROM company_report_permission AS a
  214. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  215. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  216. WHERE a.company_id=?
  217. AND c.is_suspend=0
  218. AND b.cygx_auth=1
  219. AND c.status IN('正式','试用','永续')
  220. AND a.status IN('正式','试用','永续') `
  221. o := orm.NewOrmUsingDB("weekly_report")
  222. err = o.Raw(sql, companyId).QueryRow(&permission)
  223. return
  224. }
  225. func GetCompanyPermissionId(companyId int) (permissionId string, err error) {
  226. sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_id ORDER BY b.sort ASC SEPARATOR ',') AS permissionId
  227. FROM company_report_permission AS a
  228. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  229. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  230. WHERE a.company_id=?
  231. AND c.is_suspend=0
  232. AND b.cygx_auth=1
  233. AND c.status IN('正式','试用','永续')
  234. AND a.status IN('正式','试用','永续') `
  235. o := orm.NewOrmUsingDB("weekly_report")
  236. err = o.Raw(sql, companyId).QueryRow(&permissionId)
  237. return
  238. }
  239. // 用户绑定手机号时同时绑定外呼手机号
  240. func BindUserOutboundMobile(mobile, countryCode string, userId int) (err error) {
  241. o := orm.NewOrmUsingDB("weekly_report")
  242. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, country_code= ? WHERE user_id=? `
  243. _, err = o.Raw(sql, mobile, countryCode, countryCode, userId).Exec()
  244. return
  245. }
  246. type UserPermissionAuthInfo struct {
  247. HasPermission int `description:"是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限"`
  248. SellerMobile string `description:"销售手机号"`
  249. SellerName string `description:"销售名称"`
  250. OperationMode string `description:"操作方式:Apply-立即申请; Call-拨号"`
  251. PopupMsg string `description:"权限弹窗信息"`
  252. }
  253. // 修改用户是否绑定外呼手机号弹窗
  254. func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
  255. o := orm.NewOrmUsingDB("weekly_report")
  256. sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
  257. _, err = o.Raw(sql, userId).Exec()
  258. return
  259. }
  260. // 已经绑定手机号,没有绑定外呼手机号的的用户,预约外呼的时候,将外呼手机号同步成手机号
  261. func BindUserOutboundMobileByMobile(mobile, countryCode string, userId int) (err error) {
  262. o := orm.NewOrmUsingDB("weekly_report")
  263. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? WHERE user_id=? `
  264. _, err = o.Raw(sql, mobile, countryCode, userId).Exec()
  265. return
  266. }
  267. // GetWxUserByMobiles 根据用户手机号获取用户详情
  268. func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
  269. lenmobiles := len(mobiles)
  270. if lenmobiles == 0 {
  271. return
  272. }
  273. sql := `SELECT* FROM wx_user WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
  274. o := orm.NewOrmUsingDB("weekly_report")
  275. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  276. return
  277. }
  278. func GetUserCompanyPermissionSand(companyId int) (items []*ChartPermissionResp, err error) {
  279. sql := ` SELECT b.*
  280. FROM company_report_permission AS a
  281. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  282. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  283. WHERE a.company_id=?
  284. AND a.product_id=2
  285. AND c.is_suspend=0
  286. AND b.cygx_auth=1
  287. AND b.is_other=0
  288. AND c.status IN('正式','试用','永续')
  289. AND a.status IN('正式','试用','永续')
  290. AND b.chart_permission_name != '专家'
  291. GROUP BY b.chart_permission_name
  292. ORDER BY b.sort ASC `
  293. o := orm.NewOrmUsingDB("weekly_report")
  294. _, err = o.Raw(sql, companyId).QueryRows(&items)
  295. return
  296. }
  297. func AddOutboundMobile(item *OutboundMobileItem, userId int) (err error) {
  298. o, err := orm.NewOrmUsingDB("weekly_report").Begin()
  299. if err != nil {
  300. return
  301. }
  302. defer func() {
  303. fmt.Println(err)
  304. if err == nil {
  305. o.Commit()
  306. } else {
  307. o.Rollback()
  308. }
  309. }()
  310. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, is_msg_outbound_mobile= 1 WHERE user_id=? `
  311. _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId).Exec()
  312. if err != nil {
  313. return
  314. }
  315. //if item.ActivityId > 0 {
  316. // sql = `UPDATE cygx_activity_signup SET outbound_mobile=? ,country_code = ? WHERE user_id=? AND activity_id = ?`
  317. // _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId, item.ActivityId).Exec()
  318. //}
  319. return
  320. }
  321. type Headimgurl struct {
  322. Headimgurl string `description:"用户头像"`
  323. }
  324. // 更改用户头像
  325. func UpdateUserHeadimgurl(headimgurl string, userId int) (err error) {
  326. o := orm.NewOrmUsingDB("weekly_report")
  327. sql := `UPDATE wx_user SET headimgurl = ? WHERE user_id=? `
  328. _, err = o.Raw(sql, headimgurl, userId).Exec()
  329. return
  330. }
  331. // 更改用户邮箱号
  332. func UpdateUserEmail(email string, userId int) (err error) {
  333. o := orm.NewOrmUsingDB("weekly_report")
  334. sql := `UPDATE wx_user SET email = ? WHERE user_id=? `
  335. _, err = o.Raw(sql, email, userId).Exec()
  336. return
  337. }
  338. func GetArticleUserCollectCount(userId int) (count int, err error) {
  339. sql := `SELECT SUM(count) AS count FROM (
  340. SELECT COUNT(1) AS count FROM cygx_article_collect AS a
  341. INNER JOIN cygx_article as art ON art.article_id = a.article_id
  342. WHERE a.user_id=? AND art.publish_status = 1 AND art.article_type_id > 0
  343. UNION ALL
  344. SELECT COUNT(1) AS count FROM cygx_yanxuan_special_collect AS a
  345. INNER JOIN cygx_yanxuan_special as b ON b.id = a.yanxuan_special_id
  346. WHERE a.user_id=? AND b.status = 3) AS c
  347. `
  348. err = orm.NewOrm().Raw(sql, userId, userId).QueryRow(&count)
  349. return
  350. }
  351. //art.article_id,
  352. //art.article_type_id,
  353. //art.title,
  354. //art.publish_date,
  355. //'' AS company_tags,
  356. //'' AS industry_tags,
  357. //art.department_id,
  358. //d.nick_name,
  359. //0 AS is_special,
  360. //0 as pv,
  361. //0 as collect_num,
  362. //a.create_time
  363. //FROM
  364. //cygx_article AS art
  365. //INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id
  366. //INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id
  367. //WHERE
  368. //a.user_id = ?
  369. //AND a.create_time >= ?
  370. //AND art.article_type_id > 0
  371. //GROUP BY
  372. //art.article_id UNION ALL
  373. //SELECT
  374. //art.id AS article_id,
  375. //- 1 AS article_type_id,
  376. //art.title,
  377. //art.publish_time AS publish_date,
  378. //art.company_tags AS company_tags,
  379. //art.industry_tags AS industry_tags,
  380. //d.id AS department_id,
  381. //d.nick_name,
  382. //1 AS is_special,
  383. //art.pv,
  384. //art.article_collect_num as collect_num,
  385. //a.create_time
  386. func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
  387. sql := `SELECT
  388. art.article_id,
  389. art.article_type_id,
  390. art.title,
  391. art.publish_date,
  392. '' AS company_tags,
  393. '' AS industry_tags,
  394. art.department_id,
  395. d.nick_name,
  396. 0 AS is_special,
  397. 0 as pv,
  398. 0 as collect_num,
  399. a.create_time
  400. FROM
  401. cygx_article AS art
  402. INNER JOIN cygx_article_collect as a ON art.article_id = a.article_id
  403. INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id
  404. WHERE a.user_id=?
  405. AND art.article_type_id > 0
  406. UNION ALL
  407. SELECT
  408. art.id AS article_id,
  409. - 1 AS article_type_id,
  410. art.title,
  411. art.publish_time AS publish_date,
  412. art.company_tags AS company_tags,
  413. art.industry_tags AS industry_tags,
  414. b.id AS department_id,
  415. b.nick_name,
  416. 1 AS is_special,
  417. art.pv,
  418. art.article_collect_num as collect_num,
  419. c.create_time
  420. FROM
  421. cygx_yanxuan_special AS art
  422. JOIN cygx_yanxuan_special_author AS b ON art.user_id = b.user_id
  423. JOIN cygx_yanxuan_special_collect AS c ON art.id = c.yanxuan_special_id
  424. WHERE
  425. 1 = 1 AND art.status = 3 AND c.user_id=?
  426. ORDER BY create_time DESC
  427. LIMIT ?,? `
  428. _, err = orm.NewOrm().Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
  429. return
  430. }
  431. func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) {
  432. sql := `SELECT COUNT( 1 ) as count
  433. FROM
  434. ( 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 `
  435. err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count)
  436. return
  437. }
  438. //func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleReportBillboardResp, err error) {
  439. // 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
  440. // WHERE a.user_id=? AND a.create_time>=? GROUP BY a.article_id
  441. // ORDER BY mid DESC LIMIT ?,? `
  442. // _, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items)
  443. // return
  444. //}
  445. func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleListResp, err error) {
  446. sql := `SELECT
  447. art.article_id,
  448. art.article_type_id,
  449. art.title,
  450. art.publish_date,
  451. '' AS company_tags,
  452. '' AS industry_tags,
  453. art.department_id,
  454. d.nick_name,
  455. 0 AS is_special,
  456. 0 as pv,
  457. 0 as collect_num,
  458. a.create_time
  459. FROM
  460. cygx_article AS art
  461. INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id
  462. INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id
  463. WHERE
  464. a.user_id = ?
  465. AND a.create_time >= ?
  466. AND art.article_type_id > 0
  467. GROUP BY
  468. art.article_id UNION ALL
  469. SELECT
  470. art.id AS article_id,
  471. - 1 AS article_type_id,
  472. art.title,
  473. art.publish_time AS publish_date,
  474. art.company_tags AS company_tags,
  475. art.industry_tags AS industry_tags,
  476. d.id AS department_id,
  477. d.nick_name,
  478. 1 AS is_special,
  479. art.pv,
  480. art.article_collect_num as collect_num,
  481. a.create_time
  482. FROM
  483. cygx_yanxuan_special AS art
  484. INNER JOIN cygx_yanxuan_special_record AS a ON art.id = a.yanxuan_special_id
  485. INNER JOIN cygx_yanxuan_special_author AS d ON d.user_id = art.user_id
  486. WHERE
  487. a.user_id = ?
  488. AND a.create_time >= ?
  489. GROUP BY
  490. art.id
  491. ORDER BY
  492. create_time DESC
  493. LIMIT ?,? `
  494. _, err = orm.NewOrm().Raw(sql, userId, endDate, userId, endDate, startSize, pageSize).QueryRows(&items)
  495. return
  496. }
  497. func GetUserMicroRoadshowCollectList(userId int) (items []*CygxArticleCollect, err error) {
  498. sql := `SELECT a.* FROM cygx_article_collect AS a
  499. WHERE a.user_id=?
  500. AND a.article_id =0
  501. ORDER BY a.create_time DESC `
  502. _, err = orm.NewOrm().Raw(sql, userId).QueryRows(&items)
  503. return
  504. }