user_read_record.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. package controllers
  2. import (
  3. "eta/eta_mini_crm/models"
  4. "eta/eta_mini_crm/models/response"
  5. "eta/eta_mini_crm/utils"
  6. "strings"
  7. "time"
  8. "github.com/beego/beego/v2/client/orm"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. type UserReadRecordController struct {
  12. BaseAuthController
  13. }
  14. // List
  15. // @Title 用户阅读统计列表
  16. // @Description 用户阅读统计列表
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param SellerId query int true "销售id"
  20. // @Param Status query int true "用户状态"
  21. // @Param KeyWord query string true "手机号/邮箱/姓名"
  22. // @Param IsRegistered query string true "是否注册"
  23. // @Param IsSubscribed query string true "是否关注"
  24. // @Param RegisterStartDate query string true "注册开始时间"
  25. // @Param RegisterEndDate query string true "注册结束时间"
  26. // @Param CreateStartDate query string true "创建开始时间"
  27. // @Param CreateEndDate query string true "创建结束时间"
  28. // @Success 200 {object} response.UserListResp
  29. // @router /list [get]
  30. func (this *UserReadRecordController) List() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. pageSize, _ := this.GetInt("PageSize")
  37. currentIndex, _ := this.GetInt("CurrentIndex")
  38. sellerId, _ := this.GetInt("SellerId")
  39. status := this.GetString("Status")
  40. keyWord := this.GetString("KeyWord")
  41. IsRegistered := this.GetString("IsRegisterd")
  42. IsSubscribed := this.GetString("IsSubscribed")
  43. registerStartDate := this.GetString("RegisterStartDate")
  44. registerEndDate := this.GetString("RegisterEndDate")
  45. createStartDate := this.GetString("CreateStartDate")
  46. createEndDate := this.GetString("CreateEndDate")
  47. var condition string
  48. var pars []interface{}
  49. if keyWord != "" {
  50. condition += ` AND (u.real_name LIKE ? OR u.phone LIKE ? OR u.email LIKE ? OR u.company LIKE ?) `
  51. pars = utils.GetLikeKeywordPars(pars, keyWord, 4)
  52. }
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. } else if pageSize > utils.PageSize100 {
  56. pageSize = utils.PageSize100
  57. }
  58. if currentIndex <= 0 {
  59. currentIndex = 1
  60. }
  61. if sellerId > 0 {
  62. condition += " AND seller_id=? "
  63. pars = append(pars, sellerId)
  64. }
  65. switch status {
  66. case "禁用":
  67. condition += " AND u.status=? "
  68. pars = append(pars, 0)
  69. case "潜在":
  70. condition += " AND u.status=? "
  71. pars = append(pars, 1)
  72. case "正式":
  73. condition += " AND u.status=? "
  74. pars = append(pars, 2)
  75. case "":
  76. condition += " AND (u.status=? OR u.status=?) "
  77. pars = append(pars, 0, 2)
  78. }
  79. switch IsRegistered {
  80. case "是":
  81. condition += " AND u.is_registered=? "
  82. pars = append(pars, true)
  83. case "否":
  84. condition += " AND u.is_registered=? "
  85. pars = append(pars, false)
  86. }
  87. switch IsSubscribed {
  88. case "是":
  89. condition += " AND u.is_subscribed=? "
  90. pars = append(pars, true)
  91. case "否":
  92. condition += " AND u.is_subscribed=? "
  93. pars = append(pars, false)
  94. }
  95. if registerStartDate != "" {
  96. registerStartTime, er := time.Parse("2006-01-02 15:04:05", registerStartDate)
  97. if er != nil {
  98. br.Msg = "日期格式有误"
  99. return
  100. }
  101. condition += " AND u.register_time>? "
  102. pars = append(pars, registerStartTime)
  103. }
  104. if registerEndDate != "" {
  105. registerEndTime, er := time.Parse("2006-01-02 15:04:05", registerEndDate)
  106. if er != nil {
  107. br.Msg = "日期格式有误"
  108. return
  109. }
  110. condition += " AND u.register_time<? "
  111. pars = append(pars, registerEndTime)
  112. }
  113. if createStartDate != "" {
  114. createStartTime, er := time.Parse("2006-01-02 15:04:05", createStartDate)
  115. if er != nil {
  116. br.Msg = "日期格式有误"
  117. return
  118. }
  119. condition += " AND u.create_time>? "
  120. pars = append(pars, createStartTime)
  121. }
  122. if createEndDate != "" {
  123. createEndTime, er := time.Parse("2006-01-02 15:04:05", createEndDate)
  124. if er != nil {
  125. br.Msg = "日期格式有误"
  126. return
  127. }
  128. condition += " AND u.create_time<? "
  129. pars = append(pars, createEndTime)
  130. }
  131. if pageSize <= 0 {
  132. pageSize = utils.PageSize20
  133. } else if pageSize > utils.PageSize100 {
  134. pageSize = utils.PageSize100
  135. }
  136. if currentIndex <= 0 {
  137. currentIndex = 1
  138. }
  139. startSize := utils.StartIndex(currentIndex, pageSize)
  140. total, err := models.GetUserReadCount(condition, pars)
  141. if err != nil {
  142. br.Msg = "获取失败"
  143. br.ErrMsg = "获取失败,Err:" + err.Error()
  144. return
  145. }
  146. userList, err := models.GetUserReadList(condition, pars, startSize, pageSize)
  147. if err != nil {
  148. br.Msg = "查询用户失败"
  149. br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
  150. return
  151. }
  152. page := paging.GetPaging(currentIndex, pageSize, total)
  153. resp := new(response.UserListResp)
  154. resp.Paging = page
  155. resp.List = userList
  156. br.Data = resp
  157. br.Ret = 200
  158. br.Success = true
  159. br.Msg = "获取成功"
  160. }
  161. // Detail
  162. // @Title 用户阅读记录详情
  163. // @Description 用户阅读记录详情信息
  164. // @Param PageSize query int true "每页数据条数"
  165. // @Param CurrentIndex query int true "当前页页码,从1开始"
  166. // @Param ChartPermissionIds query string true "品种列表"
  167. // @Param ClassifyIds query string true "品种列表"
  168. // @Success 200 {object} models.LoginResp
  169. // @router /detail [get]
  170. func (this *UserReadRecordController) Detail() {
  171. br := new(models.BaseResponse).Init()
  172. defer func() {
  173. this.Data["json"] = br
  174. this.ServeJSON()
  175. }()
  176. UserId, _ := this.GetInt("UserId")
  177. pageSize, _ := this.GetInt("PageSize")
  178. currentIndex, _ := this.GetInt("CurrentIndex")
  179. chartPermissionids := this.GetString("ChartPermissionIds")
  180. classifyIds := this.GetString("ClassifyIds")
  181. if UserId <= 0 {
  182. br.Msg = "查询用户不存在"
  183. return
  184. }
  185. if pageSize <= 0 {
  186. pageSize = utils.PageSize20
  187. } else if pageSize > utils.PageSize100 {
  188. pageSize = utils.PageSize100
  189. }
  190. if currentIndex <= 0 {
  191. currentIndex = 1
  192. }
  193. startSize := utils.StartIndex(currentIndex, pageSize)
  194. user, err := models.GetUserById(UserId)
  195. if err != nil {
  196. if err == orm.ErrNoRows {
  197. br.Msg = "用户不存在或已删除,请刷新页面"
  198. return
  199. }
  200. br.Msg = "查询用户失败"
  201. br.ErrMsg = "查询用户失败,系统错误,Err:" + err.Error()
  202. return
  203. }
  204. if user == nil {
  205. br.Msg = "用户不存在或已删除,请刷新页面"
  206. return
  207. }
  208. var condition string
  209. var pars []interface{}
  210. if chartPermissionids != "" {
  211. ids := strings.Split(chartPermissionids, ",")
  212. if len(ids) != 0 {
  213. condition += ` AND ( `
  214. for i, id := range ids {
  215. if i == 0 {
  216. condition += ` urp2.chart_permission_id = ? `
  217. pars = append(pars, id)
  218. } else {
  219. condition += ` OR urp2.chart_permission_id = ? `
  220. pars = append(pars, id)
  221. }
  222. }
  223. condition += `) `
  224. }
  225. }
  226. if classifyIds != "" {
  227. ids := strings.Split(classifyIds, ",")
  228. if len(ids) != 0 {
  229. condition += ` AND ( `
  230. for i, id := range ids {
  231. if i == 0 {
  232. condition += ` classify_id2 = ? `
  233. pars = append(pars, id)
  234. } else {
  235. condition += ` OR classify_id2 = ? `
  236. pars = append(pars, id)
  237. }
  238. }
  239. condition += `) `
  240. }
  241. }
  242. readList, err := models.GetUserReadRecordByUserId(UserId, condition, pars, startSize, pageSize)
  243. if err != nil {
  244. br.Msg = "查询阅读记录失败"
  245. br.ErrMsg = "查询阅读记录失败,系统错误,Err:" + err.Error()
  246. return
  247. }
  248. page := paging.GetPaging(currentIndex, pageSize, len(readList))
  249. resp := new(response.UserReadRecordListResp)
  250. resp.Paging = page
  251. resp.List = readList
  252. br.Msg = "获取成功"
  253. br.Data = resp
  254. br.Success = true
  255. br.Ret = 200
  256. }
  257. // ReadCntChart
  258. // @Title 用户阅读量统计图信息
  259. // @Description 用户阅读量统计图信息
  260. // @Param ChartPermissionIds query string true "品种列表"
  261. // @Param ClassifyIds query string true "品种列表"
  262. // @Param StartDate query string true "开始时间"
  263. // @Param EndDate query string true "结束时间"
  264. // @Param UserId query int true "用户id"
  265. // @Success 200 {object} models.LoginResp
  266. // @router /readCntChart [get]
  267. func (this *UserReadRecordController) ReadCntChart() {
  268. br := new(models.BaseResponse).Init()
  269. defer func() {
  270. this.Data["json"] = br
  271. this.ServeJSON()
  272. }()
  273. userId, _ := this.GetInt("UserId")
  274. startDate := this.GetString("StartDate")
  275. endDate := this.GetString("EndDate")
  276. chartPermissionIds := this.GetString("ChartPermissionIds")
  277. classifyIds := this.GetString("ClassifyIds")
  278. var condition string
  279. var pars []interface{}
  280. if chartPermissionIds != "" {
  281. ids := strings.Split(chartPermissionIds, ",")
  282. if len(ids) != 0 {
  283. condition += ` AND ( `
  284. for i, id := range ids {
  285. if i == 0 {
  286. condition += ` urp.chart_permission_id = ? `
  287. pars = append(pars, id)
  288. } else {
  289. condition += ` OR urp.chart_permission_id = ? `
  290. pars = append(pars, id)
  291. }
  292. }
  293. condition += `) `
  294. }
  295. }
  296. if classifyIds != "" {
  297. ids := strings.Split(classifyIds, ",")
  298. if len(ids) != 0 {
  299. condition += ` AND ( `
  300. for i, id := range ids {
  301. if i == 0 {
  302. condition += ` classify_id2 = ? `
  303. pars = append(pars, id)
  304. } else {
  305. condition += ` OR classify_id2 = ? `
  306. pars = append(pars, id)
  307. }
  308. }
  309. condition += `) `
  310. }
  311. }
  312. if startDate == "" {
  313. startDate = time.Now().AddDate(-1, 0, 0).Format(utils.FormatDate)
  314. }
  315. if endDate == "" {
  316. endDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
  317. }
  318. if userId > 0 {
  319. condition += ` AND ur.user_id = ? `
  320. pars = append(pars, userId)
  321. }
  322. readCnts, err := models.GetStaticReadCnt(condition, pars, startDate, endDate)
  323. if err != nil {
  324. br.Msg = "获取阅读统计失败"
  325. br.ErrMsg = "获取阅读统计失败,系统错误,Err:" + err.Error()
  326. return
  327. }
  328. br.Msg = "查询成功"
  329. br.Data = readCnts
  330. br.Ret = 200
  331. br.Success = true
  332. }
  333. // readPermissionChart
  334. // @Title 用户阅读品种图信息
  335. // @Description 用户阅读品种图信息
  336. // @Param UserId query string true "用户id"
  337. // @Success 200 {object} models.LoginResp
  338. // @router /readPermissionChart [get]
  339. func (this *UserReadRecordController) ReadPermissionChart() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. this.Data["json"] = br
  343. this.ServeJSON()
  344. }()
  345. userId, _ := this.GetInt("UserId")
  346. var condition string
  347. var pars []interface{}
  348. if userId > 0 {
  349. condition += ` AND ur.user_id = ? `
  350. pars = append(pars, userId)
  351. }
  352. permissionCnts, err := models.GetStaticPermissionCnt(condition, pars)
  353. if err != nil {
  354. br.Msg = "获取品种阅读统计失败"
  355. br.ErrMsg = "获取品种阅读统计失败,系统错误,Err:" + err.Error()
  356. return
  357. }
  358. br.Msg = "查询成功"
  359. br.Data = permissionCnts
  360. br.Ret = 200
  361. br.Success = true
  362. }