fix: 优化服务号与支付逻辑,增加AccessToken为空校验及优惠描述完善
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Xml.Serialization;
|
||||
using Medallion.Threading;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -18,7 +17,7 @@ using Yi.Framework.Rbac.Application.Contracts.Dtos.Account;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Services;
|
||||
namespace Yi.Framework.AiHub.Application.Services.Fuwuhao;
|
||||
|
||||
/// <summary>
|
||||
/// 服务号服务
|
||||
@@ -224,18 +224,25 @@ public class PayService : ApplicationService, IPayService
|
||||
// 如果是尊享包商品,计算折扣
|
||||
if (goodsType.IsPremiumPackage())
|
||||
{
|
||||
discountDescription = "累计充值每10元可减2.5元,最多减50元";
|
||||
|
||||
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
discountAmount = goodsType.CalculateDiscount(totalRechargeAmount);
|
||||
actualPrice = goodsType.GetDiscountedPrice(totalRechargeAmount);
|
||||
|
||||
if (discountAmount > 0)
|
||||
{
|
||||
discountDescription = $"根据累积充值已优惠 ¥{discountAmount:F2}";
|
||||
}
|
||||
else
|
||||
{
|
||||
discountDescription = $"累积充值过低,暂无优惠";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
discountDescription = $"登录后查看优惠";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var goodsItem = new GoodsListOutput
|
||||
@@ -280,6 +287,7 @@ public class PayService : ApplicationService, IPayService
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return TradeStatusEnum.WAIT_TRADE;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public class FuwuhaoManager : DomainService
|
||||
private IDistributedCache<AccessTokenResponse> _accessTokenCache;
|
||||
private ISqlSugarRepository<AiUserExtraInfoEntity> _userRepository;
|
||||
private readonly ILogger<FuwuhaoManager> _logger;
|
||||
|
||||
public FuwuhaoManager(IOptions<FuwuhaoOptions> options, IHttpClientFactory httpClientFactory,
|
||||
ISqlSugarRepository<AiUserExtraInfoEntity> userRepository,
|
||||
IDistributedCache<AccessTokenResponse> accessTokenCache, ILogger<FuwuhaoManager> logger)
|
||||
@@ -49,6 +50,11 @@ public class FuwuhaoManager : DomainService
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
});
|
||||
if (result is null || string.IsNullOrEmpty(result.AccessToken))
|
||||
{
|
||||
throw new UserFriendlyException("微信服务号AccessToken为空");
|
||||
}
|
||||
|
||||
return result;
|
||||
}, () => new DistributedCacheEntryOptions()
|
||||
{
|
||||
@@ -175,7 +181,8 @@ public class FuwuhaoManager : DomainService
|
||||
/// <param name="title">图文消息标题</param>
|
||||
/// <param name="description">图文消息描述</param>
|
||||
/// <returns>XML格式的图文消息体</returns>
|
||||
public string BuildRegisterMessage(string toUser, string title="意社区点击一键注册账号", string description="来自意社区SSO统一注册安全中心")
|
||||
public string BuildRegisterMessage(string toUser, string title = "意社区点击一键注册账号",
|
||||
string description = "来自意社区SSO统一注册安全中心")
|
||||
{
|
||||
var createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
var fromUser = _options.FromUser;
|
||||
@@ -207,7 +214,8 @@ public class FuwuhaoManager : DomainService
|
||||
/// <param name="openId"></param>
|
||||
/// <param name="bindUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(SceneResultEnum SceneResult,Guid? UserId)> CallBackHandlerAsync(SceneTypeEnum sceneType, string openId, Guid? bindUserId)
|
||||
public async Task<(SceneResultEnum SceneResult, Guid? UserId)> CallBackHandlerAsync(SceneTypeEnum sceneType,
|
||||
string openId, Guid? bindUserId)
|
||||
{
|
||||
var aiUserInfo = await _userRepository._DbQueryable.Where(x => x.FuwuhaoOpenId == openId).FirstAsync();
|
||||
switch (sceneType)
|
||||
|
||||
Reference in New Issue
Block a user