示例#1
0
        /// <summary>
        /// 返回状态结果
        /// </summary>
        /// <param name="status"></param>
        /// <param name="sc"></param>
        /// <param name="ex">如果报错,记录错误信息</param>
        /// <returns></returns>
        private string getBackJson(int status, Song.Entities.Student_Course sc, Exception ex)
        {
            string json = "{";

            json += "'status':'" + status + "',";
            json += "'couid':'" + couid + "',";
            //当前学员的剩余钱数
            Song.Entities.Accounts st = Extend.LoginState.Accounts.CurrentUser;
            json += "'money':'" + (st != null ? st.Ac_Money : -1) + "',";
            //返回不为空
            if (sc != null)
            {
                json += "'startTime':'" + WeiSha.Common.Server.getTime(sc.Stc_StartTime) + "',";
                json += "'endTime':'" + WeiSha.Common.Server.getTime(sc.Stc_EndTime) + "',";
            }
            if (ex != null)
            {
                //写入错误日志,并返回所在路径
                string path = WeiSha.Common.Log.Error("Course", ex);
                json += "'logfile':'" + path + "',";
                json += "'errinfo':'" + ex.Message + "',";
            }
            json += "'return_url':'" + return_url + "'";
            return(json + "}");
        }
示例#2
0
 /// <summary>
 /// 试用课程
 /// </summary>
 private void Try(Song.Entities.Course course, Song.Entities.Accounts st)
 {
     //如果不可以试用
     if (!course.Cou_IsFree && !course.Cou_IsTry)
     {
         //当课程不可以试用,直接退出
         Context.Response.Write(getBackJson(7, null, null));
         return;
     }
     else
     {
         try
         {
             Song.Entities.Student_Course sc = Business.Do <ICourse>().Tryout(st.Ac_ID, couid);
             Extend.LoginState.Accounts.Course(course);
             Context.Response.Write(getBackJson(0, sc, null));
             return;
         }
         catch (Exception ex)
         {
             Context.Response.Write(getBackJson(6, null, ex));
             return;
         }
     }
 }
 /// <summary>
 /// 免费购买
 /// </summary>
 /// <param name="course"></param>
 /// <param name="st"></param>
 private void FreeBuy(Song.Entities.Course course, Song.Entities.Accounts st)
 {
     //如果不是免费课程
     if (!course.Cou_IsFree)
     {
         //当课程不是免费的,直接退出
         Context.Response.Write(getBackJson(7, null, null));
         return;
     }
     else
     {
         try
         {
             //生成学员与课程的关联
             Song.Entities.Student_Course sc = Business.Do <ICourse>().FreeStudy(st.Ac_ID, couid);
             Extend.LoginState.Accounts.Course(course);
             Context.Response.Write(getBackJson(0, sc, null));
             return;
         }
         catch (Exception ex)
         {
             Context.Response.Write(getBackJson(6, null, ex));
             return;
         }
     }
 }
示例#4
0
        /// <summary>
        /// 返回状态结果
        /// </summary>
        /// <param name="status"></param>
        /// <param name="sc"></param>
        /// <returns></returns>
        private string getBackJson(int status, Song.Entities.Student_Course sc)
        {
            string json = "{";

            json += "'status':'" + status + "',";
            json += "'couid':'" + couid + "',";
            //当前学员的剩余钱数
            Song.Entities.Accounts st = Extend.LoginState.Accounts.CurrentUser;
            json += "'money':'" + (st != null ? st.Ac_Money : -1) + "',";
            if (sc != null)
            {
                json += "'startTime':'" + new WeiSha.Common.Param.Method.ConvertToAnyValue(sc.Stc_StartTime.ToString()).JavascriptTime + "',";
                json += "'endTime':'" + new WeiSha.Common.Param.Method.ConvertToAnyValue(sc.Stc_EndTime.ToString()).JavascriptTime + "',";
            }
            json += "'return_url':'" + return_url + "'";
            return(json + "}");
        }
