Example #1
0
        public double NextFeeTime(DateTime inTime, DateTime selTime)
        {
            try
            {
                var allTime     = (selTime - inTime).TotalMinutes;
                var parkDetail  = new ParkingDetails(selTime, selTime.AddDays(1), TimeRangeList);
                var inTimeRange = parkDetail.InTimeRange;

                var count       = (int)(allTime / inTimeRange.Item1.FeeMinutes);
                var nextAllTime = (count + 1) * inTimeRange.Item1.FeeMinutes;

                //parkDetail=new ParkingDetails()
                return((count + 1) * inTimeRange.Item1.FeeMinutes - allTime);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Example #2
0
        /// <summary>
        /// 计费器 只负责计算费用  最多只会计算1天的金额
        /// </summary>
        /// <param name="inTime"></param>
        /// <param name="outTime"></param>
        /// <returns></returns>
        private decimal fareRegister(DateTime inTime, DateTime outTime)
        {
            var  parkDetail  = new ParkingDetails(inTime, outTime, TimeRangeList);
            bool IsInculdTwo = false;

            if (parkDetail.ParkInfo.TotalMinutes < 1 || parkDetail.ParkInfo.TotalMinutes <= FreeTime || inTime > outTime) //不足1分钟和在免费时长内 收费为0
            {
                return(0);
            }
            var inTimeRange = parkDetail.InTimeRange;

            if (!IsInculdeFeeTime)
            {
                inTime = inTime.AddMinutes(FreeTime); //不包含免费时长   算费时-去免费时长
            }
            var whileInTime = inTime;
            var newOutTime  = outTime;

            if (inTime.AddMinutes(parkDetail.InTimeRange.Item1.MinSpanTime) > inTimeRange.Item2.Item2)   //入场时间+最小跨度单位 跨区间  则这段时间移到结束时间
            {
                whileInTime = inTimeRange.Item2.Item2.AddMinutes(1);
                newOutTime  = newOutTime.AddMinutes((inTimeRange.Item2.Item2 - inTime).TotalMinutes);
                parkDetail  = new ParkingDetails(whileInTime, newOutTime, TimeRangeList);
                inTimeRange = parkDetail.InTimeRange;
            }
            decimal payMoney = 0, rangeMoney = 0;

            while (true)
            {
                whileInTime = whileInTime.AddMinutes(inTimeRange.Item1.FeeMinutes);

                /*
                 *                      判断当前时间是否超出当前区间
                 * 超出后 重新为inTimeRange赋值
                 * 并判断出场时间是否小于最小跨度时间
                 *  若小于最小跨度时间 则不跳费
                 *  大于最大跨度时间 则跳一次费
                 */
                if (whileInTime >= inTimeRange.Item2.Item2)
                { //当前时间大于区间结束时间
                  //if (whileInTime == inTimeRange.Item2.Item2)
                  //{
                  //    rangeMoney += inTimeRange.Item1.FeeMoney;
                  //}

                    //#region 原方法 比较有误
                    ////if (inTimeRange.Item2.Item2 != whileInTime && (inTimeRange.Item2.Item2 - whileInTime.AddMinutes(-inTimeRange.Item1.FeeMinutes)).TotalMinutes > inTimeRange.Item1.MinSpanTime)
                    ////{
                    ////    //距离区间结束最近的跳费时间 是否大于当前区间的最小跨度时间  如果大于则跳一次费
                    ////    rangeMoney += inTimeRange.Item1.FeeMoney;
                    ////}
                    //#endregion
                    //if (inTimeRange.Item2.Item2 != whileInTime && (whileInTime - inTimeRange.Item2.Item2.AddMinutes(1)).TotalMinutes > inTimeRange.Item1.MinSpanTime)
                    //{
                    //    //距离区间结束最近的跳费时间 是否大于当前区间的最小跨度时间  如果大于则跳一次费
                    //    rangeMoney += inTimeRange.Item1.FeeMoney;
                    //}

                    rangeMoney += inTimeRange.Item1.FeeMoney;
                    whileInTime = inTimeRange.Item2.Item2.AddMinutes(1); //区间算费结束 将算费时间置于下个区间的开始时间

                    if (IsStartTopMoney)
                    { //启用封顶金额
                        rangeMoney = rangeMoney > inTimeRange.Item1.TopMoney ? inTimeRange.Item1.TopMoney : rangeMoney;
                        payMoney  += rangeMoney;
                        rangeMoney = 0; //当前区间结束 重置区间金额
                                        //continue;

                        /*
                         *                                                                                      bug : 跨多区间跨天时   多区间的价格肯定大于当前区间的封顶金额  此时payMoney被重置为当前区间的封顶金额
                         */
                    }
                    //payMoney -= inTimeRange.Item1.FeeMoney;   //此时循环金额已经加了  但是已经进入下个区间 应以下个区间段算费  减去之前加的金额

                    parkDetail  = new ParkingDetails(inTimeRange.Item2.Item2.AddMinutes(1), newOutTime, TimeRangeList);
                    inTimeRange = parkDetail.InTimeRange;
                    IsInculdTwo = true;
                    continue;
                    //payMoney += inTimeRange.Item1.FeeMoney;
                }

                rangeMoney += inTimeRange.Item1.FeeMoney;  //跳费   区间收费

                if (whileInTime >= newOutTime)
                {     //超出出场时间
                    if (rangeMoney != 0)
                    { //结算当前区间的收费金额
                        rangeMoney = rangeMoney > inTimeRange.Item1.TopMoney ? inTimeRange.Item1.TopMoney : rangeMoney;
                        payMoney  += rangeMoney;
                    }
                    #region 原方法  未判断是否跳出当前区间
                    //if ((outTime - whileInTime.AddMinutes(-inTimeRange.Item1.FeeMinutes)).TotalMinutes <= inTimeRange.Item1.MinSpanTime)
                    //{ //出场时间超出最小跨度时间
                    //    payMoney -= inTimeRange.Item1.FeeMoney;
                    //}
                    #endregion
                    //if (outTime > new DateTime(outTime.Year, outTime.Month, outTime.Day, inTimeRange.Item1.EndTime.Hours, inTimeRange.Item1.EndTime.Minutes, inTimeRange.Item1.EndTime.Seconds) && (outTime - whileInTime.AddMinutes(-inTimeRange.Item1.FeeMinutes)).TotalMinutes <= inTimeRange.Item1.MinSpanTime)
                    //{ //出场时间超出最小跨度时间
                    //    payMoney -= inTimeRange.Item1.FeeMoney;
                    //}

                    if (IsInculdTwo && (newOutTime - inTimeRange.Item2.Item1).TotalMinutes <= inTimeRange.Item1.MinSpanTime)
                    { //出场时间不超出最小跨度时间
                        payMoney -= inTimeRange.Item1.FeeMoney;
                    }
                    break;
                }
            }

            return(payMoney);
        }