/// <summary> /// 查询接口 /// </summary> /// <param name="mchid"></param> /// <param name="orderid"></param> /// <param name="sign"></param> /// <returns></returns> public async Task <QueryReturn> Query(string mchid, string orderid) { QueryReturn r = new QueryReturn(); if (mchid != DB.MchId) { r.ReturnMsg = "商户号不存在"; return(r); } Pay_order order = DB.Context.From <Pay_order>().Where(p => p.Order_id == orderid).ToFirstDefault(); if (order == null || string.IsNullOrEmpty(order.Order_id)) { r.ReturnMsg = "订单不存在"; return(r); } if (order.Status == 1) { r.ReturnMsg = "ok"; r.IsPay = true; r.OrderNumber = order.Order_id; r.SerialNumber = order.Plat_order_id; r.Totalfee = order.Pay_amount; r.Attach = order.Attach; return(r); } else { Pay_mch mch = OnlinePay.GetMch(order.Mch_id); if (mch == null) { r.ReturnMsg = "平台商户信息错误"; return(r); } Pay_plat plat = OnlinePay.GetPlat(mch.Plat_id); if (plat == null) { r.ReturnMsg = "平台渠道信息错误"; return(r); } OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(plat.Plat_class), plat, mch); r = await onlinepay.OrderQuery(order.Order_id); if (r.ReturnMsg == "ok" && r.IsPay) { order.Status = 1; if (r.Totalfee > 0) { order.Pay_amount = r.Totalfee; } order.Finish_time = DateTime.Now.ToTimeStamp(); DB.Context.Save(order); } return(r); } }
/// <summary> /// 查询接口 /// </summary> /// <param name="mchid"></param> /// <param name="orderid"></param> /// <param name="sign"></param> /// <returns></returns> public async Task <QueryReturnModel> Query(string mchid, string orderid) { QueryReturnModel r = new QueryReturnModel(); if (mchid != WebConfig.MchId) { Dos.Common.LogHelper.Debug("商户号不存在"); r.ReturnMsg = "商户号不存在"; return(r); } PayOrder order = DbContext._.Db.From <PayOrder>().Where(p => p.Order_id == orderid.SqlFilters()).ToFirstDefault(); if (order == null || string.IsNullOrEmpty(order.Order_id)) { Dos.Common.LogHelper.Debug("订单不存在"); r.ReturnMsg = "订单不存在"; return(r); } if (order.Status == 1) { r.ReturnMsg = "ok"; r.IsPay = true; r.OrderNumber = order.Order_id; r.SerialNumber = order.Plat_order_id; r.Totalfee = order.Pay_amount; r.Attach = order.Attach; return(r); } else { PayMch mch = OnlinePay.GetMch(order.Mch_id); if (mch == null) { Dos.Common.LogHelper.Debug("平台商户信息错误"); r.ReturnMsg = "平台商户信息错误"; return(r); } PayPlat plat = OnlinePay.GetPlat(mch.Plat_id); if (plat == null) { Dos.Common.LogHelper.Debug("平台渠道信息错误"); r.ReturnMsg = "平台渠道信息错误"; return(r); } try { OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(plat.Plat_class), plat, mch); r = await onlinepay.OrderQuery(order.Order_id); } catch (Exception ex) { Dos.Common.LogHelper.Debug("第三方查询下单失败1:" + ex.Message); throw ex; } try { if (r.ReturnMsg == "ok" && r.IsPay) { order.Attach(EntityState.Modified); order.Status = 1; if (r.Totalfee > 0) { order.Pay_amount = r.Totalfee; } order.Finish_time = DateTime.Now.ToTimeStamp(); DbContext._.Db.Save(order); } else { Dos.Common.LogHelper.Debug("第三方查询结果:ReturnMsg " + r.ReturnMsg + "## IsPay " + r.IsPay); } } catch (Exception ex) { Dos.Common.LogHelper.Debug("第三方查询下单失败2:" + ex.Message); throw ex; } return(r); } }