Exemple #1
0
        /// <summary>
        /// 获取支付二维码
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="voucherIds">支付使用的优惠券Id</param>
        /// <param name="paytype">支付渠道(支付宝、微信)</param>
        /// <returns></returns>
        public JsonResult GetWechatPayQR(int orderId = 0, int[] voucherIds = null, int paytype = 1)
        {
            int    studentId = 0;
            string ip        = "";
            //当前登录用户
            LoginInfo studentInfo = GetCurrentUser();

            if (studentInfo != null)
            {
                studentId = studentInfo.StudentId;
                ip        = studentInfo.LastLoginIP;
            }
            StudentOrderBll studentOrderBll = new StudentOrderBll();
            DtoPreOrderPay  response        = studentOrderBll.PreOrderPay(orderId, studentId, voucherIds, ip, paytype);

            return(Json(new JsonResponse <dynamic>
            {
                State = response.State,
                ErrorCode = 0,
                ErrorMsg = response.ErrorMsg,
                Data = new
                {
                    QR = response.Base64Img,
                    IsFreeOrder = response.IsFreeOrder
                }
            }, JsonRequestBehavior.AllowGet));
        }
 public DtoPreOrderPay PreOrderPay(int orderId, int studentId, int[] voucherIds, string ip, int paytype)
 {
     DtoPreOrderPay response = new DtoPreOrderPay();
     DtoSelectCenterOrderResult courseOrderResult = GetOrderInfoForPayment(studentId, orderId);
     if (courseOrderResult.OrderStatus.Equals((int)StudentOrderStatus.待支付) || courseOrderResult.OrderStatus.Equals((int)StudentOrderStatus.支付中))
     {
         //查询用户是否已购买此课程
         var oriOrder = GetFinishOrder(studentId, courseOrderResult.CourseId);
         if (oriOrder != null && oriOrder.Yod_Id > 0)
         {
             //已购买,不再生成付款码
             response.State = false;
             response.ErrorMsg = "你已购买此课程。";
         }
         else
         {
             if (CashPayTypeEnum.微信.Equals((CashPayTypeEnum)paytype))
             {
                 //支付二维码图片
                 byte[] qrImage = null;
                 bool isFreeOrder = false;
                 bool unifiedOrderResult = WechatOrderPay(orderId, studentId, voucherIds, ip, ref qrImage, ref isFreeOrder);
                 response.State = true;
                 response.IsFreeOrder = isFreeOrder;
                 if (unifiedOrderResult)
                 {
                     response.Base64Img = Convert.ToBase64String(qrImage);
                 }
                 else if (!isFreeOrder)
                 {
                     throw new AbhsException(ErrorCodeEnum.WechatPrePayError, AbhsErrorMsg.ConstWechatPrePayError);
                 }
             }
             else
             {
                 throw new AbhsException(ErrorCodeEnum.PayTypeError, AbhsErrorMsg.PayTypeError);
             }
         }
     }
     else if (courseOrderResult.OrderStatus.Equals((int)StudentOrderStatus.已支付))
     {
         response.State = false;
         response.ErrorMsg = "此订单已支付。";
     }
     else
     {
         response.State = false;
         response.ErrorMsg = "此订单已超时。";
     }
     return response;
 }