Bläddra i källkod

专项产业调研模块

xingzai 2 år sedan
förälder
incheckning
2adfdcd3ea

+ 532 - 0
controllers/activity_special.go

@@ -0,0 +1,532 @@
+package controllers
+
+import (
+	"encoding/json"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/services"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"time"
+)
+
+//专项调研活动
+type ActivitySpecialController struct {
+	BaseAuthController
+}
+
+// @Title 专项产业调研列表
+// @Description 获取专项产业调研列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} models.GetCygxActivitySpecialDetailListResp
+// @router /list [get]
+func (this *ActivitySpecialController) SpecialList() {
+	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
+	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "")
+	if errList != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + errList.Error()
+		return
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.GetCygxActivitySpecialDetailListResp)
+	count, err := models.GetCygxUserFollowSpecial(user.UserId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+		return
+	}
+	if count == 1 && user.UserId > 0 {
+		resp.IsFollow = true
+	}
+	if user.Mobile != "" {
+		resp.IsBindingMobile = true
+	}
+	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.CygxActivitySpecialResp
+// @router /detail [get]
+func (this *ActivitySpecialController) SpecialDetail() {
+	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
+	}
+	resp := new(models.CygxActivitySpecialResp)
+	activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
+		return
+	}
+	if activityInfo == nil {
+		br.Msg = "活动不存在"
+		br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
+		return
+	}
+	havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	//判断有没有对应的权限,如果没有则给出对应的状态码
+	if havePower {
+		resp.HasPermission = 1
+		count, err := models.GetCygxUserFollowSpecial(user.UserId)
+		if err != nil {
+			br.Msg = "获取数据失败!"
+			br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+			return
+		}
+		if count == 1 {
+			resp.IsFollow = true
+		}
+		activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
+		if err != nil {
+			br.Msg = "获取数据失败!"
+			br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
+			return
+		}
+		var condition string
+		var pars []interface{}
+
+		condition += ` AND t.activity_id =  ? AND t.is_cancel = 0 `
+		pars = append(pars, activityInfo.ActivityId)
+
+		tripTota, err := models.GetActivitySpecialTripCountByActivityId(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据失败!"
+			br.ErrMsg = "GetActivitySpecialTripCountByActivityId,Err:" + err.Error()
+			return
+		}
+		activityInfo.TripNum = tripTota
+		activityInfo.ActivityTypeName = "专项调研"
+		resp.Detail = activityInfo
+		resp.Detail = activityInfo
+	} else {
+		hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+			return
+		}
+		resp.PopupMsg = popupMsg
+		resp.HasPermission = hasPermission
+		resp.SellerName = sellerName
+		resp.SellerMobile = sellerMobile
+	}
+	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.SignupSpecialStatus
+// @router /trip/add [post]
+func (this *ActivitySpecialController) SpecialTripAdd() {
+	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
+	resp := new(models.SignupSpecialStatus)
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	activityId := req.ActivityId
+	activityInfo, errInfo := models.GetCygxActivitySpecialDetail(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
+	}
+
+	havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+
+	//判断有没有对应的权限,如果没有则给出对应的状态码
+	if havePower {
+		resp.HasPermission = 1
+		signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
+			return
+		}
+		resp.PopupMsg = popupMsg
+		resp.PopupMsg2 = popupMsg2
+		resp.SignupStatus = signupStatus
+
+		if signupStatus == 1 {
+			total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
+				return
+			}
+			//判断是删除还是添加
+			if total == 0 {
+				//获取销售信息
+				sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+				if err != nil {
+					br.Msg = "操作失败"
+					br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
+					return
+				}
+				item := new(models.CygxActivitySpecialTrip)
+				item.UserId = uid
+				item.RealName = user.RealName
+				item.ActivityId = activityId
+				item.CreateTime = time.Now()
+				item.Mobile = user.Mobile
+				item.Email = user.Email
+				item.CompanyId = user.CompanyId
+				item.CompanyName = user.CompanyName
+				item.IsValid = 1
+				if sellerItem != nil {
+					item.SellerName = sellerItem.RealName
+				}
+				err = models.AddCygxActivitySpecialTrip(item)
+				if err != nil {
+					br.Msg = "操作失败"
+					br.ErrMsg = "操作失败,Err:" + err.Error()
+					return
+				}
+				//SignupStatus  int    `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
+			} else {
+				updateParams := make(map[string]interface{})
+				updateParams["IsValid"] = 1
+				updateParams["CreateTime"] = time.Now()
+				updateParams["IsCancel"] = 0
+				whereParam := map[string]interface{}{"user_id": user.UserId, "activity_id": activityId}
+				err = models.UpdateByExpr(models.CygxActivitySpecialTrip{}, whereParam, updateParams)
+				if err != nil {
+					br.Msg = "报名失败,"
+					br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
+					return
+				}
+			}
+		}
+	} else {
+		hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+			return
+		}
+		resp.PopupMsg = popupMsg
+		resp.HasPermission = hasPermission
+		resp.SellerName = sellerName
+		resp.SellerMobile = sellerMobile
+	}
+	resp.ActivityId = activityId
+	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 /trip/cancel [post]
+func (this *ActivitySpecialController) Tripcancel() {
+	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
+	activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, 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)
+	//48小时之内的取消也扣除一次参会记录
+	var isValid int
+	if time.Now().Add(+time.Hour * 48).After(resultTime) {
+		isValid = 1
+	}
+	err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
+	if err != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "已取消"
+}
+
+// @Title 感兴趣、不感兴趣
+// @Description 感兴趣、不感兴趣接口
+// @Param	request	body models.ActivityIdRep true "type json string"
+// @Success Ret=200 {object} models.SignupSpecialStatus
+// @router /signup/add [post]
+func (this *ActivitySpecialController) SpecialSignupAdd() {
+	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
+	resp := new(models.SignupSpecialStatus)
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	activityId := req.ActivityId
+	activityInfo, errInfo := models.GetCygxActivitySpecialDetail(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
+	}
+	havePower, err := services.GetSpecialDetailUserPower(user, activityInfo)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	//判断有没有对应的权限,如果没有则给出对应的状态码
+	if havePower {
+		resp.HasPermission = 1
+		total, err := models.GetUserCygxActivitySpecialSignup(user.UserId, activityId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
+			return
+		}
+		resp.SignupStatus = 1
+		//判断是删除还是添加
+		if total == 0 {
+			//获取销售信息
+			sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
+				return
+			}
+			item := new(models.CygxActivitySpecialSignup)
+			item.UserId = uid
+			item.RealName = user.RealName
+			item.ActivityId = activityId
+			item.CreateTime = time.Now()
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			if sellerItem != nil {
+				item.SellerName = sellerItem.RealName
+			}
+			err = models.AddCygxActivitySpecialSignup(item)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,Err:" + err.Error()
+				return
+			}
+			resp.Status = 1
+			resp.PopupMsg = "感谢反馈"
+			resp.PopupMsg2 = "此调研具体行程尚未确认,待预报名人数满10人后弘则会确定行程并推送给您活动日期,只有在确认行程中再次报名才完成占位。"
+			//给所属销售发送消息
+			if sellerItem.Mobile != "" {
+				openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
+				if openIpItem != nil && openIpItem.OpenId != "" {
+					if sellerItem != nil {
+						//go services.SendSpecialTemplateMsg(user.RealName+"【"+user.CompanyName+"】", time.Now().Format(utils.FormatDateTime), user.Mobile, activityInfo.ResearchTheme, "sale", openIpItem)
+					}
+				}
+			}
+			// 给芳姐发消息
+			actList, _ := models.GetActivityListSpecialByActivityId(activityId)
+			if len(actList) == 10 {
+				go services.SendWxMsgActivitySpecial10(activityInfo)
+			}
+			//用户专项调研操作行为,模板消息推送
+			//go services.SpecialActivityUserRemind(user, activityInfo, 1)
+		} else {
+			err = models.DeleteCygxActivitySpecialSignup(user.UserId, activityId)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,Err:" + err.Error()
+				return
+			}
+			resp.Status = 2
+		}
+	} else {
+		hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+			return
+		}
+		resp.PopupMsg = popupMsg
+		resp.HasPermission = hasPermission
+		resp.SellerName = sellerName
+		resp.SellerMobile = sellerMobile
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = resp
+}
+
+// @Title 新调研通知取消跟添加
+// @Description 新调研通知取消跟添加接口
+// @Param	request	body models.ArticleCollectResp true "type json string"
+// @Success 200
+// @router /follow [post]
+func (this *ActivitySpecialController) SpecialMsg() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	resp := new(models.ArticleCollectResp)
+	count, err := models.GetCygxUserFollowSpecial(user.UserId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+		return
+	}
+	if count == 0 {
+		item := new(models.CygxUserFollowSpecial)
+		item.UserId = user.UserId
+		item.RealName = user.RealName
+		item.CreateTime = time.Now()
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.CreateTime = time.Now()
+		err := models.AddUserFollowSpecial(item)
+		if err != nil {
+			br.Msg = "操作失败!"
+			br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+			return
+		}
+		resp.Status = 1
+	} else {
+		err := models.DeleteCygxUserFollowSpecial(user.UserId)
+		if err != nil {
+			br.Msg = "操作失败!"
+			br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+			return
+		}
+		resp.Status = 2
+	}
+	br.Ret = 200
+	br.Data = resp
+	br.Success = true
+	br.Msg = "操作成功!"
+}

