/// <summary>
        /// 计算充值分润
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="rechargeOrderInfo"></param>
        public void CalculateRechargeOrder(LoggingSessionInfo loggingSessionInfo, RechargeOrderEntity rechargeOrderInfo)
        {
            VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);

            VipCardProfitRuleEntity[] entityVipCardProfitRule = null;

            entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
            {
                VipCardTypeID = rechargeOrderInfo.VipCardTypeId, IsDelete = 0
            }, null);
            if (entityVipCardProfitRule != null)
            {
                var                bllVipCardGradeChangeLog = new VipCardGradeChangeLogBLL(loggingSessionInfo);
                VipAmountBLL       bllVipAmount             = new VipAmountBLL(loggingSessionInfo);
                VipAmountDetailBLL bllVipAmountDetail       = new VipAmountDetailBLL(loggingSessionInfo);
                VipAmountEntity    entityVipAmount          = new VipAmountEntity();

                string connString = string.Empty;
                foreach (var ProfitRule in entityVipCardProfitRule)
                {
                    decimal amount            = 0;
                    string  strAmountSourceId = string.Empty;
                    string  strVipId          = string.Empty;
                    string  strUserType       = string.Empty;
                    if (ProfitRule.IsApplyAllUnits == 0)
                    {
                        VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                        var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                        {
                            CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = rechargeOrderInfo.UnitId, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                        }, null).SingleOrDefault();
                        if (vipCardProfitRuleUnitMapping == null)
                        {
                            continue;
                        }
                    }
                    if (ProfitRule.ProfitOwner == "Employee")
                    {
                        strAmountSourceId = "38";
                        strVipId          = rechargeOrderInfo.UserId;
                        strUserType       = "User";
                    }
                    if (ProfitRule.ProfitOwner == "Unit")
                    {
                        strAmountSourceId = "42";
                        strVipId          = rechargeOrderInfo.UnitId;
                        strUserType       = "Unit";
                    }
                    var entityVipCardGradeChangeLog = bllVipCardGradeChangeLog.QueryByEntity(new VipCardGradeChangeLogEntity()
                    {
                        OrderId = rechargeOrderInfo.OrderID.ToString()
                    }, null).SingleOrDefault();
                    if (entityVipCardGradeChangeLog != null)//首充
                    {
                        amount = (decimal)ProfitRule.FirstRechargeProfitPct * (decimal)rechargeOrderInfo.ActuallyPaid * (decimal)0.01;
                    }
                    else//续充
                    {
                        VipCardReRechargeProfitRuleBLL bllVipCardReRechargeProfitRule = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);
                        var entityVipCardReRechargeProfitRule = bllVipCardReRechargeProfitRule.QueryByEntity(new VipCardReRechargeProfitRuleEntity()
                        {
                            VipCardTypeID = rechargeOrderInfo.VipCardTypeId, IsDelete = 0
                        }, null);
                        if (entityVipCardReRechargeProfitRule != null)
                        {
                            decimal discount = 0;
                            foreach (var ReRechargeProfitRule in entityVipCardReRechargeProfitRule)
                            {
                                if (ReRechargeProfitRule.ProfitType == "Superposition")
                                {
                                    discount = ((decimal)rechargeOrderInfo.ActuallyPaid / (decimal)ReRechargeProfitRule.LimitAmount) * (decimal)ReRechargeProfitRule.ProfitPct * (decimal)0.01;
                                }
                                if (ReRechargeProfitRule.ProfitType == "Step")
                                {
                                    if (rechargeOrderInfo.ActuallyPaid >= ReRechargeProfitRule.LimitAmount)
                                    {
                                        discount = (decimal)ReRechargeProfitRule.ProfitPct;
                                    }
                                }
                            }
                            amount = (decimal)rechargeOrderInfo.ActuallyPaid * discount;
                        }
                    }
                    //入库
                    if (amount > 0)
                    {
                        IDbTransaction tran = new DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();

                        VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity
                        {
                            VipAmountDetailId = Guid.NewGuid(),
                            VipId             = strVipId,
                            Amount            = amount,
                            UsedReturnAmount  = 0,
                            EffectiveDate     = DateTime.Now,
                            DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                            AmountSourceId    = strAmountSourceId,
                            ObjectId          = rechargeOrderInfo.OrderID.ToString(),
                            CustomerID        = loggingSessionInfo.ClientID,
                            Reason            = "超级分销商"
                        };
                        bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                        T_SplitProfitRecordBLL    bllSplitProfitRecord    = new T_SplitProfitRecordBLL(loggingSessionInfo);
                        T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity()
                        {
                            ID          = Guid.NewGuid().ToString(),
                            SourceType  = "Amount",
                            SourceId    = strAmountSourceId,
                            ObjectId    = rechargeOrderInfo.OrderID.ToString(),
                            UserType    = strUserType,
                            UserId      = rechargeOrderInfo.UserId,
                            SplitAmount = amount,
                            SplitSattus = "10",
                            CustomerID  = loggingSessionInfo.ClientID,
                            IsDelete    = 0
                        };
                        bllSplitProfitRecord.Create(entitySplitProfitRecord);

                        entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                        {
                            VipId = strVipId, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                        }, null).SingleOrDefault();
                        if (entityVipAmount == null)
                        {
                            entityVipAmount = new VipAmountEntity
                            {
                                VipId                  = strVipId,
                                BeginAmount            = 0,
                                InAmount               = amount,
                                OutAmount              = 0,
                                EndAmount              = amount,
                                TotalAmount            = amount,
                                BeginReturnAmount      = 0,
                                InReturnAmount         = 0,
                                OutReturnAmount        = 0,
                                ReturnAmount           = 0,
                                ImminentInvalidRAmount = 0,
                                InvalidReturnAmount    = 0,
                                ValidReturnAmount      = 0,
                                TotalReturnAmount      = 0,
                                IsLocking              = 0,
                                CustomerID             = loggingSessionInfo.ClientID,
                                VipCardCode            = ""
                            };
                            bllVipAmount.Create(entityVipAmount, tran);
                        }
                        else
                        {
                            entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                            entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                            entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                            entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;
                            bllVipAmount.Update(entityVipAmount);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 处理门店和激励规则信息
        /// </summary>
        /// <param name="item"></param>
        /// <param name="CardBuyToProfitRuleId"></param>
        /// <param name="tran"></param>
        public void SetUnitAndProfitRule(CardBuyToProfitRuleInfoInfo item, Guid?CardBuyToProfitRuleId, LoggingSessionInfo loggingSessionInfo, IDbTransaction tran)
        {
            VipCardProfitRuleBLL            RuleService                 = new VipCardProfitRuleBLL(loggingSessionInfo);
            SysVipCardTypeBLL               SysCardTypeService          = new SysVipCardTypeBLL(loggingSessionInfo);
            VipCardProfitRuleUnitMappingBLL UnitMappService             = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
            VipCardReRechargeProfitRuleBLL  ReRechargeProfitRuleService = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);
            UnitBLL UnitService = new UnitBLL(loggingSessionInfo);

            #region 处理门店映射信息
            if (item.IsApplyAllUnits == 0) //部分门店 添加门店映射关系
            {
                if (item.RuleUnitInfoList != null)
                {
                    foreach (var unitInfo in item.RuleUnitInfoList) //门店集合列表
                    {
                        VipCardProfitRuleUnitMappingEntity UnitMappEntity = new VipCardProfitRuleUnitMappingEntity()
                        {
                            CardBuyToProfitRuleId = CardBuyToProfitRuleId,
                            CustomerID            = CurrentUserInfo.ClientID,
                            UnitID = unitInfo.UnitID
                        };
                        if (unitInfo.Id == null) //门店编号为空 既 添加门店
                        {
                            UnitMappService.Create(UnitMappEntity, tran);
                        }
                        else   //门店编号不为空  既 {修改门店| 删除门店 }
                        {
                            UnitMappEntity.CardBuyToProfitRuleId = item.CardBuyToProfitRuleId;
                            UnitMappEntity.Id       = unitInfo.Id;
                            UnitMappEntity.IsDelete = unitInfo.IsDelete;
                            UnitMappService.Update(UnitMappEntity, tran);
                        }
                    }
                }
            }
            else
            {
                //全部门店 默认将该规则下面的 门店删除
                UnitMappService.UpdateUnitMapping(item.CardBuyToProfitRuleId, tran);
            }
            #endregion

            #region 处理充值分润规则
            if (item.ProfitTypeInfoList != null)
            {
                foreach (var ProfitTypeInfo in item.ProfitTypeInfoList) //续费充值列表
                {
                    VipCardReRechargeProfitRuleEntity VipCardReRechargeProfitRuleInfo = new VipCardReRechargeProfitRuleEntity()
                    {
                        CardBuyToProfitRuleId = CardBuyToProfitRuleId,
                        CustomerID            = loggingSessionInfo.ClientID,
                        LimitAmount           = ProfitTypeInfo.LimitAmount,
                        ProfitPct             = ProfitTypeInfo.ProfitPct,
                        ProfitType            = ProfitTypeInfo.ProfitType,
                        VipCardTypeID         = item.VipCardTypeID
                    };

                    if (ProfitTypeInfo.ReRechargeProfitRuleId == null) //续费充值分润主键为空 --->添加续费充值分润方式
                    {
                        if (ProfitTypeInfo.LimitAmount > 0)            //防止 不可充值方式参数传递问题
                        {
                            ReRechargeProfitRuleService.Create(VipCardReRechargeProfitRuleInfo, tran);
                        }
                    }
                    else //----->修改续费充值分润方式
                    {
                        VipCardReRechargeProfitRuleInfo.ReRechargeProfitRuleId = ProfitTypeInfo.ReRechargeProfitRuleId;
                        VipCardReRechargeProfitRuleInfo.IsDelete = ProfitTypeInfo.IsDelete;
                        ReRechargeProfitRuleService.Update(VipCardReRechargeProfitRuleInfo, tran);
                    }
                }
            }
            #endregion
        }