Commit e3fc219c authored by liudong1993's avatar liudong1993

销售业绩排名 接口调整

parent d3fe5023
......@@ -45,6 +45,11 @@ namespace Edu.Model.ViewModel.Finance
/// </summary>
public int? IsSelectNormal { get; set; }
/// <summary>
/// 查询订单相关单据
/// </summary>
public int IsSelectOrder { get; set; }
/// <summary>
/// 是否跟团相关
/// </summary>
......
......@@ -66,6 +66,16 @@ namespace Edu.Model.ViewModel.Sell
/// </summary>
public string EnterName { get; set; }
/// <summary>
/// 部门名称
/// </summary>
public string DeptName { get; set; }
/// <summary>
/// 校区名称
/// </summary>
public string SchoolName { get; set; }
/// <summary>
/// 订单查询状态 1正常 2取消
/// </summary>
......
......@@ -3882,6 +3882,80 @@ namespace Edu.Module.Finance
return list;
}
/// <summary>
/// 获取销售业绩排名 (单据版)
/// </summary>
/// <param name="startMonth"></param>
/// <param name="endMonth"></param>
/// <param name="group_Id"></param>
/// <returns></returns>
public List<RB_Order_ViewModel> GetSaleAchievementsRankStatistics_V2(string startMonth, string endMonth, int group_Id)
{
List<RB_Order_ViewModel> RList = new List<RB_Order_ViewModel>();
List<int> empIdList = new List<int>();//业务员列表
//首先获取当月新增订单
var olist = orderRepository.GetNewOrderStatistics(startMonth, endMonth, group_Id);//业务员 应收 报名人数 订单数量
if (olist.Any()) {
empIdList.AddRange(olist.Select(x => x.EnterID));
}
//查询当月已上课金额
var ylist = orderRepository.GetOrderClassHoursMoneyList(startMonth, endMonth, group_Id);//业务员 已上课金额
if (ylist.Any())
{
empIdList.AddRange(ylist.Select(x => x.EnterID));
}
//查询当月结课人数
var jlist = orderRepository.GetOrderGuestEndClassList(startMonth, endMonth, group_Id);//业务员 结课数量
if (jlist.Any())
{
empIdList.AddRange(jlist.Select(x => x.EnterID));
}
#region 财务单据收入
//直接查询关联订单的单据
var flist = RB_FinanceRepository.GetListForReport(new RB_Finance_Extend() { RB_Group_Id = group_Id, IsSelectOrder = 1, FinanceType = 2, sAduitDate = Convert.ToDateTime(startMonth), eAduitDate = Convert.ToDateTime(endMonth) });
if (flist.Any()) {
empIdList.AddRange(flist.Select(x => x.CreateBy ?? 0));
}
#endregion
//查询人员
empIdList = empIdList.Where(x => x > 0).Distinct().ToList();
if (empIdList.Any()) {
string userIds = string.Join(",", empIdList);
var ulist = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = group_Id, QIds = userIds });
foreach (var umodel in ulist) {
var omodel = olist.Where(x => x.EnterID == umodel.Id).FirstOrDefault();
var ymodel = ylist.Where(x => x.EnterID == umodel.Id).FirstOrDefault();
var jmodel = jlist.Where(x => x.EnterID == umodel.Id).FirstOrDefault();
var fclist = flist.Where(x => x.CreateBy == umodel.Id).ToList();
decimal Income = fclist.Where(x => x.Type == WFTempLateClassEnum.IN).Sum(x => x.Money ?? 0);
decimal PlatformTax = fclist.Where(x => x.Type == WFTempLateClassEnum.IN).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
decimal Refund = fclist.Where(x => x.Type == WFTempLateClassEnum.OUT).Sum(x => x.Money ?? 0);
RList.Add(new RB_Order_ViewModel()
{
EnterID = umodel.Id,
EnterName = umodel.EmployeeName,
DeptName = umodel.DeptName,
SchoolName = umodel.SchoolName,
PreferPrice = omodel?.PreferPrice ?? 0,
Income = Income,
PlatformTax = PlatformTax,
Refund = Refund,
YSKMoney = ymodel?.YSKMoney ?? 0,
GuestNum = omodel?.GuestNum ?? 0,
JKNum = jmodel?.JKNum ?? 0,
CancelNum = omodel?.CancelNum ?? 0
});
}
}
RList = RList.OrderByDescending(x => x.Income).ThenBy(x => x.PreferPrice).ToList();
return RList;
}
/// <summary>
/// 获取Excel导出
/// </summary>
......
......@@ -240,6 +240,10 @@ WHERE {1} {2} ", TableName, where, " ORDER BY A.FrID DESC");
where.Append(" and IFNULL(E.TCID,0) >0");//班级上的单据
where.Append(" and IFNULL(b.OrderID,0) =0");
}
if (model.IsSelectOrder == 1)
{
where.Append(" and IFNULL(b.OrderID,0) >0");//只查询订单相关单据
}
if (model.OrderSource.HasValue)
{
where.Append(" and IFNULL(b.OrderSource,0) =" + (int)model.OrderSource);
......@@ -249,7 +253,7 @@ WHERE {1} {2} ", TableName, where, " ORDER BY A.FrID DESC");
where.Append(" AND b." + nameof(RB_Finance.FinanceType) + "=" + model.FinanceType + "");
}
builder.AppendFormat(@"select distinct b.FrID,IFNULL(b.MatchMoney,0) as MatchMoney,IFNULL(E.TCID,0)TCID,D.Name,b.Status,b.TradeDate,b.CreateDate,b.RB_Branch_Id,a.ID,a.CostTypeId,IFNULL(b.Is_Cashier,0)Is_Cashier,a.Money,IFNULL(b.OrderID,0) OrderID,b.OrderSource,b.SourceID,IFNULL(b.PayMoney,0)PayMoney,IFNULL(b.Fee,0)Fee,b.Type
builder.AppendFormat(@"select distinct b.FrID,IFNULL(b.MatchMoney,0) as MatchMoney,IFNULL(E.TCID,0)TCID,D.Name,b.Status,b.TradeDate,b.CreateBy,b.CreateDate,b.RB_Branch_Id,a.ID,a.CostTypeId,IFNULL(b.Is_Cashier,0)Is_Cashier,a.Money,IFNULL(b.OrderID,0) OrderID,b.OrderSource,b.SourceID,IFNULL(b.PayMoney,0)PayMoney,IFNULL(b.Fee,0)Fee,b.Type
from rb_financedetail a INNER JOIN rb_finance as b on a.FinanceId=b.FrID and a.`Status`=0
INNER JOIN rb_costtype AS D ON D.ID=a.CostTypeId
LEFT JOIN rb_tradeway as td ON b.FrID=td.FinanceId
......
......@@ -680,7 +680,7 @@ SELECT g.Id,g.OrderId
INNER JOIN rb_education_contract ec on g.Id = ec.GuestId
LEFT JOIN (SELECT ch.OrderGuestId, SUM(ch.CurrentDeductionHours) AS CurrentDeductionHours FROM rb_class_check ch WHERE `Status` =0 GROUP BY ch.OrderGuestId) cc on cc.OrderGuestId = g.Id
)q GROUP BY q.OrderId) ttt on ttt.OrderId = o.OrderId
WHERE o.Group_Id={group_Id} and o.OrderState <> 3 and o.EnterID >0 {where} and o.CreateTime >='{startMonth}' and o.CreateTime <='{endMonth}'
WHERE o.Group_Id={group_Id} and o.OrderState <> 3 and o.EnterID >0 {where} and o.CreateTime >='{startMonth}' and o.CreateTime <='{endMonth} 23:59:59'
GROUP BY o.EnterID ORDER BY SUM(o.Income + o.PlatformTax - o.Refund) DESC
";
return GetPage<RB_Order_ViewModel>(pageIndex, pageSize, out count, sql).ToList();
......@@ -734,6 +734,75 @@ GROUP BY o.EnterID ORDER BY SUM(o.Income + o.PlatformTax - o.Refund) DESC
return Get<RB_Order_ViewModel>(sql).ToList();
}
/// <summary>
/// 获取时间范围内 新增订单统计
/// </summary>
/// <param name="startMonth"></param>
/// <param name="endMonth"></param>
/// <param name="group_Id"></param>
/// <returns></returns>
public List<RB_Order_ViewModel> GetNewOrderStatistics(string startMonth, string endMonth, int group_Id)
{
string sql = $@"SELECT o.EnterID,SUM(o.PreferPrice - o.DiscountMoney) as PreferPrice,SUM(o.GuestNum) AS GuestNum,COUNT(0) AS CancelNum
FROM rb_order o
WHERE o.Group_Id={group_Id} and o.OrderState <> 3 and o.EnterID >0 and o.CreateTime >='{startMonth}' and o.CreateTime <='{endMonth} 23:59:59'
GROUP BY o.EnterID
";
return Get<RB_Order_ViewModel>(sql).ToList();
}
/// <summary>
/// 获取时间范围内 学生上课金额
/// </summary>
/// <param name="startMonth"></param>
/// <param name="endMonth"></param>
/// <param name="group_Id"></param>
/// <returns></returns>
public List<RB_Order_ViewModel> GetOrderClassHoursMoneyList(string startMonth, string endMonth, int group_Id)
{
string sql = $@"SELECT o.EnterID,
SUM((case when q.ClassHours>0 and q.TotalSub >0 then
(q.CourseFee - q.DiscountMoney / q.TotalSub * q.CourseFee) /q.ClassHours
else 0 END) * IFNULL(q.CurrentDeductionHours,0)) AS YSKMoney
FROM(
SELECT g.Id,g.OrderId
,ec.FirstCourseFee + ec.SecondCourseFee + ec.ThirdCourseFee as CourseFee
,ec.FirstDiscountMoney + ec.SecondDiscountMoney + ec.ThirdDiscountMoney as DiscountMoney
,ec.FirstCourseFee + ec.SecondCourseFee + ec.ThirdCourseFee
+ec.FirstBookFee + ec.SecondBookFee + ec.ThirdBookFee
+ec.FirstClassFee + ec.SecondClassFee + ec.ThirdClassFee as TotalSub
,ec.FirstClassHours + ec.SecondClassHours + ec.ThirdClassHours as ClassHours
,cc.CurrentDeductionHours
FROM rb_order_guest g
INNER JOIN rb_education_contract ec on g.Id = ec.GuestId
INNER JOIN (
SELECT ch.OrderGuestId, SUM(ch.CurrentDeductionHours) AS CurrentDeductionHours
FROM rb_class_check ch WHERE ch.`Status` =0 AND ch.ClassDate >='{startMonth}' AND ch.ClassDate <='{endMonth} 23:59:59' GROUP BY ch.OrderGuestId) cc on cc.OrderGuestId = g.Id
WHERE g.Group_Id ={group_Id}
)q
LEFT JOIN rb_order o on q.OrderId = o.OrderId
GROUP BY o.EnterID
";
return Get<RB_Order_ViewModel>(sql).ToList();
}
/// <summary>
/// 获取时间范围内 结课学生数量
/// </summary>
/// <param name="startMonth"></param>
/// <param name="endMonth"></param>
/// <param name="group_Id"></param>
/// <returns></returns>
public List<RB_Order_ViewModel> GetOrderGuestEndClassList(string startMonth, string endMonth, int group_Id)
{
string sql = $@"SELECT o.EnterID,COUNT(0) AS JKNum FROM rb_order_guest g
LEFT JOIN rb_order o on g.OrderId = o.OrderId
WHERE g.`Status`=0 and g.Group_Id ={group_Id} and g.GuestState =7 and o.OrderState <> 3 and g.GraduationTime >='{startMonth}' and g.GraduationTime >='{endMonth} 23:59:59'
GROUP BY o.EnterID
";
return Get<RB_Order_ViewModel>(sql).ToList();
}
#endregion
......@@ -976,6 +1045,7 @@ ORDER BY {orderBy}
";
return Get<RB_Order_ViewModel>(sql).ToList();
}
#endregion
}
}
......@@ -1911,6 +1911,53 @@ namespace Edu.WebApi.Controllers.Finance
return ApiResult.Success("", pageModel);
}
/// <summary>
/// 获取销售业绩排名统计
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetSaleAchievementsRankStatistics_V2()
{
var userInfo = base.UserInfo;
string StartMonth = base.ParmJObj.GetStringValue("StartMonth");
string EndMonth = base.ParmJObj.GetStringValue("EndMonth");
if (string.IsNullOrEmpty(StartMonth))
{
return ApiResult.ParamIsNull("请选择开始月份");
}
if (string.IsNullOrEmpty(EndMonth))
{
return ApiResult.ParamIsNull("请选择结束月份");
}
try
{
StartMonth = Convert.ToDateTime(StartMonth + "-01").ToString("yyyy-MM-dd");
EndMonth = Convert.ToDateTime(EndMonth + "-01").AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
}
catch (Exception)
{
return ApiResult.Failed("日期格式有误");
}
var list = financeModule.GetSaleAchievementsRankStatistics_V2(StartMonth, EndMonth, userInfo.Group_Id);
return ApiResult.Success("", list.Select(x => new
{
x.EnterID,
x.EnterName,
x.DeptName,
x.SchoolName,
x.PreferPrice,
x.Income,
x.PlatformTax,
x.Refund,
RIncome = x.Income - x.Refund,
YSKMoney = Math.Round(x.YSKMoney, 6, MidpointRounding.AwayFromZero),
x.GuestNum,
x.JKNum,
OrderNum = x.CancelNum
}));
}
/// <summary>
/// 获取销售业绩统计
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment