コード例 #1
0
        public ActionResult AddIdenticalQRCode(string recordId)
        {
            try
            {
                ParkDerateQRcode derate = ParkDerateQRcodeServices.QueryByRecordId(recordId);
                if (derate == null)
                {
                    throw new MyException("获取优免二维码失败");
                }

                derate.AlreadyUseTimes = 0;
                derate.CreateTime      = DateTime.Now;
                derate.OperatorId      = SellerLoginUser.SellerID;
                derate.DataSource      = DerateQRCodeSource.Seller;
                bool result = ParkDerateQRcodeServices.Add(derate);
                if (!result)
                {
                    throw new MyException("复制二维码失败");
                }
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = "复制二维码保存成功" }));
            }
            catch (MyException ex)
            {
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "复制优免二维码失败");
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = "复制优免二维码失败" }));
            }
        }
コード例 #2
0
 public ActionResult AddOrUpdate(ParkDerateQRcode model)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(model.RecordID))
         {
             model.OperatorId = SellerLoginUser.SellerID;
             model.DataSource = DerateQRCodeSource.Seller;
             bool result = ParkDerateQRcodeServices.Add(model);
             if (!result)
             {
                 throw new MyException("添加二维码失败");
             }
         }
         else
         {
             bool result = ParkDerateQRcodeServices.Update(model);
             if (!result)
             {
                 throw new MyException("修改二维码失败");
             }
         }
         return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = "保存成功" }));
     }
     catch (MyException ex)
     {
         return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = ex.Message }));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "保存优免二维码失败", LogFrom.WeiXin);
         return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = "保存优免二维码失败" }));
     }
 }
コード例 #3
0
 public JsonResult AddOrUpdate(ParkDerateQRcode model)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(model.RecordID))
         {
             model.OperatorId       = GetLoginUser.RecordID;
             model.DerateQRcodeType = 0;
             model.DataSource       = DerateQRCodeSource.Platefrom;
             bool result = ParkDerateQRcodeServices.Add(model);
             if (!result)
             {
                 throw new MyException("添加二维码成功");
             }
         }
         else
         {
             bool result = ParkDerateQRcodeServices.Update(model);
             if (!result)
             {
                 throw new MyException("修改二维码成功");
             }
         }
         return(Json(MyResult.Success()));
     }
     catch (MyException ex)
     {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "保存优免二维码失败");
         return(Json(MyResult.Error("保存优免二维码失败")));
     }
 }
コード例 #4
0
 public bool Add(ParkDerateQRcode model)
 {
     model.CreateTime     = DateTime.Now;
     model.DataStatus     = DataStatus.Normal;
     model.LastUpdateTime = DateTime.Now;
     model.HaveUpdate     = SystemDefaultConfig.DataUpdateFlag;
     using (DbOperator dbOperator = ConnectionManager.CreateConnection())
     {
         string strSql = string.Format(@"insert ParkDerateQRcode(RecordID, DerateID, DerateValue,StartTime,EndTime,CreateTime,Remark,DataSource,OperatorId,CanUseTimes,AlreadyUseTimes,DerateQRcodeType,PKID,DataStatus,LastUpdateTime,HaveUpdate)
                                 values(@RecordID,@DerateID,@DerateValue,@StartTime,@EndTime,@CreateTime,@Remark,@DataSource,@OperatorId,@CanUseTimes,@AlreadyUseTimes,@DerateQRcodeType,@PKID,@DataStatus,@LastUpdateTime,@HaveUpdate);");
         dbOperator.ClearParameters();
         dbOperator.AddParameter("RecordID", model.RecordID);
         dbOperator.AddParameter("DerateID", model.DerateID);
         dbOperator.AddParameter("DerateValue", model.DerateValue);
         dbOperator.AddParameter("StartTime", model.StartTime);
         dbOperator.AddParameter("EndTime", model.EndTime);
         dbOperator.AddParameter("CreateTime", model.CreateTime);
         dbOperator.AddParameter("Remark", model.Remark);
         dbOperator.AddParameter("OperatorId", model.OperatorId);
         dbOperator.AddParameter("DataSource", (int)model.DataSource);
         dbOperator.AddParameter("CanUseTimes", model.CanUseTimes);
         dbOperator.AddParameter("AlreadyUseTimes", 0);
         dbOperator.AddParameter("DerateQRcodeType", model.DerateQRcodeType);
         dbOperator.AddParameter("PKID", model.PKID);
         dbOperator.AddParameter("LastUpdateTime", model.LastUpdateTime);
         dbOperator.AddParameter("HaveUpdate", model.HaveUpdate);
         dbOperator.AddParameter("DataStatus", (int)model.DataStatus);
         return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
     }
 }
コード例 #5
0
        public JsonResult AddIdenticalQRCode(string recordId, string vid, bool isAdd)
        {
            try
            {
                ParkDerateQRcode derate = ParkDerateQRcodeServices.QueryByRecordId(recordId);
                if (derate == null)
                {
                    throw new MyException("获取优免二维码失败");
                }

                if (isAdd)
                {
                    derate.AlreadyUseTimes = 0;
                    derate.CreateTime      = DateTime.Now;
                    derate.OperatorId      = GetLoginUser.RecordID;
                    bool result = ParkDerateQRcodeServices.Add(derate);
                    if (!result)
                    {
                        throw new MyException("添加优免二维码失败");
                    }
                }
                if (string.IsNullOrWhiteSpace(SystemDefaultConfig.SystemDomain))
                {
                    throw new MyException("获取系统域名失败");
                }
                BaseVillage village = VillageServices.QueryVillageByRecordId(vid);
                if (village == null)
                {
                    throw new MyException("获取小区信息失败");
                }

                string content = string.Format("{0}/QRCodeDerate/Index?vid={1}&qid={2}&sign={3}", SystemDefaultConfig.SystemDomain, vid, recordId, GetSignature(vid, recordId));
                using (System.Drawing.Image image = QRCodeServices.GenerateQRCode(content, 430))
                {
                    ImageFormat format = image.RawFormat;
                    byte[]      buffer;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Save(ms, ImageFormat.Jpeg);
                        buffer = new byte[ms.Length];
                        ms.Seek(0, SeekOrigin.Begin);
                        ms.Read(buffer, 0, buffer.Length);
                    }
                    return(Json(MyResult.Success("添加二维码成功", System.Convert.ToBase64String(buffer))));
                }
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "复制优免二维码失败");
                return(Json(MyResult.Error("复制优免二维码失败")));
            }
        }
