user.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/utils"
  7. "time"
  8. )
  9. type UserDetail struct {
  10. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  11. Mobile string `description:"手机号码"`
  12. Email string `description:"邮箱"`
  13. NickName string `description:"用户昵称"`
  14. RealName string `description:"用户实际名称"`
  15. CompanyName string `description:"公司名称"`
  16. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  17. HasPermission int `description:"1:无该行业权限,不存在权益客户下,2:潜在客户,未提交过申请,3:潜在客户,已提交过申请"`
  18. SellerMobile string `description:"销售手机号"`
  19. SellerName string `description:"销售名称"`
  20. Note string `json:"-" description:"申请提交时,公司名称"`
  21. CountryCode string `description:"区号"`
  22. OutboundMobile string `description:"外呼手机号"`
  23. OutboundCountryCode string `description:"外呼手机号区号"`
  24. ConNum int `description:"收藏"`
  25. HistoryNum int `description:"足迹"`
  26. ScheduleNum int `description:"活动日程"`
  27. }
  28. func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
  29. o := orm.NewOrmUsingDB("weekly_report")
  30. sql := `SELECT *
  31. FROM wx_user WHERE user_id = ? `
  32. err = o.Raw(sql, userId).QueryRow(&item)
  33. return
  34. }
  35. // 足迹数量
  36. func GetArticleUserHistoryNum(userId int) (count int, err error) {
  37. sql := `SELECT count(*) AS count FROM ( SELECT count(*) FROM cygx_article_history_record AS a WHERE a.user_id = ? GROUP BY a.article_id ) AS c `
  38. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  39. return
  40. }
  41. // 我的日程数量
  42. func GetArticleUserScheduleNum(userId int) (count int, err error) {
  43. sql := `SELECT COUNT( 1 ) AS count FROM cygx_my_schedule AS a INNER JOIN cygx_activity AS art ON art.activity_id = a.activity_id WHERE
  44. a.user_id = ? AND art.publish_status = 1 AND art.active_state != 3 `
  45. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  46. return
  47. }
  48. type UserPermission struct {
  49. CompanyName string `description:"公司名称"`
  50. ChartPermissionName string `description:"权限"`
  51. }
  52. type LoginReq struct {
  53. LoginType int `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
  54. Mobile string `description:"手机号"`
  55. Email string `description:"邮箱"`
  56. VCode string `description:"验证码"`
  57. CountryCode string `description:"区号"`
  58. ShareUserCode string `description:"分享人的分享码"`
  59. }
  60. func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {
  61. //loginType 登录方式:1:手机,2:邮箱
  62. o := orm.NewOrmUsingDB("weekly_report")
  63. sql := ``
  64. if loginType == 1 {
  65. sql = `SELECT * FROM wx_user WHERE mobile = ? `
  66. } else {
  67. sql = "SELECT * FROM wx_user WHERE email = ? "
  68. }
  69. user := new(WxUser)
  70. err = o.Raw(sql, mobile).QueryRow(&user)
  71. if err != nil && err.Error() != utils.ErrNoRow() {
  72. return
  73. }
  74. if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  75. msql := ``
  76. if loginType == 1 {
  77. msql = "UPDATE wx_user SET mobile = ?,bind_account = ? WHERE union_id = ? "
  78. } else {
  79. msql = "UPDATE wx_user SET email = ?,bind_account = ? WHERE union_id = ? "
  80. }
  81. _, err = o.Raw(msql, mobile, mobile, unionId).Exec()
  82. wxUserId = userId
  83. } else {
  84. if user.UnionId == "" {
  85. sql = `SELECT * FROM wx_user WHERE union_id = ? `
  86. userInfo := new(WxUser)
  87. o := orm.NewOrm()
  88. err = o.Raw(sql, unionId).QueryRow(&userInfo)
  89. if err != nil {
  90. return
  91. }
  92. var maxRegisterTime time.Time
  93. if user.RegisterTime.Before(userInfo.RegisterTime) {
  94. maxRegisterTime = user.RegisterTime
  95. } else {
  96. maxRegisterTime = userInfo.RegisterTime
  97. }
  98. wxUserId = user.UserId
  99. dsql := ` DELETE FROM wx_user WHERE union_id = ? `
  100. _, err = o.Raw(dsql, unionId).Exec()
  101. if err != nil {
  102. return wxUserId, err
  103. }
  104. msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  105. _, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  106. wxUserId = user.UserId
  107. } else {
  108. sql = `SELECT * FROM wx_user WHERE user_id = ? `
  109. userInfo := new(WxUser)
  110. o := orm.NewOrm()
  111. err = o.Raw(sql, userId).QueryRow(&userInfo)
  112. if err != nil && err.Error() != utils.ErrNoRow() {
  113. return
  114. }
  115. if user.UserId != userId {
  116. dsql := ` DELETE FROM wx_user WHERE user_id = ? `
  117. _, err = o.Raw(dsql, userId).Exec()
  118. if err != nil {
  119. return user.UserId, err
  120. }
  121. }
  122. msql := ` UPDATE wx_user SET union_id=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  123. _, err = o.Raw(msql, unionId, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  124. wxUserId = userId
  125. }
  126. }
  127. return
  128. }
  129. type LoginResp struct {
  130. UserId int `description:"用户id"`
  131. Authorization string `description:"Token"`
  132. Headimgurl string `description:"用户头像"`
  133. Mobile string `description:"手机号"`
  134. Email string `description:"邮箱"`
  135. CompanyName string `description:"客户名称"`
  136. Status string `description:"状态"`
  137. EndDate string `description:"到期日期"`
  138. ProductName string `description:"客户类型名称"`
  139. IsPotential bool `description:"是否是潜在"`
  140. }
  141. type CheckStatusResp struct {
  142. IsBind bool `description:"true:需要绑定手机号或邮箱,false:不需要绑定手机号或邮箱"`
  143. IsAuth bool `description:"true:需要授权,false:不需要授权"`
  144. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  145. }
  146. func GetArticleUserCollectCount(userId int) (count int, err error) {
  147. sql := `SELECT COUNT(1) AS count FROM cygx_article_collect AS a INNER JOIN cygx_article as art ON art.article_id = a.article_id WHERE a.user_id=? AND art.publish_status = 1 `
  148. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  149. return
  150. }
  151. func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleReportBillboardResp, err error) {
  152. sql := `SELECT a.*,art.category_id FROM cygx_article_collect AS a INNER JOIN cygx_article as art ON art.article_id = a.article_id
  153. WHERE a.user_id=?
  154. ORDER BY a.create_time DESC LIMIT ?,? `
  155. _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  156. return
  157. }
  158. type ArticleCollectListResp struct {
  159. List []*ArticleCollectList
  160. Paging *paging.PagingItem
  161. }
  162. func GetArticleUserInterviewApplyCount(userId int) (count int, err error) {
  163. sql := `SELECT COUNT(1) AS count FROM cygx_interview_apply AS a WHERE a.user_id=? `
  164. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  165. return
  166. }
  167. func GetArticleUserInterviewApplyList(startSize, pageSize, userId int) (items []*ArticleInterviewApplyList, err error) {
  168. sql := `SELECT a.* FROM cygx_interview_apply AS a
  169. WHERE a.user_id=?
  170. ORDER BY a.status ASC LIMIT ?,? `
  171. _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  172. return
  173. }
  174. type ArticleInterviewApplyListResp struct {
  175. List []*ArticleInterviewApplyList
  176. Paging *paging.PagingItem
  177. }
  178. func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) {
  179. sql := `SELECT COUNT( 1 ) as count
  180. FROM
  181. ( SELECT count(*) FROM cygx_article_history_record AS a WHERE a.user_id = ? AND a.create_time >= ? GROUP BY a.article_id ) b `
  182. err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count)
  183. return
  184. }
  185. func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleReportBillboardResp, err error) {
  186. sql := `SELECT a.* , MAX( a.id ) AS mid FROM cygx_article_history_record AS a
  187. WHERE a.user_id=? AND a.create_time>=? GROUP BY a.article_id
  188. ORDER BY mid DESC LIMIT ?,? `
  189. _, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items)
  190. return
  191. }
  192. type ArticleBrowseHistoryListResp struct {
  193. List []*ArticleInterviewApplyList
  194. Paging *paging.PagingItem
  195. }
  196. type ApplyTryReq struct {
  197. BusinessCardUrl string `description:"名片地址"`
  198. RealName string `description:"姓名"`
  199. CompanyName string `description:"公司名称"`
  200. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
  201. TryType string `description:"提交类型,Article:文章、Activity:活动、MicroAudio:微路演音频、MicroVideo:微路演视频、Researchsummary:本周研究汇总、Minutessummary:上周纪要汇总、ReportSelection:报告精选、ProductInterior:产品内测"`
  202. DetailId int `description:"详情ID"`
  203. }
  204. type CountryCode struct {
  205. IsNeedAddCountryCode bool `description:"是否需要填写区号:需要填写,false:不需要填写"`
  206. }
  207. type OutboundMobile struct {
  208. IsNeedAddOutboundMobile bool `description:"是否需要填写外呼手机号:需要填写,false:不需要填写"`
  209. }
  210. type CountryCodeItem struct {
  211. CountryCode string `description:"区号"`
  212. }
  213. func AddCountryCode(CountryCode string, user *WxUserItem) (err error) {
  214. o := orm.NewOrmUsingDB("weekly_report")
  215. if user.OutboundCountryCode == "" {
  216. sql := `UPDATE wx_user SET country_code=?,outbound_mobile=?,outbound_country_code=? WHERE user_id=? `
  217. _, err = o.Raw(sql, CountryCode, user.OutboundMobile, user.OutboundCountryCode, user.UserId).Exec()
  218. } else {
  219. sql := `UPDATE wx_user SET country_code=? WHERE user_id=? `
  220. _, err = o.Raw(sql, CountryCode, user.UserId).Exec()
  221. }
  222. return
  223. }
  224. // 修改外呼手机号
  225. type OutboundMobileItem struct {
  226. OutboundMobile string `description:"外呼手机号"`
  227. OutboundCountryCode string `description:"外呼手机号区号"`
  228. ActivityId int `description:"活动ID"`
  229. }
  230. func AddOutboundMobile(item *OutboundMobileItem, userId int) (err error) {
  231. o, err := orm.NewOrmUsingDB("weekly_report").Begin()
  232. if err != nil {
  233. return
  234. }
  235. defer func() {
  236. fmt.Println(err)
  237. if err == nil {
  238. o.Commit()
  239. } else {
  240. o.Rollback()
  241. }
  242. }()
  243. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, is_msg_outbound_mobile= 1 WHERE user_id=? `
  244. _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId).Exec()
  245. if err != nil {
  246. return
  247. }
  248. if item.ActivityId > 0 {
  249. sql = `UPDATE cygx_activity_signup SET outbound_mobile=? ,country_code = ? WHERE user_id=? AND activity_id = ?`
  250. _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId, item.ActivityId).Exec()
  251. }
  252. return
  253. }
  254. // 用户绑定手机号时同时绑定外呼手机号
  255. func BindUserOutboundMobile(mobile, countryCode string, userId int) (err error) {
  256. o := orm.NewOrmUsingDB("weekly_report")
  257. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, country_code= ? WHERE user_id=? `
  258. _, err = o.Raw(sql, mobile, countryCode, countryCode, userId).Exec()
  259. return
  260. }
  261. // 已经绑定手机号,没有绑定外呼手机号的的用户,预约外呼的时候,将外呼手机号同步成手机号
  262. func BindUserOutboundMobileByMobile(mobile, countryCode string, userId int) (err error) {
  263. o := orm.NewOrmUsingDB("weekly_report")
  264. sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? WHERE user_id=? `
  265. _, err = o.Raw(sql, mobile, countryCode, userId).Exec()
  266. return
  267. }
  268. // 将手机号为11位的用户,区号默认设置为86
  269. func ChangeUserOutboundMobileByMobile(userId int) (err error) {
  270. o := orm.NewOrmUsingDB("weekly_report")
  271. sql := `UPDATE wx_user SET country_code = 86 WHERE user_id=? `
  272. _, err = o.Raw(sql, userId).Exec()
  273. return
  274. }
  275. type UserWhiteList struct {
  276. Mobile string `description:"手机号码"`
  277. RealName string `description:"用户实际名称"`
  278. CompanyName string `description:"公司名称"`
  279. Permission string `description:"拥有权限分类,多个用英文逗号分隔"`
  280. CountryCode string `description:"区号"`
  281. SellerName string `description:"销售姓名"`
  282. CreatedTime time.Time
  283. Status string `description:"客户状态'试用','永续','冻结','流失','正式','潜在'"`
  284. }
  285. type UserWhiteListRep struct {
  286. List []*UserWhiteList
  287. }
  288. // 获取正式试用用户白名单
  289. func GetFormalUserWhiteList(fieldStr, condition string) (items []*UserWhiteList, err error) {
  290. o := orm.NewOrmUsingDB("weekly_report")
  291. sql := `SELECT ` + fieldStr + `
  292. (SELECT cp.seller_name FROM company_product AS cp WHERE cp.company_id = u.company_id ORDER BY cp.product_id DESC LIMIT 0,1 ) as seller_name,
  293. GROUP_CONCAT( DISTINCT b.chart_permission_name SEPARATOR '/' ) AS permission
  294. FROM wx_user AS u
  295. INNER JOIN company as c ON c.company_id = u.company_id
  296. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  297. INNER JOIN chart_permission AS b ON b.chart_permission_id=p.chart_permission_id
  298. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  299. WHERE 1= 1
  300. AND cp.product_id = 2
  301. AND b.product_id = 2
  302. AND u.company_id >1 ` + condition + `
  303. GROUP BY u.user_id`
  304. _, err = o.Raw(sql).QueryRows(&items)
  305. return
  306. }
  307. // 获取永续用户白名单
  308. func GetSustainableUserWhiteList(fieldStr, condition string) (items []*UserWhiteList, err error) {
  309. o := orm.NewOrmUsingDB("weekly_report")
  310. sql := `SELECT ` + fieldStr + `
  311. (SELECT cp.seller_name FROM company_product AS cp WHERE cp.company_id = u.company_id ORDER BY cp.product_id DESC LIMIT 0,1 ) as seller_name,
  312. (SELECT
  313. GROUP_CONCAT( DISTINCT b.chart_permission_name SEPARATOR '/' )
  314. FROM
  315. company_report_permission AS p
  316. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  317. WHERE
  318. p.company_id = u.company_id
  319. AND p.status IN ( '永续' )
  320. AND p.product_id = 2
  321. ) AS permission
  322. FROM wx_user AS u
  323. INNER JOIN company AS c ON c.company_id = u.company_id
  324. INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
  325. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  326. INNER JOIN company_product AS cp ON cp.company_id = u.company_id
  327. WHERE 1 = 1
  328. AND u.company_id > 1 ` + condition + `
  329. GROUP BY u.user_id `
  330. _, err = o.Raw(sql).QueryRows(&items)
  331. return
  332. }
  333. // 权益用户
  334. type GetSendEmailAllUserWithRAIRep struct {
  335. CompanyName string `description:"客户名称"`
  336. CreditCode string `description:"社会统一信用码"`
  337. ProductName string `description:"客户类型"`
  338. IndustryName string `description:"行业"`
  339. RealName string `description:"姓名"`
  340. Mobile string `description:"手机号"`
  341. Status string `description:"手机号"`
  342. StartDate string `description:"合同开始日期"`
  343. EndDate string `description:"合同结束日期"`
  344. CreatedTime string `description:"创建时间"`
  345. Permission string `description:"权限"`
  346. }
  347. func GetSendEmailAllUserWithRAI() (items []*GetSendEmailAllUserWithRAIRep, err error) {
  348. o := orm.NewOrmUsingDB("weekly_report")
  349. sql := `SELECT
  350. c.company_name,
  351. c.credit_code,
  352. cp.product_name,
  353. cp.industry_name,
  354. a.real_name,
  355. a.mobile,
  356. cp.status,
  357. cp.start_date,
  358. cp.end_date,
  359. c.created_time,
  360. GROUP_CONCAT( DISTINCT b.chart_permission_name SEPARATOR '/' ) AS permission
  361. FROM
  362. company AS c
  363. INNER JOIN company_report_permission AS p ON p.company_id = c.company_id
  364. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  365. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  366. INNER JOIN admin AS a ON a.admin_id = cp.seller_id
  367. WHERE
  368. 1 = 1
  369. AND cp.product_id = 2
  370. AND b.product_id = 2
  371. AND cp.status IN ( '正式', '试用' )
  372. GROUP BY
  373. c.company_id
  374. ORDER BY
  375. c.company_id DESC`
  376. _, err = o.Raw(sql).QueryRows(&items)
  377. return
  378. }
  379. // 权益用户
  380. type GetSendEmailAllUserWithCompanyRep struct {
  381. RealName string `description:"姓名"`
  382. Mobile string `description:"手机号"`
  383. CountryCode string `description:"国家号"`
  384. Email string `description:"邮箱"`
  385. CompanyName string `description:"客户名称"`
  386. CreditCode string `description:"社会统一信用码"`
  387. IsMaker string `description:"是否是决策人,1是,0否"`
  388. }
  389. func GetSendEmailAllUserWithCompany() (items []*GetSendEmailAllUserWithCompanyRep, err error) {
  390. o := orm.NewOrmUsingDB("weekly_report")
  391. sql := `SELECT
  392. u.real_name,
  393. u.mobile,
  394. u.country_code,
  395. u.email,
  396. c.company_name,
  397. u.is_maker
  398. FROM
  399. no_use AS n
  400. INNER JOIN company AS c ON c.company_name = n.company_name
  401. INNER JOIN company_report_permission AS p ON p.company_id = c.company_id
  402. INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
  403. INNER JOIN company_product AS cp ON cp.company_id = c.company_id
  404. INNER JOIN wx_user AS u ON u.company_id = c.company_id
  405. GROUP BY
  406. u.user_id
  407. ORDER BY
  408. c.company_id ASC`
  409. _, err = o.Raw(sql).QueryRows(&items)
  410. return
  411. }
  412. type Headimgurl struct {
  413. Headimgurl string `description:"用户头像"`
  414. }
  415. type UserEmail struct {
  416. Email string `description:"邮箱号"`
  417. }
  418. // 更改用户手机号
  419. func UpdateUserHeadimgurl(headimgurl string, userId int) (err error) {
  420. o := orm.NewOrmUsingDB("weekly_report")
  421. sql := `UPDATE wx_user SET headimgurl = ? WHERE user_id=? `
  422. _, err = o.Raw(sql, headimgurl, userId).Exec()
  423. return
  424. }
  425. // 更改用户邮箱号
  426. func UpdateUserEmail(email string, userId int) (err error) {
  427. o := orm.NewOrmUsingDB("weekly_report")
  428. sql := `UPDATE wx_user SET email = ? WHERE user_id=? `
  429. _, err = o.Raw(sql, email, userId).Exec()
  430. return
  431. }
  432. // 更新用户标签
  433. func UpdateUserLabel(userLabel string, userId int) (err error) {
  434. o := orm.NewOrmUsingDB("weekly_report")
  435. sql := `UPDATE wx_user SET user_label = ? WHERE user_id=? `
  436. _, err = o.Raw(sql, userLabel, userId).Exec()
  437. return
  438. }
  439. // 更新用户互动量
  440. func UpdateUserInteractionNum(interactionNum, userId int) (err error) {
  441. o := orm.NewOrmUsingDB("weekly_report")
  442. sql := `UPDATE wx_user SET interaction_num = ? WHERE user_id=? `
  443. _, err = o.Raw(sql, interactionNum, userId).Exec()
  444. return
  445. }
  446. // UserPermissionAuthInfo 用户通用权限信息
  447. type UserPermissionAuthInfo struct {
  448. HasPermission int `description:"是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限"`
  449. SellerMobile string `description:"销售手机号"`
  450. SellerName string `description:"销售名称"`
  451. OperationMode string `description:"操作方式:Apply-立即申请; Call-拨号"`
  452. PopupMsg string `description:"权限弹窗信息"`
  453. }
  454. func GetUserMicroRoadshowCollectList(userId int) (items []*CygxArticleCollect, err error) {
  455. sql := `SELECT a.* FROM cygx_article_collect AS a
  456. WHERE a.user_id=?
  457. AND a.article_id =0
  458. ORDER BY a.create_time DESC `
  459. _, err = orm.NewOrm().Raw(sql, userId).QueryRows(&items)
  460. return
  461. }
  462. func GetUserMicroRoadshowCollectcount(userId int) (count int, err error) {
  463. sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_collect AS a
  464. WHERE a.user_id=?
  465. AND a.article_id =0
  466. ORDER BY a.create_time DESC `
  467. o := orm.NewOrm()
  468. err = o.Raw(sqlCount, userId).QueryRow(&count)
  469. return
  470. }