user.go 22 KB

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