Beispiel #1
0
        /// <summary>
        /// 缴费操作
        /// </summary>
        /// <param name="CustomerID">客户ID</param>
        /// <param name="ChargeMonth">缴费月数</param>
        /// <param name="ChargeMoney">缴费金额</param>
        /// <returns></returns>
        public string Charge(string CustomerID, int ChargeMonth, decimal ChargeMoney, string operatorID)
        {
            CustomerRule customerRule = new CustomerRule();

            Ajax.DAL.ChargeDAL chargeDAL     = new DAL.ChargeDAL();
            Customer           customer      = customerRule.GetModel(CustomerID);
            SysParameterRule   parameterRule = new SysParameterRule();
            dynamic            result        = new System.Dynamic.ExpandoObject();

            int     status   = 0;       // 缴费状态,0 不自动审批,1 自动审批
            decimal allMoney = 0m;

            status = Convert.ToInt32(parameterRule.GetSysParameterValue(Ajax.Common.CommonEnums.SysParameterEnums.ChargeAutoPass));

            if (customer == null)
            {
                result = "客户不存在";
                return(result);
            }
            if (customer.Status != 1)
            {
                result = "客户状态非启用,不能缴费";
                return(result);
            }
            Agreements agreement = new AgreementsRule().GetAgreementByCustomerID(CustomerID);

            // 定义缴费主表对象
            Ajax.Model.Charge charge = new Ajax.Model.Charge()
            {
                AgreementID = agreement == null ? null : agreement.ID,
                BeginDate   = agreement == null ? customer.BeginChargeDate.Value : agreement.BeginDate,
                EndDate     = agreement == null?customer.BeginChargeDate.Value.AddMonths(ChargeMonth) : agreement.EndDate,
                                  CreateDate        = DateTime.Now,
                                  CustomerID        = CustomerID,
                                  ID                = Guid.NewGuid().ToString("N"),
                                  IsAgreementCharge = agreement == null ? 0 : 1,
                                  Money             = ChargeMoney,
                                  OperatorID        = operatorID,
                                  Status            = status
            };
            // 协议缴费,不计算缴费明细
            if (agreement != null)
            {
                string temp = chargeDAL.ChargeByAgreement(charge, agreement);
                if (!string.IsNullOrEmpty(temp))
                {
                    result = temp;
                }
                else
                {
                    result = "缴费成功";
                }
            }
            // 非协议缴费,计算缴费明细
            else
            {
                // 明细缴费
                List <Ajax.Model.ChargeDetail> chargeDetailList = new List <Ajax.Model.ChargeDetail>();                         // 缴费明细
                List <CustomerChargeItem>      myChargeItem     = new List <CustomerChargeItem>();
                myChargeItem = new CustomerChargeItemRule().GetListBycustomerID(CustomerID);
                ChargeItemRule chargeitemRule = new ChargeItemRule();
                //	先添加本客户
                foreach (CustomerChargeItem item in myChargeItem)
                {
                    Ajax.Model.ChargeDetail chargeDetail = new Ajax.Model.ChargeDetail()
                    {
                        ChargeID     = charge.ID,
                        CreateDate   = DateTime.Now,
                        ID           = Guid.NewGuid().ToString("N"),
                        ChargeItemID = item.ItemID,
                        ItemMoney    = chargeitemRule.GetPriceByItemID(item.ItemID, item.Count, CustomerID) * ChargeMonth,
                        Month        = ChargeMonth,
                        Status       = status
                    };
                    allMoney += chargeDetail.ItemMoney;
                    chargeDetailList.Add(chargeDetail);
                }

                List <Customer> childCustomerList = customerRule.GetChildrenCustomer(CustomerID);
                foreach (Customer c in childCustomerList)
                {
                    myChargeItem = new CustomerChargeItemRule().GetListBycustomerID(c.ID);
                    foreach (CustomerChargeItem item in myChargeItem)
                    {
                        Ajax.Model.ChargeDetail chargeDetail = new Ajax.Model.ChargeDetail()
                        {
                            ChargeID     = charge.ID,
                            CreateDate   = DateTime.Now,
                            ID           = Guid.NewGuid().ToString("N"),
                            ChargeItemID = item.ItemID,
                            ItemMoney    = chargeitemRule.GetPriceByItemID(item.ItemID, item.Count, c.ID) * ChargeMonth,
                            Month        = ChargeMonth,
                            Status       = status
                        };
                        allMoney += chargeDetail.ItemMoney;
                        chargeDetailList.Add(chargeDetail);
                    }
                }
                charge.Money = allMoney;
                chargeDAL.ChargeByMonth(charge, chargeDetailList.ToArray(), ChargeMonth);
                result = "缴费成功";
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 递归计算客户(默认包括子客户)的应缴费用
        /// </summary>
        /// <param name="customerID"></param>
        /// <param name="containChildCustomer">是否计继续算子客户应缴费用</param>
        /// <returns></returns>
        public decimal CaculateCustomerFee(string customerID, bool containChildCustomer = true)
        {
            decimal        totalFee       = 0;
            Customer       c              = new CustomerRule().GetModel(customerID);
            int            monthCount     = GetMonthCount(Convert.ToDateTime(c.BeginChargeDate));
            ChargeItemRule chargeItemRule = new ChargeItemRule();
            Agreements     agree          = new AgreementsRule().GetAgreementByCustomerID(customerID);

            if (agree != null)
            {
                totalFee = new AgreementsRule().GetLastAgreeFee(agree.ID);
                if (agree.EndDate > DateTime.Now)
                {
                    monthCount = GetMonthCount(agree.EndDate);
                    //客户缴费项
                    List <CustomerChargeItem> chargeItems = new CustomerChargeItemRule().GetListBycustomerID(customerID);
                    foreach (CustomerChargeItem chargeItem in chargeItems)
                    {
                        if (chargeItem.AgreementMoney > 0)
                        {
                            totalFee += chargeItem.AgreementMoney;
                        }
                        else
                        {
                            decimal itemPrice = chargeItemRule.GetPriceByItemID(chargeItem.ItemID, chargeItem.Count, customerID);
                            totalFee += monthCount * chargeItem.Count * itemPrice;
                        }
                    }
                }
            }
            else            //非协议用户&协议过期
            {
                //客户缴费项
                List <CustomerChargeItem> chargeItems = new CustomerChargeItemRule().GetListBycustomerID(customerID);
                foreach (CustomerChargeItem chargeItem in chargeItems)
                {
                    if (chargeItem.AgreementMoney > 0)
                    {
                        totalFee += chargeItem.AgreementMoney * monthCount;
                    }
                    else
                    {
                        decimal itemPrice = chargeItemRule.GetPriceByItemID(chargeItem.ItemID, chargeItem.Count, customerID);
                        totalFee += monthCount * chargeItem.Count * itemPrice;
                    }
                }
                //递归所有子客户应缴金额
                if (containChildCustomer)
                {
                    List <Customer> customerChildrenList = new CustomerRule().GetChildrenCustomer(customerID);
                    if (customerChildrenList != null)
                    {
                        //子客户费用
                        foreach (Customer childC in customerChildrenList)
                        {
                            totalFee += CaculateCustomerFee(childC.ID);
                        }
                    }
                }
            }
            return(totalFee);
        }