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

            VipCardProfitRuleEntity[] entityVipCardProfitRule = null;

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

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

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

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

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

                            entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                            entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;
                            bllVipAmount.Update(entityVipAmount);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算销售会员卡分润
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="orderInfo"></param>
        public void CalculateSalesVipCardOrder(LoggingSessionInfo loggingSessionInfo, T_InoutEntity orderInfo)
        {
            if (orderInfo != null)
            {
                if (orderInfo.Field17 != null && orderInfo.Field18 != null && orderInfo.Field17.Length > 0 && orderInfo.Field18.Length > 0)
                {
                    VipBLL bllVip = new VipBLL(loggingSessionInfo);

                    T_Inout_DetailBLL           bllInoutDetail            = new T_Inout_DetailBLL(loggingSessionInfo);
                    T_VirtualItemTypeSettingBLL bllVirtualItemTypeSetting = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);

                    var entityInoutDetail = bllInoutDetail.QueryByEntity(new T_Inout_DetailEntity()
                    {
                        order_id = orderInfo.order_id
                    }, null).FirstOrDefault();
                    var vipCardType = bllVirtualItemTypeSetting.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                    {
                        SkuId = entityInoutDetail.sku_id, IsDelete = 0
                    }, null).FirstOrDefault();
                    if (vipCardType != null)
                    {
                        VipCardUpgradeRuleBLL bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);

                        int intVipCardTypeID         = Convert.ToInt32(vipCardType.ObjecetTypeId);
                        var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            VipCardTypeID = intVipCardTypeID, IsPurchaseUpgrade = 1, IsDelete = 0
                        }, null).SingleOrDefault();
                        #region
                        //if (entityVipCardUpgradeRule != null)
                        //{
                        //    VipCardGradeChangeLogEntity entityVipCardGradeChangeLog = new VipCardGradeChangeLogEntity();
                        //    VipCardStatusChangeLogEntity entityVipCardStatusChangeLog = new VipCardStatusChangeLogEntity();

                        //    VipCardGradeChangeLogBLL bllVipCardGradeChangeLog = new VipCardGradeChangeLogBLL(loggingSessionInfo);
                        //    VipCardStatusChangeLogBLL bllVipCardStatusChangeLog = new VipCardStatusChangeLogBLL(loggingSessionInfo);
                        //    VipCardVipMappingBLL vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);

                        //    //会员等级改变以及如日志
                        //    DataSet dsVipInfo = bllVip.GetVipCardLevel(orderInfo.vip_no, loggingSessionInfo.ClientID);
                        //    if(dsVipInfo.Tables.Count>0 && dsVipInfo.Tables[0].Rows.Count>0)
                        //    {
                        //        //会员升级
                        //        vipCardVipMappingBLL.BindVirtualItem(orderInfo.vip_no, orderInfo.VipCardCode, "", intVipCardTypeID);
                        //        //日志
                        //        entityVipCardGradeChangeLog = new VipCardGradeChangeLogEntity()
                        //        {
                        //            ChangeLogID=Guid.NewGuid().ToString(),
                        //            VipCardUpgradeRuleId=entityVipCardUpgradeRule.VipCardUpgradeRuleId,
                        //            OrderType = "SalesCard",
                        //            OrderId=orderInfo.order_id,
                        //            VipCardID = dsVipInfo.Tables[0].Rows[0]["VipCardID"].ToString(),
                        //            ChangeBeforeVipCardID = dsVipInfo.Tables[0].Rows[0]["VipCardID"].ToString(),
                        //            ChangeBeforeGradeID = Convert.ToInt32(dsVipInfo.Tables[0].Rows[0]["VipCardTypeID"].ToString()),
                        //            NowGradeID = intVipCardTypeID,
                        //            ChangeReason="Upgrade",
                        //            OperationType = 2,
                        //            ChangeTime=DateTime.Now,
                        //            UnitID=orderInfo.sales_unit_id,
                        //            OperationUserID=orderInfo.sales_user
                        //        };
                        //        bllVipCardGradeChangeLog.Create(entityVipCardGradeChangeLog);
                        //    }
                        //}
                        #endregion
                        //计算分润
                        VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
                        var entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                        {
                            VipCardTypeID = intVipCardTypeID, IsDelete = 0
                        }, null);
                        if (entityVipCardProfitRule != null)
                        {
                            VipAmountBLL       bllVipAmount       = new VipAmountBLL(loggingSessionInfo);
                            VipAmountDetailBLL bllVipAmountDetail = new VipAmountDetailBLL(loggingSessionInfo);
                            VipAmountEntity    entityVipAmount    = new VipAmountEntity();

                            foreach (var ProfitRule in entityVipCardProfitRule)
                            {
                                decimal amount            = 0;
                                string  strAmountSourceId = string.Empty;
                                string  strVipId          = string.Empty;

                                if (ProfitRule.ProfitOwner == "Employee")
                                {
                                    strAmountSourceId = "37";
                                    strVipId          = orderInfo.sales_user;
                                }
                                if (ProfitRule.ProfitOwner == "Unit")
                                {
                                    strAmountSourceId = "40";
                                    strVipId          = orderInfo.sales_unit_id;
                                }
                                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)
                                    {
                                        amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }

                                amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                if (amount > 0)
                                {
                                    IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();

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

                                    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);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理门店和激励规则信息
        /// </summary>
        /// <param name="item"></param>
        /// <param name="CardBuyToProfitRuleId"></param>
        /// <param name="tran"></param>
        public void SetUnitAndProfitRule(CardBuyToProfitRuleInfoInfo item, Guid?CardBuyToProfitRuleId, LoggingSessionInfo loggingSessionInfo, IDbTransaction tran)
        {
            VipCardProfitRuleBLL            RuleService                 = new VipCardProfitRuleBLL(loggingSessionInfo);
            SysVipCardTypeBLL               SysCardTypeService          = new SysVipCardTypeBLL(loggingSessionInfo);
            VipCardProfitRuleUnitMappingBLL UnitMappService             = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
            VipCardReRechargeProfitRuleBLL  ReRechargeProfitRuleService = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);
            UnitBLL UnitService = new UnitBLL(loggingSessionInfo);

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

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

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