/// <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"); //} } } } } }
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 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); }