CarTouristGuideGroundRepository.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  1. using Aspose.Words.Tables;
  2. using AutoMapper;
  3. using NPOI.SS.Formula.Functions;
  4. using NPOI.SS.UserModel;
  5. using NPOI.Util;
  6. using OASystem.Domain;
  7. using OASystem.Domain.Dtos.Financial;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Dtos.QiYeWeChat;
  10. using OASystem.Domain.Entities.Financial;
  11. using OASystem.Domain.Entities.Groups;
  12. using OASystem.Domain.Entities.Resource;
  13. using OASystem.Domain.ViewModels.Groups;
  14. using OASystem.Infrastructure.Repositories.Financial;
  15. using OASystem.Infrastructure.Repositories.System;
  16. using OASystem.Infrastructure.Tools;
  17. using SqlSugar.Extensions;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Reflection;
  21. using static NPOI.HSSF.Util.HSSFColor;
  22. namespace OASystem.Infrastructure.Repositories.Groups
  23. {
  24. public class CarTouristGuideGroundRepository : BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  25. {
  26. private readonly IMapper _mapper;
  27. private readonly CheckBoxsRepository _checkRep;
  28. private readonly SetDataRepository _setDataRep;
  29. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  30. private readonly GroupCostParameterRepository _groupCostParameterRepository;
  31. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper, CheckBoxsRepository checkRep, SetDataRepository setDataRep, DailyFeePaymentRepository daiRep, GroupCostParameterRepository groupCostParameterRepository)
  32. : base(sqlSugar)
  33. {
  34. _mapper = mapper;
  35. _checkRep = checkRep;
  36. _setDataRep = setDataRep;
  37. _daiRep = daiRep;
  38. _groupCostParameterRepository = groupCostParameterRepository;
  39. }
  40. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  41. {
  42. Result result = new Result() { Code = -2, Msg = "未知错误" };
  43. BeginTran();
  44. try
  45. {
  46. int id = 0;
  47. Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  48. if (dto.Status == 1)//添加
  49. {
  50. Grp_CarTouristGuideGroundReservations grp_CarTouristGuideGround = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(a => a.IsDel == 0 && a.Area == dto.Area && a.BusName == dto.BusName && a.ServiceGuide == dto.ServiceGuide && a.DiId == dto.DiId && a.BusTel == dto.BusTel && a.ServiceTel == dto.ServiceTel && a.PriceName == dto.PriceName);
  51. if (grp_CarTouristGuideGround != null)
  52. {
  53. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  54. }
  55. else
  56. {
  57. id = await AddAsyncReturnId(grp_CarTouristGuide);
  58. if (id == 0)
  59. {
  60. RollbackTran();
  61. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  62. }
  63. else
  64. {
  65. result = new Result() { Code = 0, Msg = "添加成功!" };
  66. }
  67. }
  68. }
  69. else if (dto.Status == 2)//修改
  70. {
  71. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  72. {
  73. Area = grp_CarTouristGuide.Area,
  74. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  75. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  76. ServiceTel = grp_CarTouristGuide.ServiceTel,
  77. BusName = grp_CarTouristGuide.BusName,
  78. BusDescription = grp_CarTouristGuide.BusDescription,
  79. BusTel = grp_CarTouristGuide.BusTel,
  80. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  81. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  82. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  83. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  84. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  85. Remark = grp_CarTouristGuide.Remark,
  86. PriceType = grp_CarTouristGuide.PriceType,
  87. PriceName = grp_CarTouristGuide.PriceName,
  88. });
  89. if (res)
  90. {
  91. id = dto.Id;
  92. result = new Result() { Code = 0, Msg = "修改成功!" };
  93. }
  94. else
  95. {
  96. RollbackTran();
  97. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  98. }
  99. }
  100. if (id != 0)
  101. {
  102. Res_LocalGuideData _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.BusName && a.ContactTel == dto.BusTel && a.IsDel == 0);
  103. if (_LocalGuideDataCar == null)
  104. {
  105. Res_LocalGuideData res_LocalGuideCar = new Res_LocalGuideData();
  106. res_LocalGuideCar.UnitName = dto.BusName;
  107. res_LocalGuideCar.ContactTel = dto.BusTel;
  108. res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  109. int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  110. }
  111. Res_LocalGuideData _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.ServiceCompany && a.ContactTel == dto.ServiceTel && a.IsDel == 0);
  112. if (_LocalGuideDataService == null)
  113. {
  114. Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  115. res_LocalGuideService.UnitName = dto.ServiceCompany;
  116. res_LocalGuideService.ContactTel = dto.ServiceTel;
  117. res_LocalGuideService.Contact = dto.ServiceTel;
  118. res_LocalGuideService.CreateUserId = dto.CreateUserId;
  119. int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  120. }
  121. }
  122. CommitTran();
  123. }
  124. catch (Exception ex)
  125. {
  126. result = new Result() { Code = -2, Msg = "未知错误" + ex.Message };
  127. }
  128. return result;
  129. }
  130. public Result CarTouristGuideGroundContent(CarTouristGuideGroundContentDto dto)
  131. {
  132. Result result = new Result() { Code = -2, Msg = "未知错误" };
  133. try
  134. {
  135. DateTime start = new DateTime();
  136. DateTime end = new DateTime();
  137. Grp_CarTouristGuideGroundReservations grpCarOp = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.Id);
  138. if (!DateTime.TryParse(grpCarOp?.ServiceStartTime, out start))
  139. {
  140. result.Msg = "服务开始时间不存在!";
  141. result.Code = -1;
  142. return result;
  143. }
  144. if (!DateTime.TryParse(grpCarOp?.ServiceEndTime, out end))
  145. {
  146. result.Msg = "服务结束时间不存在!";
  147. result.Code = -1;
  148. return result;
  149. }
  150. TimeSpan ts = end - start; //计算时间差
  151. int day = ts.Days;
  152. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79).ToList();
  153. string DiId = "0";
  154. foreach (var item in grp_GroupsTaskAssignment)
  155. {
  156. DiId += item.DIId + ",";
  157. }
  158. if (DiId != "0")
  159. {
  160. DiId = DiId.Substring(0, DiId.Length - 1);
  161. }
  162. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  163. //团组下拉框
  164. List<Grp_DelegationInfo> _Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  165. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(_Delegations);
  166. //支付方式
  167. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  168. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  169. //列表初始化
  170. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  171. List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  172. _TableInitialization = _TableInitialization.OrderBy(x => x.RemarkSort).ToList();
  173. List<Sys_SetData> ssd = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 78).ToList();
  174. List<SetDataInfoView> ssdv = _mapper.Map<List<Sys_SetData>, List<SetDataInfoView>>(ssd);
  175. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  176. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  177. TableInitialization.RemoveAll(x => x.Id == 1070 || x.Id == 1071);
  178. var weiKuanArr = _TableInitialization.Where(x => x.Id == 1070 || x.Id == 1071).ToList();
  179. var weiKuanResultArr = carTouristGuides.Where(x => x.SId == 1070 || x.SId == 1071).ToList();
  180. carTouristGuides.RemoveAll(x => x.SId == 1070 || x.SId == 1071);
  181. foreach (var itemSt in TableInitialization)
  182. {
  183. var findResult = carTouristGuides.Find(x => x.SId == itemSt.Id);
  184. if (findResult == null)
  185. {
  186. carTouristGuides.Add(new CarTouristGuideGroundReservationsContentView
  187. {
  188. SId = itemSt.Id,
  189. Count = 1,
  190. SidName = itemSt.Name,
  191. });
  192. }
  193. }
  194. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x => x.Key, x => x.ToList());
  195. foreach (var item in groupResult.Keys)
  196. {
  197. #region 倒推初始化逻辑
  198. //while (groupResult[item].Count <= day)
  199. //{
  200. // groupResult[item] = groupResult[item].OrderByDescending(x => x.DatePrice).ToList();
  201. // if (groupResult[item][0]?.DatePrice is not null)
  202. // {
  203. // groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  204. // {
  205. // DatePrice = groupResult[item][0].DatePrice.ObjToDate().AddDays(1),
  206. // SId = item,
  207. // Count = 1,
  208. // });
  209. // }
  210. // else
  211. // {
  212. // groupResult[item][0].DatePrice = start;
  213. // }
  214. //}
  215. #endregion
  216. var startForTime = start;
  217. var dayResult = new List<CarTouristGuideGroundReservationsContentView>();
  218. for (var i = 0; i <= day; i++)
  219. {
  220. dayResult.Add(new CarTouristGuideGroundReservationsContentView
  221. {
  222. Count = 1,
  223. DatePrice = startForTime,
  224. SId = item,
  225. });
  226. startForTime = startForTime.AddDays(1);
  227. }
  228. if (groupResult[item].Count != day)
  229. {
  230. for (var m = 0; m < groupResult[item].Count; m++)
  231. {
  232. for (var m1 = 0; m1 < dayResult.Count; m1++)
  233. {
  234. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  235. {
  236. dayResult[m1] = groupResult[item][m];
  237. }
  238. }
  239. }
  240. }
  241. else
  242. {
  243. groupResult[item] = groupResult[item].OrderBy(x => x.DatePrice).ToList();
  244. if (groupResult[item][0].DatePrice == dayResult[0].DatePrice && groupResult[item][day - 1].DatePrice == dayResult[day - 1].DatePrice)
  245. {
  246. dayResult = groupResult[item];
  247. }
  248. else
  249. {
  250. for (var m = 0; m < groupResult[item].Count; m++)
  251. {
  252. for (var m1 = 0; m1 < dayResult.Count; m1++)
  253. {
  254. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  255. {
  256. dayResult[m1] = groupResult[item][m];
  257. }
  258. }
  259. }
  260. }
  261. }
  262. groupResult[item] = dayResult;
  263. }
  264. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).OrderBy(x => x.SId).ThenBy(x => x.DatePrice).ToList();
  265. foreach (var item in carTouristGuides.Where(x => string.IsNullOrWhiteSpace(x.SidName)).ToList())
  266. {
  267. item.SidName = TableInitialization.Find(x => x.Id == item.SId)?.Name;
  268. }
  269. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  270. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  271. if (_CreditCardPayment != null)
  272. {
  273. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  274. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency)?.Name;
  275. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  276. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  277. }
  278. Dictionary<string, string> soureDic = new Dictionary<string, string>()
  279. {
  280. {"车费", "VF"},
  281. {"导游费", "T/G S"},
  282. {"客户午餐费用" , "L"},
  283. {"导游景点费" , "T/G EF"},
  284. {"导游小费" , "T/G T"},
  285. // --
  286. {"司机小费", "DRV T"},
  287. {"司机餐补", "C/F M"},
  288. {"车超时费", "C/F OF"},
  289. {"导游餐补", "T/G M"},
  290. {"导游房补", "T/G A"},
  291. {"导游交通", "T/G TF"},
  292. {"客户早餐费用", "B"},
  293. {"客户晚餐费用", "D"},
  294. {"景点门票费", "EF"},
  295. {"饮料/零食/水果", "B/R/F"},
  296. {"翻译费", "I/F"},
  297. };
  298. var checkedItem = new List<string>();
  299. var checkedItemId = new List<int>();
  300. var isSaveCheck = false;
  301. if (string.IsNullOrWhiteSpace(grpCarOp.SelectCheck))
  302. {
  303. //获取成本选中
  304. var checkTopArr = _checkRep.GetCheckBoxsByDiid(grpCarOp.DiId);
  305. if (true)
  306. {
  307. var FindTop = checkTopArr.Find(x => x.CbType == "Top");
  308. if (FindTop != null)
  309. {
  310. var selectName = FindTop.CbValues.Split(',').ToList<string>();
  311. foreach (var soureKey in soureDic.Keys)
  312. {
  313. var find = selectName.Find(x => x == soureDic[soureKey]);
  314. if (find == null)
  315. {
  316. var Lindex = carTouristGuides.FindIndex(x => x.SidName == soureKey);
  317. //carTouristGuides.RemoveRange(Lindex, day + 1);
  318. }
  319. else
  320. {
  321. checkedItem.Add(soureKey);
  322. checkedItemId.Add(_TableInitialization.Find(x => x.Name == soureKey)!.Id);
  323. }
  324. }
  325. }
  326. else
  327. {
  328. checkedItem = _TableInitialization.Select(x => x.Name).ToList();
  329. checkedItemId.AddRange(_TableInitialization.Select(x => x.Id).ToList());
  330. }
  331. }
  332. }
  333. else
  334. {
  335. isSaveCheck = true;
  336. var checkedItemThis = grpCarOp.SelectCheck.Split(",").ToList<string>();
  337. int number = 0;
  338. foreach (var item in checkedItemThis)
  339. {
  340. if (!int.TryParse(item, out number))
  341. {
  342. checkedItemId.Add(_TableInitialization.Find(x => x.Name == item)!.Id);
  343. checkedItem.Add(item);
  344. }
  345. else
  346. {
  347. checkedItemId.Add(number);
  348. checkedItem.Add(_TableInitialization.Find(x => x.Id == int.Parse(item))!.Name);
  349. }
  350. }
  351. }
  352. if (grpCarOp.PriceType == 1062) //尾款id
  353. {
  354. if (isSaveCheck)
  355. {
  356. checkedItemId.AddRange(weiKuanArr.Select(x => x.Id).ToList());
  357. checkedItem.AddRange(weiKuanArr.Select(x => x.Name).ToList());
  358. checkedItemId = checkedItemId.Distinct().ToList();
  359. checkedItem = checkedItem.Distinct().ToList();
  360. }
  361. else
  362. {
  363. checkedItemId = weiKuanArr.Select(x => x.Id).ToList();
  364. checkedItem = weiKuanArr.Select(x => x.Name).ToList();
  365. }
  366. var weiPrice = weiKuanResultArr.Find(x => x.SId == 1070);
  367. if (weiPrice != null)
  368. {
  369. weiPrice.SidName = "尾款金额";
  370. }
  371. var weiOther = weiKuanResultArr.Find(x => x.SId == 1071);
  372. if (weiOther != null)
  373. {
  374. weiOther.SidName = "其他额外费用";
  375. }
  376. carTouristGuides.Add(weiPrice ??= new CarTouristGuideGroundReservationsContentView
  377. {
  378. Count = 1,
  379. DatePrice = DateTime.Now,
  380. Price = 0,
  381. PriceContent = "",
  382. SId = 1070,
  383. SidName = "尾款金额",
  384. Units = 0,
  385. });
  386. carTouristGuides.Add(weiOther ??= new CarTouristGuideGroundReservationsContentView
  387. {
  388. Count = 1,
  389. DatePrice = DateTime.Now,
  390. Price = 0,
  391. PriceContent = "",
  392. SId = 1071,
  393. SidName = "其他额外费用",
  394. Units = 0,
  395. });
  396. }
  397. else
  398. {
  399. _TableInitialization.RemoveAll(x => x.Id == 1070 || x.Id == 1071);
  400. }
  401. if (dto.PortType == 1)
  402. {
  403. var data = new
  404. {
  405. Payment = _Payment,
  406. Delegations = grp_Delegations,
  407. carTouristGuides = carTouristGuides,
  408. CreditCardPayment = _CreditCardPayment,
  409. start,
  410. end,
  411. ssdv,
  412. checkedItem,
  413. existItem = _TableInitialization.Select(x => x.Name).ToList(),
  414. };
  415. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  416. }
  417. else if (dto.PortType == 2)
  418. {
  419. var data = new
  420. {
  421. Payment = _Payment,
  422. TableInitialization = _TableInitialization,
  423. carTouristGuides = carTouristGuides,
  424. CreditCardPayment = _CreditCardPayment ??= new CarTouristCreditCardPaymentView(),
  425. ssdv,
  426. checkedItemId
  427. };
  428. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  429. }
  430. return result = new Result() { Code = -1, Msg = "请传入有效portType" };
  431. }
  432. catch (Exception ex)
  433. {
  434. return result = new Result() { Code = -2, Msg = "未知错误" };
  435. }
  436. }
  437. /// <summary>
  438. /// web弃用
  439. /// </summary>
  440. /// <param name="dto"></param>
  441. /// <returns></returns>
  442. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  443. {
  444. Result result = new Result() { Code = -2, Msg = "未知错误" };
  445. try
  446. {
  447. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  448. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  449. foreach (var item in carTouristGuides)
  450. {
  451. item.SidName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  452. }
  453. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  454. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  455. if (_CreditCardPayment != null)
  456. {
  457. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  458. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  459. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  460. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  461. }
  462. var data = new
  463. {
  464. CarTouristsContent = carTouristGuides,
  465. CreditCardPayment = _CreditCardPayment,
  466. };
  467. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  468. }
  469. catch (Exception ex)
  470. {
  471. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message + ")" };
  472. }
  473. }
  474. /// <summary>
  475. /// 根据diid查询op费用列表
  476. /// </summary>
  477. /// <param name="dto"></param>
  478. /// <returns></returns>
  479. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  480. {
  481. Result result = new Result() { Code = -2, Msg = "未知错误" };
  482. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  483. {
  484. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  485. }
  486. try
  487. {
  488. #region SQL条件拼接
  489. string sqlWhere = string.Empty;
  490. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  491. string UserId = "";
  492. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  493. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  494. UserId += gta.UId + ",";
  495. if (!string.IsNullOrWhiteSpace(UserId))
  496. {
  497. UserId = UserId.Substring(0, UserId.Length - 1);
  498. }
  499. else
  500. {
  501. UserId = "0";
  502. }
  503. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  504. if (dto.IsPaySign != -1)
  505. {
  506. sqlWhere += string.Format(@" And c.IsPay = {0} ", dto.IsPaySign);
  507. }
  508. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  509. {
  510. Regex r = new Regex("And");
  511. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  512. }
  513. #endregion
  514. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  515. int endIndex = startIndex + dto.PageSize - 1;
  516. Regex regex = new Regex("^[\u4e00-\u9fa5]*$");
  517. //城市列表
  518. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => new
  519. {
  520. x.Id,
  521. x.Country,
  522. x.City,
  523. }).ToList();
  524. if (dto.PortType == 1)
  525. {
  526. string sql = string.Format(@"select t.*,(select Name from Sys_SetData where isdel = 0 and id = t.priceType) as 'priceTypeStr',s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid,c.IsPay from
  527. Grp_CarTouristGuideGroundReservations t
  528. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  529. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  530. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  531. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  532. foreach (var item in infoViews)
  533. {
  534. if (!regex.IsMatch(item.Area))
  535. {
  536. for (int i = 0; i < data.Count; i++)
  537. {
  538. if (item.Area.Equals(data[i].Id.ToString()))
  539. {
  540. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  541. }
  542. }
  543. }
  544. if (string.IsNullOrWhiteSpace(item.priceTypeStr))
  545. {
  546. item.priceTypeStr = "未选择!";
  547. }
  548. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  549. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  550. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  551. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  552. item.ServiceQuotedPrice = item.PayMoney;
  553. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  554. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  555. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  556. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  557. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  558. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  559. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  560. if (s != null)
  561. {
  562. item.PayStrd = s.Name;
  563. }
  564. else item.PayStrd = "未选择";
  565. }
  566. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  567. }
  568. else if (dto.PortType == 2 || dto.PortType == 3)
  569. {
  570. string sql = string.Format(@"Select * From (
  571. Select row_number() over (order by c.IsAuditGM,c.PayPercentage desc) as RowNumber,t.*,(select Name from Sys_SetData where isdel = 0 and id = t.priceType) as 'priceTypeStr',s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayDid,c.PayMoney
  572. from
  573. Grp_CarTouristGuideGroundReservations t
  574. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  575. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  576. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  577. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  578. foreach (var item in grp_CarTourists)
  579. {
  580. if (!regex.IsMatch(item.Area))
  581. {
  582. for (int i = 0; i < data.Count; i++)
  583. {
  584. if (item.Area.Equals(data[i].Id.ToString()))
  585. {
  586. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  587. }
  588. }
  589. }
  590. if (string.IsNullOrWhiteSpace(item.priceTypeStr))
  591. {
  592. item.priceTypeStr = "未选择!";
  593. }
  594. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  595. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  596. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  597. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  598. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  599. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  600. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  601. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  602. item.ServiceQuotedPrice = item.PayMoney;
  603. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  604. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  605. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  606. if (s != null)
  607. {
  608. item.PayStrd = s.Name;
  609. }
  610. else item.PayStrd = "未选择";
  611. }
  612. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  613. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  614. Grp_CarTouristGuideGroundReservations t
  615. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  616. left Join Sys_SetData s on s.Id=t.CId {0}
  617. ) temp ", sqlWhere);
  618. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  619. if (dataCount != null)
  620. {
  621. int count = dataCount.Count;
  622. float totalPage = (float)count / dto.PageSize;//总页数
  623. if (totalPage == 0) totalPage = 1;
  624. else totalPage = (int)Math.Ceiling((double)totalPage);
  625. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  626. rst.DataList = grp_CarTourists;
  627. rst.DataCount = count;
  628. rst.CurrPageIndex = dto.PageIndex;
  629. rst.CurrPageSize = dto.PageSize;
  630. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  631. }
  632. }
  633. }
  634. catch (Exception)
  635. {
  636. return result = new Result() { Code = -2, Msg = "未知错误" };
  637. }
  638. return result;
  639. }
  640. /// <summary>
  641. /// OP费用录入填写详情
  642. /// </summary>
  643. /// <param name="dto"></param>
  644. /// <returns></returns>
  645. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  646. {
  647. Result result = new Result() { Code = -2, Msg = "未知错误" };
  648. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  649. if (di == null)
  650. {
  651. result.Code = -1;
  652. result.Msg = "无该团组信息!";
  653. return result;
  654. }
  655. try
  656. {
  657. BeginTran();
  658. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  659. {
  660. Id = item.Id,
  661. DiId = dto.DiId,
  662. CTGGRId = dto.CTGGRId,
  663. SId = item.SId,
  664. Price = item.Price,
  665. PriceContent = item.priceContent,
  666. Currency = dto.Currency,
  667. CreateUserId = dto.CreateUserId,
  668. Units = item.Units,
  669. DatePrice = item.DatePrice,
  670. Count = item.Count,
  671. }).ToList();
  672. string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm ss");
  673. var ids = carTouristList.Select(x1 => x1.Id);
  674. _ = _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(x => x.DiId == dto.DiId && x.CTGGRId == dto.CTGGRId).SetColumns(x => new Grp_CarTouristGuideGroundReservationsContent
  675. {
  676. IsDel = 1,
  677. DeleteTime = time ,
  678. DeleteUserId = dto.CreateUserId,
  679. }) .ExecuteCommand();
  680. _ = _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(x => x.DiId == dto.DiId && x.CTGGRId == dto.CTGGRId && ids.Contains(x.Id)).SetColumns(x => new Grp_CarTouristGuideGroundReservationsContent
  681. {
  682. IsDel = 0,
  683. DeleteTime = "",
  684. DeleteUserId = null,
  685. }).ExecuteCommand();
  686. if (carTouristList.Count > 0)
  687. {
  688. #region 超支处理
  689. Dictionary<int, int> mealsDic = new Dictionary<int, int>()
  690. {
  691. {988,1074},
  692. {93,1075},
  693. {989,1076},
  694. };
  695. //限制只能选择地区
  696. var opSingle = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.CTGGRId && x.IsDel == 0);
  697. var opSingleCityId = 0;
  698. Grp_NationalTravelFee cityPrice = null;
  699. string priceCity = string.Empty;
  700. //三公费用
  701. if (int.TryParse(opSingle.Area, out opSingleCityId))
  702. {
  703. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  704. x.Id == opSingleCityId
  705. ).First();
  706. priceCity = cityPrice == null ? string.Empty : cityPrice.Country + cityPrice?.City;
  707. }
  708. else
  709. {
  710. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  711. !string.IsNullOrEmpty(x.City) && x.City.Contains(opSingle.Area)
  712. ).First();
  713. priceCity = opSingle.Area;
  714. }
  715. cityPrice ??= new Grp_NationalTravelFee
  716. {
  717. FoodCost = "0",
  718. Id = 0,
  719. };
  720. List<Tuple<int, string, int, decimal>> arr = new List<Tuple<int, string, int, decimal>>();
  721. arr.Add(new Tuple<int, string, int,decimal>(1074, "早餐超支费用", 1077, 1M)); // sid name setdataid 系数
  722. arr.Add(new Tuple<int, string, int,decimal>(1075, "午餐超支费用", 1078, 1M));
  723. arr.Add(new Tuple<int, string, int,decimal>(1076, "晚餐超支费用", 1079, 1M));
  724. arr.Add(new Tuple<int, string, int, decimal>(982, "车超时费用", 1050, 2.4M));
  725. arr.Add(new Tuple<int, string, int, decimal>(1059, "导游超时费用", 1072, 1M));
  726. arr.Add(new Tuple<int, string, int, decimal>(1085, "景点门票超支费用", 1086, 1.2M));
  727. arr.Add(new Tuple<int, string, int, decimal>(1073, "翻译超时费用", 1087, 1.5M));
  728. //超支费用表(数据添加) Fin_GroupExtraCost
  729. List<Fin_GroupExtraCost> groupExtraCostsArr = new List<Fin_GroupExtraCost>();
  730. List<List<Fin_GroupExtraCost>> enterOverspendArr = new List<List<Fin_GroupExtraCost>>();
  731. var setDataArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 17).ToList();
  732. var setDataCurrArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
  733. var number = 0; //人数
  734. var aMeal = cityPrice.FoodCost.ObjToDecimal() / 2; //一顿三公费用
  735. var findSsetDataCurr = setDataCurrArr.Find(q => q.Id == carTouristList[0].Currency);
  736. foreach (var item in arr)
  737. {
  738. var a = carTouristList.Where(x => x.SId == item.Item1 && x.Price != 0).Select(x => {
  739. string remake = x.Remark;
  740. //餐费超支备注额外处理
  741. if (mealsDic.Values.Contains(item.Item1))
  742. {
  743. var keyId = mealsDic.FirstOrDefault(q => q.Value == item.Item1).Key;
  744. //今日一顿餐食费用 (今日一顿餐费 + 今日一顿超支费用)
  745. var dayMealPrice = carTouristList.Where(q => q.SId == keyId && q.Price != 0 &&
  746. DateTime.Compare(x.DatePrice.ObjToDate(),q.DatePrice.ObjToDate()) == 0).Sum( q => q.Price) + x.Price;
  747. var findSetData = setDataArr.Find(q => q.Id == keyId);
  748. if (di.VisitPNumber > 1 && x.Count == 1)
  749. {
  750. number = di.VisitPNumber;
  751. }
  752. else
  753. {
  754. number = x.Count;
  755. }
  756. dayMealPrice = dayMealPrice / number;
  757. remake = $"{x.DatePrice?.ToString("M/d")} {findSetData?.Name}{findSsetDataCurr?.Name} {dayMealPrice * number} - 财政{aMeal} * {number} = {findSsetDataCurr?.Name}{(dayMealPrice * number) - (aMeal * number)}";
  758. }
  759. return new Fin_GroupExtraCost
  760. {
  761. Coefficient = item.Item4,
  762. CreateTime = DateTime.Now,
  763. CreateUserId = dto.CreateUserId,
  764. DiId = dto.DiId,
  765. FilePath = string.Empty,
  766. IsDel = 0,
  767. PriceCount = x.Count,
  768. Price = x.Price,
  769. PriceDt = x.DatePrice.ObjToDate(),
  770. PriceCurrency = x.Currency,
  771. PriceSum = x.Count * x.Price,
  772. PriceName = di.TeamName + "-" + priceCity + "-" + $"{item.Item2}(地接导入)",
  773. PriceType = 1028,
  774. PriceDetailType = item.Item3,
  775. Remark = remake,
  776. };
  777. }).ToList();
  778. if (a.Count > 0)
  779. {
  780. enterOverspendArr.Add(a);
  781. }
  782. }
  783. //数组中的费用
  784. if (enterOverspendArr.Count > 0)
  785. {
  786. groupExtraCostsArr.AddRange(enterOverspendArr.SelectMany(x => x).ToList());
  787. }
  788. var start = opSingle.ServiceStartTime.ObjToDate();
  789. var end = opSingle.ServiceEndTime.ObjToDate();
  790. string remake = string.Empty;
  791. var exitMealCount = 0;
  792. var price = 0M;
  793. var day = 0;
  794. while (start <= end)
  795. {
  796. //查看每日每顿是否存在超支
  797. //不存在则加入退费 (三公一顿 - 消费金额)
  798. //93 , 989
  799. bool isExistsWu = carTouristList.Where(x => x.SId == mealsDic[93] && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0 && x.Price > 0).Count() == 0;
  800. bool isExistsWan = carTouristList.Where(x => x.SId == mealsDic[989] && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0 && x.Price > 0).Count() == 0;
  801. var mealPriceWu = carTouristList.Where(x => x.SId == 93 && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0).Sum(x => x.Price);
  802. var mealPriceWan = carTouristList.Where(x => x.SId == 989 && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0).Sum(x => x.Price);
  803. if (isExistsWu && isExistsWan)
  804. {
  805. remake += $"{start.ToString("M/d")}午餐和晚餐,";
  806. exitMealCount += 2;
  807. price += (aMeal * 2 * di.VisitPNumber) - (mealPriceWu) - (mealPriceWan);
  808. }
  809. else if (isExistsWu)
  810. {
  811. remake += $"{start.ToString("M/d")}午餐,";
  812. exitMealCount += 1;
  813. price += (aMeal * di.VisitPNumber) - (mealPriceWu);
  814. }
  815. else if (isExistsWan)
  816. {
  817. remake += $"{start.ToString("M/d")}晚餐,";
  818. exitMealCount += 1;
  819. price += (aMeal * di.VisitPNumber) - (mealPriceWan);
  820. }
  821. start = start.AddDays(1);
  822. day++;
  823. }
  824. var priceTypeArr = new int[] { 1061 , 1069 };
  825. if (exitMealCount > 0 && priceTypeArr.Contains(opSingle.PriceType))
  826. {
  827. remake = remake.TrimEnd(',');
  828. remake += $"财政 {findSsetDataCurr?.Name} {aMeal} * {di.VisitPNumber} * {exitMealCount}餐";
  829. price = price / di.VisitPNumber / exitMealCount;
  830. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  831. {
  832. Coefficient = 1,
  833. CreateTime = DateTime.Now,
  834. CreateUserId = dto.CreateUserId,
  835. DiId = dto.DiId,
  836. FilePath = string.Empty,
  837. IsDel = 0,
  838. PriceCount = di.VisitPNumber * exitMealCount * -1 ,
  839. Price = price,
  840. PriceDt = opSingle.ServiceStartTime.ObjToDate(),
  841. PriceCurrency = findSsetDataCurr == null ? carTouristList[0].Currency: findSsetDataCurr.Id ,
  842. PriceSum = (di.VisitPNumber * exitMealCount * -1) * price,
  843. PriceName = di.TeamName + "-" + priceCity + "-" + $"退餐费(地接导入)",
  844. PriceType = 1028,
  845. PriceDetailType = 1088,
  846. Remark = remake,
  847. });
  848. }
  849. if (groupExtraCostsArr.Count > 0)
  850. {
  851. foreach (var item in groupExtraCostsArr)
  852. {
  853. var QuerySgin = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(x => x.PriceName == item.PriceName && x.DiId == item.DiId && x.IsDel == 0 && x.PriceDt.ToString("yyyy-MM-dd") == item.PriceDt.ToString("yyyy-MM-dd")).First();
  854. if (QuerySgin == null)
  855. {
  856. _ = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  857. {
  858. coefficient = 1,
  859. createUser = dto.CreateUserId,
  860. currency = item.PriceCurrency,
  861. diId = item.DiId,
  862. editType = 1,
  863. filePath = string.Empty,
  864. payee = dto.Payee,
  865. PortType = 1,
  866. PriceCount = item.PriceCount,
  867. priceName = item.PriceName,
  868. remark = item.Remark,
  869. price = item.Price,
  870. priceDetailType = item.PriceDetailType,
  871. priceType = item.PriceType,
  872. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  873. payType = dto.PayDId,
  874. costSign = dto.OrbitalPrivateTransfer,
  875. Area = opSingle.Area.ObjToInt(),
  876. });
  877. }
  878. else
  879. {
  880. item.Id = QuerySgin.Id;
  881. _ = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  882. {
  883. coefficient = 1,
  884. createUser = dto.CreateUserId,
  885. currency = item.PriceCurrency,
  886. diId = item.DiId,
  887. editType = 2,
  888. filePath = string.Empty,
  889. payee = dto.Payee,
  890. PortType = 1,
  891. PriceCount = item.PriceCount,
  892. priceName = item.PriceName,
  893. remark = item.Remark,
  894. price = item.Price,
  895. priceDetailType = item.PriceDetailType,
  896. priceType = item.PriceType,
  897. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  898. payType = dto.PayDId,
  899. costSign = dto.OrbitalPrivateTransfer,
  900. Id = item.Id,
  901. });
  902. }
  903. }
  904. }
  905. #endregion
  906. }
  907. foreach (var item in carTouristList)
  908. {
  909. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId
  910. && a.CTGGRId == dto.CTGGRId && a.IsDel == 0);
  911. if (QueryData == null)
  912. {
  913. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  914. if (id == 0)
  915. {
  916. RollbackTran();
  917. return result = new Result() { Code = -2, Msg = "添加失败" };
  918. }
  919. }
  920. else
  921. {
  922. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  923. {
  924. Price = item.Price,
  925. PriceContent = item.PriceContent,
  926. Currency = dto.Currency,
  927. Remark = item.Remark,
  928. DatePrice = item.DatePrice,
  929. Count = item.Count,
  930. Units = item.Units,
  931. }).ExecuteCommandAsync();
  932. if (CTable == 0)
  933. {
  934. RollbackTran();
  935. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  936. }
  937. }
  938. }
  939. Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");
  940. //修改C表数据
  941. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  942. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  943. c.PaymentCurrency = dto.Currency;
  944. for (int i = 0; i < dto.SelectCheck.Count; i++)
  945. {
  946. if (!regex.IsMatch(dto.SelectCheck[i]))
  947. {
  948. for (int j = 0; j < carTouristList.Count; j++)
  949. {
  950. if (int.Parse(dto.SelectCheck[i]) == carTouristList[j].SId)
  951. {
  952. c.PayMoney += carTouristList[j].Price * carTouristList[j].Count;
  953. }
  954. }
  955. }
  956. else
  957. {
  958. c.PayMoney = carTouristList.Sum(x => x.Price * x.Count);
  959. break;
  960. }
  961. }
  962. c.PayPercentage = dto.PayPercentage;
  963. c.ConsumptionDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  964. c.CTable = 79;
  965. c.CId = dto.CTGGRId;
  966. c.IsAuditGM = 0;
  967. c.PayDId = dto.PayDId;
  968. c.DIId = dto.DiId;
  969. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  970. c.Payee = dto.Payee;
  971. c.CreateUserId = dto.CreateUserId;
  972. //if (c.PayDId == 72) c.IsPay = 1;
  973. //else c.IsPay = 0;
  974. c.IsPay = 0;
  975. c.RMBPrice = c.PayMoney;
  976. c.DayRate = 1;
  977. #region 老汇率获取
  978. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  979. //List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  980. //if (_TeamRate != null)
  981. //{
  982. // Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  983. // if (_SetData != null)
  984. // {
  985. // currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  986. // CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  987. // if (CurrencyRate != null)
  988. // {
  989. // c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  990. // c.DayRate = CurrencyRate.Rate;
  991. // }
  992. // }
  993. //}
  994. #endregion
  995. var rate = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, dto.Currency);
  996. if (rate.Code == 0)
  997. {
  998. var rateData = rate.Data as CurrencyInfo;
  999. if (rateData != null)
  1000. {
  1001. c.RMBPrice = c.PayMoney * rateData.Rate;
  1002. c.DayRate = rateData.Rate;
  1003. }
  1004. }
  1005. int noticeSign = 1; //企业微信通知标识
  1006. int noticeCcpId = 0;
  1007. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.CTGGRId && a.IsDel == 0 && a.CTable == 79 && a.DIId == dto.DiId);
  1008. if (grp_CreditCard != null)//修改
  1009. {
  1010. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId == dto.DiId).SetColumns(a => new Grp_CreditCardPayment
  1011. {
  1012. PaymentCurrency = c.PaymentCurrency,
  1013. PayMoney = c.PayMoney,
  1014. PayPercentage = c.PayPercentage,
  1015. CTable = c.CTable,
  1016. PayDId = c.PayDId,
  1017. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  1018. Payee = c.Payee,
  1019. IsPay = c.IsPay,
  1020. RMBPrice = c.RMBPrice,
  1021. DayRate = c.DayRate,
  1022. }).ExecuteCommandAsync();
  1023. noticeSign = 2;
  1024. noticeCcpId = grp_CreditCard.Id;
  1025. if (CTable == 0)
  1026. {
  1027. RollbackTran();
  1028. return result = new Result() { Code = -2, Msg = "修改失败" };
  1029. }
  1030. }
  1031. else//添加
  1032. {
  1033. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  1034. noticeCcpId = id;
  1035. if (id == 0)
  1036. {
  1037. RollbackTran();
  1038. return result = new Result() { Code = -2, Msg = "添加失败" };
  1039. }
  1040. }
  1041. _ = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId && a.IsDel == 0).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  1042. {
  1043. CId = dto.Currency,
  1044. ServiceQuotedPrice = c.PayMoney,
  1045. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  1046. SelectCheck = string.Join(',', dto.SelectCheck)
  1047. }).ExecuteCommandAsync();
  1048. var data = new { ccpId = noticeCcpId, sign = noticeSign };
  1049. result = new Result() { Code = 0, Msg = "保存成功", Data = data };
  1050. CommitTran();
  1051. }
  1052. catch (Exception ex)
  1053. {
  1054. RollbackTran();
  1055. result = new Result() { Code = -2, Msg = $"接口异常!({ex.Message})"};
  1056. }
  1057. return result;
  1058. }
  1059. /// <summary>
  1060. /// 超支费用
  1061. /// 1增、2改、3删
  1062. /// </summary>
  1063. /// <param name="dto"></param>
  1064. /// <returns></returns>
  1065. private async Task<Result> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1066. {
  1067. Result rt = new Result();
  1068. #region 验证
  1069. #endregion
  1070. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1071. _entity.DiId = dto.diId;
  1072. _entity.PriceName = dto.priceName;
  1073. _entity.Price = dto.price;
  1074. _entity.PriceCurrency = dto.currency;
  1075. _entity.PriceType = dto.priceType;
  1076. _entity.Coefficient = dto.coefficient;
  1077. _entity.PriceDetailType = dto.priceDetailType;
  1078. _entity.FilePath = dto.filePath;
  1079. _entity.Remark = dto.remark;
  1080. _entity.PriceCount = dto.PriceCount;
  1081. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  1082. _entity.PriceSum = dto.price * dto.PriceCount;
  1083. _entity.Area = dto.Area;
  1084. _daiRep.BeginTran();
  1085. if (dto.editType == 1)
  1086. {
  1087. _entity.CreateUserId = dto.createUser;
  1088. _entity.CreateTime = DateTime.Now;
  1089. _entity.IsDel = 0;
  1090. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1091. if (returnId > 0)
  1092. {
  1093. dto.Id = returnId;
  1094. }
  1095. }
  1096. else if (dto.editType == 2)
  1097. {
  1098. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1099. {
  1100. PriceName = dto.priceName,
  1101. Price = dto.price,
  1102. PriceCurrency = dto.currency,
  1103. PriceType = dto.priceType,
  1104. PriceDetailType = dto.priceDetailType,
  1105. Coefficient = dto.coefficient,
  1106. FilePath = dto.filePath,
  1107. Remark = dto.remark,
  1108. PriceCount = dto.PriceCount,
  1109. PriceDt = _entity.PriceDt,
  1110. PriceSum = _entity.PriceSum,
  1111. Area = _entity.Area,
  1112. });
  1113. if (!res)
  1114. {
  1115. _daiRep.RollbackTran();
  1116. //Ok(JsonView(false, "2操作失败!"))
  1117. rt.Msg = "2操作失败!";
  1118. return rt;
  1119. }
  1120. }
  1121. else if (dto.editType == 3)
  1122. {
  1123. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1124. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1125. {
  1126. IsDel = 1,
  1127. DeleteTime = delTime,
  1128. DeleteUserId = dto.createUser
  1129. });
  1130. if (!res)
  1131. {
  1132. _daiRep.RollbackTran();
  1133. rt.Msg = "3操作失败!";
  1134. return rt;
  1135. }
  1136. }
  1137. else
  1138. {
  1139. _daiRep.RollbackTran();
  1140. rt.Msg = "未知的editType";
  1141. return rt;
  1142. }
  1143. if (!(await extraCost_editCreditCardPayment(dto)))
  1144. {
  1145. rt.Msg = "ccp操作失败";
  1146. return rt;
  1147. }
  1148. _daiRep.CommitTran();
  1149. rt.Code = 0;
  1150. rt.Msg = "操作成功";
  1151. return rt;
  1152. }
  1153. private async Task<bool> extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1154. {
  1155. //设置团组汇率
  1156. decimal dcm_dayrate = 1M;
  1157. decimal dcm_rmbPrice = costDto.price;
  1158. int ispay = costDto.payType == 72 ? 1 : 0;
  1159. if (costDto.costSign != 3)
  1160. {
  1161. //获取新汇率 int diId,int CId, int currencyId
  1162. Result rate = await _setDataRep.PostCurrencyByDiid(costDto.diId, 1015, costDto.currency);
  1163. if (rate.Code == 0)
  1164. {
  1165. var rateInfo = (rate.Data as CurrencyInfo);
  1166. if (rateInfo is not null)
  1167. {
  1168. dcm_dayrate = rateInfo.Rate;
  1169. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  1170. }
  1171. else
  1172. {
  1173. dcm_dayrate = 1;
  1174. }
  1175. }
  1176. }
  1177. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1178. if (ccp == null)
  1179. {
  1180. ccp = new Grp_CreditCardPayment();
  1181. ccp.PayDId = costDto.payType;// dto
  1182. ccp.ConsumptionPatterns = "";
  1183. ccp.ConsumptionDate = "";
  1184. ccp.CTDId = costDto.payCardId;// dto
  1185. ccp.BankNo = "";
  1186. ccp.CardholderName = "";
  1187. ccp.PayMoney = costDto.price;// dto
  1188. ccp.PaymentCurrency = costDto.currency;// dto
  1189. ccp.CompanyBankNo = "";
  1190. ccp.OtherBankName = "";
  1191. ccp.OtherSideNo = "";
  1192. ccp.OtherSideName = "";
  1193. ccp.Remark = "";
  1194. ccp.CreateUserId = costDto.createUser;
  1195. ccp.CreateTime = DateTime.Now;
  1196. ccp.MFOperator = 0;
  1197. ccp.MFOperatorDate = "";
  1198. ccp.IsAuditDM = 0;
  1199. ccp.AuditDMOperate = 0;
  1200. ccp.AuditDMDate = "";
  1201. ccp.IsAuditMF = 0;
  1202. ccp.AuditMFOperate = 0;
  1203. ccp.AuditMFDate = "";
  1204. ccp.IsAuditGM = 0;
  1205. ccp.AuditGMOperate = 0;
  1206. ccp.AuditGMDate = "";
  1207. ccp.IsPay = ispay; // upd
  1208. ccp.DIId = costDto.diId;// dto
  1209. ccp.CId = costDto.Id;// dto
  1210. ccp.CTable = 1015; //超支费用指向id
  1211. ccp.IsDel = 0;
  1212. ccp.PayPercentage = 100M;
  1213. ccp.PayThenMoney = 0M;
  1214. ccp.PayPercentageOld = 100M;
  1215. ccp.PayThenMoneyOld = 0M;
  1216. ccp.UpdateDate = "";
  1217. ccp.Payee = costDto.payee;// dto
  1218. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1219. ccp.ExceedBudget = 0;
  1220. ccp.DayRate = dcm_dayrate; //upd
  1221. ccp.RMBPrice = dcm_rmbPrice; //upd
  1222. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1223. if (ccpInsertId > 0)
  1224. {
  1225. return true;
  1226. }
  1227. }
  1228. else
  1229. {
  1230. if (costDto.editType == 2)
  1231. {
  1232. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1233. {
  1234. PayDId = costDto.payType,
  1235. CTDId = costDto.payCardId,
  1236. PayMoney = costDto.price,
  1237. PaymentCurrency = costDto.currency,
  1238. IsPay = ispay,
  1239. Payee = costDto.payee,
  1240. OrbitalPrivateTransfer = costDto.costSign,
  1241. DayRate = dcm_dayrate,
  1242. RMBPrice = dcm_rmbPrice
  1243. });
  1244. return res;
  1245. }
  1246. else if (costDto.editType == 3)
  1247. {
  1248. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1249. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1250. {
  1251. IsDel = 1,
  1252. DeleteTime = delTime,
  1253. DeleteUserId = costDto.createUser
  1254. });
  1255. return res2;
  1256. }
  1257. }
  1258. return false;
  1259. }
  1260. }
  1261. }