Commit c078d1e6 authored by liudong1993's avatar liudong1993

和平返佣

parent bc33739d
...@@ -75,6 +75,10 @@ namespace Mall.Model.Entity.Product ...@@ -75,6 +75,10 @@ namespace Mall.Model.Entity.Product
set; set;
} }
/// <summary> /// <summary>
/// 类型 1标准返佣 2和平返佣
/// </summary>
public int? Type { get; set; }
/// <summary>
/// Remark /// Remark
/// </summary> /// </summary>
public string Remark public string Remark
......
...@@ -2379,6 +2379,7 @@ namespace Mall.Module.Product ...@@ -2379,6 +2379,7 @@ namespace Mall.Module.Product
{ {
item.CouponMoney = couponModel.CouponMoney; item.CouponMoney = couponModel.CouponMoney;
TotalMoney -= (item.CouponMoney ?? 0);//总价格需减去优惠券金额 TotalMoney -= (item.CouponMoney ?? 0);//总价格需减去优惠券金额
item.Final_Price -= (item.CouponMoney ?? 0);
} }
} }
} }
...@@ -2552,7 +2553,7 @@ namespace Mall.Module.Product ...@@ -2552,7 +2553,7 @@ namespace Mall.Module.Product
if ((basicModel?.InPurchasing ?? 2) == 1) if ((basicModel?.InPurchasing ?? 2) == 1)
{ {
disModel = distributor_InfoRepository.GetList(new RB_Distributor_Info_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, UserId = umodel.Id, AuditStatus = Common.Enum.User.DistributorAuditStatusEnum.Audited }).FirstOrDefault(); disModel = distributor_InfoRepository.GetList(new RB_Distributor_Info_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, UserId = umodel.Id, AuditStatus = Common.Enum.User.DistributorAuditStatusEnum.Audited }).FirstOrDefault();
if (disModel != null || (disModel.HPGradeId ?? 0) > 0) if (disModel != null && (disModel.HPGradeId ?? 0) > 0)
{ {
OneUserId = umodel.Id;//设置了分销内购 并且自己是分销商 并且设置了和平等级 , 那么就是自购返佣 OneUserId = umodel.Id;//设置了分销内购 并且自己是分销商 并且设置了和平等级 , 那么就是自购返佣
} }
...@@ -2560,7 +2561,7 @@ namespace Mall.Module.Product ...@@ -2560,7 +2561,7 @@ namespace Mall.Module.Product
if (OneUserId != umodel.Id) { if (OneUserId != umodel.Id) {
//求其上级 //求其上级
disModel = distributor_InfoRepository.GetList(new RB_Distributor_Info_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, UserId = OneUserId, AuditStatus = Common.Enum.User.DistributorAuditStatusEnum.Audited }).FirstOrDefault(); disModel = distributor_InfoRepository.GetList(new RB_Distributor_Info_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, UserId = OneUserId, AuditStatus = Common.Enum.User.DistributorAuditStatusEnum.Audited }).FirstOrDefault();
if (disModel != null || (disModel.HPGradeId ?? 0) > 0) if (disModel != null && (disModel.HPGradeId ?? 0) > 0)
{ {
OneUserId = umodel.SuperiorId ?? 0;//其上级可返佣 OneUserId = umodel.SuperiorId ?? 0;//其上级可返佣
} }
...@@ -2591,16 +2592,94 @@ namespace Mall.Module.Product ...@@ -2591,16 +2592,94 @@ namespace Mall.Module.Product
var gList = distributor_HPGradeRatioRepository.GetList(new RB_Distributor_HPGradeRatio_Extend() { CommissionId = hpcModel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }); var gList = distributor_HPGradeRatioRepository.GetList(new RB_Distributor_HPGradeRatio_Extend() { CommissionId = hpcModel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
var ratioModel = gList.Where(x => x.GradeId == disModel.HPGradeId).FirstOrDefault(); var ratioModel = gList.Where(x => x.GradeId == disModel.HPGradeId).FirstOrDefault();
decimal OneCommission = 0;
if (ratioModel != null)
{
decimal MPrice = (item.CostMoney ?? 0) / (1 - ((ratioModel.CommissionRatio ?? 0) / 100)); decimal MPrice = (item.CostMoney ?? 0) / (1 - ((ratioModel.CommissionRatio ?? 0) / 100));
OneCommission = (item.Final_Price ?? 0) - MPrice > 0 ? (item.Final_Price ?? 0) - MPrice : 0;
}
if (hpcModel.DecimalType == 1)
{
OneCommission = Math.Ceiling(OneCommission);
}
else if (hpcModel.DecimalType == 2)
{
OneCommission = Math.Ceiling(OneCommission * 100) / 100;
}
//插入返佣
goods_OrderCommissionRepository.Insert(new RB_Goods_OrderCommission()
{
Id = 0,
Commission = OneCommission,
CommissionState = 1,
CreateDate = DateTime.Now,
Grade = disModel.GradeId,
IsGoodsDistribution = 2,
MallBaseId = demodel.MallBaseId,
OrderDetailId = item.Id,
OrderId = OrderId,
Remark = "和平返佣",
TenantId = demodel.TenantId,
UpdateDate = DateTime.Now,
UserId = OneUserId,
Type = 2
}, trans);
//向上找出所有可以分销的
int ParentId = 0;
if (OneUserId == umodel.Id)
{
ParentId = umodel.SuperiorId ?? 0;
}
else {
ParentId = member_UserRepository.GetEntity(umodel.SuperiorId ?? 0)?.SuperiorId ?? 0;
}
decimal ParentCommission = OneCommission;
while (ParentId > 0) {
var disModel1 = distributor_InfoRepository.GetList(new RB_Distributor_Info_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, UserId = ParentId, AuditStatus = Common.Enum.User.DistributorAuditStatusEnum.Audited }).FirstOrDefault();
if (disModel1 != null && (disModel1.HPGradeId ?? 0) > 0)
{
//其上级可进行返佣
var ratioModel1 = gList.Where(x => x.GradeId == disModel1.HPGradeId).FirstOrDefault();
decimal OneCommission1 = 0;
if (ratioModel1 != null)
{
decimal MPrice1 = (item.CostMoney ?? 0) / (1 - ((ratioModel1.CommissionRatio ?? 0) / 100));
OneCommission1 = (item.Final_Price ?? 0) - MPrice1 > 0 ? (item.Final_Price ?? 0) - MPrice1 : 0;
}
if (hpcModel.DecimalType == 1) if (hpcModel.DecimalType == 1)
{ {
MPrice = Math.Ceiling(MPrice); OneCommission1 = Math.Ceiling(OneCommission1);
} }
else if (hpcModel.DecimalType == 2) else if (hpcModel.DecimalType == 2)
{ {
MPrice = Math.Ceiling(MPrice * 100) / 100; OneCommission1 = Math.Ceiling(OneCommission1 * 100) / 100;
}
//减去下级已提佣金
OneCommission1 -= ParentCommission;
ParentCommission += OneCommission1;//累计下级已提佣金
//插入返佣
goods_OrderCommissionRepository.Insert(new RB_Goods_OrderCommission()
{
Id = 0,
Commission = OneCommission1,
CommissionState = 1,
CreateDate = DateTime.Now,
Grade = disModel1.GradeId,
IsGoodsDistribution = 2,
MallBaseId = demodel.MallBaseId,
OrderDetailId = item.Id,
OrderId = OrderId,
Remark = "和平返佣",
TenantId = demodel.TenantId,
UpdateDate = DateTime.Now,
UserId = ParentId,
Type = 2
}, trans);
} }
//model.MaxShare = MaxSellMoney - MPrice > 0 ? MaxSellMoney - MPrice : 0; ParentId = member_UserRepository.GetEntity(ParentId)?.SuperiorId ?? 0;
}
} }
} }
} }
...@@ -2756,7 +2835,8 @@ namespace Mall.Module.Product ...@@ -2756,7 +2835,8 @@ namespace Mall.Module.Product
Remark = "", Remark = "",
TenantId = demodel.TenantId, TenantId = demodel.TenantId,
UpdateDate = DateTime.Now, UpdateDate = DateTime.Now,
UserId = OneUserId UserId = OneUserId,
Type = 1
}; };
gocList.Add(gocModel); gocList.Add(gocModel);
break; break;
...@@ -2822,7 +2902,8 @@ namespace Mall.Module.Product ...@@ -2822,7 +2902,8 @@ namespace Mall.Module.Product
Remark = "", Remark = "",
TenantId = demodel.TenantId, TenantId = demodel.TenantId,
UpdateDate = DateTime.Now, UpdateDate = DateTime.Now,
UserId = TwoUserId UserId = TwoUserId,
Type = 1
}; };
gocList.Add(gocModel); gocList.Add(gocModel);
} }
...@@ -2902,7 +2983,8 @@ namespace Mall.Module.Product ...@@ -2902,7 +2983,8 @@ namespace Mall.Module.Product
Remark = "", Remark = "",
TenantId = demodel.TenantId, TenantId = demodel.TenantId,
UpdateDate = DateTime.Now, UpdateDate = DateTime.Now,
UserId = ThreeUserId UserId = ThreeUserId,
Type = 1
}; };
gocList.Add(gocModel); gocList.Add(gocModel);
} }
......
...@@ -791,15 +791,15 @@ namespace Mall.Module.Product ...@@ -791,15 +791,15 @@ namespace Mall.Module.Product
var ratioModel = gList.Where(x => x.GradeId == disModel.HPGradeId).FirstOrDefault(); var ratioModel = gList.Where(x => x.GradeId == disModel.HPGradeId).FirstOrDefault();
decimal MPrice = (model.CostPrice ?? 0) / (1 - ((ratioModel.CommissionRatio ?? 0) / 100)); decimal MPrice = (model.CostPrice ?? 0) / (1 - ((ratioModel.CommissionRatio ?? 0) / 100));
model.MaxShare = MaxSellMoney - MPrice > 0 ? MaxSellMoney - MPrice : 0;
if (hpcModel.DecimalType == 1) if (hpcModel.DecimalType == 1)
{ {
MPrice = Math.Ceiling(MPrice); model.MaxShare = Math.Ceiling(model.MaxShare);
} }
else if (hpcModel.DecimalType == 2) else if (hpcModel.DecimalType == 2)
{ {
MPrice = Math.Ceiling(MPrice * 100) / 100; model.MaxShare = Math.Ceiling(model.MaxShare * 100) / 100;
} }
model.MaxShare = MaxSellMoney - MPrice > 0 ? MaxSellMoney - MPrice : 0;
} }
} }
} }
...@@ -1156,15 +1156,15 @@ namespace Mall.Module.Product ...@@ -1156,15 +1156,15 @@ namespace Mall.Module.Product
var ratioModel = gList.Where(x => x.GradeId == disModel.HPGradeId).FirstOrDefault(); var ratioModel = gList.Where(x => x.GradeId == disModel.HPGradeId).FirstOrDefault();
decimal MPrice = (model.CostPrice ?? 0) / (1 - ((ratioModel.CommissionRatio ?? 0) / 100)); decimal MPrice = (model.CostPrice ?? 0) / (1 - ((ratioModel.CommissionRatio ?? 0) / 100));
model.MaxShare = MaxSellMoney - MPrice > 0 ? MaxSellMoney - MPrice : 0;
if (hpcModel.DecimalType == 1) if (hpcModel.DecimalType == 1)
{ {
MPrice = Math.Ceiling(MPrice); model.MaxShare = Math.Ceiling(model.MaxShare);
} }
else if (hpcModel.DecimalType == 2) else if (hpcModel.DecimalType == 2)
{ {
MPrice = Math.Ceiling(MPrice * 100) / 100; model.MaxShare = Math.Ceiling(model.MaxShare * 100) / 100;
} }
model.MaxShare = MaxSellMoney - MPrice > 0 ? MaxSellMoney - MPrice : 0;
} }
} }
} }
......
...@@ -1140,9 +1140,9 @@ namespace Mall.Module.User ...@@ -1140,9 +1140,9 @@ namespace Mall.Module.User
//查询和平分销等级 //查询和平分销等级
string hpgradeIds = string.Join(",", list.Where(x => x.HPGradeId > 0).Select(x => x.HPGradeId ?? 0).Distinct()); string hpgradeIds = string.Join(",", list.Where(x => x.HPGradeId > 0).Select(x => x.HPGradeId ?? 0).Distinct());
List<RB_Distributor_HPGradeInfo_Extend> HPGradeList = new List<RB_Distributor_HPGradeInfo_Extend>(); List<RB_Distributor_HPGradeInfo_Extend> HPGradeList = new List<RB_Distributor_HPGradeInfo_Extend>();
if (!string.IsNullOrEmpty(gradeIds)) if (!string.IsNullOrEmpty(hpgradeIds))
{ {
HPGradeList = distributor_HPGradeInfoRepository.GetList(new RB_Distributor_HPGradeInfo_Extend() { GradeIds = gradeIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }); HPGradeList = distributor_HPGradeInfoRepository.GetList(new RB_Distributor_HPGradeInfo_Extend() { GradeIds = hpgradeIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
} }
//查询推荐人列表 //查询推荐人列表
string tjrIds = string.Join(",", list.Where(x => x.SuperiorId > 0).Select(x => x.SuperiorId ?? 0).Distinct()); string tjrIds = string.Join(",", list.Where(x => x.SuperiorId > 0).Select(x => x.SuperiorId ?? 0).Distinct());
...@@ -1169,11 +1169,12 @@ namespace Mall.Module.User ...@@ -1169,11 +1169,12 @@ namespace Mall.Module.User
{ {
item.GradeName = GradeList.Where(x => x.Id == item.GradeId).FirstOrDefault()?.Name ?? ""; item.GradeName = GradeList.Where(x => x.Id == item.GradeId).FirstOrDefault()?.Name ?? "";
} }
if (item.HPGradeId == 0) if ((item.HPGradeId ?? 0) == 0)
{ {
item.HPGradeName = "默认等级"; item.HPGradeName = "默认等级";
} }
else if (item.HPGradeId > 0) { else if (item.HPGradeId > 0)
{
item.HPGradeName = HPGradeList.Where(x => x.Id == item.HPGradeId).FirstOrDefault()?.GradeName ?? ""; item.HPGradeName = HPGradeList.Where(x => x.Id == item.HPGradeId).FirstOrDefault()?.GradeName ?? "";
} }
...@@ -3118,8 +3119,9 @@ namespace Mall.Module.User ...@@ -3118,8 +3119,9 @@ namespace Mall.Module.User
var rInsertList = demodel.RatioList.Where(x => !rlist.Select(z => z.GradeId).Contains(x.GradeId)).ToList(); var rInsertList = demodel.RatioList.Where(x => !rlist.Select(z => z.GradeId).Contains(x.GradeId)).ToList();
foreach (var item in rUpdateList) { foreach (var item in rUpdateList) {
var rmodel = demodel.RatioList.Where(x => x.GradeId == item.GradeId).FirstOrDefault();
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() { Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_Distributor_HPGradeRatio.CommissionRatio),item.CommissionRatio} { nameof(RB_Distributor_HPGradeRatio.CommissionRatio),rmodel?.CommissionRatio??0}
}; };
List<WhereHelper> wheres1 = new List<WhereHelper>() { List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){ new WhereHelper(){
...@@ -3324,6 +3326,7 @@ namespace Mall.Module.User ...@@ -3324,6 +3326,7 @@ namespace Mall.Module.User
/// <returns></returns> /// <returns></returns>
public object GetHpUserDistributorInfo(int userId, int tenantId, int mallBaseId) public object GetHpUserDistributorInfo(int userId, int tenantId, int mallBaseId)
{ {
var umodel = member_UserRepository.GetEntity(userId);
var model = distributor_InfoRepository.GetList(new RB_Distributor_Info_Extend() { UserId = userId, TenantId = tenantId, MallBaseId = mallBaseId }).FirstOrDefault(); var model = distributor_InfoRepository.GetList(new RB_Distributor_Info_Extend() { UserId = userId, TenantId = tenantId, MallBaseId = mallBaseId }).FirstOrDefault();
if (model == null) { if (model == null) {
return new return new
...@@ -3347,7 +3350,6 @@ namespace Mall.Module.User ...@@ -3347,7 +3350,6 @@ namespace Mall.Module.User
}; };
} }
var gmodel = distributor_HPGradeInfoRepository.GetEntity(model.HPGradeId); var gmodel = distributor_HPGradeInfoRepository.GetEntity(model.HPGradeId);
var umodel = member_UserRepository.GetEntity(userId);
return new return new
{ {
Status = 1, Status = 1,
......
...@@ -77,7 +77,7 @@ namespace Mall.Repository.User ...@@ -77,7 +77,7 @@ namespace Mall.Repository.User
where += $@" and {nameof(RB_Distributor_HPGradeInfo.GradeName)} like '%{dmodel.GradeName}%'"; where += $@" and {nameof(RB_Distributor_HPGradeInfo.GradeName)} like '%{dmodel.GradeName}%'";
} }
string sql = $@"select * from RB_Distributor_HPGradeInfo where {where} order by Id desc"; string sql = $@"select * from RB_Distributor_HPGradeInfo where {where} order by Grade asc";
return Get<RB_Distributor_HPGradeInfo_Extend>(sql).ToList(); return Get<RB_Distributor_HPGradeInfo_Extend>(sql).ToList();
} }
} }
......
...@@ -55,7 +55,7 @@ namespace Mall.Repository.User ...@@ -55,7 +55,7 @@ namespace Mall.Repository.User
where += $@" and di.{nameof(RB_Distributor_Info.Mobile)} like '%{dmodel.Mobile}%'"; where += $@" and di.{nameof(RB_Distributor_Info.Mobile)} like '%{dmodel.Mobile}%'";
} }
string sql = $@"select di.*,u.Name as NickName,u.Photo,u.Source from RB_Distributor_Info di string sql = $@"select di.*,u.Name as NickName,u.SuperiorId,u.Photo,u.Source from RB_Distributor_Info di
inner join rb_member_user u on di.UserId=u.Id inner join rb_member_user u on di.UserId=u.Id
where {where} order by di.CreateDate desc"; where {where} order by di.CreateDate desc";
return GetPage<RB_Distributor_Info_Extend>(pageIndex, pageSize, out rowCount, sql).ToList(); return GetPage<RB_Distributor_Info_Extend>(pageIndex, pageSize, out rowCount, sql).ToList();
......
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