/// <summary>
        /// 计算购卡分润
        /// </summary>
        public void CalculateSalesVipCardOrderJob()
        {
            var numCount = 50;

            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取vipcard订单数据失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }
                //DataTable dtAmountDetail = CreateTableAmountDetail();
                //DataTable dtAmount = CreateTableAmount();
                //DataTable dtSplitProfitRecord = CreateTableSplitProfitRecord();

                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var        orderInfo          = response.Result.OrderInfo.JsonDeserialize <T_InoutEntity>();
                        var        loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "RedisSystem");
                        T_InoutBLL inoutBLL           = new T_InoutBLL(loggingSessionInfo);
                        if (orderInfo != null)
                        {
                            VipBLL                      bllVip                    = new VipBLL(loggingSessionInfo);
                            T_Inout_DetailBLL           bllInoutDetail            = new T_Inout_DetailBLL(loggingSessionInfo);
                            T_VirtualItemTypeSettingBLL bllVirtualItemTypeSetting = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);
                            VipCardUpgradeRuleBLL       bllVipCardUpgradeRule     = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                            VipAmountBLL                bllVipAmount              = new VipAmountBLL(loggingSessionInfo);
                            VipAmountDetailBLL          bllVipAmountDetail        = new VipAmountDetailBLL(loggingSessionInfo);
                            T_SplitProfitRecordBLL      bllSplitProfitRecord      = new T_SplitProfitRecordBLL(loggingSessionInfo);

                            VipAmountEntity           entityVipAmount         = new VipAmountEntity();
                            VipAmountDetailEntity     entityVipAmountDetail   = new VipAmountDetailEntity();
                            T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity();

                            DataSet dsVipCardLevel    = bllVip.GetVipCardLevel(orderInfo.vip_no, loggingSessionInfo.ClientID);
                            var     entityInoutDetail = bllInoutDetail.QueryByEntity(new T_Inout_DetailEntity()
                            {
                                order_id = orderInfo.order_id
                            }, null).FirstOrDefault();
                            if (entityInoutDetail == null)
                            {
                                continue;
                            }
                            var vipCardType = bllVirtualItemTypeSetting.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                            {
                                SkuId = entityInoutDetail.sku_id, IsDelete = 0
                            }, null).FirstOrDefault();
                            if (vipCardType != null)
                            {
                                int intVipCardTypeID         = Convert.ToInt32(vipCardType.ObjecetTypeId);
                                var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                                {
                                    VipCardTypeID = intVipCardTypeID, IsPurchaseUpgrade = 1, IsDelete = 0
                                }, null).SingleOrDefault();
                                if (entityVipCardUpgradeRule != null)
                                {
                                    VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
                                    var entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                    {
                                        VipCardTypeID = intVipCardTypeID, IsDelete = 0
                                    }, null);
                                    foreach (var ProfitRule in entityVipCardProfitRule)
                                    {
                                        if (ProfitRule.IsApplyAllUnits == 0)
                                        {
                                            VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                                            var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                                            {
                                                CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = orderInfo.sales_unit_id, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                                            }, null).SingleOrDefault();
                                            if (vipCardProfitRuleUnitMapping == null)
                                            {
                                                continue;
                                            }
                                        }
                                        decimal amount            = 0;
                                        string  strAmountSourceId = string.Empty;
                                        string  strVipId          = string.Empty;
                                        string  strUserType       = string.Empty;
                                        if (ProfitRule.ProfitOwner == "Employee")
                                        {
                                            strAmountSourceId = "37";
                                            strVipId          = orderInfo.sales_user;
                                            strUserType       = "User";
                                        }
                                        if (ProfitRule.ProfitOwner == "Unit")
                                        {
                                            strAmountSourceId = "40";
                                            strVipId          = orderInfo.sales_unit_id;
                                            strUserType       = "Unit";
                                        }
                                        amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                        var vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity()
                                        {
                                            ObjectId = orderInfo.order_id, AmountSourceId = strAmountSourceId
                                        }, null);
                                        if (vipAmountDetail != null && vipAmountDetail.Length > 0)
                                        {
                                            continue;
                                        }
                                        if (amount > 0)
                                        {
                                            IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                            try {
                                                //                                 DataRow dr_SplitProfitRecord = dtSplitProfitRecord.NewRow();
                                                //                                 dr_SplitProfitRecord["Id"] = Guid.NewGuid();
                                                //                                 dr_SplitProfitRecord["SourceType"] = "Amount";
                                                //                                 dr_SplitProfitRecord["SourceId"] = strAmountSourceId;
                                                //                                 dr_SplitProfitRecord["ObjectId"] = orderInfo.order_id;
                                                //dr_SplitProfitRecord["UserType"] = strUserType;
                                                //                                 dr_SplitProfitRecord["UserId"] = orderInfo.sales_user;
                                                //                                 dr_SplitProfitRecord["SplitAmount"] = amount;
                                                //                                 dr_SplitProfitRecord["SplitSattus"] = "10";
                                                //                                 dr_SplitProfitRecord["CustomerId"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["CreateTime"] = DateTime.Now;
                                                //                                 dr_SplitProfitRecord["CreateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["LastUpdateTime"] = DateTime.Now;
                                                //                                 dr_SplitProfitRecord["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["IsDelete"] = 0;
                                                //                                 dtSplitProfitRecord.Rows.Add(dr_SplitProfitRecord);

                                                //                                 DataRow dr_AmountDetail = dtAmountDetail.NewRow();
                                                //                                 dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid();
                                                //dr_AmountDetail["VipId"] = strVipId;
                                                //                                 dr_AmountDetail["VipCardCode"] = "";
                                                //                                 dr_AmountDetail["UnitID"] = "";
                                                //                                 dr_AmountDetail["UnitName"] = "";
                                                //                                 dr_AmountDetail["SalesAmount"] = 0;
                                                //                                 dr_AmountDetail["Amount"] = amount;
                                                //                                 dr_AmountDetail["UsedReturnAmount"] = 0;
                                                //                                 dr_AmountDetail["Reason"] = "首次售卡分润";
                                                //                                 dr_AmountDetail["EffectiveDate"] = DateTime.Now;
                                                //                                 dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59");
                                                //                                 dr_AmountDetail["AmountSourceId"] = strAmountSourceId;
                                                //                                 dr_AmountDetail["ObjectId"] = orderInfo.order_id;
                                                //                                 dr_AmountDetail["Remark"] = "首次售卡分润";
                                                //                                 dr_AmountDetail["IsValid"] = 0;
                                                //                                 dr_AmountDetail["IsWithdrawCash"] = 0;
                                                //                                 dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["CreateTime"] = DateTime.Now;
                                                //                                 dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["LastUpdateTime"] = DateTime.Now;
                                                //                                 dr_AmountDetail["IsDelete"] = 0;
                                                //                                 //dr_AmountDetail["IsCalculated"] = 1;
                                                //                                 dtAmountDetail.Rows.Add(dr_AmountDetail);

                                                entitySplitProfitRecord = new T_SplitProfitRecordEntity()
                                                {
                                                    ID          = Guid.NewGuid().ToString(),
                                                    SourceType  = "Amount",
                                                    SourceId    = strAmountSourceId,
                                                    ObjectId    = orderInfo.order_id,
                                                    UserType    = strUserType,
                                                    UserId      = orderInfo.sales_user,
                                                    SplitAmount = amount,
                                                    SplitSattus = "10",
                                                    CustomerID  = loggingSessionInfo.ClientID
                                                };
                                                bllSplitProfitRecord.Create(entitySplitProfitRecord, tran);


                                                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          = orderInfo.order_id,
                                                    CustomerID        = loggingSessionInfo.ClientID,
                                                    Reason            = "首次售卡分润",
                                                    Remark            = "首次售卡分润",
                                                    IsWithdrawCash    = 0
                                                };
                                                bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                                                entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                                {
                                                    VipId = orderInfo.sales_user, IsDelete = 0
                                                }, null).SingleOrDefault();
                                                if (entityVipAmount == null)
                                                {
                                                    //DataRow dr_Amount = dtAmount.NewRow();
                                                    //dr_Amount["VipId"] = orderInfo.sales_user;
                                                    //dr_Amount["VipCardCode"] = "";
                                                    //dr_Amount["BeginAmount"] = 0;
                                                    //dr_Amount["InAmount"] = amount;
                                                    //dr_Amount["OutAmount"] = 0;
                                                    //dr_Amount["EndAmount"] = amount;
                                                    //dr_Amount["TotalAmount"] = amount;
                                                    //dr_Amount["BeginReturnAmount"] = 0;
                                                    //dr_Amount["InReturnAmount"] = 0;
                                                    //dr_Amount["OutReturnAmount"] = 0;
                                                    //dr_Amount["ReturnAmount"] = 0;
                                                    //dr_Amount["ImminentInvalidRAmount"] = 0;
                                                    //dr_Amount["InvalidReturnAmount"] = 0;
                                                    //dr_Amount["ValidReturnAmount"] = 0;
                                                    //dr_Amount["TotalReturnAmount"] = 0;
                                                    //dr_Amount["PayPassword"] = "";
                                                    //dr_Amount["IsLocking"] = 0;
                                                    //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["CreateTime"] = DateTime.Now;
                                                    //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["LastUpdateTime"] = DateTime.Now;
                                                    //dr_Amount["IsDelete"] = 0;
                                                    //dtAmount.Rows.Add(dr_Amount);
                                                    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);
                                                }
                                                tran.Commit();
                                            }
                                            catch (Exception) {
                                                tran.Rollback();
                                                throw;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //if (dtAmount.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtAmount, "VipAmount");
                //}
                //if (dtAmountDetail.Rows.Count > 0 && dtSplitProfitRecord.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtSplitProfitRecord, "T_SplitProfitRecord");
                //    Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail");

                //}
            }
        }
