【代理商需求】
https://www.tapd.cn/tapd_fe/67163502/story/detail/1167163502001000123
This commit is contained in:
@@ -208,7 +208,7 @@ namespace Hncore.Pass.Vpn.Controllers
|
||||
{
|
||||
//通过apikey获取用户信息
|
||||
var userInfo = m_BaseUserService.Query(m => m.apikey == request.apikey).FirstOrDefault();
|
||||
return await m_ProductOrderService.Refund(userInfo.Id, request.Account);
|
||||
return await m_ProductOrderService.ApiRefund(userInfo.Id, request.Account);
|
||||
}
|
||||
|
||||
[UserAuth]
|
||||
|
||||
@@ -1324,6 +1324,165 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ApiResult> ApiRefund(int userId, string account)
|
||||
{
|
||||
using (await _mutex1.LockAsync())
|
||||
{
|
||||
var reason = "";
|
||||
if(account.Contains("-")){
|
||||
string[] arrStr = account.Split('-');
|
||||
account = arrStr[0];
|
||||
reason = arrStr[1];
|
||||
}
|
||||
var accountInfo = await m_ProductAccountService.GetAccountInfo(account, userId);
|
||||
|
||||
if (accountInfo == null)
|
||||
{
|
||||
return new ApiResult(ResultCode.C_Illegal_Operation, "账户不存在");
|
||||
}
|
||||
if(accountInfo.ProductId == 20||accountInfo.ProductId == 21){
|
||||
return new ApiResult(ResultCode.C_Illegal_Operation, "无极账号不允许退款");
|
||||
}
|
||||
if (accountInfo.AccountType == (int)AccountType.Origin)
|
||||
{
|
||||
return new ApiResult(ResultCode.C_Illegal_Operation, "认证的账号不能退款");
|
||||
}
|
||||
if (accountInfo.EndTime < DateTime.Now)
|
||||
{
|
||||
return new ApiResult(ResultCode.C_Illegal_Operation, "已经过期");
|
||||
}
|
||||
var pacageInfo = await m_ProductPackageService.GetById(accountInfo.PackageId);
|
||||
|
||||
// if (pacageInfo.DayCount == 1)
|
||||
// {
|
||||
// return new ApiResult(ResultCode.C_Illegal_Operation, "天卡不能退款");
|
||||
// }
|
||||
if (pacageInfo.IsTest == 1)
|
||||
{
|
||||
return new ApiResult(ResultCode.C_Illegal_Operation, "测试卡不能退款");
|
||||
}
|
||||
var product = await this.m_ProductService.GetById(pacageInfo.ProductId);
|
||||
|
||||
//折扣
|
||||
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);
|
||||
if (discount != null){
|
||||
refundDayPrice = (product.RefundDayPrice * discount.discount / 100).ToDecimal();
|
||||
} else {
|
||||
refundDayPrice = (product.RefundDayPrice).ToDecimal();
|
||||
}
|
||||
} else {
|
||||
var userPrice = await m_ProductUserPriceService.GetPackageUserPrice(pacageInfo.Id, userId);
|
||||
|
||||
refundDayPrice = (userPrice != null && userPrice.RefundDayPrice > 0 ? userPrice.RefundDayPrice : product.RefundDayPrice).ToDecimal();
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
useDay = 0;
|
||||
}
|
||||
|
||||
var refundAmount = lastOrder.PaymentAmount / lastOrder.AccountCount - useDay * refundDayPrice * accountInfo.ConnectCount;
|
||||
refundAmount = refundAmount <= 0 ? 0 : refundAmount;
|
||||
|
||||
//退款用户总消费修改 这个好像没用用处 已经有其他的统计地方
|
||||
userEntity.ConsumeAmount -= refundAmount;
|
||||
await m_UserService.Update(userEntity);
|
||||
|
||||
var order = new ProductOrderEntity()
|
||||
{
|
||||
AccountCount = 1,
|
||||
ConnectCount = accountInfo.ConnectCount,
|
||||
OrderName = accountInfo.ProductName,
|
||||
OrderNo = GeneratOrderNO(userId, OrderType.Refund),
|
||||
OrderState = OrderStatus.RequestRefund,
|
||||
OrderType = OrderType.Refund,
|
||||
PackageId = accountInfo.PackageId.Value,
|
||||
PackageName = accountInfo.PackageName,
|
||||
ProductId = accountInfo.ProductId.Value,
|
||||
ProductName = accountInfo.ProductName,
|
||||
PayType = PayType.None,
|
||||
UserId = userId,
|
||||
UserName = accountInfo.UserCode,
|
||||
DayCount = (accountInfo.EndTime - DateTime.Now).Value.Days,
|
||||
DayPrice = refundDayPrice,
|
||||
Accounts = account,
|
||||
PaymentAmount = lastOrder.PaymentAmount/ lastOrder.AccountCount,
|
||||
RefundAmount = refundAmount,
|
||||
RefundCount = 1,
|
||||
Remark = "API退款",
|
||||
RefundReason = reason,
|
||||
agent_id = accountInfo.agent_id
|
||||
};
|
||||
var time = (accountInfo.EndTime - DateTime.Now).Value;
|
||||
order.RefundRestTime = time.ToString(@"d\天hh\时mm\分");
|
||||
|
||||
//短信内容 部分运营商收不到短信
|
||||
var tpl_info = new Dictionary<string, string>(){
|
||||
{"product",accountInfo.ProductName},
|
||||
{"package",accountInfo.PackageName },
|
||||
{"connect",accountInfo.ConnectCount.ToString() },
|
||||
{"account",account },
|
||||
{"resttime",order.RefundRestTime},
|
||||
};
|
||||
|
||||
var againBuy = lastOrder.OrderType == OrderType.AgainBuy || lastOrder.OrderType == OrderType.AgainBuys;
|
||||
|
||||
var laoyingXunFei = againBuy && lastOrder.ProductId == 4;
|
||||
if (product.AutoRefund == 1 && !laoyingXunFei)
|
||||
{
|
||||
var refundRet = await this.m_AgentService.Refund(pacageInfo, accountInfo);
|
||||
if (refundRet.Code == ResultCode.C_SUCCESS)
|
||||
{
|
||||
order.OrderState = OrderStatus.AutoRefundOver;
|
||||
}
|
||||
}
|
||||
var amountInfo = new BaseInfo.Request.User.UpdateAmountRequest()
|
||||
{
|
||||
Amount = order.RefundAmount,
|
||||
OpAmountType = ScoreType.AccountRefund,
|
||||
UserId = order.UserId,
|
||||
AttchInfo = order.OrderNo,
|
||||
OperateUserName = accountInfo.UserCode
|
||||
};
|
||||
var retAmount = await m_BaseUserService.UpdateAmount(amountInfo);
|
||||
accountInfo.EndTime = DateTime.Now;
|
||||
accountInfo.Status = AccountStatus.Refund;
|
||||
await m_ProductAccountService.Update(accountInfo);
|
||||
await this.Add(order);
|
||||
|
||||
var managerEntity = await m_ManageService.GetById(userEntity.ManagerId.ToInt());
|
||||
if (managerEntity.TenantId == 1 && managerEntity.RoleId == 100 && DateTime.Now.Hour<23 && DateTime.Now.Hour>8) {
|
||||
AliSmsService.Send("SMS_462300235", new { name = userEntity.ManagerName,phone=userEntity.Phone }, "河南华连网络科技", managerEntity.Phone);
|
||||
}
|
||||
return new ApiResult(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<ApiResult> CaclRefund(int userId, string account)
|
||||
{
|
||||
var accountInfo = await m_ProductAccountService.GetAccountInfo(account, userId);
|
||||
|
||||
Reference in New Issue
Block a user