Exemplo n.º 1
0
        public static bool Add(List <ParkCarDerate> models)
        {
            if (models == null || models.Count == 0)
            {
                throw new ArgumentNullException("models");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    foreach (var item in models)
                    {
                        bool result = factory.Add(item, dbOperator);
                        if (!result)
                        {
                            throw new MyException("保存失败");
                        }
                    }
                    dbOperator.CommitTransaction();
                    return(true);
                }
                catch {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        public static ParkCarDerate QueryBySellerIdAndIORecordId(string sellerId, string ioRecordId)
        {
            IParkCarDerate factory   = ParkCarDerateFactory.GetFactory();
            ParkCarDerate  carDerate = factory.QueryBySellerIdAndIORecordId(sellerId, ioRecordId);

            return(carDerate);
        }
Exemplo n.º 3
0
        public static Dictionary <string, int> QuerySettlementdCarDerate(List <string> derateQRCodeIds)
        {
            if (derateQRCodeIds == null || derateQRCodeIds.Count == 0)
            {
                throw new ArgumentNullException("derateQRCodeIds");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.QuerySettlementdCarDerate(derateQRCodeIds));
        }
Exemplo n.º 4
0
        public static ParkCarDerate QueryByCarDerateID(string carDerateId)
        {
            if (string.IsNullOrWhiteSpace(carDerateId))
            {
                throw new ArgumentNullException("carDerateId");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.QueryByCarDerateID(carDerateId));
        }
Exemplo n.º 5
0
        public static bool UpdateCarderateCreateTime(string carDerateID)
        {
            if (string.IsNullOrWhiteSpace(carDerateID))
            {
                throw new ArgumentNullException("carDerateID");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.UpdateCarderateCreateTime(carDerateID));
        }
Exemplo n.º 6
0
        public static ParkCarDerate GetNotUseParkCarDerate(string derateId, DateTime lessThanTime)
        {
            if (string.IsNullOrWhiteSpace(derateId))
            {
                throw new ArgumentNullException("derateId");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.GetNotUseParkCarDerate(derateId, lessThanTime));
        }
Exemplo n.º 7
0
        public static bool DeleteByExpiryTime(string derateId, DateTime expiredTime)
        {
            if (string.IsNullOrWhiteSpace(derateId))
            {
                throw new ArgumentNullException("derateId");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.DeleteByExpiryTime(derateId, expiredTime));
        }
Exemplo n.º 8
0
        public static List <ParkCarDerate> QueryByIORecordID(string ioRecordId)
        {
            if (string.IsNullOrWhiteSpace(ioRecordId))
            {
                throw new ArgumentNullException("ioRecordId");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.QueryByIORecordID(ioRecordId));
        }
Exemplo n.º 9
0
        public static List <ParkCarDerate> QueryByCardNo(string cardNo)
        {
            if (string.IsNullOrWhiteSpace(cardNo))
            {
                throw new ArgumentNullException("cardNo");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.QueryByCardNo(cardNo));
        }
Exemplo n.º 10
0
        public static List <ParkCarDerate> ParkCarDeratePage(string sellerId, string plateNumber, int?state, int?derateType, DateTime?start, DateTime?end, int pageSize, int pageIndex, ref int totalCount)
        {
            if (string.IsNullOrWhiteSpace(sellerId))
            {
                throw new ArgumentNullException("sellerId");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.ParkCarDeratePage(sellerId, plateNumber, state, derateType, start, end, pageSize, pageIndex, ref totalCount));
        }
Exemplo n.º 11
0
        public static List <ParkCarDerate> QueryByPlateNumber(string plateNumber)
        {
            if (string.IsNullOrWhiteSpace(plateNumber))
            {
                throw new ArgumentNullException("plateNumber");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.QueryByPlateNumber(plateNumber));
        }
Exemplo n.º 12
0
        public static List <ParkCarDerate> QueryByDerateId(string derateId)
        {
            if (string.IsNullOrWhiteSpace(derateId))
            {
                throw new ArgumentNullException("derateId");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.QueryByDerateId(derateId));
        }
Exemplo n.º 13
0
        public static bool UpdateStatus(string carDerateID, CarDerateStatus status)
        {
            if (string.IsNullOrWhiteSpace(carDerateID))
            {
                throw new ArgumentNullException("CarDerateID");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.UpdateStatus(carDerateID, status));
        }
Exemplo n.º 14
0
        public static bool Add(ParkCarDerate model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (string.IsNullOrWhiteSpace(model.CarDerateID))
            {
                model.CarDerateID = GuidGenerator.GetGuidString();
            }
            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.Add(model));
        }
Exemplo n.º 15
0
        public static bool Update(ParkCarDerate model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (string.IsNullOrWhiteSpace(model.CarDerateID))
            {
                throw new ArgumentNullException("CarDerateID");
            }

            IParkCarDerate factory = ParkCarDerateFactory.GetFactory();

            return(factory.Update(model));
        }
Exemplo n.º 16
0
        public static bool Delete(string recordId)
        {
            if (string.IsNullOrWhiteSpace(recordId))
            {
                throw new ArgumentNullException("RecordID");
            }

            IParkDerateQRcode factory = ParkDerateQRcodeFactory.GetFactory();
            ParkDerateQRcode  qrCode  = factory.QueryByRecordId(recordId);

            if (qrCode == null)
            {
                throw new MyException("待删除优免券不存在");
            }

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = factory.Delete(recordId, dbOperator);
                    if (!result)
                    {
                        throw new MyException("删除失败");
                    }
                    if (qrCode.DerateQRcodeType == 1)
                    {
                        IParkCarDerate factoryCarDerate = ParkCarDerateFactory.GetFactory();
                        factoryCarDerate.DeleteNotUseByDerateQRCodeID(recordId, dbOperator);
                    }
                    dbOperator.CommitTransaction();
                    return(true);
                }
                catch {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 下发有免费券
        /// </summary>
        /// <param name="carDerateIds"></param>
        /// <param name="qrCodeZipFilePath">压缩二维码的文件路径</param>
        /// <param name="qrCodeId"></param>
        /// <returns></returns>
        public static bool GrantCarDerate(List <string> carDerateIds, string qrCodeZipFilePath, string qrCodeId)
        {
            if (carDerateIds == null || carDerateIds.Count == 0)
            {
                throw new ArgumentNullException("carDerateIds");
            }
            if (string.IsNullOrWhiteSpace(qrCodeZipFilePath))
            {
                throw new ArgumentNullException("qrCodeFilePath");
            }

            string absolutePath = System.Web.HttpContext.Current.Server.MapPath("~/");
            string s            = string.Format("{0}{1}", absolutePath, qrCodeZipFilePath);

            if (!File.Exists(s))
            {
                throw new MyException("压缩二维码的文件不存在");
            }

            IParkDerateQRcode factory = ParkDerateQRcodeFactory.GetFactory();
            ParkDerateQRcode  qrCode  = factory.QueryByRecordId(qrCodeId);

            if (qrCode == null)
            {
                throw new MyException("优免券规则不存在");
            }

            if (qrCode.EndTime < DateTime.Now)
            {
                throw new MyException("该优免券规则已过期");
            }

            ParkDerate derate = ParkDerateServices.Query(qrCode.DerateID);

            if (derate == null)
            {
                throw new MyException("获取优免规则失败");
            }

            decimal totalAmount = 0;

            if (derate.DerateType == DerateType.SpecialTimePeriodPayment)
            {
                string     errorMsg = string.Empty;
                ParkSeller seller   = ParkSellerServices.GetSeller(derate.SellerID, out errorMsg);
                if (derate == null)
                {
                    throw new MyException("获取优免规则失败");
                }

                totalAmount = qrCode.DerateValue * carDerateIds.Count;
                if ((seller.Creditline + seller.Balance) < totalAmount)
                {
                    throw new MyException("商家余额不足");
                }
            }

            List <ParkCarDerate> carDerates = new List <ParkCarDerate>();

            foreach (var item in carDerateIds)
            {
                ParkCarDerate model = new ParkCarDerate();
                model.CarDerateID = item;
                model.CarDerateNo = IdGenerator.Instance.GetId().ToString();
                model.DerateID    = qrCode.DerateID;
                model.PlateNumber = "";
                model.AreaID      = "";
                model.PKID        = qrCode.PKID;
                if (derate.DerateType != DerateType.ReliefTime && derate.DerateType != DerateType.VotePayment && derate.DerateType != DerateType.DayFree)
                {
                    model.FreeMoney = qrCode.DerateValue;
                }
                else if (derate.DerateType == DerateType.DayFree)
                {
                    model.FreeMoney = qrCode.DerateValue * derate.DerateMoney;
                }
                else
                {
                    model.FreeTime = (int)qrCode.DerateValue;
                }
                model.Status         = CarDerateStatus.Used;
                model.CreateTime     = DateTime.Now;
                model.ExpiryTime     = qrCode.EndTime;
                model.DerateQRCodeID = qrCode.RecordID;
                carDerates.Add(model);
            }
            IParkCarDerate factoryCarDerate = ParkCarDerateFactory.GetFactory();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    //添加券
                    foreach (var item in carDerates)
                    {
                        bool result = factoryCarDerate.Add(item, dbOperator);
                        if (!result)
                        {
                            throw new MyException("发券失败");
                        }
                    }
                    //修改发放总张数据,修改最后压缩包路径
                    int  totalNumbers = qrCode.CanUseTimes + carDerateIds.Count;
                    bool updateResult = factory.Update(qrCodeId, qrCodeZipFilePath, totalNumbers, dbOperator);
                    if (!updateResult)
                    {
                        throw new MyException("修改券总数失败");
                    }

                    //商家扣款
                    if (totalAmount > 0)
                    {
                        IParkSeller factorySeller = ParkSellerFactory.GetFactory();
                        updateResult = factorySeller.SellerDebit(derate.SellerID, totalAmount, dbOperator);
                        if (!updateResult)
                        {
                            throw new MyException("商家扣款失败");
                        }
                    }
                    dbOperator.CommitTransaction();
                    return(true);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
Exemplo n.º 18
0
        public static bool QRCodeDiscount(string sellerId, string derateId, string carDerateId, string parkingId, string ioRecordId, string plateNumber)
        {
            if (string.IsNullOrWhiteSpace(sellerId))
            {
                throw new ArgumentNullException("sellerId");
            }
            if (string.IsNullOrWhiteSpace(derateId))
            {
                throw new ArgumentNullException("derateId");
            }
            if (string.IsNullOrWhiteSpace(carDerateId))
            {
                throw new ArgumentNullException("carDerateId");
            }
            if (string.IsNullOrWhiteSpace(parkingId))
            {
                throw new ArgumentNullException("parkingId");
            }
            if (string.IsNullOrWhiteSpace(plateNumber))
            {
                throw new ArgumentNullException("plateNumber");
            }

            List <ParkCarDerate> carDerates = ParkCarDerateServices.QueryByDerateId(carDerateId);

            if (carDerates == null || carDerates.Count == 0)
            {
                throw new MyException("该优免券不存在");
            }
            if (!string.IsNullOrWhiteSpace(carDerates.First().PlateNumber))
            {
                throw new MyException("该优免券已使用过了[001]");
            }
            if (carDerates.First().Status == CarDerateStatus.Settlementd)
            {
                throw new MyException("该优免券已使用过了[002]");
            }
            if (carDerates.First().Status != CarDerateStatus.Used)
            {
                throw new MyException("该优免券不是有效状态");
            }

            IParkCarDerate factory   = ParkCarDerateFactory.GetFactory();
            ParkCarDerate  carDerate = factory.QueryBySellerIdAndIORecordId(sellerId, ioRecordId);

            if (carDerate != null)
            {
                throw new MyException("该车辆已优免了");
            }

            ParkDerate derate = ParkDerateServices.Query(derateId);

            if (derate == null)
            {
                throw new MyException("找不到优免规则");
            }

            ParkSeller seller = ParkSellerServices.QueryBySellerId(derate.SellerID);

            if (seller == null)
            {
                throw new MyException("找不到商家信息");
            }

            return(factory.QRCodeDiscount(carDerateId, parkingId, ioRecordId, plateNumber));
        }