CarTouristGuideGroundRepository.cs 38 KB

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