コード例 #1
0
ファイル: OrderService.cs プロジェクト: glustful/.NetProject
		public bool Delete(OrderEntity entity)
		{
			try
            {
                _orderRepository.Delete(entity);
                return true;
            }
            catch (Exception e)
            {
				_log.Error(e,"数据库操作出错");
                return false;
            }
		}
コード例 #2
0
ファイル: OrderService.cs プロジェクト: glustful/.NetProject
		public OrderEntity Update (OrderEntity entity)
		{
			try
            {
                _orderRepository.Update(entity);
                return entity;
            }
            catch (Exception e)
            {
				_log.Error(e,"数据库操作出错");
                return null;
            }
		}
コード例 #3
0
        public HttpResponseMessage Post([FromBody]OrderModel model)
        {
            //获取订单明细对应的商品
            var products = _productService.GetProductsByCondition(new ProductSearchCondition
            {
                Ids = model.Details.Select(c => c.Product.Id).ToArray(),
                Type = EnumProductType.Product
            }).ToList().Select(p => new OrderDetailEntity
            {
                Count = model.Details.First(d => d.Product.Id == p.Id).Count,
                Product = p,
                UnitPrice = p.Price,
                Adddate = DateTime.Now,
                Adduser = _workContext.CurrentUser.Id,
                ProductName = p.Name,
                Remark = "",
                Snapshoturl = "",
                Totalprice = model.Details.First(d => d.Product.Id == p.Id).Count * p.Price,
                Upddate = DateTime.Now,
                Upduser = _workContext.CurrentUser.Id
            }).ToList();
            if (products.Count < 1)
                return PageHelper.toJson(PageHelper.ReturnValue(false, "没有找到商品信息"));

            //订单编号
            Random rd = new Random();
            var orderNumber = "O" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + rd.Next(100, 999);

            var entity = new OrderEntity
            {
                No = orderNumber,
                Status = EnumOrderStatus.Created,
                CustomerName = model.CustomerName,
                Remark = model.Remark,
                AddDate = DateTime.Now,
                AddUser = _workContext.CurrentUser.Id,
                UpdUser = _workContext.CurrentUser.Id,
                UpdDate = DateTime.Now,
                Totalprice = products.Sum(c => (c.Count * c.UnitPrice)),
                Actualprice = products.Sum(c => (c.Count * c.UnitPrice)),
                Details = products,
                Address = _memberAddressService.GetMemberAddressById(model.MemberAddressId),
                AddMember = _memberService.GetMemberByUserId(_workContext.CurrentUser.Id)
            };
            if (_orderService.Create(entity).Id > 0)
            {
                //TODO:回掉接口写到Msg里,完成回掉方法
                return PageHelper.toJson(PageHelper.ReturnValue(true, "http://chuanyueyun.wicp.net/Zerg/api/Alipay/Success", new OrderModel
                {
                    Id = entity.Id,
                    No = entity.No,
                    Actualprice = entity.Actualprice,
                    Adddate = entity.AddDate,
                    CustomerName = entity.CustomerName
                }));
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "生成订单出错,请联系管理员"));
        }