91 lines
2.9 KiB
C#
91 lines
2.9 KiB
C#
using CloudGaming.Core.AgileConfig.AgileConfigApi;
|
|
using CloudGaming.Core.AgileConfig;
|
|
using Newtonsoft.Json;
|
|
using AppConfig = CloudGaming.Code.DataBaseModel.AppConfig;
|
|
namespace CloudGaming.Api.Admin.ApplicationServices.Apps.Ext;
|
|
|
|
/// <summary>
|
|
/// 服务 WeChatConfigService
|
|
/// </summary>
|
|
public class AlipayConfigService(IServiceProvider serviceProvider)
|
|
: ApplicationService(serviceProvider)
|
|
{
|
|
|
|
[Autowired]
|
|
public virtual AppConfigTenant AppConfigTenant { get; set; }
|
|
[AppSettings("AgileConfig")]
|
|
public virtual AgileConfigVM AgileConfig { get; set; }
|
|
[Autowired]
|
|
public virtual IAccountService AccountService { get; set; }
|
|
|
|
[Autowired]
|
|
public virtual AppConfig appConfig { get; set; }
|
|
|
|
/// <summary>
|
|
/// 查询表单数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<Dictionary<string, object?>> FindFormAsync()
|
|
{
|
|
var res = new Dictionary<string, object?>();
|
|
AppAlipayConfig form = appConfig?.Payment.AlipayConfig;
|
|
form = form.NullSafe();
|
|
res["id"] = appConfig.TenantId;
|
|
res[nameof(form)] = form;
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存数据
|
|
/// </summary>
|
|
/// <param name="form"></param>
|
|
/// <returns></returns>
|
|
public async Task SaveFormAsync(AppAlipayConfig form)
|
|
{
|
|
|
|
if (AppConfigTenant == null)
|
|
{
|
|
AppConfigTenant = new AppConfigTenant();
|
|
}
|
|
if (AppConfigTenant.Tenants == null)
|
|
{
|
|
AppConfigTenant.Tenants = new List<AppConfig>();
|
|
}
|
|
var t = AppConfigTenant.Tenants.FirstOrDefault(it => it.TenantId == appConfig.TenantId);
|
|
if (t != null)
|
|
{
|
|
if (t.Payment == null)
|
|
{
|
|
t.Payment = new AppPayment() { };
|
|
}
|
|
t.Payment.AlipayConfig = form;
|
|
}
|
|
await SynchronizeData();
|
|
|
|
}
|
|
|
|
private async Task SynchronizeData()
|
|
{
|
|
var agileConfigServer = ServiceProvider.GetService<AgileConfigServer>();
|
|
var agileConfigApiVM = new CloudGaming.Core.AgileConfig.AgileConfigApi.AgileConfigApiVM()
|
|
{
|
|
IsPatch = false,
|
|
Json = JsonConvert.SerializeObject(AppConfigTenant)
|
|
};
|
|
if (agileConfigServer != null)
|
|
{
|
|
//var model = await agileConfigServer.AgileConfigApi.GetJson(AgileConfig.AppId, AgileConfig.Env);
|
|
var s = await agileConfigServer.AgileConfigApi.SaveJson(AgileConfig.AppId, AgileConfig.Env, agileConfigApiVM);
|
|
if (s.Success)
|
|
{
|
|
var model = new AgileConfigPublishVM()
|
|
{
|
|
log = $"{AccountService.AccountContext.Name}修改{appConfig.TenantId}支付宝配置,{DateTime.Now}自动发布",
|
|
appId = AgileConfig.AppId
|
|
};
|
|
await agileConfigServer.AgileConfigApi.Publish(AgileConfig.Env, model);
|
|
}
|
|
}
|
|
}
|
|
}
|