123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- 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)
- }
|