GroupsController.cs 33 KB

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