user_read_record.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 (real_name LIKE ? OR phone LIKE ? OR email LIKE ? OR 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 status=? "
  68. pars = append(pars, 0)
  69. case "潜在":
  70. condition += " AND status=? "
  71. pars = append(pars, 1)
  72. case "正式":
  73. condition += " AND status=? "
  74. pars = append(pars, 2)
  75. case "":
  76. condition += " AND (status=? OR status=?) "
  77. pars = append(pars, 0, 2)
  78. }
  79. switch IsRegistered {
  80. case "是":
  81. condition += " AND is_registered=? "
  82. pars = append(pars, true)
  83. case "否":
  84. condition += " AND is_registered=? "
  85. pars = append(pars, false)
  86. }
  87. switch IsSubscribed {
  88. case "是":
  89. condition += " AND is_subscribed=? "
  90. pars = append(pars, true)
  91. case "否":
  92. condition += " AND 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 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 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 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 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.GetUserCount(condition, pars)
  141. if err != nil {
  142. br.Msg = "获取失败"
  143. br.ErrMsg = "获取失败,Err:" + err.Error()
  144. return
  145. }
  146. userList, err := models.GetUserList(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. // total, err := models.GetUserReadRecordCountByUserId(UserId, condition, pars)
  243. // if err != nil {
  244. // br.Msg = "查询阅读记录失败"
  245. // br.ErrMsg = "查询阅读记录失败失败,Err:" + err.Error()
  246. // return
  247. // }
  248. // if total == 0 {
  249. // br.Msg = "该用户暂无阅读记录"
  250. // return
  251. // }
  252. readList, err := models.GetUserReadRecordByUserId(UserId, condition, pars, startSize, pageSize)
  253. if err != nil {
  254. br.Msg = "查询阅读记录失败"
  255. br.ErrMsg = "查询阅读记录失败,系统错误,Err:" + err.Error()
  256. return
  257. }
  258. page := paging.GetPaging(currentIndex, pageSize, len(readList))
  259. resp := new(response.UserReadRecordListResp)
  260. resp.Paging = page
  261. resp.List = readList
  262. br.Msg = "获取成功"
  263. br.Data = resp
  264. br.Success = true
  265. br.Ret = 200
  266. }
  267. // Info
  268. // @Title 用户阅读统计图信息
  269. // @Description 用户阅读统计图信息
  270. // @Param ChartPermissionIds query string true "品种列表"
  271. // @Param ClassifyIds query string true "品种列表"
  272. // @Param StartDate query string true "开始时间"
  273. // @Param EndDate query string true "结束时间"
  274. // @Success 200 {object} models.LoginResp
  275. // @router /chart/info [get]
  276. func (this *UserReadRecordController) Info() {
  277. br := new(models.BaseResponse).Init()
  278. defer func() {
  279. this.Data["json"] = br
  280. this.ServeJSON()
  281. }()
  282. startDate := this.GetString("StartDate")
  283. endDate := this.GetString("EndDate")
  284. chartPermissionIds := this.GetString("ChartPermissionIds")
  285. classifyIds := this.GetString("ClassifyIds")
  286. keyWord := this.GetString("KeyWord")
  287. if startDate == "" {
  288. startDate = time.Now().AddDate(-1, 0, 0).Format("2006-01-02")
  289. }
  290. if endDate == "" {
  291. endDate = time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  292. }
  293. var condition string
  294. var pars []interface{}
  295. if keyWord != "" {
  296. condition += ` AND (real_name LIKE ? OR phone LIKE ? OR email LIKE ? OR company LIKE ?) `
  297. pars = utils.GetLikeKeywordPars(pars, keyWord, 4)
  298. }
  299. if chartPermissionIds != "" {
  300. ids := strings.Split(chartPermissionIds, ",")
  301. if len(ids) != 0 {
  302. condition += ` AND ( `
  303. for i, id := range ids {
  304. if i == 0 {
  305. condition += ` urp2.chart_permission_id = ? `
  306. pars = append(pars, id)
  307. } else {
  308. condition += ` OR urp2.chart_permission_id = ? `
  309. pars = append(pars, id)
  310. }
  311. }
  312. condition += `) `
  313. }
  314. }
  315. if classifyIds != "" {
  316. ids := strings.Split(classifyIds, ",")
  317. if len(ids) != 0 {
  318. condition += ` AND ( `
  319. for i, id := range ids {
  320. if i == 0 {
  321. condition += ` classify_id2 = ? `
  322. pars = append(pars, id)
  323. } else {
  324. condition += ` OR classify_id2 = ? `
  325. pars = append(pars, id)
  326. }
  327. }
  328. condition += `) `
  329. }
  330. }
  331. readCnts, err := models.GetStaticReadCnt(condition, pars, startDate, endDate)
  332. if err != nil {
  333. br.Msg = "获取阅读统计失败"
  334. br.ErrMsg = "获取阅读统计失败,系统错误,Err:" + err.Error()
  335. return
  336. }
  337. permissionCnts, err := models.GetStaticPermissionCnt(condition, pars, startDate, endDate)
  338. if err != nil {
  339. br.Msg = "获取品种阅读统计失败"
  340. br.ErrMsg = "获取品种阅读统计失败,系统错误,Err:" + err.Error()
  341. return
  342. }
  343. resp := new(response.StaticInfoResp)
  344. resp.PermissionCntList = permissionCnts
  345. resp.ReadCntList = readCnts
  346. br.Data = resp
  347. br.Success = true
  348. br.Msg = "获取成功"
  349. br.Ret = 200
  350. }