CarTouristGuideGroundRepository.cs 72 KB

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