cygx_yanxuan_special_record.go 5.1 KB

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