Ejemplo n.º 1
0
        public ActionResult OrderCompleted(string gender, string lastName, string mealTime,
                                           string mealNumber, string tableNum)
        {
            ViewBag.Title = "Bojin's Restaurant Booking Online";
            var orderInfo = new OrderInfo();

            orderInfo.Gender     = gender;
            orderInfo.LastName   = lastName;
            orderInfo.MealTime   = Convert.ToDateTime(mealTime);
            orderInfo.MealNumber = mealNumber;

            orderInfo.CreateTime = DateTime.Now;
            orderInfo.Status     = OrderStatusEnum.Order;
            orderInfo.CustomerId = Int32.Parse(Session["userId"].ToString());
            orderInfo.TableNum   = Convert.ToInt32(tableNum);

            var result = new OrderResultModel();
            var items  = GetShoppingCartInfoFromCookie();

            if (items.Count == 0)
            {
                result.IsSuccess = false;
                return(View(result));
            }

            decimal totalPrice = 0;
            int     count      = 0;

            foreach (var item in items)
            {
                count      += item.Qty;
                totalPrice += (item.Qty * item.Price);
            }

            orderInfo.TotalPrice = totalPrice;
            orderInfo.ItemsCount = count;
            var orderId = String.Empty;

            var createResult = new OrderBuss().CreateOrder(orderInfo, items, out orderId);


            if (createResult == true)
            {
                HttpCookie aCookie = Request.Cookies["shoppingCart"];
                aCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(aCookie);

                result.IsSuccess   = true;
                result.OrderCode   = orderId;
                result.OrderAmount = orderInfo.TotalPrice;
            }
            else
            {
                result.IsSuccess = false;
            }

            return(View(result));
        }
Ejemplo n.º 2
0
        public OrderResultModel CreateOrder(string userId, OrderModel order)
        {
            if (_orderRepo.FindById(order.OrderId) != null)
            {
                throw new Exception($"Order already exists: {order.OrderId}");
            }

            var newOrder = _orderRepo.Create(new Order()
            {
                CreatedAt = DateTime.UtcNow,
                CreatedBy = userId,
                OrderId   = order.OrderId,
                ShopId    = order.ShopId
            });

            var users = _userRepository.FindAll(new[] { userId }).ToList();

            return(OrderResultModel.FromOrder(newOrder, users));
        }
Ejemplo n.º 3
0
        public OrderResultModel GetOrder(string orderId)
        {
            var order = _orderRepo.FindById(orderId);

            if (order == null)
            {
                return(null);
            }

            var users          = new List <AlipayUser>();
            var relatedUserIds = order.OrderItems.Select(x => x.CreatedBy).ToList();

            relatedUserIds.Add(order.CreatedBy);
            if (relatedUserIds.Any())
            {
                users = _userRepository.FindAll(relatedUserIds.ToArray()).ToList();
            }

            var result = OrderResultModel.FromOrder(order, users);

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  微信支付专用逻辑
        /// </summary>
        /// <returns></returns>
        public ActionResult WxPay()
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            ViewBag.OrderNo    = Request.QueryString["orderNo"].ToString();
            ViewBag.TotalPrice = double.Parse(Request.QueryString["totalprice"].ToString());

            OrderResultModel orm = new OrderResultModel();

            orm.openid           = System.Web.HttpContext.Current.Session["member"].ToString();
            orm.total_fee        = double.Parse(Request.QueryString["totalprice"].ToString()) * 100;
            orm.trade_type       = "JSAPI";
            orm.spbill_create_ip = Request.QueryString["ip"].ToString();
            orm.out_trade_no     = Request.QueryString["orderNo"].ToString();
            orm.appid            = WxPayAPI.WxPayConfig.APPID;
            orm.body             = "捷诚宝商城";
            orm.mch_id           = WxPayAPI.WxPayConfig.MCHID;
            orm.nonce_str        = WxPayAPI.WxPayApi.GenerateNonceStr();
            orm.notify_url       = HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Host + ":" + HttpContext.Request.Url.Port + "/Pay/WxPayResult";

            WxPayAPI.WxPayData data = new WxPayAPI.WxPayData();
            data.SetValue("openid", orm.openid);
            data.SetValue("total_fee", orm.total_fee);
            data.SetValue("trade_type", orm.trade_type);
            data.SetValue("spbill_create_ip", orm.spbill_create_ip);
            data.SetValue("out_trade_no", orm.out_trade_no);
            data.SetValue("appid", orm.appid);
            data.SetValue("body", orm.body);
            data.SetValue("mch_id", orm.mch_id);
            data.SetValue("nonce_str", orm.nonce_str);
            data.SetValue("notify_url", orm.notify_url);



            orm.sign = data.MakeSign();


            data.SetValue("sign", orm.sign);

            foreach (var item in data.GetValues())
            {
                LogHelper.Log.Write(item.Key + ":" + item.Value);
            }

            string xml      = data.ToXml();
            string response = WxPayAPI.HttpService.Post(xml, url, false, 5);

            WxPayAPI.WxPayData result = new WxPayAPI.WxPayData();
            result.FromXml(response);

            WxPayAPI.WxPayData jsApiParam = new WxPayAPI.WxPayData();
            jsApiParam.SetValue("appId", result.GetValue("appid"));
            jsApiParam.SetValue("timeStamp", WxPayAPI.WxPayApi.GenerateTimeStamp());
            jsApiParam.SetValue("nonceStr", WxPayAPI.WxPayApi.GenerateNonceStr());
            jsApiParam.SetValue("package", "prepay_id=" + result.GetValue("prepay_id"));
            jsApiParam.SetValue("signType", "MD5");
            jsApiParam.SetValue("paySign", jsApiParam.MakeSign());

            string jsonParam = jsApiParam.ToJson();

            ViewData["Result"]     = result;
            ViewData["JsonResult"] = jsonParam;

            return(View());
        }
