GroupsController.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. using Aspose.Cells;
  2. using Aspose.Words;
  3. using Aspose.Words.Tables;
  4. using Microsoft.AspNetCore.Mvc;
  5. using NetTaste;
  6. using Newtonsoft.Json.Serialization;
  7. using NPOI.OpenXmlFormats.Spreadsheet;
  8. using NPOI.SS.Formula.Functions;
  9. using OASystem.API.OAMethodLib;
  10. using OASystem.Domain.Dtos.Groups;
  11. using OASystem.Domain.Entities.Business;
  12. using OASystem.Domain.Entities.Groups;
  13. using OASystem.Domain.ViewModels.Groups;
  14. using OASystem.Infrastructure.Repositories.Groups;
  15. using TencentCloud.Ocr.V20181119.Models;
  16. using OASystem.Infrastructure.Tools;
  17. using System.Web;
  18. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  19. namespace OASystem.API.Controllers
  20. {
  21. /// <summary>
  22. /// 团组相关
  23. /// </summary>
  24. //[Authorize]
  25. [Route("api/[controller]/[action]")]
  26. public class GroupsController : ControllerBase
  27. {
  28. private readonly GrpScheduleRepository _grpScheduleRep;
  29. private readonly IMapper _mapper;
  30. private readonly DelegationInfoRepository _groupRepository;
  31. private readonly TaskAssignmentRepository _taskAssignmentRep;
  32. private readonly AirTicketResRepository _airTicketResRep;
  33. private readonly SqlSugarClient _sqlSugar;
  34. private string url;
  35. private string path;
  36. public GroupsController(IMapper mapper,SqlSugarClient sqlSugar, GrpScheduleRepository grpScheduleRep, DelegationInfoRepository groupRepository, TaskAssignmentRepository taskAssignmentRep, AirTicketResRepository airTicketResRep)
  37. {
  38. _mapper = mapper;
  39. _grpScheduleRep = grpScheduleRep;
  40. _groupRepository = groupRepository;
  41. _taskAssignmentRep = taskAssignmentRep;
  42. _airTicketResRep = airTicketResRep;
  43. _sqlSugar = sqlSugar;
  44. url = AppSettingsHelper.Get("ExcelBaseUrl");
  45. path = AppSettingsHelper.Get("ExcelBasePath");
  46. if (!System.IO.Directory.Exists(path))
  47. {
  48. System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
  49. }
  50. }
  51. #region 流程管控
  52. /// <summary>
  53. /// 获取团组流程管控信息
  54. /// </summary>
  55. /// <param name="paras">参数Json字符串</param>
  56. /// <returns></returns>
  57. [HttpPost]
  58. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  59. public async Task<IActionResult> PostSearchGrpSchedule(JsonDtoBase _jsonDto)
  60. {
  61. if (string.IsNullOrEmpty(_jsonDto.Paras))
  62. {
  63. return Ok(JsonView(false, "参数为空"));
  64. }
  65. Grp_ScheduleDto _ScheduleDto = JsonConvert.DeserializeObject<Grp_ScheduleDto>(_jsonDto.Paras);
  66. if (_ScheduleDto != null)
  67. {
  68. if (_ScheduleDto.SearchType == 2)//获取列表
  69. {
  70. List<Grp_ScheduleView> _grpScheduleViewList = await _grpScheduleRep.GetViewList_GrpSchedule(_ScheduleDto);
  71. return Ok(JsonView(_grpScheduleViewList));
  72. }
  73. else//获取对象
  74. {
  75. Grp_ScheduleCombinView _grpScheduleView = await _grpScheduleRep.GetView_GrpSchedule(_ScheduleDto);
  76. if (_grpScheduleView != null)
  77. {
  78. return Ok(JsonView(_grpScheduleView));
  79. }
  80. }
  81. }
  82. else
  83. {
  84. return Ok(JsonView(false, "参数反序列化失败"));
  85. }
  86. return Ok(JsonView(false, "暂无数据!"));
  87. }
  88. /// <summary>
  89. /// 修改团组流程管控详细表数据
  90. /// </summary>
  91. /// <param name="paras"></param>
  92. /// <returns></returns>
  93. [HttpPost]
  94. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  95. public async Task<IActionResult> PostUpdateGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  96. {
  97. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  98. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  99. .SetColumns(it => it.Duty == _detail.Duty)
  100. .SetColumns(it => it.ExpectBeginDt == _detail.ExpectBeginDt)
  101. .SetColumns(it => it.ExpectEndDt == _detail.ExpectEndDt)
  102. .SetColumns(it => it.JobContent == _detail.JobContent)
  103. .SetColumns(it => it.Remark == _detail.Remark)
  104. .SetColumns(it => it.StepStatus == _detail.StepStatus)
  105. .Where(s => s.Id == dto.Id)
  106. //.UpdateColumns(s => new { s.Duty, s.ExpectBeginDt, s.ExpectEndDt, s.JobContent, s.Remark, s.StepStatus })
  107. .ExecuteCommandAsync();
  108. if (result > 0)
  109. {
  110. return Ok(JsonView(true, "保存成功!"));
  111. }
  112. return Ok(JsonView(false, "保存失败!"));
  113. }
  114. /// <summary>
  115. /// 删除团组流程管控详细表数据,删除人Id请放在Duty
  116. /// </summary>
  117. /// <param name="dto"></param>
  118. /// <returns></returns>
  119. [HttpPost]
  120. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  121. public async Task<ActionResult> PostDeleteGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  122. {
  123. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  124. _detail.IsDel = 1;
  125. _detail.DeleteUserId = dto.Duty;
  126. _detail.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  127. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  128. .SetColumns(it => it.IsDel == _detail.IsDel)
  129. .SetColumns(it => it.DeleteUserId == _detail.DeleteUserId)
  130. .SetColumns(it => it.DeleteTime == _detail.DeleteTime)
  131. .Where(it => it.Id == dto.Id)
  132. //.UpdateColumns(s => new { s.IsDel, s.DeleteUserId, s.DeleteTime })
  133. //.WhereColumns(s => s.Id == dto.Id)
  134. .ExecuteCommandAsync();
  135. if (result > 0)
  136. {
  137. return Ok(JsonView(true, "删除成功!"));
  138. }
  139. return Ok(JsonView(false, "删除失败!"));
  140. }
  141. /// <summary>
  142. /// 增加团组流程管控详细表数据
  143. /// </summary>
  144. /// <param name="dto"></param>
  145. /// <returns></returns>
  146. [HttpPost]
  147. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  148. public async Task<ActionResult> PostInsertGrpScheduleDetail(Grp_ScheduleDetailInsertDto dto)
  149. {
  150. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  151. if (DateTime.Now < _detail.ExpectBeginDt)
  152. {
  153. _detail.StepStatus = 0;
  154. }
  155. else
  156. {//若大于设置时间,不考虑设置的预计结束日期,统一视为进行中
  157. _detail.StepStatus = 1;
  158. }
  159. var result = await _grpScheduleRep._sqlSugar.Insertable(_detail).ExecuteReturnIdentityAsync();
  160. if (result > 0)
  161. {
  162. Grp_ScheduleDetailView _result = await _grpScheduleRep.GetInsertBackData(result);
  163. return Ok(JsonView(true, "添加成功!", _result));
  164. }
  165. return Ok(JsonView(false, "添加失败!"));
  166. }
  167. #endregion
  168. #region 团组基本信息
  169. /// <summary>
  170. /// 接团信息列表
  171. /// </summary>
  172. /// <param name="dto">团组列表请求dto</param>
  173. /// <returns></returns>
  174. [HttpPost]
  175. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  176. public async Task<IActionResult> GetGroupList(GroupListDto dto)
  177. {
  178. var groupData = await _groupRepository.GetGroupList(dto);
  179. if (groupData.Code != 0)
  180. {
  181. return Ok(JsonView(false, groupData.Msg));
  182. }
  183. return Ok(JsonView(groupData.Data));
  184. }
  185. /// <summary>
  186. /// 接团信息详情
  187. /// </summary>
  188. /// <param name="dto">团组info请求dto</param>
  189. /// <returns></returns>
  190. [HttpPost]
  191. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  192. public async Task<IActionResult> GetGroupInfo(GroupInfoDto dto)
  193. {
  194. var groupData = await _groupRepository.GetGroupInfo(dto);
  195. if (groupData.Code != 0)
  196. {
  197. return Ok(JsonView(false, groupData.Msg));
  198. }
  199. return Ok(JsonView(groupData.Data));
  200. }
  201. /// <summary>
  202. /// 接团信息 编辑添加
  203. /// 基础信息数据源
  204. /// </summary>
  205. /// <param name="dto"></param>
  206. /// <returns></returns>
  207. [HttpPost]
  208. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  209. public async Task<IActionResult> GroupEditBasicSource(GroupListDto dto)
  210. {
  211. var groupData = await _groupRepository.GroupEditBasicSource(dto);
  212. if (groupData.Code != 0)
  213. {
  214. return Ok(JsonView(false, groupData.Msg));
  215. }
  216. return Ok(JsonView(groupData.Data));
  217. }
  218. /// <summary>
  219. /// 接团信息 操作(增改)
  220. /// </summary>
  221. /// <param name="dto"></param>
  222. /// <returns></returns>
  223. [HttpPost]
  224. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  225. public async Task<IActionResult> GroupOperation(GroupOperationDto dto)
  226. {
  227. try
  228. {
  229. var groupData = await _groupRepository.GroupOperation(dto);
  230. if (groupData.Code != 0)
  231. {
  232. return Ok(JsonView(false, groupData.Msg));
  233. }
  234. return Ok(JsonView(true));
  235. }
  236. catch (Exception ex)
  237. {
  238. Logs("[response]" + JsonConvert.SerializeObject(dto));
  239. Logs(ex.Message);
  240. return Ok(JsonView(false, ex.Message));
  241. }
  242. }
  243. /// <summary>
  244. /// 接团信息 操作(删除)
  245. /// </summary>
  246. /// <param name="dto"></param>
  247. /// <returns></returns>
  248. [HttpPost]
  249. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  250. public async Task<IActionResult> GroupDel(GroupDelDto dto)
  251. {
  252. try
  253. {
  254. var groupData = await _groupRepository.GroupDel(dto);
  255. if (groupData.Code != 0)
  256. {
  257. return Ok(JsonView(false, groupData.Msg));
  258. }
  259. return Ok(JsonView(true));
  260. }
  261. catch (Exception ex)
  262. {
  263. Logs("[response]" + JsonConvert.SerializeObject(dto));
  264. Logs(ex.Message);
  265. return Ok(JsonView(false, ex.Message));
  266. }
  267. }
  268. /// <summary>
  269. /// 获取团组销售报价号
  270. /// 团组添加时 使用
  271. /// </summary>
  272. /// <returns></returns>
  273. [HttpPost]
  274. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  275. public async Task<IActionResult> GetGroupSalesQuoteNo()
  276. {
  277. var groupData = await _groupRepository.GetGroupSalesQuoteNo();
  278. if (groupData.Code != 0)
  279. {
  280. return Ok(JsonView(false, groupData.Msg));
  281. }
  282. object salesQuoteNo = new
  283. {
  284. SalesQuoteNo = groupData.Data
  285. };
  286. return Ok(JsonView(salesQuoteNo));
  287. }
  288. /// <summary>
  289. /// 设置确认出团
  290. /// </summary>
  291. /// <param name="dto"></param>
  292. /// <returns></returns>
  293. [HttpPost]
  294. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  295. public async Task<IActionResult> SetConfirmationGroup(ConfirmationGroupDto dto)
  296. {
  297. var groupData = await _groupRepository.ConfirmationGroup(dto);
  298. if (groupData.Code != 0)
  299. {
  300. return Ok(JsonView(false, groupData.Msg));
  301. }
  302. GroupStepForDelegation.CreateWorkStep(dto.GroupId); //创建管控流程
  303. return Ok(JsonView(groupData.Data));
  304. }
  305. /// <summary>
  306. /// 获取团组名称 List
  307. /// </summary>
  308. /// <param name="dto"></param>
  309. /// <returns></returns>
  310. [HttpPost]
  311. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  312. public async Task<IActionResult> GetGroupNameList(GroupNameDto dto)
  313. {
  314. var groupData = await _groupRepository.GetGroupNameList(dto);
  315. if (groupData.Code != 0)
  316. {
  317. return Ok(JsonView(false, groupData.Msg));
  318. }
  319. return Ok(JsonView(groupData.Data, groupData.Data.Count));
  320. }
  321. /// <summary>
  322. /// 获取团组名称data And 签证国别Data
  323. /// </summary>
  324. /// <param name="dto"></param>
  325. /// <returns></returns>
  326. [HttpPost]
  327. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  328. public async Task<IActionResult> GetGroupNameAndVisaNationality(GroupNameDto dto)
  329. {
  330. var groupData = await _groupRepository.GetGroupNameAndVisaNationality(dto);
  331. if (groupData.Code != 0)
  332. {
  333. return Ok(JsonView(false, groupData.Msg));
  334. }
  335. return Ok(JsonView(groupData.Data));
  336. }
  337. #endregion
  338. #region 团组&签证
  339. /// <summary>
  340. /// 根据团组Id获取签证客户信息List
  341. /// </summary>
  342. /// <param name="dto">请求dto</param>
  343. /// <returns></returns>
  344. [HttpPost]
  345. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  346. public async Task<IActionResult> GetCrmByGroupId(ClientByGroupIdDto dto)
  347. {
  348. var groupData = await _groupRepository.GetCrmByGroupId(dto);
  349. if (groupData.Code != 0)
  350. {
  351. return Ok(JsonView(false, groupData.Msg));
  352. }
  353. return Ok(JsonView(groupData.Data));
  354. }
  355. #endregion
  356. #region 团组任务分配
  357. /// <summary>
  358. /// 团组任务分配初始化
  359. /// </summary>
  360. /// <param name="dto"></param>
  361. /// <returns></returns>
  362. [HttpPost]
  363. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  364. public async Task<IActionResult> GetTaskAssignmen()
  365. {
  366. var groupData = await _taskAssignmentRep.GetTaskAssignmen();
  367. if (groupData.Code != 0)
  368. {
  369. return Ok(JsonView(false, groupData.Msg));
  370. }
  371. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  372. }
  373. /// <summary>
  374. /// 团组任务分配查询
  375. /// </summary>
  376. /// <param name="dto"></param>
  377. /// <returns></returns>
  378. [HttpPost]
  379. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  380. public async Task<IActionResult> TaskAssignmenQuery(TaskAssignmenQueryDto dto)
  381. {
  382. var groupData = await _taskAssignmentRep.TaskAssignmenQuery(dto);
  383. if (groupData.Code != 0)
  384. {
  385. return Ok(JsonView(false, groupData.Msg));
  386. }
  387. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  388. }
  389. /// <summary>
  390. /// 团组任务分配操作
  391. /// </summary>
  392. /// <param name="dto"></param>
  393. /// <returns></returns>
  394. [HttpPost]
  395. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  396. public async Task<IActionResult> GetTaskAssignmenOp(TaskAssignmenDto dto)
  397. {
  398. Result groupData = await _taskAssignmentRep.GetTaskAssignmenOp(dto);
  399. if (groupData.Code != 0)
  400. {
  401. return Ok(JsonView(false, groupData.Msg));
  402. }
  403. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  404. }
  405. #endregion
  406. #region 团组费用审核
  407. /// <summary>
  408. /// 获取团组费用审核
  409. /// </summary>
  410. /// <param name="paras">参数Json字符串</param>
  411. /// <returns></returns>
  412. [HttpPost]
  413. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  414. public async Task<IActionResult> PostSearchGrpCreditCardPayment(Search_GrpCreditCardPaymentDto _dto)
  415. {
  416. if (_dto.DiId < 1)
  417. {
  418. return Ok(JsonView(false, "团组Id为空"));
  419. }
  420. Grp_CreditCardPaymentView _view = new Grp_CreditCardPaymentView();
  421. #region 团组基本信息
  422. Grp_DelegationInfo _delegation = _groupRepository.Query<Grp_DelegationInfo>(s => s.Id == _dto.DiId).First();
  423. if (_delegation != null)
  424. {
  425. _view.ClientName = _delegation.ClientName;
  426. _view.DiId = _dto.DiId;
  427. _view.TeamName = _delegation.TeamName;
  428. _view.VisitCountry = _delegation.VisitCountry;
  429. _view.VisitDate = _delegation.VisitStartDate.ToString("yyyy-MM-dd") + " ~ " + _delegation.VisitEndDate.ToString("yyyy-MM-dd");
  430. _view.VisitDays = _delegation.VisitDays;
  431. _view.VisitPNumber = _delegation.VisitPNumber;
  432. }
  433. else
  434. {
  435. return Ok(JsonView(false, "团组信息为空"));
  436. }
  437. #endregion
  438. #region 费用清单
  439. var exp = Expressionable.Create<Grp_CreditCardPayment>();
  440. exp.AndIF(_dto.AuditStatus != -1, it => it.IsAuditGM == _dto.AuditStatus);
  441. exp.AndIF(_dto.Label != -1, it => it.CTable == _dto.Label);
  442. //缺少IF的语法糖 CTable
  443. List<Grp_CreditCardPayment> entityList = _groupRepository
  444. .Query<Grp_CreditCardPayment>(s => s.DIId == _dto.DiId && s.IsDel == 0 && s.CreateUserId > 0)
  445. .Where(exp.ToExpression())
  446. .ToList();
  447. List<Grp_CreditCardPaymentDetailView> detailList = new List<Grp_CreditCardPaymentDetailView>();
  448. decimal CNY = 0;
  449. decimal PayCNY = 0;
  450. decimal BalanceCNY = 0;
  451. decimal YSFYCNY = 0;
  452. decimal USD = 0;
  453. decimal PayUSD = 0;
  454. decimal BalanceUSD = 0;
  455. decimal YSFYUSD = 0;
  456. decimal EUR = 0;
  457. decimal PayEUR = 0;
  458. decimal BalanceEUR = 0;
  459. decimal YSFYEUR = 0;
  460. foreach (var entity in entityList)
  461. {
  462. Grp_CreditCardPaymentDetailView _detail = new Grp_CreditCardPaymentDetailView();
  463. _detail.Id = entity.Id;
  464. /*
  465. * Bus名称
  466. */
  467. _detail.BusName = "";
  468. /*
  469. *费用所属
  470. */
  471. switch (entity.CTable)
  472. {
  473. case 85:
  474. Grp_AirTicketReservations jpRes = _groupRepository.Query<Grp_AirTicketReservations>(s => s.Id == entity.CId).First();
  475. if (jpRes != null)
  476. {
  477. string FlightsDescription = jpRes.FlightsDescription;
  478. string PriceDescription = jpRes.PriceDescription;
  479. _detail.PriceMsgContent = "航班号:" + jpRes.FlightsCode + "<br/>城市A-B:" + jpRes.FlightsCity + "<br/>航班描述:" + FlightsDescription.Replace("\r\n", "<br />") + "<br/>" + "价格描述:" + PriceDescription;
  480. _detail.PriceNameContent = "(" + jpRes.FlightsCode + ")";
  481. }
  482. break;
  483. case 79:
  484. _detail.BusName = "待增加";
  485. break;
  486. default:
  487. break;
  488. }
  489. /*
  490. * 费用模块
  491. */
  492. Sys_SetData sdPriceName = _groupRepository.Query<Sys_SetData>(s => s.Id == entity.CTable).First();
  493. if (sdPriceName != null)
  494. {
  495. _detail.PriceName = sdPriceName.Name;
  496. }
  497. /*
  498. * 应付款金额
  499. */
  500. Sys_SetData sdPaymentCurrency_WaitPay = _groupRepository.Query<Sys_SetData>(s => s.Id == entity.PaymentCurrency).First();
  501. string PaymentCurrency_WaitPay = "Unknown";
  502. if (sdPaymentCurrency_WaitPay != null)
  503. {
  504. PaymentCurrency_WaitPay = sdPaymentCurrency_WaitPay.Name;
  505. }
  506. _detail.WaitPay = entity.PayMoney.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  507. /*
  508. * 此次付款金额
  509. */
  510. decimal CurrPayStr = 0;
  511. if (entity.PayPercentage == 0)
  512. {
  513. if (entity.PayThenMoney != 0)
  514. CurrPayStr = entity.PayThenMoney * decimal.Parse(entity.DayRate);
  515. }
  516. else
  517. {
  518. CurrPayStr = entity.PayMoney * (decimal.Parse(entity.PayPercentage.ToString("#0.00")) / 100 * decimal.Parse(entity.DayRate));
  519. }
  520. _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  521. /*
  522. * 剩余尾款
  523. */
  524. decimal BalanceStr = 0;
  525. if (entity.PayMoney - (CurrPayStr / decimal.Parse(entity.DayRate)) < 0.01M)
  526. BalanceStr = 0;
  527. else
  528. BalanceStr = (entity.PayMoney - CurrPayStr / decimal.Parse(entity.DayRate));
  529. _detail.Balance = BalanceStr.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  530. /*
  531. * 申请人
  532. */
  533. string operatorName = "无";
  534. Sys_Users _opUser = _groupRepository.Query<Sys_Users>(s => s.Id == entity.CreateUserId).First();
  535. if (_opUser != null)
  536. {
  537. operatorName = _opUser.CnName;
  538. }
  539. _detail.OperatorName = operatorName;
  540. /*
  541. * 审核人
  542. */
  543. string auditOperatorName = "Unknown";
  544. if (entity.AuditGMOperate == 0)
  545. auditOperatorName = "无";
  546. else if (entity.AuditGMOperate == 4)
  547. auditOperatorName = "自动审核";
  548. else
  549. {
  550. Sys_Users _adUser = _groupRepository.Query<Sys_Users>(s => s.Id == entity.AuditGMOperate).First();
  551. if (_adUser != null)
  552. {
  553. auditOperatorName = _adUser.CnName;
  554. }
  555. }
  556. _detail.AuditOperatorName = auditOperatorName;
  557. /*
  558. *
  559. * *超预算比例
  560. */
  561. string overBudgetStr = "";
  562. if (entity.ExceedBudget == -1)
  563. overBudgetStr = sdPriceName.Name + "尚无预算";
  564. else if (entity.ExceedBudget == 0)
  565. overBudgetStr = "未超预算";
  566. else
  567. overBudgetStr = entity.ExceedBudget.ToString("P");
  568. _detail.OverBudget = overBudgetStr;
  569. /*
  570. * 费用总计
  571. */
  572. if (entity.PaymentCurrency == 48)
  573. {
  574. CNY += entity.PayMoney;
  575. PayCNY += CurrPayStr;
  576. BalanceCNY += BalanceStr;
  577. YSFYCNY += CurrPayStr;
  578. }
  579. if (entity.PaymentCurrency == 49)
  580. {
  581. USD += entity.PayMoney;
  582. PayUSD += CurrPayStr;
  583. BalanceUSD += BalanceStr;
  584. YSFYUSD += CurrPayStr;
  585. }
  586. if (entity.PaymentCurrency == 51)
  587. {
  588. EUR += entity.PayMoney;
  589. PayEUR += CurrPayStr;
  590. BalanceEUR += BalanceStr;
  591. YSFYEUR += CurrPayStr;
  592. }
  593. _detail.IsAuditGM = entity.IsAuditGM;
  594. detailList.Add(_detail);
  595. }
  596. #endregion
  597. _view.DetailList = new List<Grp_CreditCardPaymentDetailView>(detailList);
  598. _view.TotalStr1 = string.Format(@"应付款总金额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", CNY, USD, EUR);
  599. _view.TotalStr2 = string.Format(@"此次付款总金额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", PayCNY, PayUSD, PayEUR);
  600. _view.TotalStr3 = string.Format(@"目前剩余尾款总金额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", BalanceCNY, BalanceUSD, BalanceEUR);
  601. _view.TotalStr4 = string.Format(@"已审费用总额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", YSFYCNY, YSFYUSD, YSFYEUR);
  602. return Ok(JsonView(_view));
  603. }
  604. /// <summary>
  605. /// 修改团组费用审核状态
  606. /// </summary>
  607. /// <param name="paras">参数Json字符串</param>
  608. /// <returns></returns>
  609. [HttpPost]
  610. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  611. public async Task<IActionResult> PostAuditGrpCreditCardPayment(Edit_GrpCreditCardPaymentDto _dto)
  612. {
  613. List<string> idList = _dto.CreditIdStr.Split(',').ToList();
  614. Grp_CreditCardPayment _detail = _mapper.Map<Grp_CreditCardPayment>(_dto);
  615. DateTime dtNow = DateTime.Now;
  616. _groupRepository.BeginTran();
  617. int rst = 0;
  618. foreach (var item in idList)
  619. {
  620. int CreditId = int.Parse(item);
  621. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_CreditCardPayment>()
  622. .SetColumns(it => it.IsAuditGM == _dto.AuditCode)
  623. .SetColumns(it => it.AuditGMOperate == _dto.User)
  624. .SetColumns(it => it.AuditGMDate == dtNow)
  625. .Where(s => s.Id == CreditId)
  626. .ExecuteCommandAsync();
  627. if (result < 1)
  628. {
  629. rst = -1;
  630. }
  631. else
  632. {
  633. _groupRepository.RollbackTran();
  634. return Ok(JsonView(false, "保存失败并回滚!"));
  635. }
  636. }
  637. _groupRepository.CommitTran();
  638. if (rst == 0)
  639. {
  640. return Ok(JsonView(true, "保存成功!"));
  641. }
  642. return Ok(JsonView(false, "保存失败!"));
  643. }
  644. #endregion
  645. #region 机票费用录入
  646. /// <summary>
  647. /// 机票录入当前登录人可操作团组
  648. /// </summary>
  649. /// <param name="dto"></param>
  650. /// <returns></returns>
  651. [HttpPost]
  652. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  653. public async Task<IActionResult> AirTicketResSelect(AirTicketResDto dto)
  654. {
  655. try
  656. {
  657. Result groupData = await _airTicketResRep.AirTicketResSelect(dto);
  658. if (groupData.Code != 0)
  659. {
  660. return Ok(JsonView(false, groupData.Msg));
  661. }
  662. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  663. }
  664. catch (Exception ex)
  665. {
  666. return Ok(JsonView(false, "程序错误!"));
  667. throw;
  668. }
  669. }
  670. /// <summary>
  671. /// 机票费用录入列表
  672. /// </summary>
  673. /// <param name="dto"></param>
  674. /// <returns></returns>
  675. [HttpPost]
  676. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  677. public async Task<IActionResult> AirTicketResList(AirTicketResDto dto)
  678. {
  679. try
  680. {
  681. Result groupData = await _airTicketResRep.AirTicketResList(dto);
  682. if (groupData.Code != 0)
  683. {
  684. return Ok(JsonView(false, groupData.Msg));
  685. }
  686. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  687. }
  688. catch (Exception ex)
  689. {
  690. return Ok(JsonView(false, "程序错误!"));
  691. throw;
  692. }
  693. }
  694. /// <summary>
  695. /// 根据id查询费用录入信息
  696. /// </summary>
  697. /// <param name="dto"></param>
  698. /// <returns></returns>
  699. [HttpPost]
  700. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  701. public async Task<IActionResult> AirTicketResById(AirTicketResByIdDto dto)
  702. {
  703. try
  704. {
  705. Result groupData = await _airTicketResRep.AirTicketResById(dto);
  706. if (groupData.Code != 0)
  707. {
  708. return Ok(JsonView(false, groupData.Msg));
  709. }
  710. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  711. }
  712. catch (Exception ex)
  713. {
  714. return Ok(JsonView(false, "程序错误!"));
  715. throw;
  716. }
  717. }
  718. /// <summary>
  719. /// 机票费用录入操作(Status:1.新增,2.修改)
  720. /// </summary>
  721. /// <param name="dto"></param>
  722. /// <returns></returns>
  723. [HttpPost]
  724. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  725. public async Task<IActionResult> OpAirTicketRes(AirTicketResOpDto dto)
  726. {
  727. try
  728. {
  729. Result groupData = await _airTicketResRep.OpAirTicketRes(dto);
  730. if (groupData.Code != 0)
  731. {
  732. return Ok(JsonView(false, groupData.Msg));
  733. }
  734. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  735. }
  736. catch (Exception ex)
  737. {
  738. return Ok(JsonView(false, "程序错误!"));
  739. throw;
  740. }
  741. }
  742. /// <summary>
  743. /// 机票费用录入,删除
  744. /// </summary>
  745. /// <param name="dto"></param>
  746. /// <returns></returns>
  747. [HttpPost]
  748. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  749. public async Task<IActionResult> DelAirTicketRes(DelBaseDto dto)
  750. {
  751. try
  752. {
  753. var res = await _airTicketResRep.SoftDeleteByIdAsync<Grp_AirTicketReservations>(dto.Id.ToString(), dto.DeleteUserId);
  754. if (!res)
  755. {
  756. return Ok(JsonView(false, "删除失败"));
  757. }
  758. return Ok(JsonView(true, "删除成功!"));
  759. }
  760. catch (Exception ex)
  761. {
  762. return Ok(JsonView(false, "程序错误!"));
  763. throw;
  764. }
  765. }
  766. /// <summary>
  767. /// 导出机票录入报表
  768. /// </summary>
  769. /// <param name="dto"></param>
  770. /// <returns></returns>
  771. [HttpPost]
  772. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  773. public async Task<IActionResult> DeriveAirTicketRes(AirTicketResDto dto)
  774. {
  775. try
  776. {
  777. Result groupData = await _airTicketResRep.DeriveAirTicketRes(dto);
  778. if (groupData.Code != 0)
  779. {
  780. return Ok(JsonView(false, groupData.Msg));
  781. }
  782. else
  783. {
  784. List<AirTicketReservationsPayView> AirTicketReservations = groupData.Data.GetType().GetProperty("AirTicketRes").GetValue(groupData.Data);
  785. if (AirTicketReservations.Count != 0)
  786. {
  787. Grp_DelegationInfo DelegationInfo = groupData.Data.GetType().GetProperty("Delegation").GetValue(groupData.Data);
  788. Sys_Users _Users = groupData.Data.GetType().GetProperty("Users").GetValue(groupData.Data);
  789. string diCode = DelegationInfo != null ? DelegationInfo.TourCode : "XXX";
  790. string diName = DelegationInfo != null ? DelegationInfo.TeamName : "XXX";
  791. WorkbookDesigner designer = new WorkbookDesigner();
  792. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/机票预订费用报表模板.xlsx");
  793. decimal countCost = 0;
  794. foreach (var item in AirTicketReservations)
  795. {
  796. if (item.BankType == "其他")
  797. {
  798. item.BankNo = "--";
  799. }
  800. else
  801. {
  802. item.BankNo = item.BankType + ":" + item.BankNo.Substring(0, 3);
  803. }
  804. item.PrePrice = System.Decimal.Round(item.PrePrice, 2);
  805. item.Price = System.Decimal.Round(item.Price, 2);
  806. countCost += Convert.ToDecimal(item.Price);
  807. }
  808. designer.SetDataSource("Export", AirTicketReservations);
  809. designer.SetDataSource("ExportDiCode", diCode);
  810. designer.SetDataSource("ExportDiName", diName);
  811. designer.SetDataSource("ExportOpUserName", _Users.CnName);
  812. designer.SetDataSource("ExportCountCost", countCost + "(" + AirTicketReservations[0].CurrencyStr);
  813. designer.Process();
  814. string fileName = "AirfareStatement/" + diName + "机票费用报表" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
  815. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  816. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  817. return Ok(JsonView(true, "成功", url = rst));
  818. }
  819. else
  820. {
  821. return Ok(JsonView(false, "暂无数据!"));
  822. }
  823. }
  824. }
  825. catch (Exception ex)
  826. {
  827. return Ok(JsonView(false, "程序错误!"));
  828. throw;
  829. }
  830. }
  831. [HttpPost]
  832. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  833. public async Task<IActionResult> ItineraryAirTicketRes(AirTicketResDto dto)
  834. {
  835. try
  836. {
  837. Result groupData = await _airTicketResRep.ItineraryAirTicketRes(dto);
  838. if (groupData.Code != 0)
  839. {
  840. return Ok(JsonView(false, groupData.Msg));
  841. }
  842. else
  843. {
  844. List<AirTicketReservationsView> _AirTicketReservations = groupData.Data;
  845. //WorkbookDesigner designer = new WorkbookDesigner();
  846. //designer.Workbook = new Workbook(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_CN.docx");
  847. Document doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_CN.docx");
  848. DocumentBuilder builder = new DocumentBuilder();
  849. foreach (var item in _AirTicketReservations)
  850. {
  851. int tableIndex = 0;//表格索引
  852. //得到文档中的第一个表格
  853. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  854. Paragraph lastParagraph = new Paragraph(doc);
  855. //第一个表格末尾加段落
  856. table.ParentNode.InsertAfter(lastParagraph, table);
  857. //复制第一个表格
  858. Table cloneTable = (Table)table.Clone(true);
  859. //在文档末尾段落后面加入复制的表格
  860. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  861. Itinerary itinerary = new Itinerary();
  862. itinerary.ClientName = item.ClientName;
  863. itinerary.AirlineCompany = "航空公司";
  864. itinerary.TimeIssue = "2023-5-23 10:09:06";
  865. itinerary.DrawingAgent = "代理人";
  866. itinerary.AgentsAddress = "代理人地址";
  867. itinerary.AgentPhone = "代理人电话";
  868. itinerary.AgentFacsimile = "代理人传真";
  869. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  870. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  871. List<AirInfo> airInfos = new List<AirInfo>();
  872. for (int i = 0; i < DayArray.Length; i++)
  873. {
  874. string[] FlightStr = item.FlightsCode.Split('/');
  875. string[] tempstr = DayArray[i]
  876. .Replace("\r\n", string.Empty)
  877. .Replace("\\r\\n", string.Empty)
  878. .TrimStart().TrimEnd()
  879. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  880. AirInfo air = new AirInfo();
  881. string [] city = item.FlightsCity.Split('/');
  882. string cityStr = city[i];
  883. string startCity = cityStr.Substring(0, 2);
  884. Res_ThreeCode startCityThree = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == startCity && a.IsDel == 0);
  885. string endCity = cityStr.Substring(3, 5);
  886. Res_ThreeCode endCityThree = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == endCity && a.IsDel == 0);
  887. air.Destination= startCityThree.City+"-"+endCityThree.City;
  888. air.Flight = FlightStr[i];
  889. air.SeatingClass = item.CTypeName;
  890. }
  891. //designer.SetDataSource("Export", AirTicketReservations);
  892. //string AirlineRecordCode = "--";//航空公司记录编码
  893. //string ReservationRecordCode = "--";//订座记录编码
  894. //string ClientName = "--";//旅客姓名
  895. //string TicketNumber = "--";//票号
  896. //string IdentificationCode = "--";//身份识别代码
  897. //string JointTicket = "--";//联票
  898. //string AirlineCompany = "--";//出票航空公司
  899. //string TimeIssue = "--";//出票时间
  900. //string DrawingAgent = "--";//代理人
  901. //string NavigationCode = "--";//航协代码
  902. //string AgentsAddress = "--";//代理人地址
  903. //string AgentPhone = "--";//代理人电话
  904. //string AgentFacsimile = "--";//代理人传真
  905. //doc.SetDataSource("AirlineRecordCode", AirlineRecordCode);
  906. //Itinerary itinerary = new Itinerary();
  907. }
  908. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  909. //保存合并后的文档
  910. string fileName = "AirItinerary/电子客票行程单_CN.docx";
  911. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  912. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  913. return Ok(JsonView(false, "程序错误!"));
  914. }
  915. }
  916. catch (Exception ex)
  917. {
  918. return Ok(JsonView(false, "程序错误!"));
  919. throw;
  920. }
  921. }
  922. #endregion
  923. }
  924. }