コード例 #1
0
        private EOrder CreateBuyCourseOrder(string userOpenId, ECoursePrice coursePrice)
        {
            EOrder order = null;

            try
            {
                order = new EOrder
                {
                    CreateDateTime = DateTime.Now,
                    CustOpenId     = userOpenId,
                    OrderStatus    = OrderStatus.Created,
                    OrderType      = OrderType.UserCourse,
                    OrderId        = EduCodeGenerator.GetOrderOrder(),
                };
                _dbContext.Add(order);

                EOrderLine line = new EOrderLine
                {
                    OrderId  = order.OrderId,
                    ItemCode = coursePrice.PriceCode,
                    ItemName = $"课时购买{coursePrice.PriceCode}_{coursePrice.CourseScheduleType}",
                    Price    = coursePrice.Price,
                    Qty      = coursePrice.Qty,
                    Ext1     = (int)coursePrice.CourseScheduleType,
                };
                _dbContext.Add(line);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(order);
        }
コード例 #2
0
        public IActionResult OnPostBuyCourse(string priceCode)
        {
            ResultObject <ECoursePrice> result = new ResultObject <ECoursePrice>();

            try
            {
                var us = GetUserSession(false);
                if (us != null)
                {
                    if (string.IsNullOrEmpty(us.Phone))
                    {
                        result.IntMsg   = -2;
                        result.ErrorMsg = "请先绑定您的手机号";
                        return(new JsonResult(result));
                    }
                    ECoursePrice eCoursePrice = _CourseSrv.GetCoursePrice(priceCode);
                    result.Entity = eCoursePrice;
                }
                else
                {
                    result.IntMsg   = -1;
                    result.ErrorMsg = "请先重新登录";
                }
            }
            catch (EduException eex)
            {
                result.ErrorMsg = eex.Message;
            }
            catch (Exception ex)
            {
                result.ErrorMsg = "购买失败,请联系客服!";
                NLogHelper.ErrorTxt($"购买课时[OnPostBuyCourse]:{ex.Message}");
            }
            return(new JsonResult(result));
        }
コード例 #3
0
        public void OnPostPayCourseTime()
        {
            Msg = "创建成功!";
            try
            {
                string openId = "o3nwE0qI_cOkirmh_qbGGG-5G6B0";

                ECoursePrice cp = _courseSrv.GetStandPrice();
                cp.Qty   = 10;
                cp.Price = 2000;

                List <EUserCourse> eUserCourses = new List <EUserCourse>();


                eUserCourses.Add(new EUserCourse
                {
                    CourseScheduleType = cp.CourseScheduleType,
                    LessonCode         = "2019_1_5_MS-1_1_Standard",
                    UserOpenId         = openId,
                });

                eUserCourses.Add(new EUserCourse
                {
                    CourseScheduleType = cp.CourseScheduleType,
                    LessonCode         = "2019_1_6_WQ-1_1_Standard",
                    UserOpenId         = openId,
                });

                eUserCourses.Add(new EUserCourse
                {
                    CourseScheduleType = cp.CourseScheduleType,
                    LessonCode         = "2019_2_5_SF-1_1_Standard",
                    UserOpenId         = openId,
                });

                //var order = _busSrv.PayCourseOrder(openId, cp);

                //_busSrv.PayCourseSuccess(order.OrderId);

                //_busSrv.UserSelectNewCourses(openId, eUserCourses);
            }
            catch (Exception ex)
            {
                Msg = ex.Message;
            }
        }
コード例 #4
0
        public EOrder PayCourseOrder(string userOpenId, ECoursePrice coursePrice)
        {
            try
            {
                //  BeginTrans();


                //检查用户是否已经购买暑假寒假
                if (coursePrice.CourseScheduleType == CourseScheduleType.Summer ||
                    coursePrice.CourseScheduleType == CourseScheduleType.Winter)
                {
                    var sql = from o in _dbContext.DBOrder
                              join l in _dbContext.DBOrderLine on o.OrderId equals l.OrderId
                              where o.OrderStatus == OrderStatus.PaySuccess && o.CustOpenId == userOpenId &&
                              l.ItemCode == coursePrice.PriceCode
                              select o.OrderId;

                    var item = sql.FirstOrDefault();
                    if (item != null)
                    {
                        var cstName = BaseEnumSrv.GetCourseScheduleTypeName(coursePrice.CourseScheduleType);
                        throw new EduException($"[{cstName}]只能购买一次,您已购买过");
                    }
                }

                //创建购买课时的订单
                var Order = CreateBuyCourseOrder(userOpenId, coursePrice);

                _dbContext.SaveChanges();

                //  CommitTrans();

                return(Order);
            }
            catch (Exception ex)
            {
                //  RollBackTrans();

                throw ex;
            }
        }
コード例 #5
0
        public WxPayOrder JSPay(int feeAmt, int courseTime)
        {
            WxPayOrder wxOrder = null;
            var        us      = GetUserSession(false);

            try
            {
                if (us != null)
                {
                    string   notifyUrl = "http://edu.iqiban.cn/api/wxPay/Notify";
                    JsApiPay jsApiPay  = new JsApiPay();
                    jsApiPay.openid    = us.OpenId;
                    jsApiPay.total_fee = feeAmt * 100;


                    string OrderNo = WxPayApi.GenerateOutTradeNo();
                    var    desc    = "扫码支付学费";
                    if (courseTime > 0)
                    {
                        desc += $"[{courseTime}]课时";
                    }
                    /* 生成 系统订单 */
                    ECoursePrice eCoursePrice = _CourseSrv.GetCoursePrice("VIP");
                    eCoursePrice.Qty   = courseTime;
                    eCoursePrice.Price = feeAmt;
                    var order = _BusinessSrv.PayCourseOrder(us.OpenId, eCoursePrice);

                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(desc, notifyUrl, OrderNo);
                    WxPayData wxJsApiParam       = jsApiPay.GetJsApiParameters();

                    wxOrder = new WxPayOrder()
                    {
                        appId      = wxJsApiParam.GetValue("appId").ToString(),
                        nonceStr   = wxJsApiParam.GetValue("nonceStr").ToString(),
                        package    = wxJsApiParam.GetValue("package").ToString(),
                        paySign    = wxJsApiParam.GetValue("paySign").ToString(),
                        signType   = "MD5",
                        timeStamp  = wxJsApiParam.GetValue("timeStamp").ToString(),
                        OrderNo    = OrderNo,
                        EduOrderNo = order.OrderId
                    };
                }
                else
                {
                    wxOrder = new WxPayOrder()
                    {
                        IntMsg    = -1,
                        IsSuccess = false,
                        ErrorMsg  = "请重新登陆",
                    };
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"JSPay:{ex.Message}");
                wxOrder = new WxPayOrder()
                {
                    IsSuccess = false,
                    ErrorMsg  = ex.Message,
                };
            }

            return(wxOrder);
        }