152 lines
5.7 KiB
C#
152 lines
5.7 KiB
C#
using Infrastructure;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Enums;
|
|
using Infrastructure.Model;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ARW.Admin.WebApi.Extensions;
|
|
using ARW.Admin.WebApi.Filters;
|
|
using ARW.Common;
|
|
using ARW.Model.Dto.Business.GoodsManager.GoodsServicess;
|
|
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsServicess;
|
|
using ARW.Admin.WebApi.Controllers;
|
|
using ARW.Model.Models.Business.GoodsManager.GoodsServicess;
|
|
using ARW.Model.Vo.Business.GoodsManager.GoodsServicess;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using ARW.Admin.WebApi.Framework;
|
|
using ARW.Service.Business.IBusinessService.ShopManager.Shops;
|
|
|
|
|
|
namespace ARW.WebApi.Controllers.Business.GoodsManager.GoodsServicess
|
|
{
|
|
/// <summary>
|
|
/// 商品服务与承诺控制器
|
|
///
|
|
/// @author 黎文豪
|
|
/// @date 2023-06-18
|
|
/// </summary>
|
|
[Verify]
|
|
[Route("business/[controller]")]
|
|
public class GoodsServicesController : BaseController
|
|
{
|
|
private readonly IGoodsServicesService _GoodsServicesService;
|
|
private readonly IShopService _ShopService;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
/// <param name="GoodsServicesService">商品服务与承诺服务</param>
|
|
public GoodsServicesController(IGoodsServicesService GoodsServicesService, IShopService shopService)
|
|
{
|
|
_GoodsServicesService = GoodsServicesService;
|
|
_ShopService = shopService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取商品服务与承诺列表
|
|
/// </summary>
|
|
/// <param name="parm">查询参数</param>
|
|
/// <returns></returns>
|
|
[HttpGet("getGoodsServicesList")]
|
|
[ActionPermissionFilter(Permission = "business:goodsservices:list")]
|
|
public async Task<IActionResult> GetGoodsServicesList([FromQuery] GoodsServicesQueryDto parm)
|
|
{
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
if (user.UserId != 1)
|
|
{
|
|
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
|
|
if (shop == null) throw new Exception("当前用户没有店铺");
|
|
parm.ShopGuid = shop.ShopGuid;
|
|
}
|
|
|
|
var res = await _GoodsServicesService.GetGoodsServicesList(parm);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或修改商品服务与承诺
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("addOrUpdateGoodsServices")]
|
|
[ActionPermissionFilter(Permission = "business:goodsservices:addOrUpdate")]
|
|
[Log(Title = "添加或修改商品服务与承诺", BusinessType = BusinessType.ADDORUPDATE)]
|
|
public async Task<IActionResult> AddOrUpdateGoodsServices([FromBody] GoodsServicesDto parm)
|
|
{
|
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
|
|
|
var modal = new GoodsServices();
|
|
if (parm.GoodsServicesId != 0) modal = parm.Adapt<GoodsServices>().ToUpdate(HttpContext);
|
|
else modal = parm.Adapt<GoodsServices>().ToCreate(HttpContext);
|
|
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
if (user.UserId != 1)
|
|
{
|
|
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
|
|
if (shop == null) throw new Exception("当前用户没有店铺");
|
|
modal.ShopGuid = shop.ShopGuid;
|
|
}
|
|
|
|
var res = await _GoodsServicesService.AddOrUpdateGoodsServices(modal);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除商品服务与承诺
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpDelete("{ids}")]
|
|
[ActionPermissionFilter(Permission = "business:goodsservices:delete")]
|
|
[Log(Title = "商品服务与承诺删除", BusinessType = BusinessType.DELETE)]
|
|
public IActionResult Delete(string ids)
|
|
{
|
|
long[] idsArr = Tools.SpitLongArrary(ids);
|
|
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
|
var response = _GoodsServicesService.Delete(idsArr);
|
|
return SUCCESS("删除成功!");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 导出商品服务与承诺
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Log(Title = "商品服务与承诺导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
|
[HttpGet("exportGoodsServices")]
|
|
[ActionPermissionFilter(Permission = "business:goodsservices:export")]
|
|
public async Task<IActionResult> ExportExcel([FromQuery] GoodsServicesQueryDto parm)
|
|
{
|
|
parm.PageSize = 10000;
|
|
var list = await _GoodsServicesService.GetGoodsServicesList(parm);
|
|
var data = list.Result;
|
|
|
|
// 选中数据
|
|
if (!string.IsNullOrEmpty(parm.ids))
|
|
{
|
|
int[] idsArr = Tools.SpitIntArrary(parm.ids);
|
|
var selectDataList = new List<GoodsServicesVo>();
|
|
foreach (var item in idsArr)
|
|
{
|
|
var select_data = data.Where(s => s.GoodsServicesId == item).First();
|
|
selectDataList.Add(select_data);
|
|
}
|
|
data = selectDataList;
|
|
}
|
|
|
|
|
|
|
|
// 导出数据处理
|
|
var handleData = await _GoodsServicesService.HandleExportData(data);
|
|
|
|
string sFileName = ExportExcel(handleData, "GoodsServices", "商品服务与承诺列表");
|
|
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|