Ejemplo n.º 1
0
        protected override GetMemberBenefitsRD ProcessRequest(APIRequest <EmptyRequestParameter> pRequest)
        {
            GetMemberBenefitsRD rd      = new GetMemberBenefitsRD();
            var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo);

            rd.MemberBenefits = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID);
            return(rd);
        }
Ejemplo n.º 2
0
        protected override GetMemberInfoRD ProcessRequest(DTO.Base.APIRequest <GetMemberInfoRP> pRequest)
        {
            GetMemberInfoRD rd = new GetMemberInfoRD();

            rd.MemberInfo = new MemberInfo();
            var vipLoginBLL = new VipBLL(base.CurrentUserInfo);

            //如果有一个查询标识非空,就用查询标识查,发现没有会员就报错
            if (!string.IsNullOrEmpty(pRequest.Parameters.SearchFlag))
            {
                List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                };
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "ClientID", Value = CurrentUserInfo.ClientID
                });
                var cond1 = new LikeCondition()
                {
                    FieldName = "VipName", Value = "%" + pRequest.Parameters.SearchFlag + "%"
                };
                var cond2 = new LikeCondition()
                {
                    FieldName = "VipRealName", Value = "%" + pRequest.Parameters.SearchFlag + "%"
                };
                var com1 = new ComplexCondition()
                {
                    Left = cond1, Right = cond2, Operator = LogicalOperators.Or
                };

                var cond3 = new EqualsCondition()
                {
                    FieldName = "Phone", Value = pRequest.Parameters.SearchFlag
                };
                var com2 = new ComplexCondition()
                {
                    Left = com1, Right = cond3, Operator = LogicalOperators.Or
                };
                complexCondition.Add(com2);
                complexCondition.Add(new DirectCondition("(WeiXinUserId!='' Or WeiXinUserId IS NOT NULL)"));
                var tempVipList = vipLoginBLL.Query(complexCondition.ToArray(), null);
                if (tempVipList != null && tempVipList.Length != 0)
                {
                    pRequest.UserID = pRequest.Parameters.MemberID = tempVipList[0].VIPID;
                }
            }

            string m_MemberID = "";

            if (!string.IsNullOrWhiteSpace(pRequest.Parameters.OwnerVipID))
            {
                m_MemberID = string.IsNullOrWhiteSpace(pRequest.Parameters.OwnerVipID) ? pRequest.UserID : pRequest.Parameters.OwnerVipID;
            }
            else
            {
                m_MemberID = string.IsNullOrWhiteSpace(pRequest.Parameters.MemberID) ? pRequest.UserID : pRequest.Parameters.MemberID;
            }

            string UserID       = m_MemberID;
            var    VipLoginInfo = vipLoginBLL.GetByID(UserID);

            if (VipLoginInfo == null)
            {
                throw new APIException("用户不存在")
                      {
                          ErrorCode = 330
                      }
            }
            ;
            #region 20140909 kun.zou 发现状态为0,改为1
            if (VipLoginInfo.Status.HasValue && VipLoginInfo.Status == 0)
            {
                VipLoginInfo.Status = 1;
                vipLoginBLL.Update(VipLoginInfo, false);
                var log = new VipLogEntity()
                {
                    Action       = "更新",
                    ActionRemark = "vip状态为0的改为1.",
                    CreateBy     = UserID,
                    CreateTime   = DateTime.Now,
                    VipID        = VipLoginInfo.VIPID,
                    LogID        = Guid.NewGuid().ToString("N")
                };
                var logBll = new VipLogBLL(base.CurrentUserInfo);
                logBll.Create(log);
            }
            #endregion
            int couponCount = vipLoginBLL.GetVipCoupon(UserID);

            rd.MemberInfo.Mobile      = VipLoginInfo.Phone;      //手机号码
            rd.MemberInfo.Name        = VipLoginInfo.UserName;   //姓名
            rd.MemberInfo.VipID       = VipLoginInfo.VIPID;      //组标识
            rd.MemberInfo.VipName     = VipLoginInfo.VipName;    //会员名
            rd.MemberInfo.ImageUrl    = VipLoginInfo.HeadImgUrl; //会员头像  add by Henry 2014-12-5
            rd.MemberInfo.VipRealName = VipLoginInfo.VipRealName;
            rd.MemberInfo.VipNo       = VipLoginInfo.VipCode;
            rd.MemberInfo.IsDealer    = VipLoginInfo.Col48 != null?int.Parse(VipLoginInfo.Col48) : 0;

            //超级分销体系配置表 为判断是否存在分销体系使用
            var T_SuperRetailTraderConfigbll = new T_SuperRetailTraderConfigBLL(CurrentUserInfo);
            //获取分销体系信息
            var T_SuperRetailTraderConfigInfo = T_SuperRetailTraderConfigbll.QueryByEntity(new T_SuperRetailTraderConfigEntity()
            {
                IsDelete = 0, CustomerId = CurrentUserInfo.CurrentUser.customer_id
            }, null).FirstOrDefault();
            if (T_SuperRetailTraderConfigInfo != null)
            {
                rd.MemberInfo.CanBeSuperRetailTrader = 1;
            }
            else
            {
                rd.MemberInfo.CanBeSuperRetailTrader = 0;
            }
            rd.MemberInfo.SuperRetailTraderID = VipLoginInfo.Col26;
            //rd.MemberInfo.Integration = VipLoginInfo.Integration ?? 0;//会员积分

            #region 会员有效积分
            var vipIntegralBLL  = new VipIntegralBLL(CurrentUserInfo);
            var vipIntegralInfo = vipIntegralBLL.QueryByEntity(new VipIntegralEntity()
            {
                VipID = UserID, VipCardCode = VipLoginInfo.VipCode
            }, null).FirstOrDefault();
            if (vipIntegralInfo != null)
            {
                rd.MemberInfo.Integration = vipIntegralInfo.ValidIntegral != null ? vipIntegralInfo.ValidIntegral.Value : 0;
            }
            #endregion

            //会员等级
            //rd.MemberInfo.VipLevelName = string.IsNullOrEmpty(vipLoginBLL.GetVipLeave(UserID)) ? null : vipLoginBLL.GetVipLeave(UserID);
            #region 会员卡名称
            var                vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo);
            var                vipCardBLL           = new VipCardBLL(CurrentUserInfo);
            var                vipCardTypeBLL       = new SysVipCardTypeBLL(CurrentUserInfo);
            var                vipCardRuleBLL       = new VipCardRuleBLL(CurrentUserInfo);
            var                vipT_InoutBLL        = new T_InoutBLL(CurrentUserInfo);
            VipAmountBLL       vipAmountBLL         = new VipAmountBLL(CurrentUserInfo);
            ShoppingCartBLL    service     = new ShoppingCartBLL(CurrentUserInfo);
            ShoppingCartEntity queryEntity = new ShoppingCartEntity();
            queryEntity.VipId = UserID;
            int totalQty = service.GetListQty(queryEntity);
            rd.MemberInfo.ShopCartCount = totalQty;
            //定义当前自定义等级
            int?CurVipLevel        = 0;
            var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = UserID, CustomerID = CurrentUserInfo.ClientID
            },
                                                                        new OrderBy[] { new OrderBy()
                                                                                        {
                                                                                            FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                        } }).FirstOrDefault();
            if (vipCardMappingInfo != null)
            {
                var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                }, null).FirstOrDefault();
                if (vipCardInfo != null)
                {
                    var vipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        VipCardTypeID = vipCardInfo.VipCardTypeID
                    }, null).FirstOrDefault();
                    if (vipCardTypeInfo != null)
                    {
                        rd.MemberInfo.VipLevelName     = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                        rd.MemberInfo.CardTypeImageUrl = vipCardTypeInfo.PicUrl != null ? vipCardTypeInfo.PicUrl : "";
                        rd.MemberInfo.CardTypePrice    = vipCardTypeInfo.Prices != null ? vipCardTypeInfo.Prices.Value : 0;
                        rd.MemberInfo.IsExtraMoney     = vipCardTypeInfo.IsExtraMoney != null ? vipCardTypeInfo.IsExtraMoney : 0;
                        CurVipLevel             = vipCardTypeInfo.VipCardLevel;
                        rd.MemberInfo.IsPrepaid = vipCardTypeInfo.Isprepaid;
                        if (CurVipLevel > 1)
                        {
                            var VipCardTypeSysInfo = vipCardTypeBLL.GetBindVipCardTypeInfo(CurrentUserInfo.ClientID, VipLoginInfo.Phone, pRequest.UserID, CurVipLevel);
                            if (VipCardTypeSysInfo == null || VipCardTypeSysInfo.Tables[0].Rows.Count == 0)
                            {
                                rd.MemberInfo.IsNeedCard = 2;
                            }
                        }
                        else
                        {
                            rd.MemberInfo.IsNeedCard = 1;
                        }
                        //因为卡等级不能重复,知道当前等级后查找相应的下一级是否是自动升级(消费升级)
                        var NextVipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            VipCardLevel = CurVipLevel + 1, CustomerID = CurrentUserInfo.ClientID
                        }, null).FirstOrDefault();
                        if (NextVipCardTypeInfo != null)
                        {
                            //获取当前会员的消费金额信息
                            decimal CurVipConsumptionAmount = 0;
                            decimal VipConsumptionInfo      = vipT_InoutBLL.GetVipSumAmount(UserID);
                            if (VipConsumptionInfo > 0)
                            {
                                CurVipConsumptionAmount = Convert.ToDecimal(Convert.ToDecimal(VipConsumptionInfo).ToString("0.00"));
                            }
                            //知道下一等级后要判断,升级条件是否是消费升级
                            //定义累积消费金额
                            decimal AccumulatedAmount      = 0;
                            var     vipCardTypeUpGradeInfo = vipCardTypeBLL.GetVipCardTypeUpGradeInfo(CurrentUserInfo.ClientID, CurVipLevel);
                            if (vipCardTypeUpGradeInfo != null && vipCardTypeUpGradeInfo.Tables[0].Rows.Count > 0)
                            {
                                //判断拉取的所有卡等级里的最近的一级满足条件即可返回提示所需的值
                                int flag = 0;
                                foreach (DataRow dr in vipCardTypeUpGradeInfo.Tables[0].Rows)
                                {
                                    AccumulatedAmount = Convert.ToDecimal(Convert.ToDecimal(dr["BuyAmount"].ToString()).ToString("0.00"));
                                    //获取消费升级还需多少钱
                                    if (AccumulatedAmount > CurVipConsumptionAmount && flag == 0)
                                    {
                                        flag = 1;
                                        rd.MemberInfo.UpGradeNeedMoney = AccumulatedAmount - CurVipConsumptionAmount;
                                        if (rd.MemberInfo.UpGradeNeedMoney > 0)
                                        {
                                            rd.MemberInfo.UpgradePrompt = "还需要消费" + rd.MemberInfo.UpGradeNeedMoney + "元可以升级啦,快点通知会员!";
                                        }
                                    }
                                }
                            }
                        }

                        var VipCardRuleInfo = vipCardRuleBLL.QueryByEntity(new VipCardRuleEntity()
                        {
                            CustomerID = CurrentUserInfo.ClientID, VipCardTypeID = vipCardTypeInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (VipCardRuleInfo != null)
                        {
                            rd.MemberInfo.CardDiscount = Convert.ToDecimal(Convert.ToDecimal((VipCardRuleInfo.CardDiscount / 10)).ToString("0.00"));
                        }
                    }
                }
            }
            else
            {
                //表示需要领卡,并展示等级为1的默认卡
                rd.MemberInfo.IsNeedCard = 0;
                var VipCardTypeData = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                {
                    VipCardLevel = 1, CustomerID = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (VipCardTypeData != null)
                {
                    rd.MemberInfo.CardTypeImageUrl = VipCardTypeData.PicUrl != null ? VipCardTypeData.PicUrl : "";
                }
            }
            //获取红利/// decimal[0]=总收入(红利) decimal[2]=支出余额 decimal[1]=总提现金额
            decimal[] array = vipAmountBLL.GetVipSumAmountByCondition(UserID, CurrentUserInfo.ClientID, true);
            if (array[0] != null)
            {
                rd.MemberInfo.ProfitAmount = array[0];
            }
            //是否有付费的会员卡
            List <IWhereCondition> freeCardCon = new List <IWhereCondition> {
            };
            freeCardCon.Add(new EqualsCondition()
            {
                FieldName = "CustomerID", Value = CurrentUserInfo.ClientID
            });
            freeCardCon.Add(new DirectCondition("Prices>0"));
            var freeCardTypeInfo = vipCardTypeBLL.Query(freeCardCon.ToArray(), null).FirstOrDefault();
            if (freeCardTypeInfo != null)
            {
                rd.MemberInfo.IsCostCardType = 1;
            }
            else
            {
                rd.MemberInfo.IsCostCardType = 0;
            }

            #endregion

            rd.MemberInfo.Status       = VipLoginInfo.Status.HasValue ? VipLoginInfo.Status.Value : 1;
            rd.MemberInfo.CouponsCount = couponCount;
            rd.MemberInfo.IsActivate   = (VipLoginInfo.IsActivate.HasValue && VipLoginInfo.IsActivate.Value == 1 ? true : false);
            var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo);
            rd.MemberInfo.MemberBenefits = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID);



            //获取标签信息
            TagsBLL TagsBLL = new TagsBLL(base.CurrentUserInfo);


            var dsIdentity = TagsBLL.GetVipTagsList("", UserID);//“车主标签”  传7
            if (dsIdentity != null && dsIdentity.Tables.Count > 0 && dsIdentity.Tables[0].Rows.Count > 0)
            {
                rd.IdentityTagsList = DataTableToObject.ConvertToList <TagsInfo>(dsIdentity.Tables[0]).ToArray(); //“年龄段”  传8
            }


            #region 获取注册表单的列明和值

            var vipEntity = vipLoginBLL.QueryByEntity(new VipEntity()
            {
                VIPID = UserID
            }, null);

            if (vipEntity == null || vipEntity.Length == 0)
            {
                return(rd);
            }
            else
            {
                var ds = vipLoginBLL.GetVipColumnInfo(CurrentUserInfo.ClientID, "online005");

                var vipDs = vipLoginBLL.GetVipInfo(UserID);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    var temp = ds.Tables[0].AsEnumerable().Select(t => new MemberControlInfo()
                    {
                        ColumnName  = t["ColumnName"].ToString(),
                        ControlType = Convert.ToInt32(t["ControlType"]),
                        ColumnValue = vipDs.Tables[0].Rows[0][t["ColumnName"].ToString()].ToString(),
                        ColumnDesc  = t["columnDesc"].ToString()
                    });

                    rd.MemberControlList = temp.ToArray();
                }
            }

            //var vipamountBll = new VipAmountBLL(this.CurrentUserInfo);

            //var vipAmountEntity = vipamountBll.GetByID(UserID);


            var unitBll = new UnitBLL(this.CurrentUserInfo);
            //Hashtable htPara = new Hashtable();
            //htPara["MemberID"] = UserID;
            //htPara["CustomerID"] = CurrentUserInfo.ClientID;
            //htPara["PageIndex"] = 1;
            //htPara["PageSize"] = 10;
            //DataSet dsMyAccount = unitBll.GetMyAccount(htPara);

            //if (dsMyAccount.Tables[0].Rows.Count > 0)
            //{
            //    //rd.AccountList = DataTableToObject.ConvertToList<AccountInfo>(dsMyAccount.Tables[0]);
            //    //rd.MemberInfo.Balance = Convert.ToDecimal(dsMyAccount.Tables[0].Rows[0]["Total"].ToString());
            //    //rd.TotalPageCount = int.Parse(dsMyAccount.Tables[0].Rows[0]["PageCount"].ToString());

            //}
            //else
            //    rd.MemberInfo.Balance = 0;

            //返现 add by Henry 2015-4-15
            var vipAmountBll = new VipAmountBLL(CurrentUserInfo);
            //var vipAmountInfo = vipAmountBll.GetByID(UserID);
            var vipAmountInfo = vipAmountBll.QueryByEntity(new VipAmountEntity()
            {
                VipId = UserID, VipCardCode = VipLoginInfo.VipCode
            }, null).FirstOrDefault();
            decimal returnAmount = 0;
            decimal amount       = 0;
            if (vipAmountInfo != null)
            {
                returnAmount = vipAmountInfo.ValidReturnAmount == null ? 0 : vipAmountInfo.ValidReturnAmount.Value;
                amount       = vipAmountInfo.EndAmount == null ? 0 : vipAmountInfo.EndAmount.Value;
            }
            rd.MemberInfo.ReturnAmount = returnAmount; //返现
            rd.MemberInfo.Balance      = amount;       //余额
            #endregion


            //获取订单的日期和订单的里的商品名称、商品单价、商品数量
            //先获取订单列表,再获取订单详细信息
            int?         pageSize     = 3; //rp.Parameters.PageSize;,只取三条记录
            int?         pageIndex    = 1; //rp.Parameters.PageIndex;
            string       OrderBy      = "";
            string       OrderType    = "";
            T_InoutBLL   T_InoutBLL   = new T_InoutBLL(CurrentUserInfo);
            InoutService InoutService = new InoutService(CurrentUserInfo);
            //只取状态为700的
            //根据订单列表取订单详情
            DataSet dsOrder = T_InoutBLL.GetOrdersByVipID(rd.MemberInfo.VipID, pageIndex ?? 1, pageSize ?? 15, OrderBy, OrderType);//获取会员信息
            if (dsOrder != null && dsOrder.Tables.Count != 0 && dsOrder.Tables[0].Rows.Count != 0)
            {
                List <JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo> orderList = DataTableToObject.ConvertToList <JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo>(dsOrder.Tables[1]);
                foreach (JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo oi in orderList)
                {
                    IList <InoutDetailInfo> detailList = InoutService.GetInoutDetailInfoByOrderId(oi.order_id);
                    oi.DetailList = detailList;
                }
                rd.OrderList = orderList;
            }

            MessageInfo message = new MessageInfo();


            InnerGroupNewsBLL InnerGroupNewsService = new InnerGroupNewsBLL(CurrentUserInfo);
            SetoffToolsBLL    setofftoolsService    = new SetoffToolsBLL(CurrentUserInfo);

            //1=微信用户 2=APP员工
            int UnReadInnerMessageCount = InnerGroupNewsService.GetVipInnerGroupNewsUnReadCount(CurrentUserInfo.UserID, pRequest.CustomerID, 1, null, Convert.ToDateTime(VipLoginInfo.CreateTime));
            var setofftoolsMessageCount = setofftoolsService.GetUnReadSetoffToolsCount(CurrentUserInfo.UserID, pRequest.CustomerID, 1, 1);
            message.InnerGroupNewsCount = UnReadInnerMessageCount;
            message.SetoffToolsCount    = setofftoolsMessageCount;
            var VipUpNewsInfo = InnerGroupNewsService.GetVipInnerNewsInfo(CurrentUserInfo.ClientID, 2, 1, 3, 0);
            if (VipUpNewsInfo != null && VipUpNewsInfo.Tables[0].Rows.Count > 0)
            {
                message.UpGradeSucess = VipUpNewsInfo.Tables[0].Rows[0]["Text"] != null ? VipUpNewsInfo.Tables[0].Rows[0]["Text"].ToString() : "";
                //获取通知信息 并更新已读状态 数据如果不是一条进行更新所有数据
                var newsUserMappingBLL = new NewsUserMappingBLL(CurrentUserInfo);
                if (VipUpNewsInfo.Tables[0].Rows.Count > 1)//数据如果不是一条进行更新所有数据
                {
                    foreach (DataRow VipNewsdr in VipUpNewsInfo.Tables[0].Rows)
                    {
                        var vipNewsInfo = newsUserMappingBLL.QueryByEntity(new NewsUserMappingEntity()
                        {
                            CustomerId = CurrentUserInfo.ClientID, MappingID = VipNewsdr["MappingID"].ToString()
                        }, null).FirstOrDefault();
                        if (vipNewsInfo != null)
                        {
                            vipNewsInfo.HasRead = 1;
                            newsUserMappingBLL.Update(vipNewsInfo);
                        }
                    }
                }
                else
                {
                    var vipNewsInfo = newsUserMappingBLL.QueryByEntity(new NewsUserMappingEntity()
                    {
                        CustomerId = CurrentUserInfo.ClientID, MappingID = VipUpNewsInfo.Tables[0].Rows[0]["MappingID"].ToString()
                    }, null).FirstOrDefault();
                    if (vipNewsInfo != null)
                    {
                        vipNewsInfo.HasRead = 1;
                        newsUserMappingBLL.Update(vipNewsInfo);
                    }
                }
            }
            else
            {
                message.UpGradeSucess = "";
            }
            rd.MessageInfo = message;
            return(rd);
        }
    }
Ejemplo n.º 3
0
        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;
        }
    }
}