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.Finance;
using Edu.Common.Enum.Sale;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.Grade;
using Edu.Model.ViewModel.Log;
using Edu.Model.ViewModel.Sell;
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 = new RB_Class_ViewModel()
            {
                ClassName = base.ParmJObj.GetStringValue("ClassName"),
                ClassNo = base.ParmJObj.GetStringValue("ClassNo"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                Teacher_Id = base.ParmJObj.GetInt("Teacher_Id"),
                CouseId = base.ParmJObj.GetInt("CouseId"),
                Q_CanApply = base.ParmJObj.GetInt("Q_CanApply"),
                JoinStartTime = base.ParmJObj.GetStringValue("JoinStartTime"),
                JoinEndTime = base.ParmJObj.GetStringValue("JoinEndTime"),
                CourseSubject = base.ParmJObj.GetInt("CourseSubject"),
                ClassScrollType = base.ParmJObj.GetInt("ClassScrollType", 1)
            };
            dmodel.School_Id = -1;
            var schoolId = base.ParmJObj.GetStringValue("School_Id");
            if (!string.IsNullOrEmpty(schoolId))
            {
                dmodel.School_Id = base.ParmJObj.GetInt("School_Id");
            }
            dmodel.Group_Id = userInfo.Group_Id;
            var list = orderModule.GetClassPruductListModule(pageModel.PageIndex, pageModel.PageSize, out long count, dmodel);
            pageModel.Count = Convert.ToInt32(count);
            List<object> result = new List<object>();
            foreach (var x in list)
            {
                int IsInsertClass = 0;//不能插班报入
                int SurplusNum = x.ClassPersion - x.OrderStudentCount;
                if (x.ClassStatus != ClassStatusEnum.EndClass && SurplusNum > 0)
                {
                    IsInsertClass = 1;//可以插班报入
                }
                var obj = new
                {
                    x.ClassId,
                    x.ClassName,
                    x.ClassNo,
                    x.CourseName,
                    x.CouseId,
                    x.CourseFeature,
                    x.ClassHours,
                    x.Teacher_Id,
                    x.TeacherName,
                    x.TeacherHead,
                    x.RoomName,
                    x.ClassStyle,
                    ClassStyleName = x.ClassStyle.ToName(),
                    OpenTime = x.OpenTime.ToString("yyyy年MM月dd日"),
                    EndOrderTime =Common.ConvertHelper.FormatDate2(x.EndOrderTime),
                    IsCanApply = x.EndOrderTime >= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) && x.ClassPersion > x.OrderStudentCount ? 1 : 0,
                    OriginalPrice = x.CourseOriginalPrice,
                    SellPrice = x.CourseSellPrice,
                    x.IsStepPrice,
                    x.ClassPersion,
                    x.OutRemark,
                    x.OrderStudentCount,
                    SurplusNum,
                    ClassStepPriceList = x.ClassStepPriceList.Select(z => new
                    {
                        z.ClassStepPriceId,
                        z.PersionNum,
                        z.PersionPrice
                    }),
                    ClassTimeList = x.DefaultTimeList,
                    ClassPlanList = x.ClassPlanList.Select(z => new
                    {
                        z.WeekDay,
                        ClassDate = x.ClassStyle == ClassStyleEnum.FixedDate ? Common.ConvertHelper.FormatDate(z.ClassDate) : ""
                    }),
                    x.SchoolName,
                    UpdateTime = Common.ConvertHelper.FormatTime(x.UpdateTime),
                    x.OtherCourseList,
                    IsChaBan = IsInsertClass,
                    x.CourseSubject,
                    x.CourseSubjectName,
                    x.B2CRatio,
                    x.B2CReNewRatio,
                    x.B2BRebateRatio,
                    x.B2BReNewRatio,
                    x.SchoolRebateRatio,
                    x.SchoolReNewRatio
                };
                result.Add(obj);
            }
            pageModel.PageData = result;
            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
            }));
        }

        /// <summary>
        /// 获取留学就业产品名称
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyNameList()
        {
            string Ids = base.ParmJObj.GetStringValue("Ids");
            if (string.IsNullOrEmpty(Ids))
            {
                return ApiResult.ParamIsNull("请传留学就业产品编号");
            }
            var list = orderModule.GetStudyAbroadListModule(Ids);
            return ApiResult.Success("", list.Select(x => new
            {
                ClassId = x.Id,
                ClassName = x.Name,
                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.ClassName,
                        x.CourseId,
                        x.CourseName,
                        x.StartClassHours,
                        x.JoinType,
                        x.TargetJoinType,
                        x.TargetOrderId,
                        x.TargetClassName,
                        x.SourceOrderId,
                        x.SourceClassName,
                        x.ClassSchoolId,
                        x.TradeWay,
                        x.Class_Price,
                        x.Unit_Price,
                        x.GuestNum,
                        x.PreferPrice,
                        x.Income,
                        x.Refund,
                        x.DiscountMoney,
                        x.PlatformTax,
                        x.OrderType,
                        DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.PlatformTax + x.DiscountMoney),
                        x.OrderState,
                        OrderStateName = x.OrderState.ToName(),
                        x.OrderSource,
                        OrderSourceName = x.OrderSource.ToName(),
                        x.EnterID,
                        EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                        x.CreateBy,
                        CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy)?.AccountName ?? "",
                        x.CourseConsultantId,
                        ConsultantName = UserReidsCache.GetUserLoginInfo(x.CourseConsultantId)?.AccountName ?? "",
                        IsAchievements = x.YFCommission > 0 ? 1 : 2,
                        YFCommissionMoney = x.YFCommission > 0 ? x.YFCommission : GetOrderYFCommission(x),
                        x.CommissionMoney,
                        x.ExtraCommissionMoney,
                        x.ExtraRewardMoney,
                        x.ExtraDeductMoney,
                        IsCommissionGive = x.YFCommission > 0 ? 1 : x.IsCommissionGive,
                        x.CommissionBack,
                        CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        x.SaleRemark,
                        x.TeacherRemark,
                        x.RectorRemark,
                        x.DirectorRemark,
                        x.OfferId,
                        x.HelpEnterId,
                        HelpEnterName = UserReidsCache.GetUserLoginInfo(x.HelpEnterId)?.AccountName,
                        x.GeneralOccupation,
                        x.EduOccupation,
                        x.IsLessPrice,
                        x.LessPrice,
                        OpenTime = Common.ConvertHelper.FormatDate(x.OpenTime),
                        x.EffectStatus,
                        x.EffectStatusStr,
                        EffectTime = Common.ConvertHelper.FormatDate(x.EffectTime),
                        x.UpOrderId,
                        x.VisitorReserveId,
                        x.RenewOrderId,
                        x.FirstOrderId,
                        x.IsBackClass,
                        x.LXConfirmState,
                        x.CustomerId,
                        x.CustomerName,
                        x.CustomerTel,
                        x.ClassScrollType,
                        SplitDetailsList = x?.SplitDetailsList?.Select(qitem => new
                        {
                            qitem.S_ClassId,
                            qitem.S_ClassName,
                            qitem.S_JoinType,
                            S_JoinTypeName = qitem.S_JoinType.ToName(),
                            qitem.S_OrderId,
                            qitem.T_ClassId,
                            qitem.T_ClassName,
                            qitem.T_JoinType,
                            T_JoinTypeName = qitem.T_JoinType.ToName(),
                            qitem.T_OrderId
                        }),
                        SaleRemarkList = 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.GuestStateStr,
                            z.ContractNo,
                            z.ContractId,
                            z.ContractStatus,
                            z.ContractStatusStr,
                            z.GuestContractNo,
                            z.ContractType,
                            z.ContractUrl,
                            z.ContractUrlList,
                        }),
                        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,
                        x.OrderType,
                        x.PlatformTax,
                        DueInMoney = x.PreferPrice - (x.Income - x.Refund + x.DiscountMoney),
                        x.OrderState,
                        OrderStateName = x.OrderState.ToName(),
                        x.EnterID,
                        EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                        x.CreateBy,
                        CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy)?.AccountName ?? "",
                        x.CourseConsultantId,
                        ConsultantName = UserReidsCache.GetUserLoginInfo(x.CourseConsultantId)?.AccountName ?? "",
                        IsAchievements = x.YFCommission > 0 ? 1 : 2,
                        YFCommissionMoney = x.YFCommission > 0 ? x.YFCommission : GetOrderYFCommission(x),
                        x.CommissionMoney,
                        x.ExtraCommissionMoney,
                        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,
                        x.HelpEnterId,
                        HelpEnterName = UserReidsCache.GetUserLoginInfo(x.HelpEnterId)?.AccountName,
                        x.GeneralOccupation,
                        x.EduOccupation,
                        x.IsLessPrice,
                        x.LessPrice,
                        x.CustomerId,
                        x.CustomerName,
                        x.CustomerTel,
                        x.ClassScrollType,
                        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>
        /// <param name="x"></param>
        /// <returns></returns>
        private static decimal GetOrderYFCommission(RB_Order_ViewModel x)
        {
            if (x.CommissionType == x.CommissionTypeTH)
            {
                if (x.CommissionType == 1)
                {
                    return x.CommissionRate + x.CommissionRateTH - x.LessPrice;
                }
                else
                {
                    return Math.Round((x.PreferPrice - x.DiscountMoney + x.LessPrice) * (x.CommissionRate + x.CommissionRateTH) / 100, 2, MidpointRounding.AwayFromZero) - x.LessPrice;
                }
            }
            else
            {
                decimal commission1 = x.CommissionType == 1 ? x.CommissionRate : Math.Round((x.PreferPrice - x.DiscountMoney + x.LessPrice) * x.CommissionRate / 100, 2, MidpointRounding.AwayFromZero);
                decimal commission2 = x.CommissionTypeTH == 1 ? x.CommissionRateTH : Math.Round((x.PreferPrice - x.DiscountMoney + x.LessPrice) * x.CommissionRateTH / 100, 2, MidpointRounding.AwayFromZero);
                return commission1 + commission2 - x.LessPrice;
            }
        }

        /// <summary>
        /// 获取班级订单下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSelectClassOrderList()
        {
            JObject parms = JObject.Parse(RequestParm.Msg.ToString());
            var userInfo = base.UserInfo;
            var query = new RB_Order_ViewModel()
            {
                ClassId = parms.GetInt("ClassId", 0),
                OrderId = parms.GetInt("OrderId"),
                SourceId=parms.GetInt("SourceId"),
                Group_Id = base.UserInfo.Group_Id,
                OrderState = OrderStateEnum.Normal
            };
            if (query.ClassId <= 0&&query.SourceId<=0)
            {
                return ApiResult.ParamIsNull();
            }
            var orderList = orderModule.GetClassOrderListExtModule(query);
            return ApiResult.Success("", orderList.Select(x => new
            {
                x.OrderId,
                x.ClassId,
                x.ClassName,
                x.CourseId,
                x.CourseName,
                x.GuestList,
                x.ClassHours,
                x.StartClassHours,
            }));
        }

        /// <summary>
        /// 获取客户转订单续费状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetOrderGuestRenewState() {
            var userInfo = base.UserInfo;
            string StuIds = base.ParmJObj.GetStringValue("StuIds");
            if (string.IsNullOrEmpty(StuIds))
            {
                return ApiResult.ParamIsNull("请传递学生名单");
            }

            var Robj = orderModule.GetOrderGuestRenewState(StuIds, userInfo, out string msg);
            if (msg == "")
            {
                return ApiResult.Success("", Robj);
            }
            else
            {
                return ApiResult.Failed(msg);
            }
        }

        /// <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"),
                HelpEnterId = base.ParmJObj.GetInt("HelpEnterId"),
                GeneralOccupation = base.ParmJObj.GetStringValue("GeneralOccupation"),
                EduOccupation = base.ParmJObj.GetStringValue("EduOccupation"),
     
                OrderNature = (OrderNatureEnum)base.ParmJObj.GetInt("OrderNature"),
                OldPreferPrice = base.ParmJObj.GetDecimal("OldPreferPrice"),
                CourseId = base.ParmJObj.GetInt("CourseId"),
                StartClassHours = base.ParmJObj.GetInt("StartClassHours"),
                EffectTime = base.ParmJObj.GetDateTime("EffectTime"),
                UpOrderId = base.ParmJObj.GetInt("UpOrderId"),
                VisitorReserveId = base.ParmJObj.GetInt("VisitorReserveId"),
                JoinType = OrderJoinTypeEnum.Normal,
                TargetJoinType = OrderJoinTypeEnum.Normal,
                DiscountMoney = base.ParmJObj.GetDecimal("DiscountMoney"),
                PerDiscountMoney = base.ParmJObj.GetDecimal("PerDiscountMoney"),
                IsLessPrice = base.ParmJObj.GetInt("IsLessPrice"),
                LessPrice = base.ParmJObj.GetDecimal("LessPrice"),
                PerLessMoney = base.ParmJObj.GetDecimal("PerLessMoney"),
                CustomerId = base.ParmJObj.GetInt("CustomerId"),
                StuIds = base.ParmJObj.GetStringValue("StuIds"),
                OrderIdentify = base.ParmJObj.GetInt("OrderIdentify"),
                CourseConsultantId = base.ParmJObj.GetInt("CourseConsultantId"),
                EnterID = base.ParmJObj.GetInt("EnterID"),
                ScrollSchoolId = base.ParmJObj.GetInt("ScrollSchoolId")
            };
            var IsInsertClass = base.ParmJObj.GetInt("IsChaBan");
            if (IsInsertClass == 1)
            {
                demodel.JoinType = OrderJoinTypeEnum.InsertClass;
            }
            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("请选择客人来源");
            }
            if (demodel.OrderIdentify == 2 && string.IsNullOrEmpty(demodel.StuIds) && demodel.OrderId == 0)
            {
                return ApiResult.ParamIsNull("请传递选择客户");
            }
            if (demodel.OrderIdentify == 2 && !string.IsNullOrEmpty(demodel.StuIds)) {
                //验证学生是否已有其他订单
                var vlist = orderModule.ValidataStuOrder(demodel.StuIds, userInfo.Group_Id);
                if (vlist.Any()) {
                    var vmodel = vlist.FirstOrDefault();
                    return ApiResult.Tip("学员" + vmodel.GuestName + "存在有效未付款订单" + vmodel.OrderId + "，请取消该订单后再试", vmodel.OrderId);
                }
            }
            if (!string.IsNullOrEmpty(demodel.StuIds)) {
                int gNum = JsonHelper.DeserializeObject<List<int>>("[" + demodel.StuIds + "]").Count();
                if (demodel.GuestNum != gNum) {
                    return ApiResult.ParamIsNull("客人数量不正确");
                }
            }

            demodel.Group_Id = userInfo.Group_Id;
            demodel.School_Id = userInfo.School_Id;
            demodel.Dept_Id = userInfo.DeptId;
            demodel.OrderForm = OrderFormEnum.Computer;
            if (demodel.OrderIdentify != 2)
            {
                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)
            {
                if (demodel.JoinType == OrderJoinTypeEnum.Normal)
                {
                    demodel.StartClassHours = 0;
                }
                else if (demodel.JoinType == OrderJoinTypeEnum.InsertClass)
                {
                    if (demodel.CourseId <= 0)
                    {
                        return ApiResult.ParamIsNull(message: "请选择插班课程!");
                    }
                }
                flag = orderModule.SetClassOrderModule(demodel, userInfo, base.CheckUserActionAuth("Edit_Order"), out message);
            }
            else
            {
                flag = orderModule.SetStudyOrderModule(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.GetClassOrderInfoModule(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,
                    model.HelpEnterId,
                    model.GeneralOccupation,
                    model.EduOccupation,
                    model.IsLessPrice,
                    model.LessPrice,
                    model.PerLessMoney,
                    model.DiscountMoney,
                    model.PerDiscountMoney,
                    model.OrderNature,
                    OrderNatureName = model.OrderNature.ToName(),
                    model.OldPreferPrice,
                    IsChaBan = model.JoinType == OrderJoinTypeEnum.InsertClass ? 1 : 0,
                    model.CourseId,
                    model.StartClassHours,
                    EffectTime = Common.ConvertHelper.FormatDate(model.EffectTime),
                    model.UpOrderId,
                    model.VisitorReserveId,
                    model.JoinType,
                    model.TargetJoinType,
                    model.SourceOrderId,
                    model.TargetOrderId,
                    model.CustomerId,
                    model.CourseConsultantId,
                    model.OrderIdentify,
                    model.B2CRatio,
                    model.B2CReNewRatio,
                    model.B2BRebateRatio,
                    model.B2BReNewRatio,
                    model.SchoolRebateRatio,
                    model.SchoolReNewRatio
                },
                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.GetClassOrderInfoModule(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.CreateBy,
                CreateByName = UserReidsCache.GetUserLoginInfo(model.CreateBy)?.AccountName ?? "",
                model.CourseConsultantId,
                ConsultantName = UserReidsCache.GetUserLoginInfo(model.CourseConsultantId)?.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),
                OpenTime = Common.ConvertHelper.FormatDate(model.OpenTime),
            });
        }

        /// <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.GetClassOrderRemarkPageModule(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(data:list);
        }

        /// <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 = new RB_Order_Guest_ViewModel()
            {
                OrderId = base.ParmJObj.GetInt("OrderId"),
                ClassId = base.ParmJObj.GetInt("ClassId"),
                GuestState =(GuestStateEnum)base.ParmJObj.GetInt("GuestState"),
                GuestName = base.ParmJObj.GetStringValue("GuestName"),
                SourceId = base.ParmJObj.GetInt("SourceId"),
            };
            dmodel.Group_Id = userInfo.Group_Id;
            var list = orderModule.GetOrderGuestPageModule(pageModel.PageIndex, pageModel.PageSize, out long count, dmodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = list.Select(x => new
            {
                x.Id,
                x.GuestName,
                x.OrderId,
                x.Profession,
                x.Sex,
                SexStr = x.Sex == 1 ? "男" : "女",
                x.Age,
                BirthDate = Common.ConvertHelper.FormatDate(x.BirthDate),
                Mobile=x.StuTel,
                x.Basics,
                x.Education,
                EducationName = x.Education.ToName(),
                x.GuestSource,
                GuestSourceName = x.GuestSource.ToName(),
                x.LearningGoals,
                x.LearningGoalsName,
                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,
                x.StuIcon,
                x.CourseId,
                x.CourseName,
                x.StartClassHours,
                x.JoinType,
                JoinTypeName = x.JoinType.ToName(),
                x.TargetJoinType,
                TargetJoinTypeName = x.TargetJoinType.ToName(),
                x.SourceOrderId,
                x.SourceClassName,
                x.TargetOrderId,
                x.TargetClassName,
                x.EffectStatus,
                x.EffectStatusStr,
                EffectTime = Common.ConvertHelper.FormatDate(x.EffectTime),
                x.UpOrderId,
                x.GuestContractNo,
                x.ContractType,
                x.ContractUrl,
                x.ContractUrlList,
                x.TotalHours,
                x.ValidClassHours,
                x.CompleteHours,
                x.MakeUpHours,
                SurplusHours=x.TotalHours-x.CompleteHours,
                x.GuestState,
                x.GuestStateStr,
                GraduationTime = Common.ConvertHelper.FormatDate(x.GraduationTime),
                BackClassList = x?.GuestEduReceiptList?.Where(qitem => qitem.ReceiptType == ReceiptTypeEnum.BackClass)?.ToList(),
                StopClassList = x?.GuestEduReceiptList?.Where(qitem => qitem.ReceiptType == ReceiptTypeEnum.StopClass)?.ToList(),
                InvitationClassList = x?.GuestEduReceiptList?.Where(qitem => qitem.ReceiptType == ReceiptTypeEnum.InvitationClass)?.ToList(),
                OrderTransClassList = x?.GuestEduReceiptList?.Where(qitem => qitem.ReceiptType == ReceiptTypeEnum.OrderTransClass)?.ToList(),
                OrderSplitClassList = x?.GuestEduReceiptList?.Where(qitem => qitem.ReceiptType == ReceiptTypeEnum.OrderSplitClass)?.ToList(),
            });
            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 = 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"),
                BirthDate = base.ParmJObj.GetDateTime("BirthDate"),
                TotalHours = base.ParmJObj.GetDecimal("TotalHours"),
                StuIcon = base.ParmJObj.GetStringValue("StuIcon"),
                GuestContractNo = base.ParmJObj.GetStringValue("GuestContractNo"),
                ContractType = base.ParmJObj.GetInt("ContractType"),
            };
            if (dmodel.OrderId <= 0)
            {
                return ApiResult.ParamIsNull("请传递订单id");
            }
            if (string.IsNullOrEmpty(dmodel.GuestName))
            {
                return ApiResult.ParamIsNull("请输入客人姓名");
            }
            if (string.IsNullOrEmpty(dmodel.Mobile))
            {
                return ApiResult.ParamIsNull("请输入手机号码");
            }
            List<string> contractList = new List<string>();
            var contract = base.ParmJObj.GetStringValue("ContractUrl");
            if (!string.IsNullOrEmpty(contract))
            {
                contractList = Common.Plugin.JsonHelper.DeserializeObject<List<string>>(contract);
            }
            dmodel.ContractUrl = Common.Plugin.JsonHelper.Serialize(contractList);
            dmodel.GuestState = GuestStateEnum.Normal;
            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_V2(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();
            }
        }

        /// <summary>
        /// 通过我的学生直接转订单客人
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetMyStudentToGuest() {
            var userInfo = base.UserInfo;
            JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
            int OrderId = parms.GetInt("OrderId", 0);//订单
            string StuIds = parms.GetStringValue("StuIds");//学生Ids
            if (OrderId <= 0) {
                return ApiResult.ParamIsNull("订单不存在");
            }
            if (string.IsNullOrEmpty(StuIds)) {
                return ApiResult.ParamIsNull("请选择学生");
            }

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

        #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"),
                CourseId = 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"),
                CourseSubject=base.ParmJObj.GetInt("CourseSubject"),
            };
            demodel.Group_Id = userInfo.Group_Id;
            demodel.CreateBy = userInfo.Id;

            var orderList = orderModule.GetMyOrderPageList(pageModel.PageIndex, pageModel.PageSize, out long count, demodel);
            var orderS = orderModule.GetMyOrderStatisticsModule(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.CourseId,
                    x.CourseName,
                    x.JoinType,
                    JoinTypeName = x.JoinType.ToName(),
                    x.TargetJoinType,
                    TargetJoinTypeName = x.JoinType.ToName(),
                    x.SourceOrderId,
                    x.SourceClassName,
                    x.TargetOrderId,
                    x.TargetClassName,
                    x.StartClassHours,
                    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.OrderSource,
                    OrderSourceName = x.OrderSource.ToName(),
                    x.EnterID,
                    EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                    x.CreateBy,
                    CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy)?.AccountName ?? "",
                    x.CourseConsultantId,
                    ConsultantName = UserReidsCache.GetUserLoginInfo(x.CourseConsultantId)?.AccountName ?? "",
                    IsAchievements = x.YFCommission > 0 ? 1 : 2,
                    YFCommissionMoney = x.YFCommission > 0 ? x.YFCommission : GetOrderYFCommission(x),
                    x.CommissionMoney,
                    x.ExtraCommissionMoney,
                    x.ExtraRewardMoney,
                    x.ExtraDeductMoney,
                    IsCommissionGive = x.YFCommission > 0 ? 1 : x.IsCommissionGive,
                    x.CommissionBack,
                    CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    SaleRemark = x?.SaleRemark ?? "",
                    TeacherRemark = x?.TeacherRemark ?? "",
                    RectorRemark = x?.RectorRemark ?? "",
                    DirectorRemark = x?.DirectorRemark ?? "",
                    x.OfferId,
                    x.HelpEnterId,
                    HelpEnterName = UserReidsCache.GetUserLoginInfo(x.HelpEnterId)?.AccountName,
                    x.GeneralOccupation,
                    x.EduOccupation,
                    x.IsLessPrice,
                    x.LessPrice,
                    x.OrderNature,
                    OrderNatureName = x.OrderNature.ToName(),
                    x.OldPreferPrice,
                    x.EffectStatus,
                    x.EffectStatusStr,
                    EffectTime = Common.ConvertHelper.FormatDate(x.EffectTime),
                    x.UpOrderId,
                    OpenTime = Common.ConvertHelper.FormatDate(x.OpenTime),
                    x.VisitorReserveId,
                    x.RenewOrderId,
                    x.FirstOrderId,
                    x.IsBackClass,
                    x.CourseSubject,
                    x.CourseSubjectName,
                    x.CustomerId,
                    x.CustomerName,
                    x.CustomerTel,
                    x.ClassScrollType,
                    SplitDetailsList = x?.SplitDetailsList?.Select(qitem => new
                    {
                        qitem.S_ClassId,
                        qitem.S_ClassName,
                        qitem.S_JoinType,
                        S_JoinTypeName = qitem.S_JoinType.ToName(),
                        qitem.S_OrderId,
                        qitem.T_ClassId,
                        qitem.T_ClassName,
                        qitem.T_JoinType,
                        T_JoinTypeName = qitem.T_JoinType.ToName(),
                        qitem.T_OrderId
                    }),
                    SaleRemarkList = 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,
                        z.GuestStateStr,
                        z.GuestContractNo,
                        z.ContractType,
                        z.ContractUrl,
                        z.ContractUrlList,
                    }),
                    ContractList = x?.ContractList.Select(z => new
                    {
                        z.Id,
                        z.StudentName,
                        z.ContractNo,
                        z.GuestId,
                        z.Status
                    }),
                    x.CreateType,
                    CreateTypeName = x.CreateType.ToName(),
                    x.StuSourceIdName,
                })
            };
            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"),
                CourseId = 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"),
                HelpEnterId = base.ParmJObj.GetInt("HelpEnterId", 0),
                ClassNo = base.ParmJObj.GetStringValue("ClassNo"),
                CourseSubject = base.ParmJObj.GetInt("CourseSubject"),
                CustomerId = base.ParmJObj.GetInt("CustomerId", 0),
                CategoryId=base.ParmJObj.GetInt("CategoryId"),
            };
            demodel.Group_Id = userInfo.Group_Id;

            var orderList = orderModule.GetMyOrderPageList(pageModel.PageIndex, pageModel.PageSize, out long count, demodel);
            var orderS = orderModule.GetMyOrderStatisticsModule(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) > 0 ? (orderS?.CommissionMoney ?? 0) : 0,
                    ExtraRewardMoney = orderS?.ExtraRewardMoney ?? 0
                },
                List = orderList?.Select(x => new
                {
                    x.OrderId,
                    x.ClassId,
                    x.ClassNo,
                    x.OrderType,
                    x.SourceId,
                    x.ClassSchoolId,
                    x.ClassName,
                    OpenTime = Common.ConvertHelper.FormatDate(x.OpenTime),
                    x.JoinType,
                    JoinTypeName = x.JoinType.ToName(),
                    x.TargetJoinType,
                    TargetJoinTypeName = x.TargetJoinType.ToName(),
                    x.SourceOrderId,
                    x.SourceClassName,
                    x.TargetOrderId,
                    x.TargetClassName,
                    x.StartClassHours,
                    x.CourseName,
                    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.OrderSource,
                    OrderSourceName = x.OrderSource.ToName(),
                    x.EnterID,
                    EnterName = UserReidsCache.GetUserLoginInfo(x.EnterID)?.AccountName ?? "",
                    x.CreateBy,
                    CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy)?.AccountName ?? "",
                    x.CourseConsultantId,
                    ConsultantName = UserReidsCache.GetUserLoginInfo(x.CourseConsultantId)?.AccountName ?? "",
                    IsAchievements = x.YFCommission > 0 ? 1 : 2,
                    YFCommissionMoney = x.YFCommission > 0 ? x.YFCommission : GetOrderYFCommission(x),
                    x.CommissionMoney,
                    x.ExtraCommissionMoney,
                    x.ExtraRewardMoney,
                    x.ExtraDeductMoney,
                    IsCommissionGive = x.YFCommission > 0 ? 1 : x.IsCommissionGive,
                    x.CommissionBack,
                    CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    SaleRemark = x?.SaleRemark ?? "",
                    TeacherRemark = x?.TeacherRemark ?? "",
                    RectorRemark = x?.RectorRemark ?? "",
                    DirectorRemark = x?.DirectorRemark ?? "",
                    x.OfferId,
                    x.HelpEnterId,
                    HelpEnterName = UserReidsCache.GetUserLoginInfo(x.HelpEnterId)?.AccountName,
                    x.GeneralOccupation,
                    x.EduOccupation,
                    x.IsLessPrice,
                    x.LessPrice,
                    x.OrderNature,
                    OrderNatureName = x.OrderNature.ToName(),
                    x.OldPreferPrice,
                    x.EffectStatus,
                    x.EffectStatusStr,
                    EffectTime = Common.ConvertHelper.FormatDate(x.EffectTime),
                    x.UpOrderId,
                    x.VisitorReserveId,
                    x.RenewOrderId,
                    x.FirstOrderId,
                    x.IsBackClass,
                    x.CourseSubject,
                    x.CourseSubjectName,
                    x.CustomerId,
                    x.CustomerName,
                    x.CustomerTel,
                    x.ClassScrollType,
                    SplitDetailsList = x?.SplitDetailsList?.Select(qitem => new
                    {
                        qitem.S_ClassId,
                        qitem.S_ClassName,
                        qitem.S_JoinType,
                        S_JoinTypeName = qitem.S_JoinType.ToName(),
                        qitem.S_OrderId,
                        qitem.T_ClassId,
                        qitem.T_ClassName,
                        qitem.T_JoinType,
                        T_JoinTypeName = qitem.T_JoinType.ToName(),
                        qitem.T_OrderId
                    }),
                    SaleRemarkList = 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,
                        z.GuestStateStr,
                        z.GuestContractNo,
                        z.ContractType,
                        z.ContractUrl,
                        z.ContractUrlList,
                    }),
                    ContractList = x?.ContractList.Select(z => new
                    {
                        z.Id,
                        z.StudentName,
                        z.ContractNo,
                        z.GuestId,
                        z.Status,
                    }),
                    x.CreateType,
                    CreateTypeName = x.CreateType.ToName(),
                    x.StuSourceIdName,
                })
            };
            pageModel.PageData = obj;
            return ApiResult.Success("", pageModel);
        }

        /// <summary>
        /// 获取订单列表统计  Excel导出
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Obsolete]
        public FileContentResult GetOrderPageListStatisticsToExcel()
        {
            List<ExcelDataSource> slist = new List<ExcelDataSource>();
            ExcelDataSource header = new ExcelDataSource()
            {
                ExcelRows = new List<ExcelColumn>(30) {
                    new ExcelColumn(value:"订单号"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"下单日期"){CellWidth=20,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"下单人"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"市场人员"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"课程顾问"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"协助老师"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"班级"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"开班时间"){CellWidth=20,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"课程"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"人数"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"单价"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"成交单价"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"应收总额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"实收"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"优惠金额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"少价金额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"退款"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"平台税金"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"待收金额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"状态"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"学生名单"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"销售备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"教务备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"校长备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"经理备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"类型"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                }
            };
            slist.Add(header);
            string ExcelName = "报名统计" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";

            var userInfo = base.UserInfo;
            RB_Order_ViewModel demodel = new RB_Order_ViewModel()
            {
                OrderId = base.ParmJObj.GetInt("OrderId"),
                GuestName = base.ParmJObj.GetStringValue("GuestName"),
                ClassName = base.ParmJObj.GetStringValue("ClassName"),
                CourseId = 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"),
                HelpEnterId = base.ParmJObj.GetInt("HelpEnterId", 0),
                ClassNo = base.ParmJObj.GetStringValue("ClassNo")
            };
            demodel.Group_Id = userInfo.Group_Id;

            var list = orderModule.GetMyOrderPageList(1, 100000, out long count, demodel);

            try
            {
                foreach (var item in list)
                {
                    item.DueInMoney = item.PreferPrice - (item.Income - item.Refund + item.PlatformTax + item.DiscountMoney);
                    string GuestNameStr = string.Join(",", item?.GuestList.Select(x => x.GuestName));
                    ExcelDataSource firstRow = new ExcelDataSource(30)
                    {
                        ExcelRows = new List<ExcelColumn>()
                        {
                            new ExcelColumn(value: item.OrderId.ToString()){ },
                            new ExcelColumn(value: item.CreateTime.ToString("yyyy-MM-dd HH:mm")){ },
                            new ExcelColumn(value: (item.CreateBy > 0 ? UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "" : "")){ },
                            new ExcelColumn(value: (item.EnterID > 0 ? UserReidsCache.GetUserLoginInfo(item.EnterID)?.AccountName ?? "" : "")){ },
                            new ExcelColumn(value: (item.CourseConsultantId > 0 ? UserReidsCache.GetUserLoginInfo(item.CourseConsultantId)?.AccountName ?? "" : "")){ },
                            new ExcelColumn(value: (item.HelpEnterId > 0 ? UserReidsCache.GetUserLoginInfo(item.HelpEnterId)?.AccountName ?? "" : "")){ },
                            new ExcelColumn(value: item.ClassName){ },
                            new ExcelColumn(value: item.OpenTime.ToString("yyyy-MM-dd")){ },
                            new ExcelColumn(value: item.CourseName){ },
                            new ExcelColumn(value: item.GuestNum.ToString()){ },
                            new ExcelColumn(value: item.Class_Price.ToString("#0.00")){ },
                            new ExcelColumn(value: item.Unit_Price.ToString("#0.00")){ },
                            new ExcelColumn(value: item.PreferPrice.ToString("#0.00")){ },
                            new ExcelColumn(value: item.Income.ToString("#0.00")){ },
                            new ExcelColumn(value: item.DiscountMoney.ToString("#0.00")){ },
                            new ExcelColumn(value: item.LessPrice.ToString("#0.00")){ },
                            new ExcelColumn(value: item.Refund.ToString("#0.00")){ },
                            new ExcelColumn(value: item.PlatformTax.ToString("#0.00")){ },
                            new ExcelColumn(value: item.DueInMoney.ToString("#0.00")){ },
                            new ExcelColumn(value: item.OrderState.ToName()){ },
                            new ExcelColumn(value: GuestNameStr){ },
                            new ExcelColumn(value: item?.SaleRemarkList.FirstOrDefault()?.Content??""){ },
                            new ExcelColumn(value: item?.TeacherRemarkList.FirstOrDefault()?.Content??""){ },
                            new ExcelColumn(value: item?.RectorRemarkList.FirstOrDefault()?.Content??""){ },
                            new ExcelColumn(value: item?.DirectorRemarkList.FirstOrDefault()?.Content??""){ },
                            new ExcelColumn(value: item.ClassScrollType == 2 ?"约课":"跟班"){ },
                        }
                    };
                    slist.Add(firstRow);
                }

                ExcelDataSource firstRowT = new ExcelDataSource(30)
                {
                    ExcelRows = new List<ExcelColumn>()
                        {
                            new ExcelColumn(value: "合计"){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: list.Sum(x=>x.GuestNum).ToString()){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: list.Sum(x=>x.PreferPrice).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.Income).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.DiscountMoney).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.LessPrice).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.Refund).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.PlatformTax).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.DueInMoney).ToString("#0.00")){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                        }
                };
                slist.Add(firstRowT);

                var byteData = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData, "application/octet-stream", ExcelName);
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, "OutToExcelOrderStudentClassHoursList");
                var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData1, "application/octet-stream", ExcelName);
            }
        }

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

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

        /// <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.CreateBy,
                    CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy)?.AccountName ?? "",
                    x.CourseConsultantId,
                    ConsultantName = UserReidsCache.GetUserLoginInfo(x.CourseConsultantId)?.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,
                    x.HelpEnterId,
                    HelpEnterName = UserReidsCache.GetUserLoginInfo(x.HelpEnterId)?.AccountName,
                    x.GeneralOccupation,
                    x.EduOccupation,
                    x.IsLessPrice,
                    x.LessPrice,
                    x.OrderNature,
                    OrderNatureName = x.OrderNature.ToName(),
                    x.OldPreferPrice,
                    x.LXConfirmState,
                    x.LXConfirmDate,
                    x.LXConfirmEmpId,
                    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.CreateBy,
                    CreateByName = UserReidsCache.GetUserLoginInfo(x.CreateBy)?.AccountName ?? "",
                    x.CourseConsultantId,
                    ConsultantName = UserReidsCache.GetUserLoginInfo(x.CourseConsultantId)?.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,
                    x.HelpEnterId,
                    HelpEnterName = UserReidsCache.GetUserLoginInfo(x.HelpEnterId)?.AccountName,
                    x.GeneralOccupation,
                    x.EduOccupation,
                    x.IsLessPrice,
                    x.LessPrice,
                    x.OrderNature,
                    OrderNatureName = x.OrderNature.ToName(),
                    x.OldPreferPrice,
                    x.LXConfirmDate,
                    x.LXConfirmEmpId,
                    x.LXConfirmState,
                    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>
        /// 获取我的留学就业订单列表  Excel导出
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Obsolete]
        public FileContentResult GetStudyOrderPageListStatisticsToExcel()
        {
            List<ExcelDataSource> slist = new List<ExcelDataSource>();
            ExcelDataSource header = new ExcelDataSource()
            {
                ExcelRows = new List<ExcelColumn>(30) {
                    new ExcelColumn(value:"订单号"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"下单日期"){CellWidth=20,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"业务员"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"项目"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"人数"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"单价"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"成交单价"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"应收总额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"实收"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"优惠金额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"少价金额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"退款"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"平台税金"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"待收金额"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"状态"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"学生名单"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"销售备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"教务备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"校长备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                    new ExcelColumn(value:"经理备注"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                }
            };
            slist.Add(header);
            string ExcelName = "留学就业统计" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";

            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 list = orderModule.GetStudyOrderPageModule(1, 100000, out long count, demodel);

            try
            {
                foreach (var item in list)
                {
                    item.DueInMoney = item.PreferPrice - (item.Income - item.Refund + item.PlatformTax + item.DiscountMoney);
                    string GuestNameStr = string.Join(",", item?.GuestList.Select(x => x.GuestName));
                    ExcelDataSource firstRow = new ExcelDataSource(30)
                    {
                        ExcelRows = new List<ExcelColumn>()
                        {
                            new ExcelColumn(value: item.OrderId.ToString()){ },
                            new ExcelColumn(value: item.CreateTime.ToString("yyyy-MM-dd HH:mm")){ },
                            new ExcelColumn(value: item.EnterName){ },
                            new ExcelColumn(value: item.CourseName){ },
                            new ExcelColumn(value: item.GuestNum.ToString()){ },
                            new ExcelColumn(value: item.Class_Price.ToString("#0.00")){ },
                            new ExcelColumn(value: item.Unit_Price.ToString("#0.00")){ },
                            new ExcelColumn(value: item.PreferPrice.ToString("#0.00")){ },
                            new ExcelColumn(value: item.Income.ToString("#0.00")){ },
                            new ExcelColumn(value: item.DiscountMoney.ToString("#0.00")){ },
                            new ExcelColumn(value: item.LessPrice.ToString("#0.00")){ },
                            new ExcelColumn(value: item.Refund.ToString("#0.00")){ },
                            new ExcelColumn(value: item.PlatformTax.ToString("#0.00")){ },
                            new ExcelColumn(value: item.DueInMoney.ToString("#0.000000")){ },
                            new ExcelColumn(value: item.OrderState.ToName()){ },
                            new ExcelColumn(value: GuestNameStr){ },
                            new ExcelColumn(value: item?.SaleRemarkList.FirstOrDefault()?.Content??""){ },
                            new ExcelColumn(value: item?.TeacherRemarkList.FirstOrDefault()?.Content??""){ },
                            new ExcelColumn(value: item?.RectorRemarkList.FirstOrDefault()?.Content??""){ },
                            new ExcelColumn(value: item?.DirectorRemarkList.FirstOrDefault()?.Content??""){ },
                        }
                    };
                    slist.Add(firstRow);
                }

                ExcelDataSource firstRowT = new ExcelDataSource(30)
                {
                    ExcelRows = new List<ExcelColumn>()
                        {
                            new ExcelColumn(value: "合计"){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: list.Sum(x=>x.GuestNum).ToString()){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: list.Sum(x=>x.PreferPrice).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.Income).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.DiscountMoney).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.LessPrice).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.Refund).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.PlatformTax).ToString("#0.00")){ },
                            new ExcelColumn(value: list.Sum(x=>x.DueInMoney).ToString("#0.000000")){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                            new ExcelColumn(value: ""){ },
                        }
                };
                slist.Add(firstRowT);

                var byteData = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData, "application/octet-stream", ExcelName);
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, "OutToExcelOrderStudentClassHoursList");
                var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData1, "application/octet-stream", ExcelName);
            }
        }

        /// <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");
            string receiptFile = string.Empty;
            try
            {
                List<string> receiptFileList = Common.Plugin.JsonHelper.DeserializeObject<List<string>>(base.ParmJObj.GetStringValue("ReceiptFileList"));
                if (receiptFileList == null || !receiptFileList.Any())
                {
                    return ApiResult.Failed("附件必须上传");
                }
                else
                {
                    receiptFile = JsonHelper.Serialize(receiptFileList);
                }
            }
            catch (Exception ex)
            {
                Common.Plugin.LogHelper.Write(ex, "BackClassApply");
            }
            var BackAccountName = base.ParmJObj.GetStringValue("BackAccountName");
            var BackAccount = base.ParmJObj.GetStringValue("BackAccount");
            var StateMent = base.ParmJObj.GetStringValue("StateMent");

            bool flag = orderModule.CreateBackClassApplyModule(GuestId, OrderId, applyReason, base.UserInfo, receiptFile, BackAccountName, BackAccount, StateMent, out string message);
            return flag ? ApiResult.Success(message: message) : ApiResult.Failed(message: message);
        }
        #endregion

        #region 插班报入
        /// <summary>
        /// 获取插板报入配置信息
        /// </summary>
        /// <returns></returns>
        public ApiResult GetChaClassInfo()
        {
            var ClassId = base.ParmJObj.GetInt("ClassId");
            var otherClassList = orderModule.GetClassCourseListModule(ClassId);
            return ApiResult.Success(data: otherClassList);
        }

        #endregion

        #region 甲鹤小程序付款的课程同步过来
        /// <summary>
        /// 新增修改订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Microsoft.AspNetCore.Authorization.AllowAnonymous]
        public ApiResult SetBatchClassOrder()
        {
            Model.CacheModel.UserInfo userinfo = new Model.CacheModel.UserInfo();
            int EnterID = base.ParmJObj.GetInt("EnterID");
            List<RB_Order_ViewModel> list = JsonHelper.DeserializeObject<List<RB_Order_ViewModel>>(base.ParmJObj.GetStringValue("Order"));
            list.ForEach(x => x.TargetJoinType = OrderJoinTypeEnum.Normal);
            list.ForEach(x => x.JoinType = OrderJoinTypeEnum.Normal);
            list.ForEach(x => x.JoinType = OrderJoinTypeEnum.Normal);
            list.ForEach(x => x.OrderSource = OrderSourceEnum.MallApplet);
            list.ForEach(x => x.OrderType = OrderTypeEnum.CourseOrder);
            list.ForEach(x => x.Income = 0);
            if (EnterID > 0)
            {
                userinfo = UserReidsCache.GetUserLoginInfo(EnterID);
                list.ForEach(x => x.School_Id = userinfo.School_Id);
                list.ForEach(x => x.Group_Id = userinfo.Group_Id);
                list.ForEach(x => x.Dept_Id = userinfo.DeptId);
                list.ForEach(x => x.CreateBy = EnterID);
                list.ForEach(x => x.UpdateBy = EnterID);

            }
            else
            {
                userinfo.Group_Id = list.FirstOrDefault()?.Group_Id ?? 0;
            }
            list.ForEach(x => x.OrderForm = OrderFormEnum.Applet);
            list.ForEach(x => x.TradeWay = TradeWayEnum.OnLine);
            list.ForEach(x => x.CreateTime = DateTime.Now);
            list.ForEach(x => x.UpdateTime = DateTime.Now);
            list.ForEach(x => x.OrderState = OrderStateEnum.Normal);
            list.ForEach(x => x.StartClassHours = 0);
            var flag = false;
            flag = orderModule.SetBatchClassOrder(list, userinfo, false);

            return flag ? ApiResult.Success("") : ApiResult.Failed("");
        }




        /// <summary>
        /// 系统自动取消时同步规格库存
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Microsoft.AspNetCore.Authorization.AllowAnonymous]
        public ApiResult UpdateGoodsSpecification()
        {
            Model.CacheModel.UserInfo userinfo = new Model.CacheModel.UserInfo();

            List<int> list = JsonHelper.DeserializeObject<List<int>>(base.ParmJObj.GetStringValue("Order"));
            var flag = false;
            flag = orderModule.UpdateGoodsSpecification(list);
            return flag ? ApiResult.Success("") : ApiResult.Failed("");
        }



        #endregion

        #region 获取学员状态列表
        
        /// <summary>
        /// 获取学员状态列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGuestStateList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(GuestStateEnum));
            return ApiResult.Success(data: list);
        }
        #endregion
    }
}
