xingzai 2 rokov pred
rodič
commit
082eead789

+ 273 - 0
controllers/activity_special.go

@@ -1,12 +1,14 @@
 package controllers
 
 import (
+	"encoding/json"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
 	"strconv"
 	"strings"
+	"time"
 )
 
 //专项调研活动
@@ -324,3 +326,274 @@ func (this *ActivitySpecialCoAntroller) SpecialDetail() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title报名
+// @Description 感兴趣、不感兴趣接口
+// @Param	request	body models.ActivityIdRep true "type json string"
+// @Success Ret=200 {object} models.SignupSpecialStatus
+// @router /add [post]
+func (this *ActivitySpecialCoAntroller) 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
+	hasPermission := 0
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	//获取FICC销售信息
+	sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "申请失败"
+		br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
+		return
+	}
+
+	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
+	}
+	//HasPermission "1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
+	//var companyDetailStatus string
+	if user.CompanyId > 1 {
+		companyPermission, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+			return
+		}
+		if companyPermission == "" {
+			if applyCount > 0 {
+				hasPermission = 4
+			} else {
+				if sellerItem != nil {
+					hasPermission = 5
+				} else {
+					//获取权益销售信息 如果是FICC的客户类型,则默认他申请过
+					sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+					if err != nil && err.Error() != utils.ErrNoRow() {
+						br.Msg = "获取信息失败"
+						br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
+						return
+					}
+					if sellerItemQy != nil {
+						hasPermission = 2
+						resp.SellerMobile = sellerItemQy.Mobile
+						resp.SellerName = sellerItemQy.RealName
+					} else {
+						hasPermission = 3
+					}
+				}
+			}
+			resp.HasPermission = hasPermission
+			resp.ActivityId = activityId
+			resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "获取成功"
+			br.Data = resp
+			return
+		}
+		companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败!"
+			br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+			return
+		}
+		if companyDetail == nil {
+			br.Msg = "获取信息失败!"
+			br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
+			return
+		}
+	}
+	var userType int
+	var permissionStr string
+	userType, permissionStr, err = services.GetUserType(user.CompanyId)
+	if err != nil {
+		br.Msg = "获取信息失败!"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, "研选") {
+		br.Msg = "您暂无查看该活动权限"
+		br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
+		return
+	}
+
+	if user.CompanyId > 1 {
+		companyItem, err := models.GetCompanyDetailById(user.CompanyId)
+		//冻结客户
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				if applyCount > 0 {
+					hasPermission = 4
+				} else {
+					if sellerItem != nil {
+						hasPermission = 5
+					} else {
+						hasPermission = 3
+					}
+				}
+				resp.ActivityId = activityId
+				resp.HasPermission = hasPermission
+				resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
+				br.Ret = 200
+				br.Success = true
+				br.Msg = "获取成功"
+				br.Data = resp
+				return
+			} else {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
+				return
+			}
+		}
+		//判断是否有权限
+		var havePower bool
+		if strings.Contains(permissionStr, activityInfo.ActivityTypeName) {
+			havePower = true
+		}
+		if havePower {
+			hasPermission = 1
+		} else {
+			if companyItem.ProductId == 2 {
+				hasPermission = 2
+				resp.SellerMobile = companyItem.Mobile
+				resp.SellerName = companyItem.SellerName
+				if permissionStr == "专家" {
+					resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+				} else {
+					resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+				}
+			} else {
+				hasPermission = 5
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 4
+		} else {
+			if sellerItem != nil {
+				hasPermission = 5
+			} else {
+				hasPermission = 3
+			}
+		}
+		resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
+	}
+	resp.HasPermission = hasPermission
+	resp.ActivityId = activityId
+	if hasPermission == 1 {
+		resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
+		if time.Now().After(resultTime.Add(-time.Minute * 60)) {
+			resp.SignupStatus = 4
+			resp.PopupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
+			resp.PopupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "操作成功"
+			br.Data = resp
+			return
+		}
+		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
+			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:超时"`
+			resp.Status = 1
+			resp.SignupStatus = 1
+			resp.PopupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
+			resp.PopupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
+
+			////给所属销售发送消息
+			//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)
+			//		}
+			//	}
+			//}
+
+			// 给芳姐发消息
+			//cnf, _ := models.GetConfigByCode("tpl_msg")
+			//if cnf != nil {
+			//	openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
+			//	if openIpItem != nil && openIpItem.OpenId != "" {
+			//		actList, _ := models.GetActivityListSpecialAll(activityId)
+			//		if len(actList) == 5 {
+			//			var companyName string
+			//			for _, v := range actList {
+			//				companyName += "【" + v.CompanyName + "】"
+			//			}
+			//			go services.SendSpecialTemplateMsg(companyName, "", "", activityInfo.ResearchTheme, "", openIpItem)
+			//		}
+			//	}
+			//}
+			////用户专项调研操作行为,模板消息推送
+			//go services.SpecialActivityUserRemind(user, activityInfo, 1)
+		}
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = resp
+}

