CarTouristGuideGroundRepository.cs 66 KB

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