Ejemplo n.º 5
0
        public ActionResult RechargePay(double money, string ip)
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            string orderNo = Guid.NewGuid().ToString().Replace("-", "").ToUpper().Substring(0, 6) + TimeManager.GetCurrentTimestamp();

            ViewBag.OrderNo    = orderNo;
            ViewBag.TotalPrice = money;

            OrderResultModel orm = new OrderResultModel();

            orm.openid           = System.Web.HttpContext.Current.Session["member"].ToString();
            orm.total_fee        = money * 100;
            orm.trade_type       = "JSAPI";
            orm.spbill_create_ip = ip;
            orm.out_trade_no     = orderNo;
            orm.appid            = WxPayAPI.WxPayConfig.APPID;
            orm.body             = "捷诚宝个人中心充值";
            orm.mch_id           = WxPayAPI.WxPayConfig.MCHID;
            orm.nonce_str        = WxPayAPI.WxPayApi.GenerateNonceStr();

            orm.notify_url = HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Host + ":" + HttpContext.Request.Url.Port + "/Pay/RechargePayResult";

            LogHelper.Log.Write(orm.notify_url);

            WxPayAPI.WxPayData data = new WxPayAPI.WxPayData();
            data.SetValue("openid", orm.openid);
            data.SetValue("total_fee", orm.total_fee);
            data.SetValue("trade_type", orm.trade_type);
            data.SetValue("spbill_create_ip", orm.spbill_create_ip);
            data.SetValue("out_trade_no", orm.out_trade_no);
            data.SetValue("appid", orm.appid);
            data.SetValue("body", orm.body);
            data.SetValue("mch_id", orm.mch_id);
            data.SetValue("nonce_str", orm.nonce_str);
            data.SetValue("notify_url", orm.notify_url);



            orm.sign = data.MakeSign();


            data.SetValue("sign", orm.sign);

            //LogHelper.Log.Write("openid:" + data.GetValue("openid"));
            //LogHelper.Log.Write("total_fee:" + data.GetValue("total_fee"));
            //LogHelper.Log.Write("appid:" + data.GetValue("appid"));

            //LogHelper.Log.Write("notify_url:" + data.GetValue("notify_url"));

            string xml      = data.ToXml();
            string response = WxPayAPI.HttpService.Post(xml, url, false, 5);

            WxPayAPI.WxPayData result = new WxPayAPI.WxPayData();
            result.FromXml(response);

            WxPayAPI.WxPayData jsApiParam = new WxPayAPI.WxPayData();
            jsApiParam.SetValue("appId", result.GetValue("appid"));
            jsApiParam.SetValue("timeStamp", WxPayAPI.WxPayApi.GenerateTimeStamp());
            jsApiParam.SetValue("nonceStr", WxPayAPI.WxPayApi.GenerateNonceStr());
            jsApiParam.SetValue("package", "prepay_id=" + result.GetValue("prepay_id"));
            jsApiParam.SetValue("signType", "MD5");
            jsApiParam.SetValue("paySign", jsApiParam.MakeSign());

            string jsonParam = jsApiParam.ToJson();

            ViewData["Result"]     = result;
            ViewData["JsonResult"] = jsonParam;

            return(View());
        }
Ejemplo n.º 6
0
 public void DisplaySuccess(OrderResultModel orderRequestModel)
 {
     IsError = false;
 }
Ejemplo n.º 7
0
 public OrderDto(OrderResultModel resultModel = null)
 {
     //TODO: if resultModel != null, then map it to the properties
 }