+ 2 - 0
models/activity_special_signup.go

@@ -22,9 +22,11 @@ type SignupSpecialStatus struct {
 	ActivityId    int    `description:"活动ID"`
 	HasPermission int    `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
 	PopupMsg      string `description:"权限弹窗信息"`
+	PopupMsg2     string `description:"权限弹窗信息"`
 	Status        int    `description:"返回类型,1:添加,2:取消"`
 	SellerMobile  string `description:"销售电话"`
 	SellerName    string `description:"销售姓名"`
+	SignupStatus  int    `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
 }
 
 //添加

+ 41 - 0
models/activity_special_trip.go

@@ -3,8 +3,26 @@ package models
 import (
 	//"hongze/hongze_admin/models"
 	"github.com/beego/beego/v2/client/orm"
+	"time"
 )
 
+type CygxActivitySpecialTrip struct {
+	Id             int       `orm:"column(id);pk"`
+	UserId         int       `description:"用户id,多个用,隔开"`
+	ActivityId     int       `description:"活动ID"`
+	CreateTime     time.Time `description:"创建时间"`
+	Mobile         string    `description:"手机号"`
+	Email          string    `description:"邮箱号"`
+	CompanyId      int       `description:"公司ID"`
+	CompanyName    string    `description:"公司名称"`
+	RealName       string    `description:"用户实际名称"`
+	SellerName     string    `description:"所属销售"`
+	AdminId        int       `description:"销售/管理员ID"`
+	Source         int       `description:"来源,1小程序,2后台添加"`
+	OutboundMobile string    `description:"外呼手机号"`
+	CountryCode    string    `description:"手机国家区号"`
+}
+
 type CygxActivitySpecialTripResp struct {
 	Id             int    `description:"ID"`
 	UserId         int    `description:"用户id"`
@@ -29,3 +47,26 @@ func GetCygxActivitySpecialTripList(condition string, pars []interface{}) (item
 	_, err = o.Raw(sql, pars).QueryRows(&item)
 	return
 }
+
+//获取某一用户的报名的数量
+func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip  WHERE  user_id=?  AND   activity_id =? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
+	return
+}
+
+//获取某一活动的报名的数量
+func GetActivitySpecialTripCountByActivityId(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip  WHERE    1 = 1 `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, condition, pars).QueryRow(&count)
+	return
+}
+
+//添加
+func AddCygxActivitySpecialTrip(item *CygxActivitySpecialTrip) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}

+ 1 - 0
models/db.go

@@ -125,6 +125,7 @@ func init() {
 		new(CygxMicroRoadshowVideoHistory),
 		new(MicroRoadshowVideo),
 		new(CygxActivityVideoHistory),
+		new(CygxActivitySpecialTrip),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 9 - 0
routers/commentsRouter.go

@@ -223,6 +223,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySpecialCoAntroller"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySpecialCoAntroller"],
+        beego.ControllerComments{
+            Method: "SpecialTripAdd",
+            Router: `/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySpecialCoAntroller"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySpecialCoAntroller"],
         beego.ControllerComments{
             Method: "SpecialDetail",

+ 39 - 0
services/activity_special_trip.go

@@ -0,0 +1,39 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/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
+	}
+	var condition string
+	var pars []interface{}
+
+	condition += ` AND activity_id LIKE ? `
+	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 = "活动开始前1小时内无法报名,请联系对口销售处理"
+		return
+	}
+	signupStatus = 4
+	popupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
+	popupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
+	return
+}