using Edu.Common.Enum;
using Edu.Model.Entity.Course;
using Edu.Model.Entity.Sell;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.Sell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;
namespace Edu.Repository.Sell
{
///
/// 销售提成期数明细仓储层
///
public class RB_Sell_StudyAbroad_DetailsRepository : BaseRepository
{
///
/// 获取列表
///
///
///
public List GetList(RB_Sell_StudyAbroad_Details_ViewModel demodel)
{
string where = $@" 1=1";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.PeriodId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.PeriodId)} ={demodel.PeriodId}";
}
if (demodel.UserId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.UserId)} ={demodel.UserId}";
}
if (!string.IsNullOrEmpty(demodel.UserIds))
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.UserId)} in({demodel.UserIds})";
}
if (demodel.SourceId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.SourceId)} ={demodel.SourceId}";
}
if (demodel.OrderId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.OrderId)} ={demodel.OrderId}";
}
if (!string.IsNullOrEmpty(demodel.OrderIds))
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.OrderId)} in({demodel.OrderIds})";
}
string sql = $@" select r.* from RB_Sell_StudyAbroad_Details r where {where} order by r.Id asc";
return Get(sql).ToList();
}
///
/// 获取分页列表
///
///
///
///
///
///
public List GetPageList(int pageIndex, int pageSize, out long count, RB_Sell_StudyAbroad_Details_ViewModel demodel)
{
string where = $@" 1=1";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.School_Id >= 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.School_Id)} ={demodel.School_Id}";
}
if (demodel.Depart_Id > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.Depart_Id)} ={demodel.Depart_Id}";
}
if (demodel.PeriodId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.PeriodId)} ={demodel.PeriodId}";
}
if (demodel.UserId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.UserId)} ={demodel.UserId}";
}
if (demodel.SourceId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.SourceId)} ={demodel.SourceId}";
}
if (demodel.OrderId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.OrderId)} ={demodel.OrderId}";
}
string sql = $@" select r.* from RB_Sell_StudyAbroad_Details r where {where} order by r.Id desc";
return GetPage(pageIndex, pageSize, out count, sql).ToList();
}
///
/// 获取用户提成列表
///
///
///
public List GetSellCommissionUserList(RB_Sell_StudyAbroad_Details_ViewModel demodel)
{
string where = $@" 1=1";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.School_Id >= 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.School_Id)} ={demodel.School_Id}";
}
if (demodel.PeriodId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.PeriodId)} ={demodel.PeriodId}";
}
if (demodel.UserId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.UserId)} ={demodel.UserId}";
}
if (demodel.SourceId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.SourceId)} ={demodel.SourceId}";
}
if (demodel.OrderId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.OrderId)} ={demodel.OrderId}";
}
string sql = $@" select r.UserId,r.Depart_Id,r.School_Id,sum(r.StudentCount) as StudentCount,sum(r.CommissionMoney) as CommissionMoney,sum(r.OtherMoney) as OtherMoney,sum(r.BackMoney) as BackMoney
from RB_Sell_StudyAbroad_Details r where {where} group by r.UserId,r.Depart_Id,r.School_Id";
return Get(sql).ToList();
}
///
/// 获取每期校区对应提成
///
///
///
///
public List GetSchoolCommission(int schoolId, string periodsIds)
{
string sql = $@"select PeriodId,SUM(CommissionMoney + OtherMoney - BackMoney) as CommissionMoney from RB_Sell_StudyAbroad_Details
WHERE School_Id ={schoolId} and PeriodId in ({periodsIds})
GROUP BY PeriodId ";
return Get(sql).ToList();
}
///
/// 累计提成金额
///
///
///
public decimal GetSellStudyAbroadStatistics(RB_Sell_StudyAbroad_Details_ViewModel demodel)
{
string where = $@" 1=1";
if (demodel.Group_Id > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.School_Id >= 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.School_Id)} ={demodel.School_Id}";
}
if (demodel.Depart_Id > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.Depart_Id)} ={demodel.Depart_Id}";
}
if (demodel.PeriodId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.PeriodId)} ={demodel.PeriodId}";
}
if (demodel.UserId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.UserId)} ={demodel.UserId}";
}
if (demodel.SourceId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.SourceId)} ={demodel.SourceId}";
}
if (demodel.OrderId > 0)
{
where += $@" and r.{nameof(RB_Sell_StudyAbroad_Details_ViewModel.OrderId)} ={demodel.OrderId}";
}
string sql = $@" select sum(r.CommissionMoney + r.OtherMoney - r.BackMoney) from RB_Sell_StudyAbroad_Details r where {where}";
var obj = ExecuteScalar(sql);
return obj == null ? 0 : Convert.ToDecimal(obj);
}
}
}