Esempio n. 1
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(Charge model)
 {
     using (DBHelper db = DBHelper.Create())
     {
         db.Insert<Charge>(model);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Charge model)
 {
     using (DBHelper db = DBHelper.Create())
     {
         db.Insert<Charge>(model);
         return true;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 按月份缴费
        /// </summary>
        /// <param name="charge">缴费主表</param>
        /// <param name="chargeDetail">缴费明细</param>
        /// <param name="ChargeMonth">缴费时长(月)</param>
        /// <returns></returns>
        public bool ChargeByMonth(Charge charge, ChargeDetail[] chargeDetail, int ChargeMonth)
        {
            using (DBHelper db = DBHelper.Create())
            {
                db.BeginTransaction();
                // 插入主表
                db.Insert<Charge>(charge);

                // 插入明细
                db.InsertBatch<ChargeDetail>(chargeDetail);

                // 如果缴费是自动审批,缴费后更新客户的开始缴费时间
                if (charge.Status == 1)
                {
                    string sql = "update t_customer set beginChargeDate = DATEADD(MONTH,@MONTH,beginChargeDate) where ID = @customerID or PID = @customerID";
                    Dictionary<string, object> param = new Dictionary<string, object>();
                    param.Add("MONTH", ChargeMonth);
                    param.Add("customerID", charge.CustomerID);
                    int i = db.ExecuteNonQuery(sql, param);
                    if (i < 1)
                    {
                        db.RollBack();
                        return false;
                    }
                }

                db.Commit();
            }
            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// 按协议缴费
        /// </summary>
        /// <param name="charge">缴费主表</param>
        /// <param name="agreement">协议信息</param>
        /// <returns></returns>
        public string ChargeByAgreement(Charge charge, Agreements agreement)
        {
            using (DBHelper db = DBHelper.Create())
            {
                db.BeginTransaction();
                decimal agreementMoney = agreement.Money;
                #region 更新协议缴费状态
                string sql = "select sum(money) from charge where AgreementID = @AgreementID and (status = 1 or status = 0)";
                Dictionary<string, object> dic = new Dictionary<string, object>();
                dic.Add("AgreementID", agreement.ID);

                object o = db.ExcuteScular(sql, dic);

                decimal chargedSumMoney = 0m;

                decimal.TryParse((o ?? 0).ToString(), out chargedSumMoney);

                // 如果协议总金额大于等于协议金额,则更新协议状态为缴讫
                if (chargedSumMoney == agreement.Money)
                {
                    agreement.Status = 2;
                    db.Update<Agreements>(agreement);
                }
                else if ((chargedSumMoney + charge.Money) > agreement.Money)
                {
                    db.RollBack();
                    return "本期缴费金额加上历史缴费金额大于本协议缴费总金额,不能缴费,请调整缴费金额";
                }
                #endregion
                // 插入主表
                db.Insert<Charge>(charge);

                db.Commit();

                return "缴费成功";
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Ajax.Model.Charge model)
 {
     return(dal.Update(model));
 }
Esempio n. 6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(Ajax.Model.Charge model)
 {
     dal.Add(model);
 }
Esempio n. 7
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);
        }
Esempio n. 8
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;
        }