コード例 #6
0
        public static bool Add(ParkDerateQRcode model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            model.RecordID = GuidGenerator.GetGuidString();

            IParkDerateQRcode factory = ParkDerateQRcodeFactory.GetFactory();

            return(factory.Add(model));
        }
コード例 #7
0
        public static bool Update(ParkDerateQRcode model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (string.IsNullOrWhiteSpace(model.RecordID))
            {
                throw new ArgumentNullException("RecordID");
            }

            IParkDerateQRcode factory = ParkDerateQRcodeFactory.GetFactory();

            return(factory.Update(model));
        }
コード例 #8
0
 public bool Update(ParkDerateQRcode model)
 {
     model.CreateTime     = DateTime.Now;
     model.LastUpdateTime = DateTime.Now;
     model.HaveUpdate     = SystemDefaultConfig.DataUpdateFlag;
     using (DbOperator dbOperator = ConnectionManager.CreateConnection())
     {
         string strSql = string.Format(@"update ParkDerateQRcode set DerateID=@DerateID,DerateValue=@DerateValue,CanUseTimes=@CanUseTimes,StartTime=@StartTime,EndTime=@EndTime,Remark=@Remark,LastUpdateTime=@LastUpdateTime,HaveUpdate=@HaveUpdate where RecordID=@RecordID;");
         dbOperator.ClearParameters();
         dbOperator.AddParameter("RecordID", model.RecordID);
         dbOperator.AddParameter("DerateID", model.DerateID);
         dbOperator.AddParameter("DerateValue", model.DerateValue);
         dbOperator.AddParameter("StartTime", model.StartTime);
         dbOperator.AddParameter("EndTime", model.EndTime);
         dbOperator.AddParameter("CreateTime", model.CreateTime);
         dbOperator.AddParameter("Remark", model.Remark);
         dbOperator.AddParameter("CanUseTimes", model.CanUseTimes);
         dbOperator.AddParameter("LastUpdateTime", model.LastUpdateTime);
         dbOperator.AddParameter("HaveUpdate", model.HaveUpdate);
         return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
     }
 }
コード例 #9
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;
                }
            }
        }
