/// <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);
        }
Example #2
0
        protected override CTWEventShareLogRD ProcessRequest(DTO.Base.APIRequest <CTWEventShareLogRP> pRequest)
        {
            var rd   = new CTWEventShareLogRD();//返回值
            var para = pRequest.Parameters;

            if (!string.IsNullOrEmpty(para.CTWEventId) && !string.IsNullOrEmpty(para.Sender) && !string.IsNullOrEmpty(para.OpenId))
            {
                var bllLeventShareLog    = new T_LEventsSharePersonLogBLL(this.CurrentUserInfo);
                var entityLeventShareLog = new T_LEventsSharePersonLogEntity();

                entityLeventShareLog.ShareVipID    = para.Sender;
                entityLeventShareLog.ShareOpenID   = para.OpenId;
                entityLeventShareLog.BeShareOpenID = para.BeSharedOpenId;
                entityLeventShareLog.BeShareVipID  = para.BEsharedUserId;
                entityLeventShareLog.BusTypeCode   = "CTW";
                entityLeventShareLog.ObjectId      = para.CTWEventId;
                entityLeventShareLog.ShareURL      = para.ShareURL;
                entityLeventShareLog.ShareVipType  = 3;
                bllLeventShareLog.Create(entityLeventShareLog);
                //是否分享给自己
                if (para.Sender == para.BEsharedUserId)
                {
                    return(rd);
                }
                //触点奖励
                ContactEventBLL bllContactEvent = new ContactEventBLL(this.CurrentUserInfo);
                var             entityContact   = bllContactEvent.QueryByEntity(new ContactEventEntity()
                {
                    EventId = para.CTWEventId, IsDelete = 0, IsCTW = 1, ContactTypeCode = "Share"
                }, null).SingleOrDefault();
                if (entityContact != null)
                {
                    LPrizesBLL      bllPrize       = new LPrizesBLL(this.CurrentUserInfo);
                    LPrizeWinnerBLL bllPrizeWinner = new LPrizeWinnerBLL(this.CurrentUserInfo);
                    LLotteryLogBLL  bllLottery     = new LLotteryLogBLL(this.CurrentUserInfo);
                    ///判断是否已经获得奖励
                    int intLogCount = bllLottery.GetEventLotteryLogByEventId(entityContact.ContactEventId.ToString(), para.Sender);
                    if (intLogCount > 0)
                    {
                        return(rd);
                    }

                    var prize = DataTableToObject.ConvertToList <LPrizesEntity>(bllPrize.GetCouponTypeIDByEventId(entityContact.ContactEventId.ToString()).Tables[0]).FirstOrDefault();
                    if (prize != null)
                    {
                        CouponBLL bllCoupon = new CouponBLL(this.CurrentUserInfo);

                        if (prize.PrizeTypeId == "Coupon")
                        {
                            bllCoupon.CouponBindVip(para.Sender, prize.CouponTypeID, entityContact.ContactEventId.ToString(), "Share");

                            DataSet ds = bllPrize.GetAllCouponTypeByPrize(prize.PrizesID);
                            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                            {
                                var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL();

                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    redisVipMappingCouponBLL.SetVipMappingCoupon(new CC_Coupon()
                                    {
                                        CustomerId   = this.CurrentUserInfo.ClientID,
                                        CouponTypeId = dr["CouponTypeID"].ToString()
                                    }, entityContact.ContactEventId.ToString(), para.Sender, "Share");
                                }
                            }
                        }
                        if (prize.PrizeTypeId == "Point")
                        {
                            #region 调用积分统一接口
                            var            salesReturnBLL = new T_SalesReturnBLL(this.CurrentUserInfo);
                            VipIntegralBLL bllVipIntegral = new VipIntegralBLL(this.CurrentUserInfo);
                            var            vipBLL         = new VipBLL(this.CurrentUserInfo);

                            var vipInfo        = vipBLL.GetByID(para.Sender);
                            var IntegralDetail = new VipIntegralDetailEntity()
                            {
                                Integral         = prize.Point,
                                IntegralSourceID = "28",
                                ObjectId         = entityContact.ContactEventId.ToString()
                            };
                            //变动前积分
                            string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                            //变动积分
                            string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                            var    vipIntegralDetailId = bllVipIntegral.AddIntegral(ref vipInfo, null, IntegralDetail, null, this.CurrentUserInfo);
                            //发送微信积分变动通知模板消息
                            if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                            {
                                var CommonBLL = new CommonBLL();
                                CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, this.CurrentUserInfo);
                            }

                            #endregion
                        }

                        #region 奖励日志
                        LPrizeWinnerEntity entityPrizeWinner = new LPrizeWinnerEntity()
                        {
                            PrizeWinnerID = Guid.NewGuid().ToString(),
                            VipID         = para.Sender,
                            PrizeID       = prize.PrizesID,
                            PrizeName     = prize.PrizeName,
                            PrizePoolID   = "",
                            CreateBy      = this.CurrentUserInfo.UserID,
                            CreateTime    = DateTime.Now,
                            IsDelete      = 0
                        };

                        bllPrizeWinner.Create(entityPrizeWinner);


                        LLotteryLogEntity lotteryEntity = new LLotteryLogEntity()
                        {
                            LogId        = Guid.NewGuid().ToString(),
                            VipId        = para.Sender,
                            EventId      = entityContact.ContactEventId.ToString(),
                            LotteryCount = 1,
                            IsDelete     = 0
                        };
                        bllLottery.Create(lotteryEntity);
                        #endregion
                    }
                }
            }
            return(rd);
        }
        /// <summary>
        /// 支付完成时注册绑卡   (目前可用于绑卡列表处的绑卡升级处理)
        /// </summary>
        /// <param name="vipId"></param>
        /// <param name="vipCode"></param>
        /// <param name="unitId"></param>
        /// <param name="ObjecetTypeId">卡类型Id</param>
        /// <param name="OrderType">订单类型 SalesCard=销售 Recharge=充值</param>
        /// <param name="OperationType">操作类型 1-手动 2-自动</param>
        /// <returns></returns>
        public string BindVirtualItem(string vipId, string vipCode, string unitId, int ObjecetTypeId, string OrderType = "SalesCard", int OperationType = 1, string orderId = "")
        {
            var vipCardVipMappingBLL      = new VipCardVipMappingBLL(CurrentUserInfo);
            var sysVipCardTypeBLL         = new SysVipCardTypeBLL(CurrentUserInfo);
            var vipCardBLL                = new VipCardBLL(CurrentUserInfo);
            var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(CurrentUserInfo);

            string ObjectNo = string.Empty;//卡号或券号

            try
            {
                UnitService unitServer = new UnitService(CurrentUserInfo);
                if (string.IsNullOrEmpty(unitId))
                {
                    unitId = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识
                }
                //根据vipid查询VipCardVipMapping,判断是否有绑卡
                var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VIPID = vipId
                }, null).FirstOrDefault();

                //判断商户是否有付费的会员卡,有付费会员卡时,不自动绑卡
                //List<IWhereCondition> freeCardCon = new List<IWhereCondition> { };
                //freeCardCon.Add(new EqualsCondition() { FieldName = "CustomerID", Value = CurrentUserInfo.ClientID });
                //freeCardCon.Add(new DirectCondition("Prices>0"));
                //var freeCardTypeInfo = sysVipCardTypeBLL.Query(freeCardCon.ToArray(), null).FirstOrDefault();
                //if (freeCardTypeInfo == null)
                //{
                ////查询最低等级的会员卡类型
                //var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity() { CustomerID = CurrentUserInfo.ClientID, Category = 0 }, new OrderBy[] { new OrderBy() { FieldName = "vipcardlevel", Direction = OrderByDirections.Asc } }).FirstOrDefault();
                //if (vipCardTypeInfo != null)
                //{


                if (vipCardMappingInfo == 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)
                    {
                        throw new APIException("系统未创建会员卡类型")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }
                    //查询此类型会员卡是否存在
                    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);
                    }
                    ObjectNo = vipCardInfo.VipCardCode;
                    //绑定会员卡和会员
                    var vipCardVipMappingEntity = new VipCardVipMappingEntity()
                    {
                        MappingID  = Guid.NewGuid().ToString().Replace("-", ""),
                        VIPID      = vipId,
                        VipCardID  = vipCardInfo.VipCardID,
                        CustomerID = CurrentUserInfo.ClientID
                    };
                    vipCardVipMappingBLL.Create(vipCardVipMappingEntity);
                    vipCardMappingInfo = vipCardVipMappingEntity;
                    //新增会员卡操作状态信息
                    var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
                    {
                        LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                        VipCardStatusID = vipCardInfo.VipCardStatusId,
                        VipCardID       = vipCardInfo.VipCardID,
                        Action          = "注册",
                        UnitID          = unitId,
                        CustomerID      = CurrentUserInfo.ClientID
                    };
                    vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity);
                }

                #region 老卡业务处理

                ObjectNo = vipCode;
                //老卡信息获取
                var oldVipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID
                }, null).FirstOrDefault();

                //老卡卡类型ID
                int oldVipCardTypeID = 0;
                if (oldVipCardInfo != null)
                {
                    //获取老卡的类型
                    var oldVipCardType = sysVipCardTypeBLL.GetByID(oldVipCardInfo.VipCardTypeID);
                    //获取即将升级卡的类型
                    var newVipCardType = sysVipCardTypeBLL.GetByID(ObjecetTypeId);
                    if (newVipCardType.VipCardLevel > oldVipCardType.VipCardLevel)
                    {
                        //老卡卡类型ID
                        oldVipCardTypeID = oldVipCardInfo.VipCardTypeID ?? 0;
                        //更新卡信息
                        oldVipCardInfo.VipCardTypeID = ObjecetTypeId;
                        vipCardBLL.Update(oldVipCardInfo);
                        //老卡操作状态信息
                        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 vipCardGradeChangeLogBll = new VipCardGradeChangeLogBLL(CurrentUserInfo);
                        var vipCardUpgradeRuleBll    = new VipCardUpgradeRuleBLL(CurrentUserInfo);
                        var vipCardUpgradeRuleEntity = vipCardUpgradeRuleBll.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            CustomerID = CurrentUserInfo.ClientID, VipCardTypeID = ObjecetTypeId
                        }, null).FirstOrDefault();
                        var VipCardGradeChangeLogEntity = new VipCardGradeChangeLogEntity()
                        {
                            ChangeLogID           = Guid.NewGuid().ToString().Replace("-", ""),
                            VipCardUpgradeRuleId  = vipCardUpgradeRuleEntity.VipCardUpgradeRuleId,
                            OrderType             = OrderType,
                            VipCardID             = oldVipCardInfo.VipCardID,
                            ChangeBeforeVipCardID = oldVipCardInfo.VipCardID,
                            ChangeBeforeGradeID   = oldVipCardTypeID,
                            NowGradeID            = oldVipCardInfo.VipCardTypeID,
                            ChangeReason          = "upgrade",
                            OperationType         = OperationType,
                            ChangeTime            = DateTime.Now,
                            UnitID     = unitId,
                            OrderId    = orderId,
                            CustomerID = CurrentUserInfo.ClientID,
                        };
                        vipCardGradeChangeLogBll.Create(VipCardGradeChangeLogEntity);

                        //开卡礼
                        var vipCardUpgradeRewardBll        = new VipCardUpgradeRewardBLL(CurrentUserInfo);
                        var vipCardUpgradeRewardEntityList = vipCardUpgradeRewardBll.QueryByEntity(new VipCardUpgradeRewardEntity()
                        {
                            VipCardTypeID = ObjecetTypeId
                        }, 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");
                                }
                            }
                        }
                        //消费升级
                        if (OperationType == 2)
                        {
                            //群发消息表
                            var InnerGroupNewsBll    = new InnerGroupNewsBLL(CurrentUserInfo);
                            var innerGroupNewsEntity = new InnerGroupNewsEntity()
                            {
                                GroupNewsId        = Guid.NewGuid().ToString().Replace("-", ""),
                                SentType           = 2,
                                NoticePlatformType = 1,
                                BusType            = 3,
                                Title      = "升级提醒",
                                Text       = "升级成功",
                                CustomerID = CurrentUserInfo.ClientID
                            };
                            InnerGroupNewsBll.Create(innerGroupNewsEntity);
                            //消息和用户关系表
                            var newsUserMappingBll    = new NewsUserMappingBLL(CurrentUserInfo);
                            var newsUserMappingEntity = new NewsUserMappingEntity()
                            {
                                MappingID   = Guid.NewGuid().ToString().Replace("-", ""),
                                UserID      = vipId,
                                GroupNewsID = innerGroupNewsEntity.GroupNewsId,
                                CustomerId  = CurrentUserInfo.ClientID,
                                HasRead     = 0
                            };
                            newsUserMappingBll.Create(newsUserMappingEntity);
                        }
                    }
                }
                #endregion
            }
            catch { throw new APIException("升级失败!")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          }; };

            //记录会员信息改变,并且把旧的会员的标识也放在契约里
            var eventService = new EventService();
            var vipMsg       = new EventContract
            {
                Operation  = OptEnum.Update,
                EntityType = EntityTypeEnum.Vip,
                Id         = vipId,
            };
            eventService.PublishMsg(vipMsg);

            return(ObjectNo);
        }