package controllers import ( "eta/eta_mini_crm/models" "eta/eta_mini_crm/models/response" "eta/eta_mini_crm/utils" "strings" "time" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" ) type UserReadRecordController struct { BaseAuthController } // List // @Title 用户阅读统计列表 // @Description 用户阅读统计列表 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param SellerId query int true "销售id" // @Param Status query int true "用户状态" // @Param KeyWord query string true "手机号/邮箱/姓名" // @Param IsRegistered query string true "是否注册" // @Param IsSubscribed query string true "是否关注" // @Param RegisterStartDate query string true "注册开始时间" // @Param RegisterEndDate query string true "注册结束时间" // @Param CreateStartDate query string true "创建开始时间" // @Param CreateEndDate query string true "创建结束时间" // @Success 200 {object} response.UserListResp // @router /list [get] func (this *UserReadRecordController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") sellerId, _ := this.GetInt("SellerId") status := this.GetString("Status") keyWord := this.GetString("KeyWord") IsRegistered := this.GetString("IsRegisterd") IsSubscribed := this.GetString("IsSubscribed") registerStartDate := this.GetString("RegisterStartDate") registerEndDate := this.GetString("RegisterEndDate") createStartDate := this.GetString("CreateStartDate") createEndDate := this.GetString("CreateEndDate") var condition string var pars []interface{} if keyWord != "" { condition += ` AND (real_name LIKE ? OR phone LIKE ? OR email LIKE ? OR company LIKE ?) ` pars = utils.GetLikeKeywordPars(pars, keyWord, 4) } if pageSize <= 0 { pageSize = utils.PageSize20 } else if pageSize > utils.PageSize100 { pageSize = utils.PageSize100 } if currentIndex <= 0 { currentIndex = 1 } if sellerId > 0 { condition += " AND seller_id=? " pars = append(pars, sellerId) } switch status { case "禁用": condition += " AND status=? " pars = append(pars, 0) case "潜在": condition += " AND status=? " pars = append(pars, 1) case "正式": condition += " AND status=? " pars = append(pars, 2) case "": condition += " AND (status=? OR status=?) " pars = append(pars, 0, 2) } switch IsRegistered { case "是": condition += " AND is_registered=? " pars = append(pars, true) case "否": condition += " AND is_registered=? " pars = append(pars, false) } switch IsSubscribed { case "是": condition += " AND is_subscribed=? " pars = append(pars, true) case "否": condition += " AND is_subscribed=? " pars = append(pars, false) } if registerStartDate != "" { registerStartTime, er := time.Parse("2006-01-02 15:04:05", registerStartDate) if er != nil { br.Msg = "日期格式有误" return } condition += " AND register_time>? " pars = append(pars, registerStartTime) } if registerEndDate != "" { registerEndTime, er := time.Parse("2006-01-02 15:04:05", registerEndDate) if er != nil { br.Msg = "日期格式有误" return } condition += " AND register_time? " pars = append(pars, createStartTime) } if createEndDate != "" { createEndTime, er := time.Parse("2006-01-02 15:04:05", createEndDate) if er != nil { br.Msg = "日期格式有误" return } condition += " AND create_time utils.PageSize100 { pageSize = utils.PageSize100 } if currentIndex <= 0 { currentIndex = 1 } startSize := utils.StartIndex(currentIndex, pageSize) total, err := models.GetUserCount(condition, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } userList, err := models.GetUserList(condition, pars, startSize, pageSize) if err != nil { br.Msg = "查询用户失败" br.Msg = "查询用户失败,系统错误,Err:" + err.Error() return } page := paging.GetPaging(currentIndex, pageSize, total) resp := new(response.UserListResp) resp.Paging = page resp.List = userList br.Data = resp br.Ret = 200 br.Success = true br.Msg = "获取成功" } // Detail // @Title 用户阅读记录详情 // @Description 用户阅读记录详情信息 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param ChartPermissionIds query string true "品种列表" // @Param ClassifyIds query string true "品种列表" // @Success 200 {object} models.LoginResp // @router /detail [get] func (this *UserReadRecordController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() UserId, _ := this.GetInt("UserId") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") chartPermissionids := this.GetString("ChartPermissionIds") classifyIds := this.GetString("ClassifyIds") if UserId <= 0 { br.Msg = "查询用户不存在" return } if pageSize <= 0 { pageSize = utils.PageSize20 } else if pageSize > utils.PageSize100 { pageSize = utils.PageSize100 } if currentIndex <= 0 { currentIndex = 1 } startSize := utils.StartIndex(currentIndex, pageSize) user, err := models.GetUserById(UserId) if err != nil { if err == orm.ErrNoRows { br.Msg = "用户不存在或已删除,请刷新页面" return } br.Msg = "查询用户失败" br.ErrMsg = "查询用户失败,系统错误,Err:" + err.Error() return } if user == nil { br.Msg = "用户不存在或已删除,请刷新页面" return } var condition string var pars []interface{} if chartPermissionids != "" { ids := strings.Split(chartPermissionids, ",") if len(ids) != 0 { condition += ` AND ( ` for i, id := range ids { if i == 0 { condition += ` urp2.chart_permission_id = ? ` pars = append(pars, id) } else { condition += ` OR urp2.chart_permission_id = ? ` pars = append(pars, id) } } condition += `) ` } } if classifyIds != "" { ids := strings.Split(classifyIds, ",") if len(ids) != 0 { condition += ` AND ( ` for i, id := range ids { if i == 0 { condition += ` classify_id2 = ? ` pars = append(pars, id) } else { condition += ` OR classify_id2 = ? ` pars = append(pars, id) } } condition += `) ` } } // total, err := models.GetUserReadRecordCountByUserId(UserId, condition, pars) // if err != nil { // br.Msg = "查询阅读记录失败" // br.ErrMsg = "查询阅读记录失败失败,Err:" + err.Error() // return // } // if total == 0 { // br.Msg = "该用户暂无阅读记录" // return // } readList, err := models.GetUserReadRecordByUserId(UserId, condition, pars, startSize, pageSize) if err != nil { br.Msg = "查询阅读记录失败" br.ErrMsg = "查询阅读记录失败,系统错误,Err:" + err.Error() return } page := paging.GetPaging(currentIndex, pageSize, len(readList)) resp := new(response.UserReadRecordListResp) resp.Paging = page resp.List = readList br.Msg = "获取成功" br.Data = resp br.Success = true br.Ret = 200 } // Info // @Title 用户阅读统计图信息 // @Description 用户阅读统计图信息 // @Param ChartPermissionIds query string true "品种列表" // @Param ClassifyIds query string true "品种列表" // @Param StartDate query string true "开始时间" // @Param EndDate query string true "结束时间" // @Success 200 {object} models.LoginResp // @router /chart/info [get] func (this *UserReadRecordController) Info() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() startDate := this.GetString("StartDate") endDate := this.GetString("EndDate") chartPermissionIds := this.GetString("ChartPermissionIds") classifyIds := this.GetString("ClassifyIds") keyWord := this.GetString("KeyWord") if startDate == "" { startDate = time.Now().AddDate(-1, 0, 0).Format("2006-01-02") } if endDate == "" { endDate = time.Now().AddDate(0, 0, 1).Format("2006-01-02") } var condition string var pars []interface{} if keyWord != "" { condition += ` AND (real_name LIKE ? OR phone LIKE ? OR email LIKE ? OR company LIKE ?) ` pars = utils.GetLikeKeywordPars(pars, keyWord, 4) } if chartPermissionIds != "" { ids := strings.Split(chartPermissionIds, ",") if len(ids) != 0 { condition += ` AND ( ` for i, id := range ids { if i == 0 { condition += ` urp2.chart_permission_id = ? ` pars = append(pars, id) } else { condition += ` OR urp2.chart_permission_id = ? ` pars = append(pars, id) } } condition += `) ` } } if classifyIds != "" { ids := strings.Split(classifyIds, ",") if len(ids) != 0 { condition += ` AND ( ` for i, id := range ids { if i == 0 { condition += ` classify_id2 = ? ` pars = append(pars, id) } else { condition += ` OR classify_id2 = ? ` pars = append(pars, id) } } condition += `) ` } } readCnts, err := models.GetStaticReadCnt(condition, pars, startDate, endDate) if err != nil { br.Msg = "获取阅读统计失败" br.ErrMsg = "获取阅读统计失败,系统错误,Err:" + err.Error() return } permissionCnts, err := models.GetStaticPermissionCnt(condition, pars, startDate, endDate) if err != nil { br.Msg = "获取品种阅读统计失败" br.ErrMsg = "获取品种阅读统计失败,系统错误,Err:" + err.Error() return } resp := new(response.StaticInfoResp) resp.PermissionCntList = permissionCnts resp.ReadCntList = readCnts br.Data = resp br.Success = true br.Msg = "获取成功" br.Ret = 200 }