FinanceQuotationController.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Caching.Distributed;
  4. using NPOI.SS.UserModel;
  5. using NPOI.XSSF.UserModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using XYY.Authentication.Standard;
  12. using XYY.Common.Standard;
  13. using XYY.Core.Standard.Mvc;
  14. using XYY.Data.Standard.Finance;
  15. using XYY.Model.Standard.Dto.Finance;
  16. using XYY.Model.Standard.Enums;
  17. using XYY.Model.Standard.Finance;
  18. using XYY.Service.Standard.Finance;
  19. using XYY.TaskTrack.Standard;
  20. using XYY.TaskTrack.Standard.TaskModel;
  21. namespace XYY.Api.Finance.Controllers
  22. {
  23. [Route("api/[controller]/[action]")]
  24. [ApiController]
  25. public class FinanceQuotationController : ApiControllerBase
  26. {
  27. XYY.Core.Standard.AliYun.IAliYunPostFileSerivce _aliYunPostFileSerivce;
  28. private IQuotationService _quotationService;
  29. private IQuotationApproveService _quotationApproveService;
  30. private IMQManager _MQManager;
  31. private XYY.Data.Standard.IUserCustomerRepository _userCustomerRepository;
  32. private IDingDingBaseService _dingDingBaseService;
  33. IDistributedCache _cache;
  34. private ILogistics_ExpressSettlementAdjustmentRepository _expressSettlementAdjustmentRepository;
  35. ILogistics_ExpressFeeBaseRepository _feeBaseRepository;
  36. private IFinance_ServiceSurchargeService _serviceSurchargeService;
  37. public FinanceQuotationController(IQuotationService quotationService, IQuotationApproveService quotationApproveService, IMQManager MQManager, Data.Standard.IUserCustomerRepository userCustomerRepository, IDingDingBaseService dingDingBaseService, IDistributedCache cache, Core.Standard.AliYun.IAliYunPostFileSerivce aliYunPostFileSerivce, ILogistics_ExpressSettlementAdjustmentRepository expressSettlementAdjustmentRepository, IFinance_ServiceSurchargeService serviceSurchargeService, ILogistics_ExpressFeeBaseRepository feeBaseRepository)
  38. {
  39. _quotationService = quotationService;
  40. _quotationApproveService = quotationApproveService;
  41. _MQManager = MQManager;
  42. _userCustomerRepository = userCustomerRepository;
  43. _dingDingBaseService = dingDingBaseService;
  44. _cache = cache;
  45. _aliYunPostFileSerivce = aliYunPostFileSerivce;
  46. _expressSettlementAdjustmentRepository = expressSettlementAdjustmentRepository;
  47. _serviceSurchargeService = serviceSurchargeService;
  48. _feeBaseRepository = feeBaseRepository;
  49. }
  50. public async Task<IActionResult> QueryPublic(QueryModel queryModel)
  51. {
  52. var user = User.GetUserContent();
  53. if (user.Roles.Any(x => x == "销售"))
  54. {
  55. if (queryModel.QueryParamer == null)
  56. queryModel.QueryParamer = new List<QueryParamer>();
  57. queryModel.QueryParamer.Add(new QueryParamer
  58. {
  59. Method = "Eq",
  60. Filed = "SalesmanUserId",
  61. Value = user.Id.ToString()
  62. });
  63. }
  64. var data = await _quotationService.QueryData(queryModel);
  65. return Ok(data);
  66. }
  67. public async Task<IActionResult> Query(QueryModel queryModel)
  68. {
  69. var user = User.GetUserContent();
  70. if (user.Roles.Any(x => x == "销售"))
  71. {
  72. if (queryModel.QueryParamer == null)
  73. queryModel.QueryParamer = new List<QueryParamer>();
  74. queryModel.QueryParamer.Add(new QueryParamer
  75. {
  76. Method = "Eq",
  77. Filed = "SalesmanUserId",
  78. Value = user.Id.ToString()
  79. });
  80. }
  81. var data = await _quotationService.QueryData(queryModel);
  82. return Ok(data);
  83. }
  84. public async Task<IActionResult> GetChinaPostPublic(int channelId)
  85. {
  86. //邮政公开价
  87. var data = await _quotationService.QueryChinaPostPublicData(channelId);
  88. return Ok(data);
  89. }
  90. [HttpPost]
  91. [HttpGet]
  92. public async Task<IActionResult> GetChinaPostPublicDiscount(QueryModel queryMdoel)
  93. {
  94. var data = await _quotationService.QueryChinaPostPublicDiscount(queryMdoel);
  95. return Ok(data);
  96. }
  97. [HttpGet]
  98. public async Task<IActionResult> GetSettlementAdjustmentMode()
  99. {
  100. var r = new object[]
  101. {
  102. new {
  103. Key = "每票元",
  104. Value=1
  105. },
  106. new {
  107. Key = "每500G元",
  108. Value=2
  109. },
  110. new {
  111. Key = "比例(%)",
  112. Value=3
  113. }
  114. };
  115. return Ok(r);
  116. }
  117. [HttpPost]
  118. [HttpGet]
  119. public async Task<IActionResult> InputChinaPostData(string url, string sheetName)
  120. {
  121. System.Net.WebClient client = new System.Net.WebClient();
  122. var data = client.DownloadData(url);
  123. var json = _quotationService.ImportExcelToChinaPostPublicJson(data, sheetName);
  124. return Ok(json);
  125. }
  126. public async Task<IActionResult> GetExpressFeeAsAdjustment(Logistics_ExpressSettlementAdjustmentDto adjustmentDto)
  127. {
  128. QueryModel query = new QueryModel()
  129. {
  130. QueryParamer = new List<QueryParamer> {
  131. new QueryParamer{
  132. Filed = "SealId",
  133. Value="True"
  134. } ,
  135. new QueryParamer{
  136. Filed = "customerids",
  137. Method="In",
  138. Value = String.Join(',', adjustmentDto.CustomerId)
  139. },
  140. new QueryParamer{
  141. Filed ="ExpressId",
  142. Value = adjustmentDto.ExpressId.ToString()
  143. }
  144. }
  145. };
  146. adjustmentDto.Details.ForEach(x => x.IsAll = x.Zone.Split(",").Contains("全部"));
  147. var detail = await _quotationService.QueryViewExpressSettlement(query);
  148. var all = adjustmentDto.Details.Where(x => x.IsAll);
  149. //冲突调整判断
  150. var notAll = adjustmentDto.Details.Where(x => !x.IsAll).ToList();
  151. //数据校验处理
  152. var verify = AdjustmentDtoVerify(notAll);
  153. //全部调整
  154. if (all.Count() > 1)
  155. {
  156. throw new Exception("全部调整时,仅允许单种策略");
  157. }
  158. else if (!verify.Item1) { throw new Exception(verify.Item2); }
  159. else if (all.Count() == 1 && verify.Item1)
  160. {
  161. var a = all.First();
  162. var df = detail.First() as object;
  163. Type type = typeof(object);
  164. var ps = type.GetProperties();
  165. //int wi = 1;
  166. List<string> singleZone = notAll.SelectMany(x => x.Zone.Split(",")).ToList();
  167. foreach (var d in detail.Where(x => !singleZone.Contains(x.操作费)))//排除单个调整项
  168. {
  169. double f = double.Parse(d.运费);
  170. switch (a.Mode)
  171. {
  172. case SettlementAdjustmentMode.比例:
  173. f += Math.Round(f * (a.Value / 100), 3);
  174. break;
  175. case SettlementAdjustmentMode.每票元:
  176. f += a.Value;
  177. break;
  178. case SettlementAdjustmentMode.每500G元:
  179. f += Convert.ToDouble(d.结束重量) / 0.5 * a.Value;// f + a.Value * wi;
  180. break;
  181. }
  182. d.运费 = f.ToString();
  183. }
  184. //wi++;
  185. }
  186. //单独调整
  187. if (notAll != null && notAll.Count > 0)
  188. {
  189. foreach (var item in notAll)
  190. {
  191. foreach (var d in detail.Where(x => item.Zone.Split(",").Contains(x.操作费)))
  192. {
  193. double f = double.Parse(d.运费);
  194. switch (item.Mode)
  195. {
  196. case SettlementAdjustmentMode.比例:
  197. f += Math.Round(f * (item.Value / 100), 3);
  198. break;
  199. case SettlementAdjustmentMode.每票元:
  200. f += item.Value;
  201. break;
  202. case SettlementAdjustmentMode.每500G元:
  203. f += Convert.ToDouble(d.结束重量) / 0.5 * item.Value;// f + a.Value * wi;
  204. break;
  205. }
  206. d.运费 = f.ToString();
  207. }
  208. }
  209. }
  210. var json = _quotationService.ConvertSettlementView(detail.ToList());
  211. return Ok(new { json, detail });
  212. }
  213. /// <summary>
  214. /// 数据校验处理
  215. /// </summary>
  216. /// <returns></returns>
  217. private Tuple<bool, string> AdjustmentDtoVerify(List<Logistics_ExpressSettlementAdjustmentDetail> notAll)
  218. {
  219. bool result = true; string msg = string.Empty;
  220. if (notAll == null || notAll.Count == 0) { return Tuple.Create(result, msg); }
  221. //同一个分区不能出现两次
  222. List<string> zones = notAll.SelectMany(x => x.Zone.Split(",")).Distinct().ToList();
  223. foreach (var item in zones)
  224. {
  225. var temp = notAll.Where(x => x.Zone.Split(",").Contains(item)).ToList();
  226. if (temp.Count > 1) { result = false; msg += $"分区【{item}】\r\n"; }
  227. }
  228. if (!string.IsNullOrEmpty(msg)) { msg += ",存在多个调整!"; }
  229. return Tuple.Create(result, msg);
  230. }
  231. [HttpPost]
  232. /// <summary>
  233. /// 生成文件
  234. /// 并记录调整逻辑
  235. /// </summary>
  236. /// <param name="adjustmentDto"></param>
  237. /// <param name="detail"></param>
  238. /// <returns></returns>
  239. public async Task<IActionResult> GenerateExpressFeeFile(GenerateExpressFeeFileDto dto)
  240. {
  241. List<Tuple<string, string>> msgs = await _expressSettlementAdjustmentRepository.ExpressSettlementAdjustmentLog(dto.adjustmentDto);
  242. //生成计费文件
  243. string file = GetExpressFeeFile(msgs, dto.detail);
  244. if (string.IsNullOrEmpty(file)) { throw new Exception("生成调整文件失败,请联系技术部!"); }
  245. return Ok(file);
  246. }
  247. private string GetExpressFeeFile(List<Tuple<string, string>> msgs, IEnumerable<View_Quotation> detail)
  248. {
  249. string fileUrl = string.Empty;
  250. #region 基础数据整理
  251. var weights = detail.GroupBy(x => x.结束重量).ToList();
  252. List<string> headName = new List<string> { "公斤/分区" };
  253. var temp = weights[0].Select(x => x.操作费).Distinct().ToList();
  254. headName.AddRange(temp);
  255. headName.Add("备注");
  256. #endregion
  257. //考虑文件表头会变动 48和50共用
  258. XSSFWorkbook excelBook = new XSSFWorkbook();
  259. #region 样式处理
  260. //表头字体设置
  261. NPOI.SS.UserModel.IFont headFont = excelBook.CreateFont();
  262. headFont.FontHeightInPoints = 14;
  263. headFont.IsBold = true;
  264. NPOI.SS.UserModel.IFont sheetTable1Font = excelBook.CreateFont();
  265. sheetTable1Font.FontHeightInPoints = 11;
  266. sheetTable1Font.IsBold = true;
  267. //sheet 1表头
  268. ICellStyle headStyle = excelBook.CreateCellStyle();
  269. headStyle.WrapText = true;//设置换行这个要先设置
  270. headStyle.Alignment = HorizontalAlignment.Center;
  271. headStyle.BorderBottom = BorderStyle.Thin;
  272. headStyle.BorderTop = BorderStyle.Thin;
  273. headStyle.BorderLeft = BorderStyle.Thin;
  274. headStyle.BorderRight = BorderStyle.Thin;
  275. headStyle.SetFont(headFont);
  276. //单元格通用样式
  277. ICellStyle styleCommonCenter = excelBook.CreateCellStyle();
  278. styleCommonCenter.Alignment = HorizontalAlignment.Center;
  279. styleCommonCenter.WrapText = true;
  280. styleCommonCenter.VerticalAlignment = VerticalAlignment.Center;
  281. styleCommonCenter.BorderBottom = BorderStyle.Thin;
  282. styleCommonCenter.BorderTop = BorderStyle.Thin;
  283. styleCommonCenter.BorderLeft = BorderStyle.Thin;
  284. styleCommonCenter.BorderRight = BorderStyle.Thin;
  285. #endregion
  286. ISheet sheet = excelBook.CreateSheet("Sheet1");
  287. IRow row = sheet.CreateRow(0);
  288. row.Height = 200 * 3;
  289. for (int i = 0; i < headName.Count; i++)
  290. {
  291. sheet.SetColumnWidth(i, 20 * 256);
  292. ICell cell = row.CreateCell(i);
  293. cell.CellStyle = headStyle;
  294. cell.SetCellValue(headName[i]);
  295. //批注处理 不使用批注 全部设置不好对应
  296. //var tempZone = msgs.Where(x => x.Item1 == headName[i]).FirstOrDefault();
  297. //if (temp != null)
  298. //{
  299. // IDrawing drawing = sheet.CreateDrawingPatriarch();
  300. // IComment comment = drawing.CreateCellComment(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 0, 0));
  301. // comment.String =new XSSFRichTextString(tempZone.Item2);
  302. // comment.Author = "zkl";
  303. // cell.CellComment = comment;
  304. //}
  305. }
  306. //处理数据行写入
  307. for (int i = 0; i < weights.Count; i++)
  308. {
  309. IRow dataRow = sheet.CreateRow(i + 1);
  310. for (int j = 0; j < headName.Count; j++)
  311. {
  312. ICell cell = dataRow.CreateCell(j);
  313. cell.CellStyle = styleCommonCenter;
  314. if (j == 0) { cell.SetCellValue(weights[i].Key); }
  315. else if (headName[j] == "备注") { if (i < msgs.Count) { cell.SetCellValue(msgs[i].Item2); } else { cell.SetCellValue(""); } }
  316. else { cell.SetCellValue(weights[i].Where(x => x.操作费 == headName[j]).FirstOrDefault().运费); }
  317. }
  318. }
  319. MemoryStream stream = new MemoryStream();
  320. excelBook.Write(stream);
  321. var buf = stream.ToArray();
  322. fileUrl = _aliYunPostFileSerivce.PostHttpFile(new MemoryStream(buf), Guid.NewGuid().ToString() + ".xlsx");
  323. return fileUrl;
  324. }
  325. public async Task<IActionResult> GetExoressZones(int expressId)
  326. {
  327. var zones = await _quotationService.GetExpressZones(expressId);
  328. zones.Insert(0, "全部");
  329. return Ok(zones);
  330. }
  331. public async Task<IActionResult> GetFedexFeeOther()
  332. {
  333. var feeOther = await _serviceSurchargeService.GetFeeOther(new QueryModel
  334. {
  335. QueryParamer = new List<QueryParamer> { new QueryParamer {
  336. Filed = "ExpressId", Method = "Eq", Value = "48" } }
  337. });
  338. return Ok(feeOther);
  339. }
  340. public async Task<IActionResult> GetDHLFeeOther()
  341. {
  342. var feeOther = await _serviceSurchargeService.GetFeeOther(new QueryModel
  343. {
  344. QueryParamer = new List<QueryParamer> { new QueryParamer {
  345. Filed = "ExpressId", Method = "Eq", Value = "50" } }
  346. });
  347. return Ok(feeOther);
  348. }
  349. public async Task<IActionResult> GetFedexBaseFee(QueryModel queryModel)
  350. {
  351. var additionalCharge = await _serviceSurchargeService.QueryDetail(queryModel);
  352. var feeOther = await _serviceSurchargeService.GetFeeOther(queryModel);
  353. var feeBase = await _quotationService.QueryExpressFeeBase(queryModel);
  354. var jsonData = await _quotationService.QueryExpressSettlement(queryModel);
  355. //var FuelSurcharge = "";
  356. return Ok(new { feeBase = feeBase, jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(jsonData), additionalCharge = additionalCharge, feeOther = feeOther });
  357. }
  358. public async Task<IActionResult> ImportExcelToJson(Dto dto)
  359. {
  360. var file = new System.Net.WebClient().DownloadData(dto.FileUrl);
  361. var list = _quotationService.ImportExcelToJson(file);
  362. return Ok(list);
  363. }
  364. public class Dto
  365. {
  366. public string FileUrl
  367. {
  368. get; set;
  369. }
  370. public string Remark
  371. {
  372. get; set;
  373. }
  374. public int[] ChangeCustomers
  375. {
  376. get; set;
  377. }
  378. public int ExpressId
  379. {
  380. get; set;
  381. }
  382. /// <summary>
  383. /// 渠道名称
  384. /// 目前仅邮政公开价才有
  385. /// E特快 邮政E邮宝A 邮政E邮宝B 特货E邮宝
  386. /// </summary>
  387. public string ExpresssName { get; set; }
  388. public DateTime setTime
  389. {
  390. get; set;
  391. }
  392. public int userId
  393. {
  394. get; set;
  395. }
  396. public IEnumerable<View_Quotation> detail
  397. {
  398. get; set;
  399. }
  400. }
  401. [AllowAnonymous]
  402. [HttpGet]
  403. public async Task<IActionResult> GetKDFee(int customerId, bool isChengDuQuotation = false)
  404. {
  405. var fileName = await _quotationApproveService.GetGZKDFee2022(customerId, isChengDuQuotation);
  406. var stream = System.IO.File.OpenRead(fileName);
  407. return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  408. }
  409. [AllowAnonymous]
  410. [HttpGet]
  411. public async Task<IActionResult> GetCDKDFee(int customerId)
  412. {
  413. string fileName = await _quotationApproveService.GetGZKDFee2022(customerId, true);
  414. var stream = System.IO.File.OpenRead(fileName);
  415. return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  416. return Ok();
  417. }
  418. public async Task<IActionResult> SendDingDing(List<Dto> dtos)
  419. {
  420. if (dtos.Any(x => x.ChangeCustomers == null || x.ChangeCustomers.Length == 0))
  421. throw new Exception("必须选择变更客户");
  422. if (dtos.Count > 0)
  423. {
  424. CspaceFile cspaceFile = null;
  425. string fileUrl = dtos.First().FileUrl;
  426. int userId = User.GetUserContent().Id;
  427. var u = await _dingDingBaseService.GetDingDingUserInfo(userId);
  428. if (!string.IsNullOrEmpty(fileUrl))
  429. {
  430. //string tempFilePath = System.IO.Path.Combine(System.AppContext.BaseDirectory, "temp");
  431. //if (System.IO.Directory.Exists(tempFilePath))
  432. //{
  433. // System.IO.Directory.CreateDirectory(tempFilePath);
  434. //}
  435. //string fileName = System.IO.Path.GetFileName(fileUrl);
  436. //string filePath = System.IO.Path.Combine(tempFilePath, fileName);
  437. //System.Net.WebClient webClient = new System.Net.WebClient();
  438. //webClient.DownloadFile(fileUrl, filePath);
  439. //cspaceFile = await _dingDingBaseService.UpdateFileToCspace(u, fileName, filePath);
  440. }
  441. foreach (var dto in dtos)
  442. {
  443. dto.userId = userId;
  444. //string processInstanceId =
  445. // await _quotationService.SendDingDing(dto.ChangeCustomers, dto.ExpressId, dto.setTime, dto.userId, dto.Remark, dto.detail, cspaceFile);
  446. string processInstanceId = Guid.NewGuid().ToString();
  447. long approveId =
  448. await _quotationApproveService.SaveApprove(processInstanceId, dto.ChangeCustomers, dto.ExpressId, dto.setTime, dto.userId, dto.detail, fileUrl, dto.Remark);
  449. //userId = 163;
  450. //await _quotationService.SendDingDing(dto.ChangeCustomers, dto.ExpressId, dto.setTime, userId, dto.detail);
  451. }
  452. }
  453. return Ok();
  454. }
  455. public async Task<IActionResult> SendNowCustomerQuotaion(FinanceQuotation financeQuotation)
  456. {
  457. string message = await _quotationApproveService.SendNowCustomerQuotaion(financeQuotation);
  458. return Ok(message);
  459. }
  460. public async Task<IActionResult> HandleQuotationApproved(string ddid)
  461. {
  462. await _quotationApproveService.HandleQuotationApproved(ddid);
  463. return Ok();
  464. }
  465. public async Task<IActionResult> SendNowCustomerQuotaions(FinanceQuotation financeQuotation)
  466. {
  467. foreach (var item in financeQuotation.CustomerIds)
  468. {
  469. var customer = await _userCustomerRepository.GetAsync(item);
  470. FinanceQuotation f = new FinanceQuotation
  471. {
  472. CusotmerId = item,
  473. CustomerName = customer.CompanyName,
  474. EntryTime = "2021-12-03",
  475. UserId = 52
  476. };
  477. await _quotationApproveService.SendNowCustomerQuotaion(f);
  478. }
  479. return Ok();
  480. }
  481. [AllowAnonymous]
  482. [HttpGet]
  483. public async Task<IActionResult> TestProcess(string pid)
  484. {
  485. try
  486. {
  487. //await _quotationApproveService.HandleQuotationApproved(pid);
  488. List<int> ids = new List<int> { 9390 };
  489. await _quotationApproveService.SendGenerateFeeBaseFileMessage(ids, 6, "2021-11-19");
  490. }
  491. catch (Exception ex)
  492. {
  493. }
  494. return Ok();
  495. }
  496. [AllowAnonymous]
  497. [HttpPost]
  498. public async Task<IActionResult> TestSub(FinanceQuotation quotation)
  499. {
  500. await _MQManager.Publish(quotation);
  501. return Ok();
  502. }
  503. public async Task<IActionResult> PassQuotationApproved(string quotationId)
  504. {
  505. await _quotationApproveService.HandleQuotationDiscountApproved(quotationId);
  506. return Ok();
  507. }
  508. public async Task<IActionResult> PassExpressApproved(string quotationId)
  509. {
  510. await _quotationApproveService.HandleQuotationApproved(quotationId);
  511. return Ok();
  512. }
  513. public async Task<IActionResult> HandleQuotationReject(string ddid)
  514. {
  515. await _quotationApproveService.HandleQuotationReject(ddid);
  516. return Ok();
  517. }
  518. [HttpPost]
  519. public async Task<IActionResult> QueryQuotationApproveRecord(QueryModel queryModel)
  520. {
  521. if (queryModel.QueryParamer == null)
  522. queryModel.QueryParamer = new List<QueryParamer>();
  523. if (User.GetUserContent().Roles.Contains("报价超管"))
  524. {
  525. }
  526. else if (User.GetUserContent().Roles.Any(x => x.StartsWith("报价审批")))
  527. {
  528. queryModel.QueryParamer.Add(new QueryParamer
  529. {
  530. Filed = "CheckRoleName",
  531. Method = "Eq",
  532. Value = User.GetUserContent().Roles.First(x => x.StartsWith("报价审批"))
  533. });
  534. }
  535. else
  536. {
  537. queryModel.QueryParamer.Add(new QueryParamer
  538. {
  539. Filed = "CreateUserName",
  540. Method = "Eq",
  541. Value = User.GetUserContent().NiceName
  542. });
  543. }
  544. if (queryModel.QuerySort == null)
  545. {
  546. queryModel.QuerySort = new List<QuerySort>();
  547. queryModel.QuerySort.Add(new QuerySort
  548. {
  549. Field = "Id",
  550. IsDesc = true
  551. });
  552. }
  553. PageResult<QuotationApproveRecordDto> data = await _quotationApproveService.QueryApproveRecord(queryModel);
  554. return Ok(data);
  555. }
  556. [HttpGet]
  557. public async Task<IActionResult> GetQuotationDetail(int id)
  558. {
  559. IEnumerable<Finance_QutationApproveDetail> data = await _quotationApproveService.GetQuotationDetail(id);
  560. return Ok(data);
  561. }
  562. [HttpGet]
  563. public async Task<IActionResult> ExportQuotation(int customerId)
  564. {
  565. ExportQuotationParam param = new ExportQuotationParam { CustomerId = customerId };
  566. byte[] data = await _quotationApproveService.ExportQuotation(customerId);
  567. return File("报价.xlsx", data);
  568. //var fileName = await _quotationApproveService.GetCDKDFee(customerId);
  569. //var stream = System.IO.File.OpenRead(fileName);
  570. //return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  571. }
  572. public class ExportQuotationRequest
  573. {
  574. public List<int> CustomerIds
  575. {
  576. get; set;
  577. }
  578. public DateTime time
  579. {
  580. get; set;
  581. }
  582. }
  583. [HttpPost]
  584. public async Task<IActionResult> ExportQuotation(ExportQuotationRequest request)
  585. {
  586. byte[] data = await _quotationApproveService.ExportQuotation(request.CustomerIds, request.time);
  587. return File("报价.zip", data);
  588. }
  589. [AllowAnonymous]
  590. [HttpPost]
  591. public async Task<IActionResult> GenerateFeeBaseFile(GenerateFeeBaseFileMessage param)
  592. {
  593. await _quotationApproveService.UpdateFeeBaseFile(param);
  594. return Ok();
  595. }
  596. [AllowAnonymous]
  597. [HttpPost, HttpGet]
  598. public async Task<IActionResult> QueryPriceVer(QueryPriceVerReq req)
  599. {
  600. var data = await _quotationService.QueryPriceVer(req.customerNumber, req.expressId);
  601. return Ok(data);
  602. }
  603. [AllowAnonymous]
  604. [ HttpGet]
  605. public async Task<IActionResult> SyncBaseFee(int customerId)
  606. {
  607. await _quotationApproveService.SyncBaseFee(customerId);
  608. return Ok();
  609. }
  610. [AllowAnonymous]
  611. [HttpPost]
  612. public async Task<IActionResult> SyncAccounts(int[] customerIds)
  613. {
  614. foreach (var item in customerIds)
  615. {
  616. await _quotationApproveService.CreateAccount(item);
  617. }
  618. return Ok();
  619. }
  620. [AllowAnonymous]
  621. [HttpPost]
  622. public async Task<IActionResult> SyncBaseFees(int[] customerIds)
  623. {
  624. foreach (var item in customerIds)
  625. {
  626. await _quotationApproveService.SyncBaseFee(item);
  627. }
  628. return Ok();
  629. }
  630. public class QueryPriceVerReq
  631. {
  632. public string customerNumber
  633. {
  634. get; set;
  635. }
  636. public int expressId
  637. {
  638. get; set;
  639. }
  640. }
  641. #region 快递调价处理
  642. [HttpPost]
  643. public async Task<IActionResult> InputExpressSettlement()
  644. {
  645. var filelist = (await Request.ReadFormAsync()).Files;
  646. if (filelist != null && filelist.Count > 0)
  647. {
  648. var file = filelist[0];
  649. using (var ms = new System.IO.MemoryStream())
  650. {
  651. file.CopyTo(ms);
  652. var result = _quotationService.InputExpressSettlement(ms.ToArray());
  653. string json = _quotationService.ConvertSettlementView(result);
  654. string url = _aliYunPostFileSerivce.PostHttpFile(new MemoryStream(ms.ToArray()), Guid.NewGuid().ToString() + ".xlsx");
  655. return Ok(new { json = json, url = url, detail = result });
  656. }
  657. }
  658. else
  659. {
  660. return Error("请上传一个文件");
  661. }
  662. }
  663. #endregion
  664. #region 折扣信息处理
  665. [HttpPost]
  666. public async Task<IActionResult> InputChinaPostDiscountData()
  667. {
  668. var filelist = (await Request.ReadFormAsync()).Files;
  669. if (filelist != null && filelist.Count > 0)
  670. {
  671. var file = filelist[0];
  672. var result = await _quotationService.ImportExcelToChinaPostDiscountDataJson(file.OpenReadStream());
  673. return Ok(result);
  674. }
  675. else
  676. {
  677. return Error("请上传一个文件");
  678. }
  679. }
  680. public async Task<IActionResult> SendDingDingByDiscount(DiscountDto dto)
  681. {
  682. if (dto.discountData == null || dto.discountData.Count == 0)
  683. throw new Exception("无折扣数据提交,请导入数据后提交!");
  684. //四个渠道才有折扣
  685. if (dto.ExpressId != 26 && dto.ExpressId != 437 && dto.ExpressId != 106 && dto.ExpressId != 126) { throw new Exception("仅E邮宝A/E邮宝B/E特快/特货E邮宝,才有折扣!"); }
  686. if (dto.discountData.Count > 0)
  687. {
  688. int userId = User.GetUserContent().Id;
  689. string processInstanceId = Guid.NewGuid().ToString();
  690. //await _quotationService.SendDingDingByDiscount(dto, userId);
  691. long approveId =
  692. await _quotationApproveService.SaveApproveByDiscount(processInstanceId, userId, dto);
  693. }
  694. return Ok();
  695. }
  696. #endregion
  697. }
  698. }