FinanceController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. using Microsoft.AspNetCore.Mvc;
  2. using System;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using XYY.Service.Standard.Finance;
  6. using XYY.Core.Standard.AliYun;
  7. using XYY.Model.Standard.Finance;
  8. using XYY.Core.Standard.Mvc;
  9. using XYY.Common.Standard;
  10. using System.IO;
  11. using XYY.Model.Standard;
  12. using XYY.Service.Standard.Finance.Model;
  13. using XYY.Authentication.Standard;
  14. using Microsoft.AspNetCore.Authorization;
  15. namespace XYY.Api.Finance.Controllers
  16. {
  17. [Route("api/[controller]/[action]")]
  18. [ApiController]
  19. public class FinanceController : ApiControllerBase
  20. {
  21. ILadingBillService _ladingBillService;
  22. IAliYunPostFileSerivce _aliYunPostFileSerivce;
  23. ICustomerLadingBillCostService _customerLadingBillCostApp;
  24. public FinanceController(ILadingBillService ladingBillService
  25. , IAliYunPostFileSerivce aliYunPostFileSerivce,
  26. ICustomerLadingBillCostService customerLadingBillCostApp
  27. )
  28. {
  29. _ladingBillService = ladingBillService;
  30. _aliYunPostFileSerivce = aliYunPostFileSerivce;
  31. _customerLadingBillCostApp = customerLadingBillCostApp;
  32. }
  33. public async Task<IActionResult> GetQtys()
  34. {
  35. var billQtys = await _ladingBillService.GetGroupCounts();
  36. if (!billQtys.Any(x => x.Key == 0))
  37. billQtys.Add(0, 0);
  38. if (!billQtys.Any(x => x.Key == 1))
  39. billQtys.Add(1, 0);
  40. if (!billQtys.Any(x => x.Key == 2))
  41. billQtys.Add(2, 0);
  42. return Ok(billQtys.Select(x => new { Key = x.Key, Value = x.Value }).ToList());
  43. }
  44. [HttpPost]
  45. public async Task<IActionResult> GetFee(CustomerLadingBillSearchParam search)
  46. {
  47. if (search?.LaddingBills?.Any() != true)
  48. throw new Exception("参数不能为空");
  49. var content = await _customerLadingBillCostApp.DownloadLadingBillCost(search);
  50. return File($"提单_{DateTime.Now.ToString("yyyyMMddHHhhss")}.xlsx", content);
  51. }
  52. [HttpGet]
  53. public async Task<IActionResult> GetLadingDetails(string billNumber)
  54. {
  55. var content = await _customerLadingBillCostApp.DownloadLadingBillDetailCost(billNumber);
  56. return File($"提单{billNumber}明细.xlsx", content);
  57. }
  58. [HttpGet]
  59. public async Task<IActionResult> DownloadFile(int id, int type)
  60. {
  61. byte[] data = await _ladingBillService.OutBill(id, type);
  62. return File(DateTime.Now.ToString_yyyyMMddHHmm() + ".xls", data);
  63. }
  64. [HttpPost]
  65. public async Task<IActionResult> GetData(QueryModel queryModel)
  66. {
  67. if (queryModel.QueryParamer.Any(x => x.Filed == "BillType" && x.Value == "1"))
  68. {
  69. //所属划分
  70. //查找用户拥有的权限
  71. var u = User.GetUserContent();
  72. if (u.Roles.Any(x => x == "头程-朗天" || x == "头程-运控"))
  73. {
  74. var list = u.Roles.Where(x => x == "头程-朗天" || x == "头程-运控").ToList();
  75. queryModel.QueryParamer.Add(new QueryParamer
  76. {
  77. Filed = "DataBindRole",
  78. Value = String.Join(",", list.ToArray()),
  79. Method = "In"
  80. });
  81. }
  82. else
  83. {
  84. throw new Exception("无数据权限。请联系管理员添加");
  85. }
  86. }
  87. var data = await _ladingBillService.GetData(queryModel);
  88. return Ok(data);
  89. }
  90. public async Task<IActionResult> GetBillInfo(string billNumber)
  91. {
  92. var view = await _ladingBillService.GetInfo(billNumber);
  93. return Ok(view);
  94. }
  95. public async Task<IActionResult> PostStart(Finance_Logistics_LadingBill ladingBill)
  96. {
  97. await _ladingBillService.StartFrist(ladingBill.BillNumber, ladingBill.FristFileUrl, ladingBill.FristFee);
  98. return Ok();
  99. }
  100. public async Task<IActionResult> PostStart2(FinanceLadingBillDto dto)
  101. {
  102. if (dto.BillType == BillType.客户)
  103. {
  104. var u = User.GetUserContent();
  105. if (u.Roles.Any(x => x == "头程-朗天" || x == "头程-运控"))
  106. {
  107. if (u.Roles.Where(x => x == "头程-朗天" || x == "头程-运控").Count() > 1)
  108. {
  109. throw new Exception("操作人不应有多个所属,请联系管理员处理");
  110. }
  111. else
  112. {
  113. dto.DataBindRole = u.Roles.Where(x => x == "头程-朗天" || x == "头程-运控").First();
  114. }
  115. }
  116. else
  117. {
  118. throw new Exception("无数据权限。请联系管理员添加");
  119. }
  120. }
  121. await _ladingBillService.StartFrist(dto);
  122. return Ok();
  123. }
  124. [HttpGet]
  125. public async Task<IActionResult> GetIncidentals(int billId, int type)
  126. {
  127. var data = await _ladingBillService.GetIncidentals(billId, type);
  128. return Ok(data);
  129. }
  130. public async Task<IActionResult> PostEditBill(FinanceLadingBillDto ladingBill)
  131. {
  132. await _ladingBillService.Update(ladingBill);
  133. return Ok();
  134. }
  135. public async Task<IActionResult> PostPass(string billNumber)
  136. {
  137. await _ladingBillService.Review(billNumber, true);
  138. return Ok();
  139. }
  140. public async Task<IActionResult> PostReject(string billId)
  141. {
  142. await _ladingBillService.Review(billId, false);
  143. return Ok();
  144. }
  145. public class InputLadingBillDto
  146. {
  147. public string url
  148. {
  149. get; set;
  150. }
  151. public FinanceIncidentalTypeEnum feeType
  152. {
  153. get; set;
  154. }
  155. }
  156. readonly string tempPath = AppContext.BaseDirectory + "\\temp";
  157. [HttpPost]
  158. public async Task<IActionResult> PostInputFile(InputLadingBillDto dto)
  159. {
  160. //string filePath = tempPath + "\\" + Guid.NewGuid() + ".xlsx";
  161. System.Net.WebClient webClient = new System.Net.WebClient();
  162. byte[] data = webClient.DownloadData(dto.url);
  163. //System.IO.File.Delete(filePath);
  164. await _ladingBillService.ConvertLoadingBatchInputDto(data, dto.feeType);
  165. return Ok();
  166. }
  167. [HttpPost]
  168. public IActionResult UpdateLoadFile()
  169. {
  170. var filelist = Request.Form.Files;
  171. if (filelist != null && filelist.Count > 0)
  172. {
  173. var file = filelist[0];
  174. string url = _aliYunPostFileSerivce.PostHttpFile(file.OpenReadStream(), file.FileName);
  175. return Ok(new { url = url });
  176. }
  177. else
  178. {
  179. return Error("请上传一个文件");
  180. }
  181. }
  182. [HttpGet]
  183. [HttpPost]
  184. public async Task<IActionResult> GetEFFinanceBillGroup(BillSerach serach)
  185. {
  186. return Ok(await _ladingBillService.GetEFFinanceBillGroup(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId));
  187. }
  188. [HttpGet]
  189. [HttpPost]
  190. public async Task<IActionResult> GetEFFinanceBillGroupAsCustomer(BillSerach serach)
  191. {
  192. return Ok(await _ladingBillService.GetEFFinanceBillGroupAsCustomer(serach.StartDate, serach.EndDate));
  193. }
  194. [HttpGet]
  195. [HttpPost]
  196. public async Task<IActionResult> GetEFFinanceBillGroupAsChannel(BillSerach serach)
  197. {
  198. return Ok(await _ladingBillService.GetEFFinanceBillGroupAsChannel(serach.StartDate, serach.EndDate));
  199. }
  200. [HttpGet]
  201. [HttpPost]
  202. public async Task<IActionResult> GetEFFinanceBillDetails(BillSerach serach)
  203. {
  204. var list = await _ladingBillService.GetEFFinanceBillDetails(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId);
  205. return CSVFile("帐单明细.xls", list);
  206. }
  207. [HttpGet]
  208. [HttpPost]
  209. public async Task<IActionResult> GetFinanceBillGroup(BillSerach serach)
  210. {
  211. return Ok(await _ladingBillService.GetFinanceBillGroup(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId));
  212. }
  213. [HttpGet]
  214. [HttpPost]
  215. public async Task<IActionResult> GetFinanceBillGroupAsCustomer(BillSerach serach)
  216. {
  217. return Ok(await _ladingBillService.GetFinanceBillGroupAsCustomer(serach.StartDate, serach.EndDate));
  218. }
  219. [HttpGet]
  220. [HttpPost]
  221. public async Task<IActionResult> GetFinanceBillGroupAsChannel(BillSerach serach)
  222. {
  223. return Ok(await _ladingBillService.GetFinanceBillGroupAsChannel(serach.StartDate, serach.EndDate));
  224. }
  225. [HttpGet]
  226. [HttpPost]
  227. public async Task<IActionResult> GetFinanceBillDetails(BillSerach serach)
  228. {
  229. var list = await _ladingBillService.GetFinanceBillDetails(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId);
  230. return CSVFile("帐单明细.xls", list);
  231. }
  232. private SearchFinanceReportParam CreateFinanceReportParam(QueryModel queryModel)
  233. {
  234. SearchFinanceReportParam param = new SearchFinanceReportParam();
  235. if (queryModel?.QueryParamer?.Any() == true)
  236. {
  237. foreach (var p in queryModel.QueryParamer)
  238. {
  239. if (p.Filed == "CustomerId" && int.TryParse(p.Value, out int customerId))
  240. {
  241. param.CustomerId = customerId;
  242. }
  243. else if (p.Filed == "CreateOrderChannelId" && int.TryParse(p.Value, out int CreateOrderChannelId))
  244. {
  245. param.CreateOrderChannelId = CreateOrderChannelId;
  246. }
  247. else if (p.Filed == "BranchCompanyId" && int.TryParse(p.Value, out int BranchCompanyId))
  248. {
  249. param.BranchCompanyId = BranchCompanyId;
  250. }
  251. else if (p.Filed == "称重时间" && p.Method == "Gr" && DateTime.TryParse(p.Value, out DateTime receiveTimeStart))
  252. {
  253. param.ReceiveTimeStart = receiveTimeStart;
  254. }
  255. else if (p.Filed == "称重时间" && p.Method == "Le" && DateTime.TryParse(p.Value, out DateTime receiveTimeEnd))
  256. {
  257. param.ReceiveTimeEnd = receiveTimeEnd;
  258. }
  259. else if (p.Filed == "跟踪号" && !string.IsNullOrWhiteSpace(p.Value))
  260. {
  261. var arr = p.Value.Split(',', StringSplitOptions.RemoveEmptyEntries);
  262. param.TrackingNumbers = arr.ToList();
  263. }
  264. else if (p.Filed == "订单号" && !string.IsNullOrWhiteSpace(p.Value))
  265. {
  266. var arr = p.Value.Split(',', StringSplitOptions.RemoveEmptyEntries);
  267. param.TransferNumbers = arr.ToList();
  268. }
  269. else if (p.Filed == "提单号" && !string.IsNullOrWhiteSpace(p.Value))
  270. {
  271. var arr = p.Value.Split(',', StringSplitOptions.RemoveEmptyEntries);
  272. param.LadingBillNumbers = arr.ToList();
  273. }
  274. }
  275. }
  276. return param;
  277. }
  278. [HttpGet]
  279. [HttpPost]
  280. public async Task<IActionResult> DownFinanceBranchProfitReport(QueryModel queryModel)
  281. {
  282. var param = CreateFinanceReportParam(queryModel);
  283. var list = await _ladingBillService.DownFinanceBranchProfitReport(param);
  284. return CSVFile("财务报表.xls", list);
  285. }
  286. [HttpGet]
  287. [HttpPost]
  288. public async Task<IActionResult> DownFinanceReport(QueryModel queryModel)
  289. {
  290. var param = CreateFinanceReportParam(queryModel);
  291. var list = await _ladingBillService.DownFinanceReport(param);
  292. return CSVFile("财务报表.xls", list);
  293. }
  294. [HttpGet]
  295. [HttpPost]
  296. public async Task<IActionResult> GetFinanceReportDetails(QueryModel queryModel)
  297. {
  298. var list = await _ladingBillService.QueryFinanceReport(queryModel);
  299. return Ok(list);
  300. }
  301. [AllowAnonymous]
  302. public async Task<IActionResult> GetIncidentalGroupData(QueryModel queryModel)
  303. {
  304. var list = await _ladingBillService.GetIncidentalGroupData(queryModel);
  305. return Ok(list);
  306. }
  307. [AllowAnonymous]
  308. public async Task<IActionResult> GetIncidentalGroup()
  309. {
  310. var list = (await _ladingBillService.GetIncidentalGroup()).Select(x => new { Key = x.Key, Value = x.Value });
  311. return Ok(list);
  312. }
  313. public async Task<IActionResult> GetFinanceBillDetailWeightDifferenceGroup(BillSerach serach)
  314. {
  315. var list = await _ladingBillService.GetFinanceBillDetailWeightDifferenceGroup(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId);
  316. return Ok(list);
  317. }
  318. public async Task<IActionResult> OutFinanceBillDetailWeightDifferenceDetails(BillSerach serach)
  319. {
  320. byte[] financeBillDetailWeightDifferenceDetails = await _ladingBillService.OutFinanceBillDetailWeightDifferenceDetails(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId);
  321. return CSVFile("差异明细.xlsx", financeBillDetailWeightDifferenceDetails);
  322. }
  323. [HttpGet]
  324. [HttpPost]
  325. public async Task<IActionResult> GetBill(BillSerach serach)
  326. {
  327. return Ok(await _ladingBillService.GetView_FinanceBills(serach.ChannelId, serach.CustomerId, serach.StartDate, serach.EndDate, serach.SettlementCompany));
  328. }
  329. [HttpGet]
  330. [HttpPost]
  331. public async Task<IActionResult> GetBillDetail(BillSerach serach)
  332. {
  333. var list = await _ladingBillService.GetBillsDetails(serach.ChannelId, serach.CustomerId, serach.StartDate, serach.EndDate, serach.SettlementCompany);
  334. return CSVFile("帐单明细.csv", list);
  335. }
  336. public async Task<IActionResult> postPayment(PostPayment postPayment)
  337. {
  338. await _ladingBillService.PostPayment(postPayment.Id, postPayment.PostPaymentFee, postPayment.Type, postPayment.Remark);
  339. return Ok();
  340. }
  341. public async Task<IActionResult> GetLadingBillLogs(int billId, FinanceIncidentalTypeEnum type)
  342. {
  343. var list = await _ladingBillService.GetLadingBillLogs(billId, type);
  344. return Ok(list);
  345. }
  346. public async Task<IActionResult> DeleteBill(FinanceLadingBillDto financeLadingBillDto)
  347. {
  348. await _ladingBillService.DeleteBill(financeLadingBillDto.Id);
  349. return Ok();
  350. }
  351. public async Task<IActionResult> GetCompletionRate(BillSerach serach)
  352. {
  353. var data = await _ladingBillService.GetCompletionRate(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId);
  354. return Ok(data);
  355. }
  356. [HttpPost]
  357. public async Task<IActionResult> ExportCustomerMonitoring(QueryModel queryModel)
  358. {
  359. var list = await _ladingBillService.OutFinanceBillCustomerMonitoring(queryModel);
  360. return File("客户监控表.xlsx", list);
  361. }
  362. public class PostPayment
  363. {
  364. public decimal PostPaymentFee
  365. {
  366. get; set;
  367. }
  368. public int Id
  369. {
  370. get; set;
  371. }
  372. public FinanceIncidentalTypeEnum Type
  373. {
  374. get; set;
  375. }
  376. public string Remark
  377. {
  378. get; set;
  379. }
  380. }
  381. public class BillSerach
  382. {
  383. public int ChannelId
  384. {
  385. get; set;
  386. }
  387. public int CustomerId
  388. {
  389. get; set;
  390. }
  391. public DateTime StartDate
  392. {
  393. get; set;
  394. }
  395. public DateTime EndDate
  396. {
  397. get; set;
  398. }
  399. public SettlementCompany? SettlementCompany
  400. {
  401. get; set;
  402. }
  403. public int SalesmanUserId { get; set; }
  404. public int BranchCompanyId { get; set; }
  405. }
  406. public class FinanceReportSearchParam
  407. {
  408. public int? ChannelId
  409. {
  410. get; set;
  411. }
  412. public int? CustomerId
  413. {
  414. get; set;
  415. }
  416. public DateTime ReceiveTimeStart
  417. {
  418. get; set;
  419. }
  420. public DateTime ReceiveTimeEnd
  421. {
  422. get; set;
  423. }
  424. public int? BranchCompanyId { get; set; }
  425. }
  426. }
  427. }