CarTouristGuideGroundRepository.cs 61 KB

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