using System;
using System.Collections.Generic;
using System.Linq;
using Edu.Cache.User;
using Edu.Common.API;
using Edu.Common.Enum.Course;
using Edu.Common.Enum.Sale;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.Log;
using Edu.Module.Course;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;

namespace Edu.WebApi.Controllers.Course
{
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class OrderController : BaseController
    {
        /// <summary>
        /// 订单处理类对象
        /// </summary>
        private readonly OrderModule orderModule = AOP.AOPHelper.CreateAOPObject<OrderModule>();

        #region 产品管理

        /// <summary>
        /// 获取日语培训列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetClassPruductList() {
            var userInfo = base.UserInfo;
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var dmodel = JsonHelper.DeserializeObject<RB_Class_ViewModel>(RequestParm.Msg.ToString());
            dmodel.Group_Id = userInfo.Group_Id;

            var list = orderModule.GetClassPruductList(pageModel.PageIndex, pageModel.PageSize, out long count, dmodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = list.Select(x => new
            {
                x.ClassId,
                x.ClassName,
                x.CourseName,
                x.ClassHours,
                x.TeacherName,
                x.TeacherHead,
                x.RoomName,
                x.ClassStyle,
                ClassStyleName = x.ClassStyle.ToName(),
                OpenTime = x.OpenTime.ToString("yyyy年MM月dd日"),
                EndOrderTime = x.EndOrderTime.HasValue ? x.EndOrderTime.Value.ToString("yyyy年MM月dd日") : "",
                IsCanApply = x.EndOrderTime >= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) && x.ClassPersion > x.OrderStudentCount ? 1 : 0,
                x.OriginalPrice,
                x.SellPrice,
                x.IsStepPrice,
                x.ClassPersion,
                x.OutRemark,
                x.OrderStudentCount,
                SurplusNum = x.ClassPersion - x.OrderStudentCount,
                ClassStepPriceList = x.ClassStepPriceList.Select(z => new
                {
                    z.ClassStepPriceId,
                    z.PersionNum,
                    z.PersionPrice
                }),
                ClassTimeList = x.ClassTimeList.Select(z => new
                {
                    z.StartTime,
                    z.EndTime
                }),
                ClassPlanList = x.ClassPlanList.Select(z => new
                {
                    z.WeekDay,
                    ClassDate = x.ClassStyle == Common.Enum.Course.ClassStyleEnum.FixedDate ? z.ClassDate.ToString("yyyy-MM-dd") : ""
                }),
                x.SchoolName,
                UpdateTime = x.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")
            });
            return ApiResult.Success("", pageModel);
        }

        /// <summary>
        /// 获取班级名称
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetClassNameList()
        {
            var userInfo = base.UserInfo;
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            string ClassIds = parms.GetStringValue("ClassIds");
            if (string.IsNullOrEmpty(ClassIds)) {
                return ApiResult.ParamIsNull("请传递班级ids");
            }

            var list = orderModule.GetClassNameList(ClassIds);
            return ApiResult.Success("", list.Select(x => new
            {
                x.ClassId,
                x.ClassName,
                x.School_Id
            }));
        }

        #endregion

        #region 订单管理