Example #2
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <UpdateVipCardTypeSystemRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo   = new SessionManager().CurrentUserLoginInfo;
            var entitySysVipCardType = new SysVipCardTypeEntity();
            var bllSysVipCardType    = new SysVipCardTypeBLL(loggingSessionInfo);
            //卡分润规则
            var bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
            //续费充值方式
            var VipCardReRechargeProfitRuleService = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);

            //编辑会员卡等级
            try
            {
                var SysVipCardTypeInfo = bllSysVipCardType.QueryByEntity(new SysVipCardTypeEntity()
                {
                    CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = para.VipCardTypeID, IsDelete = 0
                }, null).FirstOrDefault();
                switch (para.OperateType)
                {
                //如果为1编辑会员卡等级信息
                case 1:
                    if (SysVipCardTypeInfo != null)
                    {
                        //获取当前会员信息
                        List <IWhereCondition> wheres = new List <IWhereCondition>();
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "Category", Value = 0
                        });
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "CustomerID", Value = loggingSessionInfo.ClientID
                        });
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "VipCardTypeName", Value = para.VipCardTypeName
                        });
                        wheres.Add(new DirectCondition("VipCardLevel!='" + SysVipCardTypeInfo.VipCardLevel + "'"));
                        var ExistVipCardTypeResult = bllSysVipCardType.Query(wheres.ToArray(), null).FirstOrDefault();
                        if (ExistVipCardTypeResult != null)
                        {
                            throw new APIException("会员卡名称不能重复!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  };
                        }
                        SysVipCardTypeInfo.VipCardTypeID   = para.VipCardTypeID;
                        SysVipCardTypeInfo.Category        = 0;
                        SysVipCardTypeInfo.VipCardTypeName = para.VipCardTypeName;
                        SysVipCardTypeInfo.VipCardLevel    = SysVipCardTypeInfo.VipCardLevel;
                        SysVipCardTypeInfo.IsPassword      = SysVipCardTypeInfo.IsPassword;
                        if (SysVipCardTypeInfo.VipCardLevel == 1)    //如果等级为1默认可充值
                        {
                            SysVipCardTypeInfo.Isprepaid = 1;
                        }
                        else
                        {
                            SysVipCardTypeInfo.Isprepaid = para.IsPrepaid;
                        }
                        SysVipCardTypeInfo.IsOnlineSales = para.IsOnlineSales;
                        SysVipCardTypeInfo.PicUrl        = para.PicUrl;
                        SysVipCardTypeInfo.CustomerID    = loggingSessionInfo.ClientID;
                        if (SysVipCardTypeInfo.VipCardLevel == 1)
                        {
                            SysVipCardTypeInfo.Prices           = 0;
                            SysVipCardTypeInfo.ExchangeIntegral = 0;
                            SysVipCardTypeInfo.IsExtraMoney     = 2;
                        }
                    }
                    //如果IsOnlineSales为0则需要逻辑删除分润规则数据
                    if (SysVipCardTypeInfo.IsOnlineSales == 0)
                    {
                        var VipCardProfitRuleInfo = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                        {
                            VipCardTypeID = SysVipCardTypeInfo.VipCardTypeID, CustomerID = loggingSessionInfo.ClientID
                        }, null);
                        if (VipCardProfitRuleInfo.Length > 0)
                        {
                            bllVipCardProfitRule.Delete(VipCardProfitRuleInfo);
                        }
                    }

                    if (SysVipCardTypeInfo.Isprepaid == 0)     //不可充值
                    {
                        var VipCardUpgradeRuleService = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                        //升级规则信息 永远只有一条信息
                        var CardUpgradeRuleEntity = VipCardUpgradeRuleService.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            VipCardTypeID = SysVipCardTypeInfo.VipCardTypeID
                        }, null);
                        if (CardUpgradeRuleEntity != null && CardUpgradeRuleEntity.FirstOrDefault() != null) //如果有设置了升级条件
                        {
                            if (CardUpgradeRuleEntity.FirstOrDefault().IsBuyUpgrade == 1)                    //消费升级+不可充值==>逻辑删除 会员卡销售激励规则
                            {
                                var Ids = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                {
                                    CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = SysVipCardTypeInfo.VipCardTypeID
                                }, null).Select(m => m.CardBuyToProfitRuleId.Value.ToString()).ToArray();
                                if (Ids.Length > 0)
                                {
                                    bllVipCardProfitRule.Delete(Ids);
                                }
                            }
                        }

                        //将所有梯度信息 逻辑删除
                        string[] ProfitRuleIds = bllVipCardProfitRule.GetRechargeProfitRuleByIsPrepaid(loggingSessionInfo.ClientID, SysVipCardTypeInfo.VipCardTypeID);
                        if (ProfitRuleIds.Length > 0)
                        {
                            VipCardReRechargeProfitRuleService.Delete(ProfitRuleIds);
                        }
                    }
                    bllSysVipCardType.Update(SysVipCardTypeInfo);
                    //修改虚拟商品
