Ejemplo n.º 1
0
        /// <summary>
        /// 审核通过
        /// </summary>
        /// <param name="recordId"></param>
        /// <returns></returns>
        public static bool Passed(string RecordID, string AuditRemark, string CarTypeID, string CarModelID, string AreaIDS, string GateID, string OperatorId)
        {
            if (string.IsNullOrWhiteSpace(CarTypeID))
            {
                throw new MyException("获取车类失败");
            }
            if (string.IsNullOrWhiteSpace(CarModelID))
            {
                throw new MyException("获取车型失败");
            }

            ParkMonthlyCarApply monthlyCarApply = ParkMonthlyCarApplyServices.QueryByRecordID(RecordID);

            if (monthlyCarApply == null)
            {
                throw new MyException("该申请不存在");
            }
            if (monthlyCarApply.ApplyStatus != MonthlyCarApplyStatus.Applying)
            {
                throw new MyException("该申请是申请中状态");
            }
            monthlyCarApply.CarModelID  = CarModelID;
            monthlyCarApply.CarTypeID   = CarTypeID;
            monthlyCarApply.AuditRemark = AuditRemark;

            BaseParkinfo parking = ParkingServices.QueryParkingByParkingID(monthlyCarApply.PKID);

            if (parking == null)
            {
                throw new MyException("车场信息不存在");
            }

            BaseEmployee  employee  = GenerateBaseEmployeeModel(parking.VID, monthlyCarApply.ApplyName, monthlyCarApply.ApplyMoblie, monthlyCarApply.FamilyAddress);
            EmployeePlate plate     = GenerateEmployeePlateModel(employee, parking.VID, monthlyCarApply.PlateNo);
            BaseCard      card      = GenerateCardModel(parking, employee, plate, OperatorId);
            ParkGrant     parkGrant = GenerateParkGrantModel(parking, plate, card, monthlyCarApply.PKLot, monthlyCarApply.CarModelID, monthlyCarApply.CarTypeID, AreaIDS, GateID);

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = ParkGrantServices.Add(employee, plate, card, parkGrant, dbOperator);
                    if (!result)
                    {
                        throw new MyException("保存车辆信息失败");
                    }

                    IParkMonthlyCarApply factory = ParkMonthlyCarApplyFactory.GetFactory();
                    result = factory.Passed(monthlyCarApply, dbOperator);
                    if (!result)
                    {
                        throw new MyException("修改申请状态失败");
                    }

                    dbOperator.CommitTransaction();
                    monthlyCarApply = ParkMonthlyCarApplyServices.QueryByRecordID(monthlyCarApply.RecordID);
                    OperateLogServices.AddOperateLog <ParkMonthlyCarApply>(monthlyCarApply, OperateType.Update);
                    return(result);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public static decimal CalculateMonthlyRentExpiredWaitPayAmount(DateTime start, string grantId)
        {
            ParkGrant grant = ParkGrantServices.QueryByGrantId(grantId);

            if (grant == null)
            {
                throw new MyException("获取授权失败");
            }
            if (grant.BeginDate == DateTime.MinValue || grant.EndDate == DateTime.MinValue || (grant.EndDate != DateTime.MinValue && grant.EndDate.Date >= DateTime.Now.Date))
            {
                return(0);
            }
            ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID);

            if (carType == null)
            {
                throw new MyException("获取车类失败");
            }

            if (carType.BaseTypeID != BaseCarType.MonthlyRent)
            {
                return(0);
            }

            DateTime startDate = grant.EndDate.AddDays(1).Date;
            DateTime endDate   = start.Date;

            List <string> plateNos = new List <string>();
            EmployeePlate plate    = EmployeePlateServices.Query(grant.PlateID);

            if (plate == null)
            {
                throw new MyException("获取车牌号失败");
            }

            plateNos.Add(plate.PlateNo);

            if (!string.IsNullOrWhiteSpace(grant.PKLot))
            {
                List <ParkGrant> sameGrants = ParkGrantServices.QueryByParkingAndLotAndCarType(grant.PKID, grant.PKLot, BaseCarType.MonthlyRent, grant.GID);
                foreach (var item in sameGrants)
                {
                    int lot1 = grant.PKLot.Split(',').Length;
                    int lot2 = item.PKLot.Split(',').Length;
                    if (lot1 != lot2)
                    {
                        continue;
                    }

                    EmployeePlate plate1 = EmployeePlateServices.Query(item.PlateID);
                    if (plate1 == null)
                    {
                        throw new MyException("获取车牌号失败");
                    }
                    plateNos.Add(plate1.PlateNo);
                }
            }
            IParkOrder factory = ParkOrderFactory.GetFactory();

            return(factory.QueryMonthExpiredNotPayAmount(startDate, endDate, grant.PKID, plateNos));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 续期或续费
        /// </summary>
        /// <param name="grantId"></param>
        /// <param name="renewalMonth"></param>
        /// <param name="payTotalMoney"></param>
        /// <param name="operatorId"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public static bool RenewalsOrRecharge(string grantId, int renewalMonth, decimal payTotalMoney, string operatorId, DateTime startDate, DateTime endDate)
        {
            lock (parkGrant_lock)
            {
                ParkGrant grant = ParkGrantServices.QueryByGrantId(grantId);
                if (grant == null)
                {
                    throw new MyException("获取授权信息失败");
                }

                if (endDate != null && endDate != DateTime.MinValue)
                {
                    endDate = endDate.Date.AddDays(1).AddSeconds(-1);
                }
                string   errorMsg = string.Empty;
                BaseCard card     = BaseCardServices.GetBaseCard(grant.CardID, out errorMsg);
                if (card == null || !string.IsNullOrWhiteSpace(errorMsg))
                {
                    throw new MyException("获取卡失败");
                }

                ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID);
                if (carType == null)
                {
                    throw new MyException("获取卡类失败");
                }

                List <ParkGrant> operateTargets = new List <ParkGrant>();
                List <string>    ioRecords      = new List <string>();

                using (DbOperator dbOperator = ConnectionManager.CreateConnection())
                {
                    try
                    {
                        bool renewalsResult = false;
                        dbOperator.BeginTransaction();
                        switch (carType.BaseTypeID)
                        {
                        case BaseCarType.StoredValueCar:
                        {
                            IBaseCard factory = BaseCardFactory.GetFactory();
                            if (payTotalMoney > 0)
                            {
                                ParkOrder order = ParkOrderServices.AddStoredValueCarOrder(grant.PKID, payTotalMoney, card, operatorId, dbOperator);
                                if (order == null)
                                {
                                    throw new MyException("创建充值订单失败");
                                }

                                decimal cardtotalmoney = card.Balance + payTotalMoney;
                                if (order.NewMoney != cardtotalmoney)
                                {
                                    throw new MyException("充值金额计算错误");
                                }
                                renewalsResult = factory.Recharge(card.CardID, payTotalMoney, dbOperator);
                                if (!renewalsResult)
                                {
                                    throw new MyException("卡充值失败【更改卡余额失败】");
                                }
                            }
                            renewalsResult = factory.SetEndDate(card.CardID, endDate, dbOperator);
                            if (!renewalsResult)
                            {
                                throw new MyException("卡充值失败【更改有效期失败】");
                            }
                            break;
                        }

                        case BaseCarType.VIPCar:
                        {
                            ParkOrder order = ParkOrderServices.AddVipCardOrder(grant.PKID, grantId, grant.BeginDate, grant.EndDate, startDate, endDate, renewalMonth, operatorId, dbOperator);
                            if (order == null)
                            {
                                throw new MyException("充值失败【创建充值订单失败】");
                            }

                            IParkGrant factory = ParkGrantFactory.GetFactory();
                            renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator);
                            if (!renewalsResult)
                            {
                                throw new MyException("修改车辆有效期失败");
                            }
                            break;
                        }

                        case BaseCarType.MonthlyRent:
                        {
                            int pkLotQuantity = 1;
                            if (!string.IsNullOrWhiteSpace(grant.PKLot))
                            {
                                pkLotQuantity = grant.PKLot.TrimEnd(',').Split(',').Length;
                            }
                            decimal amount = ParkOrderServices.CalculateMonthlyRentExpiredWaitPayAmount(startDate, grantId);

                            //if (payTotalMoney != ((carType.Amount * renewalMonth * pkLotQuantity) + amount))
                            //    throw new MyException("凭证续期金额计算有误");



                            List <ParkGrant> shareCardGrants = new List <ParkGrant>();
                            if (!string.IsNullOrWhiteSpace(grant.PKLot))
                            {
                                shareCardGrants = ParkGrantServices.QueryByParkingAndLotAndCarType(grant.PKID, grant.PKLot, BaseCarType.MonthlyRent, grant.GID);
                            }
                            IParkGrant factory = ParkGrantFactory.GetFactory();
                            renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator);
                            if (!renewalsResult)
                            {
                                throw new MyException("修改车辆有效期失败");
                            }


                            //修改多车多位的有效期
                            foreach (var item in shareCardGrants)
                            {
                                if (string.IsNullOrWhiteSpace(item.PKLot))
                                {
                                    continue;
                                }

                                int len1 = item.PKLot.TrimEnd(',').Split(',').Length;
                                int len2 = grant.PKLot.TrimEnd(',').Split(',').Length;
                                if (len1 != len2)
                                {
                                    continue;
                                }

                                item.BeginDate = startDate;
                                item.EndDate   = endDate;
                                factory.Update(item, dbOperator);
                                operateTargets.Add(item);
                            }
                            //过期转临停订单处理
                            if (grant.EndDate.Date < DateTime.Now.Date)
                            {
                                List <string> plateNos = new List <string>();
                                EmployeePlate plate    = EmployeePlateServices.Query(grant.PlateID);
                                if (plate == null)
                                {
                                    throw new MyException("授权车牌信息不存在");
                                }

                                plateNos.Add(plate.PlateNo);

                                foreach (var item in shareCardGrants)
                                {
                                    if (string.IsNullOrWhiteSpace(item.PKLot))
                                    {
                                        continue;
                                    }

                                    int len1 = item.PKLot.TrimEnd(',').Split(',').Length;
                                    int len2 = grant.PKLot.TrimEnd(',').Split(',').Length;
                                    if (len1 != len2)
                                    {
                                        continue;
                                    }

                                    EmployeePlate otherplate = EmployeePlateServices.Query(item.PlateID);
                                    if (otherplate == null)
                                    {
                                        throw new MyException("多车多位存在无效的车牌");
                                    }
                                    plateNos.Add(otherplate.PlateNo);
                                }

                                if (plateNos.Count > 0 && grant.EndDate != DateTime.MinValue)
                                {
                                    IParkIORecord ioRecord = ParkIORecordFactory.GetFactory();
                                    ioRecords = ioRecord.QueryMonthExpiredNotPayAmountIORecordIds(grant.EndDate.AddDays(1).Date, startDate, grant.PKID, plateNos);
                                    if (ioRecords.Count > 0)
                                    {
                                        bool result = ioRecord.UpdateIORecordEnterType(ioRecords, 0, dbOperator);
                                        if (!result)
                                        {
                                            throw new MyException("修改进出记录类型失败");
                                        }
                                        result = ParkOrderServices.AddExpiredToProStopOrder(ioRecords, operatorId, dbOperator);
                                        if (!result)
                                        {
                                            throw new MyException("创建月卡转临停订单失败");
                                        }
                                    }
                                }
                            }
                            ParkOrder order = ParkOrderServices.AddMonthlyRentOrderCS(grant.PKID, carType.CarTypeID, grant.GID, grant.BeginDate, grant.EndDate, startDate, endDate, renewalMonth, pkLotQuantity, operatorId, payTotalMoney, dbOperator);
                            if (order == null)
                            {
                                throw new MyException("续期失败【创建续期订单失败】");
                            }
                            break;
                        }

                        //case BaseCarType.WorkCar:
                        //    {
                        //        IParkGrant factory = ParkGrantFactory.GetFactory();
                        //        renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator);
                        //        if (!renewalsResult) throw new MyException("修改卡结束时间错误");
                        //        break;
                        //    }
                        default: throw new MyException("选择的车辆不能续期和充值");
                        }
                        dbOperator.CommitTransaction();

                        string remark = string.Format("grantId:{0};renewalMonth:{1};payTotalMoney:{2};operatorId:{3};startDate:{4};endDate:{5}", grantId, renewalMonth, payTotalMoney, operatorId, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
                        OperateLogServices.AddOperateLog(OperateType.Update, remark);
                        if (ioRecords.Count > 0)
                        {
                            string updateIORecord = string.Format("修改IORecord表,RecordIDs:{0},EnterType:0", string.Join(",", ioRecords));
                            OperateLogServices.AddOperateLog(OperateType.Update, updateIORecord);
                        }
                        return(renewalsResult);
                    }
                    catch (Exception ex)
                    {
                        dbOperator.RollbackTransaction();
                        throw ex;
                    }
                }
            }
        }