Commit 695ce17c authored by liudong1993's avatar liudong1993

1

parent d75637ad
......@@ -432,7 +432,7 @@ namespace Edu.Model.Entity.Sell
public int OrderIdentify { get; set; }
/// <summary>
/// 同行返佣 1按课耗反 2付款返佣
/// 返佣类型(1比例返佣,2-固定金额返佣)
/// </summary>
public int CommissionReType { get; set; }
}
......
......@@ -407,16 +407,16 @@ namespace Edu.Module.Course
Id = 0,
OrderId = model.OrderId,
OrderSourceType = x.CreateType,
OrderSourceId = x.CreateType == StuCreateTypeEnum.EmployeeInput ? x.CreateBy : (x.CreateType == StuCreateTypeEnum.CustomerInput? x.CustomerId : x.StuSourceId),
OrderSourceId = x.CreateType == StuCreateTypeEnum.EmployeeInput ? x.CreateBy : (x.CreateType == StuCreateTypeEnum.CustomerInput ? x.CustomerId : x.StuSourceId),
Status = -1, //下单默认为不可返佣,等待付款完成后更新为待返佣
UnionCashOutId = 0,
StuId = x.StuId,
CommissionType = orderCount == 0 ? 1 : 2,
SchoolId=model.School_Id,
GroupId=model.Group_Id
SchoolId = model.School_Id,
GroupId = model.Group_Id,
Remark = ""
};
FormatOrderCommissionByCourse(ref commissionModel, model.CourseId);
returnComissionRepository.Insert(commissionModel);
});
}
......@@ -444,7 +444,8 @@ namespace Edu.Module.Course
TotalMoney = 0,
CreateBy = uid,
CreateDate = DateTime.Now,
GroupId = gid
GroupId = gid,
CommissionType = type
};
//查询符合返佣条件的学员(非订单)
var list = returnComissionRepository.GetListBySetBatch(gid, type);
......@@ -457,7 +458,7 @@ namespace Edu.Module.Course
OrderSourceType = g.Key.OrderSourceType,
OrderSourceId = g.Key.OrderSourceId,
CommissionMoeny = g.Sum(item => item.CommissionMoeny),
CommissionReType = type
CommissionType = type
}));
if (userResult.Any())
......@@ -573,7 +574,13 @@ namespace Edu.Module.Course
var sellPrice = courseModel.SellPrice * ((100-(m.CommissionType == 1 ? courseModel.B2CRatio : courseModel.B2CReNewRatio)) / 100);
if ((int)m.OrderSourceType == 1)
{
m.CommissionMoeny = sellPrice * ((m.CommissionType == 1 ? courseModel.B2CRbRatio : courseModel.B2CRNRatio)/100);
if (courseModel.CommissionReType == 1)
{
m.CommissionMoeny = Math.Round(sellPrice * ((m.CommissionType == 1 ? courseModel.B2CRbRatio : courseModel.B2CRNRatio) / 100), 2, MidpointRounding.AwayFromZero);
}
else {
m.CommissionMoeny = m.CommissionType == 1 ? courseModel.B2CRbRatio : courseModel.B2CRNRatio;
}
m.CommissionReType = m.CommissionType == 1 ? courseModel.B2CRbRatioType.ToInt() : courseModel.B2CRNRatioType.ToInt();
m.CommissionReValue = m.CommissionType == 1 ? courseModel.B2CRbRatioValue : courseModel.B2CRNRatioValue;
m.Remark = $"学员来源为:直客,学员为{(m.CommissionType == 1 ? "首次报名" : "续费报名")},本次报名金额为:{sellPrice},本次返佣金额为:{m.CommissionMoeny.ToString("0.00")}";
......@@ -583,14 +590,26 @@ namespace Edu.Module.Course
var customerModel = customerRepository.GetEntity(m.OrderSourceId);
if (customerModel.CustomerType == 1)
{
m.CommissionMoeny = sellPrice * ((m.CommissionType == 1 ? courseModel.B2BRebateRatio : courseModel.B2BReNewRatio) / 100);
if (courseModel.CommissionReType == 1)
{
m.CommissionMoeny = Math.Round(sellPrice * ((m.CommissionType == 1 ? courseModel.B2BRebateRatio : courseModel.B2BReNewRatio) / 100), 2, MidpointRounding.AwayFromZero);
}
else {
m.CommissionMoeny = m.CommissionType == 1 ? courseModel.B2BRebateRatio : courseModel.B2BReNewRatio;
}
m.CommissionReType = m.CommissionType == 1 ? courseModel.B2BRebateRatioType.ToInt() : courseModel.B2BReNewRatioType.ToInt();
m.CommissionReValue = m.CommissionType == 1 ? courseModel.B2BRebateRatioValue : courseModel.B2BReNewRatioValue;
m.Remark = $"学员来源为:同业,学员为{(m.CommissionType == 1 ? "首次报名" : "续费报名")},本次报名金额为:{sellPrice},本次返佣金额为:{m.CommissionMoeny.ToString("0.00")}";
}
else
{
m.CommissionMoeny = sellPrice * ((m.CommissionType == 1 ? courseModel.SchoolRebateRatio : courseModel.SchoolReNewRatio) / 100);
if (courseModel.CommissionReType == 1)
{
m.CommissionMoeny = Math.Round(sellPrice * ((m.CommissionType == 1 ? courseModel.SchoolRebateRatio : courseModel.SchoolReNewRatio) / 100), 2, MidpointRounding.AwayFromZero);
}
else {
m.CommissionMoeny = m.CommissionType == 1 ? courseModel.SchoolRebateRatio : courseModel.SchoolReNewRatio;
}
m.CommissionReType = m.CommissionType == 1 ? courseModel.SchoolRebateRatioType.ToInt() : courseModel.SchoolReNewRatioType.ToInt();
m.CommissionReValue = m.CommissionType == 1 ? courseModel.SchoolRebateRatioValue : courseModel.SchoolReNewRatioValue;
m.Remark = $"学员来源为:校代,学员为{(m.CommissionType == 1 ? "首次报名" : "续费报名")},本次报名金额为:{sellPrice},本次返佣金额为:{m.CommissionMoeny.ToString("0.00")}";
......@@ -598,14 +617,26 @@ namespace Edu.Module.Course
}
else if ((int)m.OrderSourceType == 3)
{
m.CommissionMoeny = sellPrice * ((m.CommissionType == 1 ? courseModel.InnerRecommendRatio : courseModel.InnerRecommendReNewRatio)/100);
if (courseModel.CommissionReType == 1)
{
m.CommissionMoeny = Math.Round(sellPrice * ((m.CommissionType == 1 ? courseModel.InnerRecommendRatio : courseModel.InnerRecommendReNewRatio) / 100), 2, MidpointRounding.AwayFromZero);
}
else {
m.CommissionMoeny = m.CommissionType == 1 ? courseModel.InnerRecommendRatio : courseModel.InnerRecommendReNewRatio;
}
m.CommissionReType = m.CommissionType == 1 ? courseModel.InnerRecommendRatioType.ToInt() : courseModel.InnerRecommendReNewRatioType.ToInt();
m.CommissionReValue = m.CommissionType == 1 ? courseModel.InnerRecommendRatioValue : courseModel.InnerRecommendReNewRatioValue.Value;
m.Remark = $"学员来源为:内部介绍,学员为{(m.CommissionType == 1 ? "首次报名" : "续费报名")},本次报名金额为:{sellPrice},本次返佣金额为:{m.CommissionMoeny.ToString("0.00")}";
}
else if ((int)m.OrderSourceType == 4)
{
m.CommissionMoeny = sellPrice * ((m.CommissionType == 1 ? (courseModel.TransIntroductceRatio) : courseModel.TransIntroductceReNewRatio)/100);
if (courseModel.CommissionReType == 1)
{
m.CommissionMoeny = Math.Round(sellPrice * ((m.CommissionType == 1 ? (courseModel.TransIntroductceRatio) : courseModel.TransIntroductceReNewRatio) / 100), 2, MidpointRounding.AwayFromZero);
}
else {
m.CommissionMoeny = m.CommissionType == 1 ? (courseModel.TransIntroductceRatio) : courseModel.TransIntroductceReNewRatio;
}
m.CommissionReType = m.CommissionType == 1 ? courseModel.TransIntroductceRatioType.ToInt() : courseModel.TransIntroductceReNewRatioType.ToInt();
m.CommissionReValue = m.CommissionType == 1 ? courseModel.TransIntroductceRatioValue : courseModel.TransIntroductceReNewRatioValue;
m.Remark = $"学员来源为:学员转介绍,学员为{(m.CommissionType == 1 ? "首次报名" : "续费报名")},本次报名金额为:{sellPrice},本次返佣金额为:{m.CommissionMoeny.ToString("0.00")}";
......@@ -686,6 +717,7 @@ namespace Edu.Module.Course
demodel.TransIntroductceReNewRatio = courseModel.TransIntroductceReNewRatio;
demodel.InnerRecommendRatio = courseModel.InnerRecommendRatio;
demodel.InnerRecommendReNewRatio = courseModel.InnerRecommendReNewRatio;
demodel.CommissionReType = courseModel.CommissionReType;
}
else {
//使用订单的比例
......@@ -699,42 +731,16 @@ namespace Edu.Module.Course
courseModel.TransIntroductceReNewRatio = orderModel.TransIntroductceReNewRatio;
courseModel.InnerRecommendRatio = orderModel.InnerRecommendRatio;
courseModel.InnerRecommendReNewRatio = orderModel.InnerRecommendReNewRatio;
courseModel.CommissionReType = orderModel.CommissionReType;
}
#endregion
#region 计算订单优惠信息
List<RB_Student_ViewModel> StuList = new List<RB_Student_ViewModel>();
List<RB_Customer_BalanceDetail_ViewModel> BalanceList = new List<RB_Customer_BalanceDetail_ViewModel>();//返佣 幸福存折
//计算续费订单优惠
if (demodel.JoinType == OrderJoinTypeEnum.RenewOrder && demodel.OrderId == 0)
{
demodel.DiscountMoney = coursePrice * (courseModel.B2CReNewRatio / 100);
demodel.SaleRemark = "续费报名优惠" + courseModel.B2CReNewRatio + "%";
if (demodel.CustomerId > 0)
{
if (demodel.GuestNum > 0)
{
var customerModel = customerRepository.GetEntity(demodel.CustomerId);
string Description = "续费返佣;课程售价:" + courseModel.SellPrice + ";优惠比例:" + courseModel.B2CReNewRatio + "%;返佣比例:" + (customerModel.CustomerType == 2 ? courseModel.SchoolReNewRatio : courseModel.B2BReNewRatio) + "%";
decimal RenewCommission = Math.Round(courseModel.SellPrice * ((100 - courseModel.B2CReNewRatio) / 100) * ((customerModel.CustomerType == 2 ? courseModel.SchoolReNewRatio : courseModel.B2BReNewRatio) / 100) * demodel.GuestNum, 2, MidpointRounding.AwayFromZero);
BalanceList.Add(new RB_Customer_BalanceDetail_ViewModel()
{
Id = 0,
RebateType = 2,
CustomerId = demodel.CustomerId,
BalanceType = 1,
Money = RenewCommission,
Description = Description,
PeopleNum = demodel.GuestNum,
EmployeeId = demodel.EnterID,
Group_Id = demodel.Group_Id,
School_Id = demodel.School_Id,
ClassId = demodel.ClassId,
BalanceState = 2,
IsRemit = 2,
UpdateTime = DateTime.Now,
});
}
}
}
else if ((demodel.JoinType == OrderJoinTypeEnum.Normal || demodel.JoinType == OrderJoinTypeEnum.InsertClass) && demodel.OrderIdentify != 2)
{
......@@ -745,33 +751,6 @@ namespace Edu.Module.Course
message = "优惠金额不正确";
return false;
}
if (demodel.CustomerId > 0)
{
//生成待返佣记录表
if (demodel.GuestNum > 0)
{
var customerModel = customerRepository.GetEntity(demodel.CustomerId);
string Description = "首次返佣;课程售价:" + courseModel.SellPrice + ";优惠比例:" + courseModel.B2CRatio + "%;返佣比例:" + (customerModel.CustomerType == 2 ? courseModel.SchoolRebateRatio : courseModel.B2BRebateRatio) + "%";
decimal NormalCommission = Math.Round(courseModel.SellPrice * ((100 - courseModel.B2CRatio) / 100) * ((customerModel.CustomerType == 2 ? courseModel.SchoolRebateRatio : courseModel.B2BRebateRatio) / 100) * demodel.GuestNum, 2, MidpointRounding.AwayFromZero);
BalanceList.Add(new RB_Customer_BalanceDetail_ViewModel()
{
Id = 0,
RebateType = 1,
CustomerId = demodel.CustomerId,
BalanceType = 1,
Money = NormalCommission,
Description = Description,
PeopleNum = demodel.GuestNum,
EmployeeId = demodel.EnterID,
Group_Id = demodel.Group_Id,
School_Id = demodel.School_Id,
ClassId = demodel.ClassId,
BalanceState = 2,
IsRemit = 2,
UpdateTime = DateTime.Now,
});
}
}
}
else if (demodel.OrderIdentify == 2 && demodel.OrderId == 0)
{
......@@ -812,61 +791,6 @@ namespace Edu.Module.Course
message = "优惠金额不正确";
return false;
}
if (demodel.CustomerId > 0)
{
var customerModel = customerRepository.GetEntity(demodel.CustomerId);
//生成待返佣记录表
decimal RenewCommission = 0, NormalCommission = 0;
if (RenewNum > 0)
{
string Description = "续费返佣;课程售价:" + courseModel.SellPrice + ";优惠比例:" + courseModel.B2CReNewRatio + "%;返佣比例:" + (customerModel.CustomerType == 2 ? courseModel.SchoolReNewRatio : courseModel.B2BReNewRatio) + "%";
RenewCommission = Math.Round(courseModel.SellPrice * ((100 - courseModel.B2CReNewRatio) / 100) * ((customerModel.CustomerType == 2 ? courseModel.SchoolReNewRatio : courseModel.B2BReNewRatio) / 100) * RenewNum, 2, MidpointRounding.AwayFromZero);
BalanceList.Add(new RB_Customer_BalanceDetail_ViewModel()
{
Id = 0,
RebateType = 2,
CustomerId = demodel.CustomerId,
BalanceType = 1,
Money = RenewCommission,
Description = Description,
PeopleNum = RenewNum,
EmployeeId = demodel.EnterID,
Group_Id = demodel.Group_Id,
School_Id = demodel.School_Id,
ClassId = demodel.ClassId,
BalanceState = 2,
IsRemit = 2,
UpdateTime = DateTime.Now,
});
}
if (NormalNum > 0)
{
string Description = "首次返佣;课程售价:" + courseModel.SellPrice + ";优惠比例:" + courseModel.B2CRatio + "%;返佣比例:" + (customerModel.CustomerType == 2 ? courseModel.SchoolRebateRatio : courseModel.B2BRebateRatio) + "%";
NormalCommission = Math.Round(courseModel.SellPrice * ((100 - courseModel.B2CRatio) / 100) * ((customerModel.CustomerType == 2 ? courseModel.SchoolRebateRatio : courseModel.B2BRebateRatio) / 100) * NormalNum, 2, MidpointRounding.AwayFromZero);
BalanceList.Add(new RB_Customer_BalanceDetail_ViewModel()
{
Id = 0,
RebateType = 1,
CustomerId = demodel.CustomerId,
BalanceType = 1,
Money = NormalCommission,
Description = Description,
PeopleNum = NormalNum,
EmployeeId = demodel.EnterID,
Group_Id = demodel.Group_Id,
School_Id = demodel.School_Id,
ClassId = demodel.ClassId,
BalanceState = 2,
IsRemit = 2,
UpdateTime = DateTime.Now,
});
}
if (demodel.NormalCommission != NormalCommission || demodel.RenewCommission != RenewCommission)
{
//message = "返佣金额不正确";
//return false;
}
}
}
else if (demodel.OrderIdentify == 2 && demodel.OrderId > 0) {
//直接验证优惠金额
......@@ -1046,7 +970,7 @@ namespace Edu.Module.Course
{ nameof(RB_Order_ViewModel.CourseConsultantId),demodel.CourseConsultantId},
};
flag = orderRepository.Update(keyValues, new WhereHelper(nameof(RB_Order_ViewModel.OrderId), demodel.OrderId));
//记录日志信息
#region 记录日志信息
LogContent = $"修改日语培训订单【{demodel.OrderId}】";
if (orderModel.GuestNum != demodel.GuestNum)
{
......@@ -1112,45 +1036,6 @@ namespace Edu.Module.Course
LogContent += $",销售备注由【{orderModel.SaleRemark}】修改为【{demodel.SaleRemark}】";
SaleRemark = demodel.SaleRemark;
}
#region 幸福存折
////重置返佣 幸福存折
//if (orderModel.CustomerId > 0 && BalanceList.Any())
//{
// var balanceList = customer_BalanceDetailRepository.GetCustomerBalanceDetailListRepository(new RB_Customer_BalanceDetail_ViewModel() { Group_Id = demodel.Group_Id, OrderId = demodel.OrderId });
// foreach (var item in BalanceList)
// {
// var bmodel = balanceList.Where(x => x.RebateType == item.RebateType).FirstOrDefault();
// if (bmodel == null)
// {
// item.OrderId = demodel.OrderId;
// item.OrderSource = (int)demodel.OrderSource;
// customer_BalanceDetailRepository.Insert(item);
// }
// else
// {
// Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
// { nameof(RB_Customer_BalanceDetail_ViewModel.Money), item.Money},
// { nameof(RB_Customer_BalanceDetail_ViewModel.Description), item.Description},
// { nameof(RB_Customer_BalanceDetail_ViewModel.UpdateTime), DateTime.Now},
// { nameof(RB_Customer_BalanceDetail_ViewModel.PeopleNum), item.PeopleNum}
// };
// List<WhereHelper> wheres1 = new List<WhereHelper>() {
// new WhereHelper(){
// FiledName = nameof(RB_Customer_BalanceDetail_ViewModel.Id),
// FiledValue = item.Id,
// OperatorEnum =OperatorEnum.Equal
// }
// };
// customer_BalanceDetailRepository.Update(keyValues1, wheres1);
// }
// }
// var delBList = balanceList.Where(x => !BalanceList.Select(y => y.RebateType).Contains(x.RebateType)).ToList();
// foreach (var item in delBList)
// {
// customer_BalanceDetailRepository.Delete(item);
// }
//}
#endregion
}
else
......@@ -1412,16 +1297,6 @@ namespace Edu.Module.Course
#endregion
}
}
//返佣幸福存折
//if (flag && demodel.CustomerId > 0 && BalanceList.Any())
//{
// foreach (var item in BalanceList)
// {
// item.OrderId = OrderId;
// item.OrderSource = (int)demodel.OrderSource;
// customer_BalanceDetailRepository.Insert(item);
// }
//}
#endregion
#region 更新甲鹤小程序规格对应的库存
......@@ -1509,6 +1384,9 @@ namespace Edu.Module.Course
}
#endregion
// 处理返佣信息
System.Threading.Tasks.Task.Run(() => SetReturnOrderCommission(demodel));
}
#region 写日志
......@@ -1542,13 +1420,9 @@ namespace Edu.Module.Course
School_Id = userInfo.School_Id,
SourceId = demodel.OrderId
});
}
}
}
#endregion
// 处理返佣信息
SetReturnOrderCommission(demodel);
return flag;
}
......
......@@ -40,7 +40,7 @@ namespace Edu.Repository.Sell
DynamicParameters parameters = new DynamicParameters();
parameters.Add("gid", groupId);
parameters.Add("type", groupId);
parameters.Add("type", type);
return Get<RB_Order_ReturnComission_ViewModel>(sql, parameters).ToList();
}
......@@ -53,7 +53,7 @@ namespace Edu.Repository.Sell
/// <returns></returns>
public bool UpdateModelByBatch(int batchId,string ids)
{
var sql = $"update rb_order_returncomission set Status=1,BatchId={batchId} where Id in(ids)";
var sql = $"update rb_order_returncomission set Status=1,BatchId={batchId} where Id in({ids})";
return Execute(sql, null) > 0;
}
......@@ -100,7 +100,7 @@ namespace Edu.Repository.Sell
}
if (demodel.OrderSourceType > 0)
{
where += $@" and r.{nameof(RB_Order_ReturnComission_ViewModel.OrderSourceType)} ={demodel.OrderSourceType}";
where += $@" and r.{nameof(RB_Order_ReturnComission_ViewModel.OrderSourceType)} ={(int)demodel.OrderSourceType}";
}
if (demodel.OrderSourceId > 0)
{
......@@ -163,7 +163,7 @@ where {where} order by r.Id desc";
}
if (demodel.OrderSourceType > 0)
{
where += $@" and r.{nameof(RB_Order_ReturnComission_ViewModel.OrderSourceType)} ={demodel.OrderSourceType}";
where += $@" and r.{nameof(RB_Order_ReturnComission_ViewModel.OrderSourceType)} ={(int)demodel.OrderSourceType}";
}
if (demodel.OrderSourceId > 0)
{
......@@ -222,7 +222,7 @@ from RB_Order_ReturnComission r where {where} group by r.OrderSourceType,r.Order
}
if (demodel.OrderSourceType > 0)
{
where += $@" and r.{nameof(RB_Order_ReturnComission_ViewModel.OrderSourceType)} ={demodel.OrderSourceType}";
where += $@" and r.{nameof(RB_Order_ReturnComission_ViewModel.OrderSourceType)} ={(int)demodel.OrderSourceType}";
}
if (demodel.OrderSourceId > 0)
{
......
......@@ -76,14 +76,8 @@ namespace Edu.Repository.Sell
/// <returns></returns>
public bool ExsitModelByMonth(int groupId,string month,int type)
{
var sql = "select Count(0) from RB_ReturnMoney_Batch a where a.GroupId=@gid and DATE_FORMAT(a.CreateDate,'%Y-%m')=@month and a.CommissionType=@type";
DynamicParameters parameters = new DynamicParameters();
parameters.Add("gid", groupId);
parameters.Add("month", month);
parameters.Add("type", type);
var result = ExecuteScalar(sql, parameters);
var sql = $@"select Count(0) from RB_ReturnMoney_Batch a where a.GroupId={groupId} and DATE_FORMAT(a.CreateDate,'%Y-%m')='{month}' and a.CommissionType={type}";
var result = ExecuteScalar(sql);
return Convert.ToInt32(result) > 0;
}
}
......
......@@ -143,6 +143,7 @@ namespace Edu.WebApi.Controllers.Course
x.SchoolName,
x.UserName,
x.OrderSourceType,
OrderSourceTypeName = x.OrderSourceType.ToName(),
x.OrderSourceId,
x.ClassId,
x.ClassName,
......@@ -154,7 +155,8 @@ namespace Edu.WebApi.Controllers.Course
x.BatchId,
x.BatchName,
x.StuId,
x.StuName
x.StuName,
x.CommissionType
})
};
return ApiResult.Success("", pageModel);
......@@ -231,8 +233,8 @@ namespace Edu.WebApi.Controllers.Course
new ExcelColumn(value: ""){ },
new ExcelColumn(value: ""){ },
new ExcelColumn(value: ""){ },
new ExcelColumn(value: TotalMoney.ToString("#0.00")){ },
new ExcelColumn(value: ""){ },
new ExcelColumn(value: TotalMoney.ToString("#0.00")){ },
new ExcelColumn(value: ""){ },
new ExcelColumn(value: ""){ },
new ExcelColumn(value: ""){ },
......
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