public IActionResult CompleteOrder(int id) { Order entity = Order.Find(Order._.Id == id); if (entity == null) { tip.Message = "系统找不到本记录!"; return(Json(tip)); } if (entity.OrderStatus != Utils.OrdersState[1] || entity.PaymentStatus != Utils.PaymentState[1] || string.IsNullOrEmpty(entity.DeliverNO)) { tip.Message = "只有已经确认、支付、发货的订单,才能设置成订单已完成!"; return(Json(tip)); } entity.OrderStatus = Utils.OrdersState[2]; entity.LastModTime = DateTime.Now; entity.Update(); //执行分销 decimal totalRechargePrice = entity.TotalPrice; Member my = Member.FindById(entity.UId); //自己返现 if (my.Roles.CashBack > 0) { decimal myreward = entity.TotalPrice * my.Roles.CashBack / 100; //totalRechargePrice = totalRechargePrice - myreward;//减去自己的计算 Member.ToCashBack(my.Id, myreward, $"我的销售返现,消费:¥{entity.TotalPrice.ToString("N2")};返现比例({my.Roles.CashBack.ToString("N2")}%),共:¥{myreward.ToString("N2")}", entity.Id, entity.OrderNum); } if (my.Parent > 0) { Member.SaleCommission(my.Id, totalRechargePrice, my.Parent, entity.OrderNum, 1, entity.Id, entity.TotalPrice); } if (my.Grandfather > 0) { Member.SaleCommission(my.Id, totalRechargePrice, my.Grandfather, entity.OrderNum, 2, entity.Id, entity.TotalPrice); } Admin admin = Admin.GetMyInfo(); //写入记录 OrderLog log = new OrderLog() { AddTime = DateTime.Now, Actions = "管理员设置订单【已完成】", OrderId = entity.Id, OrderNum = entity.OrderNum, UId = -admin.Id }; log.Insert(); Admin.WriteLogActions($"完成订单(id:{entity.Id});"); tip.Message = "确认订单已完成成功!"; tip.Status = JsonTip.SUCCESS; tip.ReturnUrl = "/AdminCP/Order/EditOrder/" + entity.Id; return(Json(tip)); }
public IActionResult DoChangeOrderDeliver(int id, string DeliverType = "", string DeliverNO = "") { Order entity = Order.Find(Order._.Id == id); if (entity == null) { tip.Message = "系统找不到本记录!"; return(Json(tip)); } if (entity.PaymentStatus == Utils.PaymentState[0]) { tip.Message = "非已支付订单,无法修改订单配送状态!"; return(Json(tip)); } if (entity.OrderStatus == Utils.OrdersState[2] || entity.OrderStatus == Utils.OrdersState[3]) { tip.Message = "订单状态错误,无法修改订单配送状态!"; return(Json(tip)); } if (string.IsNullOrWhiteSpace(DeliverNO)) { tip.Message = "请输入运单号!"; return(Json(tip)); } if (entity.DeliverType == DeliverType && entity.DeliverNO == DeliverNO) { tip.Message = "物流信息并无修改!"; return(Json(tip)); } entity.DeliverType = DeliverType; entity.DeliverNO = DeliverNO; entity.DeliverStatus = Utils.DeliverState[2]; entity.LastModTime = DateTime.Now; entity.Update(); Admin admin = Admin.GetMyInfo(); //写入记录 OrderLog log = new OrderLog() { AddTime = DateTime.Now, Actions = $"发货:物流:{entity.DeliverType};订单号:{entity.DeliverNO}", OrderId = entity.Id, OrderNum = entity.OrderNum, UId = -admin.Id }; log.Insert(); Admin.WriteLogActions($"修改订单发货状态:物流:{entity.DeliverType};订单号:{entity.DeliverNO};"); tip.Message = "修改订单物流配送成功!"; tip.Status = JsonTip.SUCCESS; tip.ReturnUrl = "/AdminCP/Order/EditOrder/" + entity.Id; return(Json(tip)); }
public IActionResult DoChangeOrderFare(int id, decimal fare) { Order entity = Order.Find(Order._.Id == id); if (entity == null) { tip.Message = "系统找不到本记录!"; return(Json(tip)); } if (entity.PaymentStatus != Utils.PaymentState[0]) { tip.Message = "非未支付订单,无法修改订单运费!"; return(Json(tip)); } if (fare < 0) { tip.Message = "运费不能小于0!"; return(Json(tip)); } entity.Fare = fare; entity.TotalPay = entity.TotalPrice + fare; entity.LastModTime = DateTime.Now; entity.Update(); Admin admin = Admin.GetMyInfo(); //写入记录 OrderLog log = new OrderLog() { AddTime = DateTime.Now, Actions = $"管理员修改订单运费为:¥{entity.Fare.ToString("N2")}", OrderId = entity.Id, OrderNum = entity.OrderNum, UId = -admin.Id }; log.Insert(); Admin.WriteLogActions($"修改订单运费(id:{entity.Id},fare:{entity.Fare});"); tip.Message = "修改订单运费成功!"; tip.Status = JsonTip.SUCCESS; tip.ReturnUrl = "/AdminCP/Order/EditOrder/" + entity.Id; return(Json(tip)); }
public IActionResult ConfirmOrder(int id) { Order entity = Order.Find(Order._.Id == id); if (entity == null) { tip.Message = "系统找不到本记录!"; return(Json(tip)); } if (entity.OrderStatus != Utils.OrdersState[0]) { tip.Message = "非未确认订单,无法确认订单!"; return(Json(tip)); } entity.OrderStatus = Utils.OrdersState[1]; entity.LastModTime = DateTime.Now; entity.Update(); Admin admin = Admin.GetMyInfo(); //写入记录 OrderLog log = new OrderLog() { AddTime = DateTime.Now, Actions = "管理员确认订单", OrderId = entity.Id, OrderNum = entity.OrderNum, UId = -admin.Id }; log.Insert(); Admin.WriteLogActions($"确认订单(id:{entity.Id});"); tip.Message = "确认订单成功!"; tip.Status = JsonTip.SUCCESS; tip.ReturnUrl = "/AdminCP/Order/EditOrder/" + entity.Id; return(Json(tip)); }
/// <summary> /// 微信支付异步通知 /// </summary> /// <returns></returns> public IActionResult notify() { XTrace.WriteLine("微信支付异步通知开始:"); try { ResponseHandler resHandler = new ResponseHandler(null); string return_code = resHandler.GetParameter("return_code"); string return_msg = resHandler.GetParameter("return_msg"); //配置 Core.Config cfg = Core.Config.GetSystemConfig(); string appId = cfg.WXAppId; // ConfigurationManager.AppSettings["WeixinAppId"]; string appSecrect = cfg.WXAppSecret; // ConfigurationManager.AppSettings["WeixinAppSecrect"]; string wxmchId = cfg.MCHId; // ConfigurationManager.AppSettings["WeixinMCHId"]; string wxmchKey = cfg.MCHKey; // ConfigurationManager.AppSettings["WeixinMCHKey"]; TenPayV3Info TenPayV3Info = new TenPayV3Info(appId, appSecrect, wxmchId, wxmchKey, Utils.GetServerUrl() + "/wxpayment/notify", Utils.GetServerUrl() + "/wxpayment/notify"); string res = null; resHandler.SetKey(TenPayV3Info.Key); //验证请求是否从微信发过来(安全) if (resHandler.IsTenpaySign() && return_code.ToUpper() == "SUCCESS") { res = "success"; //正确的订单处理 //直到这里,才能认为交易真正成功了,可以进行数据库操作,但是别忘了返回规定格式的消息! string out_trade_no = resHandler.GetParameter("out_trade_no"); //商户订单号 XTrace.WriteLine("微信异步通知订单号:" + out_trade_no + ";" + JsonConvert.SerializeObject(resHandler)); OnlinePayOrder payOrder = OnlinePayOrder.Find(OnlinePayOrder._.PayOrderNum == out_trade_no); if (payOrder == null) { XTrace.WriteLine($"支付成功,但是支付订单不存在:{out_trade_no}"); res = "wrong";//错误的订单处理 } else { if (payOrder.PaymentStatus == Utils.PaymentState[0]) { //更新支付订单 payOrder.PaymentStatus = Utils.PaymentState[1]; payOrder.ReceiveTime = DateTime.Now; payOrder.IsOK = 1; payOrder.Update(); //获取订单 Order order = Order.Find(Order._.OrderNum == payOrder.OrderNum); if (order != null) { order.PaymentStatus = Utils.PaymentState[1]; order.PayType = "微信支付"; if (order.MyType == (int)Utils.MyType.分销商认证) { order.OrderStatus = Utils.OrdersState[2]; } order.Update(); //如果是属于升级会员的,那要修改会员状态 if (order.MyType == (int)Utils.MyType.分销商认证 && order.OrderType > 0) { Member he = Member.FindById(order.UId); if (he.RoleId != order.OrderType) { he.RoleId = order.OrderType; he.IsVerifySellers = 1; he.Update(); } } //写入订单记录 OrderLog log = new OrderLog(); log.AddTime = DateTime.Now; log.OrderId = order.Id; log.OrderNum = order.OrderNum; log.UId = order.UId; log.Actions = "微信支付成功;订单号:" + order.OrderNum + ";金额:" + order.TotalPay.ToString("N2"); log.Insert(); } } } } else { res = "wrong";//错误的订单处理 } #region 记录日志 XTrace.WriteLine($"微信支付回调处理结果:{res}"); #endregion string xml = string.Format(@"<xml> <return_code><![CDATA[{0}]]></return_code> <return_msg><![CDATA[{1}]]></return_msg> </xml>", return_code, return_msg); return(Content(xml, "text/xml")); } catch (Exception ex) { new WeixinException(ex.Message, ex); throw; } }
public ReJson DoPayOrder(string ordernum, string random = "", string timeStamp = "", string signature = "") { //获取订单 Order entity = Order.Find(Order._.OrderNum == ordernum); if (entity == null) { //reJson.code = 40000; //reJson.message = "系统找不到本订单!"; //return reJson; return(new ReJson(40000, "系统找不到本订单!")); } //判断订单状态 if (entity.OrderStatus == Utils.OrdersState[3]) { //reJson.code = 40000; //reJson.message = "已完成订单不允许支付!"; //return reJson; return(new ReJson(40000, "已完成订单不允许支付!")); } if (entity.PaymentStatus != Utils.PaymentState[0]) { //reJson.code = 40000; //reJson.message = "当前订单支付状态不允许支付!"; //return reJson; return(new ReJson(40000, "当前订单支付状态不允许支付!")); } //获取用户并判断是否是已经注册用户 Member my = Member.FindById(entity.UId); if (my == null || string.IsNullOrEmpty(my.WeixinAppOpenId)) { //reJson.code = 40000; //reJson.message = "用户状态错误,无法使用本功能!"; //return reJson; return(new ReJson(40000, "用户状态错误,无法使用本功能!")); } //开始生成支付订单 OnlinePayOrder model = new OnlinePayOrder(); model.OrderId = entity.Id; model.OrderNum = entity.OrderNum; model.PayId = 1; model.PaymentNotes = "微信支付"; model.PaymentStatus = Utils.PaymentState[0]; model.PayOrderNum = Utils.GetOrderNum();//在线支付订单的订单号 model.PayType = "微信支付"; model.TotalPrice = entity.TotalPay; model.TotalQty = entity.TotalQty; model.UId = entity.UId; model.IP = Utils.GetIP(); model.IsOK = 0; model.AddTime = DateTime.Now; model.Insert(); //写入日志 OrderLog log = new OrderLog(); log.AddTime = DateTime.Now; log.OrderId = entity.Id; log.OrderNum = entity.OrderNum; log.UId = entity.UId; log.Actions = "用户使用微信支付;支付订单号:" + model.PayOrderNum; log.Insert(); Core.Config cfg = Core.Config.GetSystemConfig(); string appId = cfg.WXAppId; // ConfigurationManager.AppSettings["WeixinAppId"]; string appSecrect = cfg.WXAppSecret; // ConfigurationManager.AppSettings["WeixinAppSecrect"]; string wxmchId = cfg.MCHId; // ConfigurationManager.AppSettings["WeixinMCHId"]; string wxmchKey = cfg.MCHKey; // ConfigurationManager.AppSettings["WeixinMCHKey"]; TenPayV3Info TenPayV3Info = new TenPayV3Info(appId, appSecrect, wxmchId, wxmchKey, Utils.GetServerUrl() + "/wxpayment/notify", Utils.GetServerUrl() + "/wxpayment/notify"); TenPayV3Info.TenPayV3Notify = Utils.GetServerUrl() + "/wxpayment/notify"; XTrace.WriteLine("微信支付异步通知地址:" + TenPayV3Info.TenPayV3Notify); //创建支付应答对象 RequestHandler packageReqHandler = new RequestHandler(null); var sp_billno = DateTime.Now.ToString("HHmmss") + TenPayV3Util.BuildRandomStr(26);//最多32位 var nonceStr = TenPayV3Util.GetNoncestr(); string rtimeStamp = Utils.GetTimeStamp(); //创建请求统一订单接口参数 var xmlDataInfo = new TenPayV3UnifiedorderRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, entity.Title, model.PayOrderNum, (int)(entity.TotalPay * 100), Utils.GetIP(), TenPayV3Info.TenPayV3Notify, Senparc.Weixin.TenPay.TenPayV3Type.JSAPI, my.WeixinAppOpenId, TenPayV3Info.Key, nonceStr); //返回给微信的请求 RequestHandler res = new RequestHandler(null); try { //调用统一订单接口 var result = TenPayV3.Unifiedorder(xmlDataInfo); XTrace.WriteLine("微信支付统一下单返回:" + JsonConvert.SerializeObject(result)); if (result.return_code == "FAIL") { //reJson.code = 40005; //reJson.message = result.return_msg; //return reJson; return(new ReJson(40005, result.return_msg)); } string nativeReqSign = res.CreateMd5Sign("key", TenPayV3Info.Key); //https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=3 //paySign = MD5(appId=wxd678efh567hg6787&nonceStr=5K8264ILTKCH16CQ2502SI8ZNMTM67VS&package=prepay_id=wx2017033010242291fcfe0db70013231072&signType=MD5&timeStamp=1490840662&key=qazwsxedcrfvtgbyhnujmikolp111111) string paySign = Utils.MD5($"appId={TenPayV3Info.AppId}&nonceStr={nonceStr}&package=prepay_id={result.prepay_id}&signType=MD5&timeStamp={rtimeStamp}&key={TenPayV3Info.Key}").ToUpper(); string package = $"prepay_id={result.prepay_id}"; dynamic detail = new { timeStamp = rtimeStamp, nonceStr = nonceStr, package = package, signType = "MD5", paySign = paySign }; //reJson.code = 0; //reJson.message = "下单成功!"; //reJson.detail = detail; //return reJson; return(new ReJson(40000, "下单成功!", detail)); } catch (Exception ex) { res.SetParameter("return_code", "FAIL"); res.SetParameter("return_msg", "统一下单失败"); XTrace.WriteLine($"统一下单失败:{ex.Message}"); //reJson.code = 40005; //reJson.message = "统一下单失败,请联系管理员!"; return(new ReJson(40005, "统一下单失败,请联系管理员!")); } }