Beispiel #1
0
        public ActionResult SubmitPreSaleOrder(PreSaleOrderViewModel preSaleOrderViewModel)
        {
            var jsonResult = new JsonResult();

            if (!string.IsNullOrEmpty(preSaleOrderViewModel.InviteCode))
            {
                preSaleOrderViewModel.InviteCode = preSaleOrderViewModel.InviteCode.Replace(" ", "");
            }
            var preSaleOrder = new PreSaleOrder
            {
                OrderId         = preSaleOrderViewModel.OrderId,//OrderService.GetNewOrderId(),
                UserId          = this.UserInfo.UserId,
                ProductId       = preSaleOrderViewModel.PreSaleProduct.ProductId,
                Price           = preSaleOrderViewModel.PreSaleProduct.Price,
                Count           = preSaleOrderViewModel.Count,
                ProvinceId      = preSaleOrderViewModel.ProvinceId,
                CityId          = preSaleOrderViewModel.CityId,
                Code            = preSaleOrderViewModel.AreaId,
                Address         = preSaleOrderViewModel.Address,
                Status          = 0,
                CreateTime      = DateTime.Now,
                Receiver        = preSaleOrderViewModel.UserName,
                Phone           = preSaleOrderViewModel.Phone,
                TotalMoney      = preSaleOrderViewModel.Count * preSaleOrderViewModel.PreSaleProduct.Price,
                ExpressDelivery = string.Empty,
                InviteCode      = preSaleOrderViewModel.InviteCode
            };



            var result = PreSaleOrderService.SubmitPreSaleOrder(preSaleOrder);

            if (result > 0)
            {
                #region 微信支付所需数据计算
                var timeStamp = TenPayV3Util.GetTimestamp();
                var nonceStr  = TenPayV3Util.GetNoncestr();
                var openId    = this.UserInfo.WxOpenId;
                var pre_id    = WeixinPay.WeixinPayApi.Unifiedorder(preSaleOrderViewModel.PreSaleProduct.Name,
                                                                    preSaleOrder.OrderId, preSaleOrder.Price * preSaleOrder.Count, Request.UserHostAddress, openId);
                if (pre_id == "ERROR" || pre_id == "FAIL")
                {
                    return(Content("ERROR"));
                }
                var package = "prepay_id=" + pre_id;

                var req = new RequestHandler(null);
                req.SetParameter("appId", AppId);
                req.SetParameter("timeStamp", timeStamp);
                req.SetParameter("nonceStr", nonceStr);
                req.SetParameter("package", package);
                req.SetParameter("signType", "MD5");
                var paySign = req.CreateMd5Sign("key", PayKey);


                #endregion

                preSaleOrderViewModel.NonceStr  = nonceStr;
                preSaleOrderViewModel.TimeStamp = timeStamp;
                preSaleOrderViewModel.Package   = package;
                preSaleOrderViewModel.AppId     = AppId;
                preSaleOrderViewModel.PaySign   = paySign;
            }
            else
            {
                preSaleOrderViewModel.OrderId = 0;
            }

            jsonResult.Data = preSaleOrderViewModel;
            return(jsonResult);
        }
Beispiel #2
0
        public ActionResult ConfirmPreSaleOrder(int productId)
        {
            PreSaleOrderViewModel preSaleOrderViewModel = new PreSaleOrderViewModel();


            preSaleOrderViewModel.OrderId = OrderService.GetNewOrderId();
            //预售商品
            preSaleOrderViewModel.PreSaleProduct = PreSaleProductService.GetPreSaleProduct(productId);

            preSaleOrderViewModel.PreSaleProduct.Details =
                JsonHelper.FromJson <List <PreSaleProductDetail> >(preSaleOrderViewModel.PreSaleProduct.DetailJson);
            foreach (var detail in preSaleOrderViewModel.PreSaleProduct.Details)
            {
                preSaleOrderViewModel.DetailsStr += string.Format("{0} {1}*{2}|", detail.Name, detail.Weight,
                                                                  detail.Count);
            }
            if (!string.IsNullOrEmpty(preSaleOrderViewModel.DetailsStr))
            {
                preSaleOrderViewModel.DetailsStr =
                    preSaleOrderViewModel.DetailsStr.Remove(preSaleOrderViewModel.DetailsStr.Length - 1, 1);
            }

            //加载地址及上一次订单地址
            var addresses = AddressService.GetAddresses();

            if (preSaleOrderViewModel.PreSaleProduct.BeiJinLimit == 1)
            {
                preSaleOrderViewModel.Provinces = addresses.Where(s => s.ParentCode == "" && (s.Code == "110000" || s.Code == "120000" || s.Code == "130000")).ToList();
            }
            else
            {
                preSaleOrderViewModel.Provinces = addresses.Where(s => s.ParentCode == "").ToList();
            }

            ////去除上一次的地址
            //var lastOrder = PreSaleOrderService.GetPreSaleOrderList(o=>o.UserId ==this.UserInfo.UserId,1, 1).Data.FirstOrDefault();
            //if (lastOrder != null)
            //{
            //    if (preSaleOrderViewModel.PreSaleProduct.BeiJinLimit == 1&& lastOrder.ProvinceId!= "110000")
            //    {
            //        preSaleOrderViewModel.ProvinceId = "110000";
            //    }
            //    else
            //    {
            //        preSaleOrderViewModel.ProvinceId = lastOrder.ProvinceId;
            //        preSaleOrderViewModel.CityId = lastOrder.CityId;
            //        preSaleOrderViewModel.AreaId = lastOrder.Code;
            //        preSaleOrderViewModel.Address = lastOrder.Address;
            //        preSaleOrderViewModel.UserName = lastOrder.Receiver;
            //        preSaleOrderViewModel.Phone = lastOrder.Phone;
            //    }

            //}
            ////OrderService.GetPreSaleOrderList(1, 1, 1);


            if (!string.IsNullOrEmpty(preSaleOrderViewModel.ProvinceId))
            {
                preSaleOrderViewModel.Cities =
                    addresses.Where(s => s.ParentCode == preSaleOrderViewModel.ProvinceId).ToList();
                if (!string.IsNullOrEmpty(preSaleOrderViewModel.AreaId))
                {
                    preSaleOrderViewModel.Areas =
                        addresses.Where(s => s.ParentCode == preSaleOrderViewModel.CityId).ToList();
                }
            }


            return(View(preSaleOrderViewModel));
        }