FinanceCustomerSupplementsController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using AlibabaCloud.SDK.Dingtalkservice_group_1_0.Models;
  2. using iTextSharp.text;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Configuration;
  5. using Microsoft.FSharp.Core;
  6. using NPOI.HPSF;
  7. using NPOI.OpenXmlFormats.Dml;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Security;
  12. using System.Threading.Tasks;
  13. using System.Web;
  14. using XYY.Common.Standard;
  15. using XYY.Core.Standard.ExcelHelper.MSExcelHelper;
  16. using XYY.Core.Standard.Mvc;
  17. using XYY.Model.Standard.Finance;
  18. using XYY.Model.Standard.MpsOrder.dto;
  19. using XYY.Service.Standard.Customer;
  20. using XYY.Service.Standard.Finance;
  21. namespace XYY.Api.Finance.Controllers
  22. {
  23. [Route("api/[controller]/[action]")]
  24. [ApiController]
  25. public class FinanceCustomerSupplementsController : ApiControllerBase
  26. {
  27. IFinance_Customer_SupplementService supplementService;
  28. IConfiguration _configuration;
  29. ICustomerService customerService;
  30. public FinanceCustomerSupplementsController(IFinance_Customer_SupplementService supplementService, IConfiguration configuration, ICustomerService customerService)
  31. {
  32. this.supplementService = supplementService;
  33. _configuration = configuration;
  34. this.customerService = customerService;
  35. }
  36. public async Task<IActionResult> Add(Finance_Customer_Supplement fcs)
  37. {
  38. await this.supplementService.Add(fcs);
  39. return Ok();
  40. }
  41. public async Task<IActionResult> Edit(Finance_Customer_Supplement fcs)
  42. {
  43. await this.supplementService.Edit(fcs);
  44. return Ok();
  45. }
  46. [HttpPost]
  47. public async Task<IActionResult> GetPageResult(QueryModel queryModel)
  48. {
  49. var pageReuslt = await this.supplementService.GetPageResult(queryModel);
  50. return Ok(pageReuslt);
  51. }
  52. public class SkuFeeReqItem
  53. {
  54. public decimal avgFee { get; set; }
  55. public int qty { get; set; }
  56. public string sku { get; set; }
  57. }
  58. public class SkuFeeReq
  59. {
  60. public int customerId { get; set; }
  61. public string day { get; set; }
  62. public List<SkuFeeReqItem> Items
  63. {
  64. get; set;
  65. }
  66. }
  67. public async Task<IActionResult> AddCustomerSKUFee(SkuFeeReq skuFeeReqRoot)
  68. {
  69. var customer = (await customerService.CacheGetAllCustomers()).FirstOrDefault(x => x.Id == skuFeeReqRoot.customerId);
  70. var nsmpCustomers = await customerService.GetNSMPCustomer();
  71. var list = new List<Finance_Customer_Supplement>();
  72. foreach (var skuFeeReq in skuFeeReqRoot.Items)
  73. {
  74. string orderNo = customer.CustomerNumber + "_" + skuFeeReq.sku + "_" + skuFeeReqRoot.day;
  75. var supplement = new Finance_Customer_Supplement
  76. {
  77. Fee = skuFeeReq.avgFee * skuFeeReq.qty,
  78. CreateOrderChannelId = 0,
  79. CustomerId = skuFeeReqRoot.customerId,
  80. CurrenyRate = "CNY",
  81. FinanceCustomerSupplementType = FinanceCustomerSupplementOrDeductionType.补_Sku处理费,
  82. CustomerOrderNo = orderNo,
  83. Describe = "Sku处理费",
  84. FeeString = string.Empty,
  85. Guid = Guid.NewGuid().ToString(),
  86. Month = skuFeeReqRoot.day,
  87. SMPDetailType = "Sku处理费",
  88. OrderId = 0,
  89. SystemNo = orderNo,
  90. Remark = string.Empty,
  91. OrderRemark = $"单价:{skuFeeReq.avgFee.ToString("0.00")},数量:{skuFeeReq.qty},总价{skuFeeReq.avgFee * skuFeeReq.qty}",
  92. TrackingNumber = skuFeeReq.sku,
  93. };
  94. list.Add(supplement);
  95. }
  96. await this.supplementService.InputFinanceCustomerSupplements(FinanceCustomerSupplementOrDeductionType.补_Sku处理费, list);
  97. var nsmpList = list.Where(x => nsmpCustomers.Contains(x.CustomerId)).ToList();
  98. if (nsmpList.Count() != 0)
  99. {
  100. await this.supplementService.InputFinanceCustomerSupplementsNew(FinanceCustomerSupplementOrDeductionType.补_Sku处理费, nsmpList);
  101. }
  102. return Ok();
  103. }
  104. public async Task<IActionResult> InputFinanceCustomerSupplements(
  105. FinanceCustomerSupplementOrDeductionType type,
  106. string url,
  107. string month,
  108. bool isNewFee,
  109. string currencyCode = "CNY",
  110. SupplementTargetType targetValue = SupplementTargetType.全部)
  111. {
  112. List<Finance_Customer_Supplement> list = new List<Finance_Customer_Supplement>();
  113. var nsmpCustomers = await customerService.GetNSMPCustomer();
  114. if (type == FinanceCustomerSupplementOrDeductionType.补_通用杂费)
  115. {
  116. System.Net.WebClient client = new System.Net.WebClient();
  117. byte[] data = client.DownloadData(url);
  118. MSExcelHelper excelHelper = new MSExcelHelper();
  119. var fees = excelHelper.LoadDataByByte<OtherFeeSupplementMapping, Finance_Customer_Supplement>(data);
  120. foreach (var item in fees)
  121. {
  122. item.CurrenyRate = currencyCode;
  123. item.Describe = item.AvgFee + item.CurrenyRate + "*" + item.Qty;
  124. item.CurrenyRate = currencyCode;
  125. item.SupplementTargetType = (int)targetValue;
  126. item.FinanceCustomerSupplementType = type;
  127. item.FeeString = item.Fee + item.CurrenyRate;
  128. list.Add(item);
  129. }
  130. await this.supplementService.InputFinanceCustomerSupplements(type, list);
  131. var nsmpList2 = list.Where(x => nsmpCustomers.Contains(x.CustomerId)).ToList();
  132. if (nsmpList2.Count() != 0)
  133. {
  134. await this.supplementService.InputFinanceCustomerSupplementsNew(type, nsmpList2);
  135. }
  136. return Ok();
  137. }
  138. else
  139. {
  140. System.Net.WebClient client = new System.Net.WebClient();
  141. byte[] data = client.DownloadData(url);
  142. MSExcelHelper excelHelper = new MSExcelHelper();
  143. list = excelHelper.LoadDataByByte<CustomerSupplementMapping, Finance_Customer_Supplement>(data);
  144. foreach (var item in list)
  145. {
  146. item.CurrenyRate = currencyCode;
  147. item.SupplementTargetType = (int)targetValue;
  148. item.FinanceCustomerSupplementType = type;
  149. }
  150. FinanceCustomerSupplementOrDeductionType financeCustomerSupplementType = type;
  151. list.ForEach(x =>
  152. {
  153. x.FinanceCustomerSupplementType = type;
  154. if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.补_退件费)
  155. {
  156. x.Describe = "退件费";
  157. }
  158. else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.补_重派费)
  159. {
  160. x.Describe = "重派费";
  161. }
  162. else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.扣_重量差异费)
  163. {
  164. x.Describe = "重量差异费";
  165. }
  166. else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.扣_时间差异费)
  167. {
  168. x.Describe = "时间差异费";
  169. }
  170. else if (x.FinanceCustomerSupplementType == FinanceCustomerSupplementOrDeductionType.扣_索赔)
  171. {
  172. x.Describe = "索赔费用";
  173. }
  174. x.Month = month;
  175. });
  176. }
  177. await this.supplementService.InputFinanceCustomerSupplements(type, list);
  178. var nsmpList = list.Where(x => nsmpCustomers.Contains(x.CustomerId)).ToList();
  179. if (nsmpList.Count() != 0)
  180. {
  181. await this.supplementService.InputFinanceCustomerSupplementsNew(type, nsmpList);
  182. }
  183. return Ok();
  184. }
  185. public async Task<IActionResult> GetFinanceCustomerSupplementTypes()
  186. {
  187. var items = EnumsHelper.GetEnumItems(typeof(FinanceCustomerSupplementOrDeductionType));
  188. return Ok(items);
  189. }
  190. public class OtherFeeSupplementMapping : MSExcelClassMapping<Finance_Customer_Supplement>
  191. {
  192. public OtherFeeSupplementMapping()
  193. {
  194. Map(x => x.SystemNo).Name("订单编号");
  195. Map(x => x.TrackingNumber).Name("订单编号");
  196. Map(x => x.CustomerOrderNo).Name("订单编号");
  197. Map(x => x.CreateTime).Name("业务时间");
  198. Map(x => x.CustomerName).Name("客户");
  199. Map(x => x.SMPDetailType).Name("费用名称");
  200. Map(x => x.AvgFee).Name("单价");
  201. Map(x => x.Qty).Name("数量");
  202. Map(x => x.Fee).Name("金额");
  203. Map(x => x.OrderRemark).Name("备注");
  204. }
  205. }
  206. public class CustomerSupplementMapping : MSExcelClassMapping<Finance_Customer_Supplement>
  207. {
  208. public CustomerSupplementMapping()
  209. {
  210. Map(x => x.SystemNo).Name("跟踪号");
  211. Map(x => x.SystemNo).Name("运单号");
  212. Map(x => x.SystemNo).Name("内部单号");
  213. Map(x => x.SMPDetailType).Name("费用类型");
  214. Map(x => x.FeeString).Name("费用");
  215. Map(x => x.FeeString).Name("金额");
  216. Map(x => x.FeeString).Name("退件费");
  217. Map(x => x.FeeString).Name("重派费用元/票(RMB)");
  218. Map(x => x.Describe).Name("明细");
  219. Map(x => x.OrderRemark).Name("重派单号");
  220. Map(x => x.OrderRemark).Name("尺寸");
  221. Map(x => x.OrderRemark).Name("退件原因");
  222. }
  223. }
  224. public async Task<IActionResult> Remave(Finance_Customer_Supplement fcs)
  225. {
  226. await this.supplementService.Remave(fcs);
  227. return Ok();
  228. }
  229. }
  230. }