user.go 21 KB

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