#warning 商品代码注释 Bear
                    ItemService _ItemService = new ItemService(loggingSessionInfo);
                    _ItemService.SaveCardToOffenTItem(loggingSessionInfo, SysVipCardTypeInfo);
                    break;

                //如果为2编辑升级规则信息
                case 2:
                    var bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                    //升级类型不能为空 (1=购卡升级;2=充值升级;3=消费升级;)
                    if (para.UpGradeType != 0)
                    {
                        VipCardUpgradeRuleEntity vipCardUpgradeRuleEntity = new VipCardUpgradeRuleEntity();
                        if (para.OperateObjectID != null)
                        {
                            var VipCardUpgradeRuleInfo = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                            {
                                CustomerID = loggingSessionInfo.ClientID, VipCardUpgradeRuleId = new Guid(para.OperateObjectID), VipCardTypeID = para.VipCardTypeID
                            }, null).FirstOrDefault();
                            if (VipCardUpgradeRuleInfo != null)
                            {
                                //先置为0 再进行更新
                                SysVipCardTypeInfo.IsExtraMoney           = 2;
                                SysVipCardTypeInfo.Prices                 = 0;
                                SysVipCardTypeInfo.ExchangeIntegral       = 0;
                                VipCardUpgradeRuleInfo.OnceRechargeAmount = 0;
                                VipCardUpgradeRuleInfo.OnceBuyAmount      = 0;
                                VipCardUpgradeRuleInfo.BuyAmount          = 0;
                                switch (para.UpGradeType)
                                {
                                case 1:
                                    VipCardUpgradeRuleInfo.IsPurchaseUpgrade = 1;
                                    //金额和积分 与可补差价在卡等级表里面
                                    SysVipCardTypeInfo.VipCardTypeID    = para.VipCardTypeID;
                                    SysVipCardTypeInfo.IsExtraMoney     = para.IsExtraMoney;
                                    SysVipCardTypeInfo.Prices           = para.Prices;
                                    SysVipCardTypeInfo.ExchangeIntegral = para.ExchangeIntegral;
                                    //充值升级归零
                                    VipCardUpgradeRuleInfo.IsRecharge = 0;
                                    //消费升级置零
                                    VipCardUpgradeRuleInfo.IsBuyUpgrade = 0;
                                    break;

                                case 2:
                                    VipCardUpgradeRuleInfo.IsPurchaseUpgrade  = 0;
                                    VipCardUpgradeRuleInfo.IsRecharge         = 1;
                                    VipCardUpgradeRuleInfo.IsBuyUpgrade       = 0;
                                    VipCardUpgradeRuleInfo.OnceRechargeAmount = para.OnceRechargeAmount;
                                    break;

                                case 3:
                                    VipCardUpgradeRuleInfo.IsPurchaseUpgrade = 0;
                                    VipCardUpgradeRuleInfo.IsRecharge        = 0;
                                    VipCardUpgradeRuleInfo.IsBuyUpgrade      = 1;
                                    VipCardUpgradeRuleInfo.OnceBuyAmount     = para.OnceBuyAmount;
                                    VipCardUpgradeRuleInfo.BuyAmount         = para.BuyAmount;
                                    //如果该卡为不可充值 那么就默认删除
                                    var syscardentity = bllSysVipCardType.GetByID(para.VipCardTypeID);
                                    if (syscardentity != null && syscardentity.Isprepaid == 0)         //消费升级 {不可充值} 默认删除该卡的激励规则
                                    {
                                        var Ids = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                        {
                                            CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = para.VipCardTypeID
                                        }, null).Select(m => m.CardBuyToProfitRuleId.Value.ToString()).ToArray();
                                        if (Ids.Length > 0)
                                        {
                                            bllVipCardProfitRule.Delete(Ids);
                                        }
                                    }
                                    break;
                                }
                                //更新卡等级部分信息
                                bllSysVipCardType.Update(SysVipCardTypeInfo);
                                //修改虚拟商品
                                ItemService _ItemServices = new ItemService(loggingSessionInfo);
                                _ItemServices.SaveCardToOffenTItem(loggingSessionInfo, SysVipCardTypeInfo);
                                bllVipCardUpgradeRule.Update(VipCardUpgradeRuleInfo);
                            }
                        }
                        else
                        {
                            //先置为0 再进行更新
                            SysVipCardTypeInfo.IsExtraMoney             = 2;
                            SysVipCardTypeInfo.Prices                   = 0;
                            SysVipCardTypeInfo.ExchangeIntegral         = 0;
                            vipCardUpgradeRuleEntity.OnceRechargeAmount = 0;
                            vipCardUpgradeRuleEntity.OnceBuyAmount      = 0;
                            vipCardUpgradeRuleEntity.BuyAmount          = 0;
                            switch (para.UpGradeType)
                            {
                            case 1:
                                vipCardUpgradeRuleEntity.IsPurchaseUpgrade = 1;
                                vipCardUpgradeRuleEntity.VipCardTypeID     = para.VipCardTypeID;
                                //金额和积分 与可补差价在卡等级表里面
                                SysVipCardTypeInfo.VipCardTypeID    = para.VipCardTypeID;
                                SysVipCardTypeInfo.IsExtraMoney     = para.IsExtraMoney;
                                SysVipCardTypeInfo.Prices           = para.Prices;
                                SysVipCardTypeInfo.ExchangeIntegral = para.ExchangeIntegral;
                                //充值升级归零
                                vipCardUpgradeRuleEntity.IsRecharge = 0;
                                //消费升级置零
                                vipCardUpgradeRuleEntity.IsBuyUpgrade = 0;
                                break;

                            case 2:
                                vipCardUpgradeRuleEntity.IsPurchaseUpgrade  = 0;
                                vipCardUpgradeRuleEntity.IsRecharge         = 1;
                                vipCardUpgradeRuleEntity.IsBuyUpgrade       = 0;
                                vipCardUpgradeRuleEntity.OnceRechargeAmount = para.OnceRechargeAmount;
                                break;

                            case 3:          //消费升级
                                vipCardUpgradeRuleEntity.IsPurchaseUpgrade = 0;
                                vipCardUpgradeRuleEntity.IsRecharge        = 0;
                                vipCardUpgradeRuleEntity.IsBuyUpgrade      = 1;
                                vipCardUpgradeRuleEntity.OnceBuyAmount     = para.OnceBuyAmount;
                                vipCardUpgradeRuleEntity.BuyAmount         = para.BuyAmount;
                                break;
                            }
                            //更新卡等级部分信息
                            bllSysVipCardType.Update(SysVipCardTypeInfo);
                            //修改虚拟商品
                            ItemService _ItemServices = new ItemService(loggingSessionInfo);
                            _ItemServices.SaveCardToOffenTItem(loggingSessionInfo, SysVipCardTypeInfo);
                            //添加卡升级规则
                            vipCardUpgradeRuleEntity.VipCardUpgradeRuleId = Guid.NewGuid();
                            vipCardUpgradeRuleEntity.CustomerID           = loggingSessionInfo.ClientID;
                            bllVipCardUpgradeRule.Create(vipCardUpgradeRuleEntity);
                        }
                    }
                    else
                    {
                        throw new APIException("升级类型不能为空!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }

                    break;

                //如果为3编辑基本权益信息
                case 3:
                    var bllVipCardRule    = new VipCardRuleBLL(loggingSessionInfo);
                    var entityVipCardRule = new VipCardRuleEntity();
                    var VipCardRuleInfo   = bllVipCardRule.QueryByEntity(new VipCardRuleEntity()
                    {
                        CustomerID = loggingSessionInfo.ClientID, RuleID = Convert.ToInt32(para.OperateObjectID), VipCardTypeID = para.VipCardTypeID
                    }, null).FirstOrDefault();
                    if (VipCardRuleInfo != null)
                    {
                        entityVipCardRule.RuleID               = Convert.ToInt32(para.OperateObjectID);
                        entityVipCardRule.VipCardTypeID        = para.VipCardTypeID;
                        entityVipCardRule.CardDiscount         = para.CardDiscount * 10;
                        entityVipCardRule.PaidGivePoints       = para.PaidGivePoints;
                        entityVipCardRule.PaidGivePercetPoints = para.PaidGivePercetPoints;
                        entityVipCardRule.CustomerID           = loggingSessionInfo.ClientID;
                        bllVipCardRule.Update(entityVipCardRule);
                    }
                    break;
                }

                try
                {
                    var msg = new EventContract
                    {
                        Operation  = OptEnum.Update,
                        EntityType = EntityTypeEnum.VipCardType,
                        Id         = SysVipCardTypeInfo.VipCardTypeID.ToString()
                    };
                    var eventService = new EventService();
                    eventService.PublishMsg(msg);
                }
                catch (Exception)
                {
                    throw new Exception("RabbitMQ Error");
                }
            }
            catch (APIException ex)
            {
                throw ex;
            }

            return(rd);
        }
        protected override SetVipCardProfitRuleRD ProcessRequest(DTO.Base.APIRequest <SetVipCardProfitRuleRP> pRequest)
        {
            var rd        = new SetVipCardProfitRuleRD();
            var parameter = pRequest.Parameters;
            LoggingSessionInfo   loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            VipCardProfitRuleBLL RuleService        = new VipCardProfitRuleBLL(loggingSessionInfo);
            IDbTransaction       tran = new TransactionHelper(loggingSessionInfo).CreateTransaction();

            #region  除分润规则
            foreach (var item in parameter.CardBuyToProfitRuleInfoDeleteList)
            {
                RuleService.Delete(item.CardBuyToProfitRuleId, tran);
            }
            #endregion

            #region 新增分润规则
            foreach (var item in parameter.CardBuyToProfitRuleInfoAddList)
            {
                VipCardProfitRuleEntity model = RuleService.GetEntity(item);
                model.CustomerID = loggingSessionInfo.ClientID;
                RuleService.Create(model, tran);
                //处理门店和续费充值方式
                RuleService.SetUnitAndProfitRule(item, model.CardBuyToProfitRuleId, loggingSessionInfo, tran);
            }
            #endregion

            #region 修改分润规则  如果修改了 充值分润 就新入一条数据 FirstRechargeProfitPct
            foreach (var item in parameter.CardBuyToProfitRuleInfoUpdateList)
            {
                var entity = RuleService.GetByID(item.CardBuyToProfitRuleId);
                if (entity == null)
                {
                    tran.Rollback();
                    throw new APIException("分润规则为【" + item.CardBuyToProfitRuleId + "】 的信息已被删除!无法操作该数据")
                          {
                              ErrorCode = 135
                          };
                }

                //业务逻辑:如果修改了 FirstRechargeProfitPct 字段就重新入一条数据
                if (entity.FirstRechargeProfitPct == item.FirstRechargeProfitPct) //只需要修改字段信息
                {
                    VipCardProfitRuleEntity model = RuleService.GetEntity(item);
                    model.CardBuyToProfitRuleId = item.CardBuyToProfitRuleId;
                    model.CustomerID            = loggingSessionInfo.ClientID;
                    model.IsDelete = item.IsDelete;
                    RuleService.Update(model, tran);
                }
                else //新增激励规则信息
                {
                    VipCardProfitRuleEntity model = RuleService.GetEntity(item);
                    model.CustomerID = loggingSessionInfo.ClientID;
                    RuleService.Delete(item.CardBuyToProfitRuleId, tran);
                    RuleService.Create(model, tran);
                    item.CardBuyToProfitRuleId = model.CardBuyToProfitRuleId;
                }
                //处理门店和续费充值方式
                RuleService.SetUnitAndProfitRule(item, item.CardBuyToProfitRuleId, loggingSessionInfo, tran);
            }
            #endregion
            tran.Commit();
            return(rd);
        }
