CarTouristGuideGroundRepository.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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.Groups;
  8. using OASystem.Domain.Entities.Financial;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.Entities.Resource;
  11. using OASystem.Domain.ViewModels.Groups;
  12. using OASystem.Infrastructure.Repositories.System;
  13. using OASystem.Infrastructure.Tools;
  14. using SqlSugar.Extensions;
  15. using System.Collections.Generic;
  16. using System.Reflection;
  17. namespace OASystem.Infrastructure.Repositories.Groups
  18. {
  19. public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  20. {
  21. private readonly IMapper _mapper;
  22. private readonly CheckBoxsRepository _checkRep;
  23. private readonly SetDataRepository _setDataRep;
  24. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper , CheckBoxsRepository checkRep, SetDataRepository setDataRep)
  25. : base(sqlSugar)
  26. {
  27. _mapper = mapper;
  28. _checkRep = checkRep;
  29. _setDataRep = setDataRep;
  30. }
  31. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  32. {
  33. Result result = new Result() { Code = -2, Msg = "未知错误" };
  34. BeginTran();
  35. try
  36. {
  37. int id = 0;
  38. Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  39. if (dto.Status == 1)//添加
  40. {
  41. 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);
  42. if (grp_CarTouristGuideGround != null)
  43. {
  44. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  45. }
  46. else
  47. {
  48. id = await AddAsyncReturnId(grp_CarTouristGuide);
  49. if (id == 0)
  50. {
  51. RollbackTran();
  52. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  53. }
  54. else
  55. {
  56. result = new Result() { Code = 0, Msg = "添加成功!" };
  57. }
  58. }
  59. }
  60. else if (dto.Status == 2)//修改
  61. {
  62. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  63. {
  64. Area = grp_CarTouristGuide.Area,
  65. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  66. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  67. ServiceTel = grp_CarTouristGuide.ServiceTel,
  68. BusName = grp_CarTouristGuide.BusName,
  69. BusDescription = grp_CarTouristGuide.BusDescription,
  70. BusTel = grp_CarTouristGuide.BusTel,
  71. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  72. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  73. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  74. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  75. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  76. Remark = grp_CarTouristGuide.Remark,
  77. });
  78. if (res)
  79. {
  80. id = dto.Id;
  81. result = new Result() { Code = 0, Msg = "修改成功!" };
  82. }
  83. else
  84. {
  85. RollbackTran();
  86. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  87. }
  88. }
  89. if (id!=0)
  90. {
  91. Res_LocalGuideData _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.BusName && a.ContactTel == dto.BusTel && a.IsDel == 0);
  92. if (_LocalGuideDataCar == null)
  93. {
  94. Res_LocalGuideData res_LocalGuideCar = new Res_LocalGuideData();
  95. res_LocalGuideCar.UnitName = dto.BusName;
  96. res_LocalGuideCar.ContactTel = dto.BusTel;
  97. res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  98. int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  99. }
  100. Res_LocalGuideData _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.ServiceCompany && a.ContactTel == dto.ServiceTel && a.IsDel == 0);
  101. if (_LocalGuideDataService == null)
  102. {
  103. Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  104. res_LocalGuideService.UnitName = dto.ServiceCompany;
  105. res_LocalGuideService.ContactTel = dto.ServiceTel;
  106. res_LocalGuideService.Contact = dto.ServiceTel;
  107. res_LocalGuideService.CreateUserId = dto.CreateUserId;
  108. int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  109. }
  110. }
  111. CommitTran();
  112. }
  113. catch (Exception ex)
  114. {
  115. result = new Result() { Code = -2, Msg = "未知错误" };
  116. }
  117. return result;
  118. }
  119. public Result CarTouristGuideGroundContent(CarTouristGuideGroundContentDto dto)
  120. {
  121. Result result = new Result() { Code = -2, Msg = "未知错误" };
  122. try
  123. {
  124. DateTime start = new DateTime();
  125. DateTime end = new DateTime();
  126. Grp_CarTouristGuideGroundReservations grpCarOp = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.Id);
  127. if (!DateTime.TryParse(grpCarOp?.ServiceStartTime, out start))
  128. {
  129. result.Msg = "服务开始时间不存在!";
  130. result.Code = -1;
  131. return result;
  132. }
  133. if (!DateTime.TryParse(grpCarOp?.ServiceEndTime, out end))
  134. {
  135. result.Msg = "服务结束时间不存在!";
  136. result.Code = -1;
  137. return result;
  138. }
  139. TimeSpan ts = end - start; //计算时间差
  140. int day = ts.Days;
  141. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79).ToList();
  142. string DiId = "0";
  143. foreach (var item in grp_GroupsTaskAssignment)
  144. {
  145. DiId += item.DIId + ",";
  146. }
  147. if (DiId != "0")
  148. {
  149. DiId = DiId.Substring(0, DiId.Length - 1);
  150. }
  151. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  152. //团组下拉框
  153. List<Grp_DelegationInfo> _Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  154. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(_Delegations);
  155. //支付方式
  156. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  157. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  158. //列表初始化
  159. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  160. List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  161. List<Sys_SetData> ssd = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 78).ToList();
  162. List<SetDataInfoView> ssdv = _mapper.Map<List<Sys_SetData>,List<SetDataInfoView>>(ssd);
  163. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  164. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  165. foreach (var itemSt in TableInitialization)
  166. {
  167. var findResult = carTouristGuides.Find(x => x.SId == itemSt.Id);
  168. if (findResult == null)
  169. {
  170. carTouristGuides.Add(new CarTouristGuideGroundReservationsContentView
  171. {
  172. SId = itemSt.Id,
  173. Count = 1,
  174. SidName = itemSt.Name,
  175. });
  176. }
  177. }
  178. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x => x.Key, x => x.ToList());
  179. foreach (var item in groupResult.Keys)
  180. {
  181. #region 倒推初始化逻辑
  182. //while (groupResult[item].Count <= day)
  183. //{
  184. // groupResult[item] = groupResult[item].OrderByDescending(x => x.DatePrice).ToList();
  185. // if (groupResult[item][0]?.DatePrice is not null)
  186. // {
  187. // groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  188. // {
  189. // DatePrice = groupResult[item][0].DatePrice.ObjToDate().AddDays(1),
  190. // SId = item,
  191. // Count = 1,
  192. // });
  193. // }
  194. // else
  195. // {
  196. // groupResult[item][0].DatePrice = start;
  197. // }
  198. //}
  199. #endregion
  200. var startForTime = start;
  201. var dayResult = new List<CarTouristGuideGroundReservationsContentView>();
  202. for (var i = 0; i <= day; i++)
  203. {
  204. dayResult.Add(new CarTouristGuideGroundReservationsContentView
  205. {
  206. Count = 1,
  207. DatePrice = startForTime,
  208. SId = item,
  209. });
  210. startForTime = startForTime.AddDays(1);
  211. }
  212. if (groupResult[item].Count != day)
  213. {
  214. for (var m = 0; m< groupResult[item].Count; m++)
  215. {
  216. for (var m1 = 0; m1 < dayResult.Count; m1++)
  217. {
  218. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  219. {
  220. dayResult[m1] = groupResult[item][m];
  221. }
  222. }
  223. }
  224. }
  225. else
  226. {
  227. groupResult[item] = groupResult[item].OrderBy(x => x.DatePrice).ToList();
  228. if (groupResult[item][0].DatePrice == dayResult[0].DatePrice && groupResult[item][day - 1].DatePrice == dayResult[day - 1].DatePrice)
  229. {
  230. dayResult = groupResult[item];
  231. }
  232. else
  233. {
  234. for (var m = 0; m < groupResult[item].Count; m++)
  235. {
  236. for (var m1 = 0; m1 < dayResult.Count; m1++)
  237. {
  238. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  239. {
  240. dayResult[m1] = groupResult[item][m];
  241. }
  242. }
  243. }
  244. }
  245. }
  246. groupResult[item] = dayResult;
  247. }
  248. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).OrderBy(x => x.SId).ThenBy(x => x.DatePrice).ToList();
  249. foreach (var item in carTouristGuides.Where(x => string.IsNullOrWhiteSpace(x.SidName)).ToList())
  250. {
  251. item.SidName = TableInitialization.Find(x => x.Id == item.SId)?.Name;
  252. }
  253. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  254. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  255. if (_CreditCardPayment != null)
  256. {
  257. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  258. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  259. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  260. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  261. }
  262. Dictionary<string, string> soureDic = new Dictionary<string, string>()
  263. {
  264. {"车费", "VF"},
  265. {"导游费", "T/G S"},
  266. {"客户午餐费用" , "L"},
  267. {"导游景点费" , "T/G EF"},
  268. {"导游小费" , "T/G T"},
  269. // --
  270. {"司机小费", "DRV T"},
  271. {"司机餐补", "C/F M"},
  272. {"车超时费", "C/F OF"},
  273. {"导游餐补", "T/G M"},
  274. {"导游房补", "T/G A"},
  275. {"导游交通", "T/G TF"},
  276. {"客户早餐费用", "B"},
  277. {"客户晚餐费用", "D"},
  278. {"景点门票费", "EF"},
  279. {"饮料/零食/水果", "B/R/F"},
  280. {"翻译费", "I/F"},
  281. };
  282. var checkedItem = new List<string>();
  283. var checkedItemId = new List<int>();
  284. if (string.IsNullOrWhiteSpace(grpCarOp.SelectCheck))
  285. {
  286. //获取成本选中
  287. var checkTopArr = _checkRep.GetCheckBoxsByDiid(grpCarOp.DiId);
  288. if (true)
  289. {
  290. var FindTop = checkTopArr.Find(x => x.CbType == "Top");
  291. if (FindTop != null)
  292. {
  293. var selectName = FindTop.CbValues.Split(',').ToList<string>();
  294. foreach (var soureKey in soureDic.Keys)
  295. {
  296. var find = selectName.Find(x => x == soureDic[soureKey]);
  297. if (find == null)
  298. {
  299. var Lindex = carTouristGuides.FindIndex(x => x.SidName == soureKey);
  300. //carTouristGuides.RemoveRange(Lindex, day + 1);
  301. }
  302. else
  303. {
  304. checkedItem.Add(soureKey);
  305. checkedItemId.Add(_TableInitialization.Find(x=>x.Name == soureKey)!.Id);
  306. }
  307. }
  308. }
  309. else
  310. {
  311. checkedItem = new List<string>() { "车费", "导游费", "客户午餐费用", "导游景点费", "导游小费", "接送机费", "其他费用", "司机工资", "司机小费", "司机餐补", "车超时费", "导游餐补", "导游房补", "导游交通", "客户早餐费用", "客户晚餐费用", "景点门票费", "饮料/零食/水果", "住补费用", "翻译费" };
  312. checkedItemId.AddRange(_TableInitialization.Select(x => x.Id).ToList());
  313. }
  314. }
  315. }
  316. else
  317. {
  318. checkedItem = grpCarOp.SelectCheck.Split(",").ToList<string>();
  319. int number = 0;
  320. foreach (var item in checkedItem)
  321. {
  322. if (!int.TryParse(item,out number))
  323. {
  324. checkedItemId.Add(_TableInitialization.Find(x => x.Name == item)!.Id);
  325. }
  326. else
  327. {
  328. checkedItemId.Add(number);
  329. }
  330. }
  331. }
  332. if(dto.PortType == 1)
  333. {
  334. var data = new
  335. {
  336. Payment = _Payment,
  337. Delegations = grp_Delegations,
  338. carTouristGuides = carTouristGuides,
  339. CreditCardPayment = _CreditCardPayment,
  340. start,
  341. end,
  342. ssdv,
  343. checkedItem
  344. };
  345. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  346. } else if(dto.PortType == 2)
  347. {
  348. var data = new
  349. {
  350. Payment = _Payment,
  351. TableInitialization = _TableInitialization,
  352. carTouristGuides = carTouristGuides,
  353. CreditCardPayment = _CreditCardPayment,
  354. ssdv,
  355. checkedItemId
  356. };
  357. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  358. }
  359. return result = new Result() { Code = -1, Msg = "请传入有效portType" };
  360. }
  361. catch (Exception ex)
  362. {
  363. return result = new Result() { Code = -2, Msg = "未知错误" };
  364. }
  365. }
  366. /// <summary>
  367. /// web弃用
  368. /// </summary>
  369. /// <param name="dto"></param>
  370. /// <returns></returns>
  371. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  372. {
  373. Result result = new Result() { Code = -2, Msg = "未知错误" };
  374. try
  375. {
  376. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  377. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  378. foreach (var item in carTouristGuides)
  379. {
  380. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  381. }
  382. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  383. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  384. if (_CreditCardPayment!=null)
  385. {
  386. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  387. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  388. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  389. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  390. }
  391. var data = new
  392. {
  393. CarTouristsContent = carTouristGuides,
  394. CreditCardPayment = _CreditCardPayment,
  395. };
  396. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  397. }
  398. catch (Exception ex)
  399. {
  400. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  401. }
  402. }
  403. /// <summary>
  404. /// 根据diid查询op费用列表
  405. /// </summary>
  406. /// <param name="dto"></param>
  407. /// <returns></returns>
  408. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  409. {
  410. Result result = new Result() { Code = -2, Msg = "未知错误" };
  411. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  412. {
  413. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  414. }
  415. try
  416. {
  417. #region SQL条件拼接
  418. string sqlWhere = string.Empty;
  419. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  420. string UserId = "";
  421. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  422. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  423. UserId += gta.UId + ",";
  424. if (!string.IsNullOrWhiteSpace(UserId))
  425. {
  426. UserId = UserId.Substring(0, UserId.Length - 1);
  427. }
  428. else
  429. {
  430. UserId = "0";
  431. }
  432. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  433. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  434. {
  435. Regex r = new Regex("And");
  436. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  437. }
  438. #endregion
  439. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  440. int endIndex = startIndex + dto.PageSize - 1;
  441. if (dto.PortType == 1)
  442. {
  443. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid from
  444. Grp_CarTouristGuideGroundReservations t
  445. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  446. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  447. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  448. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  449. foreach (var item in infoViews)
  450. {
  451. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  452. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  453. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  454. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  455. item.ServiceQuotedPrice = item.PayMoney;
  456. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  457. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  458. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  459. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  460. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  461. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  462. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  463. if (s!=null)
  464. {
  465. item.PayStrd = s.Name;
  466. }else item.PayStrd ="未选择";
  467. }
  468. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  469. }
  470. else if (dto.PortType == 2 || dto.PortType == 3)
  471. {
  472. string sql = string.Format(@"Select * From (
  473. Select row_number() over (order by c.IsAuditGM,c.PayPercentage desc) as RowNumber,t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayDid,c.PayMoney
  474. from
  475. Grp_CarTouristGuideGroundReservations t
  476. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  477. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  478. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  479. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  480. foreach (var item in grp_CarTourists)
  481. {
  482. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  483. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  484. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  485. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  486. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  487. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  488. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  489. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  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);
  493. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  494. if (s != null)
  495. {
  496. item.PayStrd = s.Name;
  497. }
  498. else item.PayStrd = "未选择";
  499. }
  500. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  501. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  502. Grp_CarTouristGuideGroundReservations t
  503. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  504. left Join Sys_SetData s on s.Id=t.CId {0}
  505. ) temp ", sqlWhere);
  506. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  507. if (dataCount != null)
  508. {
  509. int count = dataCount.Count;
  510. float totalPage = (float)count / dto.PageSize;//总页数
  511. if (totalPage == 0) totalPage = 1;
  512. else totalPage = (int)Math.Ceiling((double)totalPage);
  513. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  514. rst.DataList = grp_CarTourists;
  515. rst.DataCount = count;
  516. rst.CurrPageIndex = dto.PageIndex;
  517. rst.CurrPageSize = dto.PageSize;
  518. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  519. }
  520. }
  521. }
  522. catch (Exception)
  523. {
  524. return result = new Result() { Code = -2, Msg = "未知错误" };
  525. }
  526. return result;
  527. }
  528. /// <summary>
  529. /// OP费用录入填写详情
  530. /// </summary>
  531. /// <param name="dto"></param>
  532. /// <returns></returns>
  533. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  534. {
  535. Result result = new Result() { Code = -2, Msg = "未知错误" };
  536. try
  537. {
  538. BeginTran();
  539. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  540. {
  541. Id = item.Id,
  542. DiId = dto.DiId,
  543. CTGGRId = dto.CTGGRId,
  544. SId = item.SId,
  545. Price = item.Price,
  546. PriceContent = item.priceContent,
  547. Currency = dto.Currency,
  548. CreateUserId = dto.CreateUserId,
  549. Units = item.Units,
  550. DatePrice = item.DatePrice,
  551. Count = item.Count,
  552. }).ToList();
  553. if (carTouristList.Count > 0)
  554. {
  555. //#region load
  556. ////车超时费
  557. ////餐费和三公经费那个表做完匹配后也放进超支表里
  558. //DataTable tb = new DataTable();
  559. //tb.Columns.Add("日期", typeof(DateTime));
  560. //tb.Columns.Add("费用", typeof(decimal));
  561. //tb.Columns.Add("币种", typeof(string));
  562. //var addsTourClientList = new List<Grp_TourClientList>();
  563. //var carExtraList = carTouristList.Where(x => x.SId == 982).ToList();
  564. //var mealPriceList = carTouristList.Where(x => x.SId == 93 || x.SId == 988 || x.SId == 989).GroupBy(x => x.DatePrice).ToList();
  565. //mealPriceList.ForEach(x =>
  566. //{
  567. // var row = tb.NewRow();
  568. // row["日期"] = x.Key;
  569. // row["费用"] = x.Sum(x => x.Price * x.Count);
  570. // row["币种"] = x.FirstOrDefault()?.Currency;
  571. // tb.Rows.Add(row);
  572. //});
  573. ////限制只能选择地区
  574. ////三公费用
  575. //var cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  576. // !string.IsNullOrEmpty(x.City) && x.City.Contains("")
  577. //).First();
  578. ////超支费用表(数据添加) Fin_GroupExtraCost
  579. //List<Fin_GroupExtraCost> groupExtraCostsArr = new List<Fin_GroupExtraCost>();
  580. ////币种
  581. //var currOpResult = await _setDataRep.PostCurrencyByDiid(carTouristList[0].DiId, 79, carTouristList[0].Currency);
  582. //var currOp = currOpResult.Code == 0 ? (currOpResult.Data as CurrencyInfo) == null ? 1 : (currOpResult.Data as CurrencyInfo).Rate : 1;
  583. //var cityCurrResult = await _setDataRep.PostCurrencyByDiid(carTouristList[0].DiId, 79, cityPrice.Currency);
  584. //var cityCurr = cityCurrResult.Code == 0 ? (cityCurrResult.Data as CurrencyInfo) == null ? 1 : (cityCurrResult.Data as CurrencyInfo).Rate : 1;
  585. //var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId);
  586. //if (di == null)
  587. //{
  588. // result.Code = -1;
  589. // result.Msg = "无该团组信息!";
  590. // return result;
  591. //}
  592. //if (carExtraList.Count > 0)
  593. //{
  594. // foreach (var item in carExtraList)
  595. // {
  596. // groupExtraCostsArr.Add(new Fin_GroupExtraCost
  597. // {
  598. // Price = item.Price * item.Count,
  599. // CreateTime = DateTime.Now,
  600. // CreateUserId = dto.CreateUserId,
  601. // Coefficient = 1,
  602. // DiId = dto.DiId,
  603. // PriceCurrency = item.Currency,
  604. // PriceName = di.TeamName + "车超时费(地接导入)",
  605. // PriceType = 1050,
  606. // PriceDt = item.DatePrice.ObjToDate(),
  607. // });
  608. // }
  609. //}
  610. //if (tb.Rows.Count > 0)
  611. //{
  612. // foreach (DataRow item in tb.Rows)
  613. // {
  614. // decimal foodCost = 1;
  615. // if (!decimal.TryParse(cityPrice.FoodCost, out foodCost))
  616. // {
  617. // //三公费用 ( 城市餐费用有问题! )
  618. // }
  619. // var price = Convert.ToDecimal(item["费用"]);
  620. // if (item["币种"].ToString() != cityPrice.Currency.ToString()) //币种不相同
  621. // {
  622. // //全部转换为rmb;
  623. // item["费用"] = price * currOp;
  624. // cityPrice.FoodCost = (foodCost * cityCurr).ToString("F2");
  625. // item["币种"] = "836";
  626. // cityPrice.Currency = 836;
  627. // }
  628. // if (price > foodCost)
  629. // {
  630. // //每天费用大于三公费用
  631. // groupExtraCostsArr.Add(new Fin_GroupExtraCost
  632. // {
  633. // Price = price - foodCost,
  634. // CreateTime = DateTime.Now,
  635. // CreateUserId = dto.CreateUserId,
  636. // Coefficient = 1,
  637. // DiId = dto.DiId,
  638. // PriceCurrency = cityPrice.Currency,
  639. // PriceName = di.TeamName + "餐费(地接导入)",
  640. // PriceType = 1049,
  641. // PriceDt = Convert.ToDateTime(item["日期"]),
  642. // });
  643. // }
  644. // }
  645. //}
  646. //if (groupExtraCostsArr.Count > 0)
  647. //{
  648. // _sqlSugar.Insertable<Fin_GroupExtraCost>(groupExtraCostsArr);
  649. //}
  650. //#endregion
  651. }
  652. foreach (var item in carTouristList)
  653. {
  654. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  655. if (QueryData==null)
  656. {
  657. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  658. if (id == 0)
  659. {
  660. RollbackTran();
  661. return result = new Result() { Code = -2, Msg = "添加失败" };
  662. }
  663. }
  664. else
  665. {
  666. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  667. {
  668. Price = item.Price,
  669. PriceContent = item.PriceContent,
  670. Currency = dto.Currency,
  671. Remark = item.Remark,
  672. DatePrice = item.DatePrice,
  673. Count = item.Count,
  674. Units = item.Units,
  675. }).ExecuteCommandAsync();
  676. if (CTable==0)
  677. {
  678. RollbackTran();
  679. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  680. }
  681. }
  682. }
  683. //修改C表数据
  684. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  685. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  686. c.PaymentCurrency = dto.Currency;
  687. c.PayMoney = carTouristList.Sum(x => x.Price);
  688. c.PayPercentage = dto.PayPercentage;
  689. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  690. c.CTable = 79;
  691. c.CId = dto.CTGGRId;
  692. c.IsAuditGM = 0;
  693. c.PayDId=dto.PayDId;
  694. c.DIId = dto.DiId;
  695. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  696. c.Payee=dto.Payee;
  697. c.CreateUserId=dto.CreateUserId;
  698. if (c.PayDId == 72)
  699. {
  700. c.IsPay = 1;
  701. }
  702. c.RMBPrice = c.PayMoney;
  703. c.DayRate = 1;
  704. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  705. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  706. if (_TeamRate != null)
  707. {
  708. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  709. if (_SetData != null)
  710. {
  711. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  712. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  713. if (CurrencyRate != null)
  714. {
  715. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  716. c.DayRate = CurrencyRate.Rate;
  717. }
  718. }
  719. }
  720. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  721. if (grp_CreditCard!=null)//修改
  722. {
  723. 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
  724. {
  725. PaymentCurrency = c.PaymentCurrency,
  726. PayMoney = c.PayMoney,
  727. PayPercentage = c.PayPercentage,
  728. CTable = c.CTable,
  729. PayDId = c.PayDId,
  730. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  731. Payee = c.Payee,
  732. IsPay = c.IsPay,
  733. RMBPrice = c.RMBPrice,
  734. DayRate = c.DayRate,
  735. }).ExecuteCommandAsync();
  736. if (CTable == 0)
  737. {
  738. RollbackTran();
  739. return result = new Result() { Code = -2, Msg = "修改失败" };
  740. }
  741. }
  742. else//添加
  743. {
  744. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  745. if (id == 0)
  746. {
  747. RollbackTran();
  748. return result = new Result() { Code = -2, Msg = "添加失败" };
  749. }
  750. }
  751. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  752. {
  753. CId = dto.Currency,
  754. ServiceQuotedPrice = c.PayMoney,
  755. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  756. SelectCheck = string.Join(',', dto.SelectCheck)
  757. }).ExecuteCommandAsync();
  758. if (CarTouristGuideCTable == 0)
  759. {
  760. RollbackTran();
  761. return result = new Result() { Code = -2, Msg = "修改失败" };
  762. }
  763. result = new Result() { Code =0, Msg = "保存成功" };
  764. CommitTran();
  765. }
  766. catch (Exception ex)
  767. {
  768. RollbackTran();
  769. return result = new Result() { Code = -2, Msg = "未知错误" };
  770. }
  771. return result;
  772. }
  773. }
  774. }