using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Logging;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using System.Transactions;
|
using zhengcaioa.IService;
|
using zhengcaioa.Models;
|
|
namespace zhengcaioa.Controllers.admin
|
{
|
public class AdmGoodsRecordController : Controller
|
{
|
private readonly ILogger<AdmGoodsRecordController> _logger;
|
private readonly IAdmGoodsRecordService _admGoodsRecordService;
|
private readonly ILiaotianService _liaotianService;
|
|
private readonly IAdmGoodsManageService _admGoodsManageService;
|
|
public AdmGoodsRecordController(ILogger<AdmGoodsRecordController> logger, IAdmGoodsRecordService admGoodsRecordService, ILiaotianService liaotianService
|
, IAdmGoodsManageService admGoodsManageService)
|
{
|
_logger = logger;
|
|
_liaotianService = liaotianService;
|
_admGoodsRecordService = admGoodsRecordService;
|
_admGoodsManageService = admGoodsManageService;
|
}
|
|
//出库接口
|
public IActionResult BookChuKu([FromBody] AdmGoodsRecordDTO dto)
|
{
|
ReturnMsg<List<ProjectDTO>> returnMsg = new ReturnMsg<List<ProjectDTO>>();
|
returnMsg.code = 2;
|
|
if (string.IsNullOrEmpty(dto.ISBN))
|
{
|
|
returnMsg.code = 2;
|
returnMsg.error = "没有ISBN";
|
returnMsg.count = 0;
|
return new JsonResult(returnMsg);
|
|
}
|
|
var admGoodsManageDTOs = _admGoodsManageService.GetList().Where(x=>x.ISBN == dto.ISBN).FirstOrDefault();
|
|
if (admGoodsManageDTOs==null)
|
{
|
|
|
returnMsg.code = 2;
|
returnMsg.error = "没有找到该商品";
|
returnMsg.count = 0;
|
return new JsonResult(returnMsg);
|
|
}
|
else if(!admGoodsManageDTOs.GoodsLeft.HasValue )
|
{
|
returnMsg.code = 2;
|
returnMsg.error = "该商品没有库存";
|
returnMsg.count = 0;
|
return new JsonResult(returnMsg);
|
}
|
else if (admGoodsManageDTOs.GoodsLeft.Value< dto.GoodsNum)
|
{
|
returnMsg.code = 2;
|
returnMsg.error = "该商品库存不足";
|
returnMsg.count = 0;
|
return new JsonResult(returnMsg);
|
}
|
|
|
|
|
|
|
|
try
|
{
|
using (TransactionScope scope = new TransactionScope())
|
{
|
var left = admGoodsManageDTOs.GoodsLeft - dto.GoodsNum;
|
dto.GoodsId = admGoodsManageDTOs.Id;
|
dto.GoodsLeft = left;
|
dto.RecordTypeId = "02";
|
|
admGoodsManageDTOs.GoodsLeft = left;
|
|
var resultEntity = _admGoodsManageService.save(admGoodsManageDTOs);
|
|
dto.RecStatus = "A";
|
if (String.IsNullOrEmpty(dto.Id))
|
{
|
dto.Creater = "1";
|
dto.Createtime = DateTime.Now;
|
}
|
dto.Modifier = "1";
|
dto.Modifytime = DateTime.Now;
|
|
resultEntity = _admGoodsRecordService.save(dto);
|
|
returnMsg.code = 1;
|
returnMsg.count = 0;
|
returnMsg.returnObj = null;
|
scope.Complete();
|
}
|
|
}
|
catch (Exception ex)
|
{
|
returnMsg.code = 2;
|
returnMsg.error = "没有获取到token";
|
returnMsg.count = 0;
|
|
}
|
return new JsonResult(returnMsg);
|
}
|
}
|
}
|