+ 43 - 0
models/activity_special.go

@@ -3,6 +3,7 @@ package models
 import (
 	//"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 //专项调研活动列表
@@ -112,3 +113,45 @@ WHERE
 	_, err = o.Raw(sql, uid, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+type GetCygxActivitySpecialDetailListResp struct {
+	IsFollow        bool               `description:"是否关注新调研通知"`
+	IsBindingMobile bool               `description:"是否绑定了手机号"`
+	Paging          *paging.PagingItem `description:"分页数据"`
+	List            []*CygxActivitySpecialDetail
+}
+
+type CygxActivitySpecialResp struct {
+	HasPermission int    `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
+	PopupMsg      string `description:"权限弹窗信息"`
+	SellerMobile  string `description:"销售电话"`
+	SellerName    string `description:"销售姓名"`
+	IsFollow      bool   `description:"是否关注新调研通知"`
+	Detail        *CygxActivitySpecialDetail
+}
+
+//通过活动ID获取活动详情
+func GetCygxActivitySpecialDetailById(uid, ActivityId int) (item *CygxActivitySpecialDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_activity_special_signup AS s WHERE s.activity_id = a.activity_id AND s.user_id = ? ) AS is_signup 
+FROM
+	cygx_activity_special AS a 
+WHERE
+	activity_id = ?
+	AND publish_status = 1 	AND is_offline = 0  `
+	err = o.Raw(sql, uid, ActivityId).QueryRow(&item)
+	return
+}
+
+type ActivityIdRep struct {
+	ActivityId  int `description:"活动id"`
+	PlaySeconds int `description:"播放时长"`
+}
+
+//通过活动ID获取活动详情
+func GetCygxActivitySpecialDetail(ActivityId int) (item *CygxActivitySpecialDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_activity_special  WHERE activity_id=? AND publish_status = 1 `
+	err = o.Raw(sql, ActivityId).QueryRow(&item)
+	return
+}

+ 3 - 0
models/db.go

@@ -45,6 +45,9 @@ func init() {
 		new(CygxActivitySignup),
 		new(CygxActivitySignupLog),
 		new(CygxMySchedule),
+		new(CygxActivitySpecialSignup),
+		new(CygxUserFollowSpecial),
+		new(CygxActivitySpecialTrip),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 40 - 0
models/user_follow_special.go

@@ -0,0 +1,40 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserFollowSpecial struct {
+	Id          int       `orm:"column(id);pk"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+}
+
+//添加
+func AddUserFollowSpecial(item *CygxUserFollowSpecial) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+//获取某一用户的报名的数量
+func GetCygxUserFollowSpecial(uid int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_user_follow_special  WHERE  user_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid).QueryRow(&count)
+	return
+}
+
+//删除
+func DeleteCygxUserFollowSpecial(uid int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE  FROM cygx_user_follow_special   WHERE  user_id=? `
+	_, err = o.Raw(sql, uid).Exec()
+	return
+}

+ 54 - 0
routers/commentsRouter.go

@@ -52,6 +52,60 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"],
+        beego.ControllerComments{
+            Method: "SpecialDetail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"],
+        beego.ControllerComments{
+            Method: "SpecialMsg",
+            Router: `/follow`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"],
+        beego.ControllerComments{
+            Method: "SpecialList",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"],
+        beego.ControllerComments{
+            Method: "SpecialSignupAdd",
+            Router: `/signup/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"],
+        beego.ControllerComments{
+            Method: "SpecialTripAdd",
+            Router: `/trip/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ActivitySpecialController"],
+        beego.ControllerComments{
+            Method: "Tripcancel",
+            Router: `/trip/cancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ArticleController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ArticleController"],
         beego.ControllerComments{
             Method: "AskAdd",

+ 5 - 0
routers/router.go

@@ -90,6 +90,11 @@ func init() {
 				&controllers.ActivityController{},
 			),
 		),
+		web.NSNamespace("/activity_special",
+			web.NSInclude(
+				&controllers.ActivitySpecialController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 127 - 0
services/activity_special_trip.go

@@ -0,0 +1,127 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"time"
+)
+
+func SpecialTripPopupMsg(activityInfo *models.CygxActivitySpecialDetail, user *models.WxUserItem) (signupStatus int, popupMsg, popupMsg2 string, err error) {
+	//SignupStatus  int    `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
+	signupStatus = 1
+	resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
+	if time.Now().After(resultTime.Add(-time.Minute * 60)) {
+		signupStatus = 4
+		popupMsg = "活动开始前1小时内无法报名,请联系对口销售处理"
+		return
+	}
+
+	errMsg, _, e := GetTripRemainingtimesBycompany(user, activityInfo)
+	if e != nil {
+		err = errors.New("获取客户剩余报名次数失败 GetActivitySpecialUserType, Err: " + e.Error())
+		return
+	}
+	if errMsg != "" {
+		popupMsg = errMsg
+		signupStatus = 3
+		return
+	}
+	var condition string
+	var pars []interface{}
+
+	condition += ` AND activity_id =  ? AND  is_cancel = 0 `
+	pars = append(pars, activityInfo.ActivityId)
+
+	tripTota, e := models.GetActivitySpecialTripCountByActivityId(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
+		return
+	}
+	if activityInfo.LimitPeopleNum-tripTota < 1 {
+		signupStatus = 2
+		popupMsg = "此活动报名人数已满,请留意下期活动"
+		return
+	}
+	//signupStatus = 4
+	popupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
+	popupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
+	return
+}
+
+//获取用户剩余报名次数
+func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, tripRemaining int, err error) {
+
+	//获取 专项调研客户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户 8:行业升级套餐客户
+	msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
+	var tripTota int
+	var airborneTota int
+	userType, _, e := GetActivitySpecialUserType(user.CompanyId)
+	if e != nil {
+		err = errors.New("获取客户身份信息失败 GetActivitySpecialUserType, Err: " + e.Error())
+		return
+	}
+	if userType == 0 {
+		errMsg = msgTemplate
+		return
+	} else if userType == 1 {
+		tripRemaining = 999
+		return
+	} else if userType == 2 {
+		var condition string
+		var pars []interface{}
+
+		condition += ` AND company_id = ? `
+		pars = append(pars, user.CompanyId)
+
+		airborneTota, e = models.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
+		if e != nil {
+			err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
+			return
+		}
+
+		condition += ` AND is_valid = 1 `
+
+		tripTota, e = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
+		if e != nil {
+			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
+			return
+		}
+		tripTota += airborneTota
+		if tripTota >= 12 {
+			errMsg = msgTemplate
+			return
+		}
+		tripRemaining = 12 - tripTota
+	} else {
+		var condition string
+		var pars []interface{}
+
+		condition += ` AND company_id = ? `
+		pars = append(pars, user.CompanyId)
+
+		condition += ` AND chart_permission_id = ? `
+		pars = append(pars, activityInfo.ChartPermissionId)
+
+		airborneTota, e = models.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
+		if e != nil {
+			err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
+			return
+		}
+
+		condition += ` AND is_valid = 1 `
+
+		tripTota, e = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
+		if e != nil {
+			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
+			return
+		}
+		tripTota += airborneTota
+		if tripTota >= 6 {
+			errMsg = msgTemplate
+			return
+		}
+		tripRemaining = 6 - tripTota
+	}
+	return
+}