CarTouristGuideGroundRepository.cs 58 KB

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