Browse Source

添加,取消会议提醒

xingzai 3 years ago
parent
commit
e0e1f1437a
4 changed files with 162 additions and 63 deletions
  1. 134 46
      controllers/activity.go
  2. 11 3
      models/activity_meeting_reminder.go
  3. 15 14
      models/activity_signup.go
  4. 2 0
      models/db.go

+ 134 - 46
controllers/activity.go

@@ -337,52 +337,51 @@ func (this *ActivityCoAntroller) SignupAdd() {
 	}
 	//SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
 	item := new(models.CygxActivitySignup)
-	if activityId%5 == 1 {
-		signupStatus = "FullStarffed"
-		item.FailType = 1
-	} else if activityId%5 == 2 {
-		signupStatus = "TwoPeople"
-		item.FailType = 2
-	} else if activityId%5 == 3 {
-		signupStatus = "BreakPromise"
-		item.FailType = 3
-	} else if activityId%5 == 4 {
+	//if activityId%5 == 1 {
+	//	signupStatus = "FullStarffed"
+	//	item.FailType = 1
+	//} else if activityId%5 == 2 {
+	//	signupStatus = "TwoPeople"
+	//	item.FailType = 2
+	//} else if activityId%5 == 3 {
+	//	signupStatus = "BreakPromise"
+	//	item.FailType = 3
+	//} else if activityId%5 == 4 {
+	//	signupStatus = "Overtime"
+	//} else if activityId%5 == 5 {
+	//	signupStatus = "Success"
+	//}
+	signupStatus = "Success"
+	fmt.Println(signupStatus)
+
+	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)) {
 		signupStatus = "Overtime"
-	} else if activityId%5 == 5 {
-		signupStatus = "Success"
+		return
 	}
-	fmt.Println(signupStatus)
-	if item.FailType > 1 {
-		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
-		}
+	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()
@@ -588,7 +587,7 @@ func (this *ActivityCoAntroller) MeetingReminderAdd() {
 	}
 	uid := user.UserId
 	//var signupStatus string
-	signupStatus := ""
+	signupStatus := "Success"
 	var req models.ActivityIdRep
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
@@ -597,7 +596,6 @@ func (this *ActivityCoAntroller) MeetingReminderAdd() {
 		return
 	}
 	activityId := req.ActivityId
-	signupStatus = "Success"
 	//SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
 	item := new(models.CygxActivityMeetingReminder)
 	activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
@@ -627,6 +625,18 @@ func (this *ActivityCoAntroller) MeetingReminderAdd() {
 			br.Msg = "您暂未预约外呼这个活动"
 			return
 		}
+
+		totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
+		if errMeeting != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if totalMeeting > 0 {
+			br.Msg = "您已预约,请勿重复预约"
+			return
+		}
+
 		item.UserId = uid
 		item.ActivityId = activityId
 		item.CreateTime = time.Now()
@@ -651,3 +661,81 @@ func (this *ActivityCoAntroller) MeetingReminderAdd() {
 	br.Msg = "操作成功"
 	br.Data = resp
 }
+
+// @Title 取消会议提醒
+// @Description 取消会议提醒接口
+// @Param	request	body models.ActivityIdRep true "type json string"
+// @Success 200 操作成功
+// @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
+	}
+	resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
+	if time.Now().After(resultTime.Add(-time.Minute * 15)) {
+		signupStatus = "Overtime"
+		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
+		}
+		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
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = resp
+}

+ 11 - 3
models/activity_meeting_reminder.go

@@ -42,10 +42,18 @@ func AddActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64
 			o.Rollback()
 		}
 	}()
-	lastId, err = o.Insert(item)
+	var count int
+	sql := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
 	if err != nil {
 		return
 	}
+	if count > 0 {
+		sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 0  WHERE user_id=?  AND activity_id=? `
+		_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
+	} else {
+		lastId, err = o.Insert(item)
+	}
 	itemLog := new(CygxActivityMeetingReminderLog)
 	itemLog.UserId = item.UserId
 	itemLog.ActivityId = item.ActivityId
@@ -61,7 +69,7 @@ func AddActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64
 
 //获取用户报名数量
 func GetActivityMeetingReminderCount(uid, activityId int) (count int, err error) {
-	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_MeetingReminder WHERE is_cancel=0 AND user_id=? AND activity_id=? `
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel=0 AND user_id=? AND activity_id=? `
 	o := orm.NewOrm()
 	err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
 	return
@@ -79,7 +87,7 @@ func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId in
 			o.Rollback()
 		}
 	}()
-	sql := `UPDATE cygx_activity_MeetingReminder SET is_cancel = 1  WHERE user_id=?  AND activity_id=? `
+	sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 1  WHERE user_id=?  AND activity_id=? `
 	_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
 	if err != nil {
 		return

+ 15 - 14
models/activity_signup.go

@@ -19,7 +19,7 @@ type CygxActivitySignup struct {
 }
 
 type SignupStatus struct {
-	SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
+	SignupStatus string `description:"返回状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
 	GoFollow     bool   `description:"是否去关注"`
 	SignupType   int    `description:"报名方式,1预约外呼,2我要报名"`
 }
@@ -49,19 +49,20 @@ func AddActivitySignup(item *CygxActivitySignup) (lastId int64, err error) {
 			o.Rollback()
 		}
 	}()
-	//var count int
-	//sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
-	//err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
-	//if err != nil {
-	//	return
-	//}
-	//if count > 0 {
-	//	sql := `DELETE  FROM cygx_activity_signup  WHERE user_id=? AND activity_id=? `
-	//	_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
-	//} else {
-	//	lastId, err = o.Insert(item)
-	//}
-	lastId, err = o.Insert(item)
+	var count int
+	sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
+	if err != nil {
+		return
+	}
+	if count > 0 {
+		sql := `UPDATE cygx_activity_signup SET is_cancel = 0  WHERE user_id=?  AND activity_id=? `
+		_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
+	} else {
+		lastId, err = o.Insert(item)
+	}
+	//lastId, err = o.Insert(item)
+	//fmt.Println(lastId)
 	if err != nil {
 		return
 	}

+ 2 - 0
models/db.go

@@ -52,5 +52,7 @@ func init() {
 		new(CygxActivitySignup),
 		new(CygxActivitySignupLog),
 		new(CygxActivityUserSearchContent),
+		new(CygxActivityMeetingReminder),
+		new(CygxActivityMeetingReminderLog),
 	)
 }