company_user.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. package company
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/utils"
  7. "time"
  8. )
  9. // 新增客户请求参数
  10. type AddUserReq struct {
  11. RealName string `description:"姓名"`
  12. Sex int `description:"用户性别,1为男性,2为女性"`
  13. Source string `description:"来源,新增客户时添加:add_custom;领取客户时添加:pick_custom;普通领取联系人时添加:add_user"`
  14. RegionType string `description:"区域,枚举值:国内、海外"`
  15. CountryCode string `description:"区号,86、852、886等"`
  16. MobileOne string `description:"手机号1"`
  17. MobileTwo string `description:"手机号2"`
  18. Email string `description:"邮箱"`
  19. Position string `description:"职位"`
  20. IsMaker int `description:"是否决策人,1:是,0:否"`
  21. BusinessCardUrl string `description:"名片地址"`
  22. CompanyId int `description:"客户id"`
  23. DepartmentName string `description:"联系人部门"`
  24. CompanyName string `description:"客户名称(公司名称)"`
  25. }
  26. type CompanyUser struct {
  27. UserId int64 `orm:"column(user_id);pk"`
  28. CountryCode string `description:"区号,86、852、886等"`
  29. Mobile string `description:"手机号"`
  30. Email string `description:"邮箱"`
  31. CompanyId int `description:"公司id"`
  32. CompanyName string `description:"公司名称"`
  33. RealName string `description:"姓名"`
  34. CreatedTime string `description:"创建时间"`
  35. MobileTwo string `description:"备用手机号"`
  36. BusinessCardUrl string `description:"名片地址"`
  37. IsMaker int `description:"是否决策人,1:是,0:否"`
  38. Position string `description:"职位"`
  39. Sex int `description:"普通用户性别,1为男性,2为女性"`
  40. IsRegister bool `description:"是否注册,true:已注册,false:未注册"`
  41. OpenId string `json:"-"`
  42. DepartmentName string `description:"联系人部门"`
  43. SellerRealName string `description:"销售"`
  44. Status string `description:"客户状态"`
  45. HasMove bool `description:"true:可移动,false:显示知道了"`
  46. ViewTotal int `description:"累计阅读次数"`
  47. LastViewTime time.Time `json:"-" description:"最后一次阅读时间"`
  48. LastViewTimeStr string `description:"最后一次阅读时间"`
  49. ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
  50. RegisterTime string `description:"注册时间"`
  51. RegisterPlatform int `description:"注册平台,1:微信端,2:网页端"`
  52. SellerId int `description:"销售id"`
  53. SellerName string `description:"销售名称"`
  54. GroupId int `description:"所属销售分组id"`
  55. DepartmentId int `description:"所属销售分组id"`
  56. IsShared bool `description:"是否共享联系人"`
  57. ProductIds string `description:"商品权限集合,用英文,隔开"`
  58. IsChartPermissionSetting int `description:"是否设置过图表权限, 0-未设置,1-已设置,2-无需设置"`
  59. YbProductViewTotal int `description:"研报分产品阅读统计"`
  60. IsSubscribe int `description:"是否关注了微信公众号: 0-未关注; 1-已关注"`
  61. IsFollow int `description:"是否特别关注: 0-未关注; 1-已关注"`
  62. IsSubscribeHzyj int `description:"是否关注了弘则研究微信公众号: 0-未关注; 1-已关注"`
  63. IsSubscribeCygx int `description:"是否关注了查研观向微信公众号: 0-未关注; 1-已关注"`
  64. FiccViewTotal int `description:"ficc报告的阅读次数" json:"-"`
  65. FiccLastViewTime time.Time `description:"ficc报告最近一次阅读时间" json:"-"`
  66. RaiViewTotal int `description:"权益报告的阅读次数" json:"-"`
  67. RaiLastViewTime time.Time `description:"权益报告的最近一次阅读时间" json:"-"`
  68. NotRead bool `description:"是否七天内未阅读"`
  69. MfyxStartDate string `description:"买方研选权限开始日期"`
  70. MfyxEndDate string `description:"买方研选权限结束日期"`
  71. MfyxStatus string `description:"买方研选状态'试用','未开通'"`
  72. MfyxInteractionNum int `description:"互动量"`
  73. MfyxIsBinding bool `description:"买方研选是否绑定"`
  74. MfyxBindingTime string `description:"买方研选绑定时间"`
  75. HaveMoveButton bool `description:"是否移动过"`
  76. }
  77. type CompanyUserListResp struct {
  78. Paging *paging.PagingItem
  79. List []*CompanyUser
  80. }
  81. // 联系人数量总数返回数据结构体
  82. type CompanyUserTotal struct {
  83. Total int `description:"联系人总数"`
  84. }
  85. func GetCompanyUserListCount(condition string, pars []interface{}, companyId int) (count int, err error) {
  86. o := orm.NewOrm()
  87. sql := ` SELECT COUNT(1) AS count FROM wx_user AS a WHERE company_id=? `
  88. if condition != "" {
  89. sql += condition
  90. }
  91. err = o.Raw(sql, companyId, pars).QueryRow(&count)
  92. return
  93. }
  94. func GetCompanyUserList(condition string, pars []interface{}, companyId, startSize, pageSize int) (items []*CompanyUser, err error) {
  95. o := orm.NewOrm()
  96. sql := ` SELECT a.*,b.company_name,
  97. (SELECT count(1) FROM user_view_history AS uvh WHERE uvh.user_id=a.user_id GROUP BY a.user_id) AS view_total,
  98. (SELECT max(uvh.created_time) FROM user_view_history AS uvh WHERE uvh.user_id=a.user_id GROUP BY a.user_id) AS last_view_time
  99. FROM wx_user AS a
  100. INNER JOIN company AS b ON a.company_id=b.company_id
  101. WHERE a.company_id=? `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. sql += `ORDER BY a.last_updated_time DESC LIMIT ?,? `
  106. _, err = o.Raw(sql, companyId, pars, startSize, pageSize).QueryRows(&items)
  107. return
  108. }
  109. // 获取该用户下联系人数量(跟销售绑定,2021年03月09日16:35:11)
  110. func GetCompanyUserListCountV2(condition string, pars []interface{}, companyId int) (count int, err error) {
  111. o := orm.NewOrm()
  112. tmpSql := `SELECT
  113. a.*, c.subscribe AS is_subscribe
  114. FROM
  115. wx_user AS a
  116. LEFT JOIN user_seller_relation AS b ON a.user_id = b.user_id
  117. LEFT JOIN (SELECT * FROM user_record WHERE create_platform = 1 GROUP BY user_id) AS c ON a.user_id = c.user_id
  118. WHERE
  119. a.company_id = ? `
  120. if condition != "" {
  121. tmpSql += condition
  122. }
  123. sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + ` group by a.user_id) AS c `
  124. err = o.Raw(sql, companyId, pars).QueryRow(&count)
  125. return
  126. }
  127. // 获取该用户下联系人切片列表(跟销售绑定,2021年03月09日16:35:11)
  128. func GetCompanyUserListV2(condition string, pars []interface{}, companyId, startSize, pageSize int) (items []*CompanyUser, err error) {
  129. o := orm.NewOrm()
  130. sql := `SELECT
  131. a.*, a.cygx_subscribe as is_subscribe_cygx, c.subscribe AS is_subscribe_hzyj
  132. FROM
  133. wx_user AS a
  134. LEFT JOIN user_seller_relation AS b ON a.user_id = b.user_id
  135. LEFT JOIN (SELECT * FROM user_record WHERE create_platform = 1 GROUP BY user_id) AS c ON a.user_id = c.user_id
  136. WHERE
  137. a.company_id = ? `
  138. if condition != "" {
  139. sql += condition
  140. }
  141. sql += ` group by a.user_id ORDER BY CASE WHEN is_follow = 1 AND (report_last_view_time < NOW() - INTERVAL 7 DAY or report_last_view_time is NULL ) THEN 0 ELSE 1 END,a.report_last_view_time desc,a.last_updated_time DESC LIMIT ?,? `
  142. //sql += ` group by a.user_id ORDER BY CASE WHEN is_follow = 1 AND (report_last_view_time < NOW() - INTERVAL 7 DAY or report_last_view_time is NULL ) THEN 0 ELSE 1 END,a.is_register desc,a.report_last_view_time ASC,a.last_updated_time ASC LIMIT ?,? `
  143. _, err = o.Raw(sql, companyId, pars, startSize, pageSize).QueryRows(&items)
  144. return
  145. }
  146. // GetCompanyUserListById 获取该用户下联系人切片列表
  147. func GetCompanyUserListById(companyId int) (items []*CompanyUser, err error) {
  148. o := orm.NewOrm()
  149. sql := ` SELECT a.* FROM wx_user AS a WHERE a.company_id=? `
  150. _, err = o.Raw(sql, companyId).QueryRows(&items)
  151. return
  152. }
  153. // 删除客户请求参数
  154. type DeleteUserReq struct {
  155. UserId int `orm:"column(user_id);pk"`
  156. }
  157. func DeleteCompanyUser(userId int) (err error) {
  158. o := orm.NewOrm()
  159. sql := ` DELETE FROM wx_user WHERE user_id=? `
  160. _, err = o.Raw(sql, userId).Exec()
  161. return
  162. }
  163. // 新增客户请求参数
  164. type EditUserReq struct {
  165. UserId int `orm:"column(user_id);pk"`
  166. RealName string `description:"姓名"`
  167. Sex int `description:"用户性别,1为男性,2为女性"`
  168. CountryCode string `description:"区号,86、852、886等"`
  169. MobileOne string `description:"手机号1"`
  170. MobileTwo string `description:"手机号2"`
  171. Email string `description:"邮箱"`
  172. Position string `description:"职位"`
  173. IsMaker int `description:"是否决策人,1:是,0:否"`
  174. BusinessCardUrl string `description:"名片地址"`
  175. CompanyId int `description:"客户id"`
  176. DepartmentName string `description:"联系人部门"`
  177. }
  178. func EditCompanyUser(item *EditUserReq) (err error) {
  179. o := orm.NewOrm()
  180. sql := ` UPDATE wx_user
  181. SET
  182. real_name=?,
  183. mobile= ?,
  184. email = ?,
  185. sex = ?,
  186. last_updated_time = NOW(),
  187. position = ?,
  188. is_maker = ?,
  189. business_card_url = ?,
  190. mobile_two= ?,
  191. department_name=?,
  192. company_id=?,country_code=?
  193. WHERE user_id = ? `
  194. _, err = o.Raw(sql, item.RealName, item.MobileOne, item.Email, item.Sex, item.Position, item.IsMaker, item.BusinessCardUrl, item.MobileTwo, item.DepartmentName, item.CompanyId, item.CountryCode, item.UserId).Exec()
  195. return
  196. }
  197. // 修改联系人的联系方式
  198. func EditCompanyUserContact(userId int64, mobileOne, mobileTwo, email, businessCardUrl string) (err error) {
  199. o := orm.NewOrm()
  200. sql := ` UPDATE wx_user
  201. SET
  202. mobile= ?,
  203. mobile_two= ?,
  204. email = ?,
  205. business_card_url = ?,
  206. last_updated_time = NOW()
  207. WHERE user_id = ? `
  208. _, err = o.Raw(sql, mobileOne, mobileTwo, email, businessCardUrl, userId).Exec()
  209. return
  210. }
  211. func GetCompanyIdByKeyWord(keyWord string) (company_id string, err error) {
  212. o := orm.NewOrm()
  213. sql := ` SELECT GROUP_CONCAT(DISTINCT company_id) AS company_id FROM wx_user WHERE mobile LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%'`
  214. err = o.Raw(sql).QueryRow(&company_id)
  215. return
  216. }
  217. func GetCompanyIdByKeyWordAll(keyWord string) (company_id string, err error) {
  218. o := orm.NewOrm()
  219. sql := ` SELECT GROUP_CONCAT(DISTINCT company_id) AS company_id FROM wx_user WHERE mobile LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' `
  220. err = o.Raw(sql).QueryRow(&company_id)
  221. return
  222. }
  223. func GetCompanyUserCount(companyId int) (count int, err error) {
  224. o := orm.NewOrm()
  225. sql := ` SELECT COUNT(1) AS count FROM wx_user WHERE company_id =? `
  226. err = o.Raw(sql, companyId).QueryRow(&count)
  227. return
  228. }
  229. func CheckCompanyUserCountByMobileTwo(mobileTwo string) (item *CompanyUser, err error) {
  230. o := orm.NewOrm()
  231. sql := ` SELECT a.*,b.company_name,GROUP_CONCAT(DISTINCT d.real_name SEPARATOR '/') AS seller_real_name,GROUP_CONCAT(DISTINCT c.status SEPARATOR '/') AS status
  232. FROM wx_user AS a
  233. LEFT JOIN company AS b ON a.company_id=b.company_id
  234. LEFT JOIN company_product AS c ON b.company_id=c.company_id
  235. LEFT JOIN admin AS d ON c.seller_id=d.admin_id
  236. WHERE a.mobile_two =? GROUP BY a.company_id `
  237. err = o.Raw(sql, mobileTwo).QueryRow(&item)
  238. return
  239. }
  240. func CheckCompanyUserCountByEmail(email string) (item *CompanyUser, err error) {
  241. o := orm.NewOrm()
  242. sql := ` SELECT a.*,b.company_name,GROUP_CONCAT(DISTINCT d.real_name SEPARATOR '/') AS seller_real_name,GROUP_CONCAT(DISTINCT c.status SEPARATOR '/') AS status
  243. FROM wx_user AS a
  244. LEFT JOIN company AS b ON a.company_id=b.company_id
  245. LEFT JOIN company_product AS c ON b.company_id=c.company_id
  246. LEFT JOIN admin AS d ON c.seller_id=d.admin_id
  247. WHERE a.email =? GROUP BY a.company_id `
  248. err = o.Raw(sql, email).QueryRow(&item)
  249. return
  250. }
  251. func GetUserCountByMobile(mobile string) (item *CompanyUser, err error) {
  252. o := orm.NewOrm()
  253. sql := ` SELECT a.*,b.company_name,GROUP_CONCAT(DISTINCT d.real_name SEPARATOR '/') AS seller_real_name,GROUP_CONCAT(DISTINCT c.status SEPARATOR '/') AS status
  254. FROM wx_user AS a
  255. LEFT JOIN company AS b ON a.company_id=b.company_id
  256. LEFT JOIN company_product AS c ON b.company_id=c.company_id
  257. LEFT JOIN admin AS d ON c.seller_id=d.admin_id
  258. WHERE a.mobile=? GROUP BY a.company_id `
  259. err = o.Raw(sql, mobile).QueryRow(&item)
  260. return
  261. }
  262. //<template slot-scope="scope">{{scope.row.ReportType=='day'?'晨报':scope.row.ReportType=='week'?'周报':scope.row.ReportType=='twoweek'?'双周报':scope.row.ReportType=='month'?'月报':scope.row.ReportType=='rddp'?'日度点评':scope.row.ReportType=='cygx'?'查研观向':scope.row.ReportType=='advisory'?'每日商品聚焦':''}}</template>
  263. type ViewReportList struct {
  264. ResearchReportName string `description:"报告标题"`
  265. ReportType string `description:"报告类型 'day 晨报'、'week 周报'、'twoweek 双周报'、'month 月报'、'rddp 日度点评'、'cygx 查研观向'、'advisory 每日商品聚焦'"`
  266. CreatedTime string `description:"创建时间"`
  267. TxtType string `description:"类型 ficc:ficc 、 rights:权益"`
  268. MatchTypeName string `description:"匹配类型"`
  269. StopTime string `description:"停留时间"`
  270. }
  271. type ViewReportListResp struct {
  272. Total int `description:"数量"`
  273. List []*ViewReportList
  274. }
  275. func ModifyCompanyUserCompanyId(userId, companyId int) (err error) {
  276. o := orm.NewOrm()
  277. sql := ` UPDATE wx_user SET company_id=? WHERE user_id=? `
  278. _, err = o.Raw(sql, companyId, userId).Exec()
  279. return
  280. }
  281. func GetCompanyUserBusinessCardCount(companyId int) (count int, err error) {
  282. o := orm.NewOrm()
  283. sql := ` SELECT COUNT(1) AS count FROM wx_user WHERE company_id =? AND business_card_url<>'' `
  284. err = o.Raw(sql, companyId).QueryRow(&count)
  285. return
  286. }
  287. // 标记用户
  288. func DealCompanyUser(userId int) (err error) {
  289. o := orm.NewOrm()
  290. sql := ` UPDATE wx_user SET is_deal=1 WHERE user_id=? `
  291. _, err = o.Raw(sql, userId).Exec()
  292. return
  293. }
  294. type CompanyActivityUser struct {
  295. UserId int64
  296. Mobile string `description:"手机号"`
  297. Email string `description:"邮箱"`
  298. CompanyId int `description:"公司id"`
  299. CompanyName string `description:"公司名称"`
  300. RealName string `description:"姓名"`
  301. }
  302. // GetNoPotentialCompanyUserList 获取不是潜在客户的联系人列表
  303. func GetNoPotentialCompanyUserList(condition string, pars []interface{}) (items []*CompanyActivityUser, err error) {
  304. o := orm.NewOrm()
  305. sql := ` SELECT a.user_id,a.mobile,a.email,a.company_id,a.real_name,b.company_name FROM wx_user AS a
  306. INNER JOIN company AS b ON a.company_id=b.company_id WHERE a.company_id>1 `
  307. if condition != "" {
  308. sql += condition
  309. }
  310. sql += `ORDER BY a.last_updated_time DESC `
  311. _, err = o.Raw(sql, pars).QueryRows(&items)
  312. return
  313. }
  314. // GetFiccCompanyUserByUserIds 批量查询用户的购买ficc的产品详情
  315. func GetFiccCompanyUserByUserIds(userIds string) (list []*CompanyUser, err error) {
  316. o := orm.NewOrm()
  317. sql := ` SELECT a.user_id, a.real_name, if(b.company_id=1,"",b.company_name) as company_name, c.status, b.company_id, c.seller_name
  318. FROM wx_user AS a
  319. LEFT JOIN company AS b ON a.company_id=b.company_id
  320. LEFT JOIN company_product AS c ON a.company_id=c.company_id and c.product_id=1
  321. WHERE a.user_id in (` + userIds + `)`
  322. _, err = o.Raw(sql).QueryRows(&list)
  323. return
  324. }
  325. // UserImportMatchResp 联系人名单导入匹配响应体
  326. type UserImportMatchResp struct {
  327. List []*UserImportMatch `description:"名单列表"`
  328. Code string `description:"下载名单的code"`
  329. }
  330. // UserImportMatch 联系人名单导入匹配
  331. type UserImportMatch struct {
  332. UserName string `description:"姓名"`
  333. CountryCode string `description:"国际(区号)"`
  334. Mobile string `description:"手机号"`
  335. CompanyName string `description:"导入的客户名称"`
  336. SysCompanyName string `description:"系统匹配的客户名称"`
  337. FiccStatus string `descripiton:"FICC状态"`
  338. FiccSeller string `description:"FICC销售"`
  339. RaiStatus string `description:"权益状态"`
  340. RaiSeller string `description:"权益销售"`
  341. }
  342. // GetCompanyUsersByCondition 获取联系人列表
  343. func GetCompanyUsersByCondition(condition string, pars []interface{}) (list []*CompanyUser, err error) {
  344. sql := `SELECT * FROM wx_user WHERE 1 = 1 `
  345. if condition != `` {
  346. sql += condition
  347. }
  348. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  349. return
  350. }
  351. type ViewReportListV2 struct {
  352. Id int `description:"阅读记录id"`
  353. UserId int `description:"用户id"`
  354. Mobile string `description:"手机号"`
  355. Email string `description:"邮箱"`
  356. RealName string `description:"真实姓名"`
  357. CompanyName string `description:"客户名称"`
  358. ResearchReportName string `description:"报告标题"`
  359. ReportType int8 `description:"来源:1:rddp的报告;2:weekly_report的PHP报告;3:weekly_report商品的报告(应该是作废了);4:察研观向的报告""`
  360. CreatedTime string `description:"创建时间"`
  361. TxtType string `description:"类型 ficc:ficc 、 rights:权益"`
  362. MatchTypeName string `description:"匹配类型"`
  363. StopTime int `description:"停留时间"`
  364. ReportId int `description:"报告id"`
  365. ReportChapterId int `description:"报告章节id"`
  366. }
  367. func GetViewReportListByDate(startDate, endDate string) (items []*ViewReportListV2, err error) {
  368. dataName := ""
  369. sql := ``
  370. if utils.RunMode == "debug" {
  371. dataName = "test_v2_hongze_rddp"
  372. } else {
  373. dataName = "hongze_rddp"
  374. }
  375. ficcSql := `SELECT
  376. uvh.user_id,uvh.mobile,uvh.email,uvh.view_history_id AS id,uvh.real_name,uvh.company_name,
  377. uvh.research_report_id as report_id,
  378. uvh.research_report_type_id as report_chapter_id,
  379. rr.research_report_name,
  380. "2" AS report_type,
  381. 'ficc' AS txt_type,
  382. '--' AS match_type_name,
  383. '0' AS stop_time,
  384. uvh.created_time AS created_time
  385. FROM
  386. user_view_history uvh
  387. LEFT JOIN research_report rr ON rr.research_report_id = uvh.research_report_id
  388. WHERE
  389. uvh.created_time >= ? AND uvh.created_time< ?
  390. UNION ALL
  391. SELECT
  392. rvr.user_id,rvr.mobile,rvr.email,rvr.id,rvr.real_name,rvr.company_name,
  393. rvr.report_id,
  394. rvr.report_chapter_id,
  395. r.title AS research_report_name,
  396. '1' AS report_type,
  397. 'ficc' AS txt_type,
  398. r.classify_name_first AS match_type_name,
  399. '0' AS stop_time,
  400. rvr.create_time AS created_time
  401. FROM %s.report_view_record rvr
  402. LEFT JOIN %s.report r ON r.id = rvr.report_id
  403. WHERE
  404. rvr.create_time >= ? AND rvr.create_time< ?
  405. UNION ALL
  406. SELECT
  407. auc.user_id,auc.mobile,auc.email,auc.id,auc.real_name,auc.company_name,
  408. auc.chart_permission_id as report_id,
  409. '0' AS report_chapter_id,
  410. cha.permission_name AS research_report_name,
  411. '3' AS report_type,
  412. 'ficc' AS txt_type,
  413. cha.classify_name AS match_type_name,
  414. '0' AS stop_time,
  415. auc.create_time AS created_time
  416. FROM
  417. advisory_user_chart_article_record auc
  418. LEFT JOIN chart_permission cha ON cha.chart_permission_id = auc.chart_permission_id
  419. WHERE
  420. auc.create_time >= ? AND auc.create_time< ?`
  421. rightsSql := `SELECT
  422. h.user_id,h.mobile,h.email,h.id,h.company_name,'' AS real_name,
  423. h.article_id AS report_id,
  424. '0' AS report_chapter_id,
  425. art.title AS research_report_name,
  426. '4' AS report_type,
  427. 'rights' AS txt_type,
  428. art.match_type_name,
  429. h.stop_time,
  430. h.create_time AS created_time
  431. FROM
  432. cygx_article_history_record_newpv h
  433. INNER JOIN cygx_article art ON art.article_id = h.article_id
  434. WHERE
  435. h.create_time >= ? AND h.create_time< ? `
  436. sql = ` SELECT * FROM ( ` + ficcSql + " UNION ALL " + rightsSql + `
  437. )AS t ORDER BY t.created_time asc`
  438. o := orm.NewOrm()
  439. sql = fmt.Sprintf(sql, dataName, dataName)
  440. _, err = o.Raw(sql, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate).QueryRows(&items)
  441. return
  442. }
  443. // CompanyViewResp
  444. // @Description: 客户报告阅读统计
  445. type CompanyViewResp struct {
  446. UserId int `description:"联系人ID"`
  447. UserName string `description:"联系人姓名"`
  448. Mobile string `description:"手机号"`
  449. Email string `description:"邮箱地址"`
  450. ViewTotal int `description:"累计点击量"`
  451. LastViewTime string `description:"创建时间"`
  452. }
  453. // CompanyViewPageListResp 客户-点击量分页列表响应体
  454. type CompanyViewPageListResp struct {
  455. List []*CompanyViewResp
  456. Paging *paging.PagingItem `description:"分页数据"`
  457. }
  458. func GetCompanyUserListByReportCount(companyId int) (count int, err error) {
  459. o := orm.NewOrm()
  460. sql := ` SELECT COUNT(1) AS count FROM wx_user WHERE company_id =? AND ficc_view_total>0 `
  461. err = o.Raw(sql, companyId).QueryRow(&count)
  462. return
  463. }
  464. // GetCompanyUserListByReport
  465. // @Description: 根据报告阅读情况获取联系人列表
  466. // @author: Roc
  467. // @datetime 2024-02-01 16:07:59
  468. // @param companyId int
  469. // @param startSize int
  470. // @param pageSize int
  471. // @param order string
  472. // @return items []*CompanyUser
  473. // @return err error
  474. func GetCompanyUserListByReport(companyId, startSize, pageSize int, order string) (items []*CompanyUser, err error) {
  475. o := orm.NewOrm()
  476. sql := `SELECT * FROM wx_user WHERE company_id = ? AND ficc_view_total>0 `
  477. if order != "" {
  478. sql += order
  479. } else {
  480. sql += ` ORDER BY create_time DESC`
  481. }
  482. sql += ` LIMIT ?,?`
  483. _, err = o.Raw(sql, companyId, startSize, pageSize).QueryRows(&items)
  484. return
  485. }