/// <summary>
        ///
        /// </summary>
        public string GetVipCardStatusChangeLogListData()
        {
            var    service = new VipCardStatusChangeLogBLL(CurrentUserInfo);
            string content = string.Empty;

            string key = string.Empty;

            if (Request("VipCardID") != null && Request("VipCardID") != string.Empty)
            {
                key = Request("VipCardID").ToString().Trim();
            }

            int pageIndex = Utils.GetIntVal(FormatParamValue(Request("page"))) - 1;

            IList <VipCardStatusChangeLogEntity> data;

            int maxRowCount   = PageSize;
            int startRowIndex = Utils.GetIntVal(Request("start"));

            VipCardStatusChangeLogEntity queryInfo = new VipCardStatusChangeLogEntity();

            queryInfo.VipCardID = key;
            data = service.GetList(queryInfo, pageIndex, PageSize);
            int totalCount = service.GetListCount(queryInfo);

            content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}",
                                    data.ToJSON(),
                                    totalCount);

            return(content);
        }
Example #2
0
 /// <summary>
 /// 状态变更
 /// </summary>
 /// <param name="VipCardID">会员卡标识</param>
 /// <param name="StatusIDNow">当前状态标识</param>
 /// <param name="StatusIDNext">更改之后的状态标识</param>
 /// <param name="UnitID">门店标识</param>
 /// <param name="strError"></param>
 /// <returns></returns>
 public bool SetVipCardStatusChange(string VipCardID
                                    , int StatusIDNow
                                    , int StatusIDNext
                                    , string UnitID
                                    , out string strError
                                    )
 {
     try
     {
         #region
         if (VipCardID == null || VipCardID.Trim().Equals(""))
         {
             strError = "会员卡号标识不能为空.";
             return(false);
         }
         if (StatusIDNow == 0 || StatusIDNow.ToString().Trim().Equals(""))
         {
             strError = "当前状态标识不能为空.";
             return(false);
         }
         if (StatusIDNext == 0 || StatusIDNext.ToString().Trim().Equals(""))
         {
             strError = "更改之后的状态标识不能为空.";
             return(false);
         }
         #endregion
         #region 1.获取修改会员卡状态信息
         VipCardEntity vipCardInfo = new VipCardEntity();
         vipCardInfo.VipCardID       = VipCardID;
         vipCardInfo.VipCardStatusId = StatusIDNext;
         vipCardInfo.LastUpdateBy    = this.CurrentUserInfo.UserID;
         vipCardInfo.LastUpdateTime  = System.DateTime.Now;
         #endregion
         #region 2.设置状态变更记录
         VipCardStatusChangeLogEntity statusChangeInfo = new VipCardStatusChangeLogEntity();
         statusChangeInfo.LogID           = JIT.CPOS.BS.BLL.BaseService.NewGuidPub();
         statusChangeInfo.OldStatusID     = StatusIDNow;
         statusChangeInfo.VipCardStatusID = StatusIDNext;
         statusChangeInfo.VipCardID       = VipCardID;
         statusChangeInfo.CreateBy        = CurrentUserInfo.UserID;
         statusChangeInfo.LastUpdateBy    = this.CurrentUserInfo.UserID;
         statusChangeInfo.UnitID          = UnitID;
         #endregion
         return(_currentDAO.SetVipCardStatusChange(vipCardInfo, statusChangeInfo, out strError));
     }
     catch (Exception ex) {
         throw (ex);
     }
 }
Example #3
0
        /// <summary>
        /// 列表获取
        /// </summary>
        /// <param name="Page">分页页码。从0开始</param>
        /// <param name="PageSize">每页的数量。未指定时默认为15</param>
        /// <returns></returns>
        public List <VipCardStatusChangeLogEntity> GetList(VipCardStatusChangeLogEntity entity, int Page, int PageSize)
        {
            if (PageSize <= 0)
            {
                PageSize = 15;
            }

            List <VipCardStatusChangeLogEntity> list = new List <VipCardStatusChangeLogEntity>();

            DataSet ds = _currentDAO.GetList(entity, Page, PageSize);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                list = DataTableToObject.ConvertToList <VipCardStatusChangeLogEntity>(ds.Tables[0]);
            }

            return(list);
        }
