using MyCode.Project.Domain.Message.Act.Common; using MyCode.Project.Domain.Message.Common; using MyCode.Project.Domain.Message.Request.Goods; using MyCode.Project.Domain.Message.Response.Goods; using MyCode.Project.Domain.Message.Response.Inventory; using MyCode.Project.Infrastructure.Common; using MyCode.Project.Infrastructure.Exceptions; using MyCode.Project.Services; using System; using System.Collections.Generic; using System.Web.Http; namespace MyCode.Project.WebApi.Areas.Wechat.Controllers { public class GoodsController : BaseWechatController { private IGoodsService _goodsService; private IShopInventoryAmountService _shopInventoryAmountService; private IOnlineGoodsService _onlineGoodsService; /// /// 初始化一个类型的实例 /// public GoodsController(IGoodsService goodsService, IShopInventoryAmountService shopInventoryAmountService, IOnlineGoodsService onlineGoodsService) { _goodsService = goodsService; _shopInventoryAmountService = shopInventoryAmountService; _onlineGoodsService = onlineGoodsService; } #region GetSellsPageList(销售商品列表)(已优化) /// /// 销售商品列表 /// /// 查询条件 /// [HttpPost] public PageResult GetSellsPageList(PagedSearch search) { return this._goodsService.GetSellsPageList(search, this.CurrentLogin.MerchantId); } #endregion #region GetBasDeptList(获取商品分类列表) /// /// 获取商品分类列表 /// /// [HttpGet] public List GetBasDeptList() { return this._goodsService.GetBasDeptList(); } #endregion #region GetShopInventoryAmount(根据店铺id返回店铺的库存) /// /// 根据店铺id返回店铺的库存 /// /// /// [HttpGet] public ShopInventoryAmountResp GetShopInventoryAmount(Guid? shopId) { if (shopId == null) { throw new BaseException("店铺没传"); } return _shopInventoryAmountService.GetShopInventoryAmount(shopId.Value); } #endregion #region GetGoodsStock(得到商品库存信息) /// /// 得到商品库存信息 /// /// 店铺id /// 搜索关键字 /// [HttpPost] public GoodsStockResp GetGoodsStock(GetGoodsStockRequest request) { return _onlineGoodsService.GetGoodsStock(request); } #endregion #region GetGoodsStockList(得到商品库存信息) /// /// 得到商品库存信息,-1表示没有找到数据;0表示没有库存;其它则返回正常的列表 /// /// [HttpPost] public dynamic GetGoodsStockList(GetGoodsStockRequest request) { var list = _onlineGoodsService.GetGoodsStockList(request); //-1表示找不到 if (list == null || list.Count == 0) { return -1; } list.RemoveAll(p => p.StockQty == 0); if (list == null || list.Count == 0) { return 0; } return list; } #endregion } }