Commit 5462b9e7 authored by liudong1993's avatar liudong1993

1 甲鹤市场主管提成规则

parent fcdd0d51
......@@ -112,5 +112,15 @@ namespace Edu.Model.Entity.Sell
/// </summary>
public decimal ExtraMoney { get; set; }
/// <summary>
/// 是否启用 主管奖励 1是
/// </summary>
public int EnableZGAward { get; set; }
/// <summary>
/// 主管奖励规则
/// </summary>
public string ZGAwardRule { get; set; }
}
}
......@@ -29,5 +29,10 @@ namespace Edu.Model.ViewModel.Sell
/// 返佣总金额
/// </summary>
public decimal CommissionMoney { get; set; }
/// <summary>
/// 奖励数量
/// </summary>
public int AwardOrderNum { get; set; }
}
}
\ No newline at end of file
......@@ -36,6 +36,11 @@ namespace Edu.Model.ViewModel.Sell
/// 校区名称
/// </summary>
public string SchoolName { get; set; }
/// <summary>
/// 业绩比例
/// </summary>
public List<AchievementsRateModel> ZGAwardList { get; set; }
}
/// <summary>
......
......@@ -76,6 +76,10 @@ namespace Edu.Module.Course
/// 学员协助人员仓储层对象
/// </summary>
private readonly RB_Student_AssistRepository student_AssistRepository = new RB_Student_AssistRepository();
/// <summary>
/// 学生表
/// </summary>
private readonly RB_StudentRepository studentRepository = new RB_StudentRepository();
/// <summary>
/// 签到
......@@ -152,6 +156,10 @@ namespace Edu.Module.Course
if (!string.IsNullOrEmpty(item.Content)) {
item.RateList = JsonHelper.DeserializeObject<List<AchievementsRateModel>>(item.Content);
}
item.ZGAwardList = new List<AchievementsRateModel>();
if (!string.IsNullOrEmpty(item.ZGAwardRule)) {
item.ZGAwardList = JsonHelper.DeserializeObject<List<AchievementsRateModel>>(item.ZGAwardRule);
}
item.CourseList = courseList.Where(x => ("," + item.CourseIds + ",").Contains("," + x.CourseId + ",")).ToList();
item.EmpList = empList.Where(x => ("," + item.EmpIds + ",").Contains("," + x.Id + ",")).ToList();
item.ChildEmpList = new List<Employee_ViewModel>();
......@@ -218,6 +226,8 @@ namespace Edu.Module.Course
{ nameof(RB_Sell_Achievements_Rule_ViewModel.SendType), demodel.SendType},
{ nameof(RB_Sell_Achievements_Rule_ViewModel.PeopleMoney), demodel.PeopleMoney},
{ nameof(RB_Sell_Achievements_Rule_ViewModel.ExtraMoney), demodel.ExtraMoney},
{ nameof(RB_Sell_Achievements_Rule_ViewModel.EnableZGAward), demodel.EnableZGAward},
{ nameof(RB_Sell_Achievements_Rule_ViewModel.ZGAwardRule), demodel.ZGAwardRule},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
......@@ -727,6 +737,10 @@ namespace Edu.Module.Course
string EDate = Convert.ToDateTime(month + "-01").AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
var orderList = orderRepository.GetAllAchievementsSendOrderList(userInfo.Group_Id, SDate, EDate, 1, "", SchoolIds, 1);//查询所有的
List<RB_Sell_Achievements_Emp_ViewModel> AchEmpList = new List<RB_Sell_Achievements_Emp_ViewModel>();//需要新增当月的
//查询当月有效到访人数(邀约到访30分钟以上)
var stuList = studentRepository.GetValidVisitNum(Convert.ToDateTime(month + "-01").ToString("yyyy-MM-dd"), EDate, userInfo.Group_Id);
if (orderList.Any()) {
//首先查询 根据规则 适配当月业绩 并生成对应的 订单人员业绩提成
foreach (var item in rulelist) {
......@@ -736,13 +750,18 @@ namespace Edu.Module.Course
{
item.RateList = JsonHelper.DeserializeObject<List<AchievementsRateModel>>(item.Content);
}
item.ZGAwardList = new List<AchievementsRateModel>();
if (!string.IsNullOrEmpty(item.ZGAwardRule))
{
item.ZGAwardList = JsonHelper.DeserializeObject<List<AchievementsRateModel>>(item.ZGAwardRule);
}
}
//根据订单 查询同行返佣
string orderIds = string.Join(",", orderList.Select(x => x.OrderId));
var bdList = order_ReturnComissionRepository.GetOrderReturnComissionListRepositpry(new RB_Order_ReturnComission_ViewModel() { GroupId = userInfo.Group_Id, QOrderIds = orderIds });
//获取订单的学生 是否邀约到访30分钟以上
var surList = orderRepository.GetStuSureConsultTimeForOrder(orderIds);
//var surList = orderRepository.GetStuSureConsultTimeForOrder(orderIds);
#region 验证订单是否已生成返佣 (必须有返佣数据 才能参与业绩提成)
var cbdOrderlist = bdList.Where(x => x.Status >= 0).Select(x => x.OrderId).ToList();
......@@ -964,7 +983,7 @@ namespace Edu.Module.Course
decimal bdCommission = bdList.Where(x => x.OrderId == qitem.OrderId).Sum(x => x.CommissionMoeny);
decimal tCommission = AchEmpList.Where(x => x.Type == 3 && x.OrderId == qitem.OrderId).Sum(x => x.PushMoney);
decimal orderYj = qitem.PreferPrice - qitem.DiscountMoney - bdCommission - tCommission;
int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
//int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
AchEmpList.Add(new RB_Sell_Achievements_Emp_ViewModel()
{
EmpId = qitem.EnterID,
......@@ -976,17 +995,48 @@ namespace Edu.Module.Course
OrderId = qitem.OrderId,
PeriodsId = 0,
Rate = 0,
PushMoney = item.PeopleMoney + (IsSureConsultTime == 1 ? item.ExtraMoney : 0),
PushMoney = item.PeopleMoney,
RuleId = item.Id,
SaleMoney = YjMoney,
OrderSaleMoney = orderYj,
Type = 1,
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";市场根据人数发放提成:" + item.PeopleMoney + "/人" + (IsSureConsultTime == 1 ? ";满足邀约咨询30分钟以上奖励" + item.ExtraMoney : "")
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";市场根据人数发放提成:" + item.PeopleMoney + "/人"
});
}
}
}
}
if (item.ExtraMoney > 0)
{//有效到访额外奖励
List<int> EmpList = JsonHelper.DeserializeObject<List<int>>("[" + item.EmpIds + "]");
foreach (var emp in EmpList)
{
//验证是否有 有效到访奖励
var stuModel = stuList.Where(x => x.CreateBy == emp).FirstOrDefault();
if (stuModel != null)
{
AchEmpList.Add(new RB_Sell_Achievements_Emp_ViewModel()
{
EmpId = emp,
GiveOutMoney = item.ExtraMoney * stuModel.OrderCount,
GiveOutState = 1,
Group_Id = userInfo.Group_Id,
Id = 0,
IsDept = 2,
OrderId = -1,
PeriodsId = 0,
Rate = 0,
PushMoney = item.ExtraMoney * stuModel.OrderCount,
RuleId = item.Id,
SaleMoney = 0,
OrderSaleMoney = 0,
Type = 1,
Remark = "当月满足邀约咨询30分钟以上共计 " + stuModel.OrderCount + "人,奖励 " + item.ExtraMoney * stuModel.OrderCount
});
}
}
}
}
//顾问
else
......@@ -1056,7 +1106,7 @@ namespace Edu.Module.Course
decimal bdCommission = bdList.Where(x => x.OrderId == qitem.OrderId).Sum(x => x.CommissionMoeny);
decimal tCommission = AchEmpList.Where(x => x.Type == 3 && x.OrderId == qitem.OrderId).Sum(x => x.PushMoney);
decimal orderYj = qitem.PreferPrice - qitem.DiscountMoney - bdCommission - tCommission;
int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
//int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
AchEmpList.Add(new RB_Sell_Achievements_Emp_ViewModel()
{
EmpId = qitem.CourseConsultantId,
......@@ -1068,12 +1118,12 @@ namespace Edu.Module.Course
OrderId = qitem.OrderId,
PeriodsId = 0,
Rate = 0,
PushMoney = item.PeopleMoney + (IsSureConsultTime == 1 ? item.ExtraMoney : 0),
PushMoney = item.PeopleMoney, //+ (IsSureConsultTime == 1 ? item.ExtraMoney : 0),
RuleId = item.Id,
SaleMoney = YjMoney,
OrderSaleMoney = orderYj,
Type = 2,
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";根据人数发放提成:" + item.PeopleMoney + "/人" + (IsSureConsultTime == 1 ? ";满足邀约咨询30分钟以上奖励" + item.ExtraMoney : "")
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";根据人数发放提成:" + item.PeopleMoney + "/人" //+ (IsSureConsultTime == 1 ? ";满足邀约咨询30分钟以上奖励" + item.ExtraMoney : "")
});
}
}
......@@ -1150,7 +1200,7 @@ namespace Edu.Module.Course
decimal bdCommission = bdList.Where(x => x.OrderId == qitem.OrderId).Sum(x => x.CommissionMoeny);
decimal tCommission = AchEmpList.Where(x => x.Type == 3 && x.OrderId == qitem.OrderId).Sum(x => x.PushMoney);
decimal orderYj = qitem.PreferPrice - qitem.DiscountMoney - bdCommission - tCommission;
int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
//int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
foreach (var emp in EmpList)
{
AchEmpList.Add(new RB_Sell_Achievements_Emp_ViewModel()
......@@ -1164,17 +1214,49 @@ namespace Edu.Module.Course
OrderId = qitem.OrderId,
PeriodsId = 0,
Rate = 0,
PushMoney = item.PeopleMoney + (IsSureConsultTime == 1 ? item.ExtraMoney : 0),
PushMoney = item.PeopleMoney, //+ (IsSureConsultTime == 1 ? item.ExtraMoney : 0),
RuleId = item.Id,
SaleMoney = YjMoney,
OrderSaleMoney = orderYj,
Type = 1,
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";市场根据人数发放提成:" + item.PeopleMoney + "/人" + (IsSureConsultTime == 1 ? ";满足邀约咨询30分钟以上奖励" + item.ExtraMoney : "")
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";市场根据人数发放提成:" + item.PeopleMoney + "/人" //+ (IsSureConsultTime == 1 ? ";满足邀约咨询30分钟以上奖励" + item.ExtraMoney : "")
});
}
}
}
}
//启用部门
if (item.EnableZGAward == 1)
{
//算计部门下所有人 所有有效到访
int peopleNum = stuList.Where(x => item.ChildEmpIds.Split(',').Contains(x.CreateBy.ToString())).Sum(x => x.OrderCount);
var awardModel = item.ZGAwardList.Where(x => x.StartValue <= peopleNum && (x.EndValue > peopleNum || x.EndValue == -1)).FirstOrDefault();
if (awardModel != null)
{
foreach (var emp in EmpList)
{
AchEmpList.Add(new RB_Sell_Achievements_Emp_ViewModel()
{
EmpId = emp,
GiveOutMoney = awardModel.Rate,
GiveOutState = 1,
Group_Id = userInfo.Group_Id,
Id = 0,
IsDept = 1,
OrderId = -1,
PeriodsId = 0,
Rate = 0,
PushMoney = awardModel.Rate,
RuleId = item.Id,
SaleMoney = 0,
OrderSaleMoney = 0,
Type = 1,
Remark = "当月部门下满足邀约咨询30分钟以上共计" + peopleNum + "人,绩效奖励" + awardModel.Rate,
AwardOrderNum = peopleNum
});
}
}
}
}
else {
var consultantOrderList = orderList.Where(x => x.CourseConsultantId > 0 && ("," + item.ChildEmpIds + ",").Contains("," + x.CourseConsultantId + ",") && ("," + item.SchoolIds + ",").Contains("," + x.ClassSchoolId + ",")).ToList();
......@@ -1240,7 +1322,7 @@ namespace Edu.Module.Course
decimal bdCommission = bdList.Where(x => x.OrderId == qitem.OrderId).Sum(x => x.CommissionMoeny);
decimal tCommission = AchEmpList.Where(x => x.Type == 3 && x.OrderId == qitem.OrderId).Sum(x => x.PushMoney);
decimal orderYj = qitem.PreferPrice - qitem.DiscountMoney - bdCommission - tCommission;
int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
//int IsSureConsultTime = surList.Where(x => x.OrderId == qitem.OrderId).FirstOrDefault()?.OrderCount ?? 0;
foreach (var emp in EmpList)
{
AchEmpList.Add(new RB_Sell_Achievements_Emp_ViewModel()
......@@ -1254,12 +1336,12 @@ namespace Edu.Module.Course
OrderId = qitem.OrderId,
PeriodsId = 0,
Rate = 0,
PushMoney = item.PeopleMoney + (IsSureConsultTime == 1 ? item.ExtraMoney : 0),
PushMoney = item.PeopleMoney, //+ (IsSureConsultTime == 1 ? item.ExtraMoney : 0),
RuleId = item.Id,
SaleMoney = YjMoney,
OrderSaleMoney = orderYj,
Type = 2,
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";根据人数发放提成:" + item.PeopleMoney + "/人" + (IsSureConsultTime == 1 ? ";满足邀约咨询30分钟以上奖励" + item.ExtraMoney : "")
Remark = "当月业绩:" + TotalYj + ";当月老师提成:" + teacherMoney + ";订单b2b返佣:" + bdCommission + ";订单老师提成:" + tCommission + ";订单业绩:" + orderYj + ";根据人数发放提成:" + item.PeopleMoney + "/人" //+ (IsSureConsultTime == 1 ? ";满足邀约咨询30分钟以上奖励" + item.ExtraMoney : "")
});
}
}
......@@ -1507,6 +1589,35 @@ namespace Edu.Module.Course
}
}
}
//处理 主管 额外奖励
if (AchEmpList.Where(x => x.OrderId == -1).Any()) {
foreach (var qitem in AchEmpList.Where(x => x.OrderId == -1)) {
CurrentList.Add(new RB_Sell_Achievements_Details_ViewModel()
{
UserId = qitem.EmpId,
OrderId = qitem.OrderId,
CurrentPeriodMoney = qitem.GiveOutMoney,
IsFirstCommission = 1,
Remark = qitem.Remark,
ClassId = 0,
ClassType = 1,
PeriodId = 0,
Periods = month,
CommissionMoney = qitem.GiveOutMoney,
StudentCount = qitem.AwardOrderNum,
TotalHours = 0,
TotalLearn = 0,
CurrentHours = -1,//这种首次发放提成的 没有课时消费
GiveOutMoney = qitem.GiveOutMoney,
FirstRate = 100,
DeductionMoney = 0,
IsDept = qitem.IsDept,
UserType = qitem.Type,
RelatedId = qitem.Id
});
}
}
#endregion
#region 开始遍历
......@@ -1639,10 +1750,10 @@ namespace Edu.Module.Course
#region 订单关联更新
//查询所有相关的提成明细
string oIds = string.Join(",", AchEmpList.Select(x => x.OrderId).Distinct());
string oIds = string.Join(",", AchEmpList.Where(x => x.OrderId > 0).Select(x => x.OrderId).Distinct());
var adList = sell_Achievements_DetailsRepository.GetList(new RB_Sell_Achievements_Details_ViewModel() { Group_Id = userInfo.Group_Id, OrderIds = oIds });
//再次查询
foreach (var item in AchEmpList) {
foreach (var item in AchEmpList.Where(x=>x.OrderId>0)) {
var TotalCommission = adList.Where(x => x.OrderId == item.OrderId && x.UserId == item.EmpId && x.UserType == item.Type && x.IsDept == item.IsDept).Sum(x => x.CurrentPeriodMoney);
item.GiveOutMoney = TotalCommission;
item.GiveOutState = 2;
......@@ -1665,6 +1776,24 @@ namespace Edu.Module.Course
};
sell_Achievements_EmpRepository.Update(keyValues, wheres);
}
foreach (var item in AchEmpList.Where(x => x.OrderId == -1)) {
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Sell_Achievements_Emp.GiveOutMoney), item.GiveOutMoney},
{ nameof(RB_Sell_Achievements_Emp.GiveOutState), item.GiveOutState},
};
if (item.PeriodsId == 0)
{
keyValues.Add(nameof(RB_Sell_Achievements_Emp.PeriodsId), PeriodsId);
}
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName = nameof(RB_Sell_Achievements_Emp.Id),
FiledValue = item.Id,
OperatorEnum = OperatorEnum.Equal
}
};
sell_Achievements_EmpRepository.Update(keyValues, wheres);
}
#endregion
}
catch (Exception ex)
......
......@@ -456,6 +456,16 @@ WHERE 1=1
{
builder.AppendFormat(" AND (t.StuStage={0} OR t.AdvisorStatus={1}) ", 7, 7);
}
if (query.IsSureConsultTime > 0)
{
if (query.IsSureConsultTime == 1)
{
builder.AppendFormat(" AND t.{0}={1} ", nameof(RB_Student_ViewModel.IsSureConsultTime), 1);
}
else {
builder.AppendFormat(" AND t.{0}<>{1} ", nameof(RB_Student_ViewModel.IsSureConsultTime), 1);
}
}
//渠道
if (query.StuChannel > 0)
{
......@@ -1229,5 +1239,19 @@ WHERE s.`Status`=0 and s.Group_Id ={group_Id} and (s.CreateBy ={userId} or a.Ass
group by s.StuId";
return Get<RB_Student_ViewModel>(sql).ToList();
}
/// <summary>
/// 获取甲鹤学生到访30分钟以上的
/// </summary>
/// <param name="sDate"></param>
/// <param name="eDate"></param>
/// <param name="group_Id"></param>
/// <returns></returns>
public List<RB_Student_ViewModel> GetValidVisitNum(string sDate, string eDate, int group_Id)
{
string sql = $@"SELECT CreateBy,count(0) AS OrderCount FROM rb_student
WHERE Group_Id ={group_Id} and `Status` =0 and IsSureConsultTime =1 and CreateTime>='{sDate}' and CreateTime <='{eDate} 23:59:59' GROUP BY CreateBy";
return Get<RB_Student_ViewModel>(sql).ToList();
}
}
}
\ No newline at end of file
......@@ -70,6 +70,8 @@ namespace Edu.WebApi.Controllers.Course
x.SendType,
x.PeopleMoney,
x.ExtraMoney,
x.EnableZGAward,
x.ZGAwardList,
CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
}));
}
......@@ -137,6 +139,17 @@ namespace Edu.WebApi.Controllers.Course
demodel.Content = "";
}
if (demodel.EnableZGAward == 1)
{
if (demodel.ZGAwardList == null || !demodel.ZGAwardList.Any())
{
return ApiResult.ParamIsNull("请传递有效到访奖励");
}
demodel.ZGAwardRule = JsonHelper.Serialize(demodel.ZGAwardList);
}
else {
demodel.ZGAwardRule = "";
}
demodel.Status = 0;
demodel.Group_Id = userInfo.Group_Id;
demodel.CreateBy = userInfo.Id;
......
......@@ -701,6 +701,7 @@ namespace Edu.WebApi.Controllers.User
StuChannel = base.ParmJObj.GetInt("StuChannel"),
CreateType = (StuCreateTypeEnum)base.ParmJObj.GetInt("CreateType"),
StuSourceId = base.ParmJObj.GetInt("StuSourceId"),
IsSureConsultTime = base.ParmJObj.GetInt("IsSureConsultTime")
};
if (query.IsQueryMyStu == 1)
{
......
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