user.go 21 KB

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