Example #1
0
        public JsonResult AjaxSubmitCheckout(CheckOutContext context)
        {
            if (context == null)
            {
                return(Json(BuildAjaxErrorObject("无效的请求")));
            }

            ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCreateNew();

            //优先从购买商品参数来构建购物车对象
            if (!String.IsNullOrWhiteSpace(context.ShoppingItemParam))
            {
                String[] shoppingItemParams = context.ShoppingItemParam.Split(new char[] { '|' });
                if (shoppingItemParams.Length == 2)
                {
                    shoppingCart = ShoppingStorageManager.GetShoppingCartFromParam(shoppingItemParams[0], shoppingItemParams[1]);
                }
            }
            //其次从cookie中来构建购物车对象
            if (ShoppingCartIsEmpty(shoppingCart))
            {
                shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();
            }

            if (ShoppingCartIsEmpty(shoppingCart))
            {
                return(Json(new { url = PageHelper.BuildUrl("ShoppingCart") }));
            }

            CheckOutResult result = ShoppingFacade.SubmitCheckout(context, shoppingCart, CurrUser.UserSysNo, SOSource.Wechat);

            if (result.HasSucceed)
            {
                //取得订单编号列表
                List <int> soSysNoList = result.OrderProcessResult.ReturnData.SubOrderList.Select(subOrder => subOrder.Value.ID).ToList();
                ShoppingStorageManager.SaveLatestSO(soSysNoList);
                //团购订单数据不是来自cookie,不能清除cookie
                if (!result.OrderProcessResult.ReturnData.SubOrderList.Any(x => x.Value.SOType == (int)SOType.GroupBuy))
                {
                    ShoppingStorageManager.RemoveShoppingCartCookie();
                }
                return(Json(new { url = PageHelper.BuildUrl("Thankyou", result.OrderProcessResult.ReturnData.ShoppingCartID) }));
            }

            return(Json(new { error = true, messages = result.ErrorMessages }));
        }