Commit b4f66bd9 authored by liudong1993's avatar liudong1993

微信支付回调

parent 3f4489f3
using Mall.Common.AOP;
using Mall.Common.Enum.User;
using System;
using System.Collections.Generic;
using System.Text;
namespace Mall.Model.Entity.Product
{
/// <summary>
/// 订单支付信息表实体
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_Online_Trade
{
/// <summary>
/// Id
/// </summary>
public int Id
{
get;
set;
}
/// <summary>
/// 用户id
/// </summary>
public int? User_Id
{
get;
set;
}
/// <summary>
/// 类型 1收款 2退款
/// </summary>
public int? Type
{
get;
set;
}
/// <summary>
/// 订单id
/// </summary>
public int? OrderId
{
get;
set;
}
/// <summary>
/// 订单号
/// </summary>
public string Out_Trade_No
{
get;
set;
}
/// <summary>
/// 微信支付订单号
/// </summary>
public string Transaction_Id
{
get;
set;
}
/// <summary>
/// 支付类型 枚举 1微信 2支付宝 3银行卡
/// </summary>
public Common.Enum.Goods.OrderPayTypeEnum? PayWay
{
get;
set;
}
/// <summary>
/// 支付调用的是哪种api
/// </summary>
public string PayType
{
get;
set;
}
/// <summary>
/// 交易金额
/// </summary>
public decimal? Money
{
get;
set;
}
/// <summary>
/// 备注附加信息
/// </summary>
public string Remarks
{
get;
set;
}
/// <summary>
/// 0-成功 其他-失败
/// </summary>
public int? Pay_Result
{
get;
set;
}
/// <summary>
/// 交易日期
/// </summary>
public DateTime? Pay_Date
{
get;
set;
}
/// <summary>
/// 是否申请退款 1是
/// </summary>
public int? IsRefund
{
get;
set;
}
/// <summary>
/// 退款总金额
/// </summary>
public decimal? RefundMoney
{
get;
set;
}
/// <summary>
/// 退款状态 1退款中 2退款成功 3退款失败
/// </summary>
public int? RefundStatus
{
get;
set;
}
/// <summary>
/// 退款商户订单号
/// </summary>
public string RefundTrade_Order
{
get;
set;
}
/// <summary>
/// 退款时间
/// </summary>
public DateTime? Refund_Date
{
get;
set;
}
/// <summary>
/// 绑定财务单据id
/// </summary>
public int? FinanceId
{
get;
set;
}
/// <summary>
/// 商户号
/// </summary>
public int TenantId
{
get;
set;
}
/// <summary>
/// 小程序id
/// </summary>
public int MallBaseId
{
get;
set;
}
/// <summary>
/// CreateDate
/// </summary>
public DateTime? CreateDate
{
get;
set;
}
}
}
using Mall.Common.AOP;
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
namespace Mall.Model.Extend.Product
{
/// <summary>
/// 订单支付信息表扩展实体
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_Online_Trade_Extend : RB_Goods_Online_Trade
{
}
}
......@@ -36,6 +36,20 @@ namespace Mall.Module.User
/// 推荐设置
/// </summary>
private readonly RB_Product_RecommendRepository product_RecommendRepository = new RB_Product_RecommendRepository();
/// <summary>
/// 支付信息
/// </summary>
private readonly RB_Goods_Online_TradeRepository goods_Online_TradeRepository = new RB_Goods_Online_TradeRepository();
/// <summary>
/// 订单信息
/// </summary>
private readonly RB_Goods_OrderRepository goods_OrderRepository = new RB_Goods_OrderRepository();
/// <summary>
/// 会员信息
/// </summary>
private readonly RB_Member_UserRepository member_UserRepository = new RB_Member_UserRepository();
/// <summary>
/// 初始化分销基础配置
......@@ -198,5 +212,64 @@ namespace Mall.Module.User
return true;
}
}
/// <summary>
/// 新增微信支付后增加
/// </summary>
/// <param name="UserId">用户id</param>
/// <param name="OrderId">订单id</param>
/// <param name="Out_Trade_No">订单号</param>
/// <param name="Transaction_Id">交易单号</param>
/// <param name="PayWay">支付方式</param>
/// <param name="PayType">支付类型</param>
/// <param name="Money">金额</param>
/// <param name="Pay_Result">状态</param>
/// <returns></returns>
public bool InsertOrderPayInfo(int UserId, int OrderId,string Out_Trade_No, string Transaction_Id, Common.Enum.Goods.OrderPayTypeEnum PayWay, string PayType, decimal Money,DateTime Time_End, int Pay_Result) {
var umodel = member_UserRepository.GetEntity(UserId);
if (umodel == null) {
return false;
}
bool flag = goods_Online_TradeRepository.Insert(new Model.Entity.Product.RB_Goods_Online_Trade()
{
Id = 0,
User_Id = UserId,
FinanceId = 0,
CreateDate = DateTime.Now,
IsRefund = 2,
MallBaseId = umodel.MallBaseId,
Money = Money,
OrderId = OrderId,
Out_Trade_No = Out_Trade_No,
PayType = PayType,
PayWay = PayWay,
Pay_Date = Time_End,
Pay_Result = Pay_Result,
RefundMoney = 0,
RefundStatus = 0,
RefundTrade_Order = "",
Remarks = umodel.Name + "(id:" + UserId + ")",
TenantId = umodel.TenantId,
Transaction_Id = Transaction_Id,
Type = 1
}) > 0;
if (flag) {
//更新订单信息
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Goods_Order_Extend.OrderStatus),Common.Enum.Goods.OrderStatusEnum.WaitSendGoods},
{ nameof(RB_Goods_Order_Extend.PaymentTime),Time_End},
{ nameof(RB_Goods_Order_Extend.PaymentWay),Common.Enum.Goods.OrderPaymentTypeEnum.OnlinePayment}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Goods_Order_Extend.OrderId),
FiledValue=OrderId,
OperatorEnum=OperatorEnum.Equal
}
};
goods_OrderRepository.Update(keyValues, wheres);
}
return flag;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
using Mall.Model.Extend.Product;
using System.Linq;
using Mall.Model.Entity.User;
namespace Mall.Repository.Product
{
/// <summary>
/// 订单支付信息仓储层
/// </summary>
public class RB_Goods_Online_TradeRepository : RepositoryBase<RB_Goods_Online_Trade>
{
/// <summary>
/// 获取列表
/// </summary>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Goods_Online_Trade_Extend> GetList(RB_Goods_Online_Trade_Extend dmodel)
{
string where = $" 1=1 ";
if (dmodel.TenantId > 0)
{
where += $@" and {nameof(RB_Goods_Online_Trade.TenantId)}={dmodel.TenantId}";
}
if (dmodel.MallBaseId > 0)
{
where += $@" and {nameof(RB_Goods_Online_Trade.MallBaseId)}={dmodel.MallBaseId}";
}
if (dmodel.Type > 0)
{
where += $@" and {nameof(RB_Goods_Online_Trade.Type)}={dmodel.Type}";
}
if (dmodel.User_Id > 0)
{
where += $@" and {nameof(RB_Goods_Online_Trade.User_Id)}={dmodel.User_Id}";
}
string sql = $@"SELECT * FROM RB_Goods_Online_Trade where {where} order by Id asc";
return Get<RB_Goods_Online_Trade_Extend>(sql).ToList();
}
}
}
......@@ -209,7 +209,8 @@ namespace Mall.WebApi.App_Code
{"dPrice", totalFee},
{"sPayerOpenID", openid},
{"bIsRecharge", attach},
{"OrderPayType", tradeType}
{"OrderPayType", tradeType},
{"PayDate",timeEnd }
}
};
}
......
......@@ -6,6 +6,7 @@ using System.Web;
using Mall.Common.API;
using Mall.Common.Pay.WeChatPat;
using Mall.Common.Plugin;
using Mall.Module.User;
using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
......@@ -13,16 +14,14 @@ using Newtonsoft.Json.Linq;
namespace Mall.WebApi.Controllers.AppletWeChat
{
public class WeChatNotifyController : Controller
{
private static object _lock = new object();
UserCommonModule userCommonModule = new UserCommonModule();
/// <summary>
///
/// 订单支付回调
/// </summary>
/// <returns></returns>
[HttpGet]
......@@ -35,49 +34,23 @@ namespace Mall.WebApi.Controllers.AppletWeChat
if (result.IsSuccess)
{
var dic = ((Dictionary<string, string>)result.Data);
//订单No:dic["sOrderNo"]
//支付金额:dic["dPrice"]
//开始回写订单状态
lock (_lock)
{
string sOrderNo = dic["sOrderNo"];
sOrderNo = sOrderNo.Substring(17, 5);
// var model = new REBORN.Module.SellModule.CounponOrderModule().GetEntity(Convert.ToInt32(sOrderNo));//获取订单信息
string sOrderNo = dic["sOrderNo"];//订单号 时间挫+OrderId
int OrderId = Convert.ToInt32(sOrderNo[17..]);
decimal dPaid = Convert.ToDecimal(dic["dPrice"]) / 100;
string sTradeNo = dic["sTradeNo"];
string sPayerOpenID = dic["sPayerOpenID"];
int UserId = Convert.ToInt32(dic["bIsRecharge"]);
string TransactionId = dic["sTradeNo"];
string PayType = dic["OrderPayType"];
DateTime PayDate = Convert.ToDateTime(dic["PayDate"]);
#region 新增订单支付信息
//处理订单信息2020-05-26 逻辑还未处理
#region 处理订单信息
//if (model.PreferPrice == dPaid)
//{
// model.PayType = dic["OrderPayType"].Equals("JSAPI", StringComparison.CurrentCultureIgnoreCase) ? 1 : 2;
// model.sTradeNo = sTradeNo;
// model.sPayerOpenID = sPayerOpenID;
// model.Income = dPaid;
// //查询订单信息
// try
// {
// }
// catch (Exception ex)
// {
// Common.Plugin.LogHelper.Write(ex, string.Format("Notify:infoError"));
// }
// req.SetParameter("return_code", "SUCCESS");
// req.SetParameter("return_msg", "OK");
//}
//else
//{
// req.SetParameter("return_code", "FAIL");
// req.SetParameter("return_msg", "支付金额与订单金额不等");
//}
userCommonModule.InsertOrderPayInfo(UserId, OrderId, sOrderNo, TransactionId, Common.Enum.Goods.OrderPayTypeEnum.WeChatPay, PayType, dPaid, PayDate, 0);
#endregion
}
var reqXml = req.ParseXml();
//告诉微信我们已经处理成功,不需要再调用我们的接口了
......@@ -91,20 +64,6 @@ namespace Mall.WebApi.Controllers.AppletWeChat
LogHelper.Write(null, "Notify返回信息:" + reqXmlFAIL);
return reqXmlFAIL;
}
// return ApiResult.Failed();
//告诉微信我们处理失败,请继续调用我们的接口。好像是会重试8次。
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment