package controllers import ( "encoding/json" "github.com/rdlucklib/rdluck_tools/paging" "hongze/hongze_clpt/models" "hongze/hongze_clpt/utils" "time" ) type MobileTacticsController struct { BaseAuthMobileController } // @Title 时间线列表 // @Description 时间线列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Success 200 {object} models.GetCygxTacticsTimeLineResp // @router /tacticsTimeLine/list [get] func (this *MobileTacticsController) TacticsTimeLineList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } resp := new(models.GetCygxTacticsTimeLineResp) pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} condition += ` AND art.status = 1 ` total, err := models.GetCygxTacticsTimeLineCount(condition, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } condition += " ORDER BY art.publish_time DESC , art.time_line_id DESC " list, err := models.GetCygxTacticsTimeLineList(condition, pars, startSize, pageSize) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } for _, v := range list { v.PublishTime = utils.TimeRemoveHms2(v.PublishTime) } if len(list) == 0 { list = make([]*models.CygxTacticsTimeLineResp, 0) } cf, err := models.GetConfigByCode(utils.CYGX_TACTICS_TIME_LINE_STATUS) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } //如果不是弘则用户,并且设置了内部可见,那么数据就隐藏 if user.CompanyId != utils.HZ_COMPANY_ID && cf.ConfigValue != "1" { list = make([]*models.CygxTacticsTimeLineResp, 0) } page := paging.GetPaging(currentIndex, pageSize, total) resp.List = list resp.Paging = page br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 时间线用户点击记录 // @Description 时间线用户点击记录接口 // @Param request body models.TacticsTimeLineTimeLineIdReq true "type json string" // @Success Ret=200 新增成功 // @router /tacticsTimeLine/history [post] func (this *MobileTacticsController) History() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.TacticsTimeLineTimeLineIdReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } timeLineId := req.TimeLineId if timeLineId == 0 { br.Msg = "时间线ID错误" return } var sellerName string sellerName, err = models.GetCompanySellerName(user.CompanyId) if err != nil { br.Msg = "报名失败!" br.ErrMsg = "获取对应销售失败,Err:" + err.Error() return } item := models.CygxTacticsTimeLineHistory{ TimeLineId: timeLineId, UserId: user.UserId, Mobile: user.Mobile, Email: user.Email, CompanyId: user.CompanyId, CompanyName: user.CompanyName, RealName: user.RealName, SellerName: sellerName, CreateTime: time.Now(), ModifyTime: time.Now(), } err = models.AddCygxTacticsTimeLineHistory(&item) br.Ret = 200 br.Success = true br.Msg = "获取成功" }