示例#5
0
        /// <summary>
        /// 购买
        /// </summary>
        /// <param name="course"></param>
        /// <param name="st"></param>
        private void Buy(Song.Entities.Course course, Song.Entities.Accounts st)
        {
            //取图片验证码
            string imgCode = WeiSha.Common.Request.Cookies["buycode"].ParaValue;

            //验证码不正确
            if (veriCode != imgCode)
            {
                Context.Response.Write(getBackJson(2, null, null));
                return;
            }
            //价格项
            Song.Entities.CoursePrice price = Business.Do <ICourse>().PriceSingle(cpid);
            if (price == null)
            {
                Context.Response.Write(getBackJson(3, null, null));
                return;
            }
            //余额是否充足
            decimal money  = st.Ac_Money;     //资金余额
            int     coupon = st.Ac_Coupon;    //卡券余额
            int     mprice = price.CP_Price;  //价格,所需现金
            int     cprice = price.CP_Coupon; //价格,可以用来抵扣的卡券
            bool    tm     = money >= mprice || (money >= (mprice - cprice) && (coupon >= cprice));

            if (!tm)
            {
                Context.Response.Write(getBackJson(5, null, null));
                return;
            }
            //WeiSha.Common.Log.Write
            //开始实现购买
            try
            {
                Song.Entities.Student_Course sc = Business.Do <ICourse>().Buy(st.Ac_ID, couid, price);
                Extend.LoginState.Accounts.Course(course);
                Context.Response.Write(getBackJson(0, sc, null));
                return;
            }
            catch (Exception ex)
            {
                Context.Response.Write(getBackJson(6, null, ex));
                return;
            }
        }
        /// <summary>
        /// 生成json
        /// </summary>
        protected string _toJosn(List <Song.Entities.Course> courses, string action, int stid)
        {
            string tm = "{\"sum\":" + courses.Count + ",\"action\":\"" + action + "\",\"object\":[";

            for (int i = 0; i < courses.Count; i++)
            {
                Song.Entities.Course c = courses[i];
                c.Cou_LogoSmall = Upload.Get["Course"].Virtual + c.Cou_LogoSmall;
                c.Cou_Logo      = Upload.Get["Course"].Virtual + c.Cou_Logo;
                //是否免费,或是限时免费
                if (c.Cou_IsLimitFree)
                {
                    DateTime freeEnd = c.Cou_FreeEnd.AddDays(1).Date;
                    if (!(c.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now))
                    {
                        c.Cou_IsLimitFree = false;
                    }
                }
                c.Cou_Intro = c.Cou_Target = c.Cou_Content = "";
                c.Cou_Name  = c.Cou_Name.Replace("\"", "&quot;");
                //增加输出项
                Dictionary <string, object> addParas = new Dictionary <string, object>();
                addParas.Add("olcount", Business.Do <IOutline>().OutlineOfCount(c.Cou_ID, -1, true));                        //当前课程里的章节数
                addParas.Add("quscount", Business.Do <IQuestions>().QuesOfCount(c.Org_ID, c.Sbj_ID, c.Cou_ID, -1, 0, true)); //当前课程的试题
                //获取课程的购买信息
                Song.Entities.Student_Course sc = Business.Do <ICourse>().StudyCourse(stid, c.Cou_ID);
                if (sc != null)
                {
                    addParas.Add("starttime", sc.Stc_StartTime);
                    addParas.Add("endtime", sc.Stc_EndTime);
                }
                tm += "" + c.ToJson(null, null, addParas);
                if (i < courses.Count - 1)
                {
                    tm += ",";
                }
            }
            tm += "]}";
            return(tm);
        }
示例#7
0
 /// <summary>
 /// 免费购买
 /// </summary>
 /// <param name="course"></param>
 /// <param name="st"></param>
 private void FreeBuy(Song.Entities.Course course, Song.Entities.Accounts st)
 {
     //如果不是免费课程
     if (!course.Cou_IsFree)
     {
         //当课程不是免费的,直接退出
         Context.Response.Write(getBackJson(7, null, null));
         return;
     }
     else
     {
         //生成学员与课程的关联
         Song.Entities.Student_Course sc = Business.Do <ICourse>().StudyCourse(st.Ac_ID, couid);
         if (sc == null)
         {
             sc = new Entities.Student_Course();
         }
         sc.Cou_ID        = couid;
         sc.Ac_ID         = st.Ac_ID;
         sc.Stc_StartTime = DateTime.Now;
         sc.Stc_EndTime   = DateTime.Now.AddYears(101);
         sc.Stc_IsFree    = true;
         sc.Stc_IsTry     = false;
         try
         {
             Business.Do <ICourse>().Buy(sc);
             Extend.LoginState.Accounts.Course(course);
             Context.Response.Write(getBackJson(0, sc, null));
             return;
         }
         catch (Exception ex)
         {
             Context.Response.Write(getBackJson(6, null, ex));
             return;
         }
     }
 }