using Edu.AOP.CustomerAttribute; using Edu.Common; using Edu.Common.Enum; using Edu.Common.Enum.System; using Edu.Common.Enum.User; using Edu.Common.Plugin; using Edu.Model.CacheModel; using Edu.Model.ViewModel.Contract; using Edu.Model.ViewModel.Customer; using Edu.Model.ViewModel.Mall; using Edu.Model.ViewModel.Sell; using Edu.Model.ViewModel.User; using Edu.Repository.Contract; using Edu.Repository.Customer; using Edu.Repository.Mall; using Edu.Repository.Reserve; using Edu.Repository.Sell; using Edu.Repository.System; using Edu.Repository.User; using Senparc.CO2NET.Extensions; using Senparc.Weixin.Annotations; using Senparc.Weixin.MP.AdvancedAPIs; using System; using System.Collections.Generic; using System.Linq; using System.Web; using VT.FW.DB; namespace Edu.Module.User { /// /// 学生处理类 /// public class StudentModule { /// /// 学生仓储层对象 /// private readonly RB_StudentRepository studentRepository = new RB_StudentRepository(); /// /// 日志 /// private readonly RB_Student_LogRepository student_LogRepository = new RB_Student_LogRepository(); /// /// 地区仓储层对象 /// private readonly RB_DestinationRepository destinationRepository = new RB_DestinationRepository(); /// /// 同业 /// private readonly RB_CustomerRepository customerRepository = new RB_CustomerRepository(); /// /// 账号处理类 /// private readonly AccountModule accountModule = new AccountModule(); /// /// 小程序用户仓储层对象 add by:W 2021-09-15 /// private readonly RB_Member_UserRepository member_UserRepository = new RB_Member_UserRepository(); /// /// 学员订单关联表仓储层 /// private readonly RB_Student_OrderGuestRepository student_OrderGuestRepository = new RB_Student_OrderGuestRepository(); /// /// 学员跟进 /// private readonly RB_Student_FollowRepository followRepository = new RB_Student_FollowRepository(); /// /// 学员协助人员仓储层对象 /// private readonly RB_Student_AssistRepository student_AssistRepository = new RB_Student_AssistRepository(); /// /// 学员到访仓储层对象 /// private readonly RB_Student_VisitRepository student_VisitRepository = new RB_Student_VisitRepository(); /// /// 学员试听课仓储层对象 /// private readonly RB_Visitor_ReserveRepository visitor_ReserveRepository = new RB_Visitor_ReserveRepository(); /// /// 客户阶段仓储层对象 /// private readonly RB_StageRepository stageRepository = new RB_StageRepository(); /// /// 学员类型仓储层对象 /// private readonly RB_Student_TypeRepository student_TypeRepository = new RB_Student_TypeRepository(); /// /// 学习目的仓储层对象 /// private readonly RB_LearningGoalsRepository learningGoalsRepository = new RB_LearningGoalsRepository(); /// /// 渠道仓储层对象 /// private readonly RB_ChannelRepository channelRepository = new RB_ChannelRepository(); /// /// 客户需求仓储层对象 /// private readonly RB_NeedsRepository needsRepository = new RB_NeedsRepository(); /// /// 学员约访仓储层对象 /// private readonly RB_Student_AppointmentRepository student_AppointmentRepository = new RB_Student_AppointmentRepository(); /// /// 课程顾问跟进配置仓储层对象 /// private readonly RB_Student_AdvisorConfigRepository student_AdvisorConfigRepository = new RB_Student_AdvisorConfigRepository(); /// /// 课程顾问跟进仓储层对象 /// private readonly RB_Student_AdvisorRepository student_AdvisorRepository = new RB_Student_AdvisorRepository(); /// /// 订单客人仓储层 /// private readonly RB_Order_GuestRepository order_GuestRepository = new RB_Order_GuestRepository(); /// /// 订单仓储层对象 /// private readonly RB_OrderRepository orderRepository = new RB_OrderRepository(); /// /// 订单拆分仓储层对象 /// private readonly RB_Order_SplitDetailsRepository splitDetailsRepository = new RB_Order_SplitDetailsRepository(); /// /// 订单备注 /// private readonly RB_Order_RemarkRepository order_RemarkRepository = new RB_Order_RemarkRepository(); /// /// 合同 /// private readonly RB_Education_ContractRepository education_ContractRepository = new RB_Education_ContractRepository(); /// /// 业绩提成 /// private readonly RB_Sell_Achievements_EmpRepository sell_Achievements_EmpRepository = new RB_Sell_Achievements_EmpRepository(); /// /// 订单返佣仓储层对象 /// private readonly RB_Order_ReturnComissionRepository returnComissionRepository = new RB_Order_ReturnComissionRepository(); /// /// 学员配置仓储层 /// private readonly RB_Student_ConfigRepository student_ConfigRepository = new RB_Student_ConfigRepository(); /// /// 账号管理仓储层对象 /// private readonly RB_AccountRepository accountRepository = new RB_AccountRepository(); /// /// 获取学生列表 /// /// /// public List GetStudentListModule(RB_Student_ViewModel query) { return studentRepository.GetStudentListRepository(query); } /// /// 获取学生分页列表 /// /// /// /// /// /// public List GetStudentPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_ViewModel query) { var list = studentRepository.GetStudentPageListRepository(pageIndex, pageSize, out rowsCount, query); if (list != null && list.Count > 0) { //客户阶段列表 var stageList = stageRepository.GetStageListRepostory(new Model.Entity.System.RB_Stage() { Group_Id = list[0].Group_Id }); //学员类型列表 var stuTypeList = student_TypeRepository.GetStudentTypeListRepository(new RB_Student_Type_Extend()); string stuIds = string.Join(",", list.Select(qitem => qitem.StuId)); //学员跟进 var followList = followRepository.GetStudentFollowListRepository(new RB_Student_Follow_Extend() { QStuIds = stuIds }); //学员订单 var stuOrderList = student_OrderGuestRepository.GetStrOrderGuestListStaticRepository(new RB_Student_OrderGuest_ViewModel() { QStudentIds = stuIds }); //本周新增 var stuList = studentRepository.GetCustomerStuWeekListRepository(new RB_Student_ViewModel() { CustomerId = query.CustomerId }); //协助人员列表 var assistList = student_AssistRepository.GetStudentAssistListRepository(new RB_Student_Assist_Extend() { QStuIds = stuIds }); //内部介绍人 List empIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.InternalIntroduction).Select(qitem => qitem.StuSourceId))); List aIds = Common.ConvertHelper.StringToList(string.Join(",", assistList.Select(qitem => qitem.AssistId))); List createBys = Common.ConvertHelper.StringToList(string.Join(",", list.Select(qitem => qitem.CreateBy))); List accountList = new List(); if (aIds != null && aIds.Count > 0) { empIdList.AddRange(aIds); } if (createBys != null && createBys.Count > 0) { empIdList.AddRange(createBys); } if (empIdList != null && empIdList.Count > 0) { accountList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { QIds = string.Join(",", empIdList) }); } //学员到访统计 var visitList = student_VisitRepository.GetStudentVisitStatic_V2Repository(new RB_Student_Visit_Extend() { QStuIds = stuIds, StartDate = query.StartTime, EndDate = query.EndTime, }); //学员试听统计 var stuReserveList = visitor_ReserveRepository.GetStuReserveStaticsListRepository(new Model.ViewModel.Reserve.RB_Visitor_Reserve_Extend() { QVisitor_Ids = stuIds }); var provideList = list.Where(qitem => qitem.ProviceId > 0).Select(qitem => qitem.ProviceId).ToList(); var cityList = list.Where(qitem => qitem.CityId > 0).Select(qitem => qitem.CityId).ToList(); var areaList = list.Where(qitem => qitem.AreaId > 0).Select(qitem => qitem.AreaId).ToList(); List ids = new List(); if (provideList != null && provideList.Count > 0) { ids.AddRange(provideList); } if (cityList != null && cityList.Count > 0) { ids.AddRange(cityList); } if (areaList != null && areaList.Count > 0) { ids.AddRange(areaList); } string qIds = ""; if (ids != null && ids.Count > 0) { qIds = string.Join(",", ids); } else { qIds = "0"; } var destinationList = destinationRepository.GetDestinationListRepository(new Model.ViewModel.System.RB_Destination_ViewModel() { Ids = qIds }); //同业录入列表 List customerList = new List(); List customerIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.CustomerInput).Select(qitem => qitem.StuSourceId))); if (customerIdList != null && customerIdList.Count > 0) { customerList = customerRepository.GetCustomerListRepository(new RB_Customer_Extend() { CustomerIds = string.Join(",", customerIdList) }); } List transStudentList = new List(); //转介人列表 List transIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.TransIntroduction).Select(qitem => qitem.StuSourceId))); if (transIdList != null && transIdList.Count > 0) { transStudentList = studentRepository.GetStudentListRepository(new RB_Student_ViewModel() { StuIds = string.Join(",", transIdList) }); } //学习目的 string goalIds = string.Join(",", list?.Where(qitem => !string.IsNullOrWhiteSpace(qitem.StuPurpose))?.Select(qitem => qitem.StuPurpose)); var goalList = learningGoalsRepository.GetLearningGoalsListRepository(new Model.ViewModel.System.RB_LearningGoals_Extend() { QGoalIds = goalIds }); string channelIds = string.Join(",", list.Select(qitem => qitem.StuChannel)); var channelList = channelRepository.GetChannelListRepository(new Model.ViewModel.System.RB_Channel_Extend() { QChannelIds = channelIds }); var needIds = string.Join(",", list.Select(qitem => qitem.StuNeeds)); var needList = needsRepository.GetNeedsListRepository(new Model.ViewModel.System.RB_Needs_Extend() { QNeedsId = needIds }); //课程顾问跟进信息 List advisorList = student_AdvisorRepository.GetStudentAdvisorListRepository(new RB_Student_Advisor_Extend() { QStuIds = stuIds }); foreach (var item in list) { var tempOrderList = stuOrderList?.Where(qitem => qitem.Student_Id == item.StuId)?.ToList(); var tempFollow = followList?.Where(qitem => qitem.StuId == item.StuId)?.OrderByDescending(qitem => qitem.Id)?.FirstOrDefault(); item.followUpTime = Common.ConvertHelper.FormatTime(tempFollow?.CreateTime); item.WeekCount = stuList?.Count() ?? 0; item.TodayCount = stuList?.Where(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == Common.ConvertHelper.FormatDate(DateTime.Now))?.Count() ?? 0; item.OrderCount = tempOrderList?.Count() ?? 0; item.RenewOrderCount = tempOrderList?.Where(qitem => qitem.RenewState == 2)?.Count() ?? 0; item.StuGuestState = tempOrderList?.OrderByDescending(qitem => qitem.OrderId)?.LastOrDefault()?.StuGuestState ?? 0; item.AreaName = (destinationList?.FirstOrDefault(qitem => qitem.ID == item.ProviceId)?.Name ?? "") + "/" + (destinationList?.FirstOrDefault(qitem => qitem.ID == item.CityId)?.Name ?? "") + "/" + (destinationList?.FirstOrDefault(qitem => qitem.ID == item.AreaId)?.Name ?? ""); var tempAssistList = assistList?.Where(qitem => qitem.StuId == item.StuId)?.ToList(); foreach (var sItem in tempAssistList) { sItem.AssistName = accountList?.FirstOrDefault(qitem => qitem.Id == sItem.AssistId)?.AccountName ?? ""; } item.AssistList = tempAssistList; item.VisitCount = visitList?.FirstOrDefault(qitem => qitem.StuId == item.StuId)?.VisitCount ?? 0; item.TrialLessonCount = stuReserveList?.FirstOrDefault(qitem => qitem.Visitor_Id == item.StuId)?.TrialLessonCount ?? 0; if (item.CreateType == StuCreateTypeEnum.InternalIntroduction) { item.StuSourceIdName = accountList?.FirstOrDefault(qitem => qitem.Id == item.StuSourceId)?.AccountName ?? ""; } else if (item.CreateType == StuCreateTypeEnum.CustomerInput) { var tempCustomer = customerList?.FirstOrDefault(qitem => qitem.CustomerId == item.StuSourceId); item.StuSourceIdName = tempCustomer?.CustomerName ?? ""; if (tempCustomer != null) { if (tempCustomer.CustomerType == Common.Enum.Customer.CatetoryTypeEnum.Other) { item.EnterpriseName = tempCustomer?.EnterpriseName ?? ""; } else { item.EnterpriseName = tempCustomer?.CategoryName ?? ""; } } else { item.EnterpriseName = ""; } } else if (item.CreateType == StuCreateTypeEnum.TransIntroduction) { item.StuSourceIdName = transStudentList?.FirstOrDefault(qitem => qitem.StuId == item.StuSourceId)?.StuName ?? ""; } item.StuStageName = stageList?.FirstOrDefault(qitem => qitem.Id == item.StuStage)?.StageName ?? ""; item.StuTypeName = stuTypeList?.FirstOrDefault(qitem => qitem.Id == item.StuType)?.Name ?? ""; item.StuChannelName = channelList?.FirstOrDefault(qitem => qitem.Id == item.StuChannel)?.Name ?? ""; item.StuPurposeName = !string.IsNullOrWhiteSpace(item.StuPurpose) ? (string.Join(",", goalList?.Where(qitem => item.StuPurpose.Contains(qitem.Id.ToString()))?.Select(x => x.Name)) ?? "") : ""; item.StuNeedsName = needList?.FirstOrDefault(qitem => qitem.Id == item.StuNeeds)?.Name ?? ""; item.AdvisorList = advisorList?.Where(qitem => qitem.StuId == item.StuId)?.ToList() ?? new List(); item.CreateByName = accountList?.FirstOrDefault(qitem => qitem.Id == item.CreateBy)?.AccountName ?? ""; } } return list; } /// /// 检查学员是否存在资料库 /// /// /// 1-电话,2-QQ,3-微信号 /// public bool CheckStudentModule(RB_Student_ViewModel model, int Type) { List where = new List() { new WhereHelper(nameof(RB_Student_ViewModel.Group_Id),model.Group_Id), new WhereHelper(nameof(RB_Student_ViewModel.Status),(int)DateStateEnum.Normal), }; if (Type == 1) { where.Add(new WhereHelper(nameof(RB_Student_ViewModel.StuRealMobile), model.StuRealMobile)); } if (Type == 2) { where.Add(new WhereHelper(nameof(RB_Student_ViewModel.QQ), model.QQ)); } if (Type == 3) { where.Add(new WhereHelper(nameof(RB_Student_ViewModel.WeChatNo), model.WeChatNo)); } if (model.StuId > 0) { where.Add(new WhereHelper() { FiledName = nameof(RB_Student_ViewModel.StuId), FiledValue = model.StuId, OperatorEnum = OperatorEnum.NotEqual }); } var NewId = studentRepository.Exists("StuId", where); return NewId > 0; } /// /// 跟进电话号码获取学员信息 /// /// /// public RB_Student_ViewModel CheckExistsStuModule(RB_Student_ViewModel query) { var model = studentRepository.GetStuByTelRepository(query); return model; } /// /// 添加修改学生 /// /// /// 来至于同业 1是 /// public bool SetStudentModule(RB_Student_ViewModel model, int fromApp = 0) { bool IsInsert = false; if (model.StuId == 0) { IsInsert = true; } bool flag = studentRepository.SetStudentRepository(model); if (flag) { if (IsInsert && model.CustomerId > 0 && fromApp == 1) { var queryTargetWorkId = accountModule.GetWorkUserIdModule(model.CreateBy); if (!string.IsNullOrEmpty(queryTargetWorkId)) { var cmodel = customerRepository.GetEntity(model.CustomerId); var path = $"/sale/visitorRegistrat?StuId={model.StuId}"; path = System.Web.HttpUtility.UrlEncode(path); string markdownContent = $"`同业添加学生通知` \n>**概要信息** \n>同业名称:{cmodel.CustomerName}({cmodel.ContactNumber})\n>学生名称:{model.StuName}\n>学生电话:{model.StuTel}\n>请点击:[查看详情]({Common.Config.ErpUrl}/autologin?loginId={model.CreateBy}&target={path})"; Common.Message.PushMessageModel modelWork = new Common.Message.PushMessageModel() { CategoryId = Common.Enum.System.PushMessageCategoryEnum.B2BCustomerStu, Content = markdownContent, CoverImg = "", CreateByName = "系统", JumpUrl = "", WorkMsgType = "markdown", SendTime = DateTime.Now, SendType = 0, Title = "同业添加学生通知", Platform = 5, ReceiveId = queryTargetWorkId }; List pushList = new List() { modelWork }; new Common.Message.MessageHelper().SendMessage(pushList); } } } return flag; } /// /// 修改客户阶段 /// /// /// /// /// public bool SetStudentStageModule(int StuId, int StuStage, int Uid) { return studentRepository.SetStudentStageRepository(StuId, StuStage, Uid); } /// /// 获取协助人员列表 /// /// /// public List GetStuAssistListModule(int StuId) { var list = student_AssistRepository.GetStudentAssistListRepository(new RB_Student_Assist_Extend() { StuId = StuId }); return list; } /// /// 学员转交 /// /// 学员编号 /// 负责人 /// 操作人 /// public bool ForwardStudentModule(string StuIds, int CreateBy, int OperateId) { return studentRepository.ForwardStudentRepository(StuIds, CreateBy, OperateId); } /// /// 根据学生编号获取学生实体类 /// /// /// public RB_Student_ViewModel GetStudentModule(int StuId) { var extModel = studentRepository.GetEntity(StuId); if (extModel != null && extModel.StuId > 0) { var assistList = student_AssistRepository.GetStudentAssistListRepository(new RB_Student_Assist_Extend() { StuId = extModel.StuId }); //学员订单 var stuOrderList = student_OrderGuestRepository.GetStrOrderGuestListStaticRepository(new RB_Student_OrderGuest_ViewModel() { QStudentIds = extModel.StuId.ToString() }); extModel.OrderCount = stuOrderList?.Count() ?? 0; extModel.AssistList = assistList; extModel.StuStageName = stageRepository.GetEntity(extModel.StuStage)?.StageName ?? ""; extModel.StuTypeName = student_TypeRepository.GetEntity(extModel.StuType)?.Name ?? ""; extModel.StuPurposeName = !string.IsNullOrWhiteSpace(extModel.StuPurpose) ? (string.Join(",", learningGoalsRepository.GetLearningGoalsListRepository(new Model.ViewModel.System.RB_LearningGoals_Extend { QGoalIds = extModel.StuPurpose }).Select(x => x.Name)) ?? "") : ""; extModel.StuChannelName = channelRepository.GetChannelExtEntityRepository(extModel.StuChannel)?.Name ?? ""; extModel.StuNeedsName = needsRepository.GetNeedsExtEntityRepository(extModel.StuNeeds)?.Name ?? ""; //if (extModel.CustomerId > 0) //{ // extModel.CustomerName = customerRepository.GetEntity(extModel.CustomerId)?.CustomerName ?? ""; //} if (extModel.StuSourceId > 0) { if (extModel.CreateType == StuCreateTypeEnum.CustomerInput) { var customerName = customerRepository.GetEntity(extModel.StuSourceId)?.CustomerName ?? ""; extModel.StuSourceIdName = customerName; extModel.CustomerName = customerName; } else if (extModel.CreateType == StuCreateTypeEnum.EmployeeInput) { extModel.StuSourceIdName = accountModule.GetEmployeeInfo(extModel.StuSourceId)?.EmployeeName ?? ""; } else if (extModel.CreateType == StuCreateTypeEnum.InternalIntroduction) { extModel.StuSourceIdName = accountModule.GetEmployeeInfo(extModel.StuSourceId)?.EmployeeName ?? ""; } else if (extModel.CreateType == StuCreateTypeEnum.TransIntroduction) { extModel.StuSourceIdName = studentRepository.GetEntity(extModel.StuSourceId)?.StuName ?? ""; } } } return extModel; } /// /// 更新学生状态 /// /// /// /// public bool RemoveStudentModule(int StuId, int Status) { bool flag = false; var model = GetStudentModule(StuId); if (model != null && model.StuId > 0) { Dictionary fileds = new Dictionary() { {nameof(RB_Student_ViewModel.Status), Status}, }; flag = studentRepository.Update(fileds, new WhereHelper(nameof(RB_Student_ViewModel.StuId), StuId)); var accountList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { AccountId = model.StuId, Account = model.StuTel, AccountType = AccountTypeEnum.Student }); if (accountList != null && accountList.Count > 0) { flag = accountModule.SetAccountStatusModule(new RB_Account_ViewModel() { AccountType = AccountTypeEnum.Student, AccountId = model.StuId, UpdateTime = DateTime.Now, Status = (DateStateEnum)Status }); } } return flag; } /// /// 更新学员【禁用、启用】 /// /// /// 0-禁用,1-启用 /// public bool UpdateStudentIsDisableModule(object StuId, int IsDisable) { bool flag; Dictionary fileds = new Dictionary() { {nameof(RB_Student_ViewModel.IsDisable), IsDisable}, }; flag = studentRepository.Update(fileds, new WhereHelper(nameof(RB_Student_ViewModel.StuId), StuId)); return flag; } /// /// 创建学生账号 /// /// /// /// [TransactionCallHandler] public virtual bool CreateStudentAccountModule(int StuId, UserInfo user) { bool flag = false; var model = GetStudentModule(StuId); if (model != null && model.StuId > 0) { var accountList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { Account = model.StuTel, AccountType = AccountTypeEnum.Student }); if (accountList == null || (accountList != null && accountList.Count == 0)) { flag = accountModule.SetAccountModule(new RB_Account_ViewModel() { Account = model.StuTel, Password = Common.DES.Encrypt(Common.Config.DefaultPwd), AccountType = AccountTypeEnum.Student, AccountId = model.StuId, CreateBy = user.Id, UpdateBy = user.Id, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Group_Id = model.Group_Id, School_Id = model.School_Id, Status = model.Status }); } } return flag; } #region 学生兴趣爱好 /// /// 新增学生兴趣 /// /// /// public bool SetStudentInterest(RB_Student_ViewModel model) { if (model.StuId == 0) { return false; } else { Dictionary fileds = new Dictionary() { {nameof(RB_Student_ViewModel.Interest),model.Interest }, {nameof(RB_Student_ViewModel.JapanBaseInfo),(int)model.JapanBaseInfo }, {nameof(RB_Student_ViewModel.StuIcon),model.StuIcon.Trim() }, {nameof(RB_Student_ViewModel.StuSex),model.StuSex }, {nameof(RB_Student_ViewModel.UpdateTime),System.DateTime.Now } }; return studentRepository.Update(fileds, new WhereHelper(nameof(RB_Student_ViewModel.StuId), model.StuId)); } } #endregion /// /// 根据学生id获取同班账户,必须是未开班/学习中的 /// /// /// public List GetListByStudentId(int Student_Id, int Group_Id) { return studentRepository.GetListByStudentId(Student_Id, Group_Id); } /// /// 根据学生id获取学生的班级课程学校信息 /// /// /// public List GetStudentInfoModule(int Student_Id, int Group_Id) { var list = studentRepository.GetStudentInfoRepository(Student_Id, Group_Id); if (list.Where(x => x.ClassScrollType == 2).Any()) { //有滚动开班的 string GuestIds = string.Join(",", list.Where(x => x.ClassScrollType == 2).Select(x => x.GuestId)); var glist = studentRepository.GetStudentClassNumber(GuestIds, Group_Id); foreach (var item in list) { item.CompleteHours = glist.Where(x => x.GuestId == item.GuestId).FirstOrDefault()?.CompleteHours ?? item.CompleteHours; item.SuspendNum = Convert.ToInt32(item.TotalHours - item.CompleteHours); item.ClassStatus = item.CompleteHours == 0 ? 1 : item.CompleteHours < item.TotalHours ? 2 : 3; } } return list; } /// /// 获取约课课程上课次数 /// /// /// /// public RB_Student_ViewModel GetStudentClassNumber(int guestId, int groupId) { return studentRepository.GetStudentClassNumber(guestId.ToString(), groupId).FirstOrDefault(); } /// /// 推送消息 /// /// /// 1-手机,2-QQ,3-微信 public void PushMessageModule(RB_Student_ViewModel model, int type) { var assistList = GetStuAssistListModule(model.StuId); var customerModel = customerRepository.GetEntity(model.CustomerId); string searchContent = model.StuTel + "(学员电话)"; if (type == 2) { searchContent = model.QQ + "(学员电话)"; } if (type == 3) { searchContent = model.WeChatNo + "(学员微信)"; } string createByName = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { Id = model.CreateBy })?.FirstOrDefault()?.AccountName ?? ""; string markdownContent = $"`同业查重通知` \n>**概要信息** \n>同业名称:{customerModel?.CustomerName ?? ""}({customerModel?.ContactNumber ?? ""})\n>查询内容:{searchContent} \n>关联学员:{model.StuName}\n>"; markdownContent += $"关联同事:{createByName}\n> "; Common.Message.PushMessageModel modelWork = new Common.Message.PushMessageModel() { CategoryId = PushMessageCategoryEnum.B2BCustomerStu, Content = markdownContent, CoverImg = "", CreateByName = "系统", JumpUrl = "", WorkMsgType = "markdown", SendTime = DateTime.Now, SendType = 0, Title = "同业查重通知", Platform = 5, }; if (customerModel != null && customerModel.CreateBy > 0) { var queryTargetWorkId = accountModule.GetWorkUserIdModule(customerModel.CreateBy); modelWork.ReceiveId = queryTargetWorkId; List pushList = new List() { modelWork }; new Common.Message.MessageHelper().SendMessage(pushList); } //if (assistList != null && assistList.Count > 0) //{ // foreach (var item in assistList) // { // var queryTargetWorkId = accountModule.GetWorkUserIdModule(item.AssistId); // modelWork.ReceiveId = queryTargetWorkId; // Common.Message.MessageHelper.SendMessage(modelWork); // } //} } #region 小程序用户 /// /// 根据条件获取用户实体 /// /// /// public RB_Member_User_Extend GetMemberUserEntityModule(RB_Member_User_Extend query) { return member_UserRepository.GetMemberUserEntityRepository(query); } #endregion /// /// 今日新名单 /// /// public object GetStudentTodayStaticModule(int createBy) { DateTime startTime = DateTime.Now.AddMonths(-1); string startDate = Common.ConvertHelper.FormatDate(startTime); var today = Common.ConvertHelper.FormatDate(DateTime.Now); //今日新增名单 var addList = studentRepository.GetStudentStaticRepository(createBy.ToString(), startDate, today); int days = (DateTime.Now - startTime).Days; List dayList = new List(); //今日新增名单 int todayAdd = addList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == today)?.ClueCount ?? 0; //到访名单 var visitList = student_VisitRepository.GetStudentVisitStaticRepository(new RB_Student_Visit_Extend() { CreateBy = createBy, StartDate = startDate, EndDate = today }); //今日到访 int todayVisit = visitList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == today)?.VisitCount ?? 0; //预约列表 var appointmentList = student_AppointmentRepository.GetStudentVisitStaticRepository(new RB_Student_Appointment_Extend() { CreateBy = createBy, StartDate = startDate, EndDate = today, }); //今日预约 int appointmentCount = appointmentList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == today)?.AppointmentCount ?? 0; //新增同行列表 var customerList = customerRepository.GetCustomerStaticRepository(new RB_Customer_Extend() { CreateBy = createBy, StartDate = startDate, EndDate = today }); //今日新增同行 var customerCount = customerList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == today)?.CustomerCount ?? 0; //试听列表 var trialLessonList = visitor_ReserveRepository.GetVisitorReserveStaticRepository(new Model.ViewModel.Reserve.RB_Visitor_Reserve_Extend() { CreateBy = createBy, StartClassDate = startDate, EndClassDate = today }); //今日试听 var trialLessonCount = trialLessonList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == today)?.TrialLessonCount ?? 0; //未沟通人数 var notCommunicateCount = studentRepository.GetStudentListRepository(new RB_Student_ViewModel() { CreateBy = createBy, StuStage = 1 })?.Count(); for (int i = 1; i <= days; i++) { var newDate = startTime.AddDays(i); dayList.Add(new { x = Common.ConvertHelper.FormatMonthDay(newDate), y = addList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == Common.ConvertHelper.FormatDate(newDate))?.ClueCount ?? 0, AddCount = addList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == Common.ConvertHelper.FormatDate(newDate))?.ClueCount ?? 0, VisitCount = visitList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == Common.ConvertHelper.FormatDate(newDate))?.VisitCount ?? 0, appointmentCount = appointmentList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == Common.ConvertHelper.FormatDate(newDate))?.AppointmentCount ?? 0, customerCount = customerList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == Common.ConvertHelper.FormatDate(newDate))?.CustomerCount ?? 0, trialLessonCount = trialLessonList?.FirstOrDefault(qitem => Common.ConvertHelper.FormatDate(qitem.CreateTime) == Common.ConvertHelper.FormatDate(newDate))?.TrialLessonCount ?? 0, }); } object obj = new { dayList, todayAdd, todayVisit, appointmentCount, customerCount, trialLessonCount, notCommunicateCount }; return obj; } #region 小程序个人中心 /// /// 获取学生订单/留学/合同数量 /// /// /// /// public RB_Student_OrderGuest_ViewModel GetStuendOrderNum(int accountId, int group_Id) { return student_OrderGuestRepository.GetStuendOrderNum(accountId, group_Id); } /// /// 获取学生正在学习的课程 信息 /// /// /// /// public RB_Student_OrderGuest_ViewModel GetLearningCourseInfo(int accountId, int group_Id) { //获取正在学习的课程 var model = student_OrderGuestRepository.GetLearningCourseInfo(accountId, group_Id, 1); if (model == null) { model = student_OrderGuestRepository.GetLearningCourseInfo(accountId, group_Id, 2); } return model; } #endregion public void UpdateTel() { var list = studentRepository.GetStudentListRepository(new RB_Student_ViewModel()); foreach (var item in list) { Dictionary fileds = new Dictionary() { {nameof(RB_Student_ViewModel.StuTel),Common.Plugin.StringHelper.ReplaceMobile(item.StuTel) } }; studentRepository.Update(fileds, new WhereHelper(nameof(RB_Student_ViewModel.StuId), item.StuId)); } } /// /// 更新学员咨询信息 /// /// /// /// public string SetStudentConsultResults(RB_Student_ViewModel demodel, UserInfo userInfo) { var oldModel = studentRepository.GetEntity(demodel.StuId); if (oldModel == null) { return "不存在"; } string logContent = ""; if (oldModel.PlanPrice != demodel.PlanPrice) { logContent += $"规划课程及报价由【{oldModel.PlanPrice}】修改为【{demodel.PlanPrice}】;"; } if (oldModel.BaseCondition != demodel.BaseCondition) { logContent += $"基本情况由【{oldModel.BaseCondition}】修改为【{demodel.BaseCondition}】;"; } if (oldModel.DemandPoint != demodel.DemandPoint) { logContent += $"需求点由【{oldModel.DemandPoint}】修改为【{demodel.DemandPoint}】;"; } if (oldModel.ResistPoint != demodel.ResistPoint) { logContent += $"抗拒点由【{oldModel.ResistPoint}】修改为【{demodel.ResistPoint}】;"; } if (oldModel.ConsultingResults != demodel.ConsultingResults) { logContent += $"咨询结果由【{oldModel.ConsultingResults}】修改为【{demodel.ConsultingResults}】;"; } Dictionary keyValues = new Dictionary() { { nameof(RB_Student_ViewModel.ConsultDate), demodel.ConsultDate}, { nameof(RB_Student_ViewModel.PlanPrice), demodel.PlanPrice}, { nameof(RB_Student_ViewModel.BaseCondition), demodel.BaseCondition}, { nameof(RB_Student_ViewModel.DemandPoint), demodel.DemandPoint}, { nameof(RB_Student_ViewModel.ResistPoint), demodel.ResistPoint}, { nameof(RB_Student_ViewModel.ConsultingResults), demodel.ConsultingResults}, { nameof(RB_Student_ViewModel.UpdateBy), userInfo.Id}, { nameof(RB_Student_ViewModel.UpdateTime), DateTime.Now} }; List wheres = new List() { new WhereHelper() { FiledName = nameof(RB_Student_ViewModel.StuId), FiledValue = demodel.StuId, OperatorEnum =OperatorEnum.Equal } }; bool flag = studentRepository.Update(keyValues, wheres); if (flag) { student_LogRepository.Insert(new Model.Entity.Customer.RB_Student_Log() { LogId = 0, LogType = Common.Enum.Log.StudentLogTypeEnum.BasicInfo, CreateBy = userInfo.Id, CreateTime = DateTime.Now, CreateType = 1, Group_Id = userInfo.Group_Id, LogContent = logContent, LogTitle = "客户情况分析", StuId = demodel.StuId }); } return flag ? "" : "出错了,请联系管理员"; } #region 课程顾问跟进管理 /// /// 获取课程顾问跟进配置分页列表 /// /// /// /// /// /// public List GetStudentAdvisorConfigPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_AdvisorConfig_Extend query) { var list = student_AdvisorConfigRepository.GetStudentAdvisorConfigPageRepository(pageIndex, pageSize, out rowsCount, query); return list; } /// /// 获取课程顾问跟进配置列表 /// /// /// public List GetStudentAdvisorConfigListModule(RB_Student_AdvisorConfig_Extend query) { var list = student_AdvisorConfigRepository.GetStudentAdvisorConfigListRepository(query); return list; } /// /// 新增修改课程顾问配置 /// /// /// public bool SetStudentAdvisorConfigModule(RB_Student_AdvisorConfig_Extend model) { bool flag = false; if (model.Id > 0) { Dictionary fileds = new Dictionary() { {nameof(RB_Student_AdvisorConfig_Extend.Name),model.Name }, {nameof(RB_Student_AdvisorConfig_Extend.Num),model.Num }, {nameof(RB_Student_AdvisorConfig_Extend.UpdateBy),model.UpdateBy }, {nameof(RB_Student_AdvisorConfig_Extend.UpdateTime),model.UpdateTime }, {nameof(RB_Student_AdvisorConfig_Extend.Rate),model.Rate }, }; flag = student_AdvisorConfigRepository.Update(fileds, new WhereHelper(nameof(RB_Student_AdvisorConfig_Extend.Id), model.Id)); } else { var newId = student_AdvisorConfigRepository.Insert(model); model.Id = newId; flag = newId > 0; } return flag; } /// /// 根据编号获取课程顾问配置信息 /// /// /// public RB_Student_AdvisorConfig_Extend GetStudentAdvisorConfigModule(object Id) { var model = student_AdvisorConfigRepository.GetEntity(Id); return model; } /// /// 根据编号删除课程顾问配置信息 /// /// /// public bool RemoveStudentAdvisorConfigModule(object Id) { Dictionary fileds = new Dictionary() { {nameof(RB_Student_AdvisorConfig_Extend.Status), (int)DateStateEnum.Delete }, }; bool flag = student_AdvisorConfigRepository.Update(fileds, new WhereHelper(nameof(RB_Student_AdvisorConfig_Extend.Id), Id)); return flag; } /// /// 获取课程顾问跟进分页列表 /// /// /// /// /// /// public List GetStudentAdvisorPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_Advisor_Extend query) { var list = student_AdvisorRepository.GetStudentAdvisorPageRepository(pageIndex, pageSize, out rowsCount, query); return list; } /// /// 获取课程顾问跟进列表 /// /// /// public List GetStudentAdvisorListModule(RB_Student_Advisor_Extend query) { var list = student_AdvisorRepository.GetStudentAdvisorListRepository(query); return list; } /// /// 新增修改课程顾问跟进记录 /// /// /// public bool SetStudentAdvisorModule(RB_Student_Advisor_Extend model) { bool flag = false; var oldStudent = studentRepository.GetEntity(model.StuId); if (oldStudent != null) { Dictionary stuFileds = new Dictionary() { {nameof(RB_Student_ViewModel.AdvisorStatus),model.AdvisorStatus }, {nameof(RB_Student_ViewModel.AdvisorWinRate),model.AdvisorRate }, }; if (string.IsNullOrEmpty(oldStudent.AdvisorExpectDate)) { stuFileds.Add(nameof(RB_Student_ViewModel.AdvisorExpectDate), model.AdvisorExpectDate); } flag = studentRepository.Update(stuFileds, new WhereHelper(nameof(RB_Student_ViewModel.StuId), model.StuId)); } if (model.Id > 0) { Dictionary fileds = new Dictionary() { {nameof(RB_Student_Advisor_Extend.StuId),model.StuId }, {nameof(RB_Student_Advisor_Extend.AdvisorStatus),model.AdvisorStatus }, {nameof(RB_Student_Advisor_Extend.AdvisorDate),model.AdvisorDate }, {nameof(RB_Student_Advisor_Extend.AdvisorRemark),model.AdvisorRemark }, }; flag = student_AdvisorRepository.Update(fileds, new WhereHelper(nameof(RB_Student_Advisor_Extend.Id), model.Id)); } else { var newId = student_AdvisorRepository.Insert(model); model.Id = newId; flag = newId > 0; } return flag; } /// /// 根据编号获取课程顾问跟进记录 /// /// /// public RB_Student_Advisor_Extend GetStudentAdvisorModule(object Id) { var extModel = student_AdvisorRepository.GetEntity(Id); return extModel; } #endregion #region 离职转交 /// /// 学员转交 /// /// /// /// /// public string SetUserLeaveStudentCareOf(int userId, int receiveId, UserInfo userInfo) { var eModel = accountModule.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, Id = userId }).FirstOrDefault(); var reModel = accountModule.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, Id = receiveId }).FirstOrDefault(); if (eModel == null || reModel == null) { return "转交人不存在"; } if (reModel.LeaveStatus == Common.Enum.User.LeaveStatusEnum.Departure) { return "转交人非在职状态,无法交接"; } //获取学员负责人 / 服务人员 var list = studentRepository.GetUserStudentCareOf(userId, userInfo.Group_Id); if (list.Any()) { //查询所有的服务人员 var alist = student_AssistRepository.GetUserStudentAssistCareOf(userId, userInfo.Group_Id); var trans = studentRepository.DbTransaction; try { foreach (var item in list) { bool flag = true; if (item.CreateBy == userId) { Dictionary keyValues = new Dictionary() { { nameof(RB_Student_ViewModel.CreateBy), receiveId} }; List wheres = new List() { new WhereHelper(){ FiledName = nameof(RB_Student_ViewModel.StuId), FiledValue = item.StuId, OperatorEnum =OperatorEnum.Equal } }; flag = studentRepository.Update(keyValues, wheres, trans); } if (flag) { var clist = alist.Where(x => x.StuId == item.StuId).ToList(); foreach (var qitem in clist) { Dictionary keyValues = new Dictionary() { { nameof(RB_Student_Assist_Extend.AssistId),receiveId}, }; List wheres = new List() { new WhereHelper(){ FiledName = nameof(RB_Student_Assist_Extend.Id), FiledValue = qitem.Id, OperatorEnum =OperatorEnum.Equal } }; flag = student_AssistRepository.Update(keyValues, wheres, trans); } } if (flag) { //插入日志 student_LogRepository.Insert(new Model.Entity.Customer.RB_Student_Log() { CreateBy = userInfo.Id, CreateTime = DateTime.Now, CreateType = 1, Group_Id = userInfo.Group_Id, LogContent = "离职转交客人负责人与服务人员,由【" + eModel.EmployeeName + "(" + userId + ")" + "】转交给【" + reModel.EmployeeName + "(" + receiveId + ")" + "】", LogId = 0, LogTitle = "离职转交学员", LogType = Common.Enum.Log.StudentLogTypeEnum.BasicInfo, StuId = item.StuId }, trans); } } studentRepository.DBSession.Commit(); } catch (Exception ex) { LogHelper.Write(ex, "SetUserLeaveStudentCareOf"); studentRepository.DBSession.Rollback(); return "学员转交出错了,请联系管理员"; } } return ""; } /// /// 协助老师转交 /// /// /// /// /// public string SetUserLeaveTeacherCareOf(int userId, int receiveId, UserInfo userInfo) { var eModel = accountModule.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, Id = userId }).FirstOrDefault(); var reModel = accountModule.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, Id = receiveId }).FirstOrDefault(); if (eModel == null || reModel == null) { return "转交人不存在"; } if (reModel.LeaveStatus == Common.Enum.User.LeaveStatusEnum.Departure) { return "转交人非在职状态,无法交接"; } //查询所有的服务人员 var alist = student_AssistRepository.GetStudentAssistListRepository(new RB_Student_Assist_Extend { AssistId = userId }); if (alist.Any()) { var trans = student_AssistRepository.DbTransaction; try { foreach (var item in alist) { bool flag = true; Dictionary keyValues = new Dictionary() { { nameof(RB_Student_Assist_Extend.AssistId),receiveId}, }; List wheres = new List() { new WhereHelper(){ FiledName = nameof(RB_Student_Assist_Extend.Id), FiledValue = item.Id, OperatorEnum =OperatorEnum.Equal } }; flag = student_AssistRepository.Update(keyValues, wheres, trans); if (flag) { //插入日志 student_LogRepository.Insert(new Model.Entity.Customer.RB_Student_Log() { CreateBy = userInfo.Id, CreateTime = DateTime.Now, CreateType = 1, Group_Id = userInfo.Group_Id, LogContent = "转交协助人员,由【" + eModel.EmployeeName + "(" + userId + ")" + "】转交给【" + reModel.EmployeeName + "(" + receiveId + ")" + "】", LogId = 0, LogTitle = "转交协助人员", LogType = Common.Enum.Log.StudentLogTypeEnum.BasicInfo, StuId = item.StuId }, trans); } } student_AssistRepository.DBSession.Commit(); } catch (Exception ex) { LogHelper.Write(ex, "SetUserLeaveStudentCareOf"); student_AssistRepository.DBSession.Rollback(); return "转交协助人员出错了,请联系管理员"; } } return ""; } #endregion /// /// 今日需联系线索(之前预约或者24小时内收到的新线索) /// /// /// /// /// /// public List GetStudentAppointmentPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_Appointment_Extend query) { List result = new List(); var list = student_AppointmentRepository.GetStudentAppointmentPageRepository(pageIndex, pageSize, out rowsCount, query, IsQueryClue: true); if (list != null && list.Count > 0) { string stuIds = string.Join(",", list.Select(qitem => qitem.StuId)); var stuList = GetStudentPageListModule(1, 10000, out _, new RB_Student_ViewModel() { StuIds = stuIds }); List empIds = new List(); //跟进人员创建人 List createByIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Select(qitem => qitem.CreateBy))); if (createByIdList != null && createByIdList.Count > 0) { empIds.AddRange(createByIdList); } string createIds = string.Join(",", empIds); var empList = new List(); if (!string.IsNullOrEmpty(createIds)) { empList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { QIds = createIds }); } foreach (var aItem in list) { var tempEmp = empList?.FirstOrDefault(qitem => qitem.Id == aItem.CreateBy); var item = stuList?.FirstOrDefault(qitem => qitem.StuId == aItem.StuId); result.Add(new { aItem.Id, aItem.StuId, aItem.StuName, aItem.CreateBy, AppointmentTime = Common.ConvertHelper.FormatTime(aItem.AppointmentTime), EmployeeName = tempEmp?.AccountName, CreateTime = Common.ConvertHelper.FormatTime(aItem.CreateTime), aItem.Feedback, item.StuTel, item.StuIcon, item.StuSex, StuSexStr = item.StuSex == 0 ? "男" : "女", StuBirth = Common.ConvertHelper.FormatDate(item.StuBirth), item.StuStage, item.StuStageName, CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime), item.CreateByName, item.CreateType, CreateTypeStr = item.CreateType.ToName(), item.StuChannel, item.StuChannelName, item.PlatformName, item.CustomerId, item.CustomerName, AssistList = item.AssistList.Select(qitem => new { qitem.Id, qitem.StuId, qitem.AssistId, qitem.AssistName, qitem.AssistType, AssistTypeName = qitem.AssistType.ToName() }), item.JapanBaseInfo, JapanBaseInfoName = item.JapanBaseInfo.ToName(), item.StuProfession, item.StuEducation, StuEducationName = item.StuEducation.ToName(), item.StuPurpose, item.StuPurposeName, item.VisitCount, item.TrialLessonCount, item.StuSourceId, item.StuSourceIdName, item.QQ, item.WeChatNo, item.StuType, item.StuTypeName, item.StuNeeds, item.StuNeedsName, item.StuRealMobile, item.OrderCount, item.RenewOrderCount, item.EnterpriseName, item.AdvisorExpectDate, item.AdvisorStatus, item.AdvisorStatusName, item.AdvisorList, item.AdvisorWinRate, }); } } return result; } /// /// 今日需联系学员(之前预约的跟进学员或本周期内需要跟进的学员) /// /// /// /// /// /// 1-课程顾问,2-老师 /// public List GetTodayConnectPageModule(int pageIndex, int pageSize, out long rowsCount, int CreateBy, int UserType = 0, string KeyWords = "") { List result = new List(); var list = student_AppointmentRepository.GetTodayConnectPageRepository(pageIndex, pageSize, out rowsCount, Common.ConvertHelper.FormatDate(DateTime.Now), CreateBy, UserType: UserType, KeyWords: KeyWords); if (list != null && list.Count > 0) { string stuIds = string.Join(",", list.Select(qitem => qitem.StuId)); var stuList = GetStudentPageListModule(1, 10000, out _, new RB_Student_ViewModel() { StuIds = stuIds }); List empIds = new List(); //跟进人员创建人 List createByIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Select(qitem => qitem.CreateBy))); if (createByIdList != null && createByIdList.Count > 0) { empIds.AddRange(createByIdList); } string createIds = string.Join(",", empIds); var empList = new List(); if (!string.IsNullOrEmpty(createIds)) { empList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { QIds = createIds }); } foreach (var aItem in list) { var tempEmp = empList?.FirstOrDefault(qitem => qitem.Id == aItem.CreateBy); var item = stuList?.FirstOrDefault(qitem => qitem.StuId == aItem.StuId); result.Add(new { aItem.StuId, aItem.StuName, aItem.CreateBy, tempEmp?.AccountName, CreateTime = Common.ConvertHelper.FormatTime(aItem.CreateTime), item.StuTel, item.StuIcon, item.StuSex, StuSexStr = item.StuSex == 0 ? "男" : "女", StuBirth = Common.ConvertHelper.FormatDate(item.StuBirth), item.StuStage, item.StuStageName, CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime), item.CreateByName, item.CreateType, CreateTypeStr = item.CreateType.ToName(), item.StuChannel, item.StuChannelName, item.PlatformName, item.CustomerId, item.CustomerName, AssistList = item.AssistList.Select(qitem => new { qitem.Id, qitem.StuId, qitem.AssistId, qitem.AssistName, qitem.AssistType, AssistTypeName = qitem.AssistType.ToName() }), item.JapanBaseInfo, JapanBaseInfoName = item.JapanBaseInfo.ToName(), item.StuProfession, item.StuEducation, StuEducationName = item.StuEducation.ToName(), item.StuPurpose, item.StuPurposeName, item.VisitCount, item.TrialLessonCount, item.StuSourceId, item.StuSourceIdName, item.QQ, item.WeChatNo, item.StuType, item.StuTypeName, item.StuNeeds, item.StuNeedsName, item.StuRealMobile, item.OrderCount, item.RenewOrderCount, item.EnterpriseName, item.AdvisorExpectDate, item.AdvisorStatus, item.AdvisorStatusName, item.AdvisorList, item.AdvisorWinRate, }); } } return result; } /// /// 分配给我的线索 (分配给我,但是没有跟进的线索) /// /// /// /// /// /// public List GetMyClueModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_ViewModel query) { rowsCount = 0; List result = new List(); var list = GetStudentPageListModule(pageIndex, pageSize, out rowsCount, query); if (list != null && list.Count > 0) { foreach (var item in list) { result.Add(new { item.StuId, item.StuName, item.StuTel, item.StuIcon, item.StuSex, StuSexStr = item.StuSex == 0 ? "男" : "女", StuBirth = Common.ConvertHelper.FormatDate(item.StuBirth), item.StuStage, item.StuStageName, CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime), item.CreateBy, item.CreateByName, item.CreateType, CreateTypeStr = item.CreateType.ToName(), item.StuChannel, item.StuChannelName, item.PlatformName, item.CustomerId, item.CustomerName, AssistList = item.AssistList.Select(qitem => new { qitem.Id, qitem.StuId, qitem.AssistId, qitem.AssistName, qitem.AssistType, AssistTypeName = qitem.AssistType.ToName() }), item.JapanBaseInfo, JapanBaseInfoName = item.JapanBaseInfo.ToName(), item.StuProfession, item.StuEducation, StuEducationName = item.StuEducation.ToName(), item.StuPurpose, item.StuPurposeName, item.VisitCount, item.TrialLessonCount, item.StuSourceId, item.StuSourceIdName, item.QQ, item.WeChatNo, item.StuType, item.StuTypeName, item.StuNeeds, item.StuNeedsName, item.StuRealMobile, item.OrderCount, item.RenewOrderCount, item.EnterpriseName, item.AdvisorExpectDate, item.AdvisorStatus, item.AdvisorStatusName, item.AdvisorList, item.AdvisorWinRate, }); } } return result; } /// /// 分配给我的学员 (分配给我,但是没有跟进的学员) /// /// /// /// /// /// public List GetMyStudentModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_ViewModel query) { rowsCount = 0; List result = new List(); var list = GetStudentPageListModule(pageIndex, pageSize, out rowsCount, query); if (list != null && list.Count > 0) { foreach (var item in list) { result.Add(new { item.StuId, item.StuName, item.StuTel, item.StuIcon, item.StuSex, StuSexStr = item.StuSex == 0 ? "男" : "女", StuBirth = Common.ConvertHelper.FormatDate(item.StuBirth), item.StuStage, item.StuStageName, CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime), item.CreateBy, item.CreateByName, item.CreateType, CreateTypeStr = item.CreateType.ToName(), item.StuChannel, item.StuChannelName, item.PlatformName, item.CustomerId, item.CustomerName, AssistList = item.AssistList.Select(qitem => new { qitem.Id, qitem.StuId, qitem.AssistId, qitem.AssistName, qitem.AssistType, AssistTypeName = qitem.AssistType.ToName() }), item.JapanBaseInfo, JapanBaseInfoName = item.JapanBaseInfo.ToName(), item.StuProfession, item.StuEducation, StuEducationName = item.StuEducation.ToName(), item.StuPurpose, item.StuPurposeName, item.VisitCount, item.TrialLessonCount, item.StuSourceId, item.StuSourceIdName, item.QQ, item.WeChatNo, item.StuType, item.StuTypeName, item.StuNeeds, item.StuNeedsName, item.StuRealMobile, item.OrderCount, item.RenewOrderCount, item.EnterpriseName, item.AdvisorExpectDate, item.AdvisorStatus, item.AdvisorStatusName, item.AdvisorList, item.AdvisorWinRate, }); } } return result; } /// /// 获取未领取合同的订单 /// public List GetContractNotModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_OrderGuest_ViewModel query) { List result = new List(); rowsCount = 0; var list = student_OrderGuestRepository.GetStuOrderGuestPageRepository(pageIndex, pageSize, out rowsCount, query); if (list != null && list.Count > 0) { foreach (var item in list) { result.Add(new { StuId = item.Student_Id, item.OrderId, item.ClassName, item.CourseName, item.GuestName, item.GuestId, item.StuJoinType, StuJoinTypeName = item.StuJoinType.ToName(), item.StuGuestState, StuGuestStateName = item.StuGuestState.ToName(), item.OrderState, OrderStateName = item.OrderState.ToName(), item.TotalHours, item.CompleteHours, item.ClassStatus, item.RenewState, item.OrderType, OrderTypeName = item.OrderType.ToName(), }); } } return result; } /// /// 获取未完成的订单 /// /// public List GetOrderNotModule(int pageIndex, int pageSize, out long rowsCount, int UserId) { List result = new List(); var query = new RB_Order_ViewModel() { Q_OrderState = 1, Q_NotCollect = 1, CreateBy = UserId }; //获取订单列表 var orderList = orderRepository.GetOrderPageRepository(pageIndex, pageSize, out rowsCount, query); if (orderList.Any()) { string orderIds = string.Join(",", orderList.Select(x => x.OrderId)); //学员信息 List stuList = studentRepository.GetStudentListRepository(new RB_Student_ViewModel() { QOrderIds = orderIds }, isQueryCreateType: true); List idList = new List(); List sourceTargetList = new List(); var sourceOrderIdList = Common.ConvertHelper.StringToList(string.Join(",", orderList.Select(x => x.SourceOrderId))); if (sourceOrderIdList != null && sourceOrderIdList.Count > 0) { idList.AddRange(sourceOrderIdList); } var targetOrderIdList = Common.ConvertHelper.StringToList(string.Join(",", orderList.Select(x => x.TargetOrderId))); if (targetOrderIdList != null && targetOrderIdList.Count > 0) { idList.AddRange(targetOrderIdList); } List splitList = new List(); var firstOrderList = Common.ConvertHelper.StringToList(string.Join(",", orderList.Where(qitem => qitem.FirstOrderId > 0).Select(x => x.FirstOrderId))); if (firstOrderList != null && firstOrderList.Count > 0) { splitList = splitDetailsRepository.GetOrderSplitDetailsListRepository(new RB_Order_SplitDetails_ViewModel() { Q_OldOrderIds = string.Join(",", firstOrderList) }); } if (idList != null && idList.Count > 0) { string ids = string.Join(",", idList); sourceTargetList = orderRepository.GetOrderListRepository(new RB_Order_ViewModel { QOrderIds = ids }); } //获取备注列表 var remarkList = order_RemarkRepository.GetOrderRemarkListRepository(new RB_Order_Remark_ViewModel() { QOrderIds = orderIds }); //获取名单列表 var guestList = order_GuestRepository.GetOrderGuestListRepository(new RB_Order_Guest_ViewModel() { OrderIds = orderIds }); //获取合同列表 var clist = education_ContractRepository.GetList(new RB_Education_Contract_ViewModel() { OrderIds = orderIds, Status = -1 }).Where(x => x.Status != 4).ToList(); //获取新的业绩提成 var achList = sell_Achievements_EmpRepository.GetList(new RB_Sell_Achievements_Emp_ViewModel() { OrderIds = orderIds }); //获取订单的返佣 var rclist = returnComissionRepository.GetOrderReturnComissionListRepositpry(new RB_Order_ReturnComission_ViewModel() { QOrderIds = orderIds }); List empIds = new List(); // 创建人 List createByIdList = Common.ConvertHelper.StringToList(string.Join(",", orderList.Select(qitem => qitem.CreateBy))); if (createByIdList != null && createByIdList.Count > 0) { empIds.AddRange(createByIdList); } //业务员 List enterIdList = Common.ConvertHelper.StringToList(string.Join(",", orderList.Select(qitem => qitem.EnterID))); if (enterIdList != null && enterIdList.Count > 0) { empIds.AddRange(enterIdList); } //课程顾问 List courseConsultantIdList = Common.ConvertHelper.StringToList(string.Join(",", orderList.Select(qitem => qitem.CourseConsultantId))); if (courseConsultantIdList != null && courseConsultantIdList.Count > 0) { empIds.AddRange(courseConsultantIdList); } //协助老师 List HelpEnterIdList = Common.ConvertHelper.StringToList(string.Join(",", orderList.Select(qitem => qitem.HelpEnterId))); if (HelpEnterIdList != null && HelpEnterIdList.Count > 0) { empIds.AddRange(HelpEnterIdList); } string createIds = string.Join(",", empIds); var empList = new List(); if (!string.IsNullOrEmpty(createIds)) { empList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { QIds = createIds }); } foreach (var item in orderList) { if (item.SourceOrderId > 0) { item.SourceClassName = sourceTargetList?.Where(qitem => qitem.OrderId == item.SourceOrderId)?.FirstOrDefault()?.ClassName; } if (item.TargetOrderId > 0) { item.TargetClassName = sourceTargetList?.Where(qitem => qitem.OrderId == item.TargetOrderId)?.FirstOrDefault()?.ClassName; } item.SplitDetailsList = splitList.Where(qitem => qitem.OldOrderId == item.OrderId || qitem.OldOrderId == item.FirstOrderId)?.ToList() ?? new List(); item.SaleRemarkList = remarkList.Where(x => x.OrderId == item.OrderId && x.Type == 1).ToList(); item.TeacherRemarkList = remarkList.Where(x => x.OrderId == item.OrderId && x.Type == 2).ToList(); item.RectorRemarkList = remarkList.Where(x => x.OrderId == item.OrderId && x.Type == 3).ToList(); item.DirectorRemarkList = remarkList.Where(x => x.OrderId == item.OrderId && x.Type == 4).ToList(); item.GuestList = guestList.Where(x => x.OrderId == item.OrderId).ToList(); item.ContractList = clist.Where(x => x.OrderId == item.OrderId).ToList(); if (item.GuestList != null && item.GuestList.Count > 0) { foreach (var subItem in item.GuestList) { var contractModel = clist.Where(x => x.OrderId == item.OrderId && x.GuestId == subItem.Id)?.FirstOrDefault(); subItem.ContractId = contractModel?.Id ?? 0; subItem.ContractNo = contractModel?.ContractNo ?? ""; subItem.ContractStatus = contractModel?.Status ?? -1; string ContractStatusStr = ""; if (subItem.ContractStatus == 0) { ContractStatusStr = "草稿"; } else if (subItem.ContractStatus == 1) { ContractStatusStr = "提交审核"; } else if (subItem.ContractStatus == 2) { ContractStatusStr = "审核通过"; } else if (subItem.ContractStatus == 3) { ContractStatusStr = "驳回"; } else if (subItem.ContractStatus == 4) { ContractStatusStr = "取消"; } subItem.ContractStatusStr = ContractStatusStr; } } var achievementList = achList.Where(x => x.OrderId == item.OrderId).ToList(); if (achievementList.Any()) { item.CommissionMoney = achievementList.Sum(x => x.GiveOutMoney); item.YFCommission = achievementList.Sum(x => x.PushMoney); } var tempStu = stuList?.FirstOrDefault(qitem => qitem.OrderId == item.OrderId); item.CreateType = tempStu?.CreateType ?? StuCreateTypeEnum.EmployeeInput; item.StuSourceIdName = tempStu?.StuSourceIdName ?? ""; item.BrokerageMoney = rclist.Where(x => x.OrderId == item.OrderId).Sum(x => x.CommissionMoeny); result.Add(new { item.OrderId, item.ClassId, item.ClassNo, item.OrderType, item.SourceId, item.ClassSchoolId, item.ClassName, OpenTime = Common.ConvertHelper.FormatDate(item.OpenTime), item.JoinType, JoinTypeName = item.JoinType.ToName(), item.TargetJoinType, TargetJoinTypeName = item.TargetJoinType.ToName(), item.SourceOrderId, item.SourceClassName, item.TargetOrderId, item.TargetClassName, item.StartClassHours, item.CourseName, item.TradeWay, item.Class_Price, item.Unit_Price, item.GuestNum, item.PreferPrice, item.Income, item.Refund, item.DiscountMoney, item.PlatformTax, DueInMoney = item.PreferPrice - (item.Income - item.Refund + item.PlatformTax + item.DiscountMoney), item.OrderState, OrderStateName = item.OrderState.ToName(), item.OrderSource, OrderSourceName = item.OrderSource.ToName(), item.EnterID, EnterName = empList?.FirstOrDefault(qitem => qitem.Id == item.EnterID)?.AccountName ?? "", item.CreateBy, CreateByName = empList?.FirstOrDefault(qitem => qitem.Id == item.CreateBy)?.AccountName ?? "", item.CourseConsultantId, ConsultantName = empList?.FirstOrDefault(qitem => qitem.Id == item.CourseConsultantId)?.AccountName ?? "", IsAchievements = item.YFCommission > 0 ? 1 : 2, YFCommissionMoney = item.YFCommission > 0 ? item.YFCommission : GetOrderYFCommission(item), item.CommissionMoney, item.ExtraCommissionMoney, item.ExtraRewardMoney, item.ExtraDeductMoney, IsCommissionGive = item.YFCommission > 0 ? 1 : item.IsCommissionGive, item.CommissionBack, CreateTime = item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), SaleRemark = item?.SaleRemark ?? "", TeacherRemark = item?.TeacherRemark ?? "", RectorRemark = item?.RectorRemark ?? "", DirectorRemark = item?.DirectorRemark ?? "", item.OfferId, item.HelpEnterId, HelpEnterName = empList?.FirstOrDefault(qitem => qitem.Id == item.HelpEnterId)?.AccountName ?? "", item.GeneralOccupation, item.EduOccupation, item.IsLessPrice, item.LessPrice, item.OrderNature, OrderNatureName = item.OrderNature.ToName(), item.OldPreferPrice, item.EffectStatus, item.EffectStatusStr, EffectTime = Common.ConvertHelper.FormatDate(item.EffectTime), item.UpOrderId, item.VisitorReserveId, item.RenewOrderId, item.FirstOrderId, item.IsBackClass, item.CourseSubject, item.CourseSubjectName, item.CustomerId, item.CustomerName, item.CustomerTel, item.ClassScrollType, SplitDetailsList = item?.SplitDetailsList?.Select(qitem => new { qitem.S_ClassId, qitem.S_ClassName, qitem.S_JoinType, S_JoinTypeName = qitem.S_JoinType.ToName(), qitem.S_OrderId, qitem.T_ClassId, qitem.T_ClassName, qitem.T_JoinType, T_JoinTypeName = qitem.T_JoinType.ToName(), qitem.T_OrderId }), SaleRemarkList = item?.SaleRemarkList.Select(z => new { z.Id, z.Content, CreateBy = z.CreateByName, CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }), TeacherRemarkList = item?.TeacherRemarkList.Select(z => new { z.Id, z.Content, CreateBy = z.CreateByName, CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }), RectorRemarkList = item?.RectorRemarkList.Select(z => new { z.Id, z.Content, CreateBy = z.CreateByName, CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }), DirectorRemarkList = item?.DirectorRemarkList.Select(z => new { z.Id, z.Content, CreateBy = z.CreateByName, CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") }), GuestList = item?.GuestList.Select(z => new { z.Id, z.GuestName, z.GuestState, z.ContractId, z.ContractNo, z.ContractStatus, z.ContractStatusStr, z.GuestStateStr, z.GuestContractNo, z.ContractType, z.ContractUrl, z.ContractUrlList, }), ContractList = item?.ContractList.Select(z => new { z.Id, z.StudentName, z.ContractNo, z.GuestId, z.Status, }), item.CreateType, CreateTypeName = item.CreateType.ToName(), item.StuSourceIdName, item.BrokerageMoney }); } } return result; } /// /// 获取订单应发提成 /// /// /// private static decimal GetOrderYFCommission(RB_Order_ViewModel x) { if (x.CommissionType == x.CommissionTypeTH) { if (x.CommissionType == 1) { return x.CommissionRate + x.CommissionRateTH - x.LessPrice; } else { return Math.Round((x.PreferPrice - x.DiscountMoney + x.LessPrice) * (x.CommissionRate + x.CommissionRateTH) / 100, 2, MidpointRounding.AwayFromZero) - x.LessPrice; } } else { decimal commission1 = x.CommissionType == 1 ? x.CommissionRate : Math.Round((x.PreferPrice - x.DiscountMoney + x.LessPrice) * x.CommissionRate / 100, 2, MidpointRounding.AwayFromZero); decimal commission2 = x.CommissionTypeTH == 1 ? x.CommissionRateTH : Math.Round((x.PreferPrice - x.DiscountMoney + x.LessPrice) * x.CommissionRateTH / 100, 2, MidpointRounding.AwayFromZero); return commission1 + commission2 - x.LessPrice; } } /// /// 今日被跟进学员(被跟进的学员所有协助人可见) /// /// /// /// /// public List GetTodayFollowStudentModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_ViewModel query) { List result = new List(); var list = GetStudentPageListModule(pageIndex, pageSize, out rowsCount, query); if (list != null && list.Count > 0) { foreach (var item in list) { result.Add(new { item.StuId, item.StuName, item.StuTel, item.StuIcon, item.StuSex, StuSexStr = item.StuSex == 0 ? "男" : "女", StuBirth = Common.ConvertHelper.FormatDate(item.StuBirth), item.StuStage, item.StuStageName, CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime), item.CreateBy, item.CreateByName, item.CreateType, CreateTypeStr = item.CreateType.ToName(), item.StuChannel, item.StuChannelName, item.PlatformName, item.CustomerId, item.CustomerName, AssistList = item.AssistList.Select(qitem => new { qitem.Id, qitem.StuId, qitem.AssistId, qitem.AssistName, qitem.AssistType, AssistTypeName = qitem.AssistType.ToName() }), item.JapanBaseInfo, JapanBaseInfoName = item.JapanBaseInfo.ToName(), item.StuProfession, item.StuEducation, StuEducationName = item.StuEducation.ToName(), item.StuPurpose, item.StuPurposeName, item.VisitCount, item.TrialLessonCount, item.StuSourceId, item.StuSourceIdName, item.QQ, item.WeChatNo, item.StuType, item.StuTypeName, item.StuNeeds, item.StuNeedsName, item.StuRealMobile, item.OrderCount, item.RenewOrderCount, item.EnterpriseName, item.AdvisorExpectDate, item.AdvisorStatus, item.AdvisorStatusName, item.AdvisorList, item.AdvisorWinRate, }); } } return result; } /// /// 获取马上要毕业的学生 /// /// /// /// /// /// public List GetStraightwayGraduateStudentModule(int pageIndex, int pageSize, out long rowsCount, int UserId) { List result = new List(); var list = order_GuestRepository.GetAllStudentPageRepository(pageIndex, pageSize, out rowsCount, new Model.ViewModel.Sell.RB_Order_Guest_Extend() { IsImmediatelyGraduate = 1, CreateBy = UserId }); if (list != null && list.Count > 0) { foreach (var item in list) { result.Add(new { item.Id, item.GuestName, Mobile = item.StuRealMobile, item.ContractId, item.ContractNo, item.ClassId, item.ClassName, item.CourseId, item.CourseName, item.Teacher_Id, item.TeacherName, item.OrderId, OrderTime = Common.ConvertHelper.FormatTime(item.OrderTime), item.EnterID, item.EnterName, item.PreferPrice, item.Income, item.Refund, item.TotalHours, item.ValidClassHours, item.CompleteHours, item.SurplusHours, item.MakeUpHours, item.AbsenceNum, item.LeaveNum, item.EventlogNum, item.GuestState, item.GuestStateStr, GraduationTime = Common.ConvertHelper.FormatDate(item.GraduationTime), item.School_Id, item.JoinType, item.JoinTypeStr, item.Student_Id, item.CourseRate, CourseRateName = item.CourseRate.ToName().Replace("课程", ""), item.StuCreateBy, item.StuCreateByName, AssistList = item.AssistList.Select(qitem => new { qitem.Id, qitem.StuId, qitem.AssistId, qitem.AssistName, qitem.AssistType, AssistTypeName = qitem.AssistType.ToName() }), item.StuChannelId, item.StuChannelName, item.CreateType, CreateTypeName = item.CreateType.ToName(), item.StuSourceId, item.StuSourceIdName, item.EnterpriseName, item.CourseChapterNo, item.AppointNum }); } } return result; } /// /// 获取学生分页列表 /// /// /// /// /// /// public List GetStudentCoursePageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_ViewModel query) { var list = studentRepository.GetStudentCoursePageListRepository(pageIndex, pageSize, out rowsCount, query); return list; } /// /// 获取学生分页列表 /// /// /// /// /// /// public List GetStudentMonthPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Student_ViewModel query) { var list = studentRepository.GetStudentMonthPageListRepository(pageIndex, pageSize, out rowsCount, query); if (list != null && list.Count > 0) { //客户阶段列表 var stageList = stageRepository.GetStageListRepostory(new Model.Entity.System.RB_Stage() { Group_Id = list[0].Group_Id }); //学员类型列表 var stuTypeList = student_TypeRepository.GetStudentTypeListRepository(new RB_Student_Type_Extend()); string stuIds = string.Join(",", list.Select(qitem => qitem.StuId)); //学员跟进 var followList = followRepository.GetStudentFollowListRepository(new RB_Student_Follow_Extend() { QStuIds = stuIds }); //内部介绍人 List empIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.InternalIntroduction).Select(qitem => qitem.StuSourceId))); List createBys = Common.ConvertHelper.StringToList(string.Join(",", list.Select(qitem => qitem.CreateBy))); List accountList = new List(); if (createBys != null && createBys.Count > 0) { empIdList.AddRange(createBys); } if (empIdList != null && empIdList.Count > 0) { accountList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { QIds = string.Join(",", empIdList) }); } //同业录入列表 List customerList = new List(); List customerIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.CustomerInput).Select(qitem => qitem.StuSourceId))); if (customerIdList != null && customerIdList.Count > 0) { customerList = customerRepository.GetCustomerListRepository(new RB_Customer_Extend() { CustomerIds = string.Join(",", customerIdList) }); } List transStudentList = new List(); //转介人列表 List transIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.TransIntroduction).Select(qitem => qitem.StuSourceId))); if (transIdList != null && transIdList.Count > 0) { transStudentList = studentRepository.GetStudentListRepository(new RB_Student_ViewModel() { StuIds = string.Join(",", transIdList) }); } //学习目的 string goalIds = string.Join(",", list?.Where(qitem => !string.IsNullOrWhiteSpace(qitem.StuPurpose))?.Select(qitem => qitem.StuPurpose)); var goalList = learningGoalsRepository.GetLearningGoalsListRepository(new Model.ViewModel.System.RB_LearningGoals_Extend() { QGoalIds = goalIds }); string channelIds = string.Join(",", list.Select(qitem => qitem.StuChannel)); var channelList = channelRepository.GetChannelListRepository(new Model.ViewModel.System.RB_Channel_Extend() { QChannelIds = channelIds }); var needIds = string.Join(",", list.Select(qitem => qitem.StuNeeds)); var needList = needsRepository.GetNeedsListRepository(new Model.ViewModel.System.RB_Needs_Extend() { QNeedsId = needIds }); //课程顾问跟进信息 List advisorList = student_AdvisorRepository.GetStudentAdvisorListRepository(new RB_Student_Advisor_Extend() { QStuIds = stuIds }); foreach (var item in list) { var tempFollow = followList?.Where(qitem => qitem.StuId == item.StuId)?.OrderByDescending(qitem => qitem.Id)?.FirstOrDefault(); item.followUpTime = Common.ConvertHelper.FormatTime(tempFollow?.CreateTime); if (item.CreateType == StuCreateTypeEnum.InternalIntroduction) { item.StuSourceIdName = accountList?.FirstOrDefault(qitem => qitem.Id == item.StuSourceId)?.AccountName ?? ""; } else if (item.CreateType == StuCreateTypeEnum.CustomerInput) { var tempCustomer = customerList?.FirstOrDefault(qitem => qitem.CustomerId == item.StuSourceId); item.StuSourceIdName = tempCustomer?.CustomerName ?? ""; if (tempCustomer != null) { if (tempCustomer.CustomerType == Common.Enum.Customer.CatetoryTypeEnum.Other) { item.EnterpriseName = tempCustomer?.EnterpriseName ?? ""; } else { item.EnterpriseName = tempCustomer?.CategoryName ?? ""; } } else { item.EnterpriseName = ""; } } else if (item.CreateType == StuCreateTypeEnum.TransIntroduction) { item.StuSourceIdName = transStudentList?.FirstOrDefault(qitem => qitem.StuId == item.StuSourceId)?.StuName ?? ""; } item.StuStageName = stageList?.FirstOrDefault(qitem => qitem.Id == item.StuStage)?.StageName ?? ""; item.StuTypeName = stuTypeList?.FirstOrDefault(qitem => qitem.Id == item.StuType)?.Name ?? ""; item.StuChannelName = channelList?.FirstOrDefault(qitem => qitem.Id == item.StuChannel)?.Name ?? ""; item.StuPurposeName = !string.IsNullOrWhiteSpace(item.StuPurpose) ? (string.Join(",", goalList?.Where(qitem => item.StuPurpose.Contains(qitem.Id.ToString())).Select(x => x.Name)) ?? "") : ""; item.StuNeedsName = needList?.FirstOrDefault(qitem => qitem.Id == item.StuNeeds)?.Name ?? ""; item.AdvisorList = advisorList?.Where(qitem => qitem.StuId == item.StuId)?.ToList() ?? new List(); item.CreateByName = accountList?.FirstOrDefault(qitem => qitem.Id == item.CreateBy)?.AccountName ?? ""; } } return list; } /// /// 获取学生分页列表 /// /// /// /// /// /// public List GetStudentMonthListModule(RB_Student_ViewModel query) { var list = studentRepository.GetStudentMonthListRepository(query); if (list != null && list.Count > 0) { //客户阶段列表 var stageList = stageRepository.GetStageListRepostory(new Model.Entity.System.RB_Stage() { Group_Id = list[0].Group_Id }); //学员类型列表 var stuTypeList = student_TypeRepository.GetStudentTypeListRepository(new RB_Student_Type_Extend()); string stuIds = string.Join(",", list.Select(qitem => qitem.StuId)); //学员跟进 var followList = followRepository.GetStudentFollowListRepository(new RB_Student_Follow_Extend() { QStuIds = stuIds }); //内部介绍人 List empIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.InternalIntroduction).Select(qitem => qitem.StuSourceId))); List createBys = Common.ConvertHelper.StringToList(string.Join(",", list.Select(qitem => qitem.CreateBy))); List accountList = new List(); if (createBys != null && createBys.Count > 0) { empIdList.AddRange(createBys); } if (empIdList != null && empIdList.Count > 0) { accountList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { QIds = string.Join(",", empIdList) }); } //同业录入列表 List customerList = new List(); List customerIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.CustomerInput).Select(qitem => qitem.StuSourceId))); if (customerIdList != null && customerIdList.Count > 0) { customerList = customerRepository.GetCustomerListRepository(new RB_Customer_Extend() { CustomerIds = string.Join(",", customerIdList) }); } List transStudentList = new List(); //转介人列表 List transIdList = Common.ConvertHelper.StringToList(string.Join(",", list.Where(qitem => qitem.CreateType == StuCreateTypeEnum.TransIntroduction).Select(qitem => qitem.StuSourceId))); if (transIdList != null && transIdList.Count > 0) { transStudentList = studentRepository.GetStudentListRepository(new RB_Student_ViewModel() { StuIds = string.Join(",", transIdList) }); } //学习目的 string goalIds = string.Join(",", list?.Where(qitem => !string.IsNullOrWhiteSpace(qitem.StuPurpose))?.Select(qitem => qitem.StuPurpose)); var goalList = learningGoalsRepository.GetLearningGoalsListRepository(new Model.ViewModel.System.RB_LearningGoals_Extend() { QGoalIds = goalIds }); string channelIds = string.Join(",", list.Select(qitem => qitem.StuChannel)); var channelList = channelRepository.GetChannelListRepository(new Model.ViewModel.System.RB_Channel_Extend() { QChannelIds = channelIds }); var needIds = string.Join(",", list.Select(qitem => qitem.StuNeeds)); var needList = needsRepository.GetNeedsListRepository(new Model.ViewModel.System.RB_Needs_Extend() { QNeedsId = needIds }); //课程顾问跟进信息 List advisorList = student_AdvisorRepository.GetStudentAdvisorListRepository(new RB_Student_Advisor_Extend() { QStuIds = stuIds }); foreach (var item in list) { var tempFollow = followList?.Where(qitem => qitem.StuId == item.StuId)?.OrderByDescending(qitem => qitem.Id)?.FirstOrDefault(); item.followUpTime = Common.ConvertHelper.FormatTime(tempFollow?.CreateTime); if (item.CreateType == StuCreateTypeEnum.InternalIntroduction) { item.StuSourceIdName = accountList?.FirstOrDefault(qitem => qitem.Id == item.StuSourceId)?.AccountName ?? ""; } else if (item.CreateType == StuCreateTypeEnum.CustomerInput) { var tempCustomer = customerList?.FirstOrDefault(qitem => qitem.CustomerId == item.StuSourceId); item.StuSourceIdName = tempCustomer?.CustomerName ?? ""; if (tempCustomer != null) { if (tempCustomer.CustomerType == Common.Enum.Customer.CatetoryTypeEnum.Other) { item.EnterpriseName = tempCustomer?.EnterpriseName ?? ""; } else { item.EnterpriseName = tempCustomer?.CategoryName ?? ""; } } else { item.EnterpriseName = ""; } } else if (item.CreateType == StuCreateTypeEnum.TransIntroduction) { item.StuSourceIdName = transStudentList?.FirstOrDefault(qitem => qitem.StuId == item.StuSourceId)?.StuName ?? ""; } item.StuStageName = stageList?.FirstOrDefault(qitem => qitem.Id == item.StuStage)?.StageName ?? ""; item.StuTypeName = stuTypeList?.FirstOrDefault(qitem => qitem.Id == item.StuType)?.Name ?? ""; item.StuChannelName = channelList?.FirstOrDefault(qitem => qitem.Id == item.StuChannel)?.Name ?? ""; item.StuPurposeName = !string.IsNullOrWhiteSpace(item.StuPurpose) ? (string.Join(",", goalList?.Where(qitem => item.StuPurpose.Contains(qitem.Id.ToString()))?.Select(x => x.Name)) ?? "") : ""; item.StuNeedsName = needList?.FirstOrDefault(qitem => qitem.Id == item.StuNeeds)?.Name ?? ""; item.AdvisorList = advisorList?.Where(qitem => qitem.StuId == item.StuId)?.ToList() ?? new List(); item.CreateByName = accountList?.FirstOrDefault(qitem => qitem.Id == item.CreateBy)?.AccountName ?? ""; } } return list; } #region 学员配置表 /// /// 获取学员配置列表 /// /// /// public List GetStudentConfigModule(RB_Student_Config_Extend query) { var list = student_ConfigRepository.GetStudentConfigListRepository(query); return list; } /// /// 新增修改学员配置 /// /// /// public bool SetStudentConfigModule(RB_Student_Config_Extend model) { bool flag = false; if (model.Id > 0) { Dictionary fileds = new Dictionary() { {nameof(RB_Student_Config_Extend.ConfigName),model.ConfigName}, {nameof(RB_Student_Config_Extend.SortNum),model.SortNum}, {nameof(RB_Student_Config_Extend.UpdateBy),model.UpdateBy}, {nameof(RB_Student_Config_Extend.UpdateTime),DateTime.Now } }; flag = student_ConfigRepository.Update(fileds, new WhereHelper(nameof(RB_Student_Config_Extend.Id), model.Id)); } else { var newId = student_ConfigRepository.Insert(model); model.Id = newId; flag = newId > 0; } return flag; } /// /// 根据Id删除学员配置 /// /// /// /// public bool RemoveStudentConfigModule(int Id, UserInfo userInfo) { bool flag = false; Dictionary fileds = new Dictionary() { {nameof(RB_Student_Config_Extend.Status),(int)DateStateEnum.Delete }, {nameof(RB_Student_Config_Extend.UpdateBy),userInfo.Id}, {nameof(RB_Student_Config_Extend.UpdateTime),DateTime.Now } }; flag = student_ConfigRepository.Update(fileds, new WhereHelper(nameof(RB_Student_Config_Extend.Id), Id)); return flag; } /// /// 根据编号获取学员配置信息 /// /// /// public RB_Student_Config_Extend GetStudentConfigModule(int Id) { RB_Student_Config_Extend extModel = studentRepository.GetEntity(Id); return extModel; } #endregion } }