Beispiel #1
0
 /// <summary>
 /// 批量处理变更
 /// </summary>
 /// <param name="vipCardIds"></param>
 /// <param name="StatusIDNext"></param>
 /// <param name="strError"></param>
 /// <returns></returns>
 public bool SetVipCardStatusChangeBatch(string vipCardIds, int StatusIDNext, out string strError)
 {
     #region
     if (vipCardIds == null || vipCardIds.Trim().Equals(""))
     {
         strError = "会员卡号标识不能为空.";
         return(false);
     }
     if (StatusIDNext == 0 || StatusIDNext.ToString().Trim().Equals(""))
     {
         strError = "更改之后的状态标识不能为空.";
         return(false);
     }
     #endregion
     bool       bReturn       = true;
     string[]   vipCardIdArr  = vipCardIds.Split(',');
     VipCardBLL vipCardServer = new VipCardBLL(this.CurrentUserInfo);
     foreach (string id in vipCardIdArr)
     {
         VipCardEntity vipCardInfo = new VipCardEntity();
         vipCardInfo = vipCardServer.GetByID(id);
         bReturn     = SetVipCardStatusChange(id
                                              , Convert.ToInt32(vipCardInfo.VipCardStatusId)
                                              , StatusIDNext
                                              , this.CurrentUserInfo.CurrentUserRole.UnitId
                                              , out strError);
         if (!bReturn)
         {
             break;
         }
     }
     strError = "ok";
     return(bReturn);
 }
