1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "rdluck_tools/paging"
- "strconv"
- "strings"
- "time"
- )
- //活动
- type ActivityCoAntroller struct {
- BaseAuthController
- }
- // @Title 活动类型列表
- // @Description活动类型列表接口
- // @Success 200 {object} models.ActivityTypeListResp
- // @router /activityTypelist [get]
- func (this *ActivityCoAntroller) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- resp := new(models.ActivityTypeListResp)
- list, err := models.GetActivityTypeList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 活动列表
- // @Description 获取活动列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
- // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
- // @Param KeyWord query string false "搜索关键词"
- // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
- // @Param IsShowJurisdiction query int false "是否仅展示有权限的,1是,2否 默认为零"
- // @Success 200 {object} models.GetCygxActivityListRep
- // @router /list [get]
- func (this *ActivityCoAntroller) ActivityList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- return
- }
- uid := user.UserId
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- chartPermissionIds := this.GetString("ChartPermissionIds")
- activityTypeIds := this.GetString("ActivityTypeIds")
- isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
- keyWord := this.GetString("KeyWord")
- activeState := this.GetString("ActiveState")
- //if activeState == "" {
- // activeState = "1"
- //}
- //if isShowJurisdiction != 1 {
- // isShowJurisdiction = 0
- //}
- itemSearch := new(models.CygxActivityUserSearchContent)
- itemSearch.UserId = uid
- itemSearch.CreateTime = time.Now()
- itemSearch.Mobile = user.Mobile
- itemSearch.Email = user.Email
- itemSearch.CompanyId = user.CompanyId
- itemSearch.CompanyName = user.CompanyName
- itemSearch.ModifyTime = time.Now()
- itemSearch.ChartPermissionids = chartPermissionIds
- itemSearch.ActivityTypeids = activityTypeIds
- itemSearch.ActiveState = activeState
- itemSearch.IsShowJurisdiction = isShowJurisdiction
- _, errSearch := models.AddUserSearchContent(itemSearch)
- if errSearch != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errSearch.Error()
- return
- }
- if isShowJurisdiction == 1 && chartPermissionIds == "" {
- resp := new(models.GetCygxActivityListRep)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- 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{}
- if keyWord != "" {
- condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' ) `
- }
- //行业名称
- if len(chartPermissionIds) > 0 {
- condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
- }
- if activityTypeIds != "" {
- condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
- }
- condition += ` AND art.publish_status = 1 `
- if activeState != "" {
- condition += ` AND art.active_state IN (` + activeState + `)`
- }
- total, err := models.GetActivityCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if activeState == "2" || activeState == "3" || activeState == "2,3" {
- condition += ` ORDER BY art.activity_time DESC `
- }
- list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
- if errList != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + errList.Error()
- return
- }
- for k, v := range list {
- if strings.Contains(v.ActivityName, "【") {
- list[k].IsBrackets = 1
- }
- if v.SignupNum > v.LimitPeopleNum {
- list[k].SignupNum = v.LimitPeopleNum
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.GetCygxActivityListRep)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 我的日程
- // @Description 我的日程列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.GetCygxActivityListRep
- // @router /scheduleList [get]
- func (this *ActivityCoAntroller) ScheduleList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- return
- }
- uid := user.UserId
- 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.publish_status = 1 AND art.active_state IN(1,2) AND s.is_cancel = 0 AND s.fail_type = 0 `
- condition += ` AND art.publish_status = 1 AND art.active_state IN(1,2) `
- total, err := models.GetScheduleCount(uid)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
- if errList != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + errList.Error()
- return
- }
- for k, v := range list {
- if strings.Contains(v.ActivityName, "【") {
- list[k].IsBrackets = 1
- }
- if v.SignupNum > v.LimitPeopleNum {
- list[k].SignupNum = v.LimitPeopleNum
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.GetCygxActivityListRep)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 活动详情
- // @Description 获取活动详情接口
- // @Param ActivityId query int true "活动ID"
- // @Success Ret=200 {object} models.CygxActivityResp
- // @router /detail [get]
- func (this *ActivityCoAntroller) Detail() {
- 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
- }
- uid := user.UserId
- activityId, _ := this.GetInt("ActivityId")
- if activityId < 1 {
- br.Msg = "请输入活动ID"
- return
- }
- activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
- if activityInfo == nil {
- br.Msg = "活动不存在"
- br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
- return
- }
- detail, errDetail := models.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
- if errDetail != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
- return
- }
- if activityInfo.IsSignup > 0 {
- detail, errDetail := models.GetActivitySignupDetail(activityId, uid)
- if errDetail != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
- return
- }
- activityInfo.SignupType = detail.SignupType
- }
- activityInfo.ShowType = detail.ShowType
- resp := new(models.CygxActivityResp)
- hasPermission := 0
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- if user.CompanyId > 1 {
- permissionStr, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- return
- }
- companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
- //冻结客户
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- resp.HasPermission = 4
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
- return
- }
- }
- //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
- //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
- if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
- resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- resp.SellerMobile = companyItem.Mobile
- resp.OperationMode = "Call"
- hasPermission = 2
- } else {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
- hasPermission = 1
- resp.HaqveJurisdiction = true
- } else {
- resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- resp.SellerMobile = companyItem.Mobile
- resp.OperationMode = "Call"
- hasPermission = 2
- }
- }
- } else { //潜在客户
- if applyCount > 0 {
- hasPermission = 4
- } else {
- hasPermission = 3
- }
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
- }
- if hasPermission == 1 {
- if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
- activityInfo.SignupNum = activityInfo.LimitPeopleNum
- }
- resp.Detail = activityInfo
- }
- resp.HasPermission = hasPermission
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 活动报名
- // @Description 活动报名接口
- // @Param request body models.ActivitySingnupRep true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /signup/add [post]
- func (this *ActivityCoAntroller) SignupAdd() {
- 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
- }
- uid := user.UserId
- //var signupStatus string
- signupStatus := ""
- var req models.ActivitySingnupRep
- var total int
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- activityId := req.ActivityId
- signupType := req.SignupType
- //SignupStatus "报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
- //HasPermission "1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
- item := new(models.CygxActivitySignup)
- resp := new(models.SignupStatus)
- hasPermission := 0
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
- if activityInfo == nil {
- br.Msg = "操作失败"
- br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
- return
- }
- if errInfo != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errInfo.Error()
- return
- }
- if user.CompanyId > 1 {
- permissionStr, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
- //if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- //}
- //冻结客户
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- resp.HasPermission = 4
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
- return
- }
- }
- //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
- //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
- if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
- resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- resp.SellerMobile = companyItem.Mobile
- resp.OperationMode = "Call"
- hasPermission = 2
- } else {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
- hasPermission = 1
- signupStatus = "Success"
- resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
- if time.Now().After(resultTime.Add(-time.Minute * 60)) {
- signupStatus = "Overtime"
- }
- //人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
- //如果是下面几种情况则对报名信息做判断限制 (公司调研电话会(限制人数)、公司线下调研、专家/分析师线下沙龙)
- if (activityInfo.ActivityTypeId == 3 && activityInfo.IsLimitPeople == 1) || activityInfo.ActivityTypeId > 3 {
- //判断优先级:总人数限制→单机构2人限制→爽约3次限制
- total, err = models.GetUserRestrictCount(user.UserId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if total >= 1 {
- signupStatus = "BreakPromise"
- item.FailType = 3
- }
- total, err = models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if total >= 2 {
- signupStatus = "TwoPeople"
- item.FailType = 2
- }
- total, err = models.GetActivitySignupSuccessCount(activityId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if total >= activityInfo.LimitPeopleNum {
- signupStatus = "FullStarffed"
- item.FailType = 1
- }
- if signupStatus != "Success" {
- item.UserId = uid
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.SignupType = signupType
- //添加报名信息,但是不加入日程
- _, errSignup := models.AddActivitySignupNoSchedule(item)
- if errSignup != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errSignup.Error()
- return
- }
- }
- }
- total, err = models.GetActivitySignupCount(uid, activityId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if total > 0 {
- br.Msg = "您已报名这个活动"
- return
- }
- if signupStatus == "Success" {
- item.UserId = uid
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.SignupType = signupType
- item.FailType = 0
- _, errSignup := models.AddActivitySignup(item)
- if errSignup != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errSignup.Error()
- return
- }
- }
- resp.HaqveJurisdiction = true
- } else {
- resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- resp.SellerMobile = companyItem.Mobile
- resp.OperationMode = "Call"
- hasPermission = 2
- }
- }
- } else { //潜在客户
- if applyCount > 0 {
- hasPermission = 4
- } else {
- hasPermission = 3
- }
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
- }
- resp.SignupType = signupType
- resp.SignupStatus = signupStatus
- resp.HasPermission = hasPermission
- if signupStatus == "Success" {
- resp.ActivityId = activityId
- }
- total, err = models.GetUserMeetingReminderCount(user.UserId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
- return
- }
- if total == 0 {
- resp.GoFollow = true
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = resp
- }
- // @Title 活动取消报名
- // @Description 活动取消报名接口
- // @Param request body models.ActivitySingnupRep true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /signup/cancel [post]
- func (this *ActivityCoAntroller) SignupCancel() {
- 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
- }
- uid := user.UserId
- var req models.ActivitySingnupRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- activityId := req.ActivityId
- signupType := req.SignupType
- //if signupType != 1 && signupType != 2 {
- // br.Msg = "请选择正确的报名方式!"
- // return
- //}
- item := new(models.CygxActivitySignup)
- activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
- if activityInfo == nil {
- br.Msg = "操作失败"
- br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
- return
- }
- if errInfo != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errInfo.Error()
- return
- }
- resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
- if time.Now().After(resultTime.Add(-time.Minute * 60)) {
- if signupType == 1 {
- br.Msg = "活动开始前1小时内无法取消预约外呼,请联系对口销售处理"
- } else {
- br.Msg = "活动开始前1小时内无法取消报名,请联系对口销售处理"
- }
- return
- }
- total, err := models.GetActivitySignupCount(uid, activityId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if total == 0 {
- br.Msg = "您暂未报名这个活动"
- return
- }
- item.UserId = uid
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- resp := new(models.SignupStatus)
- resp.ActivityId = activityId
- _, errSignup := models.CancelActivitySignup(item)
- if errSignup != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errSignup.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = resp
- }
- // @Title 用户搜索详情
- // @Description 获取用户搜索详情接口
- // @Param IsShowJurisdiction query int true "是否仅展示有权限的,默认为0,1是,2否 "
- // @Success Ret=200 {object} models.ActivityUserSearchContentList
- // @router /getUserSearchContent [get]
- func (this *ActivityCoAntroller) GetUserSearchContent() {
- 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
- }
- uid := user.UserId
- detailSeearch := new(models.CygxActivityUserSearchContent)
- detailSeearch.IsShowJurisdiction = 0
- detailSeearch.ChartPermissionids = ""
- detailSeearch.ActiveState = ""
- detail, _ := models.GetUserSearchContentByUid(uid)
- if detail == nil {
- detail = detailSeearch
- }
- //if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取信息失败,Err:" + err.Error()
- // return
- //}
- isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
- //chartPermissionidsSlice := strings.Split(detail.ChartPermissionids, ",")
- //activityTypeidsSlice := strings.Split(detail.ActivityTypeids, ",")
- //activeStateSlice := strings.Split(detail.ActiveState, ",") //"活动进行状态 未开始:1、进行中2、已结束3"`
- listActivityType, errActivityType := models.GetActivityTypeList()
- if errActivityType != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + errActivityType.Error()
- return
- }
- //for _, v := range activityTypeidsSlice {
- // for k2, v2 := range listActivityType {
- // if strconv.Itoa(v2.ActivityTypeId) == v {
- // listActivityType[k2].IsChoose = true
- // }
- // }
- //}
- var listChartPermissionid []*models.ActivityChartPermission
- var errChart error
- if isShowJurisdiction == 1 {
- listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
- listChartPermissionid = listChartPermissionidAll
- errChart = errChartAll
- } else if isShowJurisdiction == 2 {
- listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
- listChartPermissionid = listChartPermissionidAll
- errChart = errChartAll
- } else {
- if detail.IsShowJurisdiction == 1 {
- listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
- listChartPermissionid = listChartPermissionidAll
- errChart = errChartAll
- } else {
- listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
- listChartPermissionid = listChartPermissionidAll
- errChart = errChartAll
- }
- }
- if errChart != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + errChart.Error()
- return
- }
- //for _, v := range chartPermissionidsSlice {
- // for k2, v2 := range listChartPermissionid {
- // if strconv.Itoa(v2.ChartPermissionId) == v {
- // listChartPermissionid[k2].IsChoose = true
- // }
- // }
- //}
- resp := new(models.ActivityUserSearchContentList)
- if detail.IsShowJurisdiction == 1 {
- resp.IsShowJurisdiction = true
- }
- fmt.Println(isShowJurisdiction)
- if isShowJurisdiction == 1 || detail.IsShowJurisdiction == 1 {
- resp.IsShowJurisdiction = true
- for k, _ := range listChartPermissionid {
- listChartPermissionid[k].IsChoose = true
- }
- }
- if isShowJurisdiction == 2 {
- resp.IsShowJurisdiction = false
- }
- activeStateList := []models.ActivityStaus{models.ActivityStaus{Id: 1, StatusName: "未开始", IsChoose: true}, models.ActivityStaus{Id: 2, StatusName: "进行中"}, models.ActivityStaus{Id: 3, StatusName: "已结束"}}
- //for _, v := range activeStateSlice {
- // for k2, v2 := range activeStateList {
- // if strconv.Itoa(v2.Id) == v {
- // //activeStateList[k2].IsChoose = true
- // }
- // }
- //}
- if activeStateList[1].IsChoose == activeStateList[2].IsChoose == false {
- activeStateList[0].IsChoose = true
- }
- resp.ListActivityType = listActivityType
- resp.ListChartPermission = listChartPermissionid
- resp.ListActivityStaus = activeStateList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 添加会议提醒
- // @Description 添加会议提醒接口
- // @Param request body models.ActivityIdRep true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /meetingReminder/add [post]
- func (this *ActivityCoAntroller) MeetingReminderAdd() {
- 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
- }
- uid := user.UserId
- //var signupStatus string
- signupStatus := "Success"
- var req models.ActivityIdRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- activityId := req.ActivityId
- //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
- item := new(models.CygxActivityMeetingReminder)
- resp := new(models.SignupStatus)
- hasPermission := 0
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
- if activityInfo == nil {
- br.Msg = "操作失败"
- br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
- return
- }
- if errInfo != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errInfo.Error()
- return
- }
- resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
- if time.Now().After(resultTime.Add(-time.Minute * 15)) {
- br.Msg = "活动开始前15分钟无法设置会议提醒"
- return
- }
- if user.CompanyId > 1 {
- permissionStr, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
- //if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- //}
- //冻结客户
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- resp.HasPermission = 4
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
- return
- }
- }
- if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
- resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- resp.SellerMobile = companyItem.Mobile
- resp.OperationMode = "Call"
- hasPermission = 2
- } else {
- if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
- hasPermission = 1
- signupStatus = "Success"
- totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
- if errMeeting != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
- return
- }
- if totalMeeting > 0 {
- br.Msg = "您已预约,请勿重复预约"
- return
- }
- item.UserId = uid
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- _, errSignup := models.AddActivityMeetingReminder(item)
- if errSignup != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errSignup.Error()
- return
- }
- resp.HaqveJurisdiction = true
- } else {
- resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- resp.SellerMobile = companyItem.Mobile
- resp.OperationMode = "Call"
- hasPermission = 2
- }
- }
- } else { //潜在客户
- if applyCount > 0 {
- hasPermission = 4
- } else {
- hasPermission = 3
- }
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
- }
- resp.HasPermission = hasPermission
- resp.SignupStatus = signupStatus
- resp.ActivityId = activityId
- var total int
- total, err = models.GetUserMeetingReminderCount(user.UserId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
- return
- }
- if total == 0 {
- resp.GoFollow = true
- }
- br.Ret = 200
- br.Success = true
- if hasPermission == 1 {
- br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
- }
- br.Data = resp
- }
- // @Title 取消会议提醒
- // @Description 取消会议提醒接口
- // @Param request body models.ActivityIdRep true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /meetingReminder/cancel [post]
- func (this *ActivityCoAntroller) MeetingReminderCancel() {
- 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
- }
- uid := user.UserId
- var req models.ActivityIdRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- activityId := req.ActivityId
- signupStatus := "Success"
- item := new(models.CygxActivityMeetingReminder)
- activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
- if activityInfo == nil {
- br.Msg = "操作失败"
- br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
- return
- }
- if errInfo != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errInfo.Error()
- return
- }
- //if signupStatus == "Success" {
- total, err := models.GetActivityMeetingReminderCount(uid, activityId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if total == 0 {
- br.Msg = "您暂未添加该活动会议提醒"
- return
- }
- resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
- if time.Now().After(resultTime.Add(-time.Minute * 15)) {
- br.Msg = "活动开始前15分钟无法取消会议提醒"
- return
- }
- item.UserId = uid
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- _, errSignup := models.CancelActivityMeetingReminder(item)
- if errSignup != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errSignup.Error()
- return
- }
- //}
- resp := new(models.SignupStatus)
- resp.SignupStatus = signupStatus
- resp.ActivityId = activityId
- br.Ret = 200
- br.Success = true
- br.Msg = "会议提醒已取消"
- br.Data = resp
- }
|