using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using XYY.Authentication.Standard; using XYY.Common.Standard; using XYY.Core.Standard.Mvc; using XYY.Model.Standard.Dto.MpsOrder; using XYY.Model.Standard.Finance; using XYY.Model.Standard.MpsOrder; using XYY.Model.Standard.MpsOrder.dto; using XYY.Model.Standard.MpsOrder.views; using XYY.Service.Standard.Order.FBA; namespace XYY.Api.Order.Controllers.FBA { [Route("api/[controller]/[action]")] [ApiController] public class FBAOrderController : ApiControllerBase { IFBAOrderService orderService; public FBAOrderController(IFBAOrderService orderService) { this.orderService = orderService; } #region 空派收件 public async Task GetReceivingInfo(QueryModel queryModel) { if (queryModel?.QueryParamer != null && queryModel.QueryParamer.Any(x => x.Filed == "IsGoodsNames")) { var tempParamer = queryModel.QueryParamer.Where(x => x.Filed == "IsGoodsNames").FirstOrDefault(); if (tempParamer.Value == "1") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "GoodsNames", Method = "IsNotNl", Value = "" }); } else if (tempParamer.Value == "2") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "GoodsNames", Method = "IsNl", Value = "" }); } queryModel.QueryParamer.Remove(tempParamer); } var data = await this.orderService.GetReceivingInfo(queryModel); return Ok(data); } public async Task GetReceivingBoxs(int Id) { var data = await this.orderService.GetReceivingBoxs(new List() { Id }); return Ok(data); } public async Task GetReceivingBoxsByIds(IEnumerable Ids) { var data = await this.orderService.GetReceivingBoxs(Ids); return Ok(data); } public async Task UpdateReceivingBoxs(List boxs) { var data = await this.orderService.UpdateReceivingBoxs(boxs); return Ok(data); } public async Task GoToPrint(IEnumerable Ids) { var data = await this.orderService.GoToPrint(Ids); return Ok(data); } public async Task UpdateFile(string BoxNumber) { var boxPicInfo = await orderService.GetBoxPictureOrderInfo(BoxNumber); var filelist = (await Request.ReadFormAsync()).Files; foreach (var file in filelist) { var result = await orderService.UpdateBoxPicture(boxPicInfo, file.OpenReadStream()); } return Ok(); } public async Task GetBoxPictures(string BoxNumber) { var data = await orderService.GetBoxPictures(BoxNumber); return Ok(data); } public async Task RemoveBoxPicture(int[] PicIds) { var data = await orderService.RemoveBoxPicture(PicIds); return Ok(data); } [HttpPost] public async Task ImportMpsBoxAddresseeInfo() { var filelist = (await Request.ReadFormAsync()).Files; if (filelist != null && filelist.Count > 0) { var u = User.GetUserContent(); string userName = u.NiceName; var file = filelist[0]; var result = await orderService.ImportMpsBoxAddresseeInfo(file.OpenReadStream(), userName); return Ok(result); } else { return Error("请上传一个文件"); } } #endregion //public async Task GetOrderReceivingInfo(int orderId) //{ // var data = await this.orderService.GetOrderReceivingInfo(orderId); // return Ok(data); //} //public async Task SaveOrderRceiveingInfo(View_Order_ReceivingInfo View_Order_ReceivingInfo) //{ // await this.orderService.SaveOrderRceiveingInfo(View_Order_ReceivingInfo); // return Ok(); //} #region 空派打单 public async Task GetPrintList(QueryModel queryModel) { if (queryModel?.QueryParamer != null && queryModel.QueryParamer.Any(x => x.Filed == "IsXYY")) { var tempParamer = queryModel.QueryParamer.Where(x => x.Filed == "IsXYY").FirstOrDefault(); if (tempParamer.Value == "1") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "LEFT(TrackingNumber,3)", Method = "NotEq", Value = "XYY" }); } else if (tempParamer.Value == "2") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "LEFT(TrackingNumber,3)", Method = "Eq", Value = "XYY" }); } queryModel.QueryParamer.Remove(tempParamer); } if (queryModel?.QueryParamer != null && queryModel.QueryParamer.Any(x => x.Filed == "IsOrderPrintQty")) { var tempParamer = queryModel.QueryParamer.Where(x => x.Filed == "IsOrderPrintQty").FirstOrDefault(); if (tempParamer.Value == "1") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(OrderPrintQty,0)", Method = "Eq", Value = "1" }); } else if (tempParamer.Value == "2") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(OrderPrintQty,0)", Method = "Eq", Value = "0" }); } queryModel.QueryParamer.Remove(tempParamer); } var data = await this.orderService.GetPrintList(queryModel); return Ok(data); } public async Task GetPrint(int orderId) { var data = await this.orderService.GetPrint(orderId); return Ok(data); } public async Task GetReceivingBoxsGoods(int Id) { var data = await this.orderService.GetReceivingGoods(Id); return Ok(data); } public async Task GetReceivingAddress(int Id) { var data = await this.orderService.GetReceivingAddress(Id); return Ok(data); } public async Task UpdatePrintBoxs(MpsPrint boxs) { var data = await this.orderService.UpdatePrintBoxs(boxs); return Ok(data); } public async Task GoToIncome(IEnumerable Ids) { var data = await this.orderService.GoToIncome(Ids); return Ok(data); } public async Task UpdateOrderPrintQty(int orderId, bool OrderPrintQty) { var data = await this.orderService.UpdateOrderPrintQty(orderId, OrderPrintQty); return Ok(data); } public async Task BatchUpdateOrderPrintQty(IEnumerable Ids) { var data = await this.orderService.BatchUpdateOrderPrintQty(Ids); return Ok(data); } #endregion //public async Task SavePrintInfos(View_Order_Print View_Order_ReceivingInfo) //{ // await this.orderService.SavePrintInfos(View_Order_ReceivingInfo); // return Ok(); //} #region 空派收入 public async Task GetCustomerConfirmList(QueryModel queryModel) { //判断用户角色 var u = User.GetUserContent(); if (u.Roles.Contains("销售")) { if (queryModel?.QueryParamer != null) { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "NickName", Method = "Eq", Value = u.NiceName }); } else { queryModel.QueryParamer = new List(); queryModel.QueryParamer.Add(new QueryParamer() { Filed = "NickName", Method = "Eq", Value = u.NiceName }); } } if (queryModel?.QueryParamer != null && queryModel.QueryParamer.Any(x => x.Filed == "IsConfim")) { var tempParamer = queryModel.QueryParamer.Where(x => x.Filed == "IsConfim").FirstOrDefault(); if (tempParamer.Value == "1") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(SalesmanConfirmFee,0)", Method = "Gr", Value = "0" }); } else if (tempParamer.Value == "2") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(SalesmanConfirmFee,0)", Method = "LeE", Value = "0" }); } queryModel.QueryParamer.Remove(tempParamer); } var data = await this.orderService.GetCustomerConfirmList(queryModel); return Ok(data); } public async Task GetCustomerConfirm(int orderId) { var data = await this.orderService.GetCustomerConfirm(orderId); return Ok(data); } public async Task UpdateCustomerConfirm(MpsCustomerConfirm dto) { var data = await this.orderService.UpdateCustomerConfirm(dto); return Ok(data); } public async Task GetBatchConfirmWeight(IEnumerable Ids) { var data = await this.orderService.GetBatchConfirmWeight(Ids); return Ok(data); } public async Task UpdateBatchConfirmWeight(List confirmWeights) { var data = await this.orderService.UpdateBatchConfirmWeight(confirmWeights); return Ok(); } public async Task GetBatchConfirmIncidenta(IEnumerable Ids) { var data = await this.orderService.GetBatchIncidenta(Ids, XYY.Model.Standard.Finance.FBAIncidentalCalculateTarget.客户); data = data.OrderBy(x => x.OrderId).ToList(); return Ok(data); } public async Task UpdateBatchConfirmIncidenta(List incidentals) { var data = await this.orderService.UpdateBatchConfirmIncidenta(incidentals); return Ok(); } public async Task GoToSettlement(IEnumerable Ids) { var u = User.GetUserContent(); var data = await this.orderService.GoToSettlement(Ids, u.NiceName); return Ok(data); } public async Task ExportWaitConfirm(IEnumerable Ids) { byte[] data = await orderService.ExportWaitConfirm(Ids); return File(data, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", DateTime.Now.ToString_yyyyMMddHHmm() + ".xls"); } public async Task GetBoxIDCR(Order_MpsOrderBox box) { string data = await orderService.GetBoxIDCR(box); return Ok(data); } public async Task SalesmanConfirmFee(int Id) { var data = await orderService.SalesmanConfirmFee(Id); return Ok(data); } /// /// 修改创建渠道 /// /// [HttpPost] public async Task ModifyCreateOrderChannelId(MpsModifyCreateOrderChannelId mpsModify) { var u = User.GetUserContent(); await orderService.ModifyCreateOrderChannelId(mpsModify, u); return Ok(); } //修复一下新增的计算计费 实重/泡重 数据 public async Task RepairSettlementData(List Ids) { var data = await orderService.RepairSettlementData(Ids); return Ok(data); } #endregion #region 单价获取 public async Task GetUnitPrice(KPUnitPriceRequest request) { var data = await this.orderService.GetUnitPrice(request); return Ok(data); } #endregion #region 结算 public async Task GetSettlementConfirmList(QueryModel queryModel) { if (queryModel?.QueryParamer != null && queryModel.QueryParamer.Any(x => x.Filed == "IsConfim")) { var tempParamer = queryModel.QueryParamer.Where(x => x.Filed == "IsConfim").FirstOrDefault(); if (tempParamer.Value == "1") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(IsSettlementConfirm,0)", Method = "Eq", Value = "1" }); } else if (tempParamer.Value == "2") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(IsSettlementConfirm,0)", Method = "Eq", Value = "0" }); } queryModel.QueryParamer.Remove(tempParamer); } var data = await this.orderService.GetSettlementConfirmList(queryModel); return Ok(data); } public async Task ExportEnd(QueryModel queryModel) { if (queryModel?.QueryParamer != null && queryModel.QueryParamer.Any(x => x.Filed == "IsConfim")) { var tempParamer = queryModel.QueryParamer.Where(x => x.Filed == "IsConfim").FirstOrDefault(); if (tempParamer.Value == "1") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(IsSettlementConfirm,0)", Method = "Eq", Value = "1" }); } else if (tempParamer.Value == "2") { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "isnull(IsSettlementConfirm,0)", Method = "Eq", Value = "0" }); } queryModel.QueryParamer.Remove(tempParamer); } byte[] data = await orderService.ExportSettlementConfirm(queryModel); return File(data, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", DateTime.Now.ToString_yyyyMMddHHmm() + ".xls"); } public async Task GetSettlementConfirm(int orderId) { var data = await this.orderService.GetSettlementConfirm(orderId); return Ok(data); } public async Task GetBatchSettlementWeight(IEnumerable Ids) { var data = await this.orderService.GetBatchSettlementWeight(Ids); return Ok(data); } public async Task UpdateBatchSettlementWeight(List confirmWeights) { var data = await this.orderService.UpdateBatchSettlementWeight(confirmWeights); return Ok(); } public async Task UpdateSettlementConfirm(MpsSettlementConfirm dto) { var data = await this.orderService.UpdateSettlementConfirm(dto); return Ok(data); } public async Task GetBatchSettlementIncidenta(IEnumerable Ids) { var data = await this.orderService.GetBatchIncidenta(Ids, XYY.Model.Standard.Finance.FBAIncidentalCalculateTarget.结算价); data = data.OrderBy(x => x.OrderId).ToList(); return Ok(data); } public async Task UpdateBatchSettlementIncidenta(List incidentals) { var data = await this.orderService.UpdateBatchSettlementIncidenta(incidentals); return Ok(); } public async Task UpdateSettlementConfirmForTable(MpsSettlementConfirmTableData dto) { var data = await this.orderService.UpdateSettlementConfirmForTable(dto); return Ok(data); } public async Task SettlementConfirmOperation(int orderId) { var u = User.GetUserContent(); var data = await this.orderService.SettlementConfirmOperation(orderId, u.NiceName); return Ok(data); } public async Task GoToEnd(IEnumerable Ids) { var u = User.GetUserContent(); var data = await this.orderService.GoToEnd(Ids, u.NiceName); return Ok(data); } //重算订单结算数据 public async Task recalculationOrderSettlementPrice(List Ids) { await orderService.CalculateSettlementPrice(Ids); return Ok(); } #endregion public async Task SaveCustomerConfirm(View_Order_CustomerConfirm View_Order_CustomerConfirm) { await this.orderService.SaveCustomerConfirm(View_Order_CustomerConfirm); return Ok(); } public async Task SaveSettlementConfirm(View_Order_SettlementConfirm View_Order_SettlementConfirm) { await this.orderService.SaveSettlementConfirm(View_Order_SettlementConfirm); return Ok(); } #region 合计报表 public async Task GetGrossProfitByCustomer(QueryModel queryModel) { var data = await orderService.GetGrossProfitByCustomer(queryModel); return Ok(data); } public async Task GetGrossProfitByOrder(QueryModel queryModel) { //判断用户角色 var u = User.GetUserContent(); if (u.Roles.Contains("销售")) { if (queryModel?.QueryParamer != null) { queryModel.QueryParamer.Add(new QueryParamer() { Filed = "NickName", Method = "Eq", Value = u.NiceName }); } else { queryModel.QueryParamer = new List(); queryModel.QueryParamer.Add(new QueryParamer() { Filed = "NickName", Method = "Eq", Value = u.NiceName }); } } var data = await orderService.GetGrossProfitByOrder(queryModel); return Ok(data); } #endregion } }