diff --git a/Services/Hncore.Pass.Vpn/Domain/UserEntity.cs b/Services/Hncore.Pass.Vpn/Domain/UserEntity.cs index 35d80ce..a531e0a 100644 --- a/Services/Hncore.Pass.Vpn/Domain/UserEntity.cs +++ b/Services/Hncore.Pass.Vpn/Domain/UserEntity.cs @@ -87,6 +87,7 @@ namespace Hncore.Pass.Vpn.Domain public int agent_id {get; set;} public string apikey {get; set;} public string id_code {get; set;} + public int is_agent { get; set; } } } \ No newline at end of file diff --git a/Services/Hncore.Pass.Vpn/Service/ProductOrderService.cs b/Services/Hncore.Pass.Vpn/Service/ProductOrderService.cs index f46e0f7..82aa805 100644 --- a/Services/Hncore.Pass.Vpn/Service/ProductOrderService.cs +++ b/Services/Hncore.Pass.Vpn/Service/ProductOrderService.cs @@ -1139,6 +1139,8 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, } var accountInfo = await m_ProductAccountService.GetAccountInfo(account, userId); + var userEntity = await m_UserService.GetById(userId); + if (accountInfo == null) { return new ApiResult(ResultCode.C_Illegal_Operation, "账户不存在"); @@ -1156,7 +1158,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, } var pacageInfo = await m_ProductPackageService.GetById(accountInfo.PackageId); - if (pacageInfo.DayCount == 1) + if (pacageInfo.DayCount == 1 && userEntity.is_agent == 0) { return new ApiResult(ResultCode.C_Illegal_Operation, "天卡不能退款"); } @@ -1168,7 +1170,6 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, //折扣 var refundDayPrice = 10.00M; - var userEntity = await m_UserService.GetById(userId); if((userEntity.agent_id == 0||(userEntity.agent_id != 0 && userEntity.discount_id != 0)) && userEntity.discount_id >= 0){ //获取代理折扣 var discount = await m_ProductPriceSchemeService.GetById(userEntity.discount_id); @@ -1188,7 +1189,29 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, var lastOrder = await GetLastOrderByAccount(account); + + var dateStr = lastOrder.StartTime.ToString(); + var now = DateTime.Now.GetUnixTimeStamp(); + + + + //解析字符串为 DateTime(假设是本地时间) + DateTime dateTime = DateTime.Parse(dateStr); + + // 转换为 UTC(如果原始时间是本地时间) + DateTime utcTime = dateTime.ToUniversalTime(); + + // 计算 Unix 时间戳(秒) + DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + TimeSpan timeDiff = utcTime - epoch; + long unixTimestampSeconds = (long)timeDiff.TotalSeconds + 3600; + var useDay = (int)Math.Ceiling((DateTime.Now - lastOrder.UpdateTime).TotalDays); + + if (unixTimestampSeconds > now && userEntity.is_agent == 1) { + useDay = 0; + } + var refundAmount = lastOrder.PaymentAmount / lastOrder.AccountCount - useDay * refundDayPrice * accountInfo.ConnectCount; refundAmount = refundAmount <= 0 ? 0 : refundAmount; @@ -1486,6 +1509,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, public async Task CaclRefund(int userId, string account) { var accountInfo = await m_ProductAccountService.GetAccountInfo(account, userId); + var userEntity = await m_UserService.GetById(userId); if(accountInfo.Status == AccountStatus.Refund){ return new ApiResult(ResultCode.C_Illegal_Operation, "此类帐号不允许退款"); @@ -1507,7 +1531,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, } var pacageInfo = await m_ProductPackageService.GetById(accountInfo.PackageId); - if (pacageInfo.DayCount == 1) + if (pacageInfo.DayCount == 1 && userEntity.is_agent == 0) { return new ApiResult(ResultCode.C_Illegal_Operation, "天卡不能退款"); } @@ -1517,7 +1541,6 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, //折扣 var refundDayPrice = 10.00M; - var userEntity = await m_UserService.GetById(userId); if((userEntity.agent_id == 0||(userEntity.agent_id != 0 && userEntity.discount_id != 0)) && userEntity.discount_id >= 0){ //获取代理折扣 var discount = await m_ProductPriceSchemeService.GetById(userEntity.discount_id); @@ -1533,7 +1556,30 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel, } var lastOrder = await GetLastOrderByAccount(account); - var useDay = (int)Math.Ceiling((DateTime.Now - lastOrder.UpdateTime).TotalDays); + + + var dateStr = lastOrder.StartTime.ToString(); + var now = DateTime.Now.GetUnixTimeStamp(); + + + + //解析字符串为 DateTime(假设是本地时间) + DateTime dateTime = DateTime.Parse(dateStr); + + // 转换为 UTC(如果原始时间是本地时间) + DateTime utcTime = dateTime.ToUniversalTime(); + + // 计算 Unix 时间戳(秒) + DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + TimeSpan timeDiff = utcTime - epoch; + long unixTimestampSeconds = (long)timeDiff.TotalSeconds + 3600; + + var useDay = (int)Math.Ceiling((DateTime.Now - lastOrder.UpdateTime).TotalDays); + + if (unixTimestampSeconds > now && userEntity.is_agent == 1) { + useDay = 0; + } + var RefundAmount = lastOrder.PaymentAmount / lastOrder.AccountCount - useDay * refundDayPrice * accountInfo.ConnectCount; RefundAmount = RefundAmount <= 0 ? 0 : RefundAmount;