using Edu.AOP.CustomerAttribute;
using Edu.Cache.User;
using Edu.Common;
using Edu.Common.API;
using Edu.Common.Enum;
using Edu.Common.Enum.Course;
using Edu.Common.Enum.Sale;
using Edu.Common.Plugin;
using Edu.Model.CacheModel;
using Edu.Model.Entity.Course;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.Log;
using Edu.Model.ViewModel.Reserve;
using Edu.Model.ViewModel.StudyAbroad;
using Edu.Model.ViewModel.User;
using Edu.Repository.Course;
using Edu.Repository.Finance;
using Edu.Repository.Log;
using Edu.Repository.Reserve;
using Edu.Repository.StudyAbroad;
using Edu.Repository.User;
using System;
using System.Collections.Generic;
using System.Linq;
using VT.FW.DB;

namespace Edu.Module.Course
{
    /// <summary>
    /// 订单处理类
    /// </summary>
    public partial class OrderModule
    {
        /// <summary>
        /// 订单
        /// </summary>
        private readonly RB_OrderRepository orderRepository = new RB_OrderRepository();

        /// <summary>
        /// 订单备注
        /// </summary>
        private readonly RB_Order_RemarkRepository order_RemarkRepository = new RB_Order_RemarkRepository();

        /// <summary>
        /// 客人
        /// </summary>
        private readonly RB_Order_GuestRepository order_GuestRepository = new RB_Order_GuestRepository();

        /// <summary>
        /// 用户日志
        /// </summary>
        private readonly RB_User_ChangeLogRepository changeLogRepository = new RB_User_ChangeLogRepository();

        /// <summary>
        /// 班级
        /// </summary>
        private readonly RB_ClassRepository classRepository = new RB_ClassRepository();

        /// <summary>
        /// 阶梯价格
        /// </summary>
        private readonly RB_Class_StepPriceRepository class_StepPriceRepository = new RB_Class_StepPriceRepository();

        /// <summary>
        /// 订单阶梯价格
        /// </summary>
        private readonly RB_Order_StepPriceRepository order_StepPriceRepository = new RB_Order_StepPriceRepository();

        /// <summary>
        /// 课程计划
        /// </summary>
        private readonly RB_Class_PlanRepository class_PlanRepository = new RB_Class_PlanRepository();

        /// <summary>
        /// 课程仓储层对象
        /// </summary>
        private readonly RB_CourseRepository courseRepository = new RB_CourseRepository();

        /// <summary>
        /// 课程优惠仓储层对象
        /// </summary>
        private readonly RB_Course_PreferentialRepository course_PreferentialRepository = new RB_Course_PreferentialRepository();

        /// <summary>
        /// 教师
        /// </summary>
        private readonly RB_TeacherRepository teacherRepository = new RB_TeacherRepository();

        /// <summary>
        /// 助教
        /// </summary>
        private readonly RB_AssistRepository assistRepository = new RB_AssistRepository();

        /// <summary>
        /// 学生
        /// </summary>
        private readonly RB_StudentRepository studentRepository = new RB_StudentRepository();

        /// <summary>
        /// 学生关联
        /// </summary>
        private readonly RB_Student_OrderGuestRepository student_OrderGuestRepository = new RB_Student_OrderGuestRepository();

        /// <summary>
        /// 账号
        /// </summary>
        private readonly RB_AccountRepository accountRepository = new RB_AccountRepository();

        /// <summary>
        /// 合同
        /// </summary>
        private readonly RB_Education_ContractRepository education_ContractRepository = new RB_Education_ContractRepository();
        /// <summary>
        /// 合同协调金额
        /// </summary>
        private readonly RB_Education_ContractAdjustRepository education_ContractAdjustRepository = new RB_Education_ContractAdjustRepository();

        /// <summary>
        /// 留学就业仓储层对象
        /// </summary>
        private readonly RB_StudyAbroadRepository studyAbroadRepository = new RB_StudyAbroadRepository();

        /// <summary>
        /// 报价单仓储层对象
        /// </summary>
        private readonly RB_Course_OfferRepository course_OfferRepository = new RB_Course_OfferRepository();

        /// <summary>
        /// 财务单据
        /// </summary>
        private readonly RB_FinanceRepository financeRepository = new RB_FinanceRepository();
        /// <summary>
        /// 财务单据详情
        /// </summary>
        private readonly RB_FinanceDetailRepository financeDetailRepository = new RB_FinanceDetailRepository();
        /// <summary>
        /// 交易方式
        /// </summary>
        private readonly RB_TradeWayRepository tradeWayRepository = new RB_TradeWayRepository();
        /// <summary>
        /// 币种
        /// </summary>
        private readonly RB_CurrencyRepository currencyRepository = new RB_CurrencyRepository();
        /// <summary>
        /// 银行账户
        /// </summary>
        private readonly RB_BackAccountRepository backAccountRepository = new RB_BackAccountRepository();
        /// <summary>
        /// 现金账户
        /// </summary>
        private readonly RB_CashPoolAccountRepository cashPoolAccountRepository = new RB_CashPoolAccountRepository();
        /// <summary>
        /// 平台账户
        /// </summary>
        private readonly RB_PlatformAccountRepository platformAccountRepository = new RB_PlatformAccountRepository();

        /// <summary>
        /// 班级关联课程仓储层对象
        /// </summary>
        private readonly RB_Class_CourseRepository class_CourseRepository = new RB_Class_CourseRepository();

        /// <summary>
        /// 访客预约仓储层对象
        /// </summary>
        private readonly RB_Visitor_ReserveRepository visitor_ReserveRepository = new RB_Visitor_ReserveRepository();

        #region 日语培训

        /// <summary>
        /// 获取日语培训
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        public List<RB_Class_ViewModel> GetClassPruductListModule(int pageIndex, int pageSize, out long count, RB_Class_ViewModel dmodel)
        {
            var list = classRepository.GetClassProductPageList(pageIndex, pageSize, out count, dmodel);
            if (list.Any())
            {
                string classIds = string.Join(",", list.Select(x => x.ClassId));
                //查询阶梯价格
                var stepList = class_StepPriceRepository.GetClassStepPriceListRepository(new RB_Class_StepPrice_ViewModel() { QClassIds = classIds });
                var otherCourseList = class_CourseRepository.GetClassCourseListRepository(new RB_Class_Course_Extend() { QClassIds = classIds });
                List<RB_Class_Plan_ViewModel> PlanFixed = new List<RB_Class_Plan_ViewModel>();
                string k2classIds = string.Join(",", list.Where(x => x.ClassStyle == Common.Enum.Course.ClassStyleEnum.FixedDate).Select(x => x.ClassId));
                if (!string.IsNullOrEmpty(k2classIds))
                {
                    PlanFixed = class_PlanRepository.GetClassPlanListRepository(new RB_Class_Plan_ViewModel() { QClassIds = k2classIds });
                }
                foreach (var item in list)
                {
                    item.ClassStepPriceList = stepList.Where(x => x.ClassId == item.ClassId).OrderBy(x => x.PersionNum).ToList();
                    item.OtherCourseList = otherCourseList?.Where(qitem => qitem.ClassId == item.ClassId)?.ToList() ?? new List<RB_Class_Course_Extend>();
                    item.DefaultTimeList = new List<ClassTimeItem>();
                    if (item.ClassStyle != Common.Enum.Course.ClassStyleEnum.OnLine)
                    {
                        if (!string.IsNullOrEmpty(item.DefaultTimeJson))
                        {
                            item.DefaultTimeList = JsonHelper.DeserializeObject<List<ClassTimeItem>>(item.DefaultTimeJson);
                        }
                    }
                    item.ClassPlanList = new List<RB_Class_Plan_ViewModel>();
                    if (item.ClassStyle == Common.Enum.Course.ClassStyleEnum.Week || item.ClassStyle == Common.Enum.Course.ClassStyleEnum.Month)
                    {
                        if (!string.IsNullOrEmpty(item.DateJson))
                        {
                            List<int> DayList = JsonHelper.DeserializeObject<List<int>>(item.DateJson);
                            foreach (var qitem in DayList)
                            {
                                item.ClassPlanList.Add(new RB_Class_Plan_ViewModel()
                                {
                                    WeekDay = qitem
                                });
                            }
                        }
                    }
                    else if (item.ClassStyle == Common.Enum.Course.ClassStyleEnum.FixedDate)
                    {
                        item.ClassPlanList = PlanFixed.Where(x => x.ClassId == item.ClassId).ToList();
                    }
                }
            }
            return list;
        }

        /// <summary>
        /// 获取班级课程信息
        /// </summary>
        /// <param name="classId">班级编号</param>
        /// <param name="Group_Id">集团编号</param>
        /// <returns></returns>
        public Dictionary<string, object> GetClassCourseListModule(int classId)
        {
            List<object> newCourseList = new List<object>();
            Dictionary<string, object> fileds = new Dictionary<string, object>();
            var planList = class_PlanRepository.GetClassPlanListExtRepository(new RB_Class_Plan_ViewModel() { ClassId = classId, EndTime = Common.ConvertHelper.FormatDate(DateTime.Now) });
            var totalMinutes = planList?.Sum(qitem => qitem.ClassMinutes) ?? 0;
            //查询基础课时时长
            var BasicMinutes = class_ConfigRepository.GetClassMinutesRepository(classId);
            var finishHours = totalMinutes / BasicMinutes;
            fileds.Add("finishHours", finishHours);
            var classModel = classRepository.GetEntity(classId);
            var courseModel = courseRepository.GetEntity(classModel.CouseId);
            if (courseModel != null && courseModel.CourseId > 0)
            {
                var CoursePriceList = course_PreferentialRepository.GetCoursePreferentialListRepostory(new RB_Course_Preferential_Extend() { CourseId = courseModel.CourseId });
                newCourseList.Add(new
                {
                    courseModel.CourseId,
                    courseModel.CourseName,
                    courseModel.ClassHours,
                    courseModel.SellPrice,
                    CoursePriceList
                });
            }
            var courseList = class_CourseRepository.GetClassCourseListRepository(new RB_Class_Course_Extend() { ClassId = classId });
            if (courseList != null)
            {
                string courseIds = string.Join(",", courseList.Select(qitem => qitem.CourseId));
                var coursePriceList = course_PreferentialRepository.GetCoursePreferentialListRepostory(new RB_Course_Preferential_Extend()
                {
                    QCourseIds = courseIds
                });
                foreach (var item in courseList)
                {
                    newCourseList.Add(new
                    {
                        item.CourseId,
                        item.CourseName,
                        item.ClassHours,
                        item.SellPrice,
                        item.CoursePriceList
                    });
                }
            }
            fileds.Add("otherCourse", newCourseList);
            return fileds;
        }

        /// <summary>
        /// 获取班级名称
        /// </summary>
        /// <param name="classIds"></param>
        /// <returns></returns>
        public List<RB_Class_ViewModel> GetClassNameList(string classIds)
        {
            return classRepository.GetClassListRepository(new RB_Class_ViewModel() { Q_ClassIds = classIds });
        }

        /// <summary>
        /// 获取留学就业产品名称
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public List<RB_StudyAbroad_ViewModel> GetStudyAbroadListModule(string ids)
        {
            return studyAbroadRepository.GetStudyAbroadListRepository(new RB_StudyAbroad_ViewModel()
            {
                QIds = ids
            });
        }

