CarTouristGuideGroundRepository.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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 (checkTopArr.Count > 0)
  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. }
  306. }
  307. else
  308. {
  309. checkedItem = grpCarOp.SelectCheck.Split(",").ToList<string>();
  310. int number = 0;
  311. foreach (var item in checkedItem)
  312. {
  313. if (!int.TryParse(item,out number))
  314. {
  315. checkedItemId.Add(_TableInitialization.Find(x => x.Name == item)!.Id);
  316. }
  317. else
  318. {
  319. checkedItemId.Add(number);
  320. }
  321. }
  322. }
  323. if(dto.PortType == 1)
  324. {
  325. var data = new
  326. {
  327. Payment = _Payment,
  328. Delegations = grp_Delegations,
  329. carTouristGuides = carTouristGuides,
  330. CreditCardPayment = _CreditCardPayment,
  331. start,
  332. end,
  333. ssdv,
  334. checkedItem
  335. };
  336. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  337. } else if(dto.PortType == 2)
  338. {
  339. var data = new
  340. {
  341. Payment = _Payment,
  342. TableInitialization = _TableInitialization,
  343. carTouristGuides = carTouristGuides,
  344. CreditCardPayment = _CreditCardPayment,
  345. ssdv,
  346. checkedItemId
  347. };
  348. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  349. }
  350. return result = new Result() { Code = -1, Msg = "请传入有效portType" };
  351. }
  352. catch (Exception ex)
  353. {
  354. return result = new Result() { Code = -2, Msg = "未知错误" };
  355. }
  356. }
  357. /// <summary>
  358. /// web弃用
  359. /// </summary>
  360. /// <param name="dto"></param>
  361. /// <returns></returns>
  362. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  363. {
  364. Result result = new Result() { Code = -2, Msg = "未知错误" };
  365. try
  366. {
  367. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  368. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  369. foreach (var item in carTouristGuides)
  370. {
  371. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  372. }
  373. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  374. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  375. if (_CreditCardPayment!=null)
  376. {
  377. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  378. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  379. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  380. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  381. }
  382. var data = new
  383. {
  384. CarTouristsContent = carTouristGuides,
  385. CreditCardPayment = _CreditCardPayment,
  386. };
  387. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  388. }
  389. catch (Exception ex)
  390. {
  391. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  392. }
  393. }
  394. /// <summary>
  395. /// 根据diid查询op费用列表
  396. /// </summary>
  397. /// <param name="dto"></param>
  398. /// <returns></returns>
  399. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  400. {
  401. Result result = new Result() { Code = -2, Msg = "未知错误" };
  402. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  403. {
  404. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  405. }
  406. try
  407. {
  408. #region SQL条件拼接
  409. string sqlWhere = string.Empty;
  410. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  411. string UserId = "";
  412. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  413. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  414. UserId += gta.UId + ",";
  415. if (!string.IsNullOrWhiteSpace(UserId))
  416. {
  417. UserId = UserId.Substring(0, UserId.Length - 1);
  418. }
  419. else
  420. {
  421. UserId = "0";
  422. }
  423. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  424. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  425. {
  426. Regex r = new Regex("And");
  427. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  428. }
  429. #endregion
  430. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  431. int endIndex = startIndex + dto.PageSize - 1;
  432. if (dto.PortType == 1)
  433. {
  434. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid from
  435. Grp_CarTouristGuideGroundReservations t
  436. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  437. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  438. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  439. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  440. foreach (var item in infoViews)
  441. {
  442. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  443. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  444. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  445. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  446. item.ServiceQuotedPrice = item.PayMoney;
  447. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  448. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  449. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  450. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  451. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  452. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  453. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  454. if (s!=null)
  455. {
  456. item.PayStrd = s.Name;
  457. }else item.PayStrd ="未选择";
  458. }
  459. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  460. }
  461. else if (dto.PortType == 2 || dto.PortType == 3)
  462. {
  463. string sql = string.Format(@"Select * From (
  464. 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
  465. from
  466. Grp_CarTouristGuideGroundReservations t
  467. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  468. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  469. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  470. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  471. foreach (var item in grp_CarTourists)
  472. {
  473. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  474. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  475. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  476. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  477. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  478. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  479. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  480. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  481. item.ServiceQuotedPrice = item.PayMoney;
  482. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  483. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  484. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  485. if (s != null)
  486. {
  487. item.PayStrd = s.Name;
  488. }
  489. else item.PayStrd = "未选择";
  490. }
  491. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  492. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  493. Grp_CarTouristGuideGroundReservations t
  494. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  495. left Join Sys_SetData s on s.Id=t.CId {0}
  496. ) temp ", sqlWhere);
  497. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  498. if (dataCount != null)
  499. {
  500. int count = dataCount.Count;
  501. float totalPage = (float)count / dto.PageSize;//总页数
  502. if (totalPage == 0) totalPage = 1;
  503. else totalPage = (int)Math.Ceiling((double)totalPage);
  504. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  505. rst.DataList = grp_CarTourists;
  506. rst.DataCount = count;
  507. rst.CurrPageIndex = dto.PageIndex;
  508. rst.CurrPageSize = dto.PageSize;
  509. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  510. }
  511. }
  512. }
  513. catch (Exception)
  514. {
  515. return result = new Result() { Code = -2, Msg = "未知错误" };
  516. }
  517. return result;
  518. }
  519. /// <summary>
  520. /// OP费用录入填写详情
  521. /// </summary>
  522. /// <param name="dto"></param>
  523. /// <returns></returns>
  524. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  525. {
  526. Result result = new Result() { Code = -2, Msg = "未知错误" };
  527. try
  528. {
  529. BeginTran();
  530. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  531. {
  532. Id = item.Id,
  533. DiId = dto.DiId,
  534. CTGGRId = dto.CTGGRId,
  535. SId = item.SId,
  536. Price = item.Price,
  537. PriceContent = item.priceContent,
  538. Currency = dto.Currency,
  539. CreateUserId = dto.CreateUserId,
  540. Units = item.Units,
  541. DatePrice = item.DatePrice,
  542. Count = item.Count,
  543. }).ToList();
  544. //车超时费
  545. //餐费和三公经费那个表做完匹配后也放进超支表里
  546. //DataTable tb = new DataTable();
  547. //tb.Columns.Add("日期",typeof(DateTime));
  548. //tb.Columns.Add("费用", typeof(decimal));
  549. //var addsTourClientList = new List<Grp_TourClientList>();
  550. //var carExtraList = carTouristList.Where(x => x.SId == 982).ToList();
  551. //var mealPriceList = carTouristList.Where(x => x.SId == 93 || x.SId == 988 || x.SId == 989).GroupBy(x => x.DatePrice).ToList();
  552. //mealPriceList.ForEach(x =>
  553. //{
  554. // var row = tb.NewRow();
  555. // row["日期"] = x.Key;
  556. // row["费用"] = x.Sum(x => x.Price);
  557. //});
  558. //三公费用
  559. //var cityPrice = carTouristList.Where(x=>)
  560. foreach (var item in carTouristList)
  561. {
  562. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  563. if (QueryData==null)
  564. {
  565. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  566. if (id == 0)
  567. {
  568. RollbackTran();
  569. return result = new Result() { Code = -2, Msg = "添加失败" };
  570. }
  571. }
  572. else
  573. {
  574. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  575. {
  576. Price = item.Price,
  577. PriceContent = item.PriceContent,
  578. Currency = dto.Currency,
  579. Remark = item.Remark,
  580. DatePrice = item.DatePrice,
  581. Count = item.Count,
  582. Units = item.Units,
  583. }).ExecuteCommandAsync();
  584. if (CTable==0)
  585. {
  586. RollbackTran();
  587. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  588. }
  589. }
  590. }
  591. //修改C表数据
  592. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  593. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  594. c.PaymentCurrency = dto.Currency;
  595. c.PayMoney = carTouristList.Sum(x => x.Price);
  596. c.PayPercentage = dto.PayPercentage;
  597. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  598. c.CTable = 79;
  599. c.CId = dto.CTGGRId;
  600. c.IsAuditGM = 0;
  601. c.PayDId=dto.PayDId;
  602. c.DIId = dto.DiId;
  603. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  604. c.Payee=dto.Payee;
  605. c.CreateUserId=dto.CreateUserId;
  606. if (c.PayDId == 72)
  607. {
  608. c.IsPay = 1;
  609. }
  610. c.RMBPrice = c.PayMoney;
  611. c.DayRate = 1;
  612. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  613. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  614. if (_TeamRate != null)
  615. {
  616. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  617. if (_SetData != null)
  618. {
  619. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  620. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  621. if (CurrencyRate != null)
  622. {
  623. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  624. c.DayRate = CurrencyRate.Rate;
  625. }
  626. }
  627. }
  628. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  629. if (grp_CreditCard!=null)//修改
  630. {
  631. 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
  632. {
  633. PaymentCurrency = c.PaymentCurrency,
  634. PayMoney = c.PayMoney,
  635. PayPercentage = c.PayPercentage,
  636. CTable = c.CTable,
  637. PayDId = c.PayDId,
  638. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  639. Payee = c.Payee,
  640. IsPay = c.IsPay,
  641. RMBPrice = c.RMBPrice,
  642. DayRate = c.DayRate,
  643. }).ExecuteCommandAsync();
  644. if (CTable == 0)
  645. {
  646. RollbackTran();
  647. return result = new Result() { Code = -2, Msg = "修改失败" };
  648. }
  649. }
  650. else//添加
  651. {
  652. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  653. if (id == 0)
  654. {
  655. RollbackTran();
  656. return result = new Result() { Code = -2, Msg = "添加失败" };
  657. }
  658. }
  659. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  660. {
  661. CId = dto.Currency,
  662. ServiceQuotedPrice = c.PayMoney,
  663. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  664. SelectCheck = string.Join(',', dto.SelectCheck)
  665. }).ExecuteCommandAsync();
  666. if (CarTouristGuideCTable == 0)
  667. {
  668. RollbackTran();
  669. return result = new Result() { Code = -2, Msg = "修改失败" };
  670. }
  671. result = new Result() { Code =0, Msg = "保存成功" };
  672. CommitTran();
  673. }
  674. catch (Exception ex)
  675. {
  676. RollbackTran();
  677. return result = new Result() { Code = -2, Msg = "未知错误" };
  678. }
  679. return result;
  680. }
  681. }
  682. }