111 lines
3.7 KiB
C#
Raw Normal View History

2025-04-24 18:31:27 +08:00
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;
/// <summary>
/// 初始化一个<see cref="GoodsController"/>类型的实例
/// </summary>
public GoodsController(IGoodsService goodsService,
IShopInventoryAmountService shopInventoryAmountService,
IOnlineGoodsService onlineGoodsService)
{
_goodsService = goodsService;
_shopInventoryAmountService = shopInventoryAmountService;
_onlineGoodsService = onlineGoodsService;
}
#region GetSellsPageList()()
/// <summary>
/// 销售商品列表
/// </summary>
/// <param name="search">查询条件</param>
/// <returns></returns>
[HttpPost]
public PageResult<GoodsStockPageListResp> GetSellsPageList(PagedSearch<GoodsStockPageListQuery> search)
{
return this._goodsService.GetSellsPageList(search, this.CurrentLogin.MerchantId);
}
#endregion
#region GetBasDeptList()
/// <summary>
/// 获取商品分类列表
/// </summary>
/// <returns></returns>
[HttpGet]
public List<DeptListResp> GetBasDeptList()
{
return this._goodsService.GetBasDeptList();
}
#endregion
#region GetShopInventoryAmount(id返回店铺的库存)
/// <summary>
/// 根据店铺id返回店铺的库存
/// </summary>
/// <param name="shopId"></param>
/// <returns></returns>
[HttpGet]
public ShopInventoryAmountResp GetShopInventoryAmount(Guid? shopId)
{
if (shopId == null) { throw new BaseException("店铺没传"); }
return _shopInventoryAmountService.GetShopInventoryAmount(shopId.Value);
}
#endregion
#region GetGoodsStock()
/// <summary>
/// 得到商品库存信息
/// </summary>
/// <param name="shopId">店铺id</param>
/// <param name="key">搜索关键字</param>
/// <returns></returns>
[HttpPost]
public GoodsStockResp GetGoodsStock(GetGoodsStockRequest request)
{
return _onlineGoodsService.GetGoodsStock(request);
}
#endregion
#region GetGoodsStockList()
/// <summary>
/// 得到商品库存信息,-1表示没有找到数据0表示没有库存其它则返回正常的列表
/// </summary>
/// <returns></returns>
[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
}
}