        /// <summary>
        /// 获取班级/留学就业订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetClassOrderList()
        {
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            var userInfo = base.UserInfo;
            int ClassId = parms.GetInt("ClassId", 0);
            int SourceId = parms.GetInt("SourceId", 0);
            if (ClassId <= 0 && SourceId <= 0)
            {
                return ApiResult.ParamIsNull();
            }
            var orderList = orderModule.GetClassOrderList(ClassId, userInfo.Group_Id, SourceId, out object ClassInfo);
            return ApiResult.Success("", new
            {
                ClassInfo,
                OrderList = new
                {
                    NorList = orderList.Where(x => x.OrderState != Common.Enum.Course.OrderStateEnum.Cancel).Select(x => new
                    {
                        x.OrderId,
                        x.ClassId,
                        x.ClassSchoolId,
                        x.TradeWay,
                        x.Class_Price,
                        x.Unit_Price,
                        x.GuestNum,
                        x.PreferPrice,
                        x.Income,
                        x.Refund,
                        x.DiscountMoney,
                        x.PlatformTax,
                        DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.PlatformTax + x.DiscountMoney),
                        x.OrderState,
                        OrderStateName = x.OrderState.ToName(),
                        x.EnterID,
                        EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                        x.CommissionMoney,
                        x.ExtraRewardMoney,
                        x.ExtraDeductMoney,
                        x.IsCommissionGive,
                        CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        x.SaleRemark,
                        x.TeacherRemark,
                        x.RectorRemark,
                        x.DirectorRemark,
                        x.OfferId,
                        SaleRemarkList = x.SaleRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = z.CreateByName,
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        TeacherRemarkList = x.TeacherRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = z.CreateByName,
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        RectorRemarkList = x.RectorRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = z.CreateByName,
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        DirectorRemarkList = x.DirectorRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = z.CreateByName,
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        GuestList = x.GuestList.Select(z => new
                        {
                            z.Id,
                            z.GuestName,
                            z.GuestState
                        }),
                        ContractList = x.ContractList.Select(z => new {
                            z.Id,
                            z.StudentName,
                            z.ContractNo,
                            z.GuestId,
                            z.Status
                        })
                    }),
                    CancelList = orderList.Where(x => x.OrderState == Common.Enum.Course.OrderStateEnum.Cancel).Select(x => new
                    {
                        x.OrderId,
                        x.ClassId,
                        x.TradeWay,
                        x.Class_Price,
                        x.Unit_Price,
                        x.GuestNum,
                        x.PreferPrice,
                        x.Income,
                        x.Refund,
                        x.DiscountMoney,
                        DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.DiscountMoney),
                        x.OrderState,
                        OrderStateName = x.OrderState.ToName(),
                        x.EnterID,
                        EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                        x.CommissionMoney,
                        x.ExtraRewardMoney,
                        x.ExtraDeductMoney,
                        x.IsCommissionGive,
                        CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        x.SaleRemark,
                        x.TeacherRemark,
                        x.RectorRemark,
                        x.DirectorRemark,
                        x.OfferId,
                        SaleRemarkList = x.SaleRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = UserReidsCache.GetUserLoginInfo(z.CreateBy)?.AccountName ?? "",
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        TeacherRemarkList = x.TeacherRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = UserReidsCache.GetUserLoginInfo(z.CreateBy)?.AccountName ?? "",
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        RectorRemarkList = x.RectorRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = UserReidsCache.GetUserLoginInfo(z.CreateBy)?.AccountName ?? "",
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        DirectorRemarkList = x.DirectorRemarkList.Select(z => new
                        {
                            z.Id,
                            z.Content,
                            CreateBy = UserReidsCache.GetUserLoginInfo(z.CreateBy)?.AccountName ?? "",
                            CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        }),
                        GuestList = x.GuestList.Select(z => new
                        {
                            z.Id,
                            z.GuestName,
                            z.GuestState
                        }),
                        ContractList = x.ContractList.Select(z => new {
                            z.Id,
                            z.StudentName,
                            z.ContractNo,
                            z.GuestId,
                            z.Status
                        })
                    })
                }
            });
        }

        /// <summary>
        /// 新增修改订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetClassOrder()
        {
            var userInfo = base.UserInfo;
            RB_Order_ViewModel demodel = new RB_Order_ViewModel()
            {
                OrderId=base.ParmJObj.GetInt("OrderId"),
                ClassId=base.ParmJObj.GetInt("ClassId"),
                GuestNum=base.ParmJObj.GetInt("GuestNum"),
                OrderSource=(OrderSourceEnum)base.ParmJObj.GetInt("OrderSource"),
                OrderType=(OrderTypeEnum)base.ParmJObj.GetInt("OrderType"),
                PreferPrice=base.ParmJObj.GetDecimal("PreferPrice"),
                SaleRemark=base.ParmJObj.GetStringValue("SaleRemark"),
                SourceId=base.ParmJObj.GetInt("SourceId"),
                Unit_Price=base.ParmJObj.GetDecimal("Unit_Price"),
            };
            if (demodel.OrderType== OrderTypeEnum.CourseOrder &&demodel.ClassId <= 0)
            {
                return ApiResult.ParamIsNull("请传递班级id");
            }
            if (demodel.GuestNum <= 0)
            {
                return ApiResult.ParamIsNull("请传递报名人数");
            }
            if (demodel.Unit_Price <= 0)
            {
                return ApiResult.ParamIsNull("成交单价不能小于0");
            }
            if (demodel.OrderSource <= 0)
            {
                return ApiResult.ParamIsNull("请选择客人来源");
            }

            demodel.Group_Id = userInfo.Group_Id;
            demodel.School_Id = userInfo.School_Id;
            demodel.Dept_Id = userInfo.DeptId;
            demodel.OrderForm = OrderFormEnum.Computer;
            demodel.EnterID = userInfo.Id;
            demodel.OrderState = OrderStateEnum.Normal;
            demodel.TradeWay = TradeWayEnum.OnLine;
            demodel.CreateBy = userInfo.Id;
            demodel.CreateTime = DateTime.Now;
            demodel.UpdateBy = userInfo.Id;
            demodel.UpdateTime = DateTime.Now;

            var flag = false;
            string message = "";
            if (demodel.OrderType == OrderTypeEnum.CourseOrder)
            {
                flag = orderModule.SetClassOrder(demodel, userInfo, out message);
            }
            else
            {
                flag = orderModule.SetStudyOrder(demodel, userInfo, out message);
            }
            return flag ? ApiResult.Success(message: message) : ApiResult.Failed(message: message);
        }

        /// <summary>
        /// 设置订单应收总额
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetOrderPreferPrice() {
            var userInfo = base.UserInfo;
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            int OrderId = parms.GetInt("OrderId", 0);
            decimal PreferPrice = parms.GetDecimal("PreferPrice");
            if (OrderId <= 0) {
                return ApiResult.ParamIsNull("请传递订单id");
            }

            bool flag = orderModule.SetOrderPreferPrice(OrderId, PreferPrice, userInfo);
            if (flag)
            {
                return ApiResult.Success();
            }
            else {
                return ApiResult.Failed();
            }
        }

        /// <summary>
        /// 获取订单详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetClassOrderInfo() {
            var userInfo = base.UserInfo;
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            int OrderId = parms.GetInt("OrderId", 0);
            if (OrderId <= 0)
            {
                return ApiResult.ParamIsNull();
            }

            var model = orderModule.GetClassOrderInfo(OrderId);
            if (model == null) {
                return ApiResult.Failed("订单不存在");
            }
            var list = new List<RB_Order_StepPrice_ViewModel>();
            if (model.OrderType == OrderTypeEnum.CourseOrder)
            { 
              list = orderModule.GetClassOrderSetpPrice(OrderId);
            }
            return ApiResult.Success("", new
            {
                OrderInfo = new
                {
                    model.OrderId,
                    model.ClassId,
                    model.GuestNum,
                    model.Class_Price,
                    model.Unit_Price,
                    model.PreferPrice,
                    model.OrderSource,
                    OrderSourceName = model.OrderSource.ToName(),
                    model.SaleRemark,
                    model.OrderType,
                    model.SourceId,
                },
                StepPriceList = list.Select(x => new
                {
                    x.Id,
                    x.PersionNum,
                    x.PersionPrice
                })
            });
        }

        /// <summary>
        /// 订单详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetClassOrderForDetail() 
        {
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            int OrderId = parms.GetInt("OrderId", 0);
            if (OrderId <= 0)
            {
                return ApiResult.ParamIsNull();
            }
            var model = orderModule.GetClassOrderInfo_V2(OrderId);
            if (model == null)
            {
                return ApiResult.Failed("订单不存在");
            }

            return ApiResult.Success("", new
            {
                model.OrderId,
                model.ClassId,
                model.ClassName,
                model.TradeWay,
                model.Class_Price,
                model.Unit_Price,
                model.GuestNum,
                model.PreferPrice,
                model.Income,
                model.Refund,
                model.DiscountMoney,
                model.PlatformTax,
                DueInMoney = model.PreferPrice - (model.Income - model.Refund + model.PlatformTax + model.DiscountMoney),
                model.OrderState,
                OrderStateName = model.OrderState.ToName(),
                model.EnterID,
                EnterName = UserReidsCache.GetUserLoginInfo(model.EnterID)?.AccountName ?? "",
                model.CommissionMoney,
                model.ExtraRewardMoney,
                model.ExtraDeductMoney,
                model.IsCommissionGive,
                CreateTime = model.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                CreateTime2 = model.CreateTime.ToString("yyyy年MM月dd日"),
                model.OrderType,
                model.SourceId,
                OrderTypeName=Common.Plugin.EnumHelper.ToName(model.OrderType),
            });
        }

        /// <summary>
        /// 取消订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult CancelClassOrder()
        {
            var userInfo = base.UserInfo;
            JObject prams = JObject.Parse(RequestParm.Msg.ToString());
            int OrderId = prams.GetInt("OrderId", 0);
            if (OrderId <= 0) 
            {
                return ApiResult.ParamIsNull("订单号不存在");
            }
            bool flag = orderModule.CancelClassOrder(OrderId, userInfo);
            if (flag)
            {
                return ApiResult.Success();
            }
            else {
                return ApiResult.Failed();
            }
        }

        /// <summary>
        /// 修改订单销售
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateOrderSale() {
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            var userInfo = base.UserInfo;
            int OrderId = parms.GetInt("OrderId", 0);
            int EnterID = parms.GetInt("EnterID", 0);
            if (OrderId <= 0)
            {
                return ApiResult.ParamIsNull("请传递订单id");
            }
            if (EnterID <= 0)
            {
                return ApiResult.ParamIsNull("请传递销售id");
            }

            string msg = orderModule.UpdateOrderSale(OrderId, EnterID, userInfo);
            if (msg == "")
            {
                return ApiResult.Success();
            }
            else {
                return ApiResult.Failed(msg);
            }
        }

        /// <summary>
        /// 获取班级订单备注列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetClassOrderRemarkList()
        {
            var userInfo = base.UserInfo;
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var dmodel = JsonHelper.DeserializeObject<RB_Order_Remark_ViewModel>(RequestParm.Msg.ToString());
            if (dmodel.OrderId <= 0) { return ApiResult.ParamIsNull(); }

            var list = orderModule.GetClassOrderRemarkList(pageModel.PageIndex, pageModel.PageSize, out long count, dmodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = list.Select(x => new
            {
                x.Id,
                x.OrderId,
                x.Content,
                CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy).AccountName,
                CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                x.Type
            });

            return ApiResult.Success("", pageModel);
        }

        /// <summary>
        /// 修改订单备注
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateOrderRemark() {
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            var userInfo = base.UserInfo;
            int OrderId = parms.GetInt("OrderId", 0);
            int Type = parms.GetInt("Type", 0);// 类型  1销售  2教务  3校长  4经理
            string Remark = parms.GetStringValue("Remark");
            if (OrderId <= 0)
            {
                return ApiResult.ParamIsNull("请传递订单id");
            }
            if (Type <= 0)
            {
                return ApiResult.ParamIsNull("请传递类型");
            }

            bool flag = orderModule.UpdateOrderRemark(OrderId, Type, Remark, userInfo);
            if (flag)
            {
                return ApiResult.Success();
            }
            else
            {
                return ApiResult.Failed();
            }
        }

        /// <summary>
        /// 修改订单提成
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateOrderCommission() {
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            var userInfo = base.UserInfo;
            int OrderId = parms.GetInt("OrderId", 0);
            decimal CommissionMoney = parms.GetDecimal("CommissionMoney");
            decimal ExtraRewardMoney = parms.GetDecimal("ExtraRewardMoney");
            decimal ExtraDeductMoney = parms.GetDecimal("ExtraDeductMoney");
            int Type = parms.GetInt("Type", 1);// 类型  1提成  2额外金额

            if (OrderId <= 0)
            {
                return ApiResult.ParamIsNull("请传递订单id");
            }

            bool flag = orderModule.UpdateOrderCommission(OrderId, Type, CommissionMoney, ExtraRewardMoney, ExtraDeductMoney, userInfo);
            if (flag)
            {
                return ApiResult.Success();
            }
            else
            {
                return ApiResult.Failed();
            }
        }

        /// <summary>
        /// 获取班级订单日志列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetClassOrderLogList()
        {
            var userInfo = base.UserInfo;
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var dmodel = JsonHelper.DeserializeObject<RB_User_ChangeLog_ViewModel>(RequestParm.Msg.ToString());
            if (dmodel.SourceId <= 0) { return ApiResult.ParamIsNull(); }
            dmodel.Type = 2;//订单日志
            var list = orderModule.GetClassOrderLogList(pageModel.PageIndex, pageModel.PageSize, out long count, dmodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = list.Select(x => new
            {
                x.Id,
                x.LogContent,
                CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy).AccountName,
                CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
            });

            return ApiResult.Success("", pageModel);
        }

        /// <summary>
        /// 获取枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGuestBasicsEnumList()
        {
            var list = EnumHelper.EnumToList(typeof(GuestBasicsEnum));
            return ApiResult.Success("", list.Select(x => new
            {
                x.Name,
                x.Id
            }));
        }

        /// <summary>
        /// 获取枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGuestEducationEnumList()
        {
            var list = EnumHelper.EnumToList(typeof(GuestEducationEnum));
            return ApiResult.Success("", list.Select(x => new
            {
                x.Name,
                x.Id
            }));
        }

        /// <summary>
        /// 获取枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGuestLearningGoalsEnumList()
        {
            var list = EnumHelper.EnumToList(typeof(GuestLearningGoalsEnum));
            return ApiResult.Success("", list.Select(x => new
            {
                x.Name,
                x.Id
            }));
        }

        /// <summary>
        /// 获取枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetOrderFormEnumList()
        {
            var list = EnumHelper.EnumToList(typeof(OrderFormEnum));
            return ApiResult.Success("", list.Select(x => new
            {
                x.Name,
                x.Id
            }));
        }

        /// <summary>
        /// 获取枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetOrderSourceEnumList()
        {
            var list = EnumHelper.EnumToList(typeof(OrderSourceEnum));
            return ApiResult.Success("", list.Select(x => new
            {
                x.Name,
                x.Id
            }));
        }

        /// <summary>
        /// 获取枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetOrderStateEnumList()
        {
            var list = EnumHelper.EnumToList(typeof(OrderStateEnum));
            return ApiResult.Success("", list.Select(x => new
            {
                x.Name,
                x.Id
            }));
        }

        /// <summary>
        /// 订单转班
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetClassOrderCareOfClass()
        {
            var userInfo = base.UserInfo;
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            int OrderId = parms.GetInt("OrderId", 0);
            int ClassId = parms.GetInt("ClassId", 0);
            if (OrderId <= 0) {
                return ApiResult.ParamIsNull("请传递订单id");
            }
            if (ClassId <= 0) {
                return ApiResult.ParamIsNull("请传递转入班级id");
            }

            string msg = orderModule.SetClassOrderCareOfClass(OrderId, ClassId, userInfo);
            if (msg == "")
            {
                return ApiResult.Success();
            }
            else {
                return ApiResult.Failed(msg);
            }
        }

        /// <summary>
        /// 订单使用最新班级报价
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetClassOrderUseNewClassPrice()
        {
            var userInfo = base.UserInfo;
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            int OrderId = parms.GetInt("OrderId", 0);
            if (OrderId <= 0) {
                return ApiResult.ParamIsNull();
            }

            bool flag = orderModule.SetClassOrderUseNewClassPrice(OrderId);
            if (flag)
            {
                return ApiResult.Success();
            }
            else {
                return ApiResult.Failed();
            }
        }

        #endregion

        #region 学生名单
        /// <summary>
        /// 获取学生名单分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetOrderGuestPageList()
        {
            var userInfo = base.UserInfo;
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var dmodel = JsonHelper.DeserializeObject<RB_Order_Guest_ViewModel>(RequestParm.Msg.ToString());
            dmodel.Group_Id = userInfo.Group_Id;
            
            var list = orderModule.GetOrderGuestPageList(pageModel.PageIndex, pageModel.PageSize, out long count, dmodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = list.Select(x => new
            {
                x.Id,
                x.GuestName,
                x.GuestState,
                x.OrderId,
                x.GuestStateStr,
                x.Profession,
                x.Sex,
                SexStr= x.Sex==1?"男":"女",
                x.Age,
                x.Mobile,
                x.Basics,
                x.Education,
                EducationName = x.Education.ToName(),
                x.GuestSource,
                GuestSourceName = x.GuestSource.ToName(),
                x.LearningGoals,
                LearningGoalsName = x.LearningGoals.ToName(),
                x.Contact,
                x.ContactMobile,
                x.IDCard,
                x.ContactAddress,
                x.Domicile,
                UpdateTime = x.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                IsShow=true,
                x.GraduatedSchool,
                x.GraduatedMajor,
                x.VolunteerMajor,
                x.Price,
                x.StudyRemark,
            });
            return ApiResult.Success("", pageModel);
        }

        /// <summary>
        /// 新增 修改客人
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetOrderGuestInfo() 
        {
            var userInfo = base.UserInfo;
            var dmodel = new RB_Order_Guest_ViewModel()
            {
                Id=base.ParmJObj.GetInt("Id"),
                OrderId=base.ParmJObj.GetInt("OrderId"),
                GuestName=base.ParmJObj.GetStringValue("GuestName"),
                Profession=base.ParmJObj.GetStringValue("Profession"),
                Sex=base.ParmJObj.GetInt("Sex",1),
                Age=base.ParmJObj.GetInt("Age"),
                Mobile=base.ParmJObj.GetStringValue("Mobile"),
                Basics=base.ParmJObj.GetStringValue("Basics"),
                Education=(GuestEducationEnum)base.ParmJObj.GetInt("Education"),
                GuestSource=(OrderSourceEnum)base.ParmJObj.GetInt("GuestSource"),
                LearningGoals=(GuestLearningGoalsEnum)base.ParmJObj.GetInt("LearningGoals"),
                Contact=base.ParmJObj.GetStringValue("Contact"),
                ContactMobile=base.ParmJObj.GetStringValue("ContactMobile"),
                IDCard=base.ParmJObj.GetStringValue("IDCard"),
                Domicile=base.ParmJObj.GetStringValue("Domicile"),
                ContactAddress=base.ParmJObj.GetStringValue("ContactAddress"),
                SourceId=base.ParmJObj.GetInt("SourceId"),
                GraduatedSchool=base.ParmJObj.GetStringValue("GraduatedSchool"),
                GraduatedMajor=base.ParmJObj.GetStringValue("GraduatedMajor"),
                VolunteerMajor=base.ParmJObj.GetStringValue("VolunteerMajor"),
                Price=base.ParmJObj.GetDecimal("Price"),
                StudyRemark=base.ParmJObj.GetStringValue("StudyRemark"),
            };
            if (dmodel.OrderId <= 0) 
            {
                return ApiResult.ParamIsNull("请传递订单id");
            }
            if (string.IsNullOrEmpty(dmodel.GuestName))
            {
                return ApiResult.ParamIsNull("请输入客人姓名");
            }
            if (string.IsNullOrEmpty(dmodel.Mobile))
            {
                return ApiResult.ParamIsNull("请输入手机号码");
            }
            dmodel.GuestState = 1;
            dmodel.Status = 0;
            dmodel.Group_Id = userInfo.Group_Id;
            dmodel.School_Id = userInfo.School_Id;
            dmodel.CreateBy = userInfo.Id;
            dmodel.CreateTime = DateTime.Now;
            dmodel.UpdateBy = userInfo.Id;
            dmodel.UpdateTime = DateTime.Now;
            bool flag = orderModule.SetOrderGuestInfo(dmodel,out string message);
            return flag ? ApiResult.Success() : ApiResult.Failed(message);
        }

        /// <summary>
        /// 删除客人
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult DelOrderGuestInfo() {
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            var userInfo = base.UserInfo;
            int GuestId = parms.GetInt("GuestId", 0);
            if (GuestId <= 0)
            {
                return ApiResult.ParamIsNull("");
            }

            bool flag = orderModule.DelOrderGuestInfo(GuestId, userInfo);
            if (flag)
            {
                return ApiResult.Success();
            }
            else
            {
                return ApiResult.Failed();
            }
        }

        #endregion

        #region 销售中心

        /// <summary>
        /// 获取我的订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetMyOrderPageList()
        {
            var userInfo = base.UserInfo;
            ResultPageModel pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            RB_Order_ViewModel demodel = new RB_Order_ViewModel()
            {
                OrderId = base.ParmJObj.GetInt("OrderId"),
                GuestName = base.ParmJObj.GetStringValue("GuestName"),
                ClassName = base.ParmJObj.GetStringValue("ClassName"),
                CouseId = base.ParmJObj.GetInt("CouseId"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                OPStartTime = base.ParmJObj.GetStringValue("OPStartTime"),
                OPEndTime = base.ParmJObj.GetStringValue("OPEndTime"),
                Q_NotCollect = base.ParmJObj.GetInt("Q_NotCollect"),
                OrderState = (OrderStateEnum)base.ParmJObj.GetInt("OrderState"),
                Q_OrderState = base.ParmJObj.GetInt("Q_OrderState"),
                Q_OrderBy = base.ParmJObj.GetInt("Q_OrderBy"),
                PlatformTax = base.ParmJObj.GetDecimal("PlatformTax"),
            };
            demodel.Group_Id = userInfo.Group_Id;
            demodel.EnterID = userInfo.Id;

            var orderList = orderModule.GetMyOrderPageList(pageModel.PageIndex, pageModel.PageSize, out long count, demodel);
            var orderS = orderModule.GetMyOrderStatistics(demodel);
            pageModel.Count = Convert.ToInt32(count);
            var obj = new
            {
                Statistics = new
                {
                    PreferPrice = orderS?.PreferPrice ?? 0,
                    Income = orderS?.Income ?? 0,
                    DueInMoney = orderS?.DueInMoney ?? 0,
                    GuestNum = orderS?.GuestNum ?? 0,
                    CancelNum = orderS?.CancelNum ?? 0,
                    CommissionMoney = orderS?.CommissionMoney ?? 0,
                    ExtraRewardMoney = orderS?.ExtraRewardMoney ?? 0
                },
                List = orderList?.Select(x => new
                {
                    x.OrderId,
                    x.ClassId,
                    x.OrderType,
                    x.SourceId,
                    x.ClassSchoolId,
                    x.ClassName,
                    x.TradeWay,
                    x.Class_Price,
                    x.Unit_Price,
                    x.GuestNum,
                    x.PreferPrice,
                    x.Income,
                    x.Refund,
                    x.DiscountMoney,
                    x.PlatformTax,
                    DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.PlatformTax + x.DiscountMoney),
                    x.OrderState,
                    OrderStateName = x.OrderState.ToName(),
                    x.EnterID,
                    EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                    x.CommissionMoney,
                    x.ExtraRewardMoney,
                    x.ExtraDeductMoney,
                    x.IsCommissionGive,
                    CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    SaleRemark = x?.SaleRemark ?? "",
                    TeacherRemark = x?.TeacherRemark ?? "",
                    RectorRemark = x?.RectorRemark ?? "",
                    DirectorRemark = x?.DirectorRemark ?? "",
                    x.OfferId,
                    SaleRemarkList = x?.SaleRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    TeacherRemarkList = x?.TeacherRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    RectorRemarkList = x?.RectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    DirectorRemarkList = x?.DirectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    GuestList = x?.GuestList.Select(z => new
                    {
                        z.Id,
                        z.GuestName,
                        z.GuestState,
                        z.ContractId,
                        z.ContractNo,
                        z.ContractStatus,
                        z.ContractStatusStr,
                    }),
                    ContractList = x?.ContractList.Select(z => new {
                        z.Id,
                        z.StudentName,
                        z.ContractNo,
                        z.GuestId,
                        z.Status
                    })
                })
            };
            pageModel.PageData = obj;
            return ApiResult.Success("", pageModel);
        }

        /// <summary>
        /// 获取订单列表统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetOrderPageListStatistics()
        {
            var userInfo = base.UserInfo;
            ResultPageModel pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            RB_Order_ViewModel demodel = new RB_Order_ViewModel()
            {
                OrderId = base.ParmJObj.GetInt("OrderId"),
                GuestName = base.ParmJObj.GetStringValue("GuestName"),
                ClassName = base.ParmJObj.GetStringValue("ClassName"),
                CouseId = base.ParmJObj.GetInt("CouseId"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                OPStartTime = base.ParmJObj.GetStringValue("OPStartTime"),
                OPEndTime = base.ParmJObj.GetStringValue("OPEndTime"),
                Q_NotCollect = base.ParmJObj.GetInt("Q_NotCollect"),
                OrderState = (OrderStateEnum)base.ParmJObj.GetInt("OrderState"),
                Q_OrderState = base.ParmJObj.GetInt("Q_OrderState"),
                Q_OrderBy = base.ParmJObj.GetInt("Q_OrderBy"),
                PlatformTax = base.ParmJObj.GetDecimal("PlatformTax"),
                EnterID = base.ParmJObj.GetInt("EnterID")
            };
            demodel.Group_Id = userInfo.Group_Id;

            var orderList = orderModule.GetMyOrderPageList(pageModel.PageIndex, pageModel.PageSize, out long count, demodel);
            var orderS = orderModule.GetMyOrderStatistics(demodel);
            pageModel.Count = Convert.ToInt32(count);
            var obj = new
            {
                Statistics = new
                {
                    PreferPrice = orderS?.PreferPrice ?? 0,
                    Income = orderS?.Income ?? 0,
                    DueInMoney = orderS?.DueInMoney ?? 0,
                    GuestNum = orderS?.GuestNum ?? 0,
                    CancelNum = orderS?.CancelNum ?? 0,
                    CommissionMoney = orderS?.CommissionMoney ?? 0,
                    ExtraRewardMoney = orderS?.ExtraRewardMoney ?? 0
                },
                List = orderList?.Select(x => new
                {
                    x.OrderId,
                    x.ClassId,
                    x.OrderType,
                    x.SourceId,
                    x.ClassSchoolId,
                    x.ClassName,
                    x.TradeWay,
                    x.Class_Price,
                    x.Unit_Price,
                    x.GuestNum,
                    x.PreferPrice,
                    x.Income,
                    x.Refund,
                    x.DiscountMoney,
                    x.PlatformTax,
                    DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.PlatformTax + x.DiscountMoney),
                    x.OrderState,
                    OrderStateName = x.OrderState.ToName(),
                    x.EnterID,
                    EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                    x.CommissionMoney,
                    x.ExtraRewardMoney,
                    x.ExtraDeductMoney,
                    x.IsCommissionGive,
                    CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    SaleRemark = x?.SaleRemark ?? "",
                    TeacherRemark = x?.TeacherRemark ?? "",
                    RectorRemark = x?.RectorRemark ?? "",
                    DirectorRemark = x?.DirectorRemark ?? "",
                    x.OfferId,
                    SaleRemarkList = x?.SaleRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    TeacherRemarkList = x?.TeacherRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    RectorRemarkList = x?.RectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    DirectorRemarkList = x?.DirectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    GuestList = x?.GuestList.Select(z => new
                    {
                        z.Id,
                        z.GuestName,
                        z.GuestState,
                        z.ContractId,
                        z.ContractNo,
                        z.ContractStatus,
                        z.ContractStatusStr,
                    }),
                    ContractList = x?.ContractList.Select(z => new {
                        z.Id,
                        z.StudentName,
                        z.ContractNo,
                        z.GuestId,
                        z.Status
                    })
                })
            };
            pageModel.PageData = obj;
            return ApiResult.Success("", pageModel);
        }


        /// <summary>
        /// 获取我的留学就业订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetMyStudyOrderPageList()
        {
            var userInfo = base.UserInfo;
            ResultPageModel pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            RB_Order_ViewModel demodel = new RB_Order_ViewModel()
            {
                OrderId = base.ParmJObj.GetInt("OrderId"),
                GuestName = base.ParmJObj.GetStringValue("GuestName"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                Q_NotCollect = base.ParmJObj.GetInt("Q_NotCollect"),
                OrderState = (OrderStateEnum)base.ParmJObj.GetInt("OrderState"),
                Q_OrderState = base.ParmJObj.GetInt("Q_OrderState"),
                Q_OrderBy = base.ParmJObj.GetInt("Q_OrderBy"),
                PlatformTax = base.ParmJObj.GetDecimal("PlatformTax"),
            };
            demodel.Group_Id = userInfo.Group_Id;
            demodel.EnterID = userInfo.Id;

            var orderList = orderModule.GetStudyOrderPageModule(pageModel.PageIndex, pageModel.PageSize, out long count, demodel);
            var orderS = orderModule.GetStudyOrderStatisticsModule(demodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = new
            {
                Statistics = new
                {
                    PreferPrice = orderS?.PreferPrice ?? 0,
                    Income = orderS?.Income ?? 0,
                    DueInMoney = orderS?.DueInMoney ?? 0,
                    GuestNum = orderS?.GuestNum ?? 0,
                    CancelNum = orderS?.CancelNum ?? 0,
                    CommissionMoney = orderS?.CommissionMoney ?? 0,
                    ExtraRewardMoney = orderS?.ExtraRewardMoney ?? 0
                },
                List = orderList.Select(x => new
                {
                    x.OrderId,
                    x.ClassId,
                    x.OrderType,
                    x.SourceId,
                    x.ClassSchoolId,
                    ClassName= x.StudyName,
                    x.TradeWay,
                    x.Class_Price,
                    x.Unit_Price,
                    x.GuestNum,
                    x.PreferPrice,
                    x.Income,
                    x.Refund,
                    x.DiscountMoney,
                    x.PlatformTax,
                    DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.PlatformTax + x.DiscountMoney),
                    x.OrderState,
                    OrderStateName = x.OrderState.ToName(),
                    x.EnterID,
                    EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                    x.CommissionMoney,
                    x.ExtraRewardMoney,
                    x.ExtraDeductMoney,
                    x.IsCommissionGive,
                    CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    x.SaleRemark,
                    x.TeacherRemark,
                    x.RectorRemark,
                    x.DirectorRemark,
                    x.OfferId,
                    SaleRemarkList = x.SaleRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    TeacherRemarkList = x.TeacherRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    RectorRemarkList = x.RectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    DirectorRemarkList = x.DirectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    GuestList = x.GuestList.Select(z => new
                    {
                        z.Id,
                        z.GuestName,
                        z.GuestState
                    })
                })
            };
            return ApiResult.Success("", pageModel);
        }

        /// <summary>
        /// 获取我的留学就业订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyOrderPageListStatistics()
        {
            var userInfo = base.UserInfo;
            ResultPageModel pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            RB_Order_ViewModel demodel = new RB_Order_ViewModel()
            {
                OrderId = base.ParmJObj.GetInt("OrderId"),
                GuestName = base.ParmJObj.GetStringValue("GuestName"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                Q_NotCollect = base.ParmJObj.GetInt("Q_NotCollect"),
                OrderState = (OrderStateEnum)base.ParmJObj.GetInt("OrderState"),
                Q_OrderState = base.ParmJObj.GetInt("Q_OrderState"),
                Q_OrderBy = base.ParmJObj.GetInt("Q_OrderBy"),
                PlatformTax = base.ParmJObj.GetDecimal("PlatformTax"),
                EnterID = base.ParmJObj.GetInt("EnterID")
            };
            demodel.Group_Id = userInfo.Group_Id;

            var orderList = orderModule.GetStudyOrderPageModule(pageModel.PageIndex, pageModel.PageSize, out long count, demodel);
            var orderS = orderModule.GetStudyOrderStatisticsModule(demodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = new
            {
                Statistics = new
                {
                    PreferPrice = orderS?.PreferPrice ?? 0,
                    Income = orderS?.Income ?? 0,
                    DueInMoney = orderS?.DueInMoney ?? 0,
                    GuestNum = orderS?.GuestNum ?? 0,
                    CancelNum = orderS?.CancelNum ?? 0,
                    CommissionMoney = orderS?.CommissionMoney ?? 0,
                    ExtraRewardMoney = orderS?.ExtraRewardMoney ?? 0
                },
                List = orderList.Select(x => new
                {
                    x.OrderId,
                    x.ClassId,
                    x.OrderType,
                    x.SourceId,
                    x.ClassSchoolId,
                    ClassName = x.StudyName,
                    x.TradeWay,
                    x.Class_Price,
                    x.Unit_Price,
                    x.GuestNum,
                    x.PreferPrice,
                    x.Income,
                    x.Refund,
                    x.DiscountMoney,
                    x.PlatformTax,
                    DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.PlatformTax + x.DiscountMoney),
                    x.OrderState,
                    OrderStateName = x.OrderState.ToName(),
                    x.EnterID,
                    EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                    x.CommissionMoney,
                    x.ExtraRewardMoney,
                    x.ExtraDeductMoney,
                    x.IsCommissionGive,
                    CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    x.SaleRemark,
                    x.TeacherRemark,
                    x.RectorRemark,
                    x.DirectorRemark,
                    x.OfferId,
                    SaleRemarkList = x.SaleRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    TeacherRemarkList = x.TeacherRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    RectorRemarkList = x.RectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    DirectorRemarkList = x.DirectorRemarkList.Select(z => new
                    {
                        z.Id,
                        z.Content,
                        CreateBy = z.CreateByName,
                        CreateTime = z.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    }),
                    GuestList = x.GuestList.Select(z => new
                    {
                        z.Id,
                        z.GuestName,
                        z.GuestState
                    })
                })
            };
            return ApiResult.Success("", pageModel);
        }


        /// <summary>
        /// 订单转交
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetClassOrderCareOf()
        {
            var userInfo = base.UserInfo;
            JObject prams = JObject.Parse(RequestParm.Msg.ToString());
            int OrderId = prams.GetInt("OrderId", 0);
            int CareOfPeople = prams.GetInt("CareOfPeople", 0);
            if (OrderId <= 0)
            {
                return ApiResult.ParamIsNull();
            }
            if (CareOfPeople <= 0)
            {
                return ApiResult.ParamIsNull("请选择转交人");
            }

            bool flag = orderModule.SetClassOrderCareOf(OrderId, CareOfPeople, userInfo);
            if (flag)
            {
                return ApiResult.Success();
            }
            else
            {
                return ApiResult.Failed();
            }
        }
        #endregion

        #region 退课申请
        /// <summary>
        /// 退课申请
        /// </summary>
        /// <returns></returns>
        public ApiResult BackClassApply()
        {
            var GuestId = base.ParmJObj.GetInt("GuestId");
            var OrderId = base.ParmJObj.GetInt("OrderId");
            //申请原因
            var applyReason = base.ParmJObj.GetStringValue("applyReason");
            bool flag = orderModule.CreateBackClassApplyModule(GuestId, OrderId, applyReason, base.UserInfo, out string message);
            return flag ? ApiResult.Success(message: message) : ApiResult.Failed(message: message);
        }
        #endregion
    }
}
