/// <summary> /// 设置用户token信息 /// </summary> /// <param name="UserId">用户标识</param> /// <param name="AccessToken">token不存在</param> private void SetAccessToken(string UserId, string AccessToken, LoggingSessionInfo loggingSessionInfo, string resultErrorUrl) { try { if (UserId == null || UserId.Trim().Equals("")) { Loggers.Debug(new DebugLogInfo() { Message = string.Format("新浪回调页面2-用户标识为空") }); } Response.Write("设置用户token信息1"); #region 处理业务 #region 判断用户是否存在会员表中 VipBLL vipServer = new VipBLL(loggingSessionInfo); VipEntity vipInfo = vipServer.GetByID(UserId); if (vipInfo == null || vipInfo.VIPID == null || vipInfo.VIPID.Equals("")) { vipInfo.VIPID = UserId; vipInfo.VipCode = vipServer.GetVipCode(); vipInfo.ClientID = loggingSessionInfo.CurrentUser.customer_id; vipInfo.Status = 1; vipServer.Create(vipInfo); } #endregion #region 判断用户是否存在会员的新浪微博扩展表中 VipExpandSinaWbBLL vipSinaWbServer = new VipExpandSinaWbBLL(loggingSessionInfo); VipExpandSinaWbEntity vipSinaWbInfo = new VipExpandSinaWbEntity(); vipSinaWbInfo = vipSinaWbServer.GetByID(UserId); if (vipSinaWbInfo != null && vipSinaWbInfo.VipId != null && !vipSinaWbInfo.VipId.Equals("")) { vipSinaWbInfo.AccessToken = AccessToken; vipSinaWbServer.Update(vipSinaWbInfo, false); } else { VipExpandSinaWbEntity vipSinaWbInfo1 = new VipExpandSinaWbEntity(); vipSinaWbInfo1.VipId = UserId; vipSinaWbInfo1.AccessToken = AccessToken; vipSinaWbServer.Create(vipSinaWbInfo1); } #endregion #endregion Loggers.Debug(new DebugLogInfo() { Message = string.Format("新浪回调页面3-设置用户信息成功.") }); } catch (Exception ex) { Loggers.Debug(new DebugLogInfo() { Message = string.Format("新浪回调页面4-错误信息提示 {0}:" + ex.ToString()) }); Response.Write(ex.ToString()); } }
/// <summary> /// 保存会员 /// </summary> public string SaveVipData() { var service = new VipBLL(CurrentUserInfo); VipEntity vip = new VipEntity(); string content = string.Empty; var responseData = new ResponseData(); string key = string.Empty; string vip_id = string.Empty; if (Request("vip") != null && Request("vip") != string.Empty) { key = Request("vip").ToString().Trim(); } if (Request("VipId") != null && Request("VipId") != string.Empty) { vip_id = Request("VipId").ToString().Trim(); } vip = key.DeserializeJSONTo <VipEntity>(); if (vip.VipName == null || vip.VipName.Trim().Length == 0) { responseData.success = false; responseData.msg = "会员名称不能为空"; return(responseData.ToJSON()); } bool status = true; string message = "保存成功"; if (vip.VIPID.Trim().Length == 0) { vip.VIPID = Utils.NewGuid(); vip.ClientID = this.CurrentUserInfo.CurrentUser.customer_id; vip.Status = 1; service.Create(vip); } else { vip.VIPID = vip_id; service.Update(vip, false); } responseData.success = status; responseData.msg = message; content = responseData.ToJSON(); return(content); }
const int MEMBER_HAVECARDNOTIPS = 320; //领取成功 不提示 但跳到实体卡 #endregion protected override AuthCodeLoginRD ProcessRequest(DTO.Base.APIRequest <AuthCodeLoginRP> pRequest) { var vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo); //参数验证 if (string.IsNullOrEmpty(pRequest.Parameters.Mobile)) { throw new APIException("请求参数中缺少Mobile或值为空.") { ErrorCode = ERROR_LACK_MOBILE }; } if (pRequest.Parameters.VipSource.HasValue == false) { pRequest.Parameters.VipSource = 1; //throw new APIException("请求参数中缺少VipSource或值为空.") { ErrorCode = ERROR_LACK_VIP_SOURCE }; } // AuthCodeLoginRD rd = new AuthCodeLoginRD(); var bll = new VipBLL(this.CurrentUserInfo); var codebll = new RegisterValidationCodeBLL(base.CurrentUserInfo); VipEntity vipByID = null; //根据VIP ID查找出来的VIP记录 VipEntity vipByPhone = null; //根据手机号查找出来的VIP记录 //var list = codebll.QueryByEntity(new RegisterValidationCodeEntity() //{ // Mobile = pRequest.Parameters.Mobile //}, null); //bool b = false; //if (list != null) //{ // foreach (var entity in list) // { // if (entity == null) // throw new APIException("未找到此手机的验证信息") {ErrorCode = ERROR_AUTHCODE_NOTEXISTS}; // //if (entity.IsValidated.Value == 1) // // throw new APIException("此验证码已被使用") {ErrorCode = ERROR_AUTHCODE_WAS_USED}; // //if (entity.Expires.Value < DateTime.Now) // // throw new APIException("此验证码已失效") {ErrorCode = ERROR_AUTHCODE_INVALID}; // if (entity.Code == pRequest.Parameters.AuthCode) // b = true; // } //} //if (!b) //{ // throw new APIException("验证码不正确.") { ErrorCode = ERROR_AUTHCODE_NOT_EQUALS }; //} #region 验证验证码 var entity = codebll.GetByMobile(pRequest.Parameters.Mobile); if (entity == null) { throw new APIException("未找到此手机的验证信息") { ErrorCode = ERROR_AUTHCODE_NOTEXISTS } } ; if (entity.IsValidated.Value == 1) { throw new APIException("此验证码已被使用") { ErrorCode = ERROR_AUTHCODE_WAS_USED } } ; if (entity.Expires.Value < DateTime.Now) { throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_INVALID } } ; if (entity.Code != pRequest.Parameters.AuthCode) { throw new APIException("验证码不正确.") { ErrorCode = ERROR_AUTHCODE_NOT_EQUALS } } ; #endregion #region 获取会员权益 var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo); var memberBenefit = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID); var bllPrize = new LPrizesBLL(CurrentUserInfo); #endregion //自定义没有实体卡,有实体卡时变为1 int HaveVipcard = 0; //要发送给rabbitmq的信息 var eventService = new EventService(); EventContract vipMsg = null; switch (pRequest.Parameters.VipSource.Value) { case 3: //来源是微信时,做自动合并 { #region 根据手机号查找下,看下是否存在同样手机号的VIP记录 { List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); //潜在或者正式会员 wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipByPhone = result[0]; } if (vipByPhone != null && vipByPhone.VipSourceId == "3" && vipByPhone.Status.Value >= 2) { throw new APIException("会员已经注册") { ErrorCode = ERROR_MEMBER_REGISTERED }; } } #endregion #region 根据VIP ID查找下,看下是否存在该VIP的记录 if (!string.IsNullOrEmpty(pRequest.UserID)) { List <IWhereCondition> wheres = new List <IWhereCondition>(); //wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = true }); wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = pRequest.UserID }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipByID = result[0]; } } else { //如果前端未指定VIP ID则后台指定 pRequest.UserID = Guid.NewGuid().ToString("N"); } //判断用户是从点击领取过来的 还是从点击绑定实体卡过来的 int?RegisterType = 0; if (pRequest.Parameters.registerType != null) { RegisterType = pRequest.Parameters.registerType; } //当手机号不为空时需要查询是否存在实体卡 if (!string.IsNullOrEmpty(pRequest.Parameters.Mobile) && (!string.IsNullOrEmpty(pRequest.UserID) || !string.IsNullOrEmpty(vipByPhone.VIPID))) { List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); wheres.Add(new DirectCondition("VipID!='" + pRequest.UserID + "'")); var vipInfo = bll.Query(wheres.ToArray(), null); //若是从绑定实体卡进入,进行实体卡的判断,并不注册成功 if (RegisterType == 2) { if (vipInfo == null || vipInfo.Length == 0) { throw new APIException("未检测到实体卡") { ErrorCode = MEMBER_HAVENOCARD }; } else { vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); HaveVipcard = 1; //需要给绑定实体卡的提示 } } else { vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); //若是从"点击领取"进入则进行判断有没有实体卡 有没有实体卡都进行领卡成功的提示 if (vipInfo != null && vipInfo.Length > 0) { HaveVipcard = 1; //需要给绑定实体卡的提示 } else { HaveVipcard = 2; //注册成功但没有实体卡 } } } if (vipByID == null && vipByPhone == null) //根据vipid查不出记录,并且根据手机号也查不出记录 新增一条vip { //如果不存在则首先创建一条VIP记录,补充记录 vipByID = new VipEntity() { Phone = pRequest.Parameters.Mobile, VipName = pRequest.Parameters.Mobile, UserName = pRequest.Parameters.Mobile, VipRealName = pRequest.Parameters.VipRealName, VIPID = pRequest.UserID, Status = 2, ClientID = pRequest.CustomerID, VipCode = "Vip" + bll.GetNewVipCode(pRequest.CustomerID), VipSourceId = pRequest.Parameters.VipSource.ToString(), WeiXinUserId = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID, RegistrationTime = DateTime.Now }; bll.Create(vipByID); #region 注册会员触点活动奖励 //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg"); RedisContactBLL redisContactBll = new RedisContactBLL(); redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact() { CustomerId = CurrentUserInfo.ClientID, ContactType = "Reg", VipId = CurrentUserInfo.UserID }); #endregion } else if (vipByID != null) { VipEntity vipUpdateInfo = new VipEntity(); List <IWhereCondition> wheres = new List <IWhereCondition>(); //wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = true }); wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = pRequest.UserID }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipUpdateInfo = result[0]; } vipUpdateInfo.Phone = pRequest.Parameters.Mobile; if (!string.IsNullOrEmpty(pRequest.Parameters.VipRealName)) { vipUpdateInfo.VipRealName = pRequest.Parameters.VipRealName; } vipUpdateInfo.Status = 2; vipUpdateInfo.RegistrationTime = DateTime.Now; bll.Update(vipUpdateInfo); #region 注册会员触点活动奖励 //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg"); RedisContactBLL redisContactBll = new RedisContactBLL(); redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact() { CustomerId = CurrentUserInfo.ClientID, ContactType = "Reg", VipId = CurrentUserInfo.UserID }); #endregion #region 会员金矿、注册集客奖励 bll.SetOffActionReg(vipByID); #endregion } #endregion #region 根据VIP ID及手机号查询出的结果,尝试自动合并会员 (因目前会员注册不自动绑卡,实现用户自行选择绑卡业务故将绑卡业务注释掉) //if (vipByPhone == null) //{//如果未有相同手机号的用户,则无须绑定,直接使用VIP ID对应的VIP记录作为当前注册用户的记录 // rd.MemberInfo = new MemberInfo() // { // Mobile = vipByID.Phone // , // VipID = vipByID.VIPID // , // Name = vipByID.UserName // , // VipName = vipByID.VipName // , // VipNo = vipByID.VipCode // , // MemberBenefits = memberBenefit // , // IsActivate = vipByID.IsActivate.HasValue && vipByID.IsActivate.Value == 1 ? true : false // }; // //处理绑卡业务 add by Henry 2015/10/28 // vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); //} //else //{//否则调用存储过程,做自动会员合并 // //如果会员已经注册过,并且来源是微信的则表示该帐号已经被注册过不能再次绑定 // if (vipByPhone.VipSourceId == "3" && vipByPhone.Status.Value >= 2) // { // throw new APIException("会员已经注册") { ErrorCode = ERROR_MEMBER_REGISTERED }; // } // //否则做会员合并 // if (!bll.MergeVipInfo(pRequest.CustomerID, pRequest.UserID, pRequest.Parameters.Mobile)) // { // throw new APIException("自动绑定会员信息失败") { ErrorCode = ERROR_AUTO_MERGE_MEMBER_FAILED }; // } // //合并成功后重新读取信息 // List<IWhereCondition> wheres = new List<IWhereCondition>(); // wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); // wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = pRequest.UserID }); // wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); // var result = bll.Query(wheres.ToArray(), null); // vipByID = result[0]; // rd.MemberInfo = new MemberInfo() // { // Mobile = vipByID.Phone // , // VipID = vipByID.VIPID // , // Name = vipByID.UserName // , // VipName = vipByID.VipName // , // VipNo = vipByID.VipCode // , // MemberBenefits = memberBenefit // , // IsActivate = vipByID.IsActivate.HasValue && vipByID.IsActivate.Value == 1 ? true : false // }; // //处理绑卡业务 add by Henry 2015/10/28 // vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); //} #endregion } //注册会员信息发布到rabbitmq vipMsg = new EventContract { Operation = OptEnum.Create, EntityType = EntityTypeEnum.Vip, Id = pRequest.UserID }; eventService.PublishMsg(vipMsg); break; default: //其他来源则为自动注册 { #region 根据手机号查找下,看下是否存在同样手机号的VIP记录 { List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipByPhone = result[0]; } if (vipByPhone != null && vipByPhone.Status.Value >= 2) { throw new APIException("会员已经注册") { ErrorCode = ERROR_MEMBER_REGISTERED }; } } #endregion #region 没有找到相同电话的会员则自动注册 if (vipByPhone == null) { //没有找到相同电话的会员则自动注册 vipByPhone = new VipEntity() { Phone = pRequest.Parameters.Mobile, VipName = pRequest.Parameters.Mobile, UserName = pRequest.Parameters.Mobile, VipRealName = pRequest.Parameters.VipRealName, VIPID = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID, Status = 2, //状态为注册 VipCode = "Vip" + bll.GetNewVipCode(pRequest.CustomerID), ClientID = pRequest.CustomerID, VipSourceId = pRequest.Parameters.VipSource.ToString(), WeiXinUserId = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID, RegistrationTime = DateTime.Now }; bll.Create(vipByPhone); #region 注册会员触点活动奖励 //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg"); RedisContactBLL redisContactBll = new RedisContactBLL(); redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact() { CustomerId = CurrentUserInfo.ClientID, ContactType = "Reg", VipId = CurrentUserInfo.UserID }); #endregion } #endregion #region decimal EndAmount = 0; VipAmountBLL AmountBLL = new VipAmountBLL(this.CurrentUserInfo); VipAmountEntity amountEntity = AmountBLL.GetByID(vipByPhone.VIPID); if (amountEntity != null) { EndAmount = amountEntity.EndAmount.HasValue ? amountEntity.EndAmount ?? 0 : 0; } #endregion #region 返回用户信息 rd.MemberInfo = new MemberInfo() { Mobile = vipByPhone.Phone , VipID = vipByPhone.VIPID , Name = vipByPhone.UserName , VipName = vipByPhone.VipName , VipRealName = vipByPhone.VipRealName , VipNo = vipByPhone.VipCode , MemberBenefits = memberBenefit , IsActivate = false , Integration = vipByPhone.Integration ?? 0 , Balance = EndAmount }; #endregion } //注册会员信息发布到rabbitmq vipMsg = new EventContract { Operation = OptEnum.Create, EntityType = EntityTypeEnum.Vip, Id = rd.MemberInfo.VipID }; eventService.PublishMsg(vipMsg); break; } T_LEventsRegVipLogBLL lEventRegVipLogBll = new T_LEventsRegVipLogBLL(CurrentUserInfo); if (!string.IsNullOrEmpty(pRequest.Parameters.CTWEventId)) { lEventRegVipLogBll.CTWRegOrFocusLog(pRequest.Parameters.CTWEventId, pRequest.UserID, "", CurrentUserInfo, "Reg"); } //如果是通过优惠券进来的就有couponId 新注册的需要加记录 if (!string.IsNullOrEmpty(pRequest.Parameters.couponId)) { lEventRegVipLogBll.CouponRegOrFocusLog(pRequest.Parameters.couponId, pRequest.UserID, "", CurrentUserInfo, "Reg"); } //当手机号不为空时需要查询是否存在实体卡 //if (!string.IsNullOrEmpty(pRequest.Parameters.Mobile) && (!string.IsNullOrEmpty(pRequest.UserID) || !string.IsNullOrEmpty(vipByPhone.VIPID))) //{ // List<IWhereCondition> wheres = new List<IWhereCondition>(); // wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); // wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); // wheres.Add(new DirectCondition("VipID!='" + pRequest.UserID + "'")); // var vipInfo = bll.Query(wheres.ToArray(), null); // if (vipInfo != null && vipInfo.Length > 0) // { // throw new APIException("检测到会员相关实体卡") { ErrorCode = MEMBER_HAVECARD }; // } // else // { // //如果会员当前没有实体卡,则默认绑定等级为1的卡 // vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); // throw new APIException("未检测到实体卡") { ErrorCode = MEMBER_HAVENOCARD }; // } //} //判定是否有可绑卡的定义 1=有可绑卡 if (HaveVipcard == 1 || HaveVipcard == 2) { //有积分的话给相应领取成功的积分提示 var contactEventBLL = new ContactEventBLL(CurrentUserInfo); int sendIntegral = 0; if (!string.IsNullOrEmpty(pRequest.Parameters.CTWEventId)) { sendIntegral = contactEventBLL.GetContactEventIntegral(CurrentUserInfo.ClientID, "Reg", "Point", 1); } else { sendIntegral = contactEventBLL.GetContactEventIntegral(CurrentUserInfo.ClientID, "Reg", "Point", 0); } if (sendIntegral > 0) { if (pRequest.Parameters.registerType != 2 && HaveVipcard == 2) { throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分") { ErrorCode = MEMBER_GETSUCCESS }; //领取成功不跳转跳转到实体卡 } else if (pRequest.Parameters.registerType == 2 && HaveVipcard == 1) { throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分") { ErrorCode = MEMBER_HAVECARD_Integral }; //检测到有相关实体卡前端不提示领取成功 并跳到实体卡列表 } else { throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分") { ErrorCode = MEMBER_HAVECARD }; //领取成功,提示领取成功,并跳到相关实体卡 } } else { if (pRequest.Parameters.registerType != 2 && HaveVipcard == 2) { throw new APIException("领取成功") { ErrorCode = MEMBER_GETSUCCESS }; //领取成功不跳转跳转到实体卡 } else if (pRequest.Parameters.registerType == 2 && HaveVipcard == 1) { throw new APIException("检测到有相关实体卡") { ErrorCode = MEMBER_HAVECARD }; //检测到有相关实体卡前端不提示领取成功 并跳到实体卡列表 } else if (pRequest.Parameters.registerType != 2 && HaveVipcard == 1) { throw new APIException("领取成功") { ErrorCode = MEMBER_HAVECARD }; //领取成功有实体卡,并跳转 } else { throw new APIException("检测到有相关实体卡") { ErrorCode = MEMBER_HAVECARD }; //领取成功,提示领取成功,并跳到相关实体卡 } } } #region 将验证码设置为已验证 //entity.IsValidated = 1; //codebll.Update(entity); #endregion return(rd); //AuthCodeLoginRD rd = new AuthCodeLoginRD(); //rd.MemberInfo = new MemberInfo(); //var codebll = new RegisterValidationCodeBLL(base.CurrentUserInfo); //var entity = codebll.GetByMobile(pRequest.Parameters.Mobile); //if (entity == null) // throw new APIException("未找到此手机的验证信息") { ErrorCode = ERROR_AUTHCODE_NOTEXISTS }; //if (entity.IsValidated.Value == 1) // throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_FAILURE }; //if (entity.Expires.Value < DateTime.Now) // throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_FAILURE }; //var vipbll = new VipBLL(base.CurrentUserInfo); //var vipinfo = vipbll.GetByMobile(pRequest.Parameters.Mobile, pRequest.CustomerID); //#region VIP来源更新 //switch (pRequest.Parameters.VipSource.Value) //{ // case 4: // case 9: // vipinfo.VipSourceId = pRequest.Parameters.VipSource.ToString(); // vipbll.Update(vipinfo); // break; //} //#endregion //if (string.IsNullOrEmpty(vipinfo.ClientID)) //{ // vipinfo.ClientID = pRequest.CustomerID; // vipbll.Update(vipinfo); //} //rd.MemberInfo.Mobile = vipinfo.Phone; //rd.MemberInfo.Name = vipinfo.UserName; //rd.MemberInfo.VipID = vipinfo.VIPID; //rd.MemberInfo.VipName = vipinfo.VipName; //var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo); //rd.MemberInfo.MemberBenefits = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID); //entity.IsValidated = 1; //codebll.Update(entity); //return rd; } } }
protected override SetVipCardRD ProcessRequest(DTO.Base.APIRequest <OpenVipCardRP> pRequest) { var rd = new SetVipCardRD(); var para = pRequest.Parameters; var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo; //登录状态信息 var vipBLL = new VipBLL(loggingSessionInfo); //会员业务对象实例化 var vipTagsMappingBLL = new VipTagsMappingBLL(loggingSessionInfo); //会员和标签关系业务对象实例化 var vipCardBLL = new VipCardBLL(loggingSessionInfo); //会员卡业务对象实例化 var vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo); //会员和会员卡关系业务对象实例化 var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(loggingSessionInfo); //会员卡状态变更业务对象实例化 var vipAddressBLL = new VipAddressBLL(loggingSessionInfo); //会员地址信息业务对象实例化 var pTran = vipCardBLL.GetTran(); //事务 using (pTran.Connection) { try { //创建会员信息 var vipEntity = new VipEntity() { VIPID = Guid.NewGuid().ToString().Replace("-", ""), VipName = para.VipName, VipRealName = para.VipName, //VipCode = "Vip" + vipBLL.GetNewVipCode(loggingSessionInfo.ClientID), //获取会员编号 VipCode = para.VipCardCode, //会员卡号 CouponInfo = loggingSessionInfo.CurrentUserRole.UnitId, //原会集店字段 MembershipStore = loggingSessionInfo.CurrentUserRole.UnitId, //新增的会集店字段 Phone = para.Phone, Birthday = para.Birthday, Gender = para.Gender, Email = para.Email, Col18 = para.IDCard, //身份证 Status = 2, //已注册状态 VipSourceId = "20", //来源开卡 ClientID = loggingSessionInfo.ClientID }; vipBLL.Create(vipEntity, pTran); //保存年龄段标签 var vipTagsMappingEntity = new VipTagsMappingEntity() { MappingId = Guid.NewGuid().ToString().Replace("-", ""), VipId = vipEntity.VIPID, TagsId = para.TagsID }; vipTagsMappingBLL.Create(vipTagsMappingEntity, pTran); //保存会员地址信息 //var vipAddressEntity = new VipAddressEntity() //{ // VIPID = vipEntity.VIPID, // LinkMan = para.VipName, // LinkTel = para.Phone, // CityID = para.CityID, // Address = para.Address, // IsDefault = 1 //}; //vipAddressBLL.Create(vipAddressEntity, pTran); //更新会员卡信息 var vipCardEntity = vipCardBLL.GetByID(para.VipCardID); if (vipCardEntity != null) { #region 返回卡ID rd.VipCardID = vipCardEntity.VipCardID; #endregion //vipCardEntity.VipCardStatusId = 1; if (!string.IsNullOrEmpty(vipCardEntity.MembershipUnit)) { throw new APIException("此会员卡已绑定会员") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; if (vipCardEntity.VipCardStatusId > 0) { throw new APIException("此会员卡状态异常") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; vipCardEntity.MembershipTime = DateTime.Now; vipCardEntity.MembershipUnit = loggingSessionInfo.CurrentUserRole.UnitId; vipCardEntity.IsGift = para.IsGift; //vipCardEntity.SalesUserId = para.SalesUserId; vipCardEntity.SalesUserName = para.SalesUserName; //用户输入名称,后期需要根据姓名查找用户ID,更新到SalesUserId vipCardEntity.CreateBy = loggingSessionInfo.UserID; //开卡人,即入会员工 vipCardBLL.Update(vipCardEntity, pTran); } else { throw new APIException("查不到此会员卡") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } }; //新增会员卡操作状态信息 var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity() { LogID = Guid.NewGuid().ToString().Replace("-", ""), VipCardStatusID = vipCardEntity.VipCardStatusId, VipCardID = para.VipCardID, Action = "开卡", //Reason = "", UnitID = loggingSessionInfo.CurrentUserRole.UnitId, CustomerID = loggingSessionInfo.ClientID }; vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity, pTran); //绑定会员卡和会员 var vipCardVipMappingEntity = new VipCardVipMappingEntity() { MappingID = Guid.NewGuid().ToString().Replace("-", ""), VIPID = vipEntity.VIPID, VipCardID = para.VipCardID, CustomerID = loggingSessionInfo.ClientID }; vipCardVipMappingBLL.Create(vipCardVipMappingEntity, pTran); pTran.Commit(); //提交事物 } catch (APIException apiEx) { pTran.Rollback();//回滚事物 throw new APIException(apiEx.ErrorCode, apiEx.Message); } catch (Exception ex) { pTran.Rollback();//回滚事物 throw new Exception(ex.Message); } } return(rd); }
public string UpdateVip() { string content = string.Empty; var respData = new UpdateVipRespData(); respData.content = new UpdateVipRespContentData(); try { string reqContent = Request["ReqContent"]; Loggers.Debug(new DebugLogInfo() { Message = string.Format("UpdateVip: {0}", reqContent) }); #region //解析请求字符串 chech var reqObj = reqContent.DeserializeJSONTo <UpdateVipReqData>(); reqObj = reqObj == null ? new UpdateVipReqData() : reqObj; if (reqObj.special == null) { respData.code = "102"; respData.description = "没有特殊参数"; return(respData.ToJSON().ToString()); } if (reqObj.special.vipRealName == null || reqObj.special.vipRealName.Equals("")) { respData.code = "2201"; respData.description = "姓名不能为空"; return(respData.ToJSON().ToString()); } if (reqObj.special.phone == null || reqObj.special.phone.Equals("")) { respData.code = "2202"; respData.description = "电话不能为空"; return(respData.ToJSON().ToString()); } if (reqObj.special.school == null || reqObj.special.school.Equals("")) { respData.code = "2203"; respData.description = "学校不能为空"; return(respData.ToJSON().ToString()); } if (reqObj.special.className == null || reqObj.special.className.Equals("")) { respData.code = "2204"; respData.description = "班级不能为空"; return(respData.ToJSON().ToString()); } if (reqObj.special.company == null || reqObj.special.company.Equals("")) { respData.code = "2205"; respData.description = "公司不能为空"; return(respData.ToJSON().ToString()); } if (reqObj.special.position == null || reqObj.special.position.Equals("")) { respData.code = "2206"; respData.description = "职位不能为空"; return(respData.ToJSON().ToString()); } #endregion #region //判断客户ID是否传递 if (!string.IsNullOrEmpty(reqObj.common.customerId)) { customerId = reqObj.common.customerId; } var loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1"); #endregion #region 设置参数 vipBLL = new VipBLL(loggingSessionInfo); VipEntity vipInfo = vipBLL.Query( new IWhereCondition[] { new EqualsCondition() { FieldName = "Phone", Value = reqObj.special.phone } , new EqualsCondition() { FieldName = "ClientId", Value = customerId } } , null).FirstOrDefault(); bool newFlag = false; if (vipInfo == null) { newFlag = true; vipInfo = new VipEntity(); vipInfo.VIPID = Utils.NewGuid(); vipInfo.Phone = reqObj.special.phone; vipInfo.VipLevel = 1; vipInfo.Status = 1; vipInfo.ClientID = customerId; vipInfo.RegistrationTime = DateTime.Now; vipInfo.IsDelete = 0; vipInfo.CreateTime = DateTime.Now; vipInfo.CreateBy = vipInfo.VIPID; } else { vipInfo.LastUpdateTime = DateTime.Now; vipInfo.LastUpdateBy = reqObj.common.userId; } vipInfo.VipRealName = reqObj.special.vipRealName; vipInfo.Col41 = reqObj.special.school; vipInfo.Col42 = reqObj.special.className; vipInfo.Col43 = reqObj.special.company; vipInfo.Col44 = reqObj.special.position; vipInfo.Email = reqObj.special.email; vipInfo.Col46 = reqObj.special.hobby; vipInfo.Col47 = reqObj.special.myValue; vipInfo.Col48 = reqObj.special.needValue; vipInfo.SinaMBlog = reqObj.special.sinaMBlog; vipInfo.TencentMBlog = reqObj.special.weixin; // CreateQrcode var qrImageUrl = ""; var qrFlag = cUserService.CreateQrcode(vipInfo.VipRealName, vipInfo.Email, "", vipInfo.Phone, "", vipInfo.Col43, vipInfo.Col44, "", "", ref qrImageUrl); if (qrFlag) { vipInfo.QRVipCode = qrImageUrl; } else { respData.code = "2207"; respData.description = "用户二维码数据保存失败"; return(respData.ToJSON().ToString()); } #endregion string strError = string.Empty; if (newFlag) { vipBLL.Create(vipInfo); } else { vipBLL.Update(vipInfo, false); } respData.content.VipId = vipInfo.VIPID; } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo() { ErrorMessage = ex.Message }); respData.code = "103"; respData.description = "数据库操作错误"; respData.exception = ex.ToString(); } content = respData.ToJSON(); return(content); }
/// <summary> /// 验证真伪得积分 /// </summary> public string SetCheckReal() { string content = string.Empty; var respData = new SetCheckRealRespData(); try { string openId = Request["openID"]; //openId = "o8Y7Ejl1zl5RHXDvPONCNqoC5Md8"; Loggers.Debug(new DebugLogInfo() { Message = string.Format( "OpenID:{0}", openId) }); var currentUser = Default.GetLoggingSession(); VipBLL vipBLL = new VipBLL(currentUser); IntegralRuleBLL integralRuleBLL = new IntegralRuleBLL(currentUser); VipIntegralDetailBLL vipIntegralDetailBLL = new VipIntegralDetailBLL(currentUser); VipIntegralBLL vipIntegralBLL = new VipIntegralBLL(currentUser); string vipId = null; if (true) { VipEntity vipIdData = null; var vipIdDataList = vipBLL.QueryByEntity(new VipEntity() { WeiXinUserId = openId }, null); if (vipIdDataList == null || vipIdDataList.Length == 0 || vipIdDataList[0] == null || vipIdDataList[0].VIPID == null) { respData.Code = "103"; respData.Description = "数据库操作错误"; respData.Exception = "未查询到Vip会员"; return(respData.ToJSON()); } else { vipIdData = vipIdDataList[0]; vipId = vipIdData.VIPID; } } // SysIntegralSource: 10 string integralSourceId = "10"; int integralValue = 0; if (true) { IntegralRuleEntity integralRuleData = null; var integralRuleDataList = integralRuleBLL.QueryByEntity(new IntegralRuleEntity() { IntegralSourceID = integralSourceId }, null); if (integralRuleDataList == null || integralRuleDataList.Length == 0 || integralRuleDataList[0] == null) { respData.Code = "103"; respData.Description = "数据库操作错误"; respData.Exception = "未查询到积分规则"; return(respData.ToJSON()); } else { integralRuleData = integralRuleDataList[0]; integralValue = int.Parse(integralRuleData.Integral); } } #region 保存积分 if (true) { string tmpVipId = vipId; int tmpIntegralValue = integralValue; string tmpIntegralSourceId = integralSourceId; string tmpOpenId = openId; string msgModel = "【验真品,送积分】活动,您本次验证赢得{0}点积分。您当前的总积分是{1}点。"; // 插入积分明细 VipIntegralDetailEntity vipIntegralDetailEntity = new VipIntegralDetailEntity(); vipIntegralDetailEntity.VipIntegralDetailID = CPOS.Common.Utils.NewGuid(); vipIntegralDetailEntity.VIPID = tmpVipId; vipIntegralDetailEntity.FromVipID = tmpVipId; vipIntegralDetailEntity.SalesAmount = 0; vipIntegralDetailEntity.Integral = tmpIntegralValue; vipIntegralDetailEntity.IntegralSourceID = tmpIntegralSourceId; vipIntegralDetailEntity.IsAdd = 1; //vipIntegralDetailBLL.Create(vipIntegralDetailEntity); // 更新积分 VipIntegralEntity vipIntegralEntity = new VipIntegralEntity(); var vipIntegralDataList = vipIntegralBLL.QueryByEntity( new VipIntegralEntity() { VipID = vipId }, null); if (vipIntegralDataList == null || vipIntegralDataList.Length == 0 || vipIntegralDataList[0] == null) { vipIntegralEntity.VipID = tmpVipId; vipIntegralEntity.BeginIntegral = 0; // 期初积分 vipIntegralEntity.InIntegral = tmpIntegralValue; // 增加积分 vipIntegralEntity.OutIntegral = 0; //消费积分 vipIntegralEntity.EndIntegral = tmpIntegralValue; //积分余额 vipIntegralEntity.InvalidIntegral = 0; // 累计失效积分 vipIntegralEntity.ValidIntegral = tmpIntegralValue; // 当前有效积分 //vipIntegralBLL.Create(vipIntegralEntity); } else { vipIntegralEntity.VipID = tmpVipId; vipIntegralEntity.InIntegral = vipIntegralDataList[0].InIntegral + tmpIntegralValue;; // 增加积分 //vipIntegralEntity.OutIntegral = 0; //消费积分 vipIntegralEntity.EndIntegral = vipIntegralDataList[0].EndIntegral + tmpIntegralValue; //积分余额 //vipIntegralEntity.InvalidIntegral = 0; // 累计失效积分 vipIntegralEntity.ValidIntegral = vipIntegralDataList[0].ValidIntegral + tmpIntegralValue; // 当前有效积分 //vipIntegralBLL.Update(vipIntegralEntity, false); } // 更新VIP VipEntity vipEntity = new VipEntity(); var vipEntityDataList = vipBLL.QueryByEntity( new VipEntity() { VIPID = tmpVipId }, null); if (vipEntityDataList == null || vipEntityDataList.Length == 0 || vipEntityDataList[0] == null) { vipEntity.VIPID = tmpVipId; vipEntity.Integration = vipIntegralEntity.ValidIntegral; //vipEntity.HigherVipID = highOpenId; vipEntity.ClientID = currentUser.CurrentUser.customer_id; vipEntity.Status = 1; vipBLL.Create(vipEntity); } else { vipEntity.VIPID = tmpVipId; vipEntity.Integration = vipIntegralEntity.ValidIntegral; //vipEntity.HigherVipID = highOpenId; vipEntity.ClientID = currentUser.CurrentUser.customer_id; vipBLL.Update(vipEntity, false); } // 推送消息 string msgUrl = ConfigurationManager.AppSettings["push_weixin_msg_url"].Trim(); string msgText = string.Format(msgModel, tmpIntegralValue, vipEntity.Integration); string msgData = "<xml><OpenID><![CDATA[" + tmpOpenId + "]]></OpenID><Content><![CDATA[" + msgText + "]]></Content></xml>"; var msgResult = Common.Utils.GetRemoteData(msgUrl, "POST", msgData); Loggers.Debug(new DebugLogInfo() { Message = string.Format("PushMsgResult:{0}", msgResult) }); respData.Data = tmpIntegralValue.ToString(); } #endregion } catch (Exception ex) { respData.Code = "103"; respData.Description = "数据库操作错误"; respData.Exception = ex.ToString(); } content = respData.ToJSON(); return(content); }
public string SetVipInfoByToken(string token, string openId, LoggingSessionInfo loggionSesionInfo, HttpResponse Response) { string vipId = string.Empty; var url = "https://api.weixin.qq.com/sns/userinfo?"; var postData = "access_token=" + token + "&openid=" + openId + "&lang=zh_CN"; // Response.Write(url + postData); string method = "GET"; // var data = HttpWebClient.DoHttpRequest(url, postData); var data = CommonBLL.GetRemoteData(url + postData, method, string.Empty); var openInfo = data.DeserializeJSONTo <WxOpenInfoResponse>(); if (openInfo == null) { Loggers.Debug(new DebugLogInfo() { Message = "获取微信用户信息失败:" + data.ToJSON() }); return(vipId); } else { try { //insert into vip CPOS.Common.DownloadImage downloadServer = new DownloadImage(); string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"]; var headimgurl = downloadServer.DownloadFile(openInfo.headimgurl, downloadImageUrl); vipId = BaseService.NewGuidPub(); VipBLL vipServiceUnion = new VipBLL(loggionSesionInfo); var vipInfo = new VipEntity(); vipInfo.VIPID = vipId; vipInfo.WeiXinUserId = openId; //openId微信提供 vipInfo.City = openInfo.city; //城市,微信提供 vipInfo.Gender = Convert.ToInt32(openInfo.sex); //性别,微信提供 vipInfo.VipName = openInfo.nickname; //微信昵称,微信提供 vipInfo.VipCode = vipServiceUnion.GetVipCode(); vipInfo.UnionID = openInfo.unionid; vipInfo.VipSourceId = "3"; //写死 vipInfo.HeadImgUrl = headimgurl; //注意,需要先传到我们本地服务器,可以参考(需要download下来) vipInfo.ClientID = loggionSesionInfo.ClientID; //客户标识 vipInfo.RegistrationTime = DateTime.Now; vipInfo.Status = 0; //客户没有关注 vipInfo.VipPasswrod = "e10adc3949ba59abbe56e057f20f883e"; //初始密码123456 UnitService unitServer = new UnitService(loggionSesionInfo); vipInfo.CouponInfo = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识 var wappBll = new WApplicationInterfaceBLL(loggionSesionInfo); string weixinId = ""; var wappEntity = wappBll.QueryByEntity(new WApplicationInterfaceEntity() { CustomerId = loggionSesionInfo.ClientID }, null); if (wappEntity.Length > 0) { weixinId = wappEntity[0].WeiXinID; } vipInfo.WeiXin = weixinId; //微信号码,通过数据库可以查出 vipServiceUnion.Create(vipInfo); } catch (Exception ex) { Loggers.Debug(new DebugLogInfo() { Message = "新增微信用户信息失败:" + ex.ToString() }); } return(vipId); } }