Beispiel #2
0
        /// <summary>
        /// 获取会员折扣
        /// </summary>
        /// <returns></returns>
        public decimal GetVipDiscount()
        {
            decimal vipDiscount = 10;    //会员折扣
            //判断是否启用会员折扣
            var basicSettingBLL = new CustomerBasicSettingBLL(CurrentUserInfo);
            var vipBLL          = new VipBLL(CurrentUserInfo);
            //var sysVipCardGradeBLL = new SysVipCardGradeBLL(CurrentUserInfo);
            var vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo);
            var vipCardBLL           = new VipCardBLL(CurrentUserInfo);
            var vipCardRuleBLL       = new VipCardRuleBLL(CurrentUserInfo);
            //string vipDiscountSetting = basicSettingBLL.GetSettingValueByCode("VipCardGradeSalesPreferentia");
            //if (!string.IsNullOrEmpty(vipDiscountSetting))
            //{
            //    if (int.Parse(vipDiscountSetting) > 0)//启用
            //    {
            //        var vipInfo = vipBLL.GetByID(CurrentUserInfo.UserID);
            //        if (vipInfo != null)
            //        {
            //            if (vipInfo.VipLevel>0)
            //            {
            //                //获取会员等级折扣
            //                var sysVipCardGradeInfo = sysVipCardGradeBLL.GetByID(vipInfo.VipLevel);
            //                if (sysVipCardGradeInfo != null)
            //                    vipDiscount = sysVipCardGradeInfo.SalesPreferentiaAmount.Value;
            //            }
            //        }
            //    }
            //}
            var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = CurrentUserInfo.UserID
            }, null).FirstOrDefault();

            if (vipCardMappingInfo != null)
            {
                var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID
                }, null).FirstOrDefault();
                if (vipCardInfo != null)
                {
                    var vipCardRuleInfo = vipCardRuleBLL.QueryByEntity(new VipCardRuleEntity()
                    {
                        VipCardTypeID = vipCardInfo.VipCardTypeID
                    }, null).FirstOrDefault();
                    if (vipCardRuleInfo != null && vipCardRuleInfo.CardDiscount > 0)
                    {
                        vipDiscount = vipCardRuleInfo.CardDiscount == null ? 10 : (vipCardRuleInfo.CardDiscount.Value / 10);
                    }
                }
            }
            return(vipDiscount);
        }
        public void updateVipCardByType(string vipId, int vipCardTypeId, string changeReason, string remark, string vipCode, IDbTransaction pTran)
        {
            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);
            string      unitId     = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识

            VipCardEntity vipCardInfo = vipCardBLL.GetVipCardByVipMapping(vipId);

            //更新卡信息
            vipCardInfo.VipCardTypeID = vipCardTypeId;
            vipCardBLL.Update(vipCardInfo, pTran);

            //var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity() { VipCardTypeID = vipCardTypeId, VipCardStatusId = 0, MembershipUnit = "" }, null).FirstOrDefault();

            //不存在,制卡
            //if (vipCardInfo == null)
            //{
            //    vipCardInfo = new VipCardEntity();
            //    vipCardInfo.VipCardID = Guid.NewGuid().ToString();
            //    vipCardInfo.VipCardTypeID = vipCardTypeId;
            //    vipCardInfo.VipCardTypeName = vipCardTypeName;
            //    vipCardInfo.VipCardCode = vipCode;
            //    vipCardInfo.VipCardStatusId = 1;//正常
            //    vipCardInfo.MembershipUnit = unitId;
            //    vipCardInfo.MembershipTime = DateTime.Now;
            //    vipCardInfo.CustomerID = CurrentUserInfo.ClientID;
            //    vipCardBLL.Create(vipCardInfo, pTran);
            //}

            //新增会员卡操作状态信息
            var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
            {
                LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                VipCardStatusID = vipCardInfo.VipCardStatusId,
                VipCardID       = vipCardInfo.VipCardID,
                Action          = "升级",
                Reason          = changeReason,
                Remark          = remark,
                UnitID          = unitId,
                CustomerID      = CurrentUserInfo.ClientID
            };

            vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity, pTran);


            var vipCardVipMappingEntity = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VipCardID = vipCardInfo.VipCardID
            }, null).FirstOrDefault();

            vipCardVipMappingEntity.LastUpdateTime = DateTime.Now;

            vipCardVipMappingBLL.Update(vipCardVipMappingEntity, pTran);
            //绑定会员卡和会员
            //var vipCardVipMappingEntity = new VipCardVipMappingEntity()
            //{
            //    MappingID = Guid.NewGuid().ToString().Replace("-", ""),
            //    VIPID = vipId,
            //    VipCardID = vipCardInfo.VipCardID,
            //    CustomerID = CurrentUserInfo.ClientID
            //};
            //vipCardVipMappingBLL.Create(vipCardVipMappingEntity, pTran);

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

            eventService.PublishMsg(vipMsg);
        }
        /// <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);
        }
        /// <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);
        }
 /// <summary>
 /// 充值提交
 /// </summary>
 /// <param name="VipCardID">会员卡标识【必须】</param>
 /// <param name="RechargeAmount">充值金额【必须】</param>
 /// <param name="RechargeNo">小票号【必须】</param>
 /// <param name="PaymentTypeID">充值方式【必须】</param>
 /// <param name="UnitID">充值门店【必须】</param>
 /// <param name="strError">输出信息</param>
 /// <returns></returns>
 public bool SetVipCardRecjargeRpecord(string VipCardID
                                       , decimal RechargeAmount
                                       , string RechargeNo
                                       , string PaymentTypeID
                                       , string UnitID
                                       , out string strError)
 {
     try
     {
         #region 判断输入信息是否合法
         if (VipCardID == null || VipCardID.Trim().Equals(""))
         {
             strError = "会员卡号标识不能为空.";
             return(false);
         }
         if (RechargeAmount.ToString().Trim().Equals(""))
         {
             strError = "充值金额不能为空.";
             return(false);
         }
         if (RechargeNo == null || RechargeNo.ToString().Trim().Equals(""))
         {
             strError = "小票号不能为空.";
             return(false);
         }
         if (PaymentTypeID == null || PaymentTypeID.ToString().Trim().Equals(""))
         {
             strError = "支付方式不能为空.";
             return(false);
         }
         if (UnitID == null || UnitID.ToString().Trim().Equals(""))
         {
             strError = "充值门店不能为空.";
             return(false);
         }
         #endregion
         //1.获取会员卡信息
         #region 获取会员卡信息
         VipCardBLL    vipCardServer = new VipCardBLL(this.CurrentUserInfo);
         VipCardEntity vipCardInfo   = new VipCardEntity();
         vipCardInfo = vipCardServer.GetByID(VipCardID);
         if (vipCardInfo == null)
         {
             strError = "会员卡信息不存在.";
             return(false);
         }
         if (vipCardInfo.BalanceAmount == null || vipCardInfo.BalanceAmount.ToString().Equals(""))
         {
             vipCardInfo.BalanceAmount = 0;
         }
         if (vipCardInfo.TotalAmount == null || vipCardInfo.TotalAmount.ToString().Equals(""))
         {
             vipCardInfo.TotalAmount = 0;
         }
         #endregion
         //2.修改会员卡信息
         #region
         VipCardEntity vipCard = new VipCardEntity();
         vipCard.VipCardID     = vipCardInfo.VipCardID;
         vipCard.BalanceAmount = vipCardInfo.BalanceAmount + RechargeAmount;
         vipCard.TotalAmount   = vipCardInfo.TotalAmount + RechargeAmount;
         #endregion
         //3.插入充值记录
         #region
         VipCardRechargeRecordEntity vipCardRRInfo = new VipCardRechargeRecordEntity();
         vipCardRRInfo.RechargeRecordID    = JIT.CPOS.BS.BLL.BaseService.NewGuidPub();
         vipCardRRInfo.RechargeNo          = RechargeNo;
         vipCardRRInfo.PaymentTypeID       = PaymentTypeID;
         vipCardRRInfo.RechargeAmount      = RechargeAmount;
         vipCardRRInfo.RechargeTime        = System.DateTime.Now;
         vipCardRRInfo.VipCardID           = VipCardID;
         vipCardRRInfo.BalanceBeforeAmount = vipCardInfo.BalanceAmount;
         vipCardRRInfo.BalanceAfterAmount  = vipCardInfo.BalanceAmount + RechargeAmount;
         vipCardRRInfo.RechargeUserID      = this.CurrentUserInfo.UserID;
         vipCardRRInfo.UnitID     = UnitID;
         vipCardRRInfo.CustomerID = this.CurrentUserInfo.CurrentUser.customer_id;
         #endregion
         //strError = "充值成功.";
         //return true;
         return(_currentDAO.SetVipCardRecjargeRpecord(vipCard, vipCardRRInfo, out strError));
     }
     catch (Exception ex) {
         throw (ex);
     }
 }