public IActionResult OnPostSubmitTrial(string courseCode, int Lesson, string date)
        {
            ResultNormal result = new ResultNormal();
            var          times  = StaticDataSrv.TrialTime;

            try
            {
                var us = base.GetUserSession(false);
                if (us != null)
                {
                    var cls = _CourseSrv.GetCourseInfoClass(courseCode);

                    var errorMsg = _CourseSrv.VerifyUserTrial(us.OpenId, (int)cls.CourseType, date, Lesson);
                    if (errorMsg == EduErrorMessage.ApplyTrial_OverSingleLimit)
                    {
                        result.ErrorMsg = "同类型课不能试听超过2次";
                    }
                    else if (errorMsg == EduErrorMessage.ApplyTrial_SameTypeExist)
                    {
                        result.ErrorMsg = "同时段已经有申请试听";
                    }
                    else
                    {
                        ETrialLog log = new ETrialLog
                        {
                            OpenId = us.OpenId,
                            //UserName = us.UserName,
                            TecCode        = cls.TecCode,
                            TecName        = cls.TecName,
                            CourseCode     = cls.CourseCode,
                            CourseName     = cls.CourseName,
                            CourseType     = (int)cls.CourseType,
                            ApplyDateTime  = DateTime.Now,
                            Lesson         = Lesson,
                            TrialDateTime  = DateTime.Parse(date),
                            TrialLogStatus = (int)TrialLogStatus.UserApply,
                        };
                        _CourseSrv.AddTrial(log);
                        _CourseSrv.SaveChanges();
                    }
                }
                else
                {
                    result.IntMsg   = -1;
                    result.ErrorMsg = "需要您重新登录!";
                }
            }
            catch (Exception ex)
            {
                result.ErrorMsg = "提交申请失败,请联系工作人员";
                NLogHelper.ErrorTxt($"ApplyTrialModel[OnPostSubmitTrial]:{ex.Message}");
            }
            return(new JsonResult(result));
        }
Esempio n. 2
0
        public IActionResult OnPostUpdateTrial(RTrialLog updateTrial)
        {
            ResultNormal result = new ResultNormal();
            var          times  = StaticDataSrv.TrialTime;
            bool         needWX = false;

            try
            {
                if (updateTrial.Id <= 0)
                {
                    result.ErrorMsg = "没有找到试听课,无法保存!";
                }
                else
                {
                    ETrialLog origTrial = _CourseSrv.GetTrialLog(updateTrial.Id);

                    origTrial.Lesson        = updateTrial.Lesson;
                    origTrial.TrialDateTime = updateTrial.TrialDateTime;
                    origTrial.CourseCode    = updateTrial.CourseCode;

                    var cls = _CourseSrv.GetCourseInfoClass(origTrial.CourseCode);
                    origTrial.TecCode    = cls.TecCode;
                    origTrial.TecName    = cls.TecName;
                    origTrial.CourseType = (int)cls.CourseType;
                    origTrial.CourseName = cls.CourseName;

                    var ui = _UserSrv.GetUserInfo(updateTrial.OpenId);

                    ui.Phone       = updateTrial.UserPhone;
                    ui.SalesOpenId = updateTrial.SalesOpenId;

                    if (origTrial.TrialLogStatus == (int)TrialLogStatus.UserApply)
                    {
                        needWX = true;
                        origTrial.TrialLogStatus = (int)TrialLogStatus.TecConfirm;
                        //返佣
                    }
                    _CourseSrv.SaveChanges();

                    //微信发送
                    if (needWX)
                    {
                        TecTrialRemindTemplate wxMessage = new TecTrialRemindTemplate();
                        RTrialLog rTrialLog = new RTrialLog();
                        rTrialLog.InitFromETrialLog(origTrial);
                        rTrialLog.SalesOpenId  = updateTrial.SalesOpenId;
                        rTrialLog.SalesName    = updateTrial.SalesName;
                        rTrialLog.TrialTimeStr = times[rTrialLog.Lesson].TimeRange;
                        rTrialLog.UserRealName = ui.ChildName;
                        var teacher = _TecSrv.Get(origTrial.TecCode);
                        if (teacher != null)
                        {
                            //  teacher.UserOpenId = "oh6cV1QhPLj6XPesheYUQ4XtuGTs";
                            wxMessage.data = wxMessage.GenerateData(teacher.UserOpenId, rTrialLog);
                            result         = WXApi.SendTemplateMessage <TecTrialRemindTemplate>(wxMessage);
                            result.IntMsg  = 10;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.ErrorMsg = ex.Message;
            }

            return(new JsonResult(result));
        }