コード例 #1
0
 public void Assign(CrmPayment other)
 {
     this.PayTypeCode         = other.PayTypeCode;
     this.PayMoney            = other.PayMoney;
     this.PayTypeId           = other.PayTypeId;
     this.CouponType          = other.CouponType;
     this.JoinCent            = other.JoinCent;
     this.JoinPromOfferCoupon = other.JoinPromOfferCoupon;
     this.JoinPromDecMoney    = other.JoinPromDecMoney;
 }
コード例 #2
0
        public bool ProcWhenPrepareCheckout()
        {
            if ((ArticleList == null) || (ArticleList.Count == 0) || (PaymentList == null) || (PaymentList.Count == 0))
            {
                return(true);
            }

            PaymentArticleShareList = new List <CrmPaymentArticleShare>();

            if (BillHead.BillType != CrmPosData.BillTypeSale)
            {
                foreach (CrmArticle article in ArticleList)
                {
                    article.SaleMoney = -article.SaleMoney;
                }
                foreach (CrmPayment payment in PaymentList)
                {
                    payment.PayMoney = -payment.PayMoney;
                }
            }

            double totalSaleMoney = 0;

            foreach (CrmArticle article in ArticleList)
            {
                totalSaleMoney                         = totalSaleMoney + article.SaleMoney;
                article.SaleMoneyNoShare               = article.SaleMoney;
                article.SaleMoneySharedJoinDecMoney    = 0;
                article.SaleMoneySharedJoinOfferCoupon = 0;
                article.SaleMoneyForDecMoney           = article.SaleMoney;
                article.SaleMoneyForOfferCoupon        = article.SaleMoney;
                article.SaleMoneyForCent               = article.SaleMoney;
            }
            double totalPayMoney = 0;

            foreach (CrmPayment payment in PaymentList)
            {
                payment.IsShared        = false;
                totalPayMoney           = totalPayMoney + payment.PayMoney;
                payment.PayMoneyNoShare = payment.PayMoney;
            }

            if (BillHead.BillType == CrmPosData.BillTypeSale)
            {
                if (!PromCalculator.CheckDecMoneyDataBefore(out ErrorMessage, out TotalDecMoney, BillHead.ServerBillId, ArticleList, PaymentList, PaymentArticleShareList, DbCmd))
                {
                    return(false);
                }
            }
            if (!MathUtils.DoubleAEuqalToDoubleB(totalSaleMoney - TotalDecMoney, totalPayMoney))
            {
                ErrorMessage = "销售金额 <> 收款金额,不能分摊收款金额到商品";
                return(false);
            }

            List <CrmPayment> tempPaymentList = new List <CrmPayment>();

            foreach (CrmPayment payment in PaymentList)
            {
                if ((!payment.IsShared) && (payment.CouponType >= 0))
                {
                    tempPaymentList.Add(payment);
                }
            }

            if (tempPaymentList.Count > 0)
            {
                //检查券的使用限制,去掉没有使用限制的券
                if (!PromCalculator.CheckPayLimitForCouponPaymentList(out ErrorMessage, BillHead.CompanyCode, tempPaymentList, ArticleList, BillHead.ServerBillId, DbCmd))
                {
                    return(false);
                }
            }

            if (IsToCalcOfferCoupon)
            {
                OfferCouponCalcItemList = new List <CrmPromOfferCouponCalcItem>();
                PromCalculator.MakePromOfferCouponCalcItemList(OfferCouponCalcItemList, ArticleList, BillHead.ServerBillId, BillHead.CompanyCode, BillHead.StoreCode, DbCmd);
                if (OfferCouponCalcItemList.Count > 0)
                {
                    PromCalculator.GetPromOfferCouponDataBefore(OfferCouponCalcItemList, BillHead.OfferCouponVipId, DateTimeUtils.GetMyDateIndex(BillHead.OfferCouponDate), 0, false, DbCmd);
                }
            }

            if (ArticleList.Count == 1)     //只有一条商品记录时  简化处理
            {
                CrmArticle article = ArticleList[0];
                foreach (CrmPayment payment in PaymentList)
                {
                    if (!payment.IsShared)
                    {
                        CrmPaymentArticleShare share = PromCalculator.AddPaymentArticleShareToList(false, PaymentArticleShareList, article, payment, payment.PayMoney, PromCalculator.CheckCouponPaymentJoinOfferCoupon(article, payment));

                        //payment.PayMoneyNoShare = 0;
                        payment.IsShared = true;
                    }
                }
            }
            else
            {
                tempPaymentList.Clear();
                foreach (CrmPayment payment in PaymentList)
                {
                    if (!payment.IsShared)
                    {
                        tempPaymentList.Add(payment);
                    }
                }
                if (tempPaymentList.Count == 1)
                {
                    CrmPayment payment = PaymentList[0];
                    foreach (CrmArticle article in ArticleList)
                    {
                        if (MathUtils.DoubleAGreaterThanDoubleB(article.SaleMoneyNoShare, 0))
                        {
                            CrmPaymentArticleShare share = PromCalculator.AddPaymentArticleShareToList(false, PaymentArticleShareList, article, payment, article.SaleMoneyNoShare, PromCalculator.CheckCouponPaymentJoinOfferCoupon(article, payment));
                            //payment.PayMoneyNoShare -= share.ShareMoney;
                            article.SaleMoneyNoShare = 0;
                        }
                    }
                }
                else
                {
                    bool   isToMaxOfferCoupon  = false;
                    double payMoneyOfferCoupon = 0;
                    if (IsToCalcOfferCoupon)
                    {
                        bool allPromPayment   = true;
                        bool allNoPromPayment = true;
                        foreach (CrmPayment payment in PaymentList)
                        {
                            if (payment.JoinPromOfferCoupon)
                            {
                                allNoPromPayment    = false;
                                payMoneyOfferCoupon = payMoneyOfferCoupon + payment.PayMoney;
                            }
                            else
                            {
                                allPromPayment = false;
                            }
                        }

                        isToMaxOfferCoupon = (!allNoPromPayment) && (!allPromPayment) && (OfferCouponCalcItemList.Count > 0);  //有些收款返券,有些不返券,且有商品返券,则在分摊时要考虑使返券最大化
                        if (isToMaxOfferCoupon)
                        {
                            PromCalculator.CalcPromOfferCouponToSort(OfferCouponCalcItemList, payMoneyOfferCoupon, out isToMaxOfferCoupon);
                            if (isToMaxOfferCoupon)
                            {
                                PromCalculator.SortPromOfferCouponCalcItemList(OfferCouponCalcItemList);
                            }
                        }
                    }
                    tempPaymentList.Clear();
                    foreach (CrmPayment payment in PaymentList)
                    {
                        if ((!payment.IsShared) && (payment.CouponType >= 0))
                        {
                            tempPaymentList.Add(payment);
                        }
                    }

                    //先分摊有使用限制的券(券的收款额正好等于使用限额或可用商品数为1时,简化处理,提前分摊)
                    if (tempPaymentList.Count > 0)
                    {
                        if (!PromCalculator.ShareCouponPaymentList1(out ErrorMessage, tempPaymentList, PaymentArticleShareList))
                        {
                            return(false);
                        }
                    }

                    if (tempPaymentList.Count > 0)
                    {
                        //继续分摊有使用限制的券(用券额小于使用限额且可用商品数大于1)
                        if (!PromCalculator.ShareCouponPaymentList2(out ErrorMessage, tempPaymentList, PaymentArticleShareList))
                        {
                            return(false);
                        }
                    }

                    if (isToMaxOfferCoupon)
                    {
                        payMoneyOfferCoupon = 0;    //参加返券的收款额
                        foreach (CrmPayment payment in PaymentList)
                        {
                            if ((!payment.IsShared) && (payment.JoinPromOfferCoupon))
                            {
                                payMoneyOfferCoupon = payMoneyOfferCoupon + payment.PayMoney;
                            }
                        }
                        //考虑返券最大化,分摊收款,并预算返券
                        double payMoneyDecMoneyNoShare    = 0;
                        double payMoneyOfferCouponNoShare = 0;
                        PromCalculator.CalcPromOfferCouponMax(OfferCouponCalcItemList, 0, payMoneyOfferCoupon, out payMoneyDecMoneyNoShare, out payMoneyOfferCouponNoShare);

                        if (MathUtils.DoubleASmallerThanDoubleB(payMoneyOfferCouponNoShare, payMoneyOfferCoupon))
                        {
                            PromCalculator.ShareArticleMoneyJoinOfferCouponToPayment(ArticleList, PaymentList, PaymentArticleShareList);
                        }
                    }

                    tempPaymentList.Clear();
                    foreach (CrmPayment payment in PaymentList)
                    {
                        if (!payment.IsShared)
                        {
                            tempPaymentList.Add(payment);
                        }
                    }

                    List <CrmArticle> tempArticleList = new List <CrmArticle>();
                    foreach (CrmArticle article in ArticleList)
                    {
                        if (MathUtils.DoubleAGreaterThanDoubleB(article.SaleMoneyNoShare, 0))
                        {
                            tempArticleList.Add(article);
                        }
                    }

                    if (!PromCalculator.SharePaymentEqually(out ErrorMessage, tempArticleList, tempPaymentList, PaymentArticleShareList))
                    {
                        return(false);
                    }
                } //if (tempPaymentList.Count > 1)
            }     //if (ArticleList.Count > 1)

            if (BillHead.BillType != CrmPosData.BillTypeSale)
            {
                foreach (CrmArticle article in ArticleList)
                {
                    article.SaleMoney               = -article.SaleMoney;
                    article.SaleMoneyForCent        = -article.SaleMoneyForCent;
                    article.SaleMoneyForOfferCoupon = -article.SaleMoneyForOfferCoupon;
                }
                foreach (CrmPayment payment in PaymentList)
                {
                    payment.PayMoney = -payment.PayMoney;
                }
                foreach (CrmPaymentArticleShare share in PaymentArticleShareList)
                {
                    share.ShareMoney = -share.ShareMoney;
                }
            }

            if (IsToCalcOfferCoupon)
            {
                if (OfferCouponCalcItemList.Count > 0)
                {
                    PromCalculator.CalcPromOfferCoupon(OfferCouponCalcItemList);
                }

                PaymentOfferCouponArticleList  = new List <CrmPromPaymentOfferCouponArticle>();
                PaymentOfferCouponCalcItemList = new List <CrmPromPaymentOfferCouponCalcItem>();
                CrmVipCard vipCard = new CrmVipCard();
                vipCard.CardId = BillHead.VipId;    //还没取会员卡类型,后面可能用到这个条件

                bool existPromOfferCoupon = false;
                PromRuleSearcher.LookupPromOfferCouponRuleOfPayment(out existPromOfferCoupon, DbCmd, 0, vipCard, BillHead.CompanyCode, BillHead.SaleTime, PaymentArticleShareList, PaymentOfferCouponArticleList);
                if (existPromOfferCoupon)
                {
                    PromCalculator.CalcPromPaymentOfferCoupon(PaymentOfferCouponArticleList, PaymentOfferCouponCalcItemList, DbCmd);
                }
            }

            return(true);
        }