public async Task <IActionResult> PutOders([FromRoute] string id, [FromBody] Oders odr) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != odr.OderId) { return(BadRequest()); } _database.Entry(odr).State = EntityState.Modified; try { await _database.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OdersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostOders([FromBody] Oders odr) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _database.Oders.Add(odr); try { await _database.SaveChangesAsync(); } catch (DbUpdateException) { if (OdersExists(odr.OderId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetOders", new { id = odr.OderId }, odr)); }
public ActionResult DeleteConfirmed(string id) { Oders oders = db.Oderss.Find(id); db.Oderss.Remove(oders); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Oders_id,cus_id,total_amount,payment_method,Description,fullname,address,phone,create_date")] Oders oders) { if (ModelState.IsValid) { db.Entry(oders).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.cus_id = new SelectList(db.Customers, "cus_id", "cus_name", oders.cus_id); return(View(oders)); }
// GET: Admin_quanli/Oders/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Oders oders = db.Oderss.Find(id); if (oders == null) { return(HttpNotFound()); } return(View(oders)); }
// GET: Admin_quanli/Oders/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Oders oders = db.Oderss.Find(id); if (oders == null) { return(HttpNotFound()); } ViewBag.cus_id = new SelectList(db.Customers, "cus_id", "cus_name", oders.cus_id); return(View(oders)); }
public ActionResult CheckOutt(string payment_met, string fullname, string address, string phone, Oders order, string descripsion, string date) { List <Basket> carts = (List <Basket>)Session["basket"]; var total = carts.Sum(x => x.Price * x.Quantity); var uid = Session["admin"].ToString(); Customer user = db.Customers.Find(uid); var bill = new Oders(); bill.Oders_id = "OD" + DateTime.Now.ToString("ddMMyyyy-hhmmss"); bill.cus_id = user.cus_id; bill.fullname = fullname; bill.phone = phone; bill.address = address; bill.Description = descripsion; bill.total_amount = total; bill.payment_method = payment_met; bill.create_date = DateTime.Now; try { db.Oderss.Add(bill); db.SaveChanges(); var listPay = (List <Basket>)Session["basket"]; foreach (var item in listPay) { var detail = new Oders_Detail(); //detail.OrderDetailId = "DT" + DateTime.Now.ToString("dd/MM/yyyy-mmhhss"); detail.Oders_id = bill.Oders_id; detail.pro_id = item.ProductId; detail.quantity = item.Quantity; detail.detail_sale_price = item.Price; detail.total_price = item.Money; db.Oders_Details.Add(detail); db.SaveChanges(); } Session.Remove("basket"); } catch (Exception ex) { throw new ApplicationException("Có lỗi xảy ra không thể thực hiện thanh toán: ", ex); } return(View("Success")); }
/// <summary> /// 添加信息 /// </summary> /// <param name="context"></param> protected void AddRoomInfo(HttpContext context) { var uname = WebConfigurationManager.AppSettings["zcname"];//名称 string appId = WebConfigurationManager.AppSettings["WeixinPay_AppId"].ToString(); var totalprrc = context.Request.Params["total"]; var unnum = Convert.ToInt32(context.Request.Params["tnum"]); if (context.Request.Cookies["ZCWebDomain"] == null || string.IsNullOrEmpty(context.Request.Cookies["ZCWebDomain"]["useropid"])) { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "用户数据不正确!", result = null, count = 2 }); context.Response.Write(jsonstrlist); } else { var tmpopenid = context.Request.Cookies["ZCWebDomain"]["useropid"]; var phone = context.Request.Params["phone"]; var name = context.Request.Params["name"]; string timeStamp = ""; string nonceStr = ""; string packageValue = ""; string paySign = ""; string tmpOrderId = string.Empty; using (WXDBEntities db = new WXDBEntities()) { int tmptotals = Convert.ToInt32(Convert.ToDouble(totalprrc) * 100);//总价格 var tmodel = db.Oders.Where(s => s.Mobile.Equals(phone) && s.OrderStatus.Equals(1)).FirstOrDefault(); var tmotol = 0; if (tmodel != null) { if (tmodel.Extent1.Equals(name)) { var ttinfo = db.Oders.Where(s => s.Mobile.Equals(phone) && s.OrderStatus.Equals(1)).FirstOrDefault(); if (ttinfo != null) { tmotol = db.Oders.Where(s => s.Mobile.Equals(phone) && s.OrderStatus.Equals(1)).Sum(s => s.Number); } if ((unnum + tmotol) > 20) { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "你购买的众筹份数已超额,请重新选择数量", result = null, count = 3 }); context.Response.Write(jsonstrlist); } else { //追加购买 try { Oders order = new Oders() { Title = uname, OrderId = WebConn.TenPayInfo.PartnerId + DateTime.Now.ToString("HHmmss") + TenPayV3Util.BuildRandomStr(4), Number = unnum, Mobile = phone, Soucre = "12", //房间单价格 Remark = WebConfigurationManager.AppSettings["zcname"], //所选房间 AddTime = DateTime.Now, UpdateTime = DateTime.Now, OrderStatus = 0, Status = 0, Orders = 0, Extent1 = name, Extent2 = "", AddUser = tmpopenid,//订单人 UpdateUser = "", CheckTime = DateTime.Now, CheckoutTime = DateTime.Now, Totals = tmptotals }; db.Oders.AddObject(order); db.SaveChanges(); //设置输出参数 //创建支付应答对象 RequestHandler packageReqHandler = new RequestHandler(context); //初始化 packageReqHandler.Init(); packageReqHandler.SetKey(WebConfigurationManager.AppSettings["WeixinPay_Key"]); timeStamp = TenPayV3Util.GetTimestamp(); nonceStr = TenPayV3Util.GetNoncestr().ToLower(); //设置package订单参数 packageReqHandler.SetParameter("appid", appId); //公众账号ID packageReqHandler.SetParameter("mch_id", WebConfigurationManager.AppSettings["WeixinPay_PartnerId"]); //商户号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 packageReqHandler.SetParameter("body", order.Remark); //商品描述 packageReqHandler.SetParameter("out_trade_no", order.OrderId); //商家订单号 packageReqHandler.SetParameter("total_fee", order.Totals.ToString()); //商品金额,以分为单位(money * 100).ToString() packageReqHandler.SetParameter("spbill_create_ip", context.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP packageReqHandler.SetParameter("notify_url", WebConfigurationManager.AppSettings["WeixinPay_TenpayNotify"]); //通知的URL packageReqHandler.SetParameter("trade_type", "JSAPI"); //交易类型 packageReqHandler.SetParameter("openid", order.AddUser); //用户Openid //获取package包 string sign = packageReqHandler.CreateMd5Sign("key", WebConfigurationManager.AppSettings["WeixinPay_Key"]); packageReqHandler.SetParameter("sign", sign); //sign签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.Unifiedorder(data); var res = XDocument.Parse(result); string prepayId = res.Element("xml").Element("prepay_id").Value; packageValue = string.Format("prepay_id={0}", prepayId); //设置支付参数 RequestHandler paySignReqHandler = new RequestHandler(context); paySignReqHandler.SetParameter("appId", appId); paySignReqHandler.SetParameter("timeStamp", timeStamp); paySignReqHandler.SetParameter("nonceStr", nonceStr); paySignReqHandler.SetParameter("package", string.Format("prepay_id={0}", prepayId)); paySignReqHandler.SetParameter("signType", "MD5"); paySign = paySignReqHandler.CreateMd5Sign("key", WebConfigurationManager.AppSettings["WeixinPay_Key"]);// List <object> listDesc = new List <object>(); listDesc.Add(new { appId = appId, timeStamp = timeStamp, nonceStr = nonceStr, package = packageValue, paySign = paySign, orderid = order.OrderId }); string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = listDesc.Count }); context.Response.Write(jsonstrlist); } catch (Exception ex) { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = ex.Message, result = "", count = 0 }); context.Response.Write(jsonstrlist); } } } else { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "用户数据不匹配,不能进行购买!", result = null, count = 3 }); context.Response.Write(jsonstrlist); } } else { //新的购买 try { Oders order = new Oders() { Title = uname, OrderId = WebConn.TenPayInfo.PartnerId + DateTime.Now.ToString("HHmmss") + TenPayV3Util.BuildRandomStr(4), Number = unnum, Mobile = phone, Soucre = "12", //房间单价格 Remark = WebConfigurationManager.AppSettings["zcname"], //所选房间 AddTime = DateTime.Now, UpdateTime = DateTime.Now, OrderStatus = 0, Status = 0, Orders = 0, Extent1 = name, Extent2 = "", AddUser = tmpopenid,//订单人 UpdateUser = "", CheckTime = DateTime.Now, CheckoutTime = DateTime.Now, Totals = tmptotals }; db.Oders.AddObject(order); db.SaveChanges(); //设置输出参数 //创建支付应答对象 RequestHandler packageReqHandler = new RequestHandler(context); //初始化 packageReqHandler.Init(); packageReqHandler.SetKey(WebConfigurationManager.AppSettings["WeixinPay_Key"]); timeStamp = TenPayV3Util.GetTimestamp(); nonceStr = TenPayV3Util.GetNoncestr().ToLower(); //设置package订单参数 packageReqHandler.SetParameter("appid", appId); //公众账号ID packageReqHandler.SetParameter("mch_id", WebConfigurationManager.AppSettings["WeixinPay_PartnerId"]); //商户号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 packageReqHandler.SetParameter("body", order.Remark); //商品描述 packageReqHandler.SetParameter("out_trade_no", order.OrderId); //商家订单号 packageReqHandler.SetParameter("total_fee", order.Totals.ToString()); //商品金额,以分为单位(money * 100).ToString() packageReqHandler.SetParameter("spbill_create_ip", context.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP packageReqHandler.SetParameter("notify_url", WebConfigurationManager.AppSettings["WeixinPay_TenpayNotify"]); //通知的URL packageReqHandler.SetParameter("trade_type", "JSAPI"); //交易类型 packageReqHandler.SetParameter("openid", order.AddUser); //用户Openid //获取package包 string sign = packageReqHandler.CreateMd5Sign("key", WebConfigurationManager.AppSettings["WeixinPay_Key"]); packageReqHandler.SetParameter("sign", sign); //sign签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.Unifiedorder(data); var res = XDocument.Parse(result); string prepayId = res.Element("xml").Element("prepay_id").Value; packageValue = string.Format("prepay_id={0}", prepayId); //设置支付参数 RequestHandler paySignReqHandler = new RequestHandler(context); paySignReqHandler.SetParameter("appId", appId); paySignReqHandler.SetParameter("timeStamp", timeStamp); paySignReqHandler.SetParameter("nonceStr", nonceStr); paySignReqHandler.SetParameter("package", string.Format("prepay_id={0}", prepayId)); paySignReqHandler.SetParameter("signType", "MD5"); paySign = paySignReqHandler.CreateMd5Sign("key", WebConfigurationManager.AppSettings["WeixinPay_Key"]);// List <object> listDesc = new List <object>(); listDesc.Add(new { appId = appId, timeStamp = timeStamp, nonceStr = nonceStr, package = packageValue, paySign = paySign, orderid = order.OrderId }); string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = "succ", result = listDesc, count = listDesc.Count }); context.Response.Write(jsonstrlist); } catch (Exception ex) { string jsonstrlist = JsonHelper.GetJsonString(new jsonResult { code = ex.Message, result = ex.Message, count = 0 }); context.Response.Write(jsonstrlist); } } } } }
private string SendHB(string opid, string stid, string hb, string cursjd) { var str = string.Empty; DateTime now = DateTime.Now; TimeSpan span = now.TimeOfDay; TimeSpan end = new TimeSpan(15, 0, 0); TimeSpan end1 = new TimeSpan(12, 0, 0); //cursjd.Equals("1") || //cursjd.Equals("1") && DateTime.Now.Hour >= 11 && span < end1 //cursjd.Equals("2") && DateTime.Now.Hour >= 14 && span < end if (cursjd.Equals("1") && DateTime.Now.Hour >= 11 && span < end1) { #region 设置参数信息 try { string mchbillno = DateTime.Now.ToString("HHmmss") + TenPayV3Util.BuildRandomStr(28); string nonceStr = TenPayV3Util.GetNoncestr(); RequestHandler packageReqHandler = new RequestHandler(null); //设置package订单参数 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 packageReqHandler.SetParameter("wxappid", WebConfigurationManager.AppSettings["wxappid8"]); //公众账号ID packageReqHandler.SetParameter("mch_id", WebConfigurationManager.AppSettings["WeixinPay_PartnerId8"]); //商户号 packageReqHandler.SetParameter("mch_billno", mchbillno); //填入商家订单号 packageReqHandler.SetParameter("send_name", WebConfigurationManager.AppSettings["sendname8"]); //红包发送者名称 packageReqHandler.SetParameter("re_openid", opid); //接受收红包的用户的openId packageReqHandler.SetParameter("total_amount", hb); //付款金额,单位分 packageReqHandler.SetParameter("total_num", "1"); //红包发放总人数 packageReqHandler.SetParameter("wishing", WebConfigurationManager.AppSettings["hbzf8"]); //红包祝福语 packageReqHandler.SetParameter("client_ip", _context.Request.UserHostAddress); //调用接口的机器Ip地址 packageReqHandler.SetParameter("act_name", WebConfigurationManager.AppSettings["hbname8"]); //活动名称 packageReqHandler.SetParameter("remark", WebConfigurationManager.AppSettings["hbDesc8"]); //备注信息 string sign = packageReqHandler.CreateMd5Sign("key", WebConfigurationManager.AppSettings["WeixinPay_Key8"]); packageReqHandler.SetParameter("sign", sign); //签名 //发红包需要post的数据 string data = packageReqHandler.ParseXML(); //发红包接口地址 string url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中) string cert = WebConfigurationManager.AppSettings["zswz8"]; //私钥(在安装证书时设置) string password = WebConfigurationManager.AppSettings["WeixinPay_PartnerId8"]; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); //调用证书 X509Certificate2 cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); #endregion #region 发起post请求 HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); webrequest.ClientCertificates.Add(cer); webrequest.Method = "post"; byte[] postdatabyte = Encoding.UTF8.GetBytes(data); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); HttpWebResponse httpWebResponse = (HttpWebResponse)webrequest.GetResponse(); StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()); string responseContent = streamReader.ReadToEnd(); WxZFData tdata = new WxZFData(); tdata.FromXml(responseContent); string return_code = tdata.GetValue("return_code").ToString(); //状态码 string return_msg = tdata.GetValue("return_msg").ToString(); //状态码 string result_code = tdata.GetValue("result_code").ToString().ToUpper(); if ("SUCCESS".Equals(return_code)) { //using (WXDBEntities db = new WXDBEntities()) //{ // OperateLoginfo mt = new OperateLoginfo() // { // Title = "五洲国际红包", // Descs = "进入", // AddTime = DateTime.Now, // UpdateTime = DateTime.Now, // Status = 0, // Orders = 0, // Extent1 = return_msg, // Extent2 = result_code, // LogType = 0 // }; // db.OperateLoginfo.AddObject(mt); // db.SaveChanges(); //} if ("SUCCESS".Equals(result_code)) { //红包发送成功! using (WXDBEntities db = new WXDBEntities()) { //OperateLoginfo mt = new OperateLoginfo() //{ // Title = "五洲国际红包", // Descs = stid, // AddTime = DateTime.Now, // UpdateTime = DateTime.Now, // Status = 0, // Orders = 0, // Extent1 = "", // Extent2 = cursjd, // LogType = 0 //}; //db.OperateLoginfo.AddObject(mt); //db.SaveChanges(); var model = new Oders() { OrderId = mchbillno, Title = "五洲红包", Number = 1, Mobile = "", Soucre = opid, Remark = "345", AddTime = DateTime.Now, UpdateTime = DateTime.Now, OrderStatus = 0, Status = 0, Orders = 0, Extent1 = stid, Extent2 = "789", AddUser = cursjd, UpdateUser = "******", CheckTime = DateTime.Now, CheckoutTime = DateTime.Now, Totals = Convert.ToInt32(hb) }; db.Oders.AddObject(model); db.SaveChanges(); } //加入数据库操作 str = "1|发送红包成功|" + hb; } else { string err_code = tdata.GetValue("err_code").ToString(); string err_code_des = tdata.GetValue("err_code_des").ToString(); using (WXDBEntities db = new WXDBEntities()) { OperateLoginfo mt = new OperateLoginfo() { Title = "五洲国际红包", Descs = err_code, AddTime = DateTime.Now, UpdateTime = DateTime.Now, Status = 0, Orders = 0, Extent1 = "", Extent2 = err_code_des, LogType = 1 }; db.OperateLoginfo.AddObject(mt); db.SaveChanges(); } //红包发送失败 str = "2|发送红包失败!"; } } else { using (WXDBEntities db = new WXDBEntities()) { OperateLoginfo mt = new OperateLoginfo() { Title = "五洲国际红包", Descs = return_msg, AddTime = DateTime.Now, UpdateTime = DateTime.Now, Status = 0, Orders = 0, Extent1 = "", Extent2 = "", LogType = 2 }; db.OperateLoginfo.AddObject(mt); db.SaveChanges(); } str = "3|发送红包失败"; } return(str); } catch (Exception ex) { using (WXDBEntities db = new WXDBEntities()) { OperateLoginfo mt = new OperateLoginfo() { Title = "五洲国际红包", Descs = ex.Message, AddTime = DateTime.Now, UpdateTime = DateTime.Now, Status = 0, Orders = 0, Extent1 = hb, Extent2 = "", LogType = 6 }; db.OperateLoginfo.AddObject(mt); db.SaveChanges(); } return("4|获取失败!"); } } else { str = "2|发送红包失败!"; return(str); } #endregion }
protected void Page_Load(object sender, EventArgs e) { Log.Info("回调函数", "进入"); WxPayData infos = GetNotifyData(); string out_trade_no = infos.GetValue("out_trade_no").ToString(); //财付通订单号 string transaction_id = infos.GetValue("transaction_id").ToString(); //金额,以分为单位 string total_fee = infos.GetValue("total_fee").ToString(); ////如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee //string discount = resHandler.GetParameter("discount"); //支付结果 string trade_state = infos.GetValue("result_code").ToString(); string stropid = infos.GetValue("openid").ToString();//openid //string total_fee = XmlMap["total_fee"].ToString();//总价格 //即时到账 Log.Info("回调函数", trade_state); if ("SUCCESS".Equals(trade_state)) { Log.Info("回调函数", "成功"); //------------------------------ //处理业务开始 //------------------------------ using (WXDBEntities db = new WXDBEntities()) { string tmpordids = out_trade_no; Oders order = db.Oders.Where(s => s.OrderId == tmpordids && s.OrderStatus != 1).FirstOrDefault(); if (order != null) { order.OrderStatus = 1;//支付成功 order.UpdateTime = DateTime.Now; OperateLoginfo model = new OperateLoginfo() { Title = "支付成功", Descs = "", AddTime = DateTime.Now, UpdateTime = DateTime.Now, Status = 0, Orders = 0, Extent1 = "", Extent2 = "", LogType = 1 //支付日志 }; db.OperateLoginfo.AddObject(model); db.SaveChanges(); } else { Log.Info("回调函数", "不存在数据"); } } //处理数据库逻辑 //注意交易单不要重复处理 //注意判断返回金额 //------------------------------ //处理业务完毕 //------------------------------ //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知 Response.Write("success 后台通知成功"); } else { Log.Info("回调函数", "失败"); using (WXDBEntities db = new WXDBEntities()) { OperateLoginfo model = new OperateLoginfo() { Title = "支付失败", Descs = out_trade_no, AddTime = DateTime.Now, UpdateTime = DateTime.Now, Status = 0, Orders = 0, Extent1 = "", Extent2 = "", LogType = 2 //支付日志 }; db.OperateLoginfo.AddObject(model); db.SaveChanges(); } Response.Write("支付失败"); } //回复服务器处理成功 Response.Write("success"); }