Example #4
0
        protected override GetVipCardProfitRuleListRD ProcessRequest(DTO.Base.APIRequest <GetVipCardProfitRuleListRP> pRequest)
        {
            var rd                 = new GetVipCardProfitRuleListRD();
            var parameter          = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            VipCardProfitRuleBLL            bll         = new VipCardProfitRuleBLL(loggingSessionInfo);
            VipCardProfitRuleUnitMappingBLL UnitService = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);

            //获取会员卡销售激励规则
            rd.VipCardProfitRuleList = bll.PagedQueryByEntity(new VipCardProfitRuleEntity()
            {
                CustomerID = loggingSessionInfo.ClientID
            }, null, 100, 1)
                                       .Entities.Select(m => new VipCardProfitRuleInfo()
            {
                ProfitOwner             = m.ProfitOwner,
                CardBuyToProfitRuleId   = m.CardBuyToProfitRuleId,
                VipCardTypeID           = m.VipCardTypeID,
                RechargeProfitPct       = m.RechargeProfitPct,
                IsApplyAllUnits         = m.IsApplyAllUnits,
                FirstRechargeProfitPct  = m.FirstRechargeProfitPct,
                FirstCardSalesProfitPct = m.FirstCardSalesProfitPct,
                CardSalesProfitPct      = m.CardSalesProfitPct
            }
                                                        ).ToList();

            // 按照商户获取 会员卡 续费充值规则
            var VipCardReRechargeProfitRuleDs = bll.GetVipCardReRechargeProfitRuleList(loggingSessionInfo.ClientID);
            var ruleinfolst = DataTableToObject.ConvertToList <VipCardReRechargeProfitRuleInfo>(VipCardReRechargeProfitRuleDs.Tables[0]);


            foreach (var item in rd.VipCardProfitRuleList)
            {
                //会员卡规则 续费充值 方式
                if (ruleinfolst != null)
                {
                    item.VipCardReRechargeProfitRuleList = ruleinfolst.Where(m => m.CardBuyToProfitRuleId == item.CardBuyToProfitRuleId).ToList();
                }

                //获取门店信息 table[0]=上级门店 table[1]=门店信息
                DataSet ds = UnitService.GetAllUnitTypeList(loggingSessionInfo.ClientID, item.CardBuyToProfitRuleId);

                if (ds != null && ds.Tables.Count == 2)
                {
                    //获取会员卡上级 门店 数组
                    List <Organization> parentunitList = DataTableToObject.ConvertToList <Organization>(ds.Tables[0]);
                    //获取会员卡门店信息
                    List <Stores> StoresList = DataTableToObject.ConvertToList <Stores>(ds.Tables[1]);
                    //分组匹配门店信息
                    foreach (var parentunitInfo in parentunitList)
                    {
                        RuleUnitInfoRD unit = new RuleUnitInfoRD()
                        {
                            text = parentunitInfo.unit_name, id = parentunitInfo.src_unit_id
                        };
                        unit.children = StoresList.Where(m => m.src_unit_id == parentunitInfo.src_unit_id).Select(m => new MappingUnitInfo()
                        {
                            text = m.unit_name, id = m.UnitId, MappingUnitId = m.Id
                        }).ToList();
                        item.RuleUnitInfoList.Add(unit);
                    }
                }
            }
            return(rd);
        }
