cygx_yanxuan_special_record.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxYanxuanSpecialRecord struct {
  7. CygxYanxuanSpecialRecordId int `orm:"column(cygx_yanxuan_special_record_id);pk"`
  8. UserId int // 用户ID
  9. Mobile string // 手机号
  10. Email string // 邮箱
  11. CompanyId int // 公司ID
  12. CompanyName string // 公司名称
  13. RealName string // 用户实际名称
  14. SellerName string // 所属销售
  15. CreateTime time.Time // 创建时间
  16. ModifyTime time.Time // 修改时间
  17. RegisterPlatform int // 来源 1小程序,2:网页
  18. YanxuanSpecialId int // cygx_yanxuan_special 表主键ID
  19. StopTime int // 停留时间
  20. PermissionCode int // 权限状态,1:有权限,0:无权限
  21. }
  22. type CygxYanxuanSpecialRecordResp struct {
  23. CygxYanxuanSpecialRecordId int `orm:"column(cygx_yanxuan_special_record_id);pk"`
  24. UserId int // 用户ID
  25. Mobile string // 手机号
  26. Email string // 邮箱
  27. CompanyId int // 公司ID
  28. CompanyName string // 公司名称
  29. RealName string // 用户实际名称
  30. SellerName string // 所属销售
  31. CreateTime string // 创建时间
  32. ModifyTime time.Time // 修改时间
  33. RegisterPlatform int // 来源 1小程序,2:网页
  34. YanxuanSpecialId int // cygx_yanxuan_special 表主键ID
  35. StopTime int // 停留时间
  36. PermissionCode int // 权限状态,1:有权限,0:无权限
  37. }
  38. func AddCygxYanxuanSpecialRecord(item *CygxYanxuanSpecialRecord) (lastId int64, err error) {
  39. o := orm.NewOrm()
  40. lastId, err = o.Insert(item)
  41. return
  42. }
  43. type AddCygxYanxuanSpecialRecordReq struct {
  44. SpecialId int `description:"专栏文章id"`
  45. StopTime int `description:"停留时间"`
  46. }
  47. // 获取数量
  48. func GetCygxYanxuanSpecialRecordCount(condition string, pars []interface{}) (count int, err error) {
  49. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_record as art WHERE 1= 1 `
  50. if condition != "" {
  51. sqlCount += condition
  52. }
  53. o := orm.NewOrm()
  54. err = o.Raw(sqlCount, pars).QueryRow(&count)
  55. return
  56. }
  57. // 获取数量
  58. func GetCygxYanxuanSpecialRecordCountGroup(condition string, pars []interface{}) (count int, err error) {
  59. sqlCount := ` SELECT count(*) AS count FROM
  60. ( SELECT COUNT(*) FROM cygx_yanxuan_special_record AS art WHERE 1 = 1 ` + condition + ` GROUP BY user_id ) f `
  61. o := orm.NewOrm()
  62. err = o.Raw(sqlCount, pars).QueryRow(&count)
  63. return
  64. }
  65. // 判断一个用户是否阅读过 某一篇研选专栏
  66. func GetCygxYanxuanSpecialRecordCountByUser(userId, yanxuanSpecialId int) (count int, err error) {
  67. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_record as a WHERE user_id= ? AND yanxuan_special_id = ? `
  68. o := orm.NewOrm()
  69. err = o.Raw(sqlCount, userId, yanxuanSpecialId).QueryRow(&count)
  70. return
  71. }
  72. // 详细日志记录,不过滤时长小于 3 秒的那种
  73. type CygxYanxuanSpecialRecordLog struct {
  74. CygxYanxuanSpecialRecordId int `orm:"column(cygx_yanxuan_special_record_id);pk"`
  75. UserId int // 用户ID
  76. Mobile string // 手机号
  77. Email string // 邮箱
  78. CompanyId int // 公司ID
  79. CompanyName string // 公司名称
  80. RealName string // 用户实际名称
  81. SellerName string // 所属销售
  82. CreateTime time.Time // 创建时间
  83. ModifyTime time.Time // 修改时间
  84. RegisterPlatform int // 来源 1小程序,2:网页
  85. YanxuanSpecialId int // cygx_yanxuan_special 表主键ID
  86. StopTime int // 停留时间
  87. PermissionCode int // 权限状态,1:有权限,0:无权限
  88. }
  89. func AddCygxYanxuanSpecialRecordLog(item *CygxYanxuanSpecialRecordLog) (lastId int64, err error) {
  90. o := orm.NewOrm()
  91. lastId, err = o.Insert(item)
  92. return
  93. }
  94. // 列表
  95. func GetCygxYanxuanSpecialRecordRespList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialRecordResp, err error) {
  96. o := orm.NewOrm()
  97. sql := `SELECT * FROM cygx_yanxuan_special_record as art WHERE 1= 1 `
  98. if condition != "" {
  99. sql += condition
  100. }
  101. sql += ` LIMIT ?,? `
  102. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  103. return
  104. }
  105. // 列表
  106. func GetCygxYanxuanSpecialRecordRespListAll(condition string, pars []interface{}) (items []*CygxYanxuanSpecialRecordResp, err error) {
  107. if condition == "" {
  108. return
  109. }
  110. o := orm.NewOrm()
  111. sql := `SELECT * FROM cygx_yanxuan_special_record as art WHERE 1= 1 `
  112. if condition != "" {
  113. sql += condition
  114. }
  115. _, err = o.Raw(sql, pars).QueryRows(&items)
  116. return
  117. }
  118. type LisYanxuanSpecialRecordPvResp struct {
  119. YanxuanSpecialId int `description:"文章ID"`
  120. Pv int `description:"pv"`
  121. Uv int `description:"pv"`
  122. }
  123. // pv 列表
  124. func GetCygxYanxuanSpecialRecordListPv(condition string, pars []interface{}) (items []*LisYanxuanSpecialRecordPvResp, err error) {
  125. o := orm.NewOrm()
  126. sql := `SELECT
  127. COUNT( 1 ) AS pv,
  128. yanxuan_special_id
  129. FROM
  130. cygx_yanxuan_special_record WHERE 1 = 1 `
  131. if condition != "" {
  132. sql += condition
  133. }
  134. sql += ` GROUP BY yanxuan_special_id `
  135. _, err = o.Raw(sql, pars).QueryRows(&items)
  136. return
  137. }