代理商管理
This commit is contained in:
25
Services/Hncore.Pass.Vpn/Service/AgentPriceService.cs
Normal file
25
Services/Hncore.Pass.Vpn/Service/AgentPriceService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using System.Collections.Generic;
|
||||
using Hncore.Pass.BaseInfo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class AgentPriceService : ServiceBase<AgentPriceEntity>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AgentPriceService(CourseContext dbContext
|
||||
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Services/Hncore.Pass.Vpn/Service/AgentScoreService.cs
Normal file
25
Services/Hncore.Pass.Vpn/Service/AgentScoreService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using System.Collections.Generic;
|
||||
using Hncore.Pass.BaseInfo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class AgentScoreService : ServiceBase<AgentScoreEntity>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AgentScoreService(CourseContext dbContext
|
||||
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Services/Hncore.Pass.Vpn/Service/AgentUserService.cs
Normal file
25
Services/Hncore.Pass.Vpn/Service/AgentUserService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Domain;
|
||||
using Hncore.Pass.Vpn.Request.Product;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using System.Collections.Generic;
|
||||
using Hncore.Pass.BaseInfo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class AgentUserService : ServiceBase<AgentUserEntity>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AgentUserService(CourseContext dbContext
|
||||
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,13 @@ namespace Hncore.Pass.Vpn.Service
|
||||
ProductUserPriceService m_ProductUserPriceService;
|
||||
CouponService m_CouponService;
|
||||
ProductUserPriceService m_UserPriceService;
|
||||
AgentUserService m_AgentUserService;
|
||||
AgentScoreService m_AgentScoreService;
|
||||
AgentPriceService m_AgentPriceService;
|
||||
public ProductOrderService(CourseContext dbContext
|
||||
, AgentUserService _AgentUserService
|
||||
, AgentScoreService _AgentScoreService
|
||||
, AgentPriceService _AgentPriceService
|
||||
, ProductService _ProductService
|
||||
, ProductPackageService _ProductPackageService
|
||||
, UserService _UserService
|
||||
@@ -49,6 +55,9 @@ namespace Hncore.Pass.Vpn.Service
|
||||
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
m_AgentUserService = _AgentUserService;
|
||||
m_AgentScoreService = _AgentScoreService;
|
||||
m_AgentPriceService = _AgentPriceService;
|
||||
m_ProductService = _ProductService;
|
||||
m_ProductPackageService = _ProductPackageService;
|
||||
m_UserService = _UserService;
|
||||
@@ -515,9 +524,12 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
var isOk = true;
|
||||
var accounts = order.Accounts.Split(',').ToList();
|
||||
accounts = accounts.Distinct().ToList();
|
||||
|
||||
|
||||
if (order.OrderType == OrderType.New || order.OrderType == OrderType.News)
|
||||
{
|
||||
var accountEntitys = new List<ProductAccountEntity>();
|
||||
|
||||
await accounts.ForEachAsync(async account =>
|
||||
{
|
||||
var accountEntity = new ProductAccountEntity()
|
||||
@@ -689,6 +701,32 @@ 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 score_money = order.PaymentAmount - order.ConnectCount * order.AccountCount * agentPriceEntity.price;
|
||||
|
||||
var agnetScoreEntity = new AgentScoreEntity()
|
||||
{
|
||||
agent_id = order.agent_id,
|
||||
order_id = order.Id,
|
||||
score_type = 1,
|
||||
score_value = score_money,
|
||||
remark = "客户购买产品" + order.Accounts,
|
||||
agent_name = agentEntity.username,
|
||||
op_user = order.UserName,
|
||||
rest_amount1 = agentEntity.account,
|
||||
rest_amount2 = agentEntity.account + score_money
|
||||
};
|
||||
|
||||
agentEntity.account += score_money;
|
||||
|
||||
await m_AgentScoreService.Add(agnetScoreEntity);
|
||||
await m_AgentUserService.Update(agentEntity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//public async Task ProcessOrderAccountbak(ProductOrderEntity order)
|
||||
@@ -848,6 +886,7 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
RefundCount = 1,
|
||||
Remark = "退款",
|
||||
RefundReason = reason,
|
||||
agent_id = accountInfo.agent_id
|
||||
};
|
||||
var time = (accountInfo.EndTime - DateTime.Now).Value;
|
||||
order.RefundRestTime = time.ToString(@"d\天hh\时mm\分");
|
||||
@@ -876,6 +915,41 @@ FROM product_order where {where} GROUP BY Channel,ProductName order by Channel,
|
||||
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 score_money = deduct_money - refundAmount;
|
||||
if(score_money <= 0){
|
||||
score_money = deduct_money;
|
||||
} else {
|
||||
score_money = refundAmount;
|
||||
}
|
||||
|
||||
var agnetScoreEntity = new AgentScoreEntity()
|
||||
{
|
||||
agent_id = order.agent_id,
|
||||
order_id = order.Id,
|
||||
score_type = 2,
|
||||
score_value = score_money,
|
||||
remark = "客户退款" + account,
|
||||
agent_name = agentEntity.username,
|
||||
op_user = order.UserName,
|
||||
rest_amount1 = agentEntity.account,
|
||||
rest_amount2 = agentEntity.account - score_money
|
||||
};
|
||||
|
||||
agentEntity.account -= score_money;
|
||||
|
||||
await m_AgentScoreService.Add(agnetScoreEntity);
|
||||
await m_AgentUserService.Update(agentEntity);
|
||||
}
|
||||
|
||||
return new ApiResult(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Hncore.Pass.Vpn.Service
|
||||
|
||||
public async Task<List<ProductWithPackageUserPriceResponse>> GetPackageUserPrice(int userId)
|
||||
{
|
||||
var products = await m_ProductService.Query(true).OrderBy(m=>m.Sort).ToListAsync();
|
||||
var products = await m_ProductService.Query( m=>m.OnLine == 1).OrderBy(m=>m.Sort).ToListAsync();
|
||||
|
||||
var packages = m_ProductPackageService.Query(true);
|
||||
var userPrice = this.Query(m => m.UserId == userId);
|
||||
|
||||
Reference in New Issue
Block a user