Example #4
0
        protected override SetVipCardRD ProcessRequest(DTO.Base.APIRequest <SetVipCardRP> pRequest)
        {
            var rd   = new SetVipCardRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;

            #region 业务对象
            //会员卡
            var VipCardBLL = new VipCardBLL(loggingSessionInfo);
            //余额变动记录
            var VipCardBalanceChangeBLL = new VipCardBalanceChangeBLL(loggingSessionInfo);
            //卡状态变更记录
            var VipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(loggingSessionInfo);
            //卡关系
            var VipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);
            //图片
            var objectImagesBLL = new ObjectImagesBLL(loggingSessionInfo);
            //会员
            var VipBLL = new VipBLL(loggingSessionInfo);

            var vipCardTransLogBLL = new VipCardTransLogBLL(loggingSessionInfo); //丰收日交易记录对象示例化
            var unitBLL            = new TUnitBLL(loggingSessionInfo);           //门店业务对象
            //事务
            var pTran = VipCardBLL.GetTran();
            #endregion



            using (pTran.Connection)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(para.VipCardID) || para.OperationType <= 0)
                    {
                        throw new APIException("卡ID或者操作类型参数不合法!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_REQUEST_LACK_REQUEST_PARAMETER
                              };
                    }

                    //定位当前卡业务对象
                    VipCardEntity changeEntity = VipCardBLL.GetByID(para.VipCardID);

                    if (changeEntity == null)
                    {
                        throw new APIException("当前卡信息对象为NULL!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }
                    #region 返回卡ID
                    rd.VipCardID = changeEntity.VipCardID;
                    #endregion
                    changeEntity.RechargeTotalAmount = changeEntity.RechargeTotalAmount ?? 0;
                    changeEntity.BalanceAmount       = changeEntity.BalanceAmount ?? 0;
                    string  OldVipCardCode = changeEntity.VipCardCode ?? "";                       //原卡号
                    string  NewVipCardCode = "";                                                   //新卡号,获取新卡赋值
                    decimal OldMoney       = changeEntity.BalanceAmount.Value;                     //原卡当前余额
                    decimal NewMoney       = changeEntity.BalanceAmount.Value + para.BalanceMoney; //原卡当余额+调整金额

                    //原卡会员映射关系
                    VipCardVipMappingEntity OldVipCardVipMappingData = VipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                    {
                        VipCardID = para.VipCardID
                    }, null).FirstOrDefault();
                    if (OldVipCardVipMappingData == null)
                    {
                        throw new APIException("原卡会员关系映射对象为NULL!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }

                    //门店Entity
                    var UnitData = unitBLL.GetByID(loggingSessionInfo.CurrentUserRole.UnitId);
                    //会员
                    VipEntity VipData = VipBLL.GetByID(OldVipCardVipMappingData.VIPID);

                    #region 卡状态记录对象
                    VipCardStatusChangeLogEntity AddVCStatusEntity = new VipCardStatusChangeLogEntity();
                    AddVCStatusEntity.LogID       = System.Guid.NewGuid().ToString();
                    AddVCStatusEntity.VipCardID   = para.VipCardID;
                    AddVCStatusEntity.Reason      = para.ChangeReason;
                    AddVCStatusEntity.OldStatusID = changeEntity.VipCardStatusId;
                    AddVCStatusEntity.CustomerID  = loggingSessionInfo.ClientID;
                    AddVCStatusEntity.Remark      = para.Remark;
                    AddVCStatusEntity.UnitID      = loggingSessionInfo.CurrentUserRole.UnitId;
                    #endregion



                    #region 新卡
                    VipCardEntity NewChangeVipCardData = new VipCardEntity();
                    if (!string.IsNullOrWhiteSpace(para.NewCardCode))
                    {
                        //查询参数
                        List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                        };
                        if (!string.IsNullOrEmpty(para.NewCardCode))
                        {
                            complexCondition.Add(new DirectCondition("VipCardCode='" + para.NewCardCode + "' or VipCardISN='" + para.NewCardCode.ToString() + "' "));
                        }
                        //新卡对象
                        NewChangeVipCardData = VipCardBLL.Query(complexCondition.ToArray(), null).FirstOrDefault();
                        if (NewChangeVipCardData == null)
                        {
                            throw new APIException("新卡不存在!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  };
                        }
                        //新卡号赋值
                        NewVipCardCode = NewChangeVipCardData.VipCardCode ?? "";
                        //新卡数据赋值
                        NewChangeVipCardData.VipCardGradeID      = changeEntity.VipCardGradeID;
                        NewChangeVipCardData.BatchNo             = changeEntity.BatchNo;
                        NewChangeVipCardData.BeginDate           = changeEntity.BeginDate;
                        NewChangeVipCardData.EndDate             = changeEntity.EndDate;
                        NewChangeVipCardData.TotalAmount         = changeEntity.TotalAmount == null ? 0 : changeEntity.TotalAmount.Value;
                        NewChangeVipCardData.BalanceAmount       = changeEntity.BalanceAmount == null ? 0 : changeEntity.BalanceAmount.Value;
                        NewChangeVipCardData.BalancePoints       = changeEntity.BalancePoints == null ? 0 : changeEntity.BalancePoints.Value;
                        NewChangeVipCardData.BalanceBonus        = changeEntity.BalanceBonus == null ? 0 : changeEntity.BalanceBonus.Value;
                        NewChangeVipCardData.CumulativeBonus     = changeEntity.CumulativeBonus == null ? 0 : changeEntity.CumulativeBonus.Value;
                        NewChangeVipCardData.PurchaseTotalAmount = changeEntity.PurchaseTotalAmount == null ? 0 : changeEntity.PurchaseTotalAmount.Value;
                        NewChangeVipCardData.PurchaseTotalCount  = changeEntity.PurchaseTotalCount == null ? 0 : changeEntity.PurchaseTotalCount.Value;
                        NewChangeVipCardData.CheckCode           = changeEntity.CheckCode;
                        NewChangeVipCardData.SingleTransLimit    = changeEntity.SingleTransLimit == null ? 0 : changeEntity.SingleTransLimit.Value;
                        NewChangeVipCardData.IsOverrunValid      = changeEntity.IsOverrunValid == null ? 0 : changeEntity.IsOverrunValid.Value;
                        NewChangeVipCardData.RechargeTotalAmount = changeEntity.RechargeTotalAmount == null ? 0 : changeEntity.RechargeTotalAmount.Value;
                        NewChangeVipCardData.LastSalesTime       = changeEntity.LastSalesTime;
                        NewChangeVipCardData.IsGift         = changeEntity.IsGift == null ? 0 : changeEntity.IsGift.Value;
                        NewChangeVipCardData.SalesAmount    = changeEntity.SalesAmount;
                        NewChangeVipCardData.SalesUserId    = changeEntity.SalesUserId;
                        NewChangeVipCardData.CustomerID     = changeEntity.CustomerID;
                        NewChangeVipCardData.MembershipTime = changeEntity.MembershipTime;
                        NewChangeVipCardData.SalesUserName  = changeEntity.SalesUserName == null ? "" : changeEntity.SalesUserName;
                        NewChangeVipCardData.CreateBy       = changeEntity.CreateBy;
                    }
                    #endregion


                    switch (para.OperationType)
                    {
                    case 1:
                        #region 调整卡余额
                        //卡更新

                        //卡内总金额
                        if (para.BalanceMoney > 0)
                        {
                            changeEntity.RechargeTotalAmount += para.BalanceMoney;
                            if (changeEntity.RechargeTotalAmount < 0)
                            {
                                throw new APIException("调整后的余额小于0!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      };
                            }
                        }
                        //changeEntity.BalanceAmount = changeEntity.BalanceAmount ?? 0;
                        //
                        changeEntity.BalanceAmount = NewMoney;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);

                        //新增余额变动记录
                        VipCardBalanceChangeEntity AddEntity = new VipCardBalanceChangeEntity();
                        AddEntity.ChangeID     = System.Guid.NewGuid().ToString();
                        AddEntity.VipCardCode  = changeEntity.VipCardCode;
                        AddEntity.ChangeAmount = para.BalanceMoney;
                        //变动前卡内余额
                        AddEntity.ChangeBeforeBalance = OldMoney;
                        //变动后卡内余额
                        AddEntity.ChangeAfterBalance = NewMoney;
                        AddEntity.ChangeReason       = para.ChangeReason;
                        AddEntity.Status             = 1;
                        AddEntity.Remark             = para.Remark;
                        AddEntity.CustomerID         = loggingSessionInfo.ClientID;
                        AddEntity.UnitID             = loggingSessionInfo.CurrentUserRole.UnitId;
                        //执行新增
                        VipCardBalanceChangeBLL.Create(AddEntity, pTran);

                        //增加图片上传
                        if (!string.IsNullOrEmpty(para.ImageUrl))
                        {
                            var objectImagesEntity = new ObjectImagesEntity()
                            {
                                ImageId  = Guid.NewGuid().ToString(),
                                ObjectId = AddEntity.ChangeID,
                                ImageURL = para.ImageUrl
                            };
                            objectImagesBLL.Create(objectImagesEntity, pTran);
                        }
                        #region 充值记录
                        //读取最近一次积分变更记录
                        List <OrderBy> lstOrder = new List <OrderBy> {
                        };                                                   //排序参数
                        lstOrder.Add(new OrderBy()
                        {
                            FieldName = "TransTime", Direction = OrderByDirections.Desc
                        });
                        var transLogInfo = vipCardTransLogBLL.QueryByEntity(new VipCardTransLogEntity()
                        {
                            VipCardCode = changeEntity.VipCardCode, TransType = "C"
                        }, lstOrder.ToArray()).FirstOrDefault();
                        //期末积分
                        int newValue = transLogInfo != null ? (transLogInfo.NewValue ?? 0) : 0;
                        var vipCardTransLogEntity = new VipCardTransLogEntity()
                        {
                            VipCardCode  = VipData == null ? "" : VipData.VipCode,
                            UnitCode     = UnitData == null ? "" : UnitData.UnitCode,
                            TransContent = "余额",
                            TransType    = "C",
                            TransTime    = DateTime.Now,
                            TransAmount  = para.BalanceMoney,
                            LastValue    = newValue,                                      //期初金额
                            NewValue     = Convert.ToInt32(para.BalanceMoney) + newValue, //期末金额
                            CustomerID   = loggingSessionInfo.ClientID
                        };
                        vipCardTransLogBLL.Create(vipCardTransLogEntity, pTran);

                        #endregion


                        #endregion
                        break;

                    case 2:
                        #region 卡升级

                        //卡类型升级
                        if (para.VipCardTypeId != 0)
                        {
                            VipCardVipMappingBLL.updateVipCardByType(VipData.VIPID, para.VipCardTypeId, para.ChangeReason, para.Remark, VipData.VipCode, pTran);
                        }
                        //卡号升级
                        else
                        {
                            #region 原卡

                            #region 更新原卡
                            changeEntity.VipCardStatusId = 3;
                            //当前月,累计金额清0
                            //changeEntity.BalanceAmount = 0;
                            //changeEntity.TotalAmount = 0;
                            VipCardBLL.Update(changeEntity, pTran);    //执行
                            #endregion

                            #region 新增原卡状态记录
                            AddVCStatusEntity.VipCardStatusID = 3;
                            AddVCStatusEntity.Action          = "卡升级";
                            AddVCStatusEntity.Remark         += "已升级为:" + NewChangeVipCardData.VipCardCode;
                            VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);    //执行
                            #endregion

                            #region 新增原卡余额变动记录
                            //if (OldMoney > 0)
                            //{
                            //    VipCardBalanceChangeEntity AddOldCardBalanceData = new VipCardBalanceChangeEntity();
                            //    AddOldCardBalanceData.ChangeID = System.Guid.NewGuid().ToString();
                            //    AddOldCardBalanceData.VipCardCode = changeEntity.VipCardCode;
                            //    AddOldCardBalanceData.ChangeAmount = -OldMoney;
                            //    //变动前卡内余额
                            //    AddOldCardBalanceData.ChangeBeforeBalance = OldMoney;
                            //    //变动后卡内余额
                            //    AddOldCardBalanceData.ChangeAfterBalance = 0;
                            //    AddOldCardBalanceData.ChangeReason = para.ChangeReason;
                            //    AddOldCardBalanceData.Status = 1;
                            //    AddOldCardBalanceData.Remark = para.Remark;
                            //    AddOldCardBalanceData.CustomerID = loggingSessionInfo.ClientID;
                            //    AddOldCardBalanceData.UnitID = loggingSessionInfo.CurrentUserRole.UnitId;
                            //    VipCardBalanceChangeBLL.Create(AddOldCardBalanceData, pTran);//执行
                            //    //增加图片上传
                            //    if (!string.IsNullOrEmpty(para.ImageUrl))
                            //    {
                            //        var objectImagesEntity = new ObjectImagesEntity()
                            //        {
                            //            ImageId = Guid.NewGuid().ToString(),
                            //            ObjectId = AddOldCardBalanceData.ChangeID,
                            //            ImageURL = para.ImageUrl
                            //        };
                            //        objectImagesBLL.Create(objectImagesEntity, pTran);
                            //    }
                            //}
                            #endregion

                            #endregion

                            #region 新卡

                            VipData.VipCode = para.NewCardCode;
                            VipBLL.Update(VipData, pTran);

                            #region 更新新卡
                            if (!string.IsNullOrEmpty(NewChangeVipCardData.MembershipUnit))
                            {
                                throw new APIException("该会员卡已绑定会员!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      }
                            }
                            ;
                            if (NewChangeVipCardData.VipCardStatusId != 0)
                            {
                                throw new APIException("该会员卡已激活!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      }
                            }
                            ;
                            if (NewChangeVipCardData.VipCardTypeID.Value == changeEntity.VipCardTypeID.Value)
                            {
                                throw new APIException("该卡号与原卡等级相同,请更换卡号后重新尝试!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      }
                            }
                            ;

                            #region 返回新卡卡ID
                            rd.VipCardID = NewChangeVipCardData.VipCardID;
                            #endregion
                            NewChangeVipCardData.MembershipUnit  = changeEntity.MembershipUnit;
                            NewChangeVipCardData.VipCardStatusId = 1;
                            VipCardBLL.Update(NewChangeVipCardData, pTran);    //执行
                            #endregion

                            #region 新增新卡卡关系
                            VipCardVipMappingEntity AddVipCardVipMappingData = new VipCardVipMappingEntity();
                            AddVipCardVipMappingData.MappingID  = System.Guid.NewGuid().ToString();
                            AddVipCardVipMappingData.VIPID      = OldVipCardVipMappingData.VIPID;
                            AddVipCardVipMappingData.VipCardID  = NewChangeVipCardData.VipCardID;
                            AddVipCardVipMappingData.CustomerID = loggingSessionInfo.ClientID;
                            VipCardVipMappingBLL.Create(AddVipCardVipMappingData, pTran);    //执行
                            #endregion

                            #region 更新会员编号
                            //VipEntity SJ_VipData = VipBLL.GetByID(OldVipCardVipMappingData.VIPID);
                            //if (VipData == null)
                            //    throw new APIException("会员不存在!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS };

                            //VipData.VipCode = NewChangeVipCardData.VipCardCode;
                            //VipBLL.Update(VipData, pTran);//执行
                            #endregion

                            #region 新增新卡状态记录
                            //新增新卡状态记录

                            VipCardStatusChangeLogEntity AddNewVCStatusEntity = new VipCardStatusChangeLogEntity();
                            AddNewVCStatusEntity.LogID           = System.Guid.NewGuid().ToString();
                            AddNewVCStatusEntity.VipCardID       = NewChangeVipCardData.VipCardID;
                            AddNewVCStatusEntity.VipCardStatusID = 1;
                            AddNewVCStatusEntity.Reason          = para.ChangeReason;
                            AddNewVCStatusEntity.OldStatusID     = 0;
                            AddNewVCStatusEntity.CustomerID      = loggingSessionInfo.ClientID;
                            AddNewVCStatusEntity.Action          = "卡升级";
                            AddNewVCStatusEntity.Remark          = para.Remark + "由旧卡:" + changeEntity.VipCardCode + "升级";
                            AddNewVCStatusEntity.UnitID          = loggingSessionInfo.CurrentUserRole.UnitId;
                            VipCardStatusChangeLogBLL.Create(AddNewVCStatusEntity, pTran);    //执行

                            #endregion

                            #region 新增新卡余额记录
                            //新增余额记录
                            //if (OldMoney > 0)
                            //{
                            //    VipCardBalanceChangeEntity AddNewCardBalanceData = new VipCardBalanceChangeEntity();
                            //    AddNewCardBalanceData.ChangeID = System.Guid.NewGuid().ToString();
                            //    AddNewCardBalanceData.VipCardCode = NewChangeVipCardData.VipCardCode;
                            //    AddNewCardBalanceData.ChangeAmount = OldMoney;
                            //    //变动前卡内余额
                            //    AddNewCardBalanceData.ChangeBeforeBalance = 0;
                            //    //变动后卡内余额
                            //    AddNewCardBalanceData.ChangeAfterBalance = NewChangeVipCardData.BalanceAmount == null ? 0 : NewChangeVipCardData.BalanceAmount.Value;
                            //    AddNewCardBalanceData.ChangeReason = para.ChangeReason;
                            //    AddNewCardBalanceData.Status = 1;
                            //    AddNewCardBalanceData.Remark = para.Remark;
                            //    AddNewCardBalanceData.CustomerID = loggingSessionInfo.ClientID;
                            //    VipCardBalanceChangeBLL.Create(AddNewCardBalanceData, pTran);//执行
                            //    //增加图片上传
                            //    if (!string.IsNullOrEmpty(para.ImageUrl))
                            //    {
                            //        var objectImagesEntity = new ObjectImagesEntity()
                            //        {
                            //            ImageId = Guid.NewGuid().ToString(),
                            //            ObjectId = AddNewCardBalanceData.ChangeID,
                            //            ImageURL = para.ImageUrl
                            //        };
                            //        objectImagesBLL.Create(objectImagesEntity, pTran);
                            //    }
                            //}
                            #endregion

                            #endregion
                        }
                        #endregion

                        break;

                    case 3:
                        #region 挂失
                        changeEntity.VipCardStatusId = 4;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行
                        AddVCStatusEntity.VipCardStatusID = 4;
                        AddVCStatusEntity.PicUrl          = para.ImageUrl;
                        AddVCStatusEntity.Action          = "挂失";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion

                        break;

                    case 4:

                        #region 冻结
                        changeEntity.VipCardStatusId = 2;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 2;
                        AddVCStatusEntity.Action          = "冻结";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 5:
                        #region 转卡
                        #region 原卡
                        #region 更新原卡
                        changeEntity.VipCardStatusId = 3;
                        //当前月,累计金额清0
                        changeEntity.BalanceAmount = 0;
                        changeEntity.TotalAmount   = 0;
                        VipCardBLL.Update(changeEntity, pTran);    //执行
                        #endregion

                        #region 新增原卡状态记录
                        AddVCStatusEntity.VipCardStatusID = 3;
                        AddVCStatusEntity.Action          = "转卡";
                        AddVCStatusEntity.Remark         += "已转移为:" + NewChangeVipCardData.VipCardCode;
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);    //执行
                        #endregion


                        #region 新增原卡余额变动记录
                        if (OldMoney > 0)
                        {
                            VipCardBalanceChangeEntity AddOldZKCardBalanceData = new VipCardBalanceChangeEntity();
                            AddOldZKCardBalanceData.ChangeID     = System.Guid.NewGuid().ToString();
                            AddOldZKCardBalanceData.VipCardCode  = changeEntity.VipCardCode;
                            AddOldZKCardBalanceData.ChangeAmount = -OldMoney;
                            //变动前卡内余额
                            AddOldZKCardBalanceData.ChangeBeforeBalance = OldMoney;
                            //变动后卡内余额
                            AddOldZKCardBalanceData.ChangeAfterBalance = 0;
                            AddOldZKCardBalanceData.ChangeReason       = para.ChangeReason;
                            AddOldZKCardBalanceData.Status             = 1;
                            AddOldZKCardBalanceData.Remark             = para.Remark;
                            AddOldZKCardBalanceData.CustomerID         = loggingSessionInfo.ClientID;
                            AddOldZKCardBalanceData.UnitID             = loggingSessionInfo.CurrentUserRole.UnitId;
                            VipCardBalanceChangeBLL.Create(AddOldZKCardBalanceData, pTran);     //执行
                            //增加图片上传
                            if (!string.IsNullOrEmpty(para.ImageUrl))
                            {
                                var objectImagesEntity = new ObjectImagesEntity()
                                {
                                    ImageId  = Guid.NewGuid().ToString(),
                                    ObjectId = AddOldZKCardBalanceData.ChangeID,
                                    ImageURL = para.ImageUrl
                                };
                                objectImagesBLL.Create(objectImagesEntity, pTran);
                            }
                        }
                        #endregion

                        #endregion
                        #region 新卡

                        #region 更新新卡
                        if (!string.IsNullOrEmpty(NewChangeVipCardData.MembershipUnit))
                        {
                            throw new APIException("该会员卡已绑定会员!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        if (NewChangeVipCardData.VipCardStatusId != 0)
                        {
                            throw new APIException("该会员卡已激活!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        if (NewChangeVipCardData.VipCardTypeID.Value != changeEntity.VipCardTypeID.Value)
                        {
                            throw new APIException("该卡号与原卡等级不同,请更换卡号后重新尝试!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;

                        #region 返回新卡卡ID
                        rd.VipCardID = NewChangeVipCardData.VipCardID;
                        #endregion
                        NewChangeVipCardData.MembershipUnit  = changeEntity.MembershipUnit;
                        NewChangeVipCardData.VipCardStatusId = 1;
                        VipCardBLL.Update(NewChangeVipCardData, pTran);    //执行
                        #endregion



                        #region 新增新卡卡关系
                        VipCardVipMappingEntity AddZKVipCardVipMappingData = new VipCardVipMappingEntity();
                        AddZKVipCardVipMappingData.MappingID  = System.Guid.NewGuid().ToString();
                        AddZKVipCardVipMappingData.VIPID      = OldVipCardVipMappingData.VIPID;
                        AddZKVipCardVipMappingData.VipCardID  = NewChangeVipCardData.VipCardID;
                        AddZKVipCardVipMappingData.CustomerID = loggingSessionInfo.ClientID;
                        VipCardVipMappingBLL.Create(AddZKVipCardVipMappingData, pTran);    //执行
                        #endregion

                        #region 更新会员编号
                        //VipEntity ZK_VipData = VipBLL.GetByID(OldVipCardVipMappingData.VIPID);
                        if (VipData == null)
                        {
                            throw new APIException("会员不存在!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;

                        VipData.VipCode = NewChangeVipCardData.VipCardCode;
                        VipBLL.Update(VipData, pTran);    //执行
                        #endregion

                        #region 新增新卡状态记录
                        VipCardStatusChangeLogEntity AddNewZKVCStatusEntity = new VipCardStatusChangeLogEntity();
                        AddNewZKVCStatusEntity.LogID           = System.Guid.NewGuid().ToString();
                        AddNewZKVCStatusEntity.VipCardID       = NewChangeVipCardData.VipCardID;
                        AddNewZKVCStatusEntity.VipCardStatusID = 1;
                        AddNewZKVCStatusEntity.Reason          = para.ChangeReason;
                        AddNewZKVCStatusEntity.OldStatusID     = 0;
                        AddNewZKVCStatusEntity.CustomerID      = loggingSessionInfo.ClientID;
                        AddNewZKVCStatusEntity.Action          = "转卡";
                        AddNewZKVCStatusEntity.Remark          = para.Remark + para.Remark + "由旧卡:" + changeEntity.VipCardCode + "转移";
                        AddNewZKVCStatusEntity.UnitID          = loggingSessionInfo.CurrentUserRole.UnitId;
                        VipCardStatusChangeLogBLL.Create(AddNewZKVCStatusEntity, pTran);    //执行
                        #endregion

                        #region 新增新卡余额记录
                        if (OldMoney > 0)
                        {
                            VipCardBalanceChangeEntity AddNewZKCardBalanceData = new VipCardBalanceChangeEntity();
                            AddNewZKCardBalanceData.ChangeID     = System.Guid.NewGuid().ToString();
                            AddNewZKCardBalanceData.VipCardCode  = NewChangeVipCardData.VipCardCode;
                            AddNewZKCardBalanceData.ChangeAmount = OldMoney;
                            //变动前卡内余额
                            AddNewZKCardBalanceData.ChangeBeforeBalance = 0;
                            //变动后卡内余额
                            AddNewZKCardBalanceData.ChangeAfterBalance = NewChangeVipCardData.BalanceAmount == null ? 0 : NewChangeVipCardData.BalanceAmount.Value;
                            AddNewZKCardBalanceData.ChangeReason       = para.ChangeReason;
                            AddNewZKCardBalanceData.Status             = 1;
                            AddNewZKCardBalanceData.Remark             = para.Remark;
                            AddNewZKCardBalanceData.CustomerID         = loggingSessionInfo.ClientID;
                            AddNewZKCardBalanceData.UnitID             = loggingSessionInfo.CurrentUserRole.UnitId;
                            VipCardBalanceChangeBLL.Create(AddNewZKCardBalanceData, pTran);    //执行
                            //增加图片上传
                            if (!string.IsNullOrEmpty(para.ImageUrl))
                            {
                                var objectImagesEntity = new ObjectImagesEntity()
                                {
                                    ImageId  = Guid.NewGuid().ToString(),
                                    ObjectId = AddNewZKCardBalanceData.ChangeID,
                                    ImageURL = para.ImageUrl
                                };
                                objectImagesBLL.Create(objectImagesEntity, pTran);
                            }
                        }
                        #endregion



                        #endregion
                        #endregion
                        break;

                    case 6:

                        #region 解挂
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "解挂";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 7:

                        #region 解冻
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "解冻";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 8:
                        #region 作废
                        changeEntity.VipCardStatusId = 3;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);


                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 3;
                        AddVCStatusEntity.Action          = "作废";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 9:
                        #region 唤醒
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "唤醒";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 10:
                        #region 激活
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "激活";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    default:
                        throw new APIException("当前操作类型不匹配!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_REQUEST_LACK_REQUEST_PARAMETER
                              };
                        break;
                    }
                    ;
                    pTran.Commit();
                    #region 卡升级,转卡操作转移消费记录表
                    if ((para.OperationType == 2 || para.OperationType == 5) && string.IsNullOrEmpty(para.VipCardTypeId.ToString())) //卡类型升级不执行此操作
                    {
                        string StrSql = string.Format("update VipCardTransLog set VipCardCode='{0}',OldVipCardCode='{1}' where VipCardCode='{1}'", NewVipCardCode, OldVipCardCode);
                        vipCardTransLogBLL.UpdateVipCardTransLog(StrSql);//执行
                    }
                    #endregion

                    var eventService = new EventService();
                    var vipMsg       = new EventContract
                    {
                        Operation  = OptEnum.Update,
                        EntityType = EntityTypeEnum.Vip,
                        Id         = VipData.VIPID
                    };
                    eventService.PublishMsg(vipMsg);
                }
                catch (APIException apiEx)
                {
                    pTran.Rollback();//回滚事物
                    throw new APIException(apiEx.ErrorCode, apiEx.Message);
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事务
                    throw new APIException(ex.Message);
                }
            }
            return(rd);
        }
        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);
        }
Example #8
0
        protected override SetVipCardRD ProcessRequest(DTO.Base.APIRequest <OpenVipCardRP> pRequest)
        {
            var rd   = new SetVipCardRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo        = new SessionManager().CurrentUserLoginInfo;         //登录状态信息
            var vipBLL                    = new VipBLL(loggingSessionInfo);                    //会员业务对象实例化
            var vipTagsMappingBLL         = new VipTagsMappingBLL(loggingSessionInfo);         //会员和标签关系业务对象实例化
            var vipCardBLL                = new VipCardBLL(loggingSessionInfo);                //会员卡业务对象实例化
            var vipCardVipMappingBLL      = new VipCardVipMappingBLL(loggingSessionInfo);      //会员和会员卡关系业务对象实例化
            var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(loggingSessionInfo); //会员卡状态变更业务对象实例化
            var vipAddressBLL             = new VipAddressBLL(loggingSessionInfo);             //会员地址信息业务对象实例化
            var pTran = vipCardBLL.GetTran();                                                  //事务

            using (pTran.Connection)
            {
                try
                {
                    //创建会员信息
                    var vipEntity = new VipEntity()
                    {
                        VIPID       = Guid.NewGuid().ToString().Replace("-", ""),
                        VipName     = para.VipName,
                        VipRealName = para.VipName,
                        //VipCode = "Vip" + vipBLL.GetNewVipCode(loggingSessionInfo.ClientID), //获取会员编号
                        VipCode         = para.VipCardCode,                                  //会员卡号
                        CouponInfo      = loggingSessionInfo.CurrentUserRole.UnitId,         //原会集店字段
                        MembershipStore = loggingSessionInfo.CurrentUserRole.UnitId,         //新增的会集店字段
                        Phone           = para.Phone,
                        Birthday        = para.Birthday,
                        Gender          = para.Gender,
                        Email           = para.Email,
                        Col18           = para.IDCard, //身份证
                        Status          = 2,           //已注册状态
                        VipSourceId     = "20",        //来源开卡
                        ClientID        = loggingSessionInfo.ClientID
                    };
                    vipBLL.Create(vipEntity, pTran);
                    //保存年龄段标签
                    var vipTagsMappingEntity = new VipTagsMappingEntity()
                    {
                        MappingId = Guid.NewGuid().ToString().Replace("-", ""),
                        VipId     = vipEntity.VIPID,
                        TagsId    = para.TagsID
                    };
                    vipTagsMappingBLL.Create(vipTagsMappingEntity, pTran);

                    //保存会员地址信息
                    //var vipAddressEntity = new VipAddressEntity()
                    //{
                    //    VIPID = vipEntity.VIPID,
                    //    LinkMan = para.VipName,
                    //    LinkTel = para.Phone,
                    //    CityID = para.CityID,
                    //    Address = para.Address,
                    //    IsDefault = 1
                    //};
                    //vipAddressBLL.Create(vipAddressEntity, pTran);

                    //更新会员卡信息
                    var vipCardEntity = vipCardBLL.GetByID(para.VipCardID);
                    if (vipCardEntity != null)
                    {
                        #region 返回卡ID
                        rd.VipCardID = vipCardEntity.VipCardID;
                        #endregion
                        //vipCardEntity.VipCardStatusId = 1;
                        if (!string.IsNullOrEmpty(vipCardEntity.MembershipUnit))
                        {
                            throw new APIException("此会员卡已绑定会员")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        if (vipCardEntity.VipCardStatusId > 0)
                        {
                            throw new APIException("此会员卡状态异常")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        vipCardEntity.MembershipTime = DateTime.Now;
                        vipCardEntity.MembershipUnit = loggingSessionInfo.CurrentUserRole.UnitId;
                        vipCardEntity.IsGift         = para.IsGift;
                        //vipCardEntity.SalesUserId = para.SalesUserId;
                        vipCardEntity.SalesUserName = para.SalesUserName;        //用户输入名称,后期需要根据姓名查找用户ID,更新到SalesUserId
                        vipCardEntity.CreateBy      = loggingSessionInfo.UserID; //开卡人,即入会员工
                        vipCardBLL.Update(vipCardEntity, pTran);
                    }
                    else
                    {
                        throw new APIException("查不到此会员卡")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              }
                    };

                    //新增会员卡操作状态信息
                    var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
                    {
                        LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                        VipCardStatusID = vipCardEntity.VipCardStatusId,
                        VipCardID       = para.VipCardID,
                        Action          = "开卡",
                        //Reason = "",
                        UnitID     = loggingSessionInfo.CurrentUserRole.UnitId,
                        CustomerID = loggingSessionInfo.ClientID
                    };
                    vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity, pTran);

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

                    pTran.Commit();  //提交事物
                }
                catch (APIException apiEx)
                {
                    pTran.Rollback();//回滚事物
                    throw new APIException(apiEx.ErrorCode, apiEx.Message);
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事物
                    throw new Exception(ex.Message);
                }
            }
            return(rd);
        }
Example #9
0
 /// <summary>
 /// 列表数量获取
 /// </summary>
 public int GetListCount(VipCardStatusChangeLogEntity entity)
 {
     return(_currentDAO.GetListCount(entity));
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(VipCardStatusChangeLogEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(VipCardStatusChangeLogEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <VipCardStatusChangeLogEntity> PagedQueryByEntity(VipCardStatusChangeLogEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public VipCardStatusChangeLogEntity[] QueryByEntity(VipCardStatusChangeLogEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(VipCardStatusChangeLogEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }