Commit 21567372 authored by 黄奎's avatar 黄奎

页面修改

parent cbbf226a
using Edu.Model.ViewModel.Sell;
using Edu.Repository.Bonus;
using Edu.Repository.Sell;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Edu.Model.Entity.Bonus;
namespace Edu.Module.Course
{
/// <summary>
/// 员工月度人头奖金处理类
/// </summary>
public class EmployeeBonusModule
{
/// <summary>
/// 课程顾问、市场达标奖金配置仓储层对象
/// </summary>
private readonly RB_Bonus_PlanRepository bonus_PlanRepository = new RB_Bonus_PlanRepository();
/// <summary>
/// 员工人头奖励仓储层对象
/// </summary>
private readonly RB_Personnel_BonusRepository personnel_BonusRepository = new RB_Personnel_BonusRepository();
/// <summary>
/// 员工人头奖励抵扣详情仓储层对象
/// </summary>
private readonly RB_Personnel_DeductionRepository personnel_DeductionRepository = new RB_Personnel_DeductionRepository();
/// <summary>
/// 员工人头奖励详情仓储层对象
/// </summary>
private readonly RB_Personnel_BonusDetailRepository personnel_BonusDetailRepository = new RB_Personnel_BonusDetailRepository();
/// <summary>
/// 订单仓储层对象
/// </summary>
private readonly RB_OrderRepository orderRepository = new RB_OrderRepository();
/// <summary>
/// 生成业绩
/// </summary>
public void CreateEmployeeBonusModule(int GroupId)
{
string endDate = "2021-11-30";
int CurrentYear = 2021;
int CurrentMonth = 11;
//人头配置列表
var planList= bonus_PlanRepository.GetBounsPlanListRepository(new RB_Bonus_PlanExtend() {
Group_Id=GroupId
},isGetDetail:true);
foreach (var item in planList)
{
var saleList = Common.ConvertHelper.StringToList(item.SaleIds);
foreach (var saleId in saleList)
{
var orderList = GetSaleOrderList(item, GroupId, endDate, saleId);
var curNum = orderList?.Where(qitem => qitem.Year == CurrentYear && qitem.Month == CurrentMonth)?.Sum(qitem => qitem.GuestNum) ?? 0;
var curOrderMoney = orderList?.Where(qitem => qitem.Year == CurrentYear && qitem.Month == CurrentMonth)?.Sum(qitem => qitem.OrderMoney) ?? 0;
var pModel = new RB_Personnel_Bonus()
{
Id = 0,
RewardType = item.PlanType,
YearNum = CurrentYear,
MonthNum = CurrentMonth,
EmployeeId=saleId,
CurGuestNum= curNum,
CurOrderMoney= curOrderMoney,
Group_Id =GroupId,
CurRewardMoney= GetStepAwardAmount(item, curNum)
};
var newId = personnel_BonusRepository.Insert(pModel);
pModel.Id = newId;
foreach (var oItem in orderList)
{
}
}
}
}
/// <summary>
/// 获取梯度奖励金额
/// </summary>
/// <param name="item"></param>
/// <param name="GuestNum"></param>
/// <returns></returns>
private decimal GetStepAwardAmount(RB_Bonus_PlanExtend item,int GuestNum)
{
decimal awardAmount = 0;
if (item != null && item.DetailList != null && item.DetailList.Count > 0)
{
for (var i = 0; i < item.DetailList.Count; i++)
{
var tempNum = item.DetailList[i];
if (tempNum.StartNum <= GuestNum && GuestNum <= tempNum.EndNum)
{
awardAmount = tempNum.Money;
}
}
}
return awardAmount;
}
/// <summary>
/// 获取当前人员订单列表
/// </summary>
/// <param name="item"></param>
/// <param name="GroupId"></param>
/// <param name="endDate"></param>
/// <param name="SaleId"></param>
/// <returns></returns>
private List<PersionOrderItem> GetSaleOrderList(RB_Bonus_PlanExtend item,int GroupId,string endDate,int SaleId)
{
List<PersionOrderItem> list = new List<PersionOrderItem>();
//所有当前人员订单列表
var orderList = orderRepository.GetAllBonusOrderListRepository(GroupId, endDate,SaleId);
//适用课程
if (!string.IsNullOrEmpty(item.UseCourseIds))
{
orderList = orderList?.Where(qitem => item.UseCourseIds.Contains(qitem.CourseId.ToString()))?.ToList();
}
//不适用课程
if (!string.IsNullOrEmpty(item.NotUseCourseIds))
{
orderList = orderList?.Where(qitem => !item.NotUseCourseIds.Contains(qitem.CourseId.ToString()))?.ToList();
}
//按照年份、月份统计订单人数和金额
var groupList = orderList
.GroupBy(qitem => new { qitem.CreateTime.Year, qitem.CreateTime.Month })
.Select(qitem => new
{
qitem.Key.Year,
qitem.Key.Month,
GuestNum=qitem.Sum(s=>s.GuestNum),
OrderMoney=qitem.Sum(s=>s.Income - s.Refund + s.PlatformTax)
});
foreach (var gItem in groupList)
{
list.Add(new PersionOrderItem()
{
Year = gItem.Year,
Month = gItem.Month,
GuestNum = gItem.GuestNum,
OrderMoney = gItem.OrderMoney
});
}
return list;
}
}
/// <summary>
/// 人员销售
/// </summary>
public class PersionOrderItem
{
/// <summary>
/// 年份
/// </summary>
public int Year { get; set; }
/// <summary>
/// 月份
/// </summary>
public int Month { get; set; }
/// <summary>
/// 人数
/// </summary>
public int GuestNum { get; set; }
/// <summary>
/// 订单金额
/// </summary>
public decimal OrderMoney { get; set; }
}
}
...@@ -14,6 +14,12 @@ namespace Edu.Repository.Sell ...@@ -14,6 +14,12 @@ namespace Edu.Repository.Sell
/// </summary> /// </summary>
public class RB_Bonus_PlanRepository : BaseRepository<RB_Bonus_Plan> public class RB_Bonus_PlanRepository : BaseRepository<RB_Bonus_Plan>
{ {
/// <summary>
/// 课程顾问、市场达标奖金配置阶梯仓储层对象
/// </summary>
private readonly RB_Bouns_PlanDetailRepository bouns_PlanDetailRepository = new RB_Bouns_PlanDetailRepository();
/// <summary> /// <summary>
/// 获取课程顾问、市场达标奖金配置分页列表 /// 获取课程顾问、市场达标奖金配置分页列表
/// </summary> /// </summary>
...@@ -56,7 +62,7 @@ WHERE 1=1 ...@@ -56,7 +62,7 @@ WHERE 1=1
/// </summary> /// </summary>
/// <param name="query"></param> /// <param name="query"></param>
/// <returns></returns> /// <returns></returns>
public List<RB_Bonus_PlanExtend> GetBounsPlanListRepository(RB_Bonus_PlanExtend query) public List<RB_Bonus_PlanExtend> GetBounsPlanListRepository(RB_Bonus_PlanExtend query, bool isGetDetail = false)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.AppendFormat(@" builder.AppendFormat(@"
...@@ -76,7 +82,20 @@ WHERE 1=1 ...@@ -76,7 +82,20 @@ WHERE 1=1
builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Bonus_PlanExtend.PlanType), query.PlanType); builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Bonus_PlanExtend.PlanType), query.PlanType);
} }
} }
return Get<RB_Bonus_PlanExtend>(builder.ToString()).ToList(); var list= Get<RB_Bonus_PlanExtend>(builder.ToString()).ToList();
if (list != null && list.Count > 0 && isGetDetail)
{
string planIds = string.Join(",", list.Select(qitem => qitem.Id));
List<RB_Bouns_PlanDetail_Extend> detailList = bouns_PlanDetailRepository.GetBounsPlanDetailListRepository(new RB_Bouns_PlanDetail_Extend()
{
QPlanIds = planIds
});
foreach (var item in list)
{
item.DetailList = detailList?.Where(qitem => qitem.PlanId == item.Id)?.ToList();
}
}
return list;
} }
} }
} }
...@@ -1176,7 +1176,7 @@ group by o.OrderId ...@@ -1176,7 +1176,7 @@ group by o.OrderId
/// <param name="group_Id">集团编号</param> /// <param name="group_Id">集团编号</param>
/// <param name="eDate">结束日期</param> /// <param name="eDate">结束日期</param>
/// <returns></returns> /// <returns></returns>
public List<RB_Order_ViewModel> GetAllBonusOrderListRepository(int group_Id, string eDate) public List<RB_Order_ViewModel> GetAllBonusOrderListRepository(int group_Id, string eDate,int SaleId)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.AppendFormat(@" builder.AppendFormat(@"
...@@ -1197,6 +1197,10 @@ WHERE 1=1 ...@@ -1197,6 +1197,10 @@ WHERE 1=1
{ {
builder.AppendFormat(" AND o.CreateTime <= '{0} 23:59:59' ", eDate); builder.AppendFormat(" AND o.CreateTime <= '{0} 23:59:59' ", eDate);
} }
if (SaleId > 0)
{
builder.AppendFormat(" AND ( EnterID={0} OR CreateBy={0} ) ", SaleId);
}
builder.AppendFormat(" GROUP BY o.OrderId "); builder.AppendFormat(" GROUP BY o.OrderId ");
return Get<RB_Order_ViewModel>(builder.ToString()).ToList(); return Get<RB_Order_ViewModel>(builder.ToString()).ToList();
} }
......
...@@ -10,6 +10,7 @@ using Edu.Common.Plugin; ...@@ -10,6 +10,7 @@ using Edu.Common.Plugin;
using Edu.Model.CacheModel; using Edu.Model.CacheModel;
using Edu.Model.ViewModel.System; using Edu.Model.ViewModel.System;
using Edu.Model.ViewModel.User; using Edu.Model.ViewModel.User;
using Edu.Module.Course;
using Edu.Module.Duty; using Edu.Module.Duty;
using Edu.Module.Public; using Edu.Module.Public;
using Edu.Module.System; using Edu.Module.System;
...@@ -49,12 +50,16 @@ namespace Edu.WebApi.Controllers.User ...@@ -49,12 +50,16 @@ namespace Edu.WebApi.Controllers.User
/// </summary> /// </summary>
private readonly TeacherModule teacherModule = new TeacherModule(); private readonly TeacherModule teacherModule = new TeacherModule();
private readonly EmployeeBonusModule employeeBonusModule = new EmployeeBonusModule();
[HttpGet] [HttpGet]
[HttpPost] [HttpPost]
[AllowAnonymous] [AllowAnonymous]
public ApiResult Test() public ApiResult Test()
{ {
new DutyPlanModule().TransVisitorToStu(); //new DutyPlanModule().TransVisitorToStu();
var userInfo = base.UserInfo;
employeeBonusModule.CreateEmployeeBonusModule(userInfo.Group_Id);
return ApiResult.Success(); return ApiResult.Success();
} }
......
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