company_user.go 22 KB

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