コード例 #1
0
        // 创建收货信息
        // public string createReceiveInformation(string buyerid, string receiverName, string phone, string country, string province, string city, string receivedId, string district, string detailAddr)
        public string createReceiveInformation(string buyerid, string receiverName, string phone, string detailAddr, string tag)
        {
            // 收货信息Id生成
            CreateIdCount receivedCount = new CreateIdCount(_context);
            string        receivedid    = receivedCount.GetOrderCount();

            ReceiveInformation receiveInformation = new ReceiveInformation
            {
                ReceivedId   = receivedid,
                Phone        = phone,
                ReceiverName = receiverName,
                BuyerId      = buyerid,
                Country      = "1",
                Province     = "2",
                City         = "3",
                District     = "4",
                DetailAddr   = detailAddr,
                Tag          = tag
            };

            _context.ReceiveInformations.Add(receiveInformation);

            if (_context.SaveChanges() > 0)
            {
                return(receivedid);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        // 从商品详情页面创建订单
        public bool CreateOrderFromDetail(string buyerid, string commodityid, string receivedId, int amount, decimal price)
        {
            // OrderId生成
            CreateIdCount orderCount = new CreateIdCount(_context);
            string        orderId    = orderCount.GetOrderCount();

            Global.GOrderID.Clear();
            Global.GOrderID.Add(orderId);
            Commodity commodity = _context.Commodities.Where(x => x.CommodityId == commodityid).FirstOrDefault();

            // 创建联系集 - 初始时商品状态为待付款
            OrdersCommodity ordersCommodity = new OrdersCommodity {
                OrdersId = orderId, CommodityId = commodityid, Status = COrders.ToBePay, Amount = amount
            };

            _context.OrdersCommodities.Add(ordersCommodity);

            // 创建Order —— 初始状态为待付款
            Order order = new Order
            {
                OrdersId    = orderId,
                BuyerId     = buyerid,
                OrdersDate  = DateTime.Now,
                Status      = COrders.ToBePay,
                ShopId      = commodity.ShopId,
                ReceivedId  = receivedId,
                Orderamount = price
            };

            _context.Orders.Add(order);
            if (_context.SaveChanges() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
 // 从购物车页面创建订单
 public bool CreateOrderFromChart(string buyerId, List <Good> cartCommodityList, string receivedId, decimal price)
 {
     if (buyerId == "" || cartCommodityList.Count == 0 || receivedId == "" || price == 0)
     {
         return(false);
     }
     else
     {
         List <Commodity> commodityList = new List <Commodity>();
         List <Shop>      shopList      = new List <Shop>();
         Global.GOrderID.Clear();
         CreateIdCount create   = new CreateIdCount(_context);
         decimal       oldPrice = 0;
         foreach (Good cartCommodity in cartCommodityList)
         {
             Commodity newCommodity = _context.Commodities.FirstOrDefault(c => c.CommodityId == cartCommodity.ID);
             Shop      newShop      = _context.Shops.FirstOrDefault(s => s.Name == cartCommodity.shop);
             oldPrice = oldPrice + ((int)newCommodity.Price) * cartCommodity.Soldnum;
             commodityList.Add(newCommodity);
             if (shopList.Any(s => s.ShopId == newShop.ShopId) == false)
             {
                 shopList.Add(_context.Shops.FirstOrDefault(s => s.ShopId == newShop.ShopId));
             }
             AddShoppingCart scCommodity = _context.AddShoppingCarts.FirstOrDefault(a => a.CommodityId == cartCommodity.ID && a.BuyerId == buyerId);
             _context.AddShoppingCarts.Remove(scCommodity);
         }
         List <BuyerCoupon> couponList = _context.BuyerCoupons.Where(c => c.BuyerId == buyerId).ToList();
         foreach (BuyerCoupon newBuyerCoupon in couponList)
         {
             Coupon newCoupon = _context.Coupons.FirstOrDefault(c => c.CouponId == newBuyerCoupon.CouponId);
             if (newCoupon.Threshold <= oldPrice && newCoupon.Discount1 == (oldPrice - price))
             {
                 newBuyerCoupon.Amount--;
                 if (newBuyerCoupon.Amount == 0)
                 {
                     _context.BuyerCoupons.Remove(newBuyerCoupon);
                 }
                 else
                 {
                     _context.BuyerCoupons.Update(newBuyerCoupon);
                 }
             }
         }
         decimal discountNumber = price / shopList.Count;
         foreach (Shop newShop in shopList)
         {
             Order  newOrder   = new Order();
             string newOrderId = create.GetOrderCount();
             newOrder.OrdersId = newOrderId;
             Global.GOrderID.Add(newOrderId);
             newOrder.BuyerId    = buyerId;
             newOrder.ShopId     = newShop.ShopId;
             newOrder.OrdersDate = DateTime.Now;
             newOrder.Status     = COrders.ToBePay;
             newOrder.ReceivedId = receivedId;
             decimal amount = 0;
             foreach (Commodity newCommodity in commodityList)
             {
                 Good            newcart            = cartCommodityList.FirstOrDefault(c => c.ID == newCommodity.CommodityId);
                 OrdersCommodity newOrdersCommodity = new OrdersCommodity();
                 newOrdersCommodity.OrdersId    = newOrder.OrdersId;
                 newOrdersCommodity.CommodityId = newCommodity.CommodityId;
                 newOrdersCommodity.Status      = COrders.ToBePay;
                 newOrdersCommodity.Amount      = newcart.Soldnum;
                 _context.OrdersCommodities.Add(newOrdersCommodity);
                 if (newCommodity.ShopId == newShop.ShopId)
                 {
                     amount = amount + ((int)newCommodity.Price) * newcart.Soldnum;
                 }
             }
             amount = amount - (oldPrice - price) / discountNumber;
             newOrder.Orderamount = amount;
             _context.Orders.Add(newOrder);
         }
         if (_context.SaveChanges() > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }