/// <summary> /// 扫码优免进入 /// </summary> /// <param name="vid">小区编号</param> /// <param name="qid">二维码编号</param> /// <param name="type">0-长久二维码 1-临时二维码</param> /// <param name="sign">签名</param> /// <returns></returns> public ActionResult Index(string vid, string qid, string sign) { TxtLogServices.WriteTxtLogEx("QRCodeDerate", "进入扫码打折:vid={0},qid={1},sign={2}", vid, qid, sign); try { if (SourceClient != RequestSourceClient.WeiXin) { throw new MyException("请在微信中打开"); } if (!CheckSignature(vid, qid, sign)) { throw new MyException("验证签名失败"); } if (SourceClient == RequestSourceClient.WeiXin) { if (string.IsNullOrWhiteSpace(WeiXinOpenId)) { ParkDerate derate = ParkDerateServices.Query(qid); if (derate == null) { throw new MyException("获取优免券信息失败"); } ParkSeller seller = ParkSellerServices.QueryBySellerId(derate.SellerID); if (seller == null) { throw new MyException("获取商家信息失败"); } BaseVillage village = VillageServices.QueryVillageByRecordId(seller.VID); if (village == null) { throw new MyException("获取小区信息失败"); } string id = string.Format("QRCodeDerate_Index_vid={0}^qid={1}^sign={2}^companyId={3}", vid, qid, sign, village.CPID); return(RedirectToAction("Index", "WeiXinAuthorize", new { id = id })); } } ViewBag.PlateNumber = OnlineOrderServices.QueryLastPaymentPlateNumber(PaymentChannel.WeiXinPay, WeiXinOpenId); ViewBag.VillageId = vid; ViewBag.QId = qid; return(View()); } catch (MyException ex) { TxtLogServices.WriteTxtLogEx("QRCodeDerate", "扫码打折异常:描述:{0}", ex.Message); return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message })); } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("QRCodeDerate", "扫码打折异常:描述:{0},明细:{1}", ex.Message, ex.StackTrace); return(RedirectToAction("Index", "ErrorPrompt", new { message = "扫码失败,未知异常" })); } }
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("发放优免券失败"))); } }
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 = "获取二维码失败" })); } }