diff --git a/README.md b/README.md
index d825477..5c9ec6c 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
# 在解决方案下运行
docker build -t miaoyu:dev-0.0.3 -f src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile .
docker build -t miaoyu:dev-0.0.4 --build-arg VERSION=7.0 --build-arg TARGET=dev -f src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile .
-docker build -t miaoyuapi:dev-1.2.8 -t miaoyuapi:latest -t 123.207.203.228:92/miaoyuapi:dev-1.2.8 -t 123.207.203.228:92/miaoyuapi:latest --build-arg VERSION=1.2.8 --build-arg TARGET=dev -f src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile .
+docker build -t miaoyuapi:dev-1.3.1 -t miaoyuapi:latest -t 123.207.203.228:92/miaoyuapi:dev-1.3.1 -t 123.207.203.228:92/miaoyuapi:latest --build-arg VERSION=1.2.8 --build-arg TARGET=dev -f src/2-api/HuanMeng.MiaoYu.WebApi/Dockerfile .
docker push 123.207.203.228:92/miaoyuapi:dev-1.2.8
docker push 123.207.203.228:92/miaoyuapi:latest
docker tag miaoyuapi:dev-1.2.7 123.207.203.228:92/miaoyuapi:dev-1.2.7
diff --git a/src/0-core/HuanMeng.DotNetCore/HuanMeng.DotNetCore.csproj b/src/0-core/HuanMeng.DotNetCore/HuanMeng.DotNetCore.csproj
index 0a85b54..471bff9 100644
--- a/src/0-core/HuanMeng.DotNetCore/HuanMeng.DotNetCore.csproj
+++ b/src/0-core/HuanMeng.DotNetCore/HuanMeng.DotNetCore.csproj
@@ -18,6 +18,7 @@
+
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfig.cs b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfig.cs
new file mode 100644
index 0000000..36d3662
--- /dev/null
+++ b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfig.cs
@@ -0,0 +1,44 @@
+using HuanMeng.DotNetCore.MultiTenant;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HuanMeng.MiaoYu.Code.AppExtend
+{
+ ///
+ /// 项目配置
+ ///
+ public class AppConfig
+ {
+ ///
+ /// 数据库连接字符串
+ ///
+ public string ConnectionString { get; set; }
+ ///
+ /// 域名
+ ///
+ public string DomainName { get; set; }
+ ///
+ /// 标识
+ ///
+ public string Identifier { get; set; }
+ ///
+ /// 名称
+ ///
+ public string Name { get; set; }
+ ///
+ /// redis连接字符串
+ ///
+ public string RedisConnectionString { get; set; }
+ ///
+ /// 租户
+ ///
+ public Guid TenantId { get; set; }
+ }
+
+
+
+}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigurationExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigurationExtend.cs
new file mode 100644
index 0000000..d97bddb
--- /dev/null
+++ b/src/0-core/HuanMeng.MiaoYu.Code/AppExtend/AppConfigurationExtend.cs
@@ -0,0 +1,178 @@
+using AgileConfig.Client;
+
+using HuanMeng.DotNetCore.MultiTenant.Contract;
+using HuanMeng.DotNetCore.MultiTenant;
+
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.Hosting;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using XLib.DotNetCore.CacheHelper;
+using Microsoft.Extensions.Configuration;
+using Microsoft.IdentityModel.Protocols;
+
+namespace HuanMeng.MiaoYu.Code.AppExtend
+{
+ ///
+ /// app配置项扩展
+ ///
+ public static class AppConfigurationExtend
+ {
+ ///
+ /// 配置数据
+ ///
+ //public static ConfigClient AppConfigClient { get; set; }
+
+ ///
+ ///
+ ///
+ public static ConfigurationManager ConfigurationManager { get; set; }
+
+ ///
+ ///
+ ///
+ public static ConcurrentDictionary AppConfigs { get; set; } = new ConcurrentDictionary();
+
+ ///
+ /// 获取配置项
+ ///
+ ///
+ ///
+ public static AppConfig GetAppConfig(string domainName)
+ {
+ if (AppConfigs.TryGetValue(domainName, out var appConfig))
+ {
+
+ return appConfig;
+ }
+ if (AppConfigs.TryGetValue("default", out appConfig))
+ {
+ return appConfig;
+ }
+
+ return AppConfigs.FirstOrDefault().Value;
+ }
+
+
+ ///
+ /// 配置版本号
+ ///
+ public static string AppVersion
+ {
+ get;
+ set;
+ }
+ ///
+ ///
+ ///
+ ///
+ public static void ConfigClient_ConfigChanged(ConfigReloadedArgs args)
+ {
+
+ if (args.OldConfigs.TryGetValue("Version", out var vresion) && args.NewConfigs.TryGetValue("Version", out var newVersion))
+ {
+ if (vresion != newVersion)
+ {
+ MemoryCacheHelper.cache.Clear();
+ }
+ }
+ VerifyTenant(args);
+
+ }
+
+
+
+ ///
+ /// 初始化
+ ///
+ ///
+ ///
+ public static WebApplicationBuilder AddAppConfigClient(this WebApplicationBuilder builder)
+ {
+ var configClient = new ConfigClient(builder.Configuration);
+ builder.Host.UseAgileConfig(configClient, ConfigClient_ConfigChanged);
+ //AppConfigClient = configClient;
+ ConfigurationManager = builder.Configuration;
+ AppConfigInit(builder.Configuration);
+ builder.Services.AddScoped();
+ return builder;
+
+ }
+ #region 租户
+ public static ITenantInfo ToITenantInfo(this AppConfig appConfig, ITenantInfo? tenantInfo = null)
+ {
+ if (tenantInfo == null)
+ {
+ tenantInfo = new TenantInfo();
+ }
+ tenantInfo.TenantId = appConfig.TenantId;
+ tenantInfo.Identifier = appConfig.Identifier;
+ tenantInfo.Name = appConfig.Name;
+ tenantInfo.ConnectionString = appConfig.ConnectionString;
+ return tenantInfo;
+ }
+
+
+ ///
+ /// 验证多租户
+ ///
+ ///
+ private static void VerifyTenant(ConfigReloadedArgs args)
+ {
+ var newTenant = args.NewConfigs.Where(it => it.Key.Contains("Tenant")).ToDictionary();
+ var oldTenant = args.OldConfigs.Where(it => it.Key.Contains("Tenant")).ToDictionary();
+ bool areEqual = newTenant.Count == oldTenant.Count &&
+ !newTenant.Except(oldTenant).Any();
+ if (!areEqual)
+ {
+ //更新缓存
+ AppConfigInit(ConfigurationManager);
+ }
+
+ }
+ ///
+ /// 初始化租户数据
+ ///
+ ///
+ private static void AppConfigInit(ConfigurationManager configurationManager)
+ {
+ var tenants = configurationManager.GetSection("Tenant").Get>();
+ if (tenants != null)
+ {
+ ConcurrentDictionary _AppConfigs = new ConcurrentDictionary();
+ if (tenants.Count > 0)
+ {
+ tenants?.ForEach(t =>
+ {
+
+ if (!_AppConfigs.TryAdd(t.DomainName, t))
+ {
+ Console.WriteLine($"{t.DomainName}配置加载失败");
+ }
+ if (t.Name == "default")
+ {
+ _AppConfigs.TryAdd("default", t);
+ }
+ });
+ if (!_AppConfigs.TryGetValue("default", out var x))
+ {
+ _AppConfigs.TryAdd("default", tenants[0]);
+ }
+ }
+ else
+ {
+ _AppConfigs.TryAdd("default", new AppConfig());
+ }
+ AppConfigs = _AppConfigs;
+ }
+ }
+ #endregion
+
+ }
+
+}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Base/RedisConnection.cs b/src/0-core/HuanMeng.MiaoYu.Code/Base/RedisConnection.cs
new file mode 100644
index 0000000..e14c582
--- /dev/null
+++ b/src/0-core/HuanMeng.MiaoYu.Code/Base/RedisConnection.cs
@@ -0,0 +1,40 @@
+using StackExchange.Redis;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using IDatabase = StackExchange.Redis.IDatabase;
+namespace HuanMeng.MiaoYu.Code.Base
+{
+ ///
+ /// 数据库连接字符串
+ ///
+ public static class RedisConnection
+ {
+ ///
+ /// 数据库连接
+ ///
+ public static ConcurrentDictionary Redis { get; set; } = new ConcurrentDictionary();
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static IDatabase GetRedis(string redisConnection)
+ {
+ if (!Redis.TryGetValue(redisConnection, out var database))
+ {
+ var redis = ConnectionMultiplexer.Connect(redisConnection);
+ database = redis.GetDatabase();
+ Redis.TryAdd(redisConnection, database);
+ }
+ //database.
+ //database.StringSet("", "", TimeSpan.FromSeconds(10),when: When.NotExists);
+ return database;
+ }
+ }
+}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs
index cbedf25..15cb957 100644
--- a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs
+++ b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs
@@ -32,18 +32,12 @@ namespace HuanMeng.MiaoYu.Code.MultiTenantUtil
//初始学生数据库
string MiaoYu_SqlServer_Db = builder.Configuration.GetConnectionString("MiaoYu_SqlServer_Db") ?? "";
- //添加配置项
- //string SunnySports_SqlServer_Db_SunnySport_Admin = builder.Configuration.GetConnectionString("MiaoYu_SqlServer_Db_Admin") ?? "";
+
MiaoYuMultiTenantConfig miaoYuMultiTenantConfig = new MiaoYuMultiTenantConfig(MiaoYu_SqlServer_Db); builder.Services.AddSingleton(miaoYuMultiTenantConfig);
- //添加注入全部的多租户配置项
- //builder.Services.AddSingleton(sunnySportsMultiTenantConfig);
- ////添加单个租户的配置项
+
+ //添加单个租户的配置项
builder.Services.AddScoped();
- ////添加教师端用户
- //builder.Services.AddScoped();
- //builder.Services.AddScoped();
- //添加DB
- //var iDbLog = LoggerFactory.Create(b => b.AddConsole().AddFilter("", LogLevel.Information));
+
//添加系统数据库
builder.Services.AddDbContext((serviceProvider, options) =>
{
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs
index 3265436..a2c39da 100644
--- a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs
+++ b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs
@@ -1,5 +1,6 @@
using HuanMeng.DotNetCore.MultiTenant;
using HuanMeng.DotNetCore.MultiTenant.Contract;
+using HuanMeng.MiaoYu.Code.AppExtend;
using Microsoft.AspNetCore.Http;
@@ -36,6 +37,7 @@ namespace HuanMeng.MiaoYu.Code.MultiTenantUtil
public virtual async Task Invoke(HttpContext context,
IServiceProvider _serviceProvider,
ITenantInfo tenantInfo,
+ AppConfig appConfig,
MiaoYuMultiTenantConfig miaoYuMultiTenantConfig
)
{
@@ -43,11 +45,14 @@ namespace HuanMeng.MiaoYu.Code.MultiTenantUtil
{
tenantInfo = new TenantInfo();
}
- var _ten = miaoYuMultiTenantConfig.GetMultiTenantCfgDefault();
- tenantInfo.ConnectionString = _ten.ConnectionString;
- tenantInfo.Identifier = _ten.Identifier;
- tenantInfo.TenantId = _ten.TenantId;
- tenantInfo.Name = _ten.Name;
+ var host = context.Request.Host.Host;
+ var app = AppConfigurationExtend.GetAppConfig(host);
+ app.ToITenantInfo(tenantInfo);
+ //var _ten = miaoYuMultiTenantConfig.GetMultiTenantCfgDefault();
+ //tenantInfo.ConnectionString = _ten.ConnectionString;
+ //tenantInfo.Identifier = _ten.Identifier;
+ //tenantInfo.TenantId = _ten.TenantId;
+ //tenantInfo.Name = _ten.Name;
await _next.Invoke(context);
}
}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Order/OrderBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Order/OrderBLL.cs
new file mode 100644
index 0000000..d9b5803
--- /dev/null
+++ b/src/0-core/HuanMeng.MiaoYu.Code/Order/OrderBLL.cs
@@ -0,0 +1,56 @@
+using HuanMeng.MiaoYu.Code.Cache.Special;
+using HuanMeng.MiaoYu.Code.Payment;
+using HuanMeng.MiaoYu.Model.Dto.Order;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HuanMeng.MiaoYu.Code.Order
+{
+ ///
+ /// 订单数据
+ ///
+ public class OrderBLL : MiaoYuBase
+ {
+ public OrderBLL(IServiceProvider serviceProvider) : base(serviceProvider)
+ {
+ }
+
+ public async Task> CreateOrder(string paymentMethod, string productId)
+ {
+ if (_UserId == 0)
+ {
+ throw new ArgumentNullException("未登录");
+ }
+ if (string.IsNullOrEmpty(productId))
+ {
+ throw new ArgumentNullException("产品不能为空");
+ }
+ ProductEntityCache productEntityCache = new ProductEntityCache(this);
+ var products = productEntityCache.GetDataList();
+ var product = products.FirstOrDefault(it => it.ProductId == productId);
+ if (product == null)
+ {
+ throw new NullReferenceException("未找到所属产品");
+ }
+ //productEntityCache.get
+
+ //创建订单
+ var payment = PaymentExtend.GetPayment(paymentMethod);
+ (var orderId, var order) = payment.CreateOrder(product.ProductName, product.Price.ToString(), product);
+ var t = product.ToIntentOrder(paymentMethod, orderId);
+ t.UserId = _UserId;
+ Dao.daoDbMiaoYu.context.Add(t);
+ await Dao.daoDbMiaoYu.context.SaveChangesAsync();
+ var x = new IntentOrderDto()
+ {
+ OrderId = orderId,
+ Payment = order
+ };
+ return new BaseResponse(ResonseCode.Success, "", x);
+ }
+ }
+}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Other/AppConfigurationExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/Other/AppConfigurationExtend.cs
deleted file mode 100644
index 4abd2d4..0000000
--- a/src/0-core/HuanMeng.MiaoYu.Code/Other/AppConfigurationExtend.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-using AgileConfig.Client;
-
-using Alipay.EasySDK.Kernel;
-
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Hosting;
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-using XLib.DotNetCore.CacheHelper;
-
-namespace HuanMeng.MiaoYu.Code.Other
-{
- ///
- /// app配置项扩展
- ///
- public static class AppConfigurationExtend
- {
- ///
- /// 配置数据
- ///
- public static ConfigClient AppConfigClient { get; set; }
-
- ///
- /// 配置版本号
- ///
- public static string AppVersion
- {
- get;
- set;
- }
- ///
- ///
- ///
- ///
- public static void ConfigClient_ConfigChanged(ConfigReloadedArgs args)
- {
- if (args.OldConfigs.TryGetValue("Version", out var vresion) && args.NewConfigs.TryGetValue("Version", out var newVersion))
- {
- if (vresion != newVersion)
- {
- MemoryCacheHelper.cache.Clear();
- }
- }
-
- }
-
- public static WebApplicationBuilder AddAppConfigClient(this WebApplicationBuilder builder)
- {
- var configClient = new ConfigClient(builder.Configuration);
- builder.Host.UseAgileConfig(configClient, ConfigClient_ConfigChanged);
- //var config = builder.Configuration;
- //builder.Host.ConfigureAppConfiguration((context, config) =>
- // {
- // //new一个client实例,无参构造会从本地appsettings.json文件读取配置
- // var configClient = new ConfigClient(context.Configuration);
- // //使用AddAgileConfig配置一个新的IConfigurationSource
- // config.AddAgileConfig(configClient);
- // AppConfigClient = configClient;
- // ConfigClient_ConfigChanged(null);
- // //注册配置项修改事件
- // configClient.ConfigChanged += ConfigClient_ConfigChanged;
- // });
-
- return builder;
-
- }
-
- }
-}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Payment/Alipay/AlipayPayment.cs b/src/0-core/HuanMeng.MiaoYu.Code/Payment/Alipay/AlipayPayment.cs
index 83724a5..33d88b3 100644
--- a/src/0-core/HuanMeng.MiaoYu.Code/Payment/Alipay/AlipayPayment.cs
+++ b/src/0-core/HuanMeng.MiaoYu.Code/Payment/Alipay/AlipayPayment.cs
@@ -9,6 +9,7 @@ using Alipay.EasySDK.Factory;
using Alipay.EasySDK.Kernel;
using Alipay.EasySDK.Kernel.Util;
using Alipay.EasySDK.Payment.FaceToFace.Models;
+using StackExchange.Redis;
namespace HuanMeng.MiaoYu.Code.Payment.Alipay
{
@@ -17,7 +18,7 @@ namespace HuanMeng.MiaoYu.Code.Payment.Alipay
///
public class AlipayPayment : IPayment
{
- public string CreateOrder(string orderId, string productName, string price, params object[] args)
+ public (string orderId, string order) CreateOrder(string productName, string price, params object[] args)
{
if (string.IsNullOrEmpty(productName))
{
@@ -27,10 +28,7 @@ namespace HuanMeng.MiaoYu.Code.Payment.Alipay
{
throw new ArgumentNullException($"价格不能为空!");
}
- if (string.IsNullOrEmpty(orderId))
- {
- orderId = Guid.NewGuid().ToString();
- }
+ var orderId = GenerateTimestampIdWithOffset();
//.SetOptions(GetConfig());
var response = Factory.Payment.App().Pay(productName, orderId, price);
if (ResponseChecker.Success(response))
@@ -43,7 +41,13 @@ namespace HuanMeng.MiaoYu.Code.Payment.Alipay
}
//.PreCreate("Apple iPhone11 128G", "2234567234890", "5799.00");
var zfbOrderId = response.Body;
- return zfbOrderId;
+ return (orderId, zfbOrderId);
+ }
+ private string GenerateTimestampIdWithOffset()
+ {
+ var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); // 获取Unix时间戳(毫秒)
+ var random = new Random().Next(1000, 9999); // 生成四位随机数
+ return $"ZFB{timestamp}J001S{random}";
}
}
}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Payment/AlipayPayment.cs b/src/0-core/HuanMeng.MiaoYu.Code/Payment/AlipayPayment.cs
deleted file mode 100644
index 01a0913..0000000
--- a/src/0-core/HuanMeng.MiaoYu.Code/Payment/AlipayPayment.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace HuanMeng.MiaoYu.Code.Payment
-{
- public class AlipayPayment
- {
- }
-}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Payment/Contract/IPayment.cs b/src/0-core/HuanMeng.MiaoYu.Code/Payment/Contract/IPayment.cs
index a7c595e..e98ef59 100644
--- a/src/0-core/HuanMeng.MiaoYu.Code/Payment/Contract/IPayment.cs
+++ b/src/0-core/HuanMeng.MiaoYu.Code/Payment/Contract/IPayment.cs
@@ -19,6 +19,6 @@ namespace HuanMeng.MiaoYu.Code.Payment.Contract
/// 价格
/// 其它参数
///
- string CreateOrder(string orderId, string productName, string price, params object[] args);
+ (string orderId,string order) CreateOrder(string productName, string price, params object[] args);
}
}
diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Payment/PaymentExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/Payment/PaymentExtend.cs
index 4a5662d..6458b4d 100644
--- a/src/0-core/HuanMeng.MiaoYu.Code/Payment/PaymentExtend.cs
+++ b/src/0-core/HuanMeng.MiaoYu.Code/Payment/PaymentExtend.cs
@@ -1,7 +1,13 @@
using Alipay.EasySDK.Factory;
using Alipay.EasySDK.Kernel;
+using HuanMeng.MiaoYu.Code.Payment.Alipay;
+using HuanMeng.MiaoYu.Code.Payment.Contract;
+using HuanMeng.MiaoYu.Model.Dto.Cache;
+
+using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
@@ -16,28 +22,86 @@ namespace HuanMeng.MiaoYu.Code.Payment
///
public static class PaymentExtend
{
+ ///
+ /// 支付
+ ///
+ ///
+ ///
+ public static IHostApplicationBuilder AddAlipay(this IHostApplicationBuilder builder)
+ {
+ AddAlipay(builder.Configuration);
+ return builder;
+ }
+ ///
+ /// 支付
+ ///
+ ///
public static void AddAlipay(IConfiguration configuration)
{
var x = configuration.GetSection("Payment:AlipayConfig").Get();
- var config = new Config()
+ if (x != null)
{
- Protocol = "https",
- GatewayHost = "openapi.alipay.com",
- SignType = "RSA2",
- AppId = "<-- 请填写您的AppId,例如:2019091767145019 -->",
- // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
- MerchantPrivateKey = "<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->",
- //MerchantCertPath = "<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->",
- //AlipayCertPath = "<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->",
- //AlipayRootCertPath = "<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt -->",
+ var config = new Config()
+ {
+ Protocol = "https",
+ GatewayHost = "openapi.alipay.com",
+ SignType = "RSA2",
+ AppId = x.AppId,
+ // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
+ MerchantPrivateKey = x.MerchantPrivateKey,
+ //MerchantCertPath = "<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->",
+ //AlipayCertPath = "<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->",
+ //AlipayRootCertPath = "<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt -->",
+ // 如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
+ AlipayPublicKey = x.AlipayPublicKey,
+ //可设置异步通知接收服务地址(可选)
+ NotifyUrl = x.NotifyUrl,
+ };
+ Factory.SetOptions(config);
+ }
+ else
+ {
+ Console.WriteLine("接入支付失败");
+ }
+ }
- // 如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
- AlipayPublicKey = "<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->",
+ ///
+ ///获取支付方式
+ ///
+ ///
+ ///
+ public static IPayment GetPayment(string payment)
+ {
+ if (payment == "zfb")
+ {
+ return new AlipayPayment();
+ }
+ return new AlipayPayment();
+ }
- //可设置异步通知接收服务地址(可选)
- NotifyUrl = "<-- 请填写您的支付类接口异步通知接收服务地址,例如:https://www.test.com/callback -->",
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static T_User_IntentOrder ToIntentOrder(this ProductCache productCache, string payment, string orderId)
+ {
+ T_User_IntentOrder t_User_IntentOrder = new T_User_IntentOrder()
+ {
+ Price = productCache.Price,
+ CreatedAt = DateTime.Now,
+ IntentDate = DateTime.Now,
+ Method = payment,
+ Notes = "",
+ ProductId = productCache.ProductId,
+ Quantity = 1,
+ Status = 0,
+ UpdatedAt = DateTime.Now,
+ OrderId = orderId,
};
- Factory.SetOptions(config);
+ return t_User_IntentOrder;
}
}
}
diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs
index f17bb41..41ca916 100644
--- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs
+++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs
@@ -103,11 +103,6 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
///
public virtual DbSet T_Model_Config { get; set; }
- ///
- /// 订单表
- ///
- public virtual DbSet T_Orders { get; set; }
-
///
/// 商城表
///
@@ -148,6 +143,11 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
///
public virtual DbSet T_User_Data { get; set; }
+ ///
+ /// 意向订单表
+ ///
+ public virtual DbSet T_User_IntentOrder { get; set; }
+
///
/// 用户记忆卡
///
@@ -580,37 +580,6 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
}
});
- modelBuilder.Entity(entity =>
- {
- entity.HasKey(e => e.Id).HasName("PK__T_Orders__3214EC070849C94C");
-
- entity.ToTable(tb => tb.HasComment("订单表"));
-
- entity.Property(e => e.Id)
- .ValueGeneratedNever()
- .HasComment("订单id");
- entity.Property(e => e.Amount).HasComment("金币购买数量/道具兑换数量");
- entity.Property(e => e.CreateTime)
- .HasComment("创建时间")
- .HasColumnType("datetime");
- entity.Property(e => e.OrderType).HasComment("0金币购买1道具兑换");
- entity.Property(e => e.PaymentMethod).HasComment("金币购买时的支付方式0wx 1支付宝");
- entity.Property(e => e.Price)
- .HasComment("花费的钱/花费的金币")
- .HasColumnType("money");
- entity.Property(e => e.Status).HasComment("0支付中1已支付2已取消");
- entity.Property(e => e.TenantId).HasComment("租户id");
- entity.Property(e => e.UpdateTime)
- .HasComment("更新时间")
- .HasColumnType("datetime");
- entity.Property(e => e.UserId).HasComment("用户id");
- //添加全局筛选器
- if (this.TenantInfo != null)
- {
- entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
- }
- });
-
modelBuilder.Entity(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__T_Products__3214EC07DC10A165");
@@ -873,6 +842,48 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
}
});
+ modelBuilder.Entity(entity =>
+ {
+ entity.HasKey(e => e.Id).HasName("PK__T_User_I__3214EC07D27A8CE9");
+
+ entity.ToTable(tb => tb.HasComment("意向订单表"));
+
+ entity.Property(e => e.Id).HasComment("主键");
+ entity.Property(e => e.CreatedAt)
+ .HasComment("创建时间")
+ .HasColumnType("datetime");
+ entity.Property(e => e.IntentDate)
+ .HasComment("订单创建时间")
+ .HasColumnType("datetime");
+ entity.Property(e => e.Method)
+ .HasMaxLength(1)
+ .HasComment("支付方式");
+ entity.Property(e => e.Notes)
+ .HasMaxLength(200)
+ .HasComment("备注");
+ entity.Property(e => e.OrderId)
+ .HasMaxLength(64)
+ .HasComment("订单Id");
+ entity.Property(e => e.Price)
+ .HasComment("价格")
+ .HasColumnType("money");
+ entity.Property(e => e.ProductId)
+ .HasMaxLength(50)
+ .HasComment("产品id");
+ entity.Property(e => e.Quantity).HasComment("数量");
+ entity.Property(e => e.Status).HasComment("状态");
+ entity.Property(e => e.TenantId).HasComment("租户");
+ entity.Property(e => e.UpdatedAt)
+ .HasComment("修改时间")
+ .HasColumnType("datetime");
+ entity.Property(e => e.UserId).HasComment("用户Id");
+ //添加全局筛选器
+ if (this.TenantInfo != null)
+ {
+ entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
+ }
+ });
+
modelBuilder.Entity(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__T_User_M__3214EC0706BA6604");
diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Orders.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Orders.cs
deleted file mode 100644
index 49a1a27..0000000
--- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Orders.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using System;
-
-namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu;
-
-///
-/// 订单表
-///
-public partial class T_Orders: MultiTenantEntity
-{
- ///
- /// 订单id
- ///
- public virtual int Id { get; set; }
-
- public override Guid TenantId { get; set; }
-
- ///
- /// 用户id
- ///
- public virtual int UserId { get; set; }
-
- ///
- /// 0金币购买1道具兑换
- ///
- public virtual int OrderType { get; set; }
-
- ///
- /// 金币购买数量/道具兑换数量
- ///
- public virtual int Amount { get; set; }
-
- ///
- /// 花费的钱/花费的金币
- ///
- public virtual decimal Price { get; set; }
-
- ///
- /// 0支付中1已支付2已取消
- ///
- public virtual int Status { get; set; }
-
- ///
- /// 创建时间
- ///
- public virtual DateTime CreateTime { get; set; }
-
- ///
- /// 更新时间
- ///
- public virtual DateTime UpdateTime { get; set; }
-
- ///
- /// 金币购买时的支付方式0wx 1支付宝
- ///
- public virtual int? PaymentMethod { get; set; }
-}
diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_User_Currency.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_User_Currency.cs
index 208e18a..9669557 100644
--- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_User_Currency.cs
+++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_User_Currency.cs
@@ -10,7 +10,7 @@ public partial class T_User_Currency: MultiTenantEntity
public virtual int Id { get; set; }
///
- /// 货币类型 语珠、免费币
+ /// 货币类型 付费币、免费币
///
public virtual int CurrencyType { get; set; }
diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_User_IntentOrder.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_User_IntentOrder.cs
new file mode 100644
index 0000000..abae19a
--- /dev/null
+++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_User_IntentOrder.cs
@@ -0,0 +1,71 @@
+using System;
+
+namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu;
+
+///
+/// 意向订单表
+///
+public partial class T_User_IntentOrder: MultiTenantEntity
+{
+ ///
+ /// 主键
+ ///
+ public virtual int Id { get; set; }
+
+ ///
+ /// 用户Id
+ ///
+ public virtual int UserId { get; set; }
+
+ ///
+ /// 产品id
+ ///
+ public virtual string ProductId { get; set; } = null!;
+
+ ///
+ /// 支付方式
+ ///
+ public virtual string Method { get; set; } = null!;
+
+ ///
+ /// 价格
+ ///
+ public virtual decimal Price { get; set; }
+
+ ///
+ /// 数量
+ ///
+ public virtual int Quantity { get; set; }
+
+ ///
+ /// 状态
+ ///
+ public virtual int Status { get; set; }
+
+ ///
+ /// 备注
+ ///
+ public virtual string? Notes { get; set; }
+
+ ///
+ /// 订单创建时间
+ ///
+ public virtual DateTime IntentDate { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ public virtual DateTime CreatedAt { get; set; }
+
+ ///
+ /// 修改时间
+ ///
+ public virtual DateTime UpdatedAt { get; set; }
+
+ public override Guid TenantId { get; set; }
+
+ ///
+ /// 订单Id
+ ///
+ public virtual string OrderId { get; set; } = null!;
+}
diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Order/IntentOrderDto.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Order/IntentOrderDto.cs
new file mode 100644
index 0000000..2f419b4
--- /dev/null
+++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Order/IntentOrderDto.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HuanMeng.MiaoYu.Model.Dto.Order
+{
+ ///
+ ///
+ ///
+ public class IntentOrderDto
+ {
+ ///
+ /// 订单编号
+ ///
+ public string OrderId { get; set; }
+ ///
+ /// 支付信息
+ ///
+ public object Payment { get; set; }
+ }
+}
diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs
index 0213ebd..2f32781 100644
--- a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs
+++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs
@@ -13,7 +13,7 @@ using HuanMeng.MiaoYu.Code.TencentUtile;
using HuanMeng.MiaoYu.Code.Users.UserAccount.VerificationCodeManager;
using HuanMeng.MiaoYu.Model.Dto;
using HuanMeng.MiaoYu.WebApi.Base;
-
+using HuanMeng.MiaoYu.Code.AppExtend;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.OpenApi.Models;
@@ -54,7 +54,6 @@ builder.Services.AddSingleton(typeof(ILogger), serviceProvider =>
var loggerFactory = serviceProvider.GetRequiredService();
return loggerFactory.CreateLogger();
});
-//PaymentExtend.AddAlipay(builder.Configuration);
// 检索程序集信息
AssemblyInfo assemblyInfo = AssemblyInfoHelper.GetAssemblyInfo();
// Add services to the container.
@@ -141,6 +140,7 @@ builder.Services.AddSwaggerGen(c =>
});
//配置路由选项,使URL全部小写
//builder.Services.AddRouting(options => options.LowercaseUrls = true);
+builder.AddAlipay();
//添加多租户
builder.AddMultiTenantMiaoYu();
//添加腾讯云管理
diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json b/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json
index 92d117c..61d8642 100644
--- a/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json
+++ b/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json
@@ -84,6 +84,7 @@
},
"SystemConfig": {
+ "DictionaryUrl": "https://adminapi.shhuanmeng.com/api/v1/admin/SysDictionary/GetList",
"TextCensorDir": "DataStorage/TextCensor/"
},
"AgileConfig": {