user.go 21 KB

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