        /// <summary>
        /// 日语培训下单
        /// </summary>
        /// <param name="demodel"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool SetClassOrderModule(RB_Order_ViewModel demodel, UserInfo userInfo, bool isEditOrder, out string message)
        {
            bool flag = false;
            message = "";
            //查询班级信息
            var classModel = classRepository.GetEntity(demodel.ClassId);
            if (classModel == null)
            {
                flag = false;
                message = "班级不存在";
                return flag;
            }
            if (demodel.IsChaBan == 0)
            {
                demodel.CourseId = classModel.CouseId;
            }
            //课程信息
            var courseModel = courseRepository.GetEntity(demodel.CourseId);

            #region 计算订单优惠信息
            //获取课程优惠
            var coursePreferentialList = course_PreferentialRepository.GetCoursePreferentialListRepostory(new RB_Course_Preferential_Extend()
            {
                CourseId = demodel.CourseId
            });
            //课程优惠信息
            decimal disMoney = 0;//课程最大优惠金额
            decimal coursePrice = courseModel.SellPrice;//课程最低单价
            var coursePreferentialModel = new RB_Course_Preferential_Extend();
            if (coursePreferentialList != null && coursePreferentialList.Count > 0)
            {
                if (demodel.GuestNum == 1)
                {
                    coursePreferentialModel = coursePreferentialList?.Where(qitem => qitem.PriceDiscountType == CoursePriceDiscountEnum.SingleJoin)?.FirstOrDefault();
                }
                if (demodel.GuestNum >= 2)
                {
                    coursePreferentialModel = coursePreferentialList?.Where(qitem => qitem.PriceDiscountType == CoursePriceDiscountEnum.DoubleJoin)?.FirstOrDefault();
                }
                var saleCommissionType = coursePreferentialModel?.SaleCommissionType ?? 0;
                if (saleCommissionType == 0)
                {
                    var tempMoney = (courseModel?.SellPrice ?? 0) * (coursePreferentialModel?.SaleCommissionMoney ?? 0);
                    disMoney = tempMoney / Convert.ToDecimal(100);
                }
                else
                {
                    disMoney = coursePreferentialModel?.SaleCommissionMoney ?? 0;
                }
                var b2bCommissionType = coursePreferentialModel?.B2BCommissionType ?? 0;
                if (b2bCommissionType == 0)
                {
                    var tempMoney = (courseModel?.SellPrice ?? 0) * (coursePreferentialModel?.B2BCommissionMoney ?? 0);
                    disMoney += tempMoney / Convert.ToDecimal(100);
                }
                else
                {
                    disMoney = coursePreferentialModel?.B2BCommissionMoney ?? 0;
                }

                var priceCommissionType = coursePreferentialModel?.PriceType ?? 0;
                if (priceCommissionType == 0)
                {
                    coursePrice = coursePrice * (100 - (coursePreferentialModel?.PriceMoney ?? 0)) / 100;
                }
                else
                {
                    coursePrice -= (coursePreferentialModel?.PriceMoney ?? 0);
                }
                #region 记录提成信息
                if (coursePreferentialModel == null)
                {
                    coursePreferentialModel = coursePreferentialList.FirstOrDefault();
                }
                demodel.CommissionType = coursePreferentialModel?.SaleCommissionType ?? 0;
                demodel.CommissionRate = coursePreferentialModel?.SaleCommissionMoney ?? 0;
                demodel.CommissionTypeTH = coursePreferentialModel?.B2BCommissionType ?? 0;
                demodel.CommissionRateTH = coursePreferentialModel?.B2BCommissionMoney ?? 0;
                if (coursePreferentialModel != null)
                {
                    demodel.CommissionRemark = "使用优惠Id:" + coursePreferentialModel.Id + " 返佣类型:" + demodel.CommissionType + " 返佣比例/金额:" + demodel.CommissionRate + " 同行返佣类型:" + demodel.CommissionTypeTH + " 同行返佣比例/金额:" + demodel.CommissionRateTH;
                }
                #endregion
            }
            if (demodel.IsLessPrice == 1 && demodel.LessPrice > 0)
            {
                if (coursePreferentialList != null && coursePreferentialList.Count > 0)
                {
                    if (demodel.LessPrice > disMoney)
                    {
                        message = string.Format("优惠金额不能大于{0}", disMoney.ToString("0.00"));
                        return flag;
                    }
                }
                else
                {
                    message = "此课程未配置【销售提成】信息，请通知OP在课程里面添加优惠信息!";
                    return flag;
                }
            }
            #endregion
            if (demodel.OrderSource == OrderSourceEnum.EduClient || demodel.OrderSource == OrderSourceEnum.Client)
            {
                if (demodel.OrderSource == OrderSourceEnum.EduClient)
                {
                    demodel.GeneralOccupation = "";
                }
                else if (demodel.OrderSource == OrderSourceEnum.Client)
                {
                    demodel.EduOccupation = "";
                }
            }
            else
            {
                demodel.EduOccupation = "";
                demodel.GeneralOccupation = "";
            }
            if (demodel.IsLessPrice == 0)
            {
                demodel.LessPrice = 0;
            }
            var orderModel = new RB_Order();
            if (demodel.OrderId > 0)
            {
                orderModel = orderRepository.GetEntity(demodel.OrderId);
            }
            if (demodel.OrderId > 0)
            {
                int BNum = orderRepository.GetClassOrderPeopleNumRepository(demodel.ClassId.ToString()).FirstOrDefault()?.GuestNum ?? 0;
                if (BNum + demodel.GuestNum - orderModel.GuestNum > classModel.ClassPersion)
                {
                    flag = false;
                    message = "人数报超" + (classModel.ClassPersion - (BNum + demodel.GuestNum - orderModel.GuestNum));
                    return flag;
                }
            }
            else
            {
                int BNum = orderRepository.GetClassOrderPeopleNumRepository(demodel.ClassId.ToString()).FirstOrDefault()?.GuestNum ?? 0;
                if (BNum + demodel.GuestNum > classModel.ClassPersion)
                {
                    flag = false;
                    message = "人数报超" + (classModel.ClassPersion - (BNum + demodel.GuestNum));
                    return flag;
                }
            }
            //没有总经理修改订单权限
            if (!isEditOrder)
            {
                if (demodel.Unit_Price < coursePrice)
                {
                    flag = false;
                    message = "成交单价不能小于最低价格";
                    return flag;
                }
                if (demodel.IsChaBan == 1)
                {
                    var newPreferPrice = Math.Round(coursePrice / courseModel.ClassHours * (courseModel.ClassHours - demodel.StartClassHours) * demodel.GuestNum, 2);
                    if (demodel.PreferPrice != (newPreferPrice - demodel.LessPrice))
                    {
                        flag = false;
                        message = "应收总额不正确";
                        return flag;
                    }
                }
                else
                {
                    if (demodel.PreferPrice != (demodel.Unit_Price * demodel.GuestNum - demodel.LessPrice))
                    {
                        flag = false;
                        message = "应收总额不正确";
                        return flag;
                    }
                }
            }
            //日志信息
            string LogContent = "";
            //销售备注
            string SaleRemark = "";
            if (demodel.OrderId > 0)
            {
                if (demodel.IsChaBan == 1)
                {
                    if (orderModel.EffectStatus != 2)
                    {
                        if (demodel.EffectTime < Convert.ToDateTime(Common.ConvertHelper.FormatDate(DateTime.Now)))
                        {
                            demodel.EffectStatus = 1;
                        }
                        else
                        {
                            demodel.EffectStatus = 0;
                        }
                    }
                    else
                    {
                        demodel.EffectStatus = orderModel.EffectStatus;
                    }
                }
                else
                {
                    demodel.EffectStatus = 2;
                    demodel.EffectTime = DateTime.Now;
                }

                if (orderModel == null)
                {
                    flag = false;
                    message = "订单不存在";
                    return flag;
                }
                if (orderModel.OrderState == Common.Enum.Course.OrderStateEnum.Cancel)
                {
                    flag = false;
                    message = "取消订单无法修改";
                    return flag;
                }

                #region 验证学生名单数量
                var glist = order_GuestRepository.GetOrderGuestListRepository(new RB_Order_Guest_ViewModel() { Group_Id = demodel.Group_Id, OrderId = demodel.OrderId, GuestState = 1 });
                if (glist.Count() > demodel.GuestNum)
                {
                    flag = false;
                    message = "请先取消学生名单再修改订单人员数量";
                    return flag;
                }
                #endregion

                Dictionary<string, object> keyValues = new Dictionary<string, object>()
                {
                    { nameof(RB_Order_ViewModel.GuestNum),demodel.GuestNum},
                    { nameof(RB_Order_ViewModel.Unit_Price),demodel.Unit_Price},
                    { nameof(RB_Order_ViewModel.PreferPrice),demodel.PreferPrice},
                    { nameof(RB_Order_ViewModel.OrderSource),demodel.OrderSource},
                    { nameof(RB_Order_ViewModel.SaleRemark),demodel.SaleRemark},
                    { nameof(RB_Order_ViewModel.HelpEnterId),demodel.HelpEnterId},
                    { nameof(RB_Order_ViewModel.GeneralOccupation),demodel.GeneralOccupation},
                    { nameof(RB_Order_ViewModel.EduOccupation),demodel.EduOccupation},
                    { nameof(RB_Order_ViewModel.IsLessPrice),demodel.IsLessPrice},
                    { nameof(RB_Order_ViewModel.LessPrice),demodel.LessPrice},
                    { nameof(RB_Order_ViewModel.StartClassHours),demodel.StartClassHours},
                    { nameof(RB_Order_ViewModel.CourseId),demodel.CourseId},
                    { nameof(RB_Order_ViewModel.EffectStatus),demodel.EffectStatus},
                    { nameof(RB_Order_ViewModel.EffectTime),demodel.EffectTime},
                    { nameof(RB_Order_ViewModel.UpOrderId),demodel.UpOrderId},
                };
                flag = orderRepository.Update(keyValues, new WhereHelper(nameof(RB_Order_ViewModel.OrderId), demodel.OrderId));

                //记录日志信息
                LogContent = $"修改日语培训订单【{demodel.OrderId}】";
                if (orderModel.GuestNum != demodel.GuestNum)
                {
                    LogContent += $"，人数由【{orderModel.GuestNum}】修改为【{demodel.GuestNum}】";
                }
                if (orderModel.Unit_Price != demodel.Unit_Price)
                {
                    LogContent += $"，成交单价由【{orderModel.Unit_Price}】修改为【{demodel.Unit_Price}】";
                }
                if (orderModel.PreferPrice != demodel.PreferPrice)
                {
                    LogContent += $"，应收金额由【{orderModel.PreferPrice}】修改为【{demodel.PreferPrice}】";
                }
                if (orderModel.OrderSource != demodel.OrderSource)
                {
                    LogContent += $"，客人来源由【{orderModel.OrderSource.ToName()}】修改为【{demodel.OrderSource.ToName()}】";
                }
                if (orderModel.HelpEnterId != demodel.HelpEnterId)
                {
                    var empList = accountRepository.GetAccountListRepository(new RB_Account_ViewModel() { QIds = orderModel.HelpEnterId + "," + demodel.HelpEnterId });
                    LogContent += $"，协助人员由【{empList?.Where(qitem => qitem.Id == orderModel.HelpEnterId)?.FirstOrDefault()?.AccountName}】修改为【{empList?.Where(qitem => qitem.Id == demodel.HelpEnterId)?.FirstOrDefault()?.AccountName}】";
                }
                if (orderModel.GeneralOccupation != demodel.GeneralOccupation)
                {
                    LogContent += $"，一般同行由【{orderModel.GeneralOccupation}】修改为【{demodel.GeneralOccupation}】";
                }
                if (orderModel.EduOccupation != demodel.EduOccupation)
                {
                    LogContent += $"，教育同行由【{orderModel.EduOccupation}】修改为【{demodel.EduOccupation}】";
                }
                if (orderModel.IsLessPrice != demodel.IsLessPrice)
                {
                    LogContent += $"，少价由【{(orderModel.IsLessPrice > 0 ? "少价" : "不少价")}】修改为【{(demodel.IsLessPrice > 0 ? "少价" : "不少价")}】";
                }
                if (orderModel.LessPrice != demodel.LessPrice)
                {
                    LogContent += $"，少价金额由【{(orderModel.LessPrice)}】修改为【{(demodel.LessPrice)}】";
                }
                //记录订单备注
                if (orderModel.SaleRemark != demodel.SaleRemark)
                {
                    LogContent += $"，销售备注由【{orderModel.SaleRemark}】修改为【{demodel.SaleRemark}】";
                    SaleRemark = demodel.SaleRemark;
                }
            }
            else
            {
                if (demodel.IsChaBan == 1)
                {
                    if (demodel.EffectTime < Convert.ToDateTime(Common.ConvertHelper.FormatDate(DateTime.Now)))
                    {
                        demodel.EffectStatus = 1;
                    }
                    else
                    {
                        demodel.EffectStatus = 0;
                    }
                }
                else
                {
                    demodel.EffectStatus = 1;
                    demodel.EffectTime = DateTime.Now;
                }
                if (classModel.ClassStatus == Common.Enum.Course.ClassStatusEnum.EndClass || classModel.ClassStatus == Common.Enum.Course.ClassStatusEnum.CancelClass)
                {
                    flag = false;
                    message = "班级状态不正确";
                    return flag;
                }
                demodel.Class_Price = courseModel.SellPrice;
                int OrderId = orderRepository.Insert(demodel);
                demodel.OrderId = OrderId;
                flag = OrderId > 0;
                LogContent = "新增日语培训订单";
                //记录订单备注
                if (!string.IsNullOrEmpty(demodel.SaleRemark))
                {
                    SaleRemark = demodel.SaleRemark;
                }

                #region 预约单转订单
                //预约单转订单
                if (flag && demodel.VisitorReserveId > 0)
                {
                    string remark = userInfo.AccountName + "转订单";
                    Dictionary<string, object> visitorFileds = new Dictionary<string, object>()
                    {
                        {nameof(RB_Visitor_Reserve_Extend.ReserveStatus),1 },
                        {nameof(RB_Visitor_Reserve_Extend.Remark),remark },
                        {nameof(RB_Visitor_Reserve_Extend.OrderId),demodel.OrderId },
                    };
                    flag = visitor_ReserveRepository.Update(visitorFileds, new WhereHelper(nameof(RB_Visitor_Reserve_Extend.Id), demodel.VisitorReserveId));
                    var visitorModel = visitor_ReserveRepository.GetVisitorRepository(new RB_Visitor_Reserve_Extend() { Id = demodel.VisitorReserveId })?.FirstOrDefault();
                    var guestModel = new RB_Order_Guest_ViewModel()
                    {
                        Id = 0,
                        OrderId = demodel.OrderId,
                        ClassId = demodel.ClassId,
                        GuestName = visitorModel?.Name ?? "",
                        GuestState = 1,
                        Profession = "",
                        Sex = 1,
                        Age = 18,
                        Mobile = visitorModel?.Tel ?? "",
                        Basics = visitorModel?.LevelType,
                        Education = GuestEducationEnum.N2,
                        GuestSource = demodel.OrderSource,
                        LearningGoals = GuestLearningGoalsEnum.Love,
                        Contact = "",
                        ContactMobile = "",
                        Status = 0,
                        Group_Id = demodel.Group_Id,
                        School_Id = demodel.School_Id,
                        CreateBy = demodel.CreateBy,
                        CreateTime = demodel.CreateTime,
                        UpdateBy = demodel.UpdateBy,
                        UpdateTime = demodel.UpdateTime,
                        DropOutRemark = "",
                        IDCard = "",
                        Domicile = "",
                        ContactAddress = "",
                        SourceId = 0,
                        GraduatedSchool = "",
                        GraduatedMajor = "",
                        VolunteerMajor = "",
                        Price = 0,
                        StudyRemark = "",
                        TotalHours = Convert.ToInt32(courseModel.ClassHours),
                        CompleteHours = 0,
                        MakeUpHours = 0,
                        StuIcon = "",
                    };
                    SetOrderGuestInfo(guestModel, out string Nmessage);
                }
                #endregion

                #region 续课订单 添加学员名单
                if (flag && demodel.RenewOrderId > 0 && demodel.OldGuestId>0)
                {
                    var oldGuestModel = order_GuestRepository.GetEntity(demodel.OldGuestId);
                    var guestModel = new RB_Order_Guest_ViewModel()
                    {
                        Id = 0,
                        OrderId = demodel.OrderId,
                        ClassId = demodel.ClassId,
                        GuestName = oldGuestModel?.GuestName ?? "",
                        GuestState = 1,
                        Profession = oldGuestModel?.Profession??"",
                        Sex = oldGuestModel?.Sex??1,
                        Age = oldGuestModel?.Age ?? 18,
                        Mobile = oldGuestModel?.Mobile ?? "",
                        Basics = oldGuestModel?.Basics,
                        Education = oldGuestModel?.Education?? GuestEducationEnum.N2,
                        GuestSource = demodel.OrderSource,
                        LearningGoals = oldGuestModel?.LearningGoals??GuestLearningGoalsEnum.Love,
                        Contact = oldGuestModel?.Contact??"",
                        ContactMobile = oldGuestModel?.ContactMobile?? "",
                        Status = 0,
                        Group_Id = demodel.Group_Id,
                        School_Id = demodel.School_Id,
                        CreateBy = demodel.CreateBy,
                        CreateTime = demodel.CreateTime,
                        UpdateBy = demodel.UpdateBy,
                        UpdateTime = demodel.UpdateTime,
                        DropOutRemark = "",
                        IDCard = oldGuestModel?.IDCard??"",
                        Domicile = oldGuestModel?.Domicile ?? "",
                        ContactAddress = oldGuestModel?.ContactAddress ?? "",
                        SourceId = 0,
                        GraduatedSchool = oldGuestModel?.GraduatedSchool ?? "",
                        GraduatedMajor = oldGuestModel?.GraduatedMajor ?? "",
                        VolunteerMajor = oldGuestModel?.VolunteerMajor ?? "",
                        Price = 0,
                        StudyRemark = "",
                        TotalHours = Convert.ToInt32(courseModel.ClassHours),
                        CompleteHours = 0,
                        MakeUpHours = 0,
                        StuIcon = "",
                    };
                    SetOrderGuestInfo(guestModel, out string Nmessage);
                }
                #endregion
            }

            #region 写日志
            if (flag)
            {
                //销售备注
                if (!string.IsNullOrEmpty(SaleRemark))
                {
                    order_RemarkRepository.Insert(new Model.Entity.Course.RB_Order_Remark()
                    {
                        Id = 0,
                        Content = SaleRemark,
                        CreateBy = demodel.CreateBy,
                        CreateTime = DateTime.Now,
                        OrderId = demodel.OrderId,
                        Type = 1
                    });
                }

                //订单日志
                if (!string.IsNullOrEmpty(LogContent))
                {
                    changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                    {
                        Id = 0,
                        Type = 2,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Group_Id = userInfo.Group_Id,
                        LogContent = LogContent,
                        School_Id = userInfo.School_Id,
                        SourceId = demodel.OrderId
                    });
                }
            }
            #endregion

