using Edu.AOP.CustomerAttribute; 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.Customer; using Edu.Model.ViewModel.Mall; using Edu.Model.ViewModel.User; using Edu.Repository.Customer; using Edu.Repository.Mall; using Edu.Repository.Reserve; using Edu.Repository.System; using Edu.Repository.User; using System; using System.Collections.Generic; using System.Linq; 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(); /// /// 获取学生列表 /// /// /// 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 accountList = new List(); if (aIds != null && aIds.Count > 0) { empIdList.AddRange(aIds); } 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.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 = goalList?.FirstOrDefault(qitem => qitem.Id == item.StuPurpose)?.Name ?? ""; item.StuNeedsName = needList?.FirstOrDefault(qitem => qitem.Id == item.StuNeeds)?.Name ?? ""; item.AdvisorList = advisorList?.Where(qitem => qitem.StuId == item.StuId)?.ToList() ?? new List(); } } 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 }; Common.Message.MessageHelper.SendMessage(modelWork); } } } 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 = learningGoalsRepository.GetLearningGoalsExtEntityRepository(extModel.StuPurpose)?.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; Common.Message.MessageHelper.SendMessage(modelWork); } //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.GetEmployeeInfo(userId); // var reModel = accountModule.GetEmployeeInfo(receiveId); // if (eModel == null || reModel == null) { return "转交人不存在"; } // if (reModel.IsLeave != 1) { 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 ""; //} #endregion /// /// 今日需联系线索(之前预约或者24小时内收到的新线索) /// /// /// /// /// public List GetTodayVisitModule(int CreateBy) { List result = new List(); var list = student_AppointmentRepository.GetStudentVisitListRepository(new RB_Student_Appointment_Extend() { QueryDate = Common.ConvertHelper.FormatDate(DateTime.Now), CreateBy = CreateBy }); if (list != null && list.Count > 0) { string createByIds = string.Join(",", list.Select(qitem => qitem.CreateBy)); List empList = new List(); if (!string.IsNullOrEmpty(createByIds)) { empList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel() { QIds = createByIds }); } foreach (var item in list) { var tempEmp = empList?.FirstOrDefault(qitem => qitem.Id == item.CreateBy); result.Add(new { item.Id, item.StuId, item.StuName, item.CreateBy, EmployeeName= tempEmp?.AccountName, CreateTime=Common.ConvertHelper.FormatTime(item.CreateTime), item.Feedback, }); } } return result; } } }