CarTouristGuideGroundRepository.cs 69 KB

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