public string SendCode(string mobile) { string result = "200"; VipBLL vipBLL = new VipBLL(CurrentUserInfo); var vip = vipBLL.Query(new IWhereCondition[] { new EqualsCondition() { FieldName = "Phone", Value = mobile } , new EqualsCondition() { FieldName = "ClientID", Value = CurrentUserInfo.ClientID } }, null).FirstOrDefault(); if (vip != null) { Random rd = new Random(); string code = rd.Next(100000, 999999).ToString(); string sign = ""; sign = vipBLL.GetSettingValue(CurrentUserInfo.ClientID); string msg = ""; if (!Utils.SendSMSCode(CurrentUserInfo.ClientID, mobile, code, sign, out msg))//发送短信 { throw new Exception("短信发送失败:" + msg); } else { string message = (ConfigurationManager.AppSettings["ValidationMessage"] ?? "{0}").ToString(); message = string.Format(message, code); _currentDAO.InsertSMS(mobile, message, sign); } this.Create(new RegisterValidationCodeEntity() { CodeID = JIT.CPOS.Common.Utils.NewGuid(), Mobile = mobile, Code = code, IsValidated = 0 }); } else { result = "102"; } return(result); }
/// <summary> /// 华硕校园发送验证码 /// </summary> /// <param name="mobile"></param> /// <param name="code"></param> /// <param name="loggingSessionInfo"></param> /// <returns></returns> public string HS_SendCode(string mobile, string code, LoggingSessionInfo loggingSessionInfo) { string result = "200"; VipBLL vipBLL = new VipBLL(loggingSessionInfo); var vip = vipBLL.Query(new IWhereCondition[] { new EqualsCondition() { FieldName = "Phone", Value = mobile }, new EqualsCondition() { FieldName = "ClientID", Value = this.CurrentUserInfo.ClientID } }, null).FirstOrDefault(); if (vip == null) { this.Create(new RegisterValidationCodeEntity() { CodeID = JIT.CPOS.Common.Utils.NewGuid(), Mobile = mobile, Code = code, IsValidated = 0 }); } return(result); }
/// <summary> /// 会员微信注册绑卡 /// </summary> /// <param name="vipId"></param> /// <param name="vipCode"></param> /// <param name="unitId">会籍店</param> public void BindVipCard(string vipId, string vipCode, string unitId) { var vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo); var sysVipCardTypeBLL = new SysVipCardTypeBLL(CurrentUserInfo); var vipCardBLL = new VipCardBLL(CurrentUserInfo); var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(CurrentUserInfo); UnitService unitServer = new UnitService(CurrentUserInfo); if (string.IsNullOrEmpty(unitId)) { unitId = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识 } //根据vipid查询VipCardVipMapping,判断是否有绑卡,没绑卡默认给等级1的卡 var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity() { VIPID = vipId }, null).FirstOrDefault(); if (vipCardMappingInfo == null) { //判断商户是否有付费的会员卡,有付费会员卡时,不自动绑卡 List <IWhereCondition> freeCardCon = new List <IWhereCondition> { }; freeCardCon.Add(new EqualsCondition() { FieldName = "CustomerID", Value = CurrentUserInfo.ClientID }); freeCardCon.Add(new DirectCondition("VipCardLevel=1")); var orderBys = new OrderBy[1]; orderBys[0] = new OrderBy() { FieldName = "VipCardLevel", Direction = OrderByDirections.Asc }; var freeCardTypeInfo = sysVipCardTypeBLL.Query(freeCardCon.ToArray(), orderBys).FirstOrDefault(); if (freeCardTypeInfo != null) { //查询最低等级的会员卡类型 var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity() { CustomerID = CurrentUserInfo.ClientID, Category = 0, VipCardLevel = 1 }, new OrderBy[] { new OrderBy() { FieldName = "vipcardlevel", Direction = OrderByDirections.Asc } }).FirstOrDefault(); if (vipCardTypeInfo != null) { //查询此类型会员卡是否存在 var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity() { VipCardTypeID = vipCardTypeInfo.VipCardTypeID, VipCardStatusId = 0, MembershipUnit = "" }, null).FirstOrDefault(); //不存在,制卡 if (vipCardInfo == null) { vipCardInfo = new VipCardEntity(); vipCardInfo.VipCardID = Guid.NewGuid().ToString(); vipCardInfo.VipCardTypeID = vipCardTypeInfo.VipCardTypeID; vipCardInfo.VipCardTypeName = vipCardTypeInfo.VipCardTypeName; vipCardInfo.VipCardCode = vipCode; vipCardInfo.VipCardStatusId = 1;//正常 vipCardInfo.MembershipUnit = unitId; vipCardInfo.MembershipTime = DateTime.Now; vipCardInfo.CustomerID = CurrentUserInfo.ClientID; vipCardBLL.Create(vipCardInfo); } else//存在更新成现在的 { vipCardInfo.VipCardStatusId = 1;//正常 vipCardInfo.MembershipUnit = unitId; vipCardInfo.MembershipTime = DateTime.Now; vipCardInfo.VipCardTypeID = vipCardTypeInfo.VipCardTypeID; vipCardBLL.Update(vipCardInfo); //存在导入的卡时,更新当前会员的VipCode var vipbll = new VipBLL(CurrentUserInfo); List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0 }); wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = vipId }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = CurrentUserInfo.ClientID }); var VipInfo = vipbll.Query(wheres.ToArray(), null).FirstOrDefault(); if (VipInfo != null && !string.IsNullOrEmpty(VipInfo.VIPID)) { VipInfo.VipCode = vipCardInfo.VipCardCode; //更新VipCode信息 vipbll.Update(VipInfo); } } //新增会员卡操作状态信息 var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity() { LogID = Guid.NewGuid().ToString().Replace("-", ""), VipCardStatusID = vipCardInfo.VipCardStatusId, VipCardID = vipCardInfo.VipCardID, Action = "注册", UnitID = unitId, CustomerID = CurrentUserInfo.ClientID }; vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity); //绑定会员卡和会员 var vipCardVipMappingEntity = new VipCardVipMappingEntity() { MappingID = Guid.NewGuid().ToString().Replace("-", ""), VIPID = vipId, VipCardID = vipCardInfo.VipCardID, CustomerID = CurrentUserInfo.ClientID }; vipCardVipMappingBLL.Create(vipCardVipMappingEntity); //开卡礼 var vipCardUpgradeRewardBll = new VipCardUpgradeRewardBLL(CurrentUserInfo); var vipCardUpgradeRewardEntityList = vipCardUpgradeRewardBll.QueryByEntity(new VipCardUpgradeRewardEntity() { VipCardTypeID = vipCardTypeInfo.VipCardTypeID }, null); var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL(); if (vipCardUpgradeRewardEntityList.Length > 0) { foreach (var vipCardUpgradeRewardEntity in vipCardUpgradeRewardEntityList) { for (int i = 0; i < vipCardUpgradeRewardEntity.CouponNum; i++) { redisVipMappingCouponBLL.SetVipMappingCoupon(new CC_Coupon() { CustomerId = CurrentUserInfo.ClientID, CouponTypeId = vipCardUpgradeRewardEntity.CouponTypeId.ToString() }, vipCardUpgradeRewardEntity.CardUpgradeRewardId.ToString(), vipId, "OpenVipCard"); } } } } else { throw new APIException("系统未创建会员卡类型") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } }; } } else //更新旧卡 需要确认旧卡是否为卡体系内的卡 { var oldVipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity() { VipCardID = vipCardMappingInfo.VipCardID, CustomerID = CurrentUserInfo.ClientID }, null).FirstOrDefault(); int oldVipCardTypeID = oldVipCardInfo.VipCardTypeID ?? 0; //查询最低等级的会员卡类型 var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity() { CustomerID = CurrentUserInfo.ClientID, Category = 0, VipCardLevel = 1 }, new OrderBy[] { new OrderBy() { FieldName = "vipcardlevel", Direction = OrderByDirections.Asc } }).FirstOrDefault(); if (vipCardTypeInfo == null) { throw new APIException("系统未创建会员卡类型体系") { ErrorCode = ERROR_CODES.INVALID_BUSINESS }; } if (oldVipCardInfo != null) { //旧卡不为空时,确认当前VipCardTypeID是否属于卡体系 var curvipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity() { CustomerID = CurrentUserInfo.ClientID, Category = 0, VipCardTypeID = oldVipCardInfo.VipCardTypeID }, new OrderBy[] { new OrderBy() { FieldName = "VipCardTypeID", Direction = OrderByDirections.Asc } }).FirstOrDefault(); if (curvipCardTypeInfo == null) //若为空 则更新为当前信息 { oldVipCardInfo.VipCardStatusId = 1; //正常 oldVipCardInfo.MembershipUnit = unitId; oldVipCardInfo.MembershipTime = DateTime.Now; oldVipCardInfo.VipCardTypeID = vipCardTypeInfo.VipCardTypeID; vipCardBLL.Update(oldVipCardInfo); //存在导入的卡时,更新当前会员的VipCode var vipbll = new VipBLL(CurrentUserInfo); List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0 }); wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = vipId }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = CurrentUserInfo.ClientID }); var VipInfo = vipbll.Query(wheres.ToArray(), null).FirstOrDefault(); if (VipInfo != null && !string.IsNullOrEmpty(VipInfo.VIPID)) { VipInfo.VipCode = oldVipCardInfo.VipCardCode; //更新VipCode信息 vipbll.Update(VipInfo); } //开卡礼 var vipCardUpgradeRewardBll = new VipCardUpgradeRewardBLL(CurrentUserInfo); var vipCardUpgradeRewardEntityList = vipCardUpgradeRewardBll.QueryByEntity(new VipCardUpgradeRewardEntity() { VipCardTypeID = vipCardTypeInfo.VipCardTypeID }, null); var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL(); if (vipCardUpgradeRewardEntityList.Length > 0) { foreach (var vipCardUpgradeRewardEntity in vipCardUpgradeRewardEntityList) { for (int i = 0; i < vipCardUpgradeRewardEntity.CouponNum; i++) { redisVipMappingCouponBLL.SetVipMappingCoupon(new CC_Coupon() { CustomerId = CurrentUserInfo.ClientID, CouponTypeId = vipCardUpgradeRewardEntity.CouponTypeId.ToString() }, vipCardUpgradeRewardEntity.CardUpgradeRewardId.ToString(), vipId, "OpenVipCard"); } } } } } //老卡操作状态信息 var oldVipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity() { LogID = Guid.NewGuid().ToString().Replace("-", ""), VipCardStatusID = oldVipCardInfo.VipCardStatusId, VipCardID = oldVipCardInfo.VipCardID, Action = "注册", UnitID = unitId, CustomerID = CurrentUserInfo.ClientID }; vipCardStatusChangeLogBLL.Create(oldVipCardStatusChangeLogEntity); } //记录会员信息改变,并且把旧的会员的标识也放在契约里 var eventService = new EventService(); var vipMsg = new EventContract { Operation = OptEnum.Update, EntityType = EntityTypeEnum.Vip, Id = vipId, }; eventService.PublishMsg(vipMsg); }
public SuccessResponse <IAPIResponseData> VipConsume(APIRequest <VipConsumeRP> rp) { var cardDepositBLL = new CardDepositBLL(CurrentUserInfo); var registerValidationCodeBLL = new RegisterValidationCodeBLL(CurrentUserInfo); var vipBLL = new VipBLL(CurrentUserInfo); var rd = new EmptyRD(); var rsp = new SuccessResponse <IAPIResponseData>(rd); string phone = ""; var vip = vipBLL.Query(new IWhereCondition[] { new EqualsCondition() { FieldName = "VipID", Value = rp.Parameters.VipID } }, null); if (vip.Length > 0) { phone = vip[0].Phone; if (string.IsNullOrEmpty(phone)) { rsp.ResultCode = 202; rsp.Message = "会员未注册手机号!"; } else if (string.IsNullOrEmpty(rp.Parameters.SMSCode)) { //发送验证码 registerValidationCodeBLL.SendCode(phone); } else { //验证验证码 var codeEntity = registerValidationCodeBLL.Query(new IWhereCondition[] { new EqualsCondition() { FieldName = "Mobile", Value = phone } , new EqualsCondition() { FieldName = "Code", Value = rp.Parameters.SMSCode } , new EqualsCondition() { FieldName = "IsValidated", Value = 0 } , new EqualsCondition() { FieldName = "IsDelete", Value = 0 } }, new OrderBy[] { new OrderBy() { FieldName = "CreateTime", Direction = OrderByDirections.Desc } }); if (codeEntity != null && codeEntity.Length > 0) { System.Data.SqlClient.SqlTransaction tran = GetTran(); using (tran.Connection) { registerValidationCodeBLL.DeleteByMobile(phone, 1, tran); string errorMessage = ""; VipAmountBLL vipAmountBLL = new VipAmountBLL(CurrentUserInfo); vipAmountBLL.SetVipAmountChange(CurrentUserInfo.ClientID, 5, rp.Parameters.VipID, rp.Parameters.Amount, CurrentUserInfo.CurrentUserRole.UnitId, "Prepaid card consumption" + "~" + (rp.Parameters.DocumentCode ?? ""), "Out", out errorMessage, tran); tran.Commit(); } } else { rsp.ResultCode = 203; rsp.Message = "请先获取验证码!"; } } } else { rsp.ResultCode = 201; rsp.Message = "会员不存在!"; } return(rsp); }