public IActionResult Index(RechargeAddModel model) { DateTime now = DateTime.Now; if (model.CardExpiry < now) { ModelState.AddModelError("CardExpiry", "Your Credit Card is Expire"); return(View(model)); } if (ModelState.IsValid) { var card = GetCard(model.Customercard); var package = GetPackage(card.Package.Id); Recharge recharge = new Recharge() { CardExpiry = model.CardExpiry, Cost = model.Total, CreditCardNumber = model.CreditCardNumber, CVV = model.CVV, PaymentType = model.PaymentType, RechargeDate = now, CustomerCard = card, Package = package }; var cp = _cpService.GetByCardId(card.Id); cp.Status = _statusService.GetByName("Charged"); cp.ExpirationDate = now.AddMonths(model.Months); cp.NumberOfMonths = model.Months; cp.Package = card.Package; cp.CustomerCard = card; _cpService.Update(cp); _rechargeService.Add(recharge); ModelState.Clear(); ViewBag.success = "success"; ViewBag.msg = "Your Account has been Recharge ,Thank You! for chossing our service"; return(View()); } return(View(model)); }
//public IActionResult PayDo(List<IFormFile> formFiles) //{ // try // { // var pay = Request.Form["pay"].ToString(); // ali/wx // var payment = CreatePayment(pay); //创建支付类型,支付宝/微信 // //订单编号 10线上 11线下 // var outTradeNo = DateTime.Now.ToStringTimeStamp();//_orderService.CreateOrderId("10")); // + Request.Query["Id"];商户订单号,需要保证不重复 // //订单名称,必填 // var subject = Request.Form["Name"]; // ////流水号 // //var Sernumber = DateTime.Now.ToStringTimeStamp(); // + Request.Query["Id"]; // //付款金额,必填 // var totalFee = Convert.ToDecimal(Request.Form["Money"]); // //总条数 // var num = Convert.ToInt32(Request.Form["Total"]); // //商品编号 // var prodId = Request.Form["Id"].ToString(); // //生成订单发送到支付宝/微信 // var payRlt = payment.Pay(outTradeNo, subject, totalFee); // //订单写入数据库 todo:充值表.余额表 redis 或者考虑加一张订单表 // // var addOrder = AddOrder(pay, prodId, outTradeNo, totalFee, num); // var rlt = Add(pay, outTradeNo, totalFee, num, subject); // if (pay == "wx") // { // //string ImageUrl = "/Wx/MakeQrCode?data=" + HttpUtility.UrlEncode(payRlt.Message); // //Request.HttpContext.Session.SetString("ImageUrl", ImageUrl); // //HttpContext.Session.CommitAsync(); // //return Redirect("/Prod/WxPay"); //微信二维码支付页面 // } // return Content(payRlt.Message, "text/html"); //支付宝支付页面 // } // catch (Exception ex) // { // Logger.Error("Pay.PayDo:", ex); // return Content(ex.Message); // } //} private Result Add(string pay, string outTradeNo, decimal totalFee, int total, string subject) { var salesMan = _customer.Get(LoginInfo.Id).SalesMan; var orderDto = new RechargeDto { UserId = LoginInfo.Id, OperatorId = LoginInfo.Id, Value = total, Money = Convert.ToInt32(totalFee), CreateDate = DateTime.Now, OrderNumber = outTradeNo, OrderName = subject, IdenTity = IdenTity.Client, OrderDate = DateTime.Now, TradeType = pay.Equals("ali") ? TradeType.AliPay : TradeType.WxPay, TradeResult = TradeResult.Wait, SalesMan = salesMan, RechargeMode = RechargeMode.ContinuedCharge, TranId = "" }; var result = _rechargeService.Add(orderDto, UserType.Admin); return(result); }