package controllers import ( "encoding/json" "fmt" "hongze/hongze_open_api/models/request/yidong" "hongze/hongze_open_api/models/tables/company_product" cygxActivity "hongze/hongze_open_api/models/tables/cygx/cygx_activity" "hongze/hongze_open_api/models/tables/cygx/cygx_three_api_log" "hongze/hongze_open_api/services/alarm_msg" servicesYidong "hongze/hongze_open_api/services/yidong" "hongze/hongze_open_api/utils" "math" "strconv" "strings" "time" ) // 易董 type YiDongController struct { BaseCommon } // YiDongController // @Title 易董提交报名用户审核接口 // @Description 易董提交报名用户审核接口 // @Param request body yidong.ActivityExamineReq true "type json string" // @Success 200 创建成功 // @router /activity/examine/signup [post] func (c *YiDongController) ActivityExamine() { var req yidong.ActivityExamineReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常") return } activityIdYiDong := req.ActivityId timeInt := req.Time list := req.List appid := req.Appid timeUnix := time.Now().Unix() //当前格林威治时间,int64类型 timestamp := int64(timeInt) if math.Abs(float64(timeUnix-timestamp)) > 600 { c.FailWithMessage("当前时间异常,请调整设备时间与北京时间一致:" + strconv.Itoa(timeInt)) return } //校验 APPID 与ip白名单 ip := c.Ctx.Input.IP() err = servicesYidong.CheckAppidAndIp(appid, ip) if err != nil { c.FailWithMessage(err.Error()) return } //校验 签名 signStr := servicesYidong.GetSign(activityIdYiDong, timeInt) ownSign := req.Sign if ownSign != signStr { c.FailWithMessage("签名错误!") return } activityInfo, err := cygxActivity.GetAddActivityInfoById(activityIdYiDong) if err != nil { c.FailWithMessage("会议id异常:" + activityIdYiDong) return } activityId := activityInfo.ActivityId var examineMobile string var delMyMobile string //审核不通过需要删除日程的手机号 var delSignupMobile string //取消活动需要删除报名信息的手机号 var itemsLog []*cygxActivity.CygxYidongActivityExamineStatus for _, v := range list { var dateTxt = []byte(v.Mobile) resultDe := utils.DesBase64Decrypt(dateTxt) deMobile := string(resultDe) if deMobile == "" { go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+v.Mobile, 3) c.FailWithMessage("加密手机号解密失败:" + v.Mobile) return } examineMobile += "'" + deMobile + "'" + "," itemlog := new(cygxActivity.CygxYidongActivityExamineStatus) //记录日志 itemlog.ActivityId = activityId itemlog.YidongActivityId = activityIdYiDong itemlog.CreateTime = time.Now() itemlog.ExamineTime = v.CreateTime itemlog.Mobile = deMobile itemlog.YidongExamineStatus = v.ExamineStatus itemsLog = append(itemsLog, itemlog) } //记录日志 err = cygxActivity.AddActivityItemsLogNumMulti(itemsLog) if err != nil { c.FailWithMessage("修改活动审核状态失败:" + activityIdYiDong) go alarm_msg.SendAlarmMsg("修改活动审核状态失败AddActivityItemsLogNumMulti:"+err.Error()+"活动ID"+activityIdYiDong, 3) return } //以下处理传过来的逻辑 // 获取已经报名了的用户列表 signupList, err := cygxActivity.GetActivitySignupListByActivity(activityId) if err != nil { c.FailWithMessage("会议id异常:" + activityIdYiDong) return } mapSignUp := make(map[string]string) for _, v := range signupList { mapSignUp[v.Mobile] = v.Mobile } // 获取我的日程列表 myScheduleList, err := cygxActivity.GetCygxMyScheduleList(activityId) if err != nil { c.FailWithMessage("会议id异常:" + activityIdYiDong) return } mapMyScheduleList := make(map[string]string) for _, v := range myScheduleList { mapMyScheduleList[v.Mobile] = v.Mobile } examineMobile = strings.TrimRight(examineMobile, ",") userList, err := cygxActivity.GetUserListByMobile(examineMobile) if err != nil { c.FailWithMessage("操作失败,用户信息不存在") return } mapUserinfo := make(map[string]*cygxActivity.CygxActivitySignup) mapMySchedule := make(map[string]*cygxActivity.CygxMySchedule) for _, v := range userList { item := new(cygxActivity.CygxActivitySignup) item.UserId = v.UserId item.RealName = v.RealName item.SellerName = v.SellerName item.ActivityId = activityId item.CreateTime = time.Now() item.Mobile = v.Mobile item.Email = v.Email item.CompanyId = v.CompanyId item.CompanyName = v.CompanyName item.Source = 3 //优先绑定用户修改过的外呼手机号 if v.OutboundMobile != "" { item.OutboundMobile = v.OutboundMobile if v.OutboundCountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = v.OutboundCountryCode } } else { item.OutboundMobile = v.Mobile if v.CountryCode == "" { item.CountryCode = "86" } else { item.CountryCode = v.CountryCode } } item.SignupType = 1 mapUserinfo[v.Mobile] = item //添加我的日程 itemMySchedule := new(cygxActivity.CygxMySchedule) itemMySchedule.UserId = v.UserId itemMySchedule.ActivityId = activityId itemMySchedule.CreateTime = time.Now() itemMySchedule.Mobile = v.Mobile itemMySchedule.Email = v.Email itemMySchedule.CompanyId = v.CompanyId itemMySchedule.CompanyName = v.CompanyName mapMySchedule[v.Mobile] = itemMySchedule } var items []*cygxActivity.ExamineStatusReq var itemsAdd []*cygxActivity.CygxActivitySignup var itemsMyAdd []*cygxActivity.CygxMySchedule for _, v := range list { item := new(cygxActivity.ExamineStatusReq) var dateTxt = []byte(v.Mobile) resultDe := utils.DesBase64Decrypt(dateTxt) deMobile := string(resultDe) if mapSignUp[deMobile] != "" { item.ActivityId = activityId item.Mobile = deMobile item.ExamineStatus = v.ExamineStatus items = append(items, item) } else { if mapUserinfo[deMobile] != nil { mapUserinfo[deMobile].YidongExamineStatus = v.ExamineStatus if v.ExamineStatus != 3 { itemsAdd = append(itemsAdd, mapUserinfo[deMobile]) } } } //处理我的日程 if mapMyScheduleList[deMobile] != "" { if v.ExamineStatus != 1 { delMyMobile += "'" + deMobile + "'" + "," } if v.ExamineStatus == 3 { delSignupMobile += "'" + deMobile + "'" + "," } } else { if mapMySchedule[deMobile] != nil { if v.ExamineStatus == 1 { itemsMyAdd = append(itemsMyAdd, mapMySchedule[deMobile]) } } } } //fmt.Println(delSignupMobile) //return //处理要删除的日程 delMyMobile = strings.TrimRight(delMyMobile, ",") if delMyMobile != "" { fmt.Println("删除日程") err = cygxActivity.DelCygxMyScheduleList(delMyMobile, activityId) if err != nil { go alarm_msg.SendAlarmMsg("处理要删除的日程失败 DelCygxMyScheduleList:"+err.Error()+"活动ID"+activityIdYiDong, 3) } } //处理要删除的报名信息 delSignupMobile = strings.TrimRight(delSignupMobile, ",") if delSignupMobile != "" { fmt.Println("处理要删除的报名信息") err = cygxActivity.DelCygxcActivitySignup(delSignupMobile, activityId) if err != nil { go alarm_msg.SendAlarmMsg("处理要删除的报名信息失败 DelCygxMyScheduleList:"+err.Error()+"活动ID"+activityIdYiDong, 3) } } //修改审核状态 err = cygxActivity.UpdateActivitySignupNumMulti(items) if err != nil { fmt.Println(err, "UpdateActivitySignupNumMulti") go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3) } // 批量添加报名信息 err = cygxActivity.AddActivitySignupNumMulti(itemsAdd) if err != nil { fmt.Println(err, "AddActivitySignupNumMulti") go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3) } // 批量添加我的日程 err = cygxActivity.AddCygxMyScheduleLNumMulti(itemsMyAdd) if err != nil { fmt.Println(err, "AddCygxMyScheduleLNumMulti") go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3) } c.OkWithMessage("操作成功") } // YiDongController // @Title 易董提交报名时,获取用户信息接口 // @Description 易董提交报名时,获取用户信息接口 // @Param request body yidong.ActivityExamineReq true "type json string" // @Success 200 创建成功 // @router /activity/user/signup [post] func (c *YiDongController) UserSignup() { var req yidong.ActivitySignUpReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常") return } activityIdYiDong := req.ActivityId timeInt := req.Time appid := req.Appid mobile := req.Mobile timeUnix := time.Now().Unix() //当前格林威治时间,int64类型 timestamp := int64(timeInt) if math.Abs(float64(timeUnix-timestamp)) > 600 { c.FailWithMessage("当前时间异常,请调整设备时间与北京时间一致:" + strconv.Itoa(timeInt)) return } //校验 APPID 与ip白名单 ip := c.Ctx.Input.IP() err = servicesYidong.CheckAppidAndIp(appid, ip) if err != nil { c.FailWithMessage(err.Error()) return } //校验 签名 signStr := servicesYidong.GetSign(activityIdYiDong, timeInt) fmt.Println("____") fmt.Println(signStr) ownSign := req.Sign if ownSign != signStr { c.FailWithMessage("签名错误!") return } activityInfo, err := cygxActivity.GetAddActivityInfoById(activityIdYiDong) if err != nil { c.FailWithMessage("会议id异常:" + activityIdYiDong) return } activityId := activityInfo.ActivityId var dateTxt = []byte(mobile) resultDe := utils.DesBase64Decrypt(dateTxt) deMobile := string(resultDe) if deMobile == "" { go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+mobile, 3) c.FailWithMessage("加密手机号解密失败:" + mobile) return } item := new(cygxActivity.CygxYidongActivitySignupLog) item.ActivityId = activityId item.YidongActivityId = activityIdYiDong item.CreateTime = time.Now() item.Mobile = deMobile err = cygxActivity.AddCygxYidongActivitySignupLog(item) if err != nil { fmt.Println(err) c.FailWithMessage("获取用户信息失败:" + activityIdYiDong) go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3) return } userInfo, err := cygxActivity.GetAddActivityInfoByMobile(deMobile) if err != nil { fmt.Println(err) c.FailWithMessage("获取用户信息失败:" + activityIdYiDong) go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3) return } c.OkDetailed(userInfo, "获取成功") } // YiDongController // @Title 校验用户是否有对应权限 // @Description 校验用户是否有对应权限接口 // @Param request body yidong.ActivityExamineReq true "type json string" // @Success 200 创建成功 // @router /activity/user/check [post] func (c *YiDongController) UserCheck() { var req yidong.ActivitySignUpReq err := json.Unmarshal(c.Ctx.Input.RequestBody, &req) if err != nil { c.FailWithMessage("参数解析异常") return } activityIdYiDong := req.ActivityId timeInt := req.Time appid := req.Appid mobile := req.Mobile timeUnix := time.Now().Unix() //当前格林威治时间,int64类型 timestamp := int64(timeInt) if math.Abs(float64(timeUnix-timestamp)) > 600 { c.FailWithMessage("当前时间异常,请调整设备时间与北京时间一致:" + strconv.Itoa(timeInt)) return } //校验 APPID 与ip白名单 ip := c.Ctx.Input.IP() err = servicesYidong.CheckAppidAndIp(appid, ip) if err != nil { c.FailWithMessage(err.Error()) return } signStr := servicesYidong.GetSign(activityIdYiDong, timeInt) ownSign := req.Sign if ownSign != signStr { c.FailWithMessage("签名错误!") return } //activityDetail, err := cygxActivity.GetAddActivityInfoById(activityIdYiDong) //if err != nil { // c.FailWithMessage("会议id异常:" + activityIdYiDong) // return //} var dateTxt = []byte(mobile) resultDe := utils.DesBase64Decrypt(dateTxt) deMobile := string(resultDe) if deMobile == "" { go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+mobile, 3) c.FailWithMessage("加密手机号解密失败:" + mobile) return } resp := new(yidong.CheckHaspermissionResp) total, err := company_product.CheckUserAaiPerssionByMobile(deMobile) if err != nil { c.FailWithMessage("校验失败!" + err.Error()) return } ////获取所有的权限名称 //companyPermissionName, err := company_product.GetCompanyPermissionByMobile(deMobile) //if err != nil { // c.FailWithMessage("校验失败!" + err.Error()) // return //} //if companyPermissionName != "" { // companyPermissionName += ",宏观" // 有任意一个权限,就可以参加宏观权限的活动 //} //if strings.Contains(companyPermissionName, activityDetail.ChartPermissionName) { // resp.Haspermission = true //} //校验是否是系统内权益的正式、试用、永续客户(不区分行业),若是,返回审核通过 if total > 0 { resp.Haspermission = true } else { statusResp, err := servicesYidong.GetClptCrmWorkerRule(deMobile) if err != nil { c.FailWithMessage("校验失败!" + err.Error()) return } if statusResp == 1 { resp.Haspermission = true } } //添加请求日志记录 itemApiLog := new(cygx_three_api_log.CygxThreeApiLog) itemApiLog.CreateTime = time.Now() itemApiLog.Source = 2 itemApiLog.Url = c.Ctx.Input.URI() data, _ := json.Marshal(req) jsonstr := string(data) itemApiLog.Body = fmt.Sprint(jsonstr, "deMobile=", deMobile) itemApiLog.Result = fmt.Sprint(resp) _, errlog := cygx_three_api_log.AddCygxThreeApiLog(itemApiLog) if errlog != nil { go alarm_msg.SendAlarmMsg("易董校验用户是否有对应权限日志记录失败 AddCygxThreeApiLog:"+errlog.Error()+fmt.Sprint(req, "deMobile=", deMobile), 3) } c.OkDetailed(resp, "获取成功") }