private static GoodsCarDTO ToDTO(GoodsCarEntity entity, string imgUrl) { GoodsCarDTO dto = new GoodsCarDTO(); dto.GoodsId = entity.GoodsId; dto.UserId = entity.UserId; dto.Code = entity.Goods.Code; dto.CreateTime = entity.CreateTime; dto.Description = entity.Goods.Description; dto.Id = entity.Id; if (string.IsNullOrEmpty(imgUrl)) { dto.ImgUrl = ""; } else { dto.ImgUrl = imgUrl; } dto.Name = entity.Goods.Name; dto.Price = entity.Goods.Price; dto.RealityPrice = entity.Goods.RealityPrice; dto.Standard = entity.Goods.Standard; dto.Number = entity.Number; dto.IsSelected = entity.IsSelected; dto.GoodsAmount = entity.Goods.RealityPrice * entity.Number; dto.Inventory = entity.Goods.Inventory; return(dto); }
public async Task <ApiResult> Place(OrderPlaceModel model) { GoodsCarDTO dto = new GoodsCarDTO(); var goods = await goodsService.GetModelAsync(model.GoodsId); if (goods == null) { return(new ApiResult { status = 0, msg = "商品不存在" }); } if (goods.Inventory < model.Number) { return(new ApiResult { status = 0, msg = "商品库存不足" }); } dto.GoodsId = model.GoodsId; dto.ImgUrl = goodsImgService.GetFirstImg(model.GoodsId); dto.Name = goods.Name; dto.Number = model.Number; dto.RealityPrice = goods.RealityPrice; dto.Price = goods.Price; User user = JwtHelper.JwtDecrypt <User>(ControllerContext); await orderApplyService.DeleteListAsync(user.Id); dto.UserId = user.Id; dto.GoodsAmount = dto.RealityPrice * dto.Number; long id = await orderApplyService.AddAsync(dto); if (id <= 0) { return(new ApiResult { status = 0, msg = "下单失败" }); } return(new ApiResult { status = 1, msg = "下单成功" }); }