コード例 #10
0
        public ActionResult Edit(string recordId)
        {
            try
            {
                ParkDerateQRcode derate = new ParkDerateQRcode();
                if (!string.IsNullOrWhiteSpace(recordId))
                {
                    derate = ParkDerateQRcodeServices.QueryByRecordId(recordId);
                }
                else
                {
                    derate.StartTime = DateTime.Now;
                    derate.EndTime   = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
                }

                List <ParkDerate>  derates        = ParkDerateServices.QueryBySellerID(SellerLoginUser.SellerID);
                List <EnumContext> derateContexts = new List <EnumContext>();
                foreach (var item in derates)
                {
                    EnumContext model = new EnumContext();
                    model.EnumString  = item.DerateID;
                    model.Description = item.Name;
                    model.EnumValue   = (int)item.DerateType;
                    derateContexts.Add(model);
                }
                ViewBag.DerateContexts = derateContexts;
                return(View(derate));
            }
            catch (MyException ex)
            {
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "微信修优免二维码失败", LogFrom.WeiXin);
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = "操作失败" }));
            }
        }
コード例 #11
0
        public JsonResult GrantCarDerate(string vid, string qid, string sellerName, string derateName, int number)
        {
            try
            {
                if (number <= 0)
                {
                    throw new MyException("发放优免券数量不正确");
                }

                if (string.IsNullOrWhiteSpace(SystemDefaultConfig.SystemDomain))
                {
                    throw new MyException("获取系统域名失败");
                }
                ParkDerateQRcode qrCode = ParkDerateQRcodeServices.QueryByRecordId(qid);
                if (qrCode == null)
                {
                    throw new MyException("优免券规则不存在");
                }

                ParkDerate derate = ParkDerateServices.Query(qrCode.DerateID);
                if (derate == null)
                {
                    throw new MyException("获取优免规则失败");
                }

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

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

                BaseVillage village = VillageServices.QueryVillageByRecordId(vid);
                if (village == null)
                {
                    throw new MyException("获取小区信息失败");
                }

                string        folderName   = string.Format("{0}_{1}_{2}", sellerName, derateName, IdGenerator.Instance.GetId().ToString());
                List <string> carDerateIds = new List <string>();
                for (int i = 0; i < number; i++)
                {
                    string carDerateId = GuidGenerator.GetGuidString();
                    string content     = string.Format("{0}/QRCodeDerate/Index?vid={1}&qid={2}&did={3}&sign={4}", SystemDefaultConfig.SystemDomain, vid, qid, carDerateId, GetSignature(vid, qid, carDerateId));
                    string result      = QRCodeServices.GenerateQRCode(village.CPID, content, 430, carDerateId, folderName);
                    if (string.IsNullOrWhiteSpace(result))
                    {
                        throw new MyException("创建二维码失败");
                    }
                    carDerateIds.Add(carDerateId);
                }
                string filePath    = string.Format("/Uploads/{0}", folderName);
                string zipFilePath = string.Format("{0}/{1}_{2}.zip", filePath, sellerName, derateName);
                string mapPath     = Server.MapPath("~/");

                ZipHelper.ZipFiles(string.Format("{0}/{1}", mapPath, filePath), string.Format("{0}/{1}", mapPath, zipFilePath));
                if (carDerateIds.Count != number)
                {
                    throw new MyException("二维码数量与待创建的数量不匹配");
                }

                bool grantResult = ParkDerateQRcodeServices.GrantCarDerate(carDerateIds, zipFilePath, qid);
                if (!grantResult)
                {
                    throw new MyException("发放券失败");
                }

                return(Json(MyResult.Success("", zipFilePath)));
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "发放优免券失败");
                return(Json(MyResult.Error("发放优免券失败")));
            }
        }
コード例 #12
0
        public ActionResult DerateQRCode(string recordId)
        {
            try
            {
                ParkDerateQRcode derateQRcode = ParkDerateQRcodeServices.QueryByRecordId(recordId);
                if (derateQRcode == null)
                {
                    throw new MyException("该二维码不存在");
                }

                ParkDerate derate = ParkDerateServices.Query(derateQRcode.DerateID);
                if (derate == null)
                {
                    throw new MyException("优免规则不存在");
                }
                derateQRcode.DerateName = derate.Name;

                ParkSeller seller = ParkSellerServices.QueryBySellerId(derate.SellerID);
                if (seller == null)
                {
                    throw new MyException("商家不存在");
                }
                derateQRcode.SellerName = seller.SellerName;

                if (string.IsNullOrWhiteSpace(SystemDefaultConfig.SystemDomain))
                {
                    throw new MyException("获取系统域名失败");
                }
                BaseVillage village = VillageServices.QueryVillageByRecordId(seller.VID);
                if (village == null)
                {
                    throw new MyException("获取小区信息失败");
                }

                string content = string.Format("{0}/QRCodeDerate/Index?vid={1}&qid={2}&sign={3}", SystemDefaultConfig.SystemDomain, seller.VID, recordId, GetSignature(seller.VID, recordId));
                using (System.Drawing.Image image = QRCodeServices.GenerateQRCode(content, 430))
                {
                    ImageFormat format = image.RawFormat;
                    byte[]      buffer;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Save(ms, ImageFormat.Jpeg);
                        buffer = new byte[ms.Length];
                        ms.Seek(0, SeekOrigin.Begin);
                        ms.Read(buffer, 0, buffer.Length);
                    }
                    derateQRcode.ImageData = System.Convert.ToBase64String(buffer);
                }
                ViewBag.CompanyID   = village.CPID;
                ViewBag.ShareAction = "XFJMDerateQRCode/DerateQRCode?recordId=" + recordId;
                return(View(derateQRcode));
            }
            catch (MyException ex)
            {
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "微信获取二维码失败", LogFrom.WeiXin);
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = "获取二维码失败" }));
            }
        }
