using JiepeiWMS.Common.Enums; using JiepeiWMS.Common.Helper; using JiepeiWMS.Common.HttpContextUser; using JiepeiWMS.Extends; using JiepeiWMS.Filter; using JiepeiWMS.IServices; using JiepeiWMS.Model; using JiepeiWMS.Model.Models; using JiepeiWMS.Model.ViewModels; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SqlSugar; using System; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; namespace JiepeiWMS.Api.Controllers { [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class WMQuoteInfoController : ControllerBase { /// /// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下 /// private readonly IWMQuoteInfoServices _BllWMQuoteInfo; private readonly IWMQuoteInfoLogServices _BllWMQuoteInfoLog; private readonly IWMPurchaseQuoteDetailServices _BllWMPurchaseQuoteDetail; private readonly IWMSupplierServices _BllWMSupplier; private readonly IWMPurchaseInfoServices _BllWMPurchase; private readonly ISysUserInfoServices _BllSysUserInfo; private readonly ISysOrgServices _BllSysOrg; private readonly IWMProductUnitServices _BllWMProductUnit; private readonly IUser _User; ILogger _Logger; public WMQuoteInfoController( IWMQuoteInfoServices BllWMQuoteInfo, IWMPurchaseQuoteDetailServices BllWMPurchaseQuoteDetail, IWMSupplierServices BllWMSupplier, ISysUserInfoServices BllSysUserInfo, ISysOrgServices BllSysOrg, IWMProductUnitServices BllWMProductUnit, IUser User, ILogger Logger, IWMQuoteInfoLogServices BllWMQuoteInfoLog, IWMPurchaseInfoServices BllWMPurchase ) { _BllWMQuoteInfo = BllWMQuoteInfo; _BllWMPurchaseQuoteDetail = BllWMPurchaseQuoteDetail; _BllWMSupplier = BllWMSupplier; _BllSysUserInfo = BllSysUserInfo; _BllSysOrg = BllSysOrg; _BllWMProductUnit = BllWMProductUnit; _User = User; _Logger = Logger; _BllWMQuoteInfoLog = BllWMQuoteInfoLog; _BllWMPurchase = BllWMPurchase; } [HttpGet] public async Task>> GetList( int? Id = null, DateTime? StartTime = null, DateTime? EndTime = null, string QuoteCode = null, int PageIndex = 1, int PageSize = 20) { Expression> whereExpression = (pg) => pg.SysOrgId == _User.SysOrgId; if (Id != null) { whereExpression = whereExpression.And((pg) => pg.Id == Id); } if (!string.IsNullOrEmpty(QuoteCode)) { QuoteCode = QuoteCode.Trim(); whereExpression = whereExpression.And((pg) => pg.QuoteCode == QuoteCode); } if (StartTime.HasValue) { whereExpression = whereExpression.And((pg) => pg.CreateTime >= StartTime.Value); } if (EndTime.HasValue) { EndTime = EndTime.Value.AddSeconds(1); whereExpression = whereExpression.And((pg) => pg.CreateTime < EndTime.Value); } var pglst = await _BllWMQuoteInfo.QueryTabsPage( (pg, s, ue, uc) => new object[] { JoinType.Left, pg.SupplierId==s.Id, JoinType.Left,pg.EmployeeId==ue.uID, JoinType.Left,pg.CheckAdminId==uc.uID }, (pg, s, ue, uc) => new WMQuoteInfo { ActualAmount = pg.ActualAmount, AddRemark = pg.AddRemark, CheckAdminId = pg.CheckAdminId, Bank = pg.Bank, BankAccount = pg.BankAccount, CheckKey = pg.CheckKey, CheckRank = pg.CheckRank, CheckRemark = pg.CheckRemark, CreateTime = pg.CreateTime, EmployeeId = pg.EmployeeId, ExpectedArrivalTime = pg.ExpectedArrivalTime, FileUrl = pg.FileUrl, Payee = pg.Payee, Id = pg.Id, PayPic = pg.PayPic, PayType = pg.PayType, QuoteCode = pg.QuoteCode, Remark = pg.Remark, SettlementAmount = pg.SettlementAmount, Status = pg.Status, SupplierId = pg.SupplierId, UpdateTime = pg.UpdateTime, EmployeeName = ue.uRealName, SupplierName = s.Name, SysOrgId = pg.SysOrgId }, whereExpression, PageIndex, PageSize, "pg.Id desc"); var dicstatus = typeof(EnumWMPurchaseDetailStatus)._GetValueDescriptionDicFromEnumType(); foreach (var i in pglst.data) { string name; i.StatusName = dicstatus.TryGetValue((EnumWMPurchaseDetailStatus)i.Status, out name) ? name : string.Empty; } //测试接口 //var dsdfss = await _BllWMQuoteInfo.QueryById(2121); //var sdd = await _BllWMPurchaseQuoteDetail.Query(x => x.QuoteId == dsdfss.Id); //foreach (var item in sdd) //{ // item.inputNum = 2; //} //var s = await _BllWMQuoteInfo.BeginPurchaseinInNC(dsdfss, sdd); //var s = await _BllWMPurchaseQuoteDetail.BeginPurchaseinInNC(dsdfss, sdd); return new MessageModel>() { msg = "获取成功", success = true, response = pglst }; } [HttpGet] public async Task> GetParams() { var dicStatus = typeof(EnumWMPurchaseDetailStatus)._GetValueDescriptionDicFromEnumType().Select(t => new { Key = t.Key.GetHashCode(), t.Value }); var dicSupplierId = await _BllWMSupplier.Query(); var dicEmployeeId = await _BllSysUserInfo.Query(t => t.tdIsDelete == false); var dicPurchaseUnit = await _BllWMProductUnit.Query(); var dicSysOrgId = await _BllSysOrg.Query(); var dicPayType = typeof(EnumPayType)._GetValueDescriptionDicFromEnumType().Select(t => new { Key = t.Key.GetHashCode(), t.Value }); return new MessageModel() { msg = "获取成功", success = true, response = new { dicStatus, dicSupplierId, dicEmployeeId, dicPurchaseUnit, dicSysOrgId, dicPayType } }; } [HttpPost] public async Task> Add([FromBody] WMQuoteInfo request) { var data = new MessageModel(); var id = await _BllWMQuoteInfo.Add(request); data.success = id > 0; if (data.success) { data.response = id.ObjToString(); data.msg = "添加成功"; } return data; } [HttpPut] public async Task> Edit([FromBody] VMWMQuoteInfo request) { string msg = string.Empty; if (request.Id <= 0) { msg = "采购单编号有误"; goto ErrorResult; } switch (request.Status) { case 40: msg = await _BllWMQuoteInfo.ConfirmQuoteInfo(request, _User.ID); break; case 46: msg = await _BllWMQuoteInfo.ConfirmPayInfo(request, _User.ID); break; case 78: msg = await _BllWMQuoteInfo.Purchase(request.Id, _User.ID); break; default: msg = await _BllWMQuoteInfo.EditInfo(request, _User.ID); break; } if (!string.IsNullOrEmpty(msg)) { goto ErrorResult; } return new MessageModel { success = true, msg = "更新成功" }; ErrorResult: return new MessageModel { success = false, msg = msg }; } [HttpDelete] public async Task> Delete(int id = 0) { var data = new MessageModel(); if (id > 0) { var detail = await _BllWMQuoteInfo.QueryById(id); if (detail != null) { data.success = await _BllWMQuoteInfo.Delete(detail); if (data.success) { data.msg = "删除成功"; data.response = detail?.Id.ObjToString(); } } } return data; } [HttpDelete] public async Task> DeleteMore(string Ids = "") { var data = new MessageModel(); var lstid = Ids._ToIntList(); if (lstid.Count > 0) { var ok = await _BllWMQuoteInfo.DeleteByIds(lstid.Select(t => (object)t).ToArray()); if (ok) { data.msg = "删除成功"; data.response = string.Empty; } } return data; } [HttpGet] public async Task> Detail(int Id) { var detail = new VMWMQuoteInfo(); var quoteinfo = await _BllWMQuoteInfo.GetModel(t => t.Id == Id); if (quoteinfo == null) { quoteinfo = new WMQuoteInfo { Id = 0 }; } var purchasedetails = await _BllWMPurchaseQuoteDetail.QueryTabsPage( (pg, pl, pi, ps, d) => new object[] { JoinType.Left, pg.ProductId == pl.Id, JoinType.Left, pg.QuoteId == pi.Id, JoinType.Left, pl.SpecIds == ps.Id, JoinType.Left, pg.DepartmentId == d.Id }, (pg, pl, pi, ps, d) => new WMPurchaseQuoteDetail { Id = pg.Id, Amount = pg.Amount, CheckNum = pg.CheckNum, CreateTime = pg.CreateTime, DepartmentId = pg.DepartmentId, DepartmentName = d.Name, DisAmount = pg.DisAmount, Discount = pg.Discount, DiscountPrice = pg.DiscountPrice, Price = pg.Price, ProductCode = pl.Code, ProductId = pg.ProductId, ProductName = pl.Name, ProductSpec = ps.Name, PurchaseId = pg.PurchaseId, PurchaseNum = pg.PurchaseNum, PurchaseUnit = pg.PurchaseUnit, Quantity = pg.Quantity, QuoteId = pg.QuoteId, Remark = pg.Remark, Status = pg.Status, StorageNum = pg.StorageNum, SysOrgId = pg.SysOrgId, TypeId = pg.TypeId, UpdateTime = pg.UpdateTime }, pg => pg.QuoteId == quoteinfo.Id ); detail.ListDetail = purchasedetails.data.Select(t => { t.StatusName = ((EnumWMPurchaseDetailStatus)t.Status)._GetDescriptionByEnumValue(); return t; }).ToList(); return new MessageModel() { msg = "获取成功", success = true, response = detail }; } /// /// 报价审核 /// /// 代码 /// 是否通过 /// 不通过原因 /// 拒绝类型 0 通过 1临时 2永久 /// 结果 [HttpGet, AllowAnonymous, AuthKeySecret] public async Task> SetQuoteCheckResult(string QuoteCode, bool? IsPass, string Msg,int RejectType) { var msg = string.Empty; if (!IsPass.HasValue) { msg = "IsPass必须设置值"; goto ErrorResult; } if (!IsPass.Value && string.IsNullOrWhiteSpace(Msg)) { msg = "审核失败必须设置原因"; goto ErrorResult; } if (RejectType<0) { msg = "RejectType必须设置值"; goto ErrorResult; } msg = await _BllWMQuoteInfo.SetCheckQuoteIsPass(QuoteCode, IsPass.Value, Msg,RejectType); if (!string.IsNullOrEmpty(msg)) { goto ErrorResult; } return new MessageModel() { msg = string.Empty, success = true }; ErrorResult: return new MessageModel() { msg = msg, success = false }; } /// /// 请款审核 /// /// 代码 /// 是否通过 /// 不通过原因 /// 拒绝类型 0 通过 1临时 2永久 /// 结果 [HttpGet, AllowAnonymous, AuthKeySecret] public async Task> SetPayCheckResult(string QuoteCode, bool? IsPass, string Msg,int RejectType) { var msg = string.Empty; if (!IsPass.HasValue) { msg = "IsPass必须设置值"; goto ErrorResult; } if (!IsPass.Value && string.IsNullOrWhiteSpace(Msg)) { msg = "审核失败必须设置原因"; goto ErrorResult; } if (RejectType < 0) { msg = "RejectType必须设置值"; goto ErrorResult; } msg = await _BllWMQuoteInfo.SetCheckPayIsPass(QuoteCode, IsPass.Value, Msg,RejectType); if (!string.IsNullOrEmpty(msg)) { goto ErrorResult; } return new MessageModel() { msg = string.Empty, success = true }; ErrorResult: return new MessageModel() { msg = msg, success = false }; } /// /// 下单采购 /// /// /// [HttpGet] public async Task> Purchase(int Id) { var msg = await _BllWMQuoteInfo.Purchase(Id, _User.ID); if (string.IsNullOrEmpty(msg)) { goto ErrorResult; } return new MessageModel() { success = true }; ErrorResult: return new MessageModel() { msg = msg, success = false }; } /// /// 完成交易 /// /// /// [HttpGet] public async Task> Done(int Id) { var msg = await _BllWMQuoteInfo.Done(Id, _User.ID); if (!string.IsNullOrEmpty(msg)) { goto ErrorResult; } return new MessageModel() { msg = "设置完成", success = true }; ErrorResult: return new MessageModel() { msg = msg, success = false }; } } }