|
|
|
|
@@ -39,9 +39,11 @@ namespace Hncore.Pass.Vpn.Service
|
|
|
|
|
AgentUserService m_AgentUserService;
|
|
|
|
|
AgentScoreService m_AgentScoreService;
|
|
|
|
|
AgentPriceService m_AgentPriceService;
|
|
|
|
|
ProductPriceSchemeService m_ProductPriceSchemeService;
|
|
|
|
|
public ProductOrderService(CourseContext dbContext
|
|
|
|
|
, AgentUserService _AgentUserService
|
|
|
|
|
, AgentScoreService _AgentScoreService
|
|
|
|
|
, ProductPriceSchemeService _ProductPriceSchemeService
|
|
|
|
|
, AgentPriceService _AgentPriceService
|
|
|
|
|
, ProductService _ProductService
|
|
|
|
|
, ProductPackageService _ProductPackageService
|
|
|
|
|
@@ -56,6 +58,7 @@ namespace Hncore.Pass.Vpn.Service
|
|
|
|
|
{
|
|
|
|
|
m_DbContext = dbContext;
|
|
|
|
|
m_AgentUserService = _AgentUserService;
|
|
|
|
|
m_ProductPriceSchemeService = _ProductPriceSchemeService;
|
|
|
|
|
m_AgentScoreService = _AgentScoreService;
|
|
|
|
|
m_AgentPriceService = _AgentPriceService;
|
|
|
|
|
m_ProductService = _ProductService;
|
|
|
|
|
@@ -258,12 +261,34 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
|
|
|
|
var is_user_price = true;
|
|
|
|
|
|
|
|
|
|
var price = packageEntity.Price;
|
|
|
|
|
var userPrice = await this.m_ProductUserPriceService.Query(true).FirstOrDefaultAsync(m => m.UserId == userId && m.PackageId == packageEntity.Id && m.Status == 1);
|
|
|
|
|
if (userPrice != null && userPrice.UserPrice > 0)
|
|
|
|
|
{
|
|
|
|
|
price = userPrice.UserPrice;
|
|
|
|
|
is_user_price = false;
|
|
|
|
|
|
|
|
|
|
var dis_price = 1000000M;
|
|
|
|
|
|
|
|
|
|
if(userEntity.agent_id == 0||(userEntity.agent_id != 0 && userEntity.discount_id != 0)){
|
|
|
|
|
//根据折扣设置价格
|
|
|
|
|
var discount = await m_ProductPriceSchemeService.GetById(userEntity.discount_id);
|
|
|
|
|
if (discount != null)
|
|
|
|
|
{
|
|
|
|
|
dis_price = packageEntity.LinePrice * discount.discount / 100;
|
|
|
|
|
is_user_price = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//根据会员价
|
|
|
|
|
var userPrice = await this.m_ProductUserPriceService.Query(true).FirstOrDefaultAsync(m => m.UserId == userId && m.PackageId == packageEntity.Id && m.Status == 1);
|
|
|
|
|
if (userPrice != null && userPrice.UserPrice > 0)
|
|
|
|
|
{
|
|
|
|
|
dis_price = userPrice.UserPrice;
|
|
|
|
|
is_user_price = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(dis_price<price){
|
|
|
|
|
price = dis_price;
|
|
|
|
|
}
|
|
|
|
|
if(price<packageEntity.MinPrice){
|
|
|
|
|
price = packageEntity.MinPrice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ProductAccountCount == 0 && request.OrderType != OrderType.News && packageEntity.DayCount == 1 && request.ConnectCount == 1 && request.OrderType!=OrderType.AgainBuy&& request.OrderType!=OrderType.AgainBuys){
|
|
|
|
|
price = 0.1M;
|
|
|
|
|
@@ -739,11 +764,25 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userEntity = await m_UserService.GetById(order.UserId);
|
|
|
|
|
|
|
|
|
|
if(order.agent_id != 0 && order.PaymentAmount != 0.1M){
|
|
|
|
|
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 score_money = order.PaymentAmount - order.ConnectCount * order.AccountCount * agentPriceEntity.price;
|
|
|
|
|
|
|
|
|
|
//根据折扣设置价格
|
|
|
|
|
var score_money = 0.00M;
|
|
|
|
|
if(userEntity.agent_id == 0||(userEntity.agent_id != 0 && userEntity.discount_id != 0)){
|
|
|
|
|
//获取代理折扣
|
|
|
|
|
var discount = await m_ProductPriceSchemeService.GetById(agentEntity.discount_id);
|
|
|
|
|
var packageEntity = await m_ProductPackageService.GetById(order.PackageId);
|
|
|
|
|
var price = packageEntity.LinePrice * discount.discount / 100;
|
|
|
|
|
score_money = order.PaymentAmount - order.ConnectCount * order.AccountCount * price;
|
|
|
|
|
} else {
|
|
|
|
|
var agentPriceEntity = await m_AgentPriceService.Query(m => m.agent_id == order.agent_id && m.package_id == order.PackageId).FirstOrDefaultAsync();
|
|
|
|
|
score_money = order.PaymentAmount - order.ConnectCount * order.AccountCount * agentPriceEntity.price;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var agnetScoreEntity = new AgentScoreEntity()
|
|
|
|
|
{
|
|
|
|
|
@@ -764,6 +803,26 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
|
|
|
|
await m_AgentUserService.Update(agentEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userEntity.pay_time = DateTime.Now.ToString();
|
|
|
|
|
userEntity.ConsumeAmount += order.PaymentAmount;
|
|
|
|
|
|
|
|
|
|
//折扣设置
|
|
|
|
|
var user_discount_id = userEntity.discount_id;
|
|
|
|
|
if (userEntity.ConsumeAmount>=200 && userEntity.ConsumeAmount<500){
|
|
|
|
|
userEntity.discount_id = 1;
|
|
|
|
|
} else if(userEntity.ConsumeAmount>=500 && userEntity.ConsumeAmount<1500) {
|
|
|
|
|
userEntity.discount_id = 2;
|
|
|
|
|
} else if(userEntity.ConsumeAmount>=1500 && userEntity.ConsumeAmount<3000) {
|
|
|
|
|
userEntity.discount_id = 4;
|
|
|
|
|
} else if(userEntity.ConsumeAmount>=3000 && userEntity.ConsumeAmount<6000) {
|
|
|
|
|
userEntity.discount_id = 5;
|
|
|
|
|
} else if(userEntity.ConsumeAmount>=6000) {
|
|
|
|
|
userEntity.discount_id = 6;
|
|
|
|
|
}
|
|
|
|
|
if(userEntity.discount_id !=0 && userEntity.discount_id>user_discount_id && userEntity.agent_id!=0){
|
|
|
|
|
await m_UserService.Update(userEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -894,15 +953,35 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
|
|
|
|
}
|
|
|
|
|
var product = await this.m_ProductService.GetById(pacageInfo.ProductId);
|
|
|
|
|
|
|
|
|
|
var userPrice = await m_ProductUserPriceService.GetPackageUserPrice(pacageInfo.Id, userId);
|
|
|
|
|
//折扣
|
|
|
|
|
var refundDayPrice = 10.00M;
|
|
|
|
|
var userEntity = await m_UserService.GetById(userId);
|
|
|
|
|
if(userEntity.agent_id == 0||(userEntity.agent_id != 0 && userEntity.discount_id != 0)){
|
|
|
|
|
//获取代理折扣
|
|
|
|
|
var discount = await m_ProductPriceSchemeService.GetById(userEntity.discount_id);
|
|
|
|
|
refundDayPrice = (product.RefundDayPrice * discount.discount / 100).ToDecimal();
|
|
|
|
|
} else {
|
|
|
|
|
var userPrice = await m_ProductUserPriceService.GetPackageUserPrice(pacageInfo.Id, userId);
|
|
|
|
|
|
|
|
|
|
var refundDayPrice = userPrice != null && userPrice.RefundDayPrice > 0 ? userPrice.RefundDayPrice : product.RefundDayPrice;
|
|
|
|
|
refundDayPrice = (userPrice != null && userPrice.RefundDayPrice > 0 ? userPrice.RefundDayPrice : product.RefundDayPrice).ToDecimal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("=====================================================");
|
|
|
|
|
Console.WriteLine(refundDayPrice);
|
|
|
|
|
Console.WriteLine("=====================================================");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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,
|
|
|
|
|
@@ -958,15 +1037,25 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
|
|
|
|
|
|
|
|
|
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 re_money = 0.00M;
|
|
|
|
|
if(userEntity.agent_id == 0||(userEntity.agent_id != 0 && userEntity.discount_id != 0)){
|
|
|
|
|
//获取代理折扣
|
|
|
|
|
var discount = await m_ProductPriceSchemeService.GetById(agentEntity.discount_id);
|
|
|
|
|
re_money = useDay * (refundDayPrice - (product.RefundDayPrice).ToDecimal() * discount.discount / 100) * accountInfo.ConnectCount;
|
|
|
|
|
} else {
|
|
|
|
|
var agentPriceEntity = await m_AgentPriceService.Query(m => m.agent_id == order.agent_id && m.package_id == order.PackageId).FirstOrDefaultAsync();
|
|
|
|
|
//使用天数 回补佣金
|
|
|
|
|
re_money = useDay * (refundDayPrice - agentPriceEntity.refund) * accountInfo.ConnectCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//佣金
|
|
|
|
|
var score_money = agentEntity.account - deduct_money + re_money;
|
|
|
|
|
|
|
|
|
|
@@ -1017,13 +1106,24 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
|
|
|
|
}
|
|
|
|
|
var product = await this.m_ProductService.GetById(pacageInfo.ProductId);
|
|
|
|
|
|
|
|
|
|
var userPrice = await m_ProductUserPriceService.GetPackageUserPrice(pacageInfo.Id, userId);
|
|
|
|
|
|
|
|
|
|
var refundDayPrice = userPrice == null ? product.RefundDayPrice : userPrice.RefundDayPrice;
|
|
|
|
|
|
|
|
|
|
//折扣
|
|
|
|
|
var refundDayPrice = 10.00M;
|
|
|
|
|
var userEntity = await m_UserService.GetById(userId);
|
|
|
|
|
if(userEntity.agent_id == 0||(userEntity.agent_id != 0 && userEntity.discount_id != 0)){
|
|
|
|
|
//获取代理折扣
|
|
|
|
|
var discount = await m_ProductPriceSchemeService.GetById(userEntity.discount_id);
|
|
|
|
|
refundDayPrice = (product.RefundDayPrice * discount.discount / 100).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 useDay = (int)Math.Ceiling((DateTime.Now - lastOrder.UpdateTime).TotalDays);
|
|
|
|
|
var RefundAmount = lastOrder.PaymentAmount / lastOrder.AccountCount - useDay * refundDayPrice.Value * accountInfo.ConnectCount;
|
|
|
|
|
var RefundAmount = lastOrder.PaymentAmount / lastOrder.AccountCount - useDay * refundDayPrice * accountInfo.ConnectCount;
|
|
|
|
|
RefundAmount = RefundAmount <= 0 ? 0 : RefundAmount;
|
|
|
|
|
|
|
|
|
|
var time = (lastOrder.EndTime - DateTime.Now).Value;
|
|
|
|
|
|