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_Achievements_EmpRepository : BaseRepository { /// /// 获取列表 /// /// /// public List GetList(RB_Sell_Achievements_Emp_ViewModel demodel) { string where = $@" 1=1"; if (demodel.Group_Id > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.Group_Id)} ={demodel.Group_Id}"; } if (demodel.OrderId > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.OrderId)} ={demodel.OrderId}"; } if (demodel.Type > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.Type)} ={demodel.Type}"; } if (demodel.EmpId > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.EmpId)} ={demodel.EmpId}"; } if (demodel.IsDept > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.IsDept)} ={demodel.IsDept}"; } if (demodel.PeriodsId > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.PeriodsId)} ={demodel.PeriodsId}"; } if (demodel.GiveOutState > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.GiveOutState)} ={demodel.GiveOutState}"; } if (demodel.IsSelectNor == 1) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.PeriodsId)} >0"; } if (!string.IsNullOrEmpty(demodel.OrderIds)) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.OrderId)} in({demodel.OrderIds})"; } string sql = $@" select r.* from RB_Sell_Achievements_Emp r where {where} order by r.Id desc"; return Get(sql).ToList(); } /// /// 获取分页列表 /// /// /// /// /// /// public List GetPageList(int pageIndex,int pageSize,out long count,RB_Sell_Achievements_Emp_ViewModel demodel) { string where = $@" 1=1"; if (demodel.Group_Id > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.Group_Id)} ={demodel.Group_Id}"; } if (demodel.OrderId > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.OrderId)} ={demodel.OrderId}"; } if (demodel.Type > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.Type)} ={demodel.Type}"; } if (demodel.EmpId > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.EmpId)} ={demodel.EmpId}"; } if (demodel.IsDept > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.IsDept)} ={demodel.IsDept}"; } if (demodel.PeriodsId > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.PeriodsId)} ={demodel.PeriodsId}"; } if (demodel.GiveOutState > 0) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.GiveOutState)} ={demodel.GiveOutState}"; } if (demodel.IsSelectNor == 1) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.PeriodsId)} >0"; } if (!string.IsNullOrEmpty(demodel.OrderIds)) { where += $@" and r.{nameof(RB_Sell_Achievements_Emp_ViewModel.OrderId)} in({demodel.OrderIds})"; } string sql = $@" select r.* from RB_Sell_Achievements_Emp r where {where} order by r.OrderId desc"; return GetPage(pageIndex, pageSize, out count, sql).ToList(); } /// /// 获取当月业绩(个人) /// /// /// /// /// public RB_Sell_Achievements_Emp_ViewModel GetMonthSaleMoney(int empId, int periodsId, int group_Id) { string sql = $@"SELECT MAX(SaleMoney) as SaleMoney,SUM(PushMoney) as PushMoney FROM rb_sell_achievements_emp WHERE Group_Id ={group_Id} and EmpId ={empId} and IsDept =2 and PeriodsId ={periodsId}"; return Get(sql).FirstOrDefault(); } /// /// 获取当月新收/续费业绩金额(个人) /// /// /// /// /// public List GetMonthNorOrderMoney(int empId, int periodsId, int group_Id) { string sql = $@" SELECT g.RenewState as Type,SUM(e.OrderSaleMoney) as OrderSaleMoney FROM rb_sell_achievements_emp e INNER JOIN rb_order_guest g on e.OrderId = g.OrderId WHERE e.Group_Id ={group_Id} and e.EmpId ={empId} and e.IsDept =2 and e.PeriodsId ={periodsId} GROUP BY g.RenewState"; return Get(sql).ToList(); } /// /// 获取用户累计已发提成(个人) /// /// /// /// public RB_Sell_Achievements_Emp_ViewModel GetEmpTotalCommission(int empId, int group_Id) { string sql = $@"SELECT SUM(PushMoney) as PushMoney,SUM(GiveOutMoney) as GiveOutMoney FROM rb_sell_achievements_emp WHERE Group_Id ={group_Id} and EmpId ={empId} and IsDept =2"; return Get(sql).FirstOrDefault(); } } }