コード例 #13
0
        public ActionResult SubmitDerate(string vid, string qid, string plateNumber)
        {
            try
            {
                TxtLogServices.WriteTxtLogEx("QRCodeDerate", "licensePlate:{0},villageId:{1},QId:{2}", plateNumber, vid, qid);

                ParkDerateQRcode qrCode = ParkDerateQRcodeServices.QueryByRecordId(qid);
                if (qrCode == null)
                {
                    throw new MyException("二维码不存在");
                }

                if (qrCode.DerateQRcodeType != 0 && qrCode.DerateQRcodeType != 1)
                {
                    throw new MyException("优免类型不正确");
                }
                if (qrCode.DerateQRcodeType == 0)
                {
                    TxtLogServices.WriteTxtLogEx("QRCodeDerate", "长久二维码开始提交优免");

                    //长久二维码
                    string errorMsg  = string.Empty;
                    string parkingId = string.Empty;
                    bool   result    = false;//DiscountServices.NewQRCodeDiscount(villageId, QId, licensePlate, out errorMsg, out parkingId);
                    TxtLogServices.WriteTxtLogEx("QRCodeDerate", "长久二维码开始提交优免结果:{0},消息:{1}", result.ToString(), errorMsg);

                    if (!string.IsNullOrWhiteSpace(errorMsg))
                    {
                        return(RedirectToAction("BrowseError", "QRCodeDerate", new { errorMsg = errorMsg }));
                    }
                    if (!result)
                    {
                        throw new Exception("保存优免信息出错!");
                    }

                    if (!string.IsNullOrWhiteSpace(parkingId))
                    {
                        //PKParkinfo parking = ParkingServices.GetParkinfo(parkingId);
                        //if (parking == null || parking.IsMobilePayment == 0)
                        //{
                        //    parkingId = string.Empty;
                        //}
                    }
                    return(RedirectToAction("DerateSuccess", "QRCodeDerate", new { msg = "", parkingId = parkingId, plateNumber = plateNumber }));
                }
                else
                {
                    TxtLogServices.WriteTxtLogEx("QRCodeDerate", "临时二维码开始提交优免");
                    //临时二维码
                    string errorMsg  = string.Empty;
                    string parkingId = string.Empty;
                    bool   result    = false;//DiscountServices.NewQRCodeCarderateDiscount(villageId, QId, licensePlate, out errorMsg, out parkingId);
                    TxtLogServices.WriteTxtLogEx("QRCodeDerate", "临时二维码提交优免结果:{0},消息:{1}", result.ToString(), errorMsg);

                    if (!string.IsNullOrWhiteSpace(errorMsg))
                    {
                        return(RedirectToAction("BrowseError", "QRCodeDerate", new { errorMsg = errorMsg }));
                    }
                    if (!result)
                    {
                        throw new Exception("保存优免信息出错!");
                    }
                    if (!string.IsNullOrWhiteSpace(parkingId))
                    {
                        //PKParkinfo parking = ParkingServices.GetParkinfo(parkingId);
                        //if (parkingId == null || parking.IsMobilePayment == 0 || parking.IsSupportBSGOnLinePay == 0)
                        //{
                        //    parkingId = string.Empty;
                        //}
                    }
                    return(RedirectToAction("DerateSuccess", "QRCodeDerate", new { msg = "", parkingId = parkingId, plateNumber = plateNumber }));
                }
            }
            catch (MyException ex)
            {
                TxtLogServices.WriteTxtLogEx("QRCodeDerate", "保存优免信息出错:描述:{0}", ex.Message);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("QRCodeDerate", "保存优免信息出错", ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "提交优免信息出错" }));
            }
        }
コード例 #14
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;
                }
            }
        }