Example #5
0
        /// <summary>
        /// 充值订单循环队列计算
        /// </summary>
        public void CalculateRechargeOrderJob()
        {
            var numCount    = 50;
            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCRechargeOrder().GetRechargeOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取充值订单数据失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }
                var loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "RedisSystem");
                VipCardProfitRuleBLL      bllVipCardProfitRule    = new VipCardProfitRuleBLL(loggingSessionInfo);
                VipCardProfitRuleEntity[] entityVipCardProfitRule = null;
                var                    bllVipCardGradeChangeLog   = new VipCardGradeChangeLogBLL(loggingSessionInfo);
                VipAmountBLL           bllVipAmount         = new VipAmountBLL(loggingSessionInfo);
                VipAmountDetailBLL     bllVipAmountDetail   = new VipAmountDetailBLL(loggingSessionInfo);
                T_SplitProfitRecordBLL bllSplitProfitRecord = new T_SplitProfitRecordBLL(loggingSessionInfo);

                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCRechargeOrder().GetRechargeOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var rechargeOrderInfo = response.Result.OrderInfo.JsonDeserialize <RechargeOrderEntity>();

                        entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                        {
                            VipCardTypeID = rechargeOrderInfo.VipCardTypeId, IsDelete = 0
                        }, null);
                        if (entityVipCardProfitRule != null)
                        {
                            //DataTable dtAmountDetail = CreateTableAmountDetail();
                            //DataTable dtAmount = CreateTableAmount();
                            //DataTable dtSplitProfitRecord = CreateTableSplitProfitRecord();



                            VipAmountEntity           entityVipAmount         = new VipAmountEntity();
                            VipAmountDetailEntity     entityVipAmountDetail   = new VipAmountDetailEntity();
                            T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity();

                            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 vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity()
                                {
                                    ObjectId = rechargeOrderInfo.OrderID.ToString(), AmountSourceId = strAmountSourceId
                                }, null);
                                if (vipAmountDetail != null && vipAmountDetail.Length > 0)
                                {
                                    continue;
                                }
                                if (rechargeOrderInfo.OrderDesc == "Upgrade")                                //首充
                                {
                                    amount = (decimal)ProfitRule.FirstRechargeProfitPct * (decimal)rechargeOrderInfo.ActuallyPaid * (decimal)0.01;
                                }
                                if (rechargeOrderInfo.OrderDesc == "ReRecharge")//续充
                                {
                                    VipCardReRechargeProfitRuleBLL bllVipCardReRechargeProfitRule = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);
                                    var entityVipCardReRechargeProfitRule = bllVipCardReRechargeProfitRule.QueryByEntity(new VipCardReRechargeProfitRuleEntity()
                                    {
                                        VipCardTypeID = rechargeOrderInfo.VipCardTypeId, CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, IsDelete = 0
                                    }, null);
                                    if (entityVipCardReRechargeProfitRule != null)
                                    {
                                        decimal discount = 0;
                                        foreach (var ReRechargeProfitRule in entityVipCardReRechargeProfitRule.OrderByDescending(a => a.LimitAmount))
                                        {
                                            if (ReRechargeProfitRule.ProfitType == "Superposition")
                                            {
                                                discount = (decimal)(ReRechargeProfitRule.LimitAmount * ReRechargeProfitRule.ProfitPct) * (decimal)0.01;
                                                amount   = (decimal)(rechargeOrderInfo.ActuallyPaid / ReRechargeProfitRule.LimitAmount) * discount;
                                            }
                                            if (ReRechargeProfitRule.ProfitType == "Step")
                                            {
                                                if (rechargeOrderInfo.ActuallyPaid >= ReRechargeProfitRule.LimitAmount)
                                                {
                                                    if (discount == 0)
                                                    {
                                                        discount = (decimal)ReRechargeProfitRule.ProfitPct * (decimal)0.01;
                                                        amount   = (decimal)rechargeOrderInfo.ActuallyPaid * discount;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                //入库
                                if (amount > 0)
                                {
                                    IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                    try {
                                        //                           DataRow dr_AmountDetail = dtAmountDetail.NewRow();
                                        //                           dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid();
                                        //                           dr_AmountDetail["VipId"] = strVipId;
                                        //                           dr_AmountDetail["VipCardCode"] = "";
                                        //                           dr_AmountDetail["UnitID"] = "";
                                        //                           dr_AmountDetail["UnitName"] = "";
                                        //                           dr_AmountDetail["SalesAmount"] = 0;
                                        //                           dr_AmountDetail["Amount"] = amount;
                                        //                           dr_AmountDetail["UsedReturnAmount"] = 0;
                                        //                           dr_AmountDetail["Reason"] = "充值";
                                        //                           dr_AmountDetail["EffectiveDate"] = DateTime.Now;
                                        //                           dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59");
                                        //                           dr_AmountDetail["AmountSourceId"] = strAmountSourceId;
                                        //                           dr_AmountDetail["ObjectId"] = rechargeOrderInfo.OrderID.ToString();
                                        //							 dr_AmountDetail["Remark"] = "充值";
                                        //                           dr_AmountDetail["IsValid"] = 0;
                                        //                           dr_AmountDetail["IsWithdrawCash"] = 0;
                                        //                           dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID;
                                        //                           dr_AmountDetail["CreateTime"] = DateTime.Now;
                                        //                           dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                        //                           dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                        //                           dr_AmountDetail["LastUpdateTime"] = DateTime.Now;
                                        //                           dr_AmountDetail["IsDelete"] = 0;
                                        //                           //dr_AmountDetail["IsCalculated"] = 1;
                                        //                           dtAmountDetail.Rows.Add(dr_AmountDetail);

                                        //DataRow dr_SplitProfitRecord = dtSplitProfitRecord.NewRow();
                                        //dr_SplitProfitRecord["Id"] = Guid.NewGuid();
                                        //dr_SplitProfitRecord["SourceType"] = "Amount";
                                        //dr_SplitProfitRecord["SourceId"] = strAmountSourceId;
                                        //dr_SplitProfitRecord["ObjectId"] = rechargeOrderInfo.OrderID.ToString();
                                        //dr_SplitProfitRecord["UserType"] = strUserType;
                                        //dr_SplitProfitRecord["UserId"] = rechargeOrderInfo.UserId;
                                        //dr_SplitProfitRecord["SplitAmount"] = amount;
                                        //dr_SplitProfitRecord["SplitSattus"] = "10";
                                        //dr_SplitProfitRecord["CustomerId"] = loggingSessionInfo.ClientID;
                                        //dr_SplitProfitRecord["CreateTime"] = DateTime.Now;
                                        //dr_SplitProfitRecord["CreateBy"] = loggingSessionInfo.ClientID;
                                        //dr_SplitProfitRecord["LastUpdateTime"] = DateTime.Now;
                                        //dr_SplitProfitRecord["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                        //dr_SplitProfitRecord["IsDelete"] = 0;
                                        //dtSplitProfitRecord.Rows.Add(dr_SplitProfitRecord);

                                        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
                                        };
                                        bllSplitProfitRecord.Create(entitySplitProfitRecord, tran);


                                        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            = "充值",
                                            IsWithdrawCash    = 0
                                        };
                                        bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);


                                        entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                        {
                                            VipId = strVipId, IsDelete = 0
                                        }, 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);

                                            //DataRow dr_Amount = dtAmount.NewRow();
                                            //dr_Amount["VipId"] = strVipId;
                                            //dr_Amount["VipCardCode"] = "";
                                            //dr_Amount["BeginAmount"] = 0;
                                            //dr_Amount["InAmount"] = amount;
                                            //dr_Amount["OutAmount"] = 0;
                                            //dr_Amount["EndAmount"] = amount;
                                            //dr_Amount["TotalAmount"] = amount;
                                            //dr_Amount["BeginReturnAmount"] = 0;
                                            //dr_Amount["InReturnAmount"] = 0;
                                            //dr_Amount["OutReturnAmount"] = 0;
                                            //dr_Amount["ReturnAmount"] = 0;
                                            //dr_Amount["ImminentInvalidRAmount"] = 0;
                                            //dr_Amount["InvalidReturnAmount"] = 0;
                                            //dr_Amount["ValidReturnAmount"] = 0;
                                            //dr_Amount["TotalReturnAmount"] = 0;
                                            //dr_Amount["PayPassword"] = "";
                                            //dr_Amount["IsLocking"] = 0;
                                            //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID;
                                            //dr_Amount["CreateTime"] = DateTime.Now;
                                            //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID;
                                            //dr_Amount["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                            //dr_Amount["LastUpdateTime"] = DateTime.Now;
                                            //dr_Amount["IsDelete"] = 0;
                                            //dtAmount.Rows.Add(dr_Amount);
                                        }
                                        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);
                                        }
                                        tran.Commit();
                                    }
                                    catch (Exception) {
                                        tran.Rollback();
                                        throw;
                                    }
                                }
                            }
                            //if (dtAmount.Rows.Count > 0 && dtAmountDetail.Rows.Count == dtAmount.Rows.Count)
                            //{
                            //    Utils.SqlBulkCopy(connString, dtAmount, "VipAmount");
                            //}
                            //if (dtAmountDetail.Rows.Count > 0 && dtSplitProfitRecord.Rows.Count > 0)
                            //{
                            //    Utils.SqlBulkCopy(connString, dtSplitProfitRecord, "T_SplitProfitRecord");
                            //    Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail");

                            //}
                        }
                    }
                }
            }
        }
