Ejemplo n.º 1
0
        public JsonResult SaveOrder(Models.m_YueBing model)
        {
            int orgID = int.Parse(DESEncrypt.Decrypt(ViewBag.EnOrgID));
            var goods = sellBLL.GetModel(model.goodsID);

            if (null == goods)
            {
                throw new Exception("该商品已达上限");
            }
            //if (goods.Balance.Value < model.Amount)
            //{
            //    return GetErrorResult("数量不足");
            //}
            ShiMiao.Model.TD_Shop_Order_Consignee consignee = new Model.TD_Shop_Order_Consignee();
            consignee.Address = model.useraddress;
            consignee.Name    = model.username;
            consignee.Phone   = model.userphone;

            var member = MemberData.GetMember();

            Model.TD_Shop_Order order = new Model.TD_Shop_Order();
            order.PayType     = Constants.PayType.WeiXin;
            order.MemberID    = member.MemberID;
            order.HeaderImage = member.HeaderImage;
            order.NickName    = member.NickName;
            order.OrderType   = (int)Constants.DonationType.Shop1;
            order.OrgID       = orgID;
            //月饼常规价格 + 快递费
            decimal ExtraPrice = 0;

            switch (model.ExtraPrice)
            {
            case 0:    //自提
                ExtraPrice = 0;
                break;

            case 1:    //省内
                ExtraPrice = 6;
                break;

            case 2:    //省外
                ExtraPrice = 8;
                break;

            default:    //其他
                ExtraPrice = 8;
                break;
            }
            order.ExtraPrice = ExtraPrice * model.Amount;
            order.OriPrice   = goods.Price * model.Amount + order.ExtraPrice;
            decimal realPrice = goods.Price.Value;

            if (model.Amount >= 5)
            {//优惠价格 + 快递费
                order.RealPrice = 88 * model.Amount + ExtraPrice * model.Amount;
                realPrice       = 88;
            }
            else
            {
                order.RealPrice = order.OriPrice;
            }
            order.Status = (int)Constants.OrderStatus.WaitPay;

            IList <Model.TD_Shop_OrderGoods> orderGoodsList = new List <Model.TD_Shop_OrderGoods>();

            Model.TD_Shop_OrderGoods orderGoods = new Model.TD_Shop_OrderGoods();
            orderGoods.GoodsID   = goods.GoodsID;
            orderGoods.Title     = goods.Title;
            orderGoods.Amount    = model.Amount;
            orderGoods.OrgID     = orgID;
            orderGoods.OriPrice  = goods.Price;
            orderGoods.RealPrice = realPrice;//goods.Price;
            orderGoodsList.Add(orderGoods);
            int result = orderBLL.Save(order, consignee, orderGoodsList);

            if (result > 0)
            {
                string url = string.Empty;
                if (order.PayType == Constants.PayType.WeiXin)
                {
                    url = "/WeiXinPay/PayForShop?oid=" + ViewBag.EnOrgID + "&orderid=" + order.OrderID + "&url=" + HttpUtility.UrlEncode("/Shop/YueBing/Index?oid=" + ViewBag.EnOrgID);
                }
                return(GetSucceedResult(new
                {
                    url = url
                }, ""));
            }
            else
            {
                return(GetErrorResult("保存失败,请稍候再试"));
            }
        }
Ejemplo n.º 2
0
        public JsonResult SaveOrder(Models.m_YueBing model)
        {
            int orgID = int.Parse(DESEncrypt.Decrypt(ViewBag.EnOrgID));

            Model.TD_Shop_Goods goods = goodsBLL.GetModel(model.goodsID);
            if (goods.Balance.Value < model.Amount)
            {
                return(GetErrorResult("数量不足"));
            }
            ShiMiao.Model.TD_Shop_Order_Consignee consignee = new Model.TD_Shop_Order_Consignee();
            consignee.Address        = model.Adress;
            consignee.Name           = model.username;
            consignee.Phone          = model.Phone;
            consignee.Identification = model.Identification;

            var member = MemberData.GetMember();

            Model.TD_Shop_Order order = new Model.TD_Shop_Order();
            order.PayType     = Constants.PayType.WeiXin;
            order.MemberID    = member.MemberID;
            order.HeaderImage = member.HeaderImage;
            order.NickName    = member.NickName;
            order.OrderType   = (int)Constants.DonationType.Shop1;
            order.OrgID       = orgID;
            //月饼常规价格 + 快递费
            order.OriPrice = goods.Price * model.Amount + model.ExtraPrice * model.Amount;
            if (model.Amount >= 5)
            {//优惠价格 + 快递费
                order.RealPrice = 88 * model.Amount + model.ExtraPrice * model.Amount;
            }
            else
            {
                order.RealPrice = order.OriPrice;
            }
            order.Status = (int)Constants.OrderStatus.WaitPay;

            IList <Model.TD_Shop_OrderGoods> orderGoodsList = new List <Model.TD_Shop_OrderGoods>();

            Model.TD_Shop_OrderGoods orderGoods = new Model.TD_Shop_OrderGoods();
            orderGoods.GoodsID   = goods.GoodsID;
            orderGoods.Title     = goods.Title;
            orderGoods.Amount    = model.Amount;
            orderGoods.OrgID     = orgID;
            orderGoods.OriPrice  = goods.Price;
            orderGoods.RealPrice = goods.Price;
            orderGoodsList.Add(orderGoods);
            int result = orderBLL.Save(order, orderGoodsList);

            if (result > 0)
            {
                string url = string.Empty;
                if (order.PayType == Constants.PayType.WeiXin)
                {
                    url = "/WeiXinPay/PayForShop?oid=" + ViewBag.EnOrgID + "&orderid=" + order.OrderID + "&url=" + HttpUtility.UrlEncode("/Shop/Goods2/Index?oid=" + ViewBag.EnOrgID);
                }
                return(GetSucceedResult(new
                {
                    url = url
                }, ""));
            }
            else
            {
                return(GetErrorResult("保存失败,请稍候再试"));
            }
        }