public async Task <BaseApiResponse> AddGoods(AddGoodsRequest request) { request.CheckNotNull(nameof(request)); TryInitUserModel(); //创建商品 var goodsId = GuidUtil.NewSequentialId(); var command = new CreateGoodsCommand( goodsId, request.StoreId, request.CategoryIds, request.Name, request.Description, request.Pics, request.Price, request.OriginalPrice, request.Stock, request.IsPayOnDelivery, request.IsInvoice, request.Is7SalesReturn, request.Sort); var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } //初始化默认规格 var thumb = ""; if (request.Pics.Any()) { thumb = request.Pics[0]; } var command2 = new AddSpecificationCommand( goodsId, "默认规格", "默认规格", thumb, request.Price, request.Stock, request.OriginalPrice, request.OriginalPrice / 100M, "", ""); var result2 = await ExecuteCommandAsync(command2); if (!result2.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new AddGoodsResponse { GoodsId = goodsId }); }
public async Task <BaseApiResponse> StoreUpdateGoods(AddGoodsRequest request) { request.CheckNotNull(nameof(request)); TryInitUserModel(); var command = new StoreUpdateGoodsCommand( request.CategoryIds, request.Name, request.Description, request.Pics, request.Price, request.OriginalPrice, request.Stock, request.IsPayOnDelivery, request.IsInvoice, request.Is7SalesReturn, request.Sort) { AggregateRootId = request.Id }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } //更新默认规格 var specification = _goodsQueryService.GetGoodsDefaultSpecification(request.Id); if (specification != null) { var thumb = specification.Thumb; if (request.Pics.Any()) { thumb = request.Pics[0]; } //更新默认规格 var command2 = new UpdateSpecificationCommand( request.Id, specification.Id, "默认规格", "默认规格", thumb, request.Price, request.OriginalPrice, request.OriginalPrice / 100M, "", "", request.Stock); var result2 = await ExecuteCommandAsync(command2); if (!result2.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } } return(new BaseApiResponse()); }