Example #6
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <SetVipCardTypeSystemRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            //卡相关逻辑
            var bllVipCardType = new SysVipCardTypeBLL(loggingSessionInfo);

            //升级规则逻辑
            var bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);

            //基本权益逻辑
            var bllVipCardRule = new VipCardRuleBLL(loggingSessionInfo);

            //开卡礼逻辑
            var bllVipCardUpgradeReward = new VipCardUpgradeRewardBLL(loggingSessionInfo);
            //卡分润规则
            var bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
            //续费充值方式
            var VipCardReRechargeProfitRuleService = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);

            string _CustomerId = loggingSessionInfo.ClientID;

            if (para.VipCardRelateList.Count > 0)
            {
                try
                {
                    foreach (var VipCardSystem in para.VipCardRelateList)
                    {
                        //获取当前会员信息
                        //List<IWhereCondition> wheres = new List<IWhereCondition>();
                        //wheres.Add(new EqualsCondition() { FieldName = "Category", Value = 0 });
                        //wheres.Add(new EqualsCondition() { FieldName = "CustomerID", Value = loggingSessionInfo.ClientID });
                        //wheres.Add(new EqualsCondition() { FieldName = "VipCardTypeName", Value = VipCardSystem.VipCardType.VipCardTypeName });
                        //wheres.Add(new DirectCondition("VipCardLevel!='" + VipCardSystem.VipCardType.VipCardLevel + "'"));
                        //var ExistVipCardTypeResult = bllVipCardType.Query(wheres.ToArray(), null).FirstOrDefault();
                        //if (ExistVipCardTypeResult != null)
                        //{
                        //    throw new APIException("会员卡名称不能重复!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS };
                        //}
                        //获取当前待添加的卡等级数据
                        var VipCardTypeResult = bllVipCardType.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            Category = 0, VipCardLevel = VipCardSystem.VipCardType.VipCardLevel, CustomerID = loggingSessionInfo.ClientID
                        }, null).FirstOrDefault();

                        if (VipCardTypeResult != null)
                        {
                            #region 编辑会员卡等级信息
                            //throw new APIException("卡等级不能重复!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS };
                            //如果存在数据需要进行修改
                            VipCardTypeResult.VipCardTypeName = VipCardSystem.VipCardType.VipCardTypeName;
                            VipCardTypeResult.VipCardLevel    = VipCardSystem.VipCardType.VipCardLevel;
                            if (VipCardTypeResult.VipCardLevel == 1)//如果等级为1默认可充值
                            {
                                VipCardTypeResult.Isprepaid = 1;
                            }
                            else
                            {
                                VipCardTypeResult.Isprepaid = VipCardSystem.VipCardType.IsPrepaid;
                            }
                            VipCardTypeResult.IsOnlineSales = VipCardSystem.VipCardType.IsOnlineSales;
                            //如果IsOnlineSales为0则需要逻辑删除分润规则数据
                            if (VipCardTypeResult.IsOnlineSales == 0)
                            {
                                var VipCardProfitRuleInfo = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                {
                                    VipCardTypeID = VipCardTypeResult.VipCardTypeID, CustomerID = loggingSessionInfo.ClientID
                                }, null);
                                if (VipCardProfitRuleInfo.Length > 0)
                                {
                                    bllVipCardProfitRule.Delete(VipCardProfitRuleInfo);
                                }
                            }
                            VipCardTypeResult.PicUrl = VipCardSystem.VipCardType.PicUrl;
                            if (VipCardSystem.VipCardUpgradeRule != null)
                            {
                                if (VipCardSystem.VipCardUpgradeRule.IsPurchaseUpgrade == 1)
                                {
                                    VipCardTypeResult.Prices           = VipCardSystem.VipCardUpgradeRule.Prices;
                                    VipCardTypeResult.ExchangeIntegral = VipCardSystem.VipCardUpgradeRule.ExchangeIntegral;
                                    VipCardTypeResult.IsExtraMoney     = VipCardSystem.VipCardUpgradeRule.IsExtraMoney;
                                }
                                else
                                {
                                    VipCardTypeResult.Prices           = 0;
                                    VipCardTypeResult.ExchangeIntegral = 0;
                                    VipCardTypeResult.IsExtraMoney     = 2;
                                }
                            }
                            else
                            {
                                VipCardTypeResult.Prices           = 0;
                                VipCardTypeResult.ExchangeIntegral = 0;
                                VipCardTypeResult.IsExtraMoney     = 2;
                            }
                            //要先生成卡等级数据  不然取不到VipCardTypeID
                            if (VipCardSystem.VipCardType.VipCardLevel != 0)
                            {
                                bllVipCardType.Update(VipCardTypeResult);
                                //修改虚拟商品
#warning 商品代码注释 Bear
                                ItemService _ItemService = new ItemService(loggingSessionInfo);
                                _ItemService.SaveCardToOffenTItem(loggingSessionInfo, VipCardTypeResult);

                                try
                                {
                                    var msg = new EventContract
                                    {
                                        Operation  = OptEnum.Update,
                                        EntityType = EntityTypeEnum.VipCardType,
                                        Id         = VipCardTypeResult.VipCardTypeID.ToString()
                                    };
                                    var eventService = new EventService();
                                    eventService.PublishMsg(msg);
                                }
                                catch (Exception)
                                {
                                    throw new Exception("RabbitMQ Error");
                                }
                            }

                            #endregion
                            #region 编辑卡升级规则信息
                            //编辑卡升级规则
                            if (VipCardSystem.VipCardType.VipCardLevel != 1)
                            {
                                VipCardUpgradeRuleEntity vipCardUpgradeRuleEntity = new VipCardUpgradeRuleEntity();
                                var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                                {
                                    CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = VipCardTypeResult.VipCardTypeID
                                }, null).FirstOrDefault();
                                //entityVipCardUpgradeRule.VipCardUpgradeRuleId = System.Guid.NewGuid();
                                if (entityVipCardUpgradeRule != null)
                                {
                                    if (VipCardTypeResult.Isprepaid == 0) //不可充值
                                    {
                                        //将所有梯度信息 逻辑删除
                                        string[] ProfitRuleIds = bllVipCardProfitRule.GetRechargeProfitRuleByIsPrepaid(loggingSessionInfo.ClientID, VipCardTypeResult.VipCardTypeID);
                                        if (ProfitRuleIds.Length > 0)
                                        {
                                            VipCardReRechargeProfitRuleService.Delete(ProfitRuleIds);
                                        }
                                    }

                                    if (VipCardTypeResult != null && VipCardTypeResult.VipCardTypeID != null)
                                    {
                                        entityVipCardUpgradeRule.VipCardTypeID = VipCardTypeResult.VipCardTypeID;
                                    }
                                    //是否购卡升级
                                    if (VipCardSystem.VipCardUpgradeRule != null)
                                    {
                                        if (VipCardSystem.VipCardUpgradeRule.IsPurchaseUpgrade == 1)
                                        {
                                            entityVipCardUpgradeRule.IsPurchaseUpgrade = 1;
                                        }
                                        else
                                        {
                                            entityVipCardUpgradeRule.IsPurchaseUpgrade = 0;
                                        }
                                        //是否充值升级
                                        if (VipCardSystem.VipCardUpgradeRule.IsRecharge == 1)
                                        {
                                            entityVipCardUpgradeRule.IsRecharge         = 1;
                                            entityVipCardUpgradeRule.OnceRechargeAmount = VipCardSystem.VipCardUpgradeRule.OnceRechargeAmount;
                                        }
                                        else
                                        {
                                            entityVipCardUpgradeRule.IsRecharge         = 0;
                                            entityVipCardUpgradeRule.OnceRechargeAmount = 0;
                                        }
                                        //是否消费升级
                                        if (VipCardSystem.VipCardUpgradeRule.IsBuyUpgrade == 1)
                                        {
                                            entityVipCardUpgradeRule.IsBuyUpgrade  = 1;
                                            entityVipCardUpgradeRule.BuyAmount     = VipCardSystem.VipCardUpgradeRule.BuyAmount;
                                            entityVipCardUpgradeRule.OnceBuyAmount = VipCardSystem.VipCardUpgradeRule.OnceBuyAmount;
                                        }
                                        else
                                        {
                                            entityVipCardUpgradeRule.IsBuyUpgrade  = 0;
                                            entityVipCardUpgradeRule.BuyAmount     = 0;
                                            entityVipCardUpgradeRule.OnceBuyAmount = 0;
                                        }
                                    }
                                    else
                                    {
                                        throw new APIException("升级条件不能为空!")
                                              {
                                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                              };
                                    }
                                    entityVipCardUpgradeRule.CustomerID = loggingSessionInfo.ClientID;
                                }
                                else
                                {
                                    if (VipCardTypeResult != null && VipCardTypeResult.VipCardTypeID != null)
                                    {
                                        vipCardUpgradeRuleEntity.VipCardTypeID = VipCardTypeResult.VipCardTypeID;
                                    }
                                    //是否购卡升级
                                    if (VipCardSystem.VipCardUpgradeRule != null)
                                    {
                                        if (VipCardSystem.VipCardUpgradeRule.IsPurchaseUpgrade == 1)
                                        {
                                            vipCardUpgradeRuleEntity.IsPurchaseUpgrade = 1;
                                        }
                                        else
                                        {
                                            vipCardUpgradeRuleEntity.IsPurchaseUpgrade = 0;
                                        }
                                        //是否充值升级
                                        if (VipCardSystem.VipCardUpgradeRule.IsRecharge == 1)
                                        {
                                            vipCardUpgradeRuleEntity.IsRecharge         = 1;
                                            vipCardUpgradeRuleEntity.OnceRechargeAmount = VipCardSystem.VipCardUpgradeRule.OnceRechargeAmount;
                                        }
                                        else
                                        {
                                            vipCardUpgradeRuleEntity.IsRecharge         = 0;
                                            vipCardUpgradeRuleEntity.OnceRechargeAmount = 0;
                                        }
                                        //是否消费升级
                                        if (VipCardSystem.VipCardUpgradeRule.IsBuyUpgrade == 1)
                                        {
                                            vipCardUpgradeRuleEntity.IsBuyUpgrade  = 1;
                                            vipCardUpgradeRuleEntity.BuyAmount     = VipCardSystem.VipCardUpgradeRule.BuyAmount;
                                            vipCardUpgradeRuleEntity.OnceBuyAmount = VipCardSystem.VipCardUpgradeRule.OnceBuyAmount;
                                        }
                                        else
                                        {
                                            vipCardUpgradeRuleEntity.IsBuyUpgrade  = 0;
                                            vipCardUpgradeRuleEntity.BuyAmount     = 0;
                                            vipCardUpgradeRuleEntity.OnceBuyAmount = 0;
                                        }
                                    }
                                    else
                                    {
                                        throw new APIException("升级条件不能为空!")
                                              {
                                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                              };
                                    }
                                    vipCardUpgradeRuleEntity.CustomerID = loggingSessionInfo.ClientID;
                                }

                                //将卡升级规则进行入库
                                if (entityVipCardUpgradeRule != null)
                                {
                                    bllVipCardUpgradeRule.Update(entityVipCardUpgradeRule);
                                }
                                else
                                {
                                    vipCardUpgradeRuleEntity.VipCardUpgradeRuleId = Guid.NewGuid();
                                    bllVipCardUpgradeRule.Create(vipCardUpgradeRuleEntity);
                                }
                            }
                            #endregion
                            #region 编辑基本权益信息
                            //基本权益实体
                            var VipCardRuleInfo = bllVipCardRule.QueryByEntity(new VipCardRuleEntity()
                            {
                                VipCardTypeID = VipCardTypeResult.VipCardTypeID, CustomerID = loggingSessionInfo.ClientID
                            }, null).FirstOrDefault();
                            if (VipCardRuleInfo != null)
                            {
                                if (VipCardSystem.VipCardRule != null)
                                {
                                    VipCardRuleInfo.CardDiscount         = VipCardSystem.VipCardRule.CardDiscount * 10;//因为给的是整数 目前折扣这里乘10
                                    VipCardRuleInfo.PaidGivePoints       = VipCardSystem.VipCardRule.PaidGivePoints;
                                    VipCardRuleInfo.PaidGivePercetPoints = VipCardSystem.VipCardRule.PaidGivePercetPoints;
                                }
                                else
                                {
                                    VipCardRuleInfo.CardDiscount         = 0;//因为给的是整数 目前折扣这里乘10
                                    VipCardRuleInfo.PaidGivePoints       = 0;
                                    VipCardRuleInfo.PaidGivePercetPoints = 0;
                                }
                                //将基本权益数据进行入库
                                bllVipCardRule.Update(VipCardRuleInfo);
                            }
                            else
                            {
                                var vipCardRuleEntity = new VipCardRuleEntity();
                                vipCardRuleEntity.VipCardTypeID        = VipCardTypeResult.VipCardTypeID;
                                vipCardRuleEntity.CardDiscount         = VipCardSystem.VipCardRule.CardDiscount * 10;//因为给的是整数 目前折扣这里乘10
                                vipCardRuleEntity.PaidGivePoints       = VipCardSystem.VipCardRule.PaidGivePoints;
                                vipCardRuleEntity.PaidGivePercetPoints = VipCardSystem.VipCardRule.PaidGivePercetPoints;
                                vipCardRuleEntity.CustomerID           = loggingSessionInfo.ClientID;
                                bllVipCardRule.Create(vipCardRuleEntity);
                            }



                            #endregion
                            #region 编辑开卡礼信息
                            if (VipCardSystem.VipCardUpgradeRewardList != null)
                            {
                                //开卡礼处理
                                foreach (var Rewards in VipCardSystem.VipCardUpgradeRewardList)
                                {
                                    var entityVipCardUpgradeReward = new VipCardUpgradeRewardEntity();
                                    if (VipCardTypeResult != null && VipCardTypeResult.VipCardTypeID != null)
                                    {
                                        entityVipCardUpgradeReward.VipCardTypeID = VipCardTypeResult.VipCardTypeID;
                                    }
                                    entityVipCardUpgradeReward.CouponTypeId = new Guid(Rewards.CouponTypeID);
                                    entityVipCardUpgradeReward.CouponNum    = Rewards.CouponNum;
                                    entityVipCardUpgradeReward.CustomerID   = loggingSessionInfo.ClientID;
                                    if (!string.IsNullOrEmpty(Rewards.CardUpgradeRewardId))
                                    {
                                        entityVipCardUpgradeReward.CardUpgradeRewardId = new Guid(Rewards.CardUpgradeRewardId);
                                    }
                                    switch (Rewards.OperateType) //判断此处为何种操作(0=删除券;1=新增;2=修改;)
                                    {
                                    case 0:                      //删除券
                                        bllVipCardUpgradeReward.Delete(entityVipCardUpgradeReward);
                                        break;

                                    case 1:    //新增券
                                        var existVipCardUpgradeReward = bllVipCardUpgradeReward.QueryByEntity(new VipCardUpgradeRewardEntity()
                                        {
                                            CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = VipCardTypeResult.VipCardTypeID, CouponTypeId = new Guid(Rewards.CouponTypeID)
                                        }, null).FirstOrDefault();
                                        if (existVipCardUpgradeReward != null)
                                        {
                                            existVipCardUpgradeReward.CouponTypeId = new Guid(Rewards.CouponTypeID);
                                            existVipCardUpgradeReward.CouponNum    = Rewards.CouponNum;
                                            existVipCardUpgradeReward.CustomerID   = loggingSessionInfo.ClientID;
                                            bllVipCardUpgradeReward.Update(existVipCardUpgradeReward);
                                        }
                                        else
                                        {
                                            entityVipCardUpgradeReward.CardUpgradeRewardId = Guid.NewGuid();
                                            bllVipCardUpgradeReward.Create(entityVipCardUpgradeReward);
                                        }
                                        break;

                                    case 2:    //修改
                                        bllVipCardUpgradeReward.Update(entityVipCardUpgradeReward);
                                        break;
                                    }
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region 添加会员卡等级信息
                            //如果卡等级不重复则添加卡等级数据
                            var entityVipCardType = new SysVipCardTypeEntity();
                            entityVipCardType.Category        = 0;
                            entityVipCardType.VipCardTypeName = VipCardSystem.VipCardType.VipCardTypeName;
                            entityVipCardType.VipCardLevel    = VipCardSystem.VipCardType.VipCardLevel;
                            entityVipCardType.IsPassword      = 0;
                            if (entityVipCardType.VipCardLevel == 1)//如果等级为1默认可充值
                            {
                                entityVipCardType.Isprepaid = 1;
                            }
                            else
                            {
                                entityVipCardType.Isprepaid = VipCardSystem.VipCardType.IsPrepaid;
                            }
                            entityVipCardType.IsOnlineSales = VipCardSystem.VipCardType.IsOnlineSales;
                            entityVipCardType.PicUrl        = VipCardSystem.VipCardType.PicUrl;
                            entityVipCardType.CustomerID    = loggingSessionInfo.ClientID;
                            if (VipCardSystem.VipCardUpgradeRule != null)
                            {
                                if (VipCardSystem.VipCardUpgradeRule.IsPurchaseUpgrade == 1)
                                {
                                    entityVipCardType.Prices           = VipCardSystem.VipCardUpgradeRule.Prices;
                                    entityVipCardType.ExchangeIntegral = VipCardSystem.VipCardUpgradeRule.ExchangeIntegral;
                                    entityVipCardType.IsExtraMoney     = VipCardSystem.VipCardUpgradeRule.IsExtraMoney;
                                }
                                else
                                {
                                    entityVipCardType.Prices           = 0;
                                    entityVipCardType.ExchangeIntegral = 0;
                                    entityVipCardType.IsExtraMoney     = 2;
                                }
                            }
                            else
                            {
                                entityVipCardType.Prices           = 0;
                                entityVipCardType.ExchangeIntegral = 0;
                                entityVipCardType.IsExtraMoney     = 2;
                            }
                            var existVipCardType = bllVipCardType.QueryByEntity(new SysVipCardTypeEntity()
                            {
                                Category = 0, VipCardLevel = VipCardSystem.VipCardType.VipCardLevel, CustomerID = loggingSessionInfo.ClientID
                            }, null).FirstOrDefault();
                            if (existVipCardType == null)
                            {
                                //要先生成卡等级数据  不然取不到VipCardTypeID
                                if (VipCardSystem.VipCardType.VipCardLevel != 0 && VipCardSystem.VipCardType.VipCardLevel < 8)
                                {
                                    bllVipCardType.Create(entityVipCardType);
                                    //添加虚拟商品
#warning 商品代码注释 Bear
                                    ItemService _ItemService = new ItemService(loggingSessionInfo);
                                    _ItemService.SaveCardToOffenTItem(loggingSessionInfo, entityVipCardType);

                                    var tmp =
                                        bllVipCardType.QueryByEntity(
                                            new SysVipCardTypeEntity()
                                    {
                                        Category     = 0,
                                        VipCardLevel = entityVipCardType.VipCardLevel,
                                        CustomerID   = loggingSessionInfo.ClientID
                                    }, null).FirstOrDefault();


                                    try
                                    {
                                        var msg = new EventContract
                                        {
                                            Operation  = OptEnum.Create,
                                            EntityType = EntityTypeEnum.VipCardType,
                                            Id         = tmp.VipCardTypeID.ToString()
                                        };
                                        var eventService = new EventService();
                                        eventService.PublishMsg(msg);
                                    }
                                    catch (Exception)
                                    {
                                        throw new Exception("RabbitMQ Error");
                                    }
                                }
                                else
                                {
                                    throw new APIException("等级不能超过七级!")
                                          {
                                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                          };
                                }
                            }
                            //else
                            //{
                            //    throw new APIException("会员卡名称不能重复!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS };
                            //}

                            #endregion
                            //因为卡等级不能重复  所以这里根据卡等级获取VipCardTypeID的信息
                            var vipCardTypeInfo = bllVipCardType.QueryByEntity(new SysVipCardTypeEntity()
                            {
                                Category = 0, VipCardLevel = VipCardSystem.VipCardType.VipCardLevel, CustomerID = loggingSessionInfo.ClientID
                            }, null).FirstOrDefault();
                            //因为注册表单暂时没用上 如果卡等级不等于1时 就有升级条件数据存进去
                            if (VipCardSystem.VipCardType.VipCardLevel != 0)
                            {
                                #region 添加卡升级规则信息
                                if (VipCardSystem.VipCardType.VipCardLevel != 1)
                                {
                                    var entityVipCardUpgradeRule = new VipCardUpgradeRuleEntity();
                                    entityVipCardUpgradeRule.VipCardUpgradeRuleId = System.Guid.NewGuid();
                                    if (vipCardTypeInfo != null && vipCardTypeInfo.VipCardTypeID != null)
                                    {
                                        entityVipCardUpgradeRule.VipCardTypeID = vipCardTypeInfo.VipCardTypeID;
                                    }
                                    //是否购卡升级
                                    if (VipCardSystem.VipCardUpgradeRule != null)
                                    {
                                        if (VipCardSystem.VipCardUpgradeRule.IsPurchaseUpgrade == 1)
                                        {
                                            entityVipCardUpgradeRule.IsPurchaseUpgrade = 1;
                                        }
                                        else
                                        {
                                            entityVipCardUpgradeRule.IsPurchaseUpgrade  = 0;
                                            entityVipCardUpgradeRule.OnceRechargeAmount = 0;
                                        }
                                        //是否充值升级
                                        if (VipCardSystem.VipCardUpgradeRule.IsRecharge == 1)
                                        {
                                            entityVipCardUpgradeRule.IsRecharge         = 1;
                                            entityVipCardUpgradeRule.OnceRechargeAmount = VipCardSystem.VipCardUpgradeRule.OnceRechargeAmount;
                                        }
                                        else
                                        {
                                            entityVipCardUpgradeRule.IsRecharge         = 0;
                                            entityVipCardUpgradeRule.OnceRechargeAmount = 0;
                                        }
                                        //是否消费升级
                                        if (VipCardSystem.VipCardUpgradeRule.IsBuyUpgrade == 1)
                                        {
                                            entityVipCardUpgradeRule.IsBuyUpgrade  = 1;
                                            entityVipCardUpgradeRule.BuyAmount     = VipCardSystem.VipCardUpgradeRule.BuyAmount;
                                            entityVipCardUpgradeRule.OnceBuyAmount = VipCardSystem.VipCardUpgradeRule.OnceBuyAmount;
                                        }
                                        else
                                        {
                                            entityVipCardUpgradeRule.IsBuyUpgrade  = 0;
                                            entityVipCardUpgradeRule.BuyAmount     = 0;
                                            entityVipCardUpgradeRule.OnceBuyAmount = 0;
                                        }
                                    }
                                    else
                                    {
                                        throw new APIException("升级条件不能为空!")
                                              {
                                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                              };
                                    }
                                    entityVipCardUpgradeRule.CustomerID = loggingSessionInfo.ClientID;
                                    //将卡升级规则进行入库
                                    bllVipCardUpgradeRule.Create(entityVipCardUpgradeRule);
                                }
                                #endregion
                                #region 添加基本权益实体
                                //基本权益实体
                                var entityVipCardRule = new VipCardRuleEntity();
                                if (vipCardTypeInfo != null && vipCardTypeInfo.VipCardTypeID != null)
                                {
                                    entityVipCardRule.VipCardTypeID = vipCardTypeInfo.VipCardTypeID;
                                }
                                if (VipCardSystem.VipCardRule != null)
                                {
                                    entityVipCardRule.CardDiscount         = VipCardSystem.VipCardRule.CardDiscount * 10;//因为给的是整数 目前折扣这里乘10
                                    entityVipCardRule.PaidGivePoints       = VipCardSystem.VipCardRule.PaidGivePoints;
                                    entityVipCardRule.PaidGivePercetPoints = VipCardSystem.VipCardRule.PaidGivePercetPoints;
                                }
                                else
                                {
                                    entityVipCardRule.CardDiscount         = 0;//因为给的是整数 目前折扣这里乘10
                                    entityVipCardRule.PaidGivePoints       = 0;
                                    entityVipCardRule.PaidGivePercetPoints = 0;
                                }
                                entityVipCardRule.CustomerID = loggingSessionInfo.ClientID;
                                //将基本权益数据进行入库
                                bllVipCardRule.Create(entityVipCardRule);
                                #endregion
                                #region 添加开卡礼信息
                                if (VipCardSystem.VipCardUpgradeRewardList != null)
                                {
                                    //开卡礼处理
                                    foreach (var Rewards in VipCardSystem.VipCardUpgradeRewardList)
                                    {
                                        var entityVipCardUpgradeReward = new VipCardUpgradeRewardEntity();
                                        entityVipCardUpgradeReward.CardUpgradeRewardId = Guid.NewGuid();
                                        if (vipCardTypeInfo != null && vipCardTypeInfo.VipCardTypeID != null)
                                        {
                                            entityVipCardUpgradeReward.VipCardTypeID = vipCardTypeInfo.VipCardTypeID;
                                        }
                                        entityVipCardUpgradeReward.CouponTypeId = new Guid(Rewards.CouponTypeID);
                                        entityVipCardUpgradeReward.CouponNum    = Rewards.CouponNum;
                                        entityVipCardUpgradeReward.CustomerID   = loggingSessionInfo.ClientID;
                                        var existVipCardUpgradeReward = bllVipCardUpgradeReward.QueryByEntity(new VipCardUpgradeRewardEntity()
                                        {
                                            CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = vipCardTypeInfo.VipCardTypeID, CouponTypeId = new Guid(Rewards.CouponTypeID)
                                        }, null).FirstOrDefault();
                                        if (existVipCardUpgradeReward != null)
                                        {
                                            existVipCardUpgradeReward.CouponTypeId = new Guid(Rewards.CouponTypeID);
                                            existVipCardUpgradeReward.CouponNum    = Rewards.CouponNum;
                                            existVipCardUpgradeReward.CustomerID   = loggingSessionInfo.ClientID;
                                            bllVipCardUpgradeReward.Update(existVipCardUpgradeReward);
                                        }
                                        else
                                        {
                                            bllVipCardUpgradeReward.Create(entityVipCardUpgradeReward);
                                        }
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                }
                catch (APIException ex)
                {
                    //pTran.Rollback();
                    throw ex;
                }
            }
            return(rd);
        }