user.go 22 KB

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