/// <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; } } }
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)); }