CarTouristGuideGroundRepository.cs 67 KB

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