CarTouristGuideGroundRepository.cs 61 KB

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