同时退款并发问题
This commit is contained in:
@@ -860,134 +860,137 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
|
||||
public async Task<ApiResult> Refund(int userId, string account)
|
||||
{
|
||||
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)
|
||||
using (await _mutex1.LockAsync())
|
||||
{
|
||||
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 userPrice = await m_ProductUserPriceService.GetPackageUserPrice(pacageInfo.Id, userId);
|
||||
|
||||
var refundDayPrice = userPrice != null && userPrice.RefundDayPrice > 0 ? userPrice.RefundDayPrice : product.RefundDayPrice;
|
||||
|
||||
var lastOrder = await GetLastOrderByAccount(account);
|
||||
|
||||
var useDay = (int)Math.Ceiling((DateTime.Now - lastOrder.UpdateTime).TotalDays);
|
||||
var refundAmount = lastOrder.PaymentAmount / lastOrder.AccountCount - useDay * refundDayPrice.Value * accountInfo.ConnectCount;
|
||||
refundAmount = refundAmount <= 0 ? 0 : refundAmount;
|
||||
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 = "退款",
|
||||
RefundReason = reason,
|
||||
agent_id = accountInfo.agent_id
|
||||
};
|
||||
var time = (accountInfo.EndTime - DateTime.Now).Value;
|
||||
order.RefundRestTime = time.ToString(@"d\天hh\时mm\分");
|
||||
|
||||
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 reason = "";
|
||||
if(account.Contains("-")){
|
||||
string[] arrStr = account.Split('-');
|
||||
account = arrStr[0];
|
||||
reason = arrStr[1];
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
if(order.agent_id != 0 ){
|
||||
var accountInfo = await m_ProductAccountService.GetAccountInfo(account, userId);
|
||||
|
||||
var agentEntity = await m_AgentUserService.Query(m => m.id == order.agent_id).FirstOrDefaultAsync();
|
||||
var agentPriceEntity = await m_AgentPriceService.Query(m => m.agent_id == order.agent_id && m.package_id == order.PackageId).FirstOrDefaultAsync();
|
||||
var agentScoreEntity = await m_AgentScoreService.Query(m => m.agent_id == order.agent_id && m.order_id == lastOrder.Id).FirstOrDefaultAsync();
|
||||
|
||||
var deduct_money = agentScoreEntity.score_value / lastOrder.AccountCount;
|
||||
|
||||
//
|
||||
//使用天数 回补佣金
|
||||
var re_money = useDay * (refundDayPrice.Value - agentPriceEntity.refund) * accountInfo.ConnectCount;
|
||||
//佣金
|
||||
var score_money = agentEntity.account - deduct_money + re_money;
|
||||
|
||||
var agnetScoreEntity = new AgentScoreEntity()
|
||||
if (accountInfo == null)
|
||||
{
|
||||
agent_id = order.agent_id,
|
||||
order_id = order.Id,
|
||||
score_type = 2,
|
||||
score_value = re_money - deduct_money,
|
||||
remark = "客户退款" + account,
|
||||
agent_name = agentEntity.username,
|
||||
op_user = order.UserName,
|
||||
rest_amount1 = agentEntity.account,
|
||||
rest_amount2 = score_money
|
||||
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 userPrice = await m_ProductUserPriceService.GetPackageUserPrice(pacageInfo.Id, userId);
|
||||
|
||||
var refundDayPrice = userPrice != null && userPrice.RefundDayPrice > 0 ? userPrice.RefundDayPrice : product.RefundDayPrice;
|
||||
|
||||
var lastOrder = await GetLastOrderByAccount(account);
|
||||
|
||||
var useDay = (int)Math.Ceiling((DateTime.Now - lastOrder.UpdateTime).TotalDays);
|
||||
var refundAmount = lastOrder.PaymentAmount / lastOrder.AccountCount - useDay * refundDayPrice.Value * accountInfo.ConnectCount;
|
||||
refundAmount = refundAmount <= 0 ? 0 : refundAmount;
|
||||
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 = "退款",
|
||||
RefundReason = reason,
|
||||
agent_id = accountInfo.agent_id
|
||||
};
|
||||
var time = (accountInfo.EndTime - DateTime.Now).Value;
|
||||
order.RefundRestTime = time.ToString(@"d\天hh\时mm\分");
|
||||
|
||||
agentEntity.account = score_money;
|
||||
var againBuy = lastOrder.OrderType == OrderType.AgainBuy || lastOrder.OrderType == OrderType.AgainBuys;
|
||||
|
||||
await m_AgentScoreService.Add(agnetScoreEntity);
|
||||
await m_AgentUserService.Update(agentEntity);
|
||||
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);
|
||||
|
||||
if(order.agent_id != 0 ){
|
||||
|
||||
var agentEntity = await m_AgentUserService.Query(m => m.id == order.agent_id).FirstOrDefaultAsync();
|
||||
var agentPriceEntity = await m_AgentPriceService.Query(m => m.agent_id == order.agent_id && m.package_id == order.PackageId).FirstOrDefaultAsync();
|
||||
var agentScoreEntity = await m_AgentScoreService.Query(m => m.agent_id == order.agent_id && m.order_id == lastOrder.Id).FirstOrDefaultAsync();
|
||||
|
||||
var deduct_money = agentScoreEntity.score_value / lastOrder.AccountCount;
|
||||
|
||||
//
|
||||
//使用天数 回补佣金
|
||||
var re_money = useDay * (refundDayPrice.Value - agentPriceEntity.refund) * accountInfo.ConnectCount;
|
||||
//佣金
|
||||
var score_money = agentEntity.account - deduct_money + re_money;
|
||||
|
||||
var agnetScoreEntity = new AgentScoreEntity()
|
||||
{
|
||||
agent_id = order.agent_id,
|
||||
order_id = order.Id,
|
||||
score_type = 2,
|
||||
score_value = re_money - deduct_money,
|
||||
remark = "客户退款" + account,
|
||||
agent_name = agentEntity.username,
|
||||
op_user = order.UserName,
|
||||
rest_amount1 = agentEntity.account,
|
||||
rest_amount2 = score_money
|
||||
};
|
||||
|
||||
agentEntity.account = score_money;
|
||||
|
||||
await m_AgentScoreService.Add(agnetScoreEntity);
|
||||
await m_AgentUserService.Update(agentEntity);
|
||||
}
|
||||
|
||||
return new ApiResult(1);
|
||||
}
|
||||
|
||||
return new ApiResult(1);
|
||||
}
|
||||
|
||||
public async Task<ApiResult> CaclRefund(int userId, string account)
|
||||
|
||||
Reference in New Issue
Block a user