CarTouristGuideGroundRepository.cs 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  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. if (carTouristList.Count > 0)
  662. {
  663. #region load
  664. //车超时费
  665. //餐费和三公经费那个表做完匹配后也放进超支表里
  666. //添加导游超时费用
  667. DataTable tb = new DataTable();
  668. tb.Columns.Add("日期", typeof(DateTime));
  669. tb.Columns.Add("费用", typeof(decimal));
  670. tb.Columns.Add("币种", typeof(string));
  671. var addsTourClientList = new List<Grp_TourClientList>();
  672. var carExtraList = carTouristList.Where(x => x.SId == 982 && x.Price != 0).ToList();
  673. var mealPriceList = carTouristList.Where(x => (x.SId == 93 || x.SId == 988 || x.SId == 989) && x.Price != 0).GroupBy(x => x.DatePrice).ToList();
  674. var tgOvertime = carTouristList.Where(x => x.SId == 1059 && x.Price != 0).ToList();
  675. //Dictionary<int,string> enterOverspendArrParam = new Dictionary<int,string>();
  676. //enterOverspendArrParam.Add(0,"");
  677. //enterOverspendArrParam.Add(1, "");
  678. //enterOverspendArrParam.Add(2, "");
  679. //List<List<Grp_CarTouristGuideGroundReservationsContent>> enterOverspendArr = new List<List<Grp_CarTouristGuideGroundReservationsContent>>();
  680. //foreach (var item in enterOverspendArrParam.Keys)
  681. //{
  682. // var a = carTouristList.Where(x => x.SId == item).ToList();
  683. // var b = a.Select(x => new Fin_GroupExtraCost
  684. // {
  685. // Coefficient = 1,
  686. // CreateTime = DateTime.Now,
  687. // CreateUserId = dto.CreateUserId,
  688. // DiId = dto.DiId,
  689. // FilePath = string.Empty,
  690. // IsDel = 0,
  691. // PriceCount = 0,
  692. // }).ToList();
  693. //}
  694. //成本数据
  695. List<Grp_GroupCost> _GroupCosts = new List<Grp_GroupCost>();
  696. var _GroupCostParameters = _groupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.DiId);
  697. if (_GroupCostParameters != null && _GroupCostParameters.IsShare == 1)
  698. {
  699. _GroupCosts = _sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  700. }
  701. //处理date为空问题
  702. if (_GroupCosts.Count > 0)
  703. {
  704. for (int i = 0; i < _GroupCosts.Count; i++)
  705. {
  706. if (string.IsNullOrEmpty(_GroupCosts[i].Date))
  707. {
  708. if (i > 0)
  709. {
  710. _GroupCosts[i].Date = _GroupCosts[i - 1].Date;
  711. }
  712. }
  713. }
  714. var CostSoure = _GroupCosts.GroupBy(x => x.Date).ToList();
  715. _GroupCosts.Clear();
  716. foreach (var costSoure in CostSoure)
  717. {
  718. var cost = costSoure.ToList();
  719. cost[0].D = cost.Sum(x => x.D);
  720. cost[0].B = cost.Sum(x => x.B);
  721. cost[0].L = cost.Sum(x => x.L);
  722. _GroupCosts.Add(cost[0]);
  723. }
  724. }
  725. mealPriceList.ForEach(x =>
  726. {
  727. var row = tb.NewRow();
  728. row["日期"] = x.Key;
  729. row["费用"] = x.Sum(x => x.Price * x.Count);
  730. row["币种"] = x.FirstOrDefault()?.Currency;
  731. tb.Rows.Add(row);
  732. });
  733. //限制只能选择地区
  734. var opSingle = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.CTGGRId && x.IsDel == 0);
  735. var opSingleCityId = 0;
  736. Grp_NationalTravelFee cityPrice = null;
  737. string priceCity = string.Empty;
  738. //三公费用
  739. if (int.TryParse(opSingle.Area, out opSingleCityId))
  740. {
  741. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  742. x.Id == opSingleCityId
  743. ).First();
  744. priceCity = cityPrice == null ? string.Empty : cityPrice.Country + cityPrice?.City;
  745. }
  746. else
  747. {
  748. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  749. !string.IsNullOrEmpty(x.City) && x.City.Contains(opSingle.Area)
  750. ).First();
  751. priceCity = opSingle.Area;
  752. }
  753. //超支费用表(数据添加) Fin_GroupExtraCost
  754. List<Fin_GroupExtraCost> groupExtraCostsArr = new List<Fin_GroupExtraCost>();
  755. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  756. if (di == null)
  757. {
  758. result.Code = -1;
  759. result.Msg = "无该团组信息!";
  760. return result;
  761. }
  762. if (carExtraList.Count > 0)
  763. {
  764. foreach (var item in carExtraList)
  765. {
  766. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  767. {
  768. Price = item.Price,
  769. CreateTime = DateTime.Now,
  770. CreateUserId = dto.CreateUserId,
  771. Coefficient = 1,
  772. DiId = dto.DiId,
  773. PriceCurrency = item.Currency,
  774. PriceName = di.TeamName + "-" + priceCity + "-" + "车超时费(地接导入)",
  775. PriceType = 1028,
  776. PriceDt = item.DatePrice.ObjToDate(),
  777. PriceSum = item.Price * item.Count,
  778. PriceCount = item.Count,
  779. FilePath = string.Empty,
  780. PriceDetailType = 1050,
  781. });
  782. }
  783. }
  784. //导游超时费用
  785. if (tgOvertime.Count > 0)
  786. {
  787. foreach (var item in tgOvertime)
  788. {
  789. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  790. {
  791. Price = item.Price,
  792. CreateTime = DateTime.Now,
  793. CreateUserId = dto.CreateUserId,
  794. Coefficient = 1,
  795. DiId = dto.DiId,
  796. PriceCurrency = item.Currency,
  797. PriceName = di.TeamName + "-" + priceCity + "-" + "导游超时费(地接导入)",
  798. PriceType = 1028,
  799. PriceDt = item.DatePrice.ObjToDate(),
  800. PriceSum = item.Price * item.Count,
  801. PriceCount = item.Count,
  802. FilePath = string.Empty,
  803. PriceDetailType = 1072,
  804. });
  805. }
  806. }
  807. if (_GroupCostParameters != null)
  808. {
  809. //币种
  810. var currOpResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, carTouristList[0].Currency);
  811. var currOp = currOpResult.Code == 0 ? (currOpResult.Data as CurrencyInfo) == null ? 1 : (currOpResult.Data as CurrencyInfo)!.Rate : 1;
  812. //三公费用汇率 (修改为对比成本)
  813. //var cityCurrResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, cityPrice.Currency);
  814. //var cityCurr = cityCurrResult.Code == 0 ? (cityCurrResult.Data as CurrencyInfo) == null ? 1 : (cityCurrResult.Data as CurrencyInfo)!.Rate : 1;
  815. //成本汇率
  816. var costCurr = _GroupCostParameters.Rate;
  817. if (tb.Rows.Count > 0)
  818. {
  819. foreach (DataRow item in tb.Rows)
  820. {
  821. var listTime = Convert.ToDateTime(item["日期"]);
  822. var costFliterArr = _GroupCosts.Where(x => DateTime.TryParse(x.Date, out DateTime costData)
  823. && costData.ToString("yyyy-MM-dd") == listTime.ToString("yyyy-MM-dd")).ToList();
  824. //成本日期费用
  825. decimal foodCost = (costFliterArr.Sum(x => x.D) + costFliterArr.Sum(x => x.L) + costFliterArr.Sum(x => x.B)) * di.VisitPNumber;
  826. var price = Convert.ToDecimal(item["费用"]);
  827. if (item["币种"].ToString() != _GroupCostParameters.Currency.ToString().Trim()) //币种不相同
  828. {
  829. var a = item["币种"].ToString();
  830. var b = _GroupCostParameters.Currency.ToString().Trim();
  831. //币种str匹配不上在匹配Name
  832. if (int.TryParse(a, out int a1))
  833. {
  834. a = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == a1).Name;
  835. }
  836. if (int.TryParse(b, out int b1))
  837. {
  838. b = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == b1).Name;
  839. }
  840. if (a != b)
  841. {
  842. //全部转换为rmb;
  843. item["费用"] = price * currOp;
  844. foodCost = (foodCost * costCurr);
  845. item["币种"] = "836";
  846. //cityPrice.Currency = 836;
  847. }
  848. }
  849. if (price > foodCost)
  850. {
  851. //每天费用大于三公费用
  852. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  853. {
  854. Price = price - foodCost,
  855. CreateTime = DateTime.Now,
  856. CreateUserId = dto.CreateUserId,
  857. Coefficient = 1,
  858. DiId = dto.DiId,
  859. PriceCurrency = Convert.ToInt32(item["币种"]),
  860. PriceName = di.TeamName + "-" + priceCity + "-" + "餐费(地接导入)",
  861. PriceType = 1028,
  862. PriceDt = Convert.ToDateTime(item["日期"]),
  863. PriceSum = price - foodCost,
  864. PriceCount = 1,
  865. FilePath = string.Empty,
  866. PriceDetailType = 1049,
  867. });
  868. }
  869. }
  870. }
  871. }
  872. var isTrue = false;
  873. if (groupExtraCostsArr.Count > 0)
  874. {
  875. foreach (var item in groupExtraCostsArr)
  876. {
  877. 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();
  878. if (QuerySgin == null)
  879. {
  880. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  881. {
  882. coefficient = 1,
  883. createUser = dto.CreateUserId,
  884. currency = item.PriceCurrency,
  885. diId = item.DiId,
  886. editType = 1,
  887. filePath = string.Empty,
  888. payee = dto.Payee,
  889. PortType = 1,
  890. PriceCount = item.PriceCount,
  891. priceName = item.PriceName,
  892. remark = item.Remark,
  893. price = item.Price,
  894. priceDetailType = item.PriceDetailType,
  895. priceType = item.PriceType,
  896. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  897. payType = dto.PayDId,
  898. costSign = dto.OrbitalPrivateTransfer
  899. });
  900. isTrue = resultThis.Code == 0 ? true : false;
  901. }
  902. else
  903. {
  904. item.Id = QuerySgin.Id;
  905. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  906. {
  907. coefficient = 1,
  908. createUser = dto.CreateUserId,
  909. currency = item.PriceCurrency,
  910. diId = item.DiId,
  911. editType = 2,
  912. filePath = string.Empty,
  913. payee = dto.Payee,
  914. PortType = 1,
  915. PriceCount = item.PriceCount,
  916. priceName = item.PriceName,
  917. remark = item.Remark,
  918. price = item.Price,
  919. priceDetailType = item.PriceDetailType,
  920. priceType = item.PriceType,
  921. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  922. payType = dto.PayDId,
  923. costSign = dto.OrbitalPrivateTransfer,
  924. Id = item.Id,
  925. });
  926. isTrue = resultThis.Code == 0 ? true : false;
  927. }
  928. }
  929. }
  930. #endregion
  931. }
  932. foreach (var item in carTouristList)
  933. {
  934. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel == 0);
  935. if (QueryData == null)
  936. {
  937. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  938. if (id == 0)
  939. {
  940. RollbackTran();
  941. return result = new Result() { Code = -2, Msg = "添加失败" };
  942. }
  943. }
  944. else
  945. {
  946. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  947. {
  948. Price = item.Price,
  949. PriceContent = item.PriceContent,
  950. Currency = dto.Currency,
  951. Remark = item.Remark,
  952. DatePrice = item.DatePrice,
  953. Count = item.Count,
  954. Units = item.Units,
  955. }).ExecuteCommandAsync();
  956. if (CTable == 0)
  957. {
  958. RollbackTran();
  959. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  960. }
  961. }
  962. }
  963. Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");
  964. //修改C表数据
  965. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  966. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  967. c.PaymentCurrency = dto.Currency;
  968. for (int i = 0; i < dto.SelectCheck.Count; i++)
  969. {
  970. if (!regex.IsMatch(dto.SelectCheck[i]))
  971. {
  972. for (int j = 0; j < carTouristList.Count; j++)
  973. {
  974. if (int.Parse(dto.SelectCheck[i]) == carTouristList[j].SId)
  975. {
  976. c.PayMoney += carTouristList[j].Price * carTouristList[j].Count;
  977. }
  978. }
  979. }
  980. else
  981. {
  982. c.PayMoney = carTouristList.Sum(x => x.Price * x.Count);
  983. break;
  984. }
  985. }
  986. c.PayPercentage = dto.PayPercentage;
  987. c.ConsumptionDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  988. c.CTable = 79;
  989. c.CId = dto.CTGGRId;
  990. c.IsAuditGM = 0;
  991. c.PayDId = dto.PayDId;
  992. c.DIId = dto.DiId;
  993. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  994. c.Payee = dto.Payee;
  995. c.CreateUserId = dto.CreateUserId;
  996. if (c.PayDId == 72) c.IsPay = 1;
  997. else c.IsPay = 0;
  998. c.RMBPrice = c.PayMoney;
  999. c.DayRate = 1;
  1000. #region 老汇率获取
  1001. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  1002. //List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  1003. //if (_TeamRate != null)
  1004. //{
  1005. // Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  1006. // if (_SetData != null)
  1007. // {
  1008. // currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  1009. // CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  1010. // if (CurrencyRate != null)
  1011. // {
  1012. // c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  1013. // c.DayRate = CurrencyRate.Rate;
  1014. // }
  1015. // }
  1016. //}
  1017. #endregion
  1018. var rate = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, dto.Currency);
  1019. if (rate.Code == 0)
  1020. {
  1021. var rateData = rate.Data as CurrencyInfo;
  1022. if (rateData != null)
  1023. {
  1024. c.RMBPrice = c.PayMoney * rateData.Rate;
  1025. c.DayRate = rateData.Rate;
  1026. }
  1027. }
  1028. int noticeSign = 1; //企业微信通知标识
  1029. int noticeCcpId = 0;
  1030. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.CTGGRId && a.IsDel == 0 && a.CTable == 79 && a.DIId == dto.DiId);
  1031. if (grp_CreditCard != null)//修改
  1032. {
  1033. 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
  1034. {
  1035. PaymentCurrency = c.PaymentCurrency,
  1036. PayMoney = c.PayMoney,
  1037. PayPercentage = c.PayPercentage,
  1038. CTable = c.CTable,
  1039. PayDId = c.PayDId,
  1040. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  1041. Payee = c.Payee,
  1042. IsPay = c.IsPay,
  1043. RMBPrice = c.RMBPrice,
  1044. DayRate = c.DayRate,
  1045. }).ExecuteCommandAsync();
  1046. noticeSign = 2;
  1047. noticeCcpId = grp_CreditCard.Id;
  1048. if (CTable == 0)
  1049. {
  1050. RollbackTran();
  1051. return result = new Result() { Code = -2, Msg = "修改失败" };
  1052. }
  1053. }
  1054. else//添加
  1055. {
  1056. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  1057. noticeCcpId = id;
  1058. if (id == 0)
  1059. {
  1060. RollbackTran();
  1061. return result = new Result() { Code = -2, Msg = "添加失败" };
  1062. }
  1063. }
  1064. 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
  1065. {
  1066. CId = dto.Currency,
  1067. ServiceQuotedPrice = c.PayMoney,
  1068. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  1069. SelectCheck = string.Join(',', dto.SelectCheck)
  1070. }).ExecuteCommandAsync();
  1071. if (CarTouristGuideCTable == 0)
  1072. {
  1073. RollbackTran();
  1074. return result = new Result() { Code = -2, Msg = "修改失败" };
  1075. }
  1076. var data = new { ccpId = noticeCcpId, sign = noticeSign };
  1077. result = new Result() { Code = 0, Msg = "保存成功", Data = data };
  1078. CommitTran();
  1079. }
  1080. catch (Exception ex)
  1081. {
  1082. RollbackTran();
  1083. return result = new Result() { Code = -2, Msg = "未知错误" };
  1084. }
  1085. return result;
  1086. }
  1087. /// <summary>
  1088. /// 超支费用
  1089. /// 1增、2改、3删
  1090. /// </summary>
  1091. /// <param name="dto"></param>
  1092. /// <returns></returns>
  1093. private async Task<Result> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1094. {
  1095. Result rt = new Result();
  1096. #region 验证
  1097. #endregion
  1098. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1099. _entity.DiId = dto.diId;
  1100. _entity.PriceName = dto.priceName;
  1101. _entity.Price = dto.price;
  1102. _entity.PriceCurrency = dto.currency;
  1103. _entity.PriceType = dto.priceType;
  1104. _entity.Coefficient = dto.coefficient;
  1105. _entity.PriceDetailType = dto.priceDetailType;
  1106. _entity.FilePath = dto.filePath;
  1107. _entity.Remark = dto.remark;
  1108. _entity.PriceCount = dto.PriceCount;
  1109. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  1110. _entity.PriceSum = dto.price * dto.PriceCount;
  1111. _daiRep.BeginTran();
  1112. if (dto.editType == 1)
  1113. {
  1114. _entity.CreateUserId = dto.createUser;
  1115. _entity.CreateTime = DateTime.Now;
  1116. _entity.IsDel = 0;
  1117. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1118. if (returnId > 0)
  1119. {
  1120. dto.Id = returnId;
  1121. }
  1122. }
  1123. else if (dto.editType == 2)
  1124. {
  1125. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1126. {
  1127. PriceName = dto.priceName,
  1128. Price = dto.price,
  1129. PriceCurrency = dto.currency,
  1130. PriceType = dto.priceType,
  1131. PriceDetailType = dto.priceDetailType,
  1132. Coefficient = dto.coefficient,
  1133. FilePath = dto.filePath,
  1134. Remark = dto.remark,
  1135. PriceCount = dto.PriceCount,
  1136. PriceDt = _entity.PriceDt,
  1137. PriceSum = _entity.PriceSum
  1138. });
  1139. if (!res)
  1140. {
  1141. _daiRep.RollbackTran();
  1142. //Ok(JsonView(false, "2操作失败!"))
  1143. rt.Msg = "2操作失败!";
  1144. return rt;
  1145. }
  1146. }
  1147. else if (dto.editType == 3)
  1148. {
  1149. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1150. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1151. {
  1152. IsDel = 1,
  1153. DeleteTime = delTime,
  1154. DeleteUserId = dto.createUser
  1155. });
  1156. if (!res)
  1157. {
  1158. _daiRep.RollbackTran();
  1159. rt.Msg = "3操作失败!";
  1160. return rt;
  1161. }
  1162. }
  1163. else
  1164. {
  1165. _daiRep.RollbackTran();
  1166. rt.Msg = "未知的editType";
  1167. return rt;
  1168. }
  1169. if (!extraCost_editCreditCardPayment(dto))
  1170. {
  1171. rt.Msg = "ccp操作失败";
  1172. return rt;
  1173. }
  1174. _daiRep.CommitTran();
  1175. rt.Code = 0;
  1176. rt.Msg = "操作成功";
  1177. return rt;
  1178. }
  1179. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1180. {
  1181. //设置团组汇率
  1182. decimal dcm_dayrate = 1M;
  1183. decimal dcm_rmbPrice = costDto.price;
  1184. int ispay = costDto.payType == 72 ? 1 : 0;
  1185. if (costDto.costSign != 3)
  1186. {
  1187. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1188. if (tr != null)
  1189. {
  1190. if (costDto.currency == 49)
  1191. {
  1192. dcm_dayrate = tr.RateU;
  1193. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1194. }
  1195. else if (costDto.currency == 51)
  1196. {
  1197. dcm_dayrate = tr.RateE;
  1198. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1199. }
  1200. }
  1201. }
  1202. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1203. if (ccp == null)
  1204. {
  1205. ccp = new Grp_CreditCardPayment();
  1206. ccp.PayDId = costDto.payType;// dto
  1207. ccp.ConsumptionPatterns = "";
  1208. ccp.ConsumptionDate = "";
  1209. ccp.CTDId = costDto.payCardId;// dto
  1210. ccp.BankNo = "";
  1211. ccp.CardholderName = "";
  1212. ccp.PayMoney = costDto.price;// dto
  1213. ccp.PaymentCurrency = costDto.currency;// dto
  1214. ccp.CompanyBankNo = "";
  1215. ccp.OtherBankName = "";
  1216. ccp.OtherSideNo = "";
  1217. ccp.OtherSideName = "";
  1218. ccp.Remark = "";
  1219. ccp.CreateUserId = costDto.createUser;
  1220. ccp.CreateTime = DateTime.Now;
  1221. ccp.MFOperator = 0;
  1222. ccp.MFOperatorDate = "";
  1223. ccp.IsAuditDM = 0;
  1224. ccp.AuditDMOperate = 0;
  1225. ccp.AuditDMDate = "";
  1226. ccp.IsAuditMF = 0;
  1227. ccp.AuditMFOperate = 0;
  1228. ccp.AuditMFDate = "";
  1229. ccp.IsAuditGM = 0;
  1230. ccp.AuditGMOperate = 0;
  1231. ccp.AuditGMDate = "";
  1232. ccp.IsPay = ispay; // upd
  1233. ccp.DIId = costDto.diId;// dto
  1234. ccp.CId = costDto.Id;// dto
  1235. ccp.CTable = 1015; //超支费用指向id
  1236. ccp.IsDel = 0;
  1237. ccp.PayPercentage = 100M;
  1238. ccp.PayThenMoney = 0M;
  1239. ccp.PayPercentageOld = 100M;
  1240. ccp.PayThenMoneyOld = 0M;
  1241. ccp.UpdateDate = "";
  1242. ccp.Payee = costDto.payee;// dto
  1243. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1244. ccp.ExceedBudget = 0;
  1245. ccp.DayRate = dcm_dayrate; //upd
  1246. ccp.RMBPrice = dcm_rmbPrice; //upd
  1247. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1248. if (ccpInsertId > 0)
  1249. {
  1250. return true;
  1251. }
  1252. }
  1253. else
  1254. {
  1255. if (costDto.editType == 2)
  1256. {
  1257. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1258. {
  1259. PayDId = costDto.payType,
  1260. CTDId = costDto.payCardId,
  1261. PayMoney = costDto.price,
  1262. PaymentCurrency = costDto.currency,
  1263. IsPay = ispay,
  1264. Payee = costDto.payee,
  1265. OrbitalPrivateTransfer = costDto.costSign,
  1266. DayRate = dcm_dayrate,
  1267. RMBPrice = dcm_rmbPrice
  1268. });
  1269. return res;
  1270. }
  1271. else if (costDto.editType == 3)
  1272. {
  1273. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1274. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1275. {
  1276. IsDel = 1,
  1277. DeleteTime = delTime,
  1278. DeleteUserId = costDto.createUser
  1279. });
  1280. return res2;
  1281. }
  1282. }
  1283. return false;
  1284. }
  1285. }
  1286. }