chart_visit_log.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // ChartDailyVisitLog 每日访问记录
  8. type ChartDailyVisitLog struct {
  9. Id int `orm:"column(id);pk"`
  10. CompanyId int `description:"客户ID"`
  11. CompanyName string `description:"客户名称"`
  12. UserId int `description:"用户ID"`
  13. RealName string `description:"用户名称"`
  14. Mobile string `description:"用户手机号"`
  15. Email string `description:"电子邮箱"`
  16. ChartInfoId int `description:"图表ID"`
  17. ChartName string `description:"图表名称"`
  18. MyChartClassifyId int `description:"图表分类ID"`
  19. MyChartClassifyName string `description:"图表分类名称"`
  20. CreateTime time.Time `description:"访问时间"`
  21. }
  22. // ChartVisitPageListResp 图表阅读统计列表响应体
  23. type ChartVisitPageListResp struct {
  24. Paging *paging.PagingItem
  25. List []*ChartVisitList `description:"列表数据"`
  26. }
  27. // ChartVisitList 图表阅读统计列表
  28. type ChartVisitList struct {
  29. ClassifyId int `description:"分类ID"`
  30. ClassifyName string `description:"分类名称"`
  31. VisitCount int `description:"阅读量"`
  32. LastVisitTime string `description:"最后阅读时间"`
  33. }
  34. // GetChartVisitPageList 获取图表阅读统计列表-分页
  35. func GetChartVisitPageList(classifyId, startSize, pageSize, order int) (total int, list []*ChartVisitList, err error) {
  36. o := orm.NewOrm()
  37. var pars []interface{}
  38. sql := ` SELECT
  39. my_chart_classify_id AS classify_id,
  40. my_chart_classify_name AS classify_name,
  41. COUNT(1) AS visit_count,
  42. MAX(create_time) AS last_visit_time
  43. FROM
  44. yb_chart_daily_visit_log AS a
  45. WHERE
  46. 1 = 1 `
  47. if classifyId > 0 {
  48. sql += ` AND my_chart_classify_id = ? `
  49. pars = append(pars, classifyId)
  50. }
  51. sql += ` GROUP BY my_chart_classify_id `
  52. orderBy := ""
  53. switch order {
  54. case 1:
  55. orderBy = "visit_count ASC "
  56. case 2:
  57. orderBy = "visit_count DESC "
  58. case 3:
  59. orderBy = "last_visit_time ASC "
  60. case 4:
  61. orderBy = "last_visit_time DESC "
  62. default:
  63. orderBy = "visit_count DESC "
  64. }
  65. sql += ` ORDER BY ` + orderBy
  66. totalSql := `select count(1) total from (` + sql + `) z `
  67. err = o.Raw(totalSql, pars).QueryRow(&total)
  68. if err != nil {
  69. return
  70. }
  71. sql += ` LIMIT ?,? `
  72. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  73. return
  74. }
  75. // ChartVisitDetailPageListResp 图表阅读详情统计列表响应体
  76. type ChartVisitDetailPageListResp struct {
  77. Paging *paging.PagingItem
  78. List []*ChartVisitDetailList `description:"列表数据"`
  79. VisitTotal int `description:"阅读总人数"`
  80. }
  81. // ChartVisitDetailList 图表阅读统计详情
  82. type ChartVisitDetailList struct {
  83. UserId int `description:"联系人ID"`
  84. UserName string `description:"联系人姓名"`
  85. CompanyId int `description:"客户ID"`
  86. CompanyName string `description:"客户名称"`
  87. CompanyStatus string `description:"客户状态"`
  88. SellerName string `description:"销售名称"`
  89. VisitCount int `description:"阅读量"`
  90. LastVisitTime string `description:"最后阅读时间"`
  91. }
  92. // GetChartVisitDetailPageList 获取图表阅读统计详情列表-分页
  93. func GetChartVisitDetailPageList(condition string, pars []interface{}, order, startSize, pageSize int) (total int, list []*ChartVisitDetailList, err error) {
  94. o := orm.NewOrm()
  95. sql := ` SELECT
  96. l.user_id,
  97. l.company_id,
  98. l.company_name,
  99. l.real_name AS user_name,
  100. p.seller_name,
  101. p.status AS company_status,
  102. COUNT(1) AS visit_count,
  103. MAX(l.create_time) AS last_visit_time
  104. FROM
  105. yb_chart_daily_visit_log AS l
  106. INNER JOIN company AS c ON l.company_id = c.company_id
  107. INNER JOIN company_product AS p ON c.company_id = p.company_id AND p.product_id = 1
  108. WHERE
  109. l.my_chart_classify_id = ? `
  110. sql += condition
  111. sql += ` GROUP BY l.user_id `
  112. orderBy := ""
  113. switch order {
  114. case 1:
  115. orderBy = "last_visit_time ASC "
  116. case 2:
  117. orderBy = "last_visit_time DESC "
  118. default:
  119. orderBy = "last_visit_time DESC "
  120. }
  121. sql += ` ORDER BY ` + orderBy
  122. totalSql := `select count(1) total from (` + sql + `) z `
  123. err = o.Raw(totalSql, pars).QueryRow(&total)
  124. if err != nil {
  125. return
  126. }
  127. sql += ` LIMIT ?,? `
  128. pars = append(pars, startSize, pageSize)
  129. _, err = o.Raw(sql, pars).QueryRows(&list)
  130. return
  131. }
  132. // GetClassifyChartTotalVisit 获取分类阅读总人数
  133. func GetClassifyChartTotalVisit(condition string, pars []interface{}) (total int, err error) {
  134. o := orm.NewOrm()
  135. sql := ` SELECT
  136. COUNT(1)
  137. FROM
  138. yb_chart_daily_visit_log AS l
  139. INNER JOIN company AS c ON l.company_id = c.company_id
  140. INNER JOIN company_product AS p ON c.company_id = p.company_id AND p.product_id = 1
  141. WHERE
  142. l.my_chart_classify_id = ? `
  143. sql += condition
  144. err = o.Raw(sql, pars).QueryRow(&total)
  145. return
  146. }
  147. // UserClassifyChartVisitList 用户指定分类的图表访问列表
  148. type UserClassifyChartVisitList struct {
  149. ChartName string `description:"图表名称"`
  150. VisitCount int `description:"访问次数"`
  151. }
  152. // GetUserClassifyChartVisitList 获取用户指定分类的图表访问列表
  153. func GetUserClassifyChartVisitList(classifyId, userId int) (list []*UserClassifyChartVisitList, err error) {
  154. o := orm.NewOrm()
  155. sql := ` SELECT
  156. chart_name,
  157. COUNT(1) AS visit_count
  158. FROM
  159. yb_chart_daily_visit_log
  160. WHERE
  161. my_chart_classify_id = ?
  162. AND user_id = ?
  163. GROUP BY
  164. chart_info_id `
  165. _, err = o.Raw(sql, classifyId, userId).QueryRows(&list)
  166. return
  167. }
  168. // CompanyAuthCensusPageListResp 图表权限开通统计响应体
  169. type CompanyAuthCensusPageListResp struct {
  170. Paging *paging.PagingItem
  171. List []*CompanyAuthCensusList `description:"列表数据"`
  172. UserTotal int `description:"联系人总数"`
  173. CompanyTotal int `description:"用户总数"`
  174. }
  175. // CompanyAuthCensusList 图库权限开通统计
  176. type CompanyAuthCensusList struct {
  177. UserId int `description:"联系人ID"`
  178. UserName string `description:"联系人姓名"`
  179. CompanyId int `description:"客户ID"`
  180. CompanyName string `description:"客户名称"`
  181. CompanyStatus string `description:"客户状态"`
  182. SellerName string `description:"销售名称"`
  183. StartTime string `description:"权限开始日期"`
  184. EndTime string `description:"权限结束日期"`
  185. RestDay int `description:"剩余天数"`
  186. CreateTime string `description:"权限开通时间"`
  187. }
  188. // GetCompanyAuthCensusPageList 获取图库权限开通统计列表-分页
  189. func GetCompanyAuthCensusPageList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*CompanyAuthCensusList, err error) {
  190. o := orm.NewOrm()
  191. sql := ` SELECT
  192. a.user_id,
  193. b.real_name AS user_name,
  194. c.company_id,
  195. c.company_name,
  196. d.seller_id,
  197. d.seller_name,
  198. d.status AS company_status,
  199. a.start_time,
  200. a.end_time,
  201. a.create_time
  202. FROM
  203. company_user_chart_classify_permission AS a
  204. INNER JOIN wx_user AS b ON a.user_id = b.user_id
  205. INNER JOIN company AS c ON b.company_id = c.company_id
  206. INNER JOIN company_product AS d ON c.company_id = d.company_id AND d.product_id = 1 AND d.status NOT IN ("冻结", "潜在", "流失")
  207. WHERE
  208. 1 = 1
  209. AND a.enabled = 1 `
  210. sql += condition
  211. sql += ` GROUP BY a.user_id`
  212. totalSql := `select count(1) total from (` + sql + `) z `
  213. err = o.Raw(totalSql, pars).QueryRow(&total)
  214. if err != nil {
  215. return
  216. }
  217. pars = append(pars, startSize, pageSize)
  218. sql += ` LIMIT ?,? `
  219. _, err = o.Raw(sql, pars).QueryRows(&list)
  220. return
  221. }
  222. type CountCompanyChartAuth struct {
  223. //CountUser int `description:"开通权限用户数"`
  224. CountCompany int `description:"开通权限客户数"`
  225. }
  226. // GetCompanyAuthTotal 获取开通图表权限客户总数
  227. func GetCompanyAuthTotal(condition string, pars []interface{}) (total CountCompanyChartAuth, err error) {
  228. o := orm.NewOrm()
  229. sql := ` SELECT
  230. COUNT(DISTINCT c.company_id) AS count_company
  231. FROM
  232. company_user_chart_classify_permission AS a
  233. INNER JOIN wx_user AS b ON a.user_id = b.user_id
  234. INNER JOIN company AS c ON b.company_id = c.company_id
  235. INNER JOIN company_product AS d ON c.company_id = d.company_id AND d.product_id = 1 AND d.status NOT IN ("冻结", "潜在", "流失")
  236. WHERE
  237. 1 = 1
  238. AND a.enabled = 1 `
  239. sql += condition
  240. err = o.Raw(sql, pars).QueryRow(&total)
  241. return
  242. }