company_user.go 22 KB

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