Commit 41707d5d authored by 吴春's avatar 吴春

提交代码

parent 2ae59b01
using VT.FW.DB;
using Mall.Common.Enum.MallBase;
using System;
using System.Collections.Generic;
using System.Text;
namespace Mall.Model.Entity.BaseSetUp
{
/// <summary>
/// 文件上传位置
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Video_Store
{
public int ID { get; set; }
/// <summary>
/// 商户id
/// </summary>
public int TenantId { get; set; }
/// <summary>
/// 小程序id
/// </summary>
public int MallBaseId { get; set; }
/// <summary>
/// 0-否1-是
/// </summary>
public int IsDefault { get; set; }
public int Status { get; set; }
public DateTime CreateDate { get; set; }
public DateTime UpdateDate { get; set; }
///// <summary>
///// 空间名称
///// </summary>
//public string Bucket { get; set; }
/// <summary>
/// 存储位置,1-腾讯云,2-阿里,3-其他
/// </summary>
public StoreTypeEnum StoreType { get; set; }
/// <summary>
/// 所属区域
/// </summary>
public string Region { get; set; }
///// <summary>
///// 自定义域名
///// </summary>
//public string CustomDomain { get; set; }
/// <summary>
/// 自定义域名
/// </summary>
public string SecretKey { get; set; }
/// <summary>
/// 自定义域名
/// </summary>
public string SecretId { get; set; }
}
}
......@@ -36,7 +36,7 @@ namespace Mall.Module.BaseSetUp
/// </summary>
private readonly RB_Express_ConfigRepository express_ConfigRepository = new RB_Express_ConfigRepository();
private readonly RB_Video_StoreRepository videoStoreRepository = new RB_Video_StoreRepository();
#region 基础设置
/// <summary>
......@@ -1418,6 +1418,52 @@ namespace Mall.Module.BaseSetUp
#endregion
#region 上传视频设置
/// <summary>
/// 获取上传存储信息
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_Video_Store> GetVideoStoreList(RB_Video_Store query)
{
return videoStoreRepository.GetListRepository(query);
}
/// <summary>
/// 新增/修改存储位置
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool AddOrUpdateVideoStore(RB_Video_Store model)
{
bool result = false;
int id = 0;
if (model.ID == 0)
{
id = videoStoreRepository.Insert(model);
result = id > 0;
}
else
{
id = model.ID;
result = videoStoreRepository.Update(model);
}
//判断当前的是否设置成默认没有
if (model.IsDefault == 1 && result)//将其他的默认赋值成0
{
Dictionary<string, object> fileds = new Dictionary<string, object>() { { nameof(RB_Video_Store.IsDefault), 0 }, };
List<WhereHelper> whereHelpers = new List<WhereHelper>()
{
new WhereHelper(){ FiledName=nameof(RB_Video_Store.TenantId),FiledValue=model.TenantId ,OperatorEnum=OperatorEnum.Equal},
new WhereHelper(){ FiledName=nameof(RB_Video_Store.MallBaseId),FiledValue=model.MallBaseId, OperatorEnum=OperatorEnum.Equal },
new WhereHelper(){ FiledName=nameof(RB_Video_Store.ID),FiledValue=id, OperatorEnum=OperatorEnum.NotEqual },
};
storeRepository.Update(fileds, whereHelpers);
}
return result;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mall.Model.Entity.BaseSetUp;
namespace Mall.Repository.BaseSetUp
{
public class RB_Video_StoreRepository:BaseRepository<RB_Video_Store>
{
/// <summary>
/// 表名称
/// </summary>
public string TableName { get { return nameof(RB_Video_Store); } }
/// <summary>
/// 获取上传视频存储信息
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_Video_Store> GetListRepository(RB_Video_Store query)
{
StringBuilder builder = new StringBuilder();
builder.Append($" SELECT * FROM {TableName} WHERE {nameof(RB_Video_Store.Status)}=0");
if (query != null)
{
if (query.TenantId > 0)
{
builder.Append($" AND {nameof(RB_Video_Store.TenantId)}={query.TenantId}");
}
if (query.MallBaseId > 0)
{
builder.Append($" AND {nameof(RB_Video_Store.MallBaseId)}={query.MallBaseId}");
}
if (query.StoreType > 0)
{
builder.Append($" AND {nameof(RB_Video_Store.StoreType)}={(int)query.StoreType}");
}
if (query.IsDefault > 0)
{
builder.Append($" AND {nameof(RB_Video_Store.IsDefault)}={query.IsDefault}");
}
}
return Get<RB_Video_Store>(builder.ToString()).ToList();
}
}
}
......@@ -108,6 +108,90 @@ namespace Mall.WebApi.App_Code
}
}
/// <summary>
/// 支付
/// </summary>
/// <returns></returns>
public BaseResult AllNotify(IHttpContextAccessor accessor, int MallBaseId, int TenantId)
{
try
{
var res = new ResponseHandler(accessor);
var tradeType = res.GetParameter("trade_type");
LogHelper.WriteInfo("Notify支付回调:res-" + res.ToString());
RB_MiniProgram_Extend model = new RB_MiniProgram_Extend();
model = programModule.GetMiniProgramModule(new RB_MiniProgram_Extend { MallBaseId = MallBaseId, TenantId = TenantId });
res.SetKey(model.WeChatApiSecret);
//判断签名
if (res.IsWXsign(out string error))
{
#region 参数
var returnCode = res.GetParameter("return_code");
//返回信息,如非空,为错误原因签名失败参数格式校验错误
var returnMsg = res.GetParameter("return_msg");
var appid = res.GetParameter("appid");
//以下字段在 return_code 为 SUCCESS 的时候有返回--------------------------------
var mchId = res.GetParameter("mch_id");
var deviceInfo = res.GetParameter("device_info");
var nonceStr = res.GetParameter("nonce_str");
var resultCode = res.GetParameter("result_code");
var errCode = res.GetParameter("err_code");
var errCodeDes = res.GetParameter("err_code_des");
//以下字段在 return_code 和 result_code 都为 SUCCESS 的时候有返回---------------
var openid = res.GetParameter("openid");
//Y-关注,N-未关注,仅在公众账号类型支付有效
var isSubscribe = res.GetParameter("is_subscribe");
//银行类型,采用字符串类型的银行标识
var bankType = res.GetParameter("bank_type");
var totalFee = res.GetParameter("total_fee");
//货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
var feeType = res.GetParameter("fee_type");
//微信支付订单号
var transactionId = res.GetParameter("transaction_id");
//商户系统的订单号,与请求一致。
var outTradeNo = res.GetParameter("out_trade_no");
var attach = res.GetParameter("attach");
//格 式 为yyyyMMddhhmmss
var timeEnd = res.GetParameter("time_end");
#endregion
//支付成功
if (!outTradeNo.Equals("") && returnCode.Equals("SUCCESS") && resultCode.Equals("SUCCESS"))
{
return new BaseResult()
{
IsSuccess = true,
Data = new Dictionary<string, string>
{
{"sOrderNo", outTradeNo},
{"sTradeNo", transactionId},
{"dPrice", totalFee},
{"sPayerOpenID", openid},
{"bIsRecharge", attach},
{"OrderPayType", tradeType},
{"PayDate",timeEnd }
}
};
}
else
{
LogHelper.WriteInfo("Notify支付回调:returnMsg-" + returnMsg);
}
}
else
{
LogHelper.Write(null, "Notify签名验证失败:");
}
}
catch (Exception ex)
{
LogHelper.Write(ex, "Notify支付错误:");
}
return new BaseResult() { IsSuccess = false };
}
......
......@@ -17,7 +17,8 @@ using Newtonsoft.Json.Linq;
namespace Mall.WebApi.Controllers.AppletWeChat
{
[Route("api/[controller]/[action]")]
[Route("api/[controller]/[action]/{MallBaseId?}/{TenantId?}")]
[ApiExceptionFilter]
[ApiController]
[EnableCors("AllowCors")]
......@@ -61,6 +62,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
decimal dPaid = Convert.ToDecimal(dic["dPrice"]) / 100;
string sPayerOpenID = dic["sPayerOpenID"];
int UserId = Convert.ToInt32(dic["bIsRecharge"]);
string TransactionId = dic["sTradeNo"];
string PayType = dic["OrderPayType"];
......@@ -92,6 +94,58 @@ namespace Mall.WebApi.Controllers.AppletWeChat
}
/// <summary>
/// 订单支付回调
/// </summary>
/// <returns></returns>
[HttpGet]
[HttpPost]
public string AllNotify(int MallBaseId, int TenantId)
{
var req = new RequestHandler();
App_Code.PayUtil PayUtil = new App_Code.PayUtil();
var result = PayUtil.AllNotify(_accessor, MallBaseId, TenantId);
if (result.IsSuccess)
{
var dic = ((Dictionary<string, string>)result.Data);
//开始回写订单状态
lock (_lock)
{
string sOrderNo = dic["sOrderNo"];//订单号 时间挫+OrderId
int OrderId = Convert.ToInt32(sOrderNo[17..]);
decimal dPaid = Convert.ToDecimal(dic["dPrice"]) / 100;
string sPayerOpenID = dic["sPayerOpenID"];
int UserId = Convert.ToInt32(dic["bIsRecharge"]);
string TransactionId = dic["sTradeNo"];
string PayType = dic["OrderPayType"];
DateTime PayDate = DateTime.ParseExact(dic["PayDate"], "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);//转换时间// Convert.ToDateTime(dic["PayDate"]);
#region 新增订单支付信息
userCommonModule.InsertOrderPayInfo(UserId, OrderId, sOrderNo, TransactionId, Common.Enum.Goods.OrderPayTypeEnum.WeChatPay, PayType, dPaid, PayDate, 0);
#endregion
}
//告诉微信我们已经处理成功,不需要再调用我们的接口了
req.SetParameter("return_code", "SUCCESS");
req.SetParameter("return_msg", "OK");
var reqXml = req.ParseXml();
return reqXml;
// return ApiResult.Success("", reqXml);
}
else
{
req.SetParameter("return_code", "FAIL");
req.SetParameter("return_msg", "订单失败");
var reqXmlFAIL = req.ParseXml();
LogHelper.Write(null, "Notify返回信息:" + reqXmlFAIL);
return reqXmlFAIL;
// return ApiResult.Failed("", reqXmlFAIL);
}
}
/// <summary>
......
......@@ -93,7 +93,8 @@ namespace Mall.WebApi.Controllers.AppletWeChat
switch ((int)demodel.OrderPayType)
{
case 1://微信支付 _accessor.HttpContext.Connection.RemoteIpAddress.ToString()
sPayInfo = App_Code.PayUtil.GetMinUnifiedOrder(sOrderNo, demodel.GoodsName, model.Income.Value, model.UserId.ToString(), demodel.OpenId, (model.MallBaseId==6&&model.TenantId==16)? "https://mallapi.oytour.com/api/WeChatNotify/NotifyZhouTian" : Config.sTenpayNotify, miniProgram, _accessor, System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.ToString());
//(model.MallBaseId==6&&model.TenantId==16)? "https://mallapi.oytour.com/api/WeChatNotify/NotifyZhouTian" :
sPayInfo = App_Code.PayUtil.GetMinUnifiedOrder(sOrderNo, demodel.GoodsName, model.Income.Value, model.UserId.ToString(), demodel.OpenId, (Config.sTenpayNotify+"/"+ model.MallBaseId+"/"+ model.TenantId), miniProgram, _accessor, System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.ToString());
break;
default:
break;
......
......@@ -1328,5 +1328,101 @@ namespace Mall.WebApi.Controllers.MallBase
}
#endregion
#region 上传视频设置
public ApiResult GetVideoStoreList()
{
var parms = RequestParm;
var query = new RB_Video_Store();
query.TenantId = UserInfo.TenantId;
query.MallBaseId = parms.MallBaseId;
var list = mallBaseModule.GetVideoStoreList(query);
return ApiResult.Success("获取成功", list);
}
/// <summary>
/// 新增/修改上传设置
/// </summary>
/// <returns></returns>
public ApiResult AddOrUpdateVideoStore()
{
var parms = RequestParm;
var query = JsonConvert.DeserializeObject<RB_Video_Store>(RequestParm.msg.ToString());
query.TenantId = UserInfo.TenantId;
query.MallBaseId = parms.MallBaseId;
if (query == null)
{
return ApiResult.Failed("请传入上传设置信息");
}
else
{
if ((int)query.StoreType == 0)
{
return ApiResult.Failed("请选择存储位置");
}
if (query.ID == 0)
{
query.CreateDate = System.DateTime.Now;
}
query.UpdateDate = System.DateTime.Now;
bool result = mallBaseModule.AddOrUpdateVideoStore(query);
if (result)
{
return ApiResult.Success("上传设置保存成功");
}
else
{
return ApiResult.Failed("上传设置保存失败");
}
}
}
/// <summary>
/// 获取上传信息的详情
/// </summary>
/// <returns></returns>
public ApiResult GetVideoStoreDetail()
{
var parms = RequestParm;
var query = new RB_Video_Store();
query.TenantId = UserInfo.TenantId;
query.MallBaseId = parms.MallBaseId;
var model = mallBaseModule.GetVideoStoreList(query).FirstOrDefault();
if (model == null)
{
model = new RB_Video_Store();
}
return ApiResult.Success("获取成功", model);
}
/// <summary>
/// 获取默认上传信息的详情
/// </summary>
/// <returns></returns>
public ApiResult GetDefaultVideoStore()
{
var parms = RequestParm;
var query = new RB_Video_Store();
query.TenantId = UserInfo.TenantId;
query.MallBaseId = parms.MallBaseId;
var model = mallBaseModule.GetVideoStoreList(query).Where(x => x.IsDefault == 1).FirstOrDefault();
if (model == null)
{
model = new RB_Video_Store();
}
return ApiResult.Success("获取成功", model);
}
#endregion
}
}
\ 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