123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- using AlibabaCloud.SDK.Dingtalkservice_group_1_0.Models;
- using iTextSharp.text;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.FSharp.Core;
- using NPOI.HPSF;
- using NPOI.OpenXmlFormats.Dml;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security;
- using System.Threading.Tasks;
- using System.Web;
- using XYY.Common.Standard;
- using XYY.Core.Standard.ExcelHelper.MSExcelHelper;
- using XYY.Core.Standard.Mvc;
- using XYY.Model.Standard.Finance;
- using XYY.Model.Standard.MpsOrder.dto;
- using XYY.Service.Standard.Customer;
- using XYY.Service.Standard.Finance;
- namespace XYY.Api.Finance.Controllers
- {
- [Route("api/[controller]/[action]")]
- [ApiController]
- public class FinanceCustomerSupplementsController : ApiControllerBase
- {
- IFinance_Customer_SupplementService supplementService;
- IConfiguration _configuration;
- ICustomerService customerService;
- public FinanceCustomerSupplementsController(IFinance_Customer_SupplementService supplementService, IConfiguration configuration, ICustomerService customerService)
- {
- this.supplementService = supplementService;
- _configuration = configuration;
- this.customerService = customerService;
- }
- public async Task<IActionResult> Add(Finance_Customer_Supplement fcs)
- {
- await this.supplementService.Add(fcs);
- return Ok();
- }
- public async Task<IActionResult> Edit(Finance_Customer_Supplement fcs)
- {
- await this.supplementService.Edit(fcs);
- return Ok();
- }
- [HttpPost]
- public async Task<IActionResult> GetPageResult(QueryModel queryModel)
- {
- var pageReuslt = await this.supplementService.GetPageResult(queryModel);
- return Ok(pageReuslt);
- }
- public class SkuFeeReqItem
- {
- public decimal avgFee { get; set; }
- public int qty { get; set; }
- public string sku { get; set; }
- }
- public class SkuFeeReq
- {
- public int customerId { get; set; }
- public string day { get; set; }
- public List<SkuFeeReqItem> Items
- {
- get; set;
- }
- }
- public async Task<IActionResult> AddCustomerSKUFee(SkuFeeReq skuFeeReqRoot)
- {
- var customer = (await customerService.CacheGetAllCustomers()).FirstOrDefault(x => x.Id == skuFeeReqRoot.customerId);
- var nsmpCustomers = await customerService.GetNSMPCustomer();
- var list = new List<Finance_Customer_Supplement>();
- foreach (var skuFeeReq in skuFeeReqRoot.Items)
- {
- string orderNo = customer.CustomerNumber + "_" + skuFeeReq.sku + "_" + skuFeeReqRoot.day;
- var supplement = new Finance_Customer_Supplement
- {
- Fee = skuFeeReq.avgFee * skuFeeReq.qty,
- CreateOrderChannelId = 0,
- CustomerId = skuFeeReqRoot.customerId,
- CurrenyRate = "CNY",
- FinanceCustomerSupplementType = FinanceCustomerSupplementOrDeductionType.补_Sku处理费,
- CustomerOrderNo = orderNo,
- Describe = "Sku处理费",
- FeeString = string.Empty,
- Guid = Guid.NewGuid().ToString(),
- Month = skuFeeReqRoot.day,
- SMPDetailType = "Sku处理费",
- OrderId = 0,
- SystemNo = orderNo,
- Remark = string.Empty,
- OrderRemark = $"单价:{skuFeeReq.avgFee.ToString("0.00")},数量:{skuFeeReq.qty},总价{skuFeeReq.avgFee * skuFeeReq.qty}",
- TrackingNumber = skuFeeReq.sku,
- };
- list.Add(supplement);
- }
- await this.supplementService.InputFinanceCustomerSupplements(FinanceCustomerSupplementOrDeductionType.补_Sku处理费, list);
- var nsmpList = list.Where(x => nsmpCustomers.Contains(x.CustomerId)).ToList();
- if (nsmpList.Count() != 0)
- {
- await this.supplementService.InputFinanceCustomerSupplementsNew(FinanceCustomerSupplementOrDeductionType.补_Sku处理费, nsmpList);
- }
- return Ok();
- }
- public async Task<IActionResult> InputFinanceCustomerSupplements(
- FinanceCustomerSupplementOrDeductionType type,
- string url,
- string month,
- bool isNewFee,
- string currencyCode = "CNY",
- SupplementTargetType targetValue = SupplementTargetType.全部)
- {
- List<Finance_Customer_Supplement> list = new List<Finance_Customer_Supplement>();
- var nsmpCustomers = await customerService.GetNSMPCustomer();
- if (type == FinanceCustomerSupplementOrDeductionType.补_通用杂费)
- {
- System.Net.WebClient client = new System.Net.WebClient();
- byte[] data = client.DownloadData(url);
- MSExcelHelper excelHelper = new MSExcelHelper();
- var fees = excelHelper.LoadDataByByte<OtherFeeSupplementMapping, Finance_Customer_Supplement>(data);
- foreach (var item in fees)
- {
- item.CurrenyRate = currencyCode;
- item.Describe = item.AvgFee + item.CurrenyRate + "*" + item.Qty;
- item.CurrenyRate = currencyCode;
- item.SupplementTargetType = (int)targetValue;
- item.FinanceCustomerSupplementType = type;
- item.FeeString = item.Fee + item.CurrenyRate;
- list.Add(item);
- }
- await this.supplementService.InputFinanceCustomerSupplements(type, list);
- var nsmpList2 = list.Where(x => nsmpCustomers.Contains(x.CustomerId)).ToList();
- if (nsmpList2.Count() != 0)
- {
- await this.supplementService.InputFinanceCustomerSupplementsNew(type, nsmpList2);
- }
- return Ok();
- }
- else
- {
- System.Net.WebClient client = new System.Net.WebClient();
- byte[] data = client.DownloadData(url);
- MSExcelHelper excelHelper = new MSExcelHelper();
- list = excelHelper.LoadDataByByte<CustomerSupplementMapping, Finance_Customer_Supplement>(data);
- foreach (var item in list)
- {
- item.CurrenyRate = currencyCode;
- item.SupplementTargetType = (int)targetValue;
- item.FinanceCustomerSupplementType = type;
- }
- FinanceCustomerSupplementOrDeductionType financeCustomerSupplementType = type;
- list.ForEach(x =>
- {
- x.FinanceCustomerSupplementType = type;
- if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.补_退件费)
- {
- x.Describe = "退件费";
- }
- else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.补_重派费)
- {
- x.Describe = "重派费";
- }
- else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.扣_重量差异费)
- {
- x.Describe = "重量差异费";
- }
- else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.扣_时间差异费)
- {
- x.Describe = "时间差异费";
- }
- else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.扣_索赔)
- {
- x.Describe = "索赔费用";
- }
- x.Month = month;
- });
- }
- await this.supplementService.InputFinanceCustomerSupplements(type, list);
- var nsmpList = list.Where(x => nsmpCustomers.Contains(x.CustomerId)).ToList();
- if (nsmpList.Count() != 0)
- {
- await this.supplementService.InputFinanceCustomerSupplementsNew(type, nsmpList);
- }
- return Ok();
- }
- public async Task<IActionResult> GetFinanceCustomerSupplementTypes()
- {
- var items = EnumsHelper.GetEnumItems(typeof(FinanceCustomerSupplementOrDeductionType));
- return Ok(items);
- }
- public class OtherFeeSupplementMapping : MSExcelClassMapping<Finance_Customer_Supplement>
- {
- public OtherFeeSupplementMapping()
- {
- Map(x => x.SystemNo).Name("订单编号");
- Map(x => x.TrackingNumber).Name("订单编号");
- Map(x => x.CustomerOrderNo).Name("订单编号");
- Map(x => x.CreateTime).Name("业务时间");
- Map(x => x.CustomerName).Name("客户");
- Map(x => x.SMPDetailType).Name("费用名称");
- Map(x => x.AvgFee).Name("单价");
- Map(x => x.Qty).Name("数量");
- Map(x => x.Fee).Name("金额");
- Map(x => x.OrderRemark).Name("备注");
- }
- }
- public class CustomerSupplementMapping : MSExcelClassMapping<Finance_Customer_Supplement>
- {
- public CustomerSupplementMapping()
- {
- Map(x => x.SystemNo).Name("跟踪号");
- Map(x => x.SystemNo).Name("运单号");
- Map(x => x.SystemNo).Name("内部单号");
- Map(x => x.SMPDetailType).Name("费用类型");
- Map(x => x.FeeString).Name("费用");
- Map(x => x.FeeString).Name("金额");
- Map(x => x.FeeString).Name("退件费");
- Map(x => x.FeeString).Name("重派费用元/票(RMB)");
- Map(x => x.Describe).Name("明细");
- Map(x => x.OrderRemark).Name("重派单号");
- Map(x => x.OrderRemark).Name("尺寸");
- Map(x => x.OrderRemark).Name("退件原因");
- }
- }
- public async Task<IActionResult> Remave(Finance_Customer_Supplement fcs)
- {
- await this.supplementService.Remave(fcs);
- return Ok();
- }
- }
- }
|