            return flag;
        }

        /// <summary>
        /// 更新订单提成比例
        /// </summary>
        /// <returns></returns>
        public bool UpdateClassOrderCommissionRate()
        {
            var orderList = orderRepository.GetOrderListRepository(new RB_Order_ViewModel() { Group_Id = 100000, OrderType = OrderTypeEnum.CourseOrder, Q_OrderState = 1 });
            foreach (var item in orderList)
            {
                //根据班级查询课程
                var classModel = classRepository.GetEntity(item.ClassId);

                #region 计算订单优惠信息
                //获取课程优惠
                var coursePreferentialList = course_PreferentialRepository.GetCoursePreferentialListRepostory(new RB_Course_Preferential_Extend()
                {
                    CourseId = classModel.CouseId
                });
                //课程优惠信息
                RB_Course_Preferential_Extend coursePreferentialModel = null;
                if (coursePreferentialList != null && coursePreferentialList.Count > 0)
                {
                    if (item.RenewOrderId > 0 && coursePreferentialList.Where(x => x.PriceDiscountType == CoursePriceDiscountEnum.Renewal).Any())
                    {
                        coursePreferentialModel = coursePreferentialList?.Where(qitem => qitem.PriceDiscountType == CoursePriceDiscountEnum.Renewal)?.FirstOrDefault();
                    }
                    if (coursePreferentialModel == null)
                    {
                        if (item.GuestNum == 1)
                        {
                            coursePreferentialModel = coursePreferentialList?.Where(qitem => qitem.PriceDiscountType == CoursePriceDiscountEnum.SingleJoin)?.FirstOrDefault();
                        }
                        if (item.GuestNum >= 2)
                        {
                            coursePreferentialModel = coursePreferentialList?.Where(qitem => qitem.PriceDiscountType == CoursePriceDiscountEnum.DoubleJoin)?.FirstOrDefault();
                        }
                    }
                    if (coursePreferentialModel == null)
                    {
                        //随便取一个了
                        coursePreferentialModel = coursePreferentialList.FirstOrDefault();
                    }

                    #region 记录提成信息
                    item.CommissionType = coursePreferentialModel?.SaleCommissionType ?? 0;
                    item.CommissionRate = coursePreferentialModel?.SaleCommissionMoney ?? 0;
                    item.CommissionTypeTH = coursePreferentialModel?.B2BCommissionType ?? 0;
                    item.CommissionRateTH = coursePreferentialModel?.B2BCommissionMoney ?? 0;
                    if (coursePreferentialModel != null)
                    {
                        item.CommissionRemark = "初始化使用优惠Id:" + coursePreferentialModel.Id + " 返佣类型:" + item.CommissionType + " 返佣比例/金额:" + item.CommissionRate + " 同行返佣类型:" + item.CommissionTypeTH + " 同行返佣比例/金额:" + item.CommissionRateTH;
                    }
                    Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                        { nameof(RB_Order_ViewModel.CommissionType),item.CommissionType},
                        { nameof(RB_Order_ViewModel.CommissionRate),item.CommissionRate},
                        { nameof(RB_Order_ViewModel.CommissionTypeTH),item.CommissionTypeTH},
                        { nameof(RB_Order_ViewModel.CommissionRateTH),item.CommissionRateTH},
                        { nameof(RB_Order_ViewModel.CommissionRemark),item.CommissionRemark},
                    };
                    List<WhereHelper> wheres = new List<WhereHelper>() {
                        new WhereHelper(){
                             FiledName=nameof(RB_Order_ViewModel.OrderId),
                              FiledValue=item.OrderId,
                               OperatorEnum=OperatorEnum.Equal
                        }
                    };
                    orderRepository.Update(keyValues, wheres);
                    #endregion
                }
                #endregion
            }
            return true;
        }

        /// <summary>
        /// 留学就业下单
        /// </summary>
        /// <param name="demodel"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool SetStudyOrderModule(RB_Order_ViewModel demodel, UserInfo userInfo, out string message)
        {
            bool flag = false;
            message = "";
            var studyModel = studyAbroadRepository.GetEntity(demodel.SourceId);
            if (studyModel == null)
            {
                flag = false;
                message = "留学就业产品不存在";
                return flag;
            }
            demodel.OldPreferPrice = studyModel.SellPrice * demodel.GuestNum;

            demodel.Class_Price = studyModel.SellPrice;
            decimal MinPrice = studyModel.SellPrice;
            if (demodel.Unit_Price < MinPrice)
            {
                flag = false;
                message = "成交单价不能小于最低价格";
                return flag;
            }
            if (demodel.OrderNature == OrderNatureEnum.ThroughTrain && demodel.PreferPrice != demodel.Unit_Price * demodel.GuestNum)
            {
                flag = false;
                message = "应收总额不正确";
                return flag;
            }
            if (demodel.OrderId > 0)
            {
                var orderModel = orderRepository.GetEntity(demodel.OrderId);
                if (orderModel == null)
                {
                    flag = false;
                    message = "订单不存在";
                    return flag;
                }
                if (orderModel.OrderState == Common.Enum.Course.OrderStateEnum.Cancel)
                {
                    flag = false;
                    message = "取消订单无法修改";
                    return flag;
                }
                Dictionary<string, object> keyValues = new Dictionary<string, object>()
                {
                    { nameof(RB_Order_ViewModel.GuestNum),demodel.GuestNum},
                    { nameof(RB_Order_ViewModel.Unit_Price),demodel.Unit_Price},
                    { nameof(RB_Order_ViewModel.PreferPrice),demodel.PreferPrice},
                    { nameof(RB_Order_ViewModel.OrderSource),demodel.OrderSource},
                    { nameof(RB_Order_ViewModel.SaleRemark),demodel.SaleRemark},
                    { nameof(RB_Order_ViewModel.OrderNature),demodel.OrderNature},
                    { nameof(RB_Order_ViewModel.OldPreferPrice),demodel.OldPreferPrice},
                };
                flag = orderRepository.Update(keyValues, new WhereHelper(nameof(RB_Order_ViewModel.OrderId), demodel.OrderId));
                if (flag)
                {
                    //记录日志信息
                    string LogContent = $"修改留学就业订单【{demodel.OrderId}】";
                    if (orderModel.GuestNum != demodel.GuestNum)
                    {
                        LogContent += $"，人数由【{orderModel.GuestNum}】修改为【{demodel.GuestNum}】";
                    }
                    if (orderModel.Unit_Price != demodel.Unit_Price)
                    {
                        LogContent += $"，成交单价由【{orderModel.Unit_Price}】修改为【{demodel.Unit_Price}】";
                    }
                    if (orderModel.PreferPrice != demodel.PreferPrice)
                    {
                        LogContent += $"，应收金额由【{orderModel.PreferPrice}】修改为【{demodel.PreferPrice}】";
                    }
                    if (orderModel.OrderSource != demodel.OrderSource)
                    {
                        LogContent += $"，客人来源由【{orderModel.OrderSource.ToName()}】修改为【{demodel.OrderSource.ToName()}】";
                    }
                    if (orderModel.OrderNature != demodel.OrderNature)
                    {
                        LogContent += $"，订单性质由【{orderModel.OrderSource.ToName()}】修改为【{demodel.OrderSource.ToName()}】";
                    }
                    //记录订单备注
                    if (orderModel.SaleRemark != demodel.SaleRemark)
                    {
                        LogContent += $"，销售备注由【{orderModel.SaleRemark}】修改为【{demodel.SaleRemark}】";
                        order_RemarkRepository.Insert(new Model.Entity.Course.RB_Order_Remark()
                        {
                            Id = 0,
                            Content = demodel.SaleRemark,
                            CreateBy = demodel.CreateBy,
                            CreateTime = DateTime.Now,
                            OrderId = demodel.OrderId,
                            Type = 1
                        });
                    }
                    changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                    {
                        Id = 0,
                        Type = 2,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Group_Id = userInfo.Group_Id,
                        LogContent = LogContent,
                        School_Id = userInfo.School_Id,
                        SourceId = demodel.OrderId
                    });
                }
            }
            else
            {
                if (studyModel.SaleState != Common.Enum.Sale.SaleStateEnum.Sell)
                {
                    flag = false;
                    message = "留学就业产品不正确";
                    return flag;
                }
                int OrderId = orderRepository.Insert(demodel);
                flag = OrderId > 0;
                if (flag)
                {
                    //记录订单备注
                    if (!string.IsNullOrEmpty(demodel.SaleRemark))
                    {
                        order_RemarkRepository.Insert(new Model.Entity.Course.RB_Order_Remark()
                        {
                            Id = 0,
                            Content = demodel.SaleRemark,
                            CreateBy = demodel.CreateBy,
                            CreateTime = DateTime.Now,
                            OrderId = OrderId,
                            Type = 1
                        });
                    }
                    //记录日志信息
                    changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                    {
                        Id = 0,
                        Type = 2,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Group_Id = userInfo.Group_Id,
                        LogContent = "新增留学就业订单",
                        School_Id = userInfo.School_Id,
                        SourceId = OrderId
                    });
                }
            }
            return flag;
        }

        /// <summary>
        /// 获取订单详情
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public RB_Order_ViewModel GetClassOrderInfoModule(int orderId)
        {
            var model = orderRepository.GetEntity<RB_Order_ViewModel>(orderId);
            if (model != null)
            {
                if (model.OrderType == Common.Enum.Sale.OrderTypeEnum.CourseOrder)
                {
                    var classModel = classRepository.GetEntity(model.ClassId);
                    if (classModel != null)
                    {
                        model.ClassName = classModel?.ClassName ?? "";
                        model.OpenTime = classModel.OpenTime;
                    }
                }
                else if (model.OrderType == Common.Enum.Sale.OrderTypeEnum.StudyabroadOrder)
                {
                    model.ClassName = studyAbroadRepository.GetEntity(model.SourceId)?.Name ?? "";
                }
            }
            return model;
        }



        /// <summary>
        /// 获取订单阶梯价格
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public List<RB_Order_StepPrice_ViewModel> GetClassOrderSetpPrice(int orderId)
        {
            return order_StepPriceRepository.GetList(new RB_Order_StepPrice_ViewModel() { OrderId = orderId });
        }

        /// <summary>
        /// 获取日志列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        public List<RB_User_ChangeLog_ViewModel> GetClassOrderLogList(int pageIndex, int pageSize, out long count, RB_User_ChangeLog_ViewModel dmodel)
        {
            return changeLogRepository.GetPageList(pageIndex, pageSize, out count, dmodel);
        }

        /// <summary>
        /// 转交订单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="careOfPeople"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool SetClassOrderCareOf(int orderId, int careOfPeople, UserInfo userInfo)
        {
            var ordermodel = orderRepository.GetEntity(orderId);
            if (ordermodel == null) { return false; }
            if (ordermodel.EnterID != userInfo.Id)
            {
                return false;
            }
            Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                { nameof(RB_Order_ViewModel.EnterID),careOfPeople}
            };
            List<WhereHelper> wheres = new List<WhereHelper>() {
                new WhereHelper(){
                     FiledName=nameof(RB_Order_ViewModel.OrderId),
                      FiledValue=orderId,
                       OperatorEnum=OperatorEnum.Equal
                }
            };
            bool flag = orderRepository.Update(keyValues, wheres);
            if (flag)
            {
                //记录日志信息
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    LogContent = $"修改【{orderId}】订单业务员，由【{UserReidsCache.GetUserLoginInfo(ordermodel.EnterID).AccountName}({ordermodel.EnterID})】修改为【{UserReidsCache.GetUserLoginInfo(careOfPeople).AccountName}({careOfPeople})】",
                    School_Id = userInfo.School_Id,
                    SourceId = orderId
                });
            }
            return flag;
        }

        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool CancelClassOrder(int orderId, UserInfo userInfo)
        {
            var orderModel = orderRepository.GetEntity(orderId);
            Dictionary<string, object> keyValues = new Dictionary<string, object>()
            {
                { nameof(RB_Order_ViewModel.OrderState),OrderStateEnum.Cancel}
            };
            if (orderModel.OfferId > 0)
            {
                keyValues.Add(nameof(RB_Order_ViewModel.OfferId), 0);
            }
            List<WhereHelper> wheres = new List<WhereHelper>()
            {
                new WhereHelper()
                {
                    FiledName=nameof(RB_Order_ViewModel.OrderId),
                    FiledValue=orderId,
                    OperatorEnum=OperatorEnum.Equal
                }
            };
            bool flag = orderRepository.Update(keyValues, wheres);
            if (flag)
            {
                if (orderModel.OfferId > 0)
                {
                    Dictionary<string, object> offerFileds = new Dictionary<string, object>()
                    {
                        { nameof(RB_Course_Offer_ViewModel.CustomerStatus),(int)CustomerStatusEnum.Cancel},
                        { nameof(RB_Course_Offer_ViewModel.OrderId),0},
                    };
                    flag = course_OfferRepository.Update(offerFileds, new WhereHelper(nameof(RB_Course_Offer_ViewModel.Id), orderModel.OfferId));
                }
                //记录日志信息
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    LogContent = $"取消日语培训订单【{orderId}】",
                    School_Id = userInfo.School_Id,
                    SourceId = orderId
                });
            }
            return flag;
        }

        #endregion

        #region 班级或留学产品订单

        /// <summary>
        /// 班级或留学产品订单
        /// </summary>
        /// <param name="classId">班级编号</param>
        /// <param name="groupId"></param>
        /// <param name="SourceId">留学就业产品编号</param>
        /// <param name="ClassInfo"></param>
        /// <returns></returns>
        public List<RB_Order_ViewModel> GetClassOrderList(int classId, int groupId, int SourceId, out object ClassInfo)
        {
            ClassInfo = new { };
            //获取订单列表
            var orderList = new List<RB_Order_ViewModel>();
            int courseId = 0;
            if (classId > 0)
            {
                var cModel = classRepository.GetEntity(classId);
                if (cModel == null)
                {
                    return new List<RB_Order_ViewModel>();
                }
                courseId = cModel.CouseId;
                //获取班级教师
                var tModel = teacherRepository.GetEntity(cModel.Teacher_Id);
                var zModel = assistRepository.GetEntity(cModel.Assist_Id);
                ClassInfo = new
                {
                    cModel.ClassName,
                    cModel.ClassNo,
                    tModel?.TeacherName,
                    tModel?.TeacherIcon,
                    zModel?.AssistName,
                    zModel?.AssistIcon
                };
            }
            else if (SourceId > 0)
            {
                var studyModel = studyAbroadRepository.GetEntity(SourceId);
                if (studyModel != null && studyModel.Id > 0)
                {
                    ClassInfo = new
                    {
                        StudyName = studyModel.Name,
                    };
                }
            }
            //获取订单列表
            var query = new RB_Order_ViewModel() { Group_Id = groupId, ClassId = classId, SourceId = SourceId };
            orderList = OrderPageModule(1, 100000, out _, query);
            return orderList;
        }

        /// <summary>
        /// 获取班级订单列表
        /// </summary>
        /// <param name="classId"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public List<RB_Order_ViewModel> GetClassOrderListExtModule(RB_Order_ViewModel query)
        {
            //获取订单列表
            var orderList = orderRepository.GetOrderListRepository(query);
            var guestList = new List<RB_Order_Guest_ViewModel>();
            if (orderList != null && orderList.Count > 0)
            {
                string orderIds = string.Join(",", orderList.Select(x => x.OrderId));
                //获取名单列表
                guestList = order_GuestRepository.GetOrderGuestListRepository(new RB_Order_Guest_ViewModel() { OrderIds = orderIds });
            }
            foreach (var item in orderList)
            {
                item.GuestList = guestList.Where(x => x.OrderId == item.OrderId).ToList();
            }
            return orderList;
        }

        /// <summary>
        /// 设置订单使用最新的班级价格
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public bool SetClassOrderUseNewClassPrice(int orderId)
        {
            var demodel = orderRepository.GetEntity(orderId);
            //查询班级信息
            var classModel = classRepository.GetEntity(demodel.ClassId);
            if (classModel == null)
            {
                return false;
            }
            List<RB_Class_StepPrice_ViewModel> spList = new List<RB_Class_StepPrice_ViewModel>();
            if (classModel.IsStepPrice == 1)
            {
                spList = class_StepPriceRepository.GetClassStepPriceListRepository(new RB_Class_StepPrice_ViewModel() { ClassId = demodel.ClassId });
            }
            return true;
        }

        /// <summary>
        /// 更新订单销售
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="enterID"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public string UpdateOrderSale(int orderId, int enterID, UserInfo userInfo)
        {
            var orderModel = orderRepository.GetEntity(orderId);
            if (orderModel == null) { return "订单不存在，请核实后再试"; }
            if (orderModel.EnterID == enterID)
            {
                return "不能转交给同一人";
            }
            Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                { nameof(RB_Order_ViewModel.EnterID),enterID}
            };
            List<WhereHelper> wheres = new List<WhereHelper>() {
                new WhereHelper(){
                     FiledName=nameof(RB_Order_ViewModel.OrderId),
                      FiledValue=orderId,
                       OperatorEnum=OperatorEnum.Equal
                }
            };
            bool flag = orderRepository.Update(keyValues, wheres);
            if (flag)
            {
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    LogContent = "修改销售，由" + (UserReidsCache.GetUserLoginInfo(orderModel.EnterID)?.AccountName ?? "") + "(" + orderModel.EnterID + ") 修改为" + (UserReidsCache.GetUserLoginInfo(enterID)?.AccountName ?? "") + "(" + enterID + ")",
                    School_Id = userInfo.School_Id,
                    SourceId = orderId
                });
            }
            return flag ? "" : "操作失败，请联系管理员";
        }

        /// <summary>
        /// 获取订单备注列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        public List<RB_Order_Remark_ViewModel> GetClassOrderRemarkPageModule(int pageIndex, int pageSize, out long count, RB_Order_Remark_ViewModel dmodel)
        {
            return order_RemarkRepository.GetOrderRemarkPageRepository(pageIndex, pageSize, out count, dmodel);
        }

        /// <summary>
        /// 修改备注
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="type"></param>
        /// <param name="remark"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool UpdateOrderRemark(int orderId, int type, string remark, UserInfo userInfo)
        {
            var orderModel = orderRepository.GetEntity(orderId);
            if (orderModel == null) { return false; }
            Dictionary<string, object> keyValues = new Dictionary<string, object>() { };
            string LogContent;
            if (type == 2)
            {
                if (orderModel.TeacherRemark == remark) { return true; }
                keyValues.Add(nameof(RB_Order_ViewModel.TeacherRemark), remark);
                LogContent = "修改教务备注：由【" + orderModel.TeacherRemark + "】修改为【" + remark + "】";
            }
            else if (type == 3)
            {
                if (orderModel.RectorRemark == remark) { return true; }
                keyValues.Add(nameof(RB_Order_ViewModel.RectorRemark), remark);
                LogContent = "修改校长备注：由【" + orderModel.RectorRemark + "】修改为【" + remark + "】";
            }
            else if (type == 4)
            {
                if (orderModel.DirectorRemark == remark) { return true; }
                keyValues.Add(nameof(RB_Order_ViewModel.DirectorRemark), remark);
                LogContent = "修改经理备注：由【" + orderModel.DirectorRemark + "】修改为【" + remark + "】";
            }
            else if (type == 1)
            {
                if (orderModel.SaleRemark == remark) { return true; }
                keyValues.Add(nameof(RB_Order_ViewModel.SaleRemark), remark);
                LogContent = "修改销售备注：由【" + orderModel.SaleRemark + "】修改为【" + remark + "】";
            }
            else { return false; }
            List<WhereHelper> wheres = new List<WhereHelper>() {
                new WhereHelper(){
                     FiledName=nameof(RB_Order_ViewModel.OrderId),
                      FiledValue=orderId,
                       OperatorEnum=OperatorEnum.Equal
                }
            };
            var flag = orderRepository.Update(keyValues, wheres);
            if (flag)
            {
                if (type == 1)
                {
                    order_RemarkRepository.Insert(new Model.Entity.Course.RB_Order_Remark()
                    {
                        Id = 0,
                        OrderId = orderId,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Content = remark,
                        Type = 1
                    });
                }
                else if (type == 2)
                {
                    order_RemarkRepository.Insert(new Model.Entity.Course.RB_Order_Remark()
                    {
                        Id = 0,
                        OrderId = orderId,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Content = remark,
                        Type = 2
                    });
                }
                else if (type == 3)
                {
                    order_RemarkRepository.Insert(new Model.Entity.Course.RB_Order_Remark()
                    {
                        Id = 0,
                        OrderId = orderId,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Content = remark,
                        Type = 3
                    });
                }
                else if (type == 4)
                {
                    order_RemarkRepository.Insert(new Model.Entity.Course.RB_Order_Remark()
                    {
                        Id = 0,
                        OrderId = orderId,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Content = remark,
                        Type = 4
                    });
                }
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    LogContent = LogContent,
                    School_Id = userInfo.School_Id,
                    SourceId = orderId
                });
            }
            return flag;
        }

        /// <summary>
        /// 修改提成
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="type"></param>
        /// <param name="commissionMoney"></param>
        /// <param name="extraRewardMoney"></param>
        /// <param name="extraDeductMoney"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool UpdateOrderCommission(int orderId, int type, decimal commissionMoney, decimal extraRewardMoney, decimal extraDeductMoney, UserInfo userInfo)
        {
            var orderModel = orderRepository.GetEntity(orderId);
            if (orderModel == null) { return false; }
            if (type == 1)
            {
                if (orderModel.IsCommissionGive != 1)
                {
                    return false;
                }
                if (orderModel.CommissionMoney == commissionMoney) { return true; }
                Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                    { nameof(RB_Order_ViewModel.CommissionMoney),commissionMoney}
                };
                List<WhereHelper> wheres = new List<WhereHelper>() {
                     new WhereHelper(){
                         FiledName=nameof(RB_Order_ViewModel.OrderId),
                          FiledValue=orderId,
                           OperatorEnum=OperatorEnum.Equal
                     }
                };
                var flag = orderRepository.Update(keyValues, wheres);
                if (flag)
                {
                    changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                    {
                        Id = 0,
                        Type = 2,
                        CreateBy = userInfo.Id,
                        CreateTime = DateTime.Now,
                        Group_Id = userInfo.Group_Id,
                        LogContent = "修改提成，由【" + orderModel.CommissionMoney + "】修改为【" + commissionMoney + "】",
                        School_Id = userInfo.School_Id,
                        SourceId = orderId
                    });
                }
                return flag;
            }
            else
            {
                if (orderModel.ExtraRewardMoney != extraRewardMoney || orderModel.ExtraDeductMoney != extraDeductMoney)
                {
                    Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                        { nameof(RB_Order_ViewModel.ExtraRewardMoney),extraRewardMoney},
                        { nameof(RB_Order_ViewModel.ExtraDeductMoney),extraDeductMoney}
                    };
                    List<WhereHelper> wheres = new List<WhereHelper>() {
                         new WhereHelper(){
                             FiledName=nameof(RB_Order_ViewModel.OrderId),
                              FiledValue=orderId,
                               OperatorEnum=OperatorEnum.Equal
                         }
                    };
                    var flag = orderRepository.Update(keyValues, wheres);
                    if (flag)
                    {
                        string LogContent = "修改额外金额";
                        if (orderModel.ExtraRewardMoney != extraRewardMoney)
                        {
                            LogContent += "，额外奖励由【" + orderModel.ExtraRewardMoney + "】修改为【" + extraRewardMoney + "】";
                        }
                        if (orderModel.ExtraDeductMoney != extraDeductMoney)
                        {
                            LogContent += "，额外扣除由【" + orderModel.ExtraDeductMoney + "】修改为【" + extraDeductMoney + "】";
                        }
                        changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                        {
                            Id = 0,
                            Type = 2,
                            CreateBy = userInfo.Id,
                            CreateTime = DateTime.Now,
                            Group_Id = userInfo.Group_Id,
                            LogContent = LogContent,
                            School_Id = userInfo.School_Id,
                            SourceId = orderId
                        });
                    }
                    return flag;
                }
                else
                {
                    return true;
                }
            }
        }

        /// <summary>
        /// 订单转班
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="classId"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public string SetClassOrderCareOfClass(int orderId, int classId, UserInfo userInfo)
        {
            var orderModel = orderRepository.GetEntity(orderId);
            if (orderModel == null) { return "订单不存在"; }
            if (orderModel.OrderState == OrderStateEnum.Cancel) { return "订单状态不正确"; }
            if (orderModel.ClassId == classId) { return "转入班级不正确"; }
            var classModel = classRepository.GetEntity(classId);
            if (classModel == null) { return "班级不存在"; }
            //获取该班级下订单人数
            int BNum = orderRepository.GetClassOrderPeopleNumRepository(classId.ToString()).FirstOrDefault()?.GuestNum ?? 0;
            if (BNum + orderModel.GuestNum > classModel.ClassPersion)
            {
                return "转入班级剩余招收人数不足，请核实后再试";
            }

            Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                { nameof(RB_Order_ViewModel.ClassId),classId}
            };
            List<WhereHelper> wheres = new List<WhereHelper>() {
                new WhereHelper(){
                     FiledName=nameof(RB_Order_ViewModel.OrderId),
                      FiledValue=orderId,
                       OperatorEnum=OperatorEnum.Equal
                }
            };
            bool flag = orderRepository.Update(keyValues, wheres);
            if (flag)
            {
                //查询所有的学生名单
                var glist = order_GuestRepository.GetOrderGuestListRepository(new RB_Order_Guest_ViewModel() { OrderId = orderId });
                foreach (var item in glist)
                {
                    Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
                        { nameof(RB_Order_Guest_ViewModel.ClassId),classId}
                    };
                    List<WhereHelper> wheres1 = new List<WhereHelper>() {
                        new WhereHelper(){
                             FiledName=nameof(RB_Order_Guest_ViewModel.Id),
                              FiledValue=item.Id,
                               OperatorEnum=OperatorEnum.Equal
                        }
                    };
                    order_GuestRepository.Update(keyValues1, wheres1);
                }
                //记录日志
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    LogContent = $"订单转班，由【{orderModel.ClassId}】转移至【{classId}】",
                    School_Id = userInfo.School_Id,
                    SourceId = orderId
                });
                return "";
            }
            else
            {
                return "出错了，请联系管理员";
            }
        }

        /// <summary>
        /// 设置订单应收金额
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="preferPrice"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool SetOrderPreferPrice(int orderId, decimal preferPrice, UserInfo userInfo)
        {
            var orderModel = orderRepository.GetEntity(orderId);
            if (orderModel == null) { return false; }
            Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                { nameof(RB_Order_ViewModel.PreferPrice),preferPrice}
            };
            if (orderModel.PreferPrice != preferPrice)
            {
                keyValues.Add(nameof(RB_Order_ViewModel.IsCommissionGiveOK), 0);
            }
            List<WhereHelper> wheres = new List<WhereHelper>() {
                    new WhereHelper(){
                        FiledName=nameof(RB_Order_ViewModel.OrderId),
                        FiledValue=orderId,
                        OperatorEnum=OperatorEnum.Equal
                    }
            };
            var flag = orderRepository.Update(keyValues, wheres);
            if (flag)
            {
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    LogContent = "修改订单应收总额，由【" + orderModel.PreferPrice + "】修改为【" + preferPrice + "】",
                    School_Id = userInfo.School_Id,
                    SourceId = orderId
                });
            }
            return flag;
        }

        /// <summary>
        /// 获取班级订单列表
        /// </summary>
        /// <param name="classId"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public List<RB_Order_ViewModel> GetClassOrderList_V2(int classId, int groupId, int SourceId)
        {
            //获取订单列表
            var orderList = orderRepository.GetOrderListRepository(new RB_Order_ViewModel() { Group_Id = groupId, ClassId = classId, SourceId = SourceId });
            return orderList;
        }

        #endregion

        #region 学生名单
        /// <summary>
        /// 获取学生名单列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        public List<RB_Order_Guest_ViewModel> GetOrderGuestPageModule(int pageIndex, int pageSize, out long count, RB_Order_Guest_ViewModel dmodel)
        {
            var list = order_GuestRepository.GetOrderGuestPageRepository(pageIndex, pageSize, out count, dmodel);
            return list;
        }

        /// <summary>
        /// 新增修改 学生
        /// </summary>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        [TransactionCallHandler]
        public virtual bool SetOrderGuestInfo(RB_Order_Guest_ViewModel dmodel, out string message)
        {
            bool flag = false;
            if (dmodel.BirthDate != null)
            {
                dmodel.Age = Common.ConvertHelper.GetAgeByBirthdate(dmodel.BirthDate);
            }
            message = "";
            if (dmodel.Id > 0)
            {
                var gModel = order_GuestRepository.GetEntity(dmodel.Id);
                string LogContent = "修改学生名单【" + dmodel.Id + "】";
                if (gModel.Age != dmodel.Age)
                {
                    LogContent += "，年龄由【" + gModel.Age + "】修改为【" + dmodel.Age + "】";
                }
                gModel.Age = dmodel.Age;

                if (gModel.Basics != dmodel.Basics)
                {
                    LogContent += "，日语基础由【" + gModel.Basics + "】修改为【" + dmodel.Basics + "】";
                }
                gModel.Basics = dmodel.Basics;

                if (gModel.Contact != dmodel.Contact)
                {
                    LogContent += "，紧急联系人由【" + gModel.Contact + "】修改为【" + dmodel.Contact + "】";
                }
                gModel.Contact = dmodel.Contact;

                if (gModel.ContactMobile != dmodel.ContactMobile)
                {
                    LogContent += "，紧急联系电话由【" + gModel.ContactMobile + "】修改为【" + dmodel.ContactMobile + "】";
                }
                gModel.ContactMobile = dmodel.ContactMobile;

                if (gModel.Education != dmodel.Education)
                {
                    LogContent += "，学历由【" + gModel.Education.ToName() + "】修改为【" + dmodel.Education.ToName() + "】";
                }
                gModel.Education = dmodel.Education;

                if (gModel.GuestName != dmodel.GuestName)
                {
                    LogContent += "，客人名称由【" + gModel.GuestName + "】修改为【" + dmodel.GuestName + "】";
                }
                gModel.GuestName = dmodel.GuestName;

                if (gModel.GuestSource != dmodel.GuestSource)
                {
                    LogContent += "，客人来源由【" + gModel.GuestSource.ToName() + "】修改为【" + dmodel.GuestSource.ToName() + "】";
                }
                gModel.GuestSource = dmodel.GuestSource;

                if (gModel.LearningGoals != dmodel.LearningGoals)
                {
                    LogContent += "，学习目的由【" + gModel.LearningGoals.ToName() + "】修改为【" + dmodel.LearningGoals.ToName() + "】";
                }
                gModel.LearningGoals = dmodel.LearningGoals;

                if (gModel.Mobile != dmodel.Mobile)
                {
                    LogContent += "，手机号码由【" + gModel.Mobile + "】修改为【" + dmodel.Mobile + "】";
                }
                gModel.Mobile = dmodel.Mobile;

                if (gModel.Profession != dmodel.Profession)
                {
                    LogContent += "，职业由【" + gModel.Profession + "】修改为【" + dmodel.Profession + "】";
                }
                gModel.Profession = dmodel.Profession;

                if (gModel.Sex != dmodel.Sex)
                {
                    LogContent += "，性别由【" + gModel.Sex + "】修改为【" + dmodel.Sex + "】";
                }
                gModel.Sex = dmodel.Sex;

                if (gModel.IDCard != dmodel.IDCard)
                {
                    LogContent += "，身份证由【" + gModel.IDCard + "】修改为【" + dmodel.IDCard + "】";
                }
                gModel.IDCard = dmodel.IDCard;

                if (gModel.Domicile != dmodel.Domicile)
                {
                    LogContent += "，身份证居住地由【" + gModel.Domicile + "】修改为【" + dmodel.Domicile + "】";
                }
                gModel.Domicile = dmodel.Domicile;

                if (gModel.ContactAddress != dmodel.ContactAddress)
                {
                    LogContent += "，联系地址由【" + gModel.ContactAddress + "】修改为【" + dmodel.ContactAddress + "】";
                }
                gModel.ContactAddress = dmodel.ContactAddress;

                if (gModel.GraduatedSchool != dmodel.GraduatedSchool)
                {
                    LogContent += "，毕业院校由【" + gModel.GraduatedSchool + "】修改为【" + dmodel.GraduatedSchool + "】";
                }
                gModel.GraduatedSchool = dmodel.GraduatedSchool;

                if (gModel.GraduatedMajor != dmodel.GraduatedMajor)
                {
                    LogContent += "，毕业专业由【" + gModel.GraduatedMajor + "】修改为【" + dmodel.GraduatedMajor + "】";
                }
                gModel.GraduatedMajor = dmodel.GraduatedMajor;

                if (gModel.VolunteerMajor != dmodel.VolunteerMajor)
                {
                    LogContent += "，志愿专业由【" + gModel.VolunteerMajor + "】修改为【" + dmodel.VolunteerMajor + "】";
                }
                gModel.VolunteerMajor = dmodel.VolunteerMajor;

                if (gModel.Price != dmodel.Price)
                {
                    LogContent += "，价格由【" + gModel.Price + "】修改为【" + dmodel.Price + "】";
                }
                gModel.Price = dmodel.Price;

                if (gModel.StudyRemark != dmodel.StudyRemark)
                {
                    LogContent += "，备注由【" + gModel.StudyRemark + "】修改为【" + dmodel.StudyRemark + "】";
                }
                gModel.StudyRemark = dmodel.StudyRemark;

                if (gModel.BirthDate != dmodel.BirthDate)
                {
                    LogContent += "，出身日期由【" + gModel.BirthDate + "】修改为【" + dmodel.BirthDate + "】";
                }
                gModel.BirthDate = dmodel.BirthDate;
                if (gModel.TotalHours != dmodel.TotalHours)
                {
                    LogContent += "，总课时由【" + gModel.TotalHours + "】修改为【" + dmodel.TotalHours + "】";
                }

                if (gModel.StuIcon != dmodel.StuIcon)
                {
                    LogContent += "，学生头像由【" + gModel.StuIcon + "】修改为【" + dmodel.StuIcon + "】";
                }
                gModel.StuIcon = dmodel.StuIcon;

                gModel.TotalHours = dmodel.TotalHours;

                gModel.UpdateTime = dmodel.UpdateTime;
                flag = order_GuestRepository.Update(gModel);
                if (flag)
                {
                    //记录日志
                    changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                    {
                        Id = 0,
                        Type = 2,
                        CreateBy = dmodel.CreateBy,
                        CreateTime = DateTime.Now,
                        Group_Id = dmodel.Group_Id,
                        LogContent = LogContent,
                        School_Id = dmodel.School_Id,
                        SourceId = gModel.OrderId
                    });

                    if (!string.IsNullOrWhiteSpace(dmodel.StuIcon))//更新学生表中的头像
                    {
                        var orderGuestModel = student_OrderGuestRepository.GetStrOrderGuestListRepository(new RB_Student_OrderGuest_ViewModel { ClassId = gModel.ClassId, OrderId = gModel.OrderId, GuestId = gModel.Id }).FirstOrDefault();
                        if (orderGuestModel != null && orderGuestModel.Student_Id > 0)
                        {
                            Dictionary<string, object> fileds = new Dictionary<string, object>()
                            {
                                {nameof(RB_Student_ViewModel.StuIcon),dmodel.StuIcon},
                            };
                            studentRepository.Update(fileds, new WhereHelper(nameof(RB_Student_ViewModel.StuId), orderGuestModel.Student_Id));
                        }
                    }
                }
            }
            else
            {
                var ordermodel = orderRepository.GetEntity(dmodel.OrderId);
                if (ordermodel == null)
                {
                    message = "订单不存在";
                    return flag;
                }
                dmodel.ClassId = ordermodel.ClassId;
                dmodel.SourceId = ordermodel.SourceId;
                int GuestNum = order_GuestRepository.GetOrderGuestNumRepository(new RB_Order_Guest_ViewModel() { OrderId = dmodel.OrderId, GuestState = 1 });
                if (GuestNum >= ordermodel.GuestNum)
                {
                    message = "学生名单已录入完毕";
                    return flag;
                }
                int Id = order_GuestRepository.Insert(dmodel);
                flag = Id > 0;
                if (flag)
                {
                    var classmodel = classRepository.GetEntity(ordermodel.ClassId);
                    //验证账号是否存在
                    var accmodel = accountRepository.GetAccountListRepository(new RB_Account_ViewModel() { Group_Id = dmodel.Group_Id, AccountType = Common.Enum.User.AccountTypeEnum.Student, Account = dmodel.Mobile }).FirstOrDefault();
                    string LogContent = "新增学生名单【" + Id + "】";
                    if (dmodel.ClassId > 0)
                    {
                        if (accmodel != null)
                        {
                            student_OrderGuestRepository.Insert(new Model.Entity.User.RB_Student_OrderGuest()
                            {
                                Id = 0,
                                Account_Id = accmodel.Id,
                                ClassId = ordermodel.ClassId,
                                CreateBy = dmodel.CreateBy,
                                CreateTime = DateTime.Now,
                                GuestId = Id,
                                OrderId = dmodel.OrderId,
                                Status = DateStateEnum.Normal,
                                Student_Id = accmodel.AccountId
                            });
                            LogContent += ",添加学生账号关联【" + accmodel.Id + "】";
                        }
                        else
                        {
                            //创建学生账号
                            int StudentId = studentRepository.Insert(new Model.Entity.User.RB_Student()
                            {
                                StuId = 0,
                                AreaId = 0,
                                CityId = 0,
                                CreateBy = dmodel.CreateBy,
                                CreateTime = DateTime.Now,
                                Group_Id = dmodel.Group_Id,
                                IsDisable = 1,
                                ProviceId = 0,
                                School_Id = classmodel.School_Id,
                                Status = DateStateEnum.Normal,
                                StuBirth = dmodel.BirthDate,
                                StuIcon = dmodel.StuIcon,
                                StuName = dmodel.GuestName,
                                StuSex = dmodel.Sex - 1,
                                StuTel = dmodel.Mobile,
                                UpdateBy = dmodel.CreateBy,
                                UpdateTime = DateTime.Now,

                            });
                            int AccountId = accountRepository.Insert(new Model.Entity.User.RB_Account()
                            {
                                Id = 0,
                                Account = dmodel.Mobile,
                                AccountId = StudentId,
                                AccountType = Common.Enum.User.AccountTypeEnum.Student,
                                AnnualLeaveDay = 0,
                                CreateBy = dmodel.CreateBy,
                                CreateTime = DateTime.Now,
                                Group_Id = dmodel.Group_Id,
                                School_Id = classmodel.School_Id,
                                Status = DateStateEnum.Normal,
                                UpdateBy = dmodel.UpdateBy,
                                UpdateTime = DateTime.Now,
                                Password = Common.DES.Encrypt(Common.Config.DefaultPwd)
                            });
                            student_OrderGuestRepository.Insert(new Model.Entity.User.RB_Student_OrderGuest()
                            {
                                Id = 0,
                                Account_Id = AccountId,
                                ClassId = ordermodel.ClassId,
                                CreateBy = dmodel.CreateBy,
                                CreateTime = DateTime.Now,
                                GuestId = Id,
                                OrderId = dmodel.OrderId,
                                Status = DateStateEnum.Normal,
                                Student_Id = StudentId
                            });
                            LogContent += ",自动创建学生账号【" + AccountId + "】";
                        }
                    }
                    changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                    {
                        Id = 0,
                        Type = 2,
                        CreateBy = dmodel.CreateBy,
                        CreateTime = DateTime.Now,
                        Group_Id = dmodel.Group_Id,
                        LogContent = LogContent,
                        School_Id = dmodel.School_Id,
                        SourceId = dmodel.OrderId,
                    });
                }
            }
            return flag;
        }

        /// <summary>
        /// 删除学生名单
        /// </summary>
        /// <param name="guestId"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool DelOrderGuestInfo(int guestId, UserInfo userInfo)
        {
            Dictionary<string, object> keyValues = new Dictionary<string, object>() {
                { nameof(RB_Order_Guest_ViewModel.Status),1}
            };
            List<WhereHelper> wheres = new List<WhereHelper>() {
                new WhereHelper(){
                     FiledName=nameof(RB_Order_Guest_ViewModel.Id),
                      FiledValue=guestId,
                       OperatorEnum=OperatorEnum.Equal
                }
            };
            bool flag = order_GuestRepository.Update(keyValues, wheres);
            if (flag)
            {
                var gmodel = order_GuestRepository.GetEntity(guestId);
                //查询学生账号
                //var sModel = student_OrderGuestRepository.GetStrOrderGuestListRepository(new RB_Student_OrderGuest_ViewModel() { OrderId = gmodel?.OrderId ?? 0, GuestId = guestId }).FirstOrDefault();
                //if (sModel != null) {
                //    //更新账号表 
                //    Dictionary<string, object> valuePairs = new Dictionary<string, object>() {
                //        { nameof(RB_Account_ViewModel.Status),DateStateEnum.Delete}
                //    };
                //    List<WhereHelper> wheres1 = new List<WhereHelper>() {
                //        new WhereHelper(){
                //             FiledName=nameof(RB_Account_ViewModel.Id),
                //              FiledValue=sModel.Account_Id,
                //               OperatorEnum=OperatorEnum.Equal
                //        }
                //    };
                //    accountRepository.Update(valuePairs, wheres1);
                //}
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    LogContent = "删除学生名单【" + guestId + "】",
                    School_Id = userInfo.Id,
                    SourceId = gmodel?.OrderId ?? 0
                });
            }
            return flag;
        }

        #endregion

        #region 销售中心

        /// <summary>
        /// 获取我的订单列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Order_ViewModel> GetMyOrderPageList(int pageIndex, int pageSize, out long count, RB_Order_ViewModel demodel)
        {
            return OrderPageModule(pageIndex, pageSize, out count, demodel);
        }

        /// <summary>
        /// 获取订单分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        private List<RB_Order_ViewModel> OrderPageModule(int pageIndex, int pageSize, out long count, RB_Order_ViewModel demodel)
        {
            //获取订单列表
            var orderList = orderRepository.GetOrderPageRepository(pageIndex, pageSize, out count, demodel);
            if (orderList.Any())
            {
                string orderIds = string.Join(",", orderList.Select(x => x.OrderId));
                //获取备注列表
                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() { Group_Id = demodel.Group_Id, OrderIds = orderIds, Status = -1 }).Where(x => x.Status != 4).ToList();
                foreach (var item in orderList)
                {
                    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;
                        }
                    }
                }
            }
            return orderList;
        }

        /// <summary>
        /// 获取留学就业订单分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Order_ViewModel> GetStudyOrderPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Order_ViewModel demodel)
        {
            //获取订单列表
            var orderList = orderRepository.GetStudyOrderPageListRepository(pageIndex, pageSize, out rowsCount, demodel);
            if (orderList.Any())
            {
                string orderIds = string.Join(",", orderList.Select(x => x.OrderId));
                //获取备注列表
                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() { Group_Id = demodel.Group_Id, OrderIds = orderIds, Status = -1 }).Where(x => x.Status != 4).ToList();
                foreach (var item in orderList)
                {
                    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();
                    var ZList = item.GuestList.Where(x => !item.ContractList.Select(z => z.GuestId).Contains(x.Id)).ToList();
                    if (ZList.Any() && item.ContractList.Any())
                    {
                        foreach (var qitem in ZList)
                        {
                            item.ContractList.Add(new RB_Education_Contract_ViewModel()
                            {
                                Id = 0,
                                StudentName = qitem.GuestName,
                                ContractNo = "",
                                GuestId = qitem.Id,
                                Status = 0
                            });
                        }
                    }
                }
            }
            return orderList;
        }

        /// <summary>
        /// 获取我的留学就业订单统计
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public RB_Order_ViewModel GetStudyOrderStatisticsModule(RB_Order_ViewModel demodel)
        {
            return orderRepository.GetStudyOrderStatisticsRepository(demodel);
        }

        /// <summary>
        /// 获取我的订单统计
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public RB_Order_ViewModel GetMyOrderStatisticsModule(RB_Order_ViewModel demodel)
        {
            return orderRepository.GetMyOrderStatisticsRepository(demodel);
        }
        #endregion

        #region 订单操作
        /// <summary>
        /// 财务 更新订单实收，退款
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="income"></param>
        /// <param name="platformTax"></param>
        /// <param name="refund"></param>
        /// <param name="empModel"></param>
        /// <returns></returns>
        public bool UpdateEduOrderIncome(int orderId, decimal income, decimal platformTax, decimal refund, Employee_ViewModel empModel)
        {
            var orderModel = orderRepository.GetEntity(orderId);
            if (orderModel == null) { return false; }
            if (orderModel.Income == income && orderModel.Refund == refund) { return true; }
            Dictionary<string, object> keyValues = new Dictionary<string, object>() { };
            string LogContent;
            if (income >= 0)
            {
                keyValues.Add(nameof(RB_Order_ViewModel.Income), income);
                keyValues.Add(nameof(RB_Order_ViewModel.PlatformTax), platformTax);
                LogContent = $"，更新订单实收【{income}】平台税金【{platformTax}】";
            }
            else if (refund >= 0)
            {
                keyValues.Add(nameof(RB_Order_ViewModel.Refund), refund);
                LogContent = $"，更新退款【{refund}】";
            }
            else { return false; }
            List<WhereHelper> wheres = new List<WhereHelper>() {
                new WhereHelper(){
                     FiledName=nameof(RB_Order_ViewModel.OrderId),
                      FiledValue=orderId,
                       OperatorEnum=OperatorEnum.Equal
                }
            };
            bool flag = orderRepository.Update(keyValues, wheres);
            if (flag)
            {
                //写入日志
                changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
                {
                    Id = 0,
                    Type = 2,
                    CreateBy = empModel.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = empModel.Group_Id,
                    LogContent = $"【{empModel.EmployeeName}({empModel.Id})】单据审核通过{LogContent}",
                    School_Id = empModel.School_Id,
                    SourceId = orderId
                });
            }
            return flag;
        }
        #endregion

        #region 财务统计

        /// <summary>
        /// 获取订单完成情况一览分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        public List<RB_Education_Contract_ViewModel> GetOrderStudentClassHoursPageList(int pageIndex, int pageSize, out long count, RB_Education_Contract_ViewModel dmodel)
        {
            string datebaseStr = Config.ReadConfigKey("FinanceDateBase");//财务数据库
            var list = education_ContractRepository.GetContractPageListForFinance(pageIndex, pageSize, out count, dmodel, datebaseStr);
            if (list.Any())
            {
                string orderIds = string.Join(",", list.Select(x => x.OrderId).Distinct());
                string guestIds = string.Join(",", list.Select(x => x.GuestId).Distinct());
                //查询所有的财务单据
                var flist = financeRepository.GetListSingle(new Model.ViewModel.Finance.RB_Finance_Extend() { RB_Group_Id = dmodel.Group_Id, FinanceType = 2, IsSelectNormal = 1, OrderIdStr = orderIds, GuestIdStr = guestIds });
                if (flist.Any())
                {
                    string frIds = string.Join(",", flist.Select(x => x.FrID));
                    //查询单据明细
                    var fdlist = financeDetailRepository.GetList(new Model.ViewModel.Finance.RB_FinanceDetail_Extend() { GroupId = dmodel.Group_Id, FrIds = frIds });
                    //查询单据交易账户
                    var TradeList = tradeWayRepository.GetList(new Model.ViewModel.Finance.RB_TradeWay_Extend() { FrIdStr = frIds });
                    //获取币种列表
                    var CurrencyList = currencyRepository.GetList(new Model.Entity.Finance.RB_Currency() { RB_Group_Id = dmodel.Group_Id });
                    //查询四大账户
                    var BankList = new List<Model.ViewModel.Finance.RB_BackAccount_Extend>();
                    if (TradeList.Where(x => x.Type == Common.Enum.Finance.BranchAccountEnum.Bank).Any())
                    {
                        BankList = backAccountRepository.GetList(new Model.ViewModel.Finance.RB_BackAccount_Extend() { AccountIdStr = string.Join(",", TradeList.Where(x => x.Type == Common.Enum.Finance.BranchAccountEnum.Bank).Select(x => x.AccountId ?? 0).Distinct()) });
                    }
                    var CashPoolList = new List<Model.ViewModel.Finance.RB_CashPoolAccount_Extend>();
                    if (TradeList.Where(x => x.Type == Common.Enum.Finance.BranchAccountEnum.CashPool).Any())
                    {
                        CashPoolList = cashPoolAccountRepository.GetList(new Model.ViewModel.Finance.RB_CashPoolAccount_Extend() { AccountIdStr = string.Join(",", TradeList.Where(x => x.Type == Common.Enum.Finance.BranchAccountEnum.CashPool).Select(x => x.AccountId ?? 0).Distinct()) });
                    }
                    var PlatformList = new List<Model.ViewModel.Finance.RB_PlatformAccount_Extend>();
                    if (TradeList.Where(x => x.Type == Common.Enum.Finance.BranchAccountEnum.Platform).Any())
                    {
                        PlatformList = platformAccountRepository.GetList(new Model.ViewModel.Finance.RB_PlatformAccount_Extend() { AccountIdStr = string.Join(",", TradeList.Where(x => x.Type == Common.Enum.Finance.BranchAccountEnum.Platform).Select(x => x.AccountId ?? 0).Distinct()) });
                    }
                    List<Model.ViewModel.Finance.RB_TradeWay_Extend> tlist = new List<Model.ViewModel.Finance.RB_TradeWay_Extend>();
                    foreach (var TradeModel in TradeList)
                    {
                        Model.ViewModel.Finance.RB_TradeWay_Extend accountInFo = TradeModel.RefMapperTo<Model.ViewModel.Finance.RB_TradeWay_Extend>();
                        accountInFo.CurrencyName = CurrencyList.Where(x => x.ID == TradeModel.CurrencyId).FirstOrDefault()?.Name ?? "";
                        if (TradeModel.Type == Common.Enum.Finance.BranchAccountEnum.Bank)
                        {
                            var bank = BankList.Where(x => x.ID == TradeModel.AccountId).FirstOrDefault();
                            if (bank != null)
                            {
                                accountInFo.Alias = bank.Alias;
                                accountInFo.BankNo = bank.BackNo;
                                accountInFo.Type = Common.Enum.Finance.BranchAccountEnum.Bank;
                                accountInFo.AccountTypeId = bank.TypeId;
                            }
                        }
                        else if (TradeModel.Type == Common.Enum.Finance.BranchAccountEnum.CashPool)
                        {
                            var pool = CashPoolList.Where(x => x.ID == TradeModel.AccountId).FirstOrDefault();
                            if (pool != null)
                            {
                                accountInFo.Alias = pool.Alias;
                                accountInFo.BankNo = "";
                                accountInFo.Type = Common.Enum.Finance.BranchAccountEnum.CashPool;
                                accountInFo.AccountTypeId = pool.TypeId;
                            }
                        }
                        else if (TradeModel.Type == Common.Enum.Finance.BranchAccountEnum.Platform)
                        {
                            var platform = PlatformList.Where(x => x.ID == TradeModel.AccountId).FirstOrDefault();
                            if (platform != null)
                            {
                                accountInFo.Alias = platform.Alias;
                                accountInFo.BankNo = platform.PlatformNo;
                                accountInFo.Type = Common.Enum.Finance.BranchAccountEnum.Platform;
                                accountInFo.AccountTypeId = platform.TypeId;
                            }
                        }
                        tlist.Add(accountInFo);
                    }
                    foreach (var item in flist)
                    {
                        item.detailList = fdlist.Where(x => x.FinanceId == item.FrID).ToList();
                        item.BankList = tlist.Where(x => x.FinanceId == item.FrID).ToList();
                    }
                }
                //查询所有学生的已上课时间
                var stuTimeList = class_CheckRepository.GetClassGuestStudentTimeList(dmodel.Group_Id, guestIds, dmodel.XFStartTime, dmodel.XFEndTime);
                //查询基础课时时长
                //var configModel = class_ConfigRepository.GetClassConfigRepository(new RB_Class_Config_ViewModel() { Group_Id = dmodel.Group_Id });
                //用户信息
                var userIds = string.Join(",", list.Select(x => x.CreateBy).Distinct());
                var alist = accountRepository.GetAccountListExtRepository(new Model.ViewModel.User.RB_Account_ViewModel() { QIds = userIds });
                foreach (var item in list)
                {
                    #region 财务单据
                    item.FinanceList = flist.Where(x => x.GuestId == item.GuestId).ToList();
                    item.Income = item.FinanceList.Where(x => x.Type == Common.Enum.Finance.WFTempLateClassEnum.IN && x.Is_Cashier == 1).Sum(x => (x.Money ?? 0) + (x.Fee ?? 0));//出纳审核算有效金额
                    item.Expend = item.FinanceList.Where(x => x.Type == Common.Enum.Finance.WFTempLateClassEnum.OUT).Sum(x => (x.Money ?? 0) + (x.Fee ?? 0));//制单就算
                    #endregion
                    var stuModel = stuTimeList.Where(x => x.OrderGuestId == item.GuestId).FirstOrDefault();
                    //if (configModel == null || configModel.BasicMinutes <= 0)
                    //{
                    //    item.UseClassHours = 0;
                    //}
                    //else
                    //{
                    //    item.UseClassHours = (int)Math.Ceiling(Convert.ToDecimal(stuModel?.MinutesNum ?? 0) / configModel.BasicMinutes);// 已上课时   （暂时向上取整）
                    //}
                    item.UseClassHours = Convert.ToInt32(stuModel?.CurrentDeductionHours ?? 0);
                    item.Unit_Price = 0;
                    item.UseCourseFee = 0;
                    if (item.TotalClassHours > 0)
                    {
                        if (item.TotalDiscountMoney > 0)
                        {
                            item.Unit_Price = Math.Round((item.TotalCourseFee - (item.TotalDiscountMoney / item.TotalSub) * item.TotalCourseFee) / item.TotalClassHours, 6, MidpointRounding.AwayFromZero);//根据合同计算(包含优惠， 需减去课件费等)
                            item.UseCourseFee = Math.Round((Convert.ToDecimal(item.UseClassHours) / item.TotalClassHours) * (item.TotalCourseFee - (item.TotalDiscountMoney / item.TotalSub) * item.TotalCourseFee), 6, MidpointRounding.AwayFromZero);
                        }
                        else
                        {
                            item.Unit_Price = Math.Round(item.TotalCourseFee / item.TotalClassHours, 6, MidpointRounding.AwayFromZero);//根据合同计算(包含优惠， 需减去课件费等)
                            item.UseCourseFee = Math.Round((Convert.ToDecimal(item.UseClassHours) / item.TotalClassHours) * item.TotalCourseFee, 6, MidpointRounding.AwayFromZero);
                        }
                    }
                    item.UseBookFee = item.TotalBookFee;
                    item.UseCoursewareFee = item.TotalClassFee;
                    if (item.TotalDiscountMoney > 0)
                    {
                        item.UseBookFee = Math.Round(item.TotalBookFee - (item.TotalDiscountMoney / item.TotalSub) * item.TotalBookFee, 6, MidpointRounding.AwayFromZero);//(优惠比例)
                        item.UseCoursewareFee = Math.Round(item.TotalClassFee - (item.TotalDiscountMoney / item.TotalSub) * item.TotalClassFee, 6, MidpointRounding.AwayFromZero);//(优惠比例)
                    }
                    //用户信息
                    var amodel = alist.Where(x => x.Id == item.CreateBy).FirstOrDefault();
                    item.CreateByName = amodel?.AccountName ?? "";
                    item.CreateByPhoto = amodel?.UserIcon ?? "";
                }
            }
            return list;
        }

        /// <summary>
        /// 新增修改合同协调
        /// </summary>
        /// <param name="dmodel"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool SetContractAdjustPrice(RB_Education_ContractAdjust_ViewModel dmodel, UserInfo userInfo)
        {
            var list = education_ContractAdjustRepository.GetList(new RB_Education_ContractAdjust_ViewModel() { Group_Id = userInfo.Group_Id, ContractId = dmodel.ContractId });
            if (list.Any())
            {
                var model = list.FirstOrDefault();
                Dictionary<string, object> keyValues = new Dictionary<string, object>()
                {
                    { nameof(RB_Education_ContractAdjust_ViewModel.AdjustPrice),dmodel.AdjustPrice},
                    { nameof(RB_Education_ContractAdjust_ViewModel.UpdateBy),userInfo.Id},
                    { nameof(RB_Education_ContractAdjust_ViewModel.UpdateTime),DateTime.Now},
                };
                List<WhereHelper> wheres = new List<WhereHelper>()
                {
                    new WhereHelper()
                    {
                         FiledName=nameof(RB_Education_ContractAdjust_ViewModel.Id),
                         FiledValue= model.Id,
                         OperatorEnum=OperatorEnum.Equal
                    }
                };
                return education_ContractAdjustRepository.Update(keyValues, wheres);
            }
            else
            {
                return education_ContractAdjustRepository.Insert(new Model.Entity.Course.RB_Education_ContractAdjust()
                {
                    Id = 0,
                    ContractId = dmodel.ContractId,
                    AdjustPrice = dmodel.AdjustPrice,
                    CreateBy = userInfo.Id,
                    CreateTime = DateTime.Now,
                    Group_Id = userInfo.Group_Id,
                    UpdateBy = userInfo.Id,
                    UpdateTime = DateTime.Now
                }) > 0;
            }
        }
        #endregion


        #region 个人中心
        /// <summary>
        /// 获取我的未完成的订单
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Order_ViewModel> GetOrderNoComplete(RB_Order_ViewModel demodel)
        {
            return orderRepository.GetOrderNoComplete(demodel);
        }


        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <param name="orderIds"></param>
        /// <returns></returns>
        public List<RB_Order_Guest_ViewModel> GetOrderGuestListByEnterID(RB_Order_Guest_ViewModel demodel)
        {
            return order_GuestRepository.GetOrderGuestListByEnterID(demodel);
        }
        #endregion
    }
}