package eta_trial import ( "eta/eta_bridge/controller/resp" "eta/eta_bridge/global" "eta/eta_bridge/models/crm" etaTrialReq "eta/eta_bridge/models/request/eta_trial" "eta/eta_bridge/utils" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "time" ) type EtaTrialController struct{} // GetUserByMobile // @Description 手机号获取用户信息 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/mobile_fetch [post] func (a *EtaTrialController) GetUserByMobile(c *gin.Context) { var req etaTrialReq.GetUserReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } if req.Mobile == "" { resp.FailData("参数有误", "参数有误: Mobile", c) return } item, e := crm.GetEtaTrialByMobile(req.Mobile) if e != nil && e != utils.ErrNoRow { resp.FailData("操作失败", "获取试用客户信息失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", item, c) } // Disable // @Description 禁用 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/disable [post] func (a *EtaTrialController) Disable(c *gin.Context) { var req etaTrialReq.GetUserReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } if req.Mobile == "" { resp.FailData("参数有误", "参数有误: Mobile", c) return } if e := crm.DisableEtaTrailByMobile(req.Mobile); e != nil { resp.FailData("操作失败", "禁用试用客户失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) } // Edit // @Description 编辑 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/edit [post] func (a *EtaTrialController) Edit(c *gin.Context) { var req etaTrialReq.UserEditReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } if e := crm.UpdateEtaTrialPositionByMobile(req.RealName, req.Position, req.Mobile, req.Enabled); e != nil { resp.FailData("操作失败", "更新试用客户失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) } // Remove // @Description 删除用户 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/remove [post] func (a *EtaTrialController) Remove(c *gin.Context) { var req etaTrialReq.GetUserReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } if req.Mobile == "" { resp.FailData("参数有误", "参数有误: Mobile", c) return } if e := crm.DeleteEtaTrialByMobile(req.Mobile); e != nil { resp.FailData("操作失败", "删除试用客户失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) } // UpdateLogin // @Description 更新登录时间和次数 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/update_login [post] func (a *EtaTrialController) UpdateLogin(c *gin.Context) { var req etaTrialReq.UpdateUserLoginReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } if req.Mobile == "" { resp.FailData("参数有误", "参数有误: Mobile", c) return } if e := crm.UpdateEtaTrialLoginByMobile(req.Mobile); e != nil { resp.FailData("操作失败", "更新试用客户登录时间和次数失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) } // UpdateIndexNum // @Description 更新累计新增指标数 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/update_index_num [post] func (a *EtaTrialController) UpdateIndexNum(c *gin.Context) { var req etaTrialReq.UpdateUserIndexNumReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } if req.Mobile == "" { resp.FailData("参数有误", "参数有误: Mobile", c) return } if e := crm.UpdateEtaTrialIndexNumByMobile(req.Mobile); e != nil { resp.FailData("操作失败", "更新试用客户累计新增指标数失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) } // UpdateChartNum // @Description 更新累计新增图表数 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/update_chart_num [post] func (a *EtaTrialController) UpdateChartNum(c *gin.Context) { var req etaTrialReq.UpdateUserIndexNumReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } if req.Mobile == "" { resp.FailData("参数有误", "参数有误: Mobile", c) return } if e := crm.UpdateEtaTrialChartNumByMobile(req.Mobile); e != nil { resp.FailData("操作失败", "更新试用客户累计新增图表数失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) } // UpdateActiveTime // @Description 更新活跃时间 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/update_active_time [post] func (a *EtaTrialController) UpdateActiveTime(c *gin.Context) { var req etaTrialReq.UpdateUserActiveTimeReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } record := new(crm.EtaTrialActiveRecord) record.UserName = req.UserName record.Mobile = req.Mobile record.ActiveTime = req.ActiveTime record.Part = req.Part record.CreateTime = time.Now().Local() if e := record.Create(); e != nil { resp.FailData("操作失败", "新增试用客户活跃记录失败, Err:"+e.Error(), c) return } if e := crm.UpdateEtaTrailActiveTime(req.ActiveTime, req.Mobile); e != nil { resp.FailData("操作失败", "更新试用客户累计活跃时长失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) } // UpdateLoginDuration // @Description 更新登录时长 // @Success 200 {string} string "操作成功" // @Router /eta_trial/user/update_login_duration [post] func (a *EtaTrialController) UpdateLoginDuration(c *gin.Context) { var req etaTrialReq.UpdateUserLoginDurationReq err := c.Bind(&req) if err != nil { errs, ok := err.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+err.Error(), c) return } resp.FailData("参数解析失败", errs.Translate(global.Trans), c) return } record := new(crm.EtaTrialLoginDurationRecord) record.UserName = req.UserName record.Mobile = req.Mobile record.Duration = req.ActiveTime record.CreateTime = time.Now().Local() if e := record.Create(); e != nil { resp.FailData("操作失败", "新增试用客户登录时长记录失败, Err:"+e.Error(), c) return } if e := crm.UpdateEtaTrailLastLoginDuration(req.ActiveTime, req.Mobile); e != nil { resp.FailData("操作失败", "更新试用客户登录时长失败, Err:"+e.Error(), c) return } resp.OkData("操作成功", true, c) }