Ejemplo n.º 1
0
        public JsonResult editItem(OrderItem item)
        {
            using (DBContext db = new DBContext())
            {
                //判断订单是否存在
                Order order = db.Order.Where(q => q.ID.Equals(item.OrderId)).FirstOrDefault();

                if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); }

                if (order.Status == OrderStatus.Sended) { return Json(new { code = -2, msg = "订单已发货,无法修改" }); }

                if (order.Status == OrderStatus.Reject) { return Json(new { code = -3, msg = "订单已被驳回,无法修改" }); }

                OrderItem oldItem = db.OrderItem.Where(q => q.ID.Equals(item.ID)).FirstOrDefault();

                if (oldItem == null)
                {
                    return Json(new { code = -4, msg = "找不到对应商品" });
                }

                oldItem.Discount = item.Discount;
                oldItem.RealNumber = item.RealNumber;

                db.Entry(oldItem).State = EntityState.Modified;

                db.SaveChanges();
            }

            decimal pay = Order.RefreshPay(item.OrderId);

            return Json(new { code = 1, msg = "保存成功", pay = pay });
        }
Ejemplo n.º 2
0
        public JsonResult editItem(OrderItem item)
        {
            using (DBContext db = new DBContext())
            {
                //判断订单是否存在
                Order order = db.Order.Where(q => q.ID.Equals(item.OrderId)).FirstOrDefault();

                if (order == null) { return Json(new { code = -1, msg = "找不到对应订单" }); }

                if (order.Status > OrderStatus.BeforeSubmit && UserContext.store != null) { return Json(new { code = -2, msg = "您没有权限修改已提交过的订单" }); }

                if (order.Status == OrderStatus.Sended) { return Json(new { code = -3, msg = "订单已发货,无法修改" }); }

                if (order.Status == OrderStatus.Reject) { return Json(new { code = -4, msg = "订单已被驳回,无法修改" }); }

                //判断订单中是否已有此样商品
                OrderItem sameItem = db.OrderItem.Where(q => q.OrderId.Equals(item.OrderId) && q.ProductId.Equals(item.ProductId) && !q.ID.Equals(item.ID)).FirstOrDefault();

                if (sameItem != null) { return Json(new { code = -5, msg = "订单中已有相同商品" }); }

                OrderItem oldItem = db.OrderItem.Where(q => q.ID.Equals(item.ID)).FirstOrDefault();

                if (oldItem == null)
                {
                    Product product = db.Product.Where(q => q.ID.Equals(item.ProductId)).FirstOrDefault();

                    if (product == null) { return Json(new { code = -6, msg = "抱歉,找不到对应商品" }); }

                    item.ID = StringUtil.UniqueID();
                    item.ProductCode = product.ProductCode;
                    item.ProductName = product.ProductName;
                    item.Price = product.Price;
                    item.RealNumber = item.OrderNumber;

                    db.OrderItem.Add(item);
                }
                else
                {
                    oldItem.OrderNumber = item.OrderNumber;
                    oldItem.RealNumber = item.OrderNumber;

                    db.Entry(oldItem).State = EntityState.Modified;
                }

                db.SaveChanges();
            }

            Order.RefreshPay(item.OrderId);

            return Json(new { code = 1, msg = "保存成功" });
        }