CarTouristGuideGroundRepository.cs 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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 && a.IsDel == 0);
  964. if (QueryData == null)
  965. {
  966. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  967. if (id == 0)
  968. {
  969. RollbackTran();
  970. return result = new Result() { Code = -2, Msg = "添加失败" };
  971. }
  972. }
  973. else
  974. {
  975. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  976. {
  977. Price = item.Price,
  978. PriceContent = item.PriceContent,
  979. Currency = dto.Currency,
  980. Remark = item.Remark,
  981. DatePrice = item.DatePrice,
  982. Count = item.Count,
  983. Units = item.Units,
  984. }).ExecuteCommandAsync();
  985. if (CTable == 0)
  986. {
  987. RollbackTran();
  988. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  989. }
  990. }
  991. }
  992. Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");
  993. //修改C表数据
  994. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  995. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  996. c.PaymentCurrency = dto.Currency;
  997. for (int i = 0; i < dto.SelectCheck.Count; i++)
  998. {
  999. if (!regex.IsMatch(dto.SelectCheck[i]))
  1000. {
  1001. for (int j = 0; j < carTouristList.Count; j++)
  1002. {
  1003. if (int.Parse(dto.SelectCheck[i]) == carTouristList[j].SId)
  1004. {
  1005. c.PayMoney += carTouristList[j].Price * carTouristList[j].Count;
  1006. }
  1007. }
  1008. }
  1009. else
  1010. {
  1011. c.PayMoney = carTouristList.Sum(x => x.Price * x.Count);
  1012. break;
  1013. }
  1014. }
  1015. c.PayPercentage = dto.PayPercentage;
  1016. c.ConsumptionDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1017. c.CTable = 79;
  1018. c.CId = dto.CTGGRId;
  1019. c.IsAuditGM = 0;
  1020. c.PayDId = dto.PayDId;
  1021. c.DIId = dto.DiId;
  1022. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  1023. c.Payee = dto.Payee;
  1024. c.CreateUserId = dto.CreateUserId;
  1025. if (c.PayDId == 72) c.IsPay = 1;
  1026. else c.IsPay = 0;
  1027. c.RMBPrice = c.PayMoney;
  1028. c.DayRate = 1;
  1029. #region 老汇率获取
  1030. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  1031. //List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  1032. //if (_TeamRate != null)
  1033. //{
  1034. // Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  1035. // if (_SetData != null)
  1036. // {
  1037. // currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  1038. // CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  1039. // if (CurrencyRate != null)
  1040. // {
  1041. // c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  1042. // c.DayRate = CurrencyRate.Rate;
  1043. // }
  1044. // }
  1045. //}
  1046. #endregion
  1047. var rate = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, dto.Currency);
  1048. if (rate.Code == 0)
  1049. {
  1050. var rateData = rate.Data as CurrencyInfo;
  1051. if (rateData != null)
  1052. {
  1053. c.RMBPrice = c.PayMoney * rateData.Rate;
  1054. c.DayRate = rateData.Rate;
  1055. }
  1056. }
  1057. int noticeSign = 1; //企业微信通知标识
  1058. int noticeCcpId = 0;
  1059. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.CTGGRId && a.IsDel == 0 && a.CTable == 79 && a.DIId == dto.DiId);
  1060. if (grp_CreditCard != null)//修改
  1061. {
  1062. 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
  1063. {
  1064. PaymentCurrency = c.PaymentCurrency,
  1065. PayMoney = c.PayMoney,
  1066. PayPercentage = c.PayPercentage,
  1067. CTable = c.CTable,
  1068. PayDId = c.PayDId,
  1069. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  1070. Payee = c.Payee,
  1071. IsPay = c.IsPay,
  1072. RMBPrice = c.RMBPrice,
  1073. DayRate = c.DayRate,
  1074. }).ExecuteCommandAsync();
  1075. noticeSign = 2;
  1076. noticeCcpId = grp_CreditCard.Id;
  1077. if (CTable == 0)
  1078. {
  1079. RollbackTran();
  1080. return result = new Result() { Code = -2, Msg = "修改失败" };
  1081. }
  1082. }
  1083. else//添加
  1084. {
  1085. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  1086. noticeCcpId = id;
  1087. if (id == 0)
  1088. {
  1089. RollbackTran();
  1090. return result = new Result() { Code = -2, Msg = "添加失败" };
  1091. }
  1092. }
  1093. 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
  1094. {
  1095. CId = dto.Currency,
  1096. ServiceQuotedPrice = c.PayMoney,
  1097. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  1098. SelectCheck = string.Join(',', dto.SelectCheck)
  1099. }).ExecuteCommandAsync();
  1100. if (CarTouristGuideCTable == 0)
  1101. {
  1102. RollbackTran();
  1103. return result = new Result() { Code = -2, Msg = "修改失败" };
  1104. }
  1105. var data = new { ccpId = noticeCcpId, sign = noticeSign };
  1106. result = new Result() { Code = 0, Msg = "保存成功", Data = data };
  1107. CommitTran();
  1108. }
  1109. catch (Exception ex)
  1110. {
  1111. RollbackTran();
  1112. return result = new Result() { Code = -2, Msg = $"接口异常!({ex.Message})"};
  1113. }
  1114. return result;
  1115. }
  1116. /// <summary>
  1117. /// 超支费用
  1118. /// 1增、2改、3删
  1119. /// </summary>
  1120. /// <param name="dto"></param>
  1121. /// <returns></returns>
  1122. private async Task<Result> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1123. {
  1124. Result rt = new Result();
  1125. #region 验证
  1126. #endregion
  1127. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1128. _entity.DiId = dto.diId;
  1129. _entity.PriceName = dto.priceName;
  1130. _entity.Price = dto.price;
  1131. _entity.PriceCurrency = dto.currency;
  1132. _entity.PriceType = dto.priceType;
  1133. _entity.Coefficient = dto.coefficient;
  1134. _entity.PriceDetailType = dto.priceDetailType;
  1135. _entity.FilePath = dto.filePath;
  1136. _entity.Remark = dto.remark;
  1137. _entity.PriceCount = dto.PriceCount;
  1138. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  1139. _entity.PriceSum = dto.price * dto.PriceCount;
  1140. _daiRep.BeginTran();
  1141. if (dto.editType == 1)
  1142. {
  1143. _entity.CreateUserId = dto.createUser;
  1144. _entity.CreateTime = DateTime.Now;
  1145. _entity.IsDel = 0;
  1146. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1147. if (returnId > 0)
  1148. {
  1149. dto.Id = returnId;
  1150. }
  1151. }
  1152. else if (dto.editType == 2)
  1153. {
  1154. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1155. {
  1156. PriceName = dto.priceName,
  1157. Price = dto.price,
  1158. PriceCurrency = dto.currency,
  1159. PriceType = dto.priceType,
  1160. PriceDetailType = dto.priceDetailType,
  1161. Coefficient = dto.coefficient,
  1162. FilePath = dto.filePath,
  1163. Remark = dto.remark,
  1164. PriceCount = dto.PriceCount,
  1165. PriceDt = _entity.PriceDt,
  1166. PriceSum = _entity.PriceSum
  1167. });
  1168. if (!res)
  1169. {
  1170. _daiRep.RollbackTran();
  1171. //Ok(JsonView(false, "2操作失败!"))
  1172. rt.Msg = "2操作失败!";
  1173. return rt;
  1174. }
  1175. }
  1176. else if (dto.editType == 3)
  1177. {
  1178. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1179. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1180. {
  1181. IsDel = 1,
  1182. DeleteTime = delTime,
  1183. DeleteUserId = dto.createUser
  1184. });
  1185. if (!res)
  1186. {
  1187. _daiRep.RollbackTran();
  1188. rt.Msg = "3操作失败!";
  1189. return rt;
  1190. }
  1191. }
  1192. else
  1193. {
  1194. _daiRep.RollbackTran();
  1195. rt.Msg = "未知的editType";
  1196. return rt;
  1197. }
  1198. if (!extraCost_editCreditCardPayment(dto))
  1199. {
  1200. rt.Msg = "ccp操作失败";
  1201. return rt;
  1202. }
  1203. _daiRep.CommitTran();
  1204. rt.Code = 0;
  1205. rt.Msg = "操作成功";
  1206. return rt;
  1207. }
  1208. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1209. {
  1210. //设置团组汇率
  1211. decimal dcm_dayrate = 1M;
  1212. decimal dcm_rmbPrice = costDto.price;
  1213. int ispay = costDto.payType == 72 ? 1 : 0;
  1214. if (costDto.costSign != 3)
  1215. {
  1216. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1217. if (tr != null)
  1218. {
  1219. if (costDto.currency == 49)
  1220. {
  1221. dcm_dayrate = tr.RateU;
  1222. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1223. }
  1224. else if (costDto.currency == 51)
  1225. {
  1226. dcm_dayrate = tr.RateE;
  1227. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1228. }
  1229. }
  1230. }
  1231. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1232. if (ccp == null)
  1233. {
  1234. ccp = new Grp_CreditCardPayment();
  1235. ccp.PayDId = costDto.payType;// dto
  1236. ccp.ConsumptionPatterns = "";
  1237. ccp.ConsumptionDate = "";
  1238. ccp.CTDId = costDto.payCardId;// dto
  1239. ccp.BankNo = "";
  1240. ccp.CardholderName = "";
  1241. ccp.PayMoney = costDto.price;// dto
  1242. ccp.PaymentCurrency = costDto.currency;// dto
  1243. ccp.CompanyBankNo = "";
  1244. ccp.OtherBankName = "";
  1245. ccp.OtherSideNo = "";
  1246. ccp.OtherSideName = "";
  1247. ccp.Remark = "";
  1248. ccp.CreateUserId = costDto.createUser;
  1249. ccp.CreateTime = DateTime.Now;
  1250. ccp.MFOperator = 0;
  1251. ccp.MFOperatorDate = "";
  1252. ccp.IsAuditDM = 0;
  1253. ccp.AuditDMOperate = 0;
  1254. ccp.AuditDMDate = "";
  1255. ccp.IsAuditMF = 0;
  1256. ccp.AuditMFOperate = 0;
  1257. ccp.AuditMFDate = "";
  1258. ccp.IsAuditGM = 0;
  1259. ccp.AuditGMOperate = 0;
  1260. ccp.AuditGMDate = "";
  1261. ccp.IsPay = ispay; // upd
  1262. ccp.DIId = costDto.diId;// dto
  1263. ccp.CId = costDto.Id;// dto
  1264. ccp.CTable = 1015; //超支费用指向id
  1265. ccp.IsDel = 0;
  1266. ccp.PayPercentage = 100M;
  1267. ccp.PayThenMoney = 0M;
  1268. ccp.PayPercentageOld = 100M;
  1269. ccp.PayThenMoneyOld = 0M;
  1270. ccp.UpdateDate = "";
  1271. ccp.Payee = costDto.payee;// dto
  1272. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1273. ccp.ExceedBudget = 0;
  1274. ccp.DayRate = dcm_dayrate; //upd
  1275. ccp.RMBPrice = dcm_rmbPrice; //upd
  1276. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1277. if (ccpInsertId > 0)
  1278. {
  1279. return true;
  1280. }
  1281. }
  1282. else
  1283. {
  1284. if (costDto.editType == 2)
  1285. {
  1286. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1287. {
  1288. PayDId = costDto.payType,
  1289. CTDId = costDto.payCardId,
  1290. PayMoney = costDto.price,
  1291. PaymentCurrency = costDto.currency,
  1292. IsPay = ispay,
  1293. Payee = costDto.payee,
  1294. OrbitalPrivateTransfer = costDto.costSign,
  1295. DayRate = dcm_dayrate,
  1296. RMBPrice = dcm_rmbPrice
  1297. });
  1298. return res;
  1299. }
  1300. else if (costDto.editType == 3)
  1301. {
  1302. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1303. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1304. {
  1305. IsDel = 1,
  1306. DeleteTime = delTime,
  1307. DeleteUserId = costDto.createUser
  1308. });
  1309. return res2;
  1310. }
  1311. }
  1312. return false;
  1313. }
  1314. }
  1315. }