CarTouristGuideGroundRepository.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Financial;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.Entities.Resource;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using OASystem.Infrastructure.Tools;
  9. using SqlSugar.Extensions;
  10. using System.Collections.Generic;
  11. namespace OASystem.Infrastructure.Repositories.Groups
  12. {
  13. public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  14. {
  15. private readonly IMapper _mapper;
  16. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper)
  17. : base(sqlSugar)
  18. {
  19. _mapper = mapper;
  20. }
  21. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  22. {
  23. Result result = new Result() { Code = -2, Msg = "未知错误" };
  24. BeginTran();
  25. try
  26. {
  27. int id = 0;
  28. Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  29. if (dto.Status == 1)//添加
  30. {
  31. 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);
  32. if (grp_CarTouristGuideGround != null)
  33. {
  34. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  35. }
  36. else
  37. {
  38. id = await AddAsyncReturnId(grp_CarTouristGuide);
  39. if (id == 0)
  40. {
  41. RollbackTran();
  42. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  43. }
  44. else
  45. {
  46. result = new Result() { Code = 0, Msg = "添加成功!" };
  47. }
  48. }
  49. }
  50. else if (dto.Status == 2)//修改
  51. {
  52. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  53. {
  54. Area = grp_CarTouristGuide.Area,
  55. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  56. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  57. ServiceTel = grp_CarTouristGuide.ServiceTel,
  58. BusName = grp_CarTouristGuide.BusName,
  59. BusDescription = grp_CarTouristGuide.BusDescription,
  60. BusTel = grp_CarTouristGuide.BusTel,
  61. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  62. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  63. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  64. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  65. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  66. Remark = grp_CarTouristGuide.Remark,
  67. });
  68. if (res)
  69. {
  70. id = dto.Id;
  71. result = new Result() { Code = 0, Msg = "修改成功!" };
  72. }
  73. else
  74. {
  75. RollbackTran();
  76. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  77. }
  78. }
  79. if (id!=0)
  80. {
  81. Res_LocalGuideData _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.BusName && a.ContactTel == dto.BusTel && a.IsDel == 0);
  82. if (_LocalGuideDataCar == null)
  83. {
  84. Res_LocalGuideData res_LocalGuideCar = new Res_LocalGuideData();
  85. res_LocalGuideCar.UnitName = dto.BusName;
  86. res_LocalGuideCar.ContactTel = dto.BusTel;
  87. res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  88. int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  89. }
  90. Res_LocalGuideData _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.ServiceCompany && a.ContactTel == dto.ServiceTel && a.IsDel == 0);
  91. if (_LocalGuideDataService == null)
  92. {
  93. Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  94. res_LocalGuideService.UnitName = dto.ServiceCompany;
  95. res_LocalGuideService.ContactTel = dto.ServiceTel;
  96. res_LocalGuideService.Contact = dto.ServiceTel;
  97. res_LocalGuideService.CreateUserId = dto.CreateUserId;
  98. int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  99. }
  100. }
  101. CommitTran();
  102. }
  103. catch (Exception ex)
  104. {
  105. result = new Result() { Code = -2, Msg = "未知错误" };
  106. }
  107. return result;
  108. }
  109. public Result CarTouristGuideGroundContent(CarTouristGuideGroundContentDto dto)
  110. {
  111. Result result = new Result() { Code = -2, Msg = "未知错误" };
  112. try
  113. {
  114. DateTime start = new DateTime();
  115. var dayResult = GetDifferenceDate(dto.Id, out start);
  116. var day = 0;
  117. if (dayResult.Code == 0)
  118. {
  119. day = Convert.ToInt32(dayResult.Data);
  120. }
  121. else
  122. {
  123. return dayResult;
  124. }
  125. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79).ToList();
  126. string DiId = "0";
  127. foreach (var item in grp_GroupsTaskAssignment)
  128. {
  129. DiId += item.DIId + ",";
  130. }
  131. if (DiId != "0")
  132. {
  133. DiId = DiId.Substring(0, DiId.Length - 1);
  134. }
  135. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  136. //团组下拉框
  137. List<Grp_DelegationInfo> _Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  138. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(_Delegations);
  139. //支付方式
  140. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  141. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  142. //币种
  143. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  144. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  145. //列表初始化
  146. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  147. //List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  148. //_TableInitialization= _TableInitialization.OrderBy(a=>a.Name).ToList();
  149. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  150. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  151. foreach (var itemSt in TableInitialization)
  152. {
  153. if (carTouristGuides.Find(x=>x.SId == itemSt.Id) == null)
  154. {
  155. carTouristGuides.Add(new CarTouristGuideGroundReservationsContentView
  156. {
  157. SId = itemSt.Id,
  158. Count = 1,
  159. SidName = itemSt.Name,
  160. });
  161. }
  162. }
  163. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x => x.Key, x => x.ToList());
  164. foreach (var item in groupResult.Keys)
  165. {
  166. while (groupResult[item].Count < day)
  167. {
  168. groupResult[item] = groupResult[item].OrderByDescending(x => x.DatePrice).ToList();
  169. if (groupResult[item][0]?.DatePrice is not null)
  170. {
  171. groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  172. {
  173. DatePrice = groupResult[item][0].DatePrice.ObjToDate().AddDays(1),
  174. SId = item,
  175. Count = 1,
  176. SidName = TableInitialization.Find(x=>x.Id == item)?.Name
  177. });
  178. }
  179. else
  180. {
  181. groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  182. {
  183. DatePrice = start,
  184. SId = item,
  185. Count = 1,
  186. SidName = TableInitialization.Find(x => x.Id == item)?.Name
  187. });
  188. }
  189. }
  190. }
  191. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).ToList();
  192. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  193. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  194. if (_CreditCardPayment != null)
  195. {
  196. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  197. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  198. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  199. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  200. }
  201. var data = new
  202. {
  203. Payment = _Payment,
  204. CurrencyList = _CurrencyList,
  205. Delegations = grp_Delegations,
  206. carTouristGuides = carTouristGuides,
  207. CreditCardPayment = _CreditCardPayment,
  208. };
  209. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  210. }
  211. catch (Exception)
  212. {
  213. return result = new Result() { Code = -2, Msg = "未知错误" };
  214. }
  215. }
  216. public async Task<Result> OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  217. {
  218. Result result = new Result() { Code = -2, Msg = "未知错误" };
  219. try
  220. {
  221. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  222. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  223. DateTime start = new DateTime();
  224. var dayResult = GetDifferenceDate(dto.Id, out start);
  225. var day = 0;
  226. if (dayResult.Code == 0)
  227. {
  228. day = Convert.ToInt32(dayResult.Data);
  229. }
  230. else
  231. {
  232. return dayResult;
  233. }
  234. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x=>x.Key,x=>x.ToList());
  235. foreach (var item in groupResult.Keys)
  236. {
  237. while (groupResult[item].Count < day)
  238. {
  239. groupResult[item] = groupResult[item].OrderByDescending(x=>x.DatePrice).ToList();
  240. if (groupResult[item][0]?.DatePrice is not null)
  241. {
  242. groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  243. {
  244. DatePrice = groupResult[item][0].DatePrice.ObjToDate().AddDays(1),
  245. SId = item,
  246. Count = 1,
  247. });
  248. }
  249. else
  250. {
  251. groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  252. {
  253. DatePrice = start,
  254. SId = item,
  255. Count = 1,
  256. }) ;
  257. }
  258. }
  259. }
  260. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).ToList();
  261. foreach (var item in carTouristGuides)
  262. {
  263. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  264. }
  265. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  266. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  267. if (_CreditCardPayment!=null)
  268. {
  269. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  270. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  271. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  272. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  273. }
  274. var data = new
  275. {
  276. CarTouristsContent = carTouristGuides,
  277. CreditCardPayment = _CreditCardPayment,
  278. };
  279. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  280. }
  281. catch (Exception ex)
  282. {
  283. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  284. }
  285. }
  286. /// <summary>
  287. /// 根据diid查询op费用列表
  288. /// </summary>
  289. /// <param name="dto"></param>
  290. /// <returns></returns>
  291. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  292. {
  293. Result result = new Result() { Code = -2, Msg = "未知错误" };
  294. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  295. {
  296. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  297. }
  298. try
  299. {
  300. #region SQL条件拼接
  301. string sqlWhere = string.Empty;
  302. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  303. string UserId = "";
  304. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  305. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  306. UserId += gta.UId + ",";
  307. if (!string.IsNullOrWhiteSpace(UserId))
  308. {
  309. UserId = UserId.Substring(0, UserId.Length - 1);
  310. }
  311. else
  312. {
  313. UserId = "0";
  314. }
  315. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  316. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  317. {
  318. Regex r = new Regex("And");
  319. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  320. }
  321. #endregion
  322. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  323. int endIndex = startIndex + dto.PageSize - 1;
  324. if (dto.PortType == 1)
  325. {
  326. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid from
  327. Grp_CarTouristGuideGroundReservations t
  328. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  329. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  330. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  331. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  332. foreach (var item in infoViews)
  333. {
  334. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  335. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  336. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  337. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  338. item.ServiceQuotedPrice = item.PayMoney;
  339. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  340. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  341. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  342. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  343. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  344. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  345. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  346. if (s!=null)
  347. {
  348. item.PayStrd = s.Name;
  349. }else item.PayStrd ="未选择";
  350. }
  351. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  352. }
  353. else if (dto.PortType == 2 || dto.PortType == 3)
  354. {
  355. string sql = string.Format(@"Select * From (
  356. 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
  357. from
  358. Grp_CarTouristGuideGroundReservations t
  359. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  360. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  361. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  362. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  363. foreach (var item in grp_CarTourists)
  364. {
  365. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  366. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  367. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  368. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  369. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  370. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  371. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  372. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  373. item.ServiceQuotedPrice = item.PayMoney;
  374. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  375. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  376. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  377. if (s != null)
  378. {
  379. item.PayStrd = s.Name;
  380. }
  381. else item.PayStrd = "未选择";
  382. }
  383. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  384. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  385. Grp_CarTouristGuideGroundReservations t
  386. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  387. left Join Sys_SetData s on s.Id=t.CId {0}
  388. ) temp ", sqlWhere);
  389. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  390. if (dataCount != null)
  391. {
  392. int count = dataCount.Count;
  393. float totalPage = (float)count / dto.PageSize;//总页数
  394. if (totalPage == 0) totalPage = 1;
  395. else totalPage = (int)Math.Ceiling((double)totalPage);
  396. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  397. rst.DataList = grp_CarTourists;
  398. rst.DataCount = count;
  399. rst.CurrPageIndex = dto.PageIndex;
  400. rst.CurrPageSize = dto.PageSize;
  401. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  402. }
  403. }
  404. }
  405. catch (Exception)
  406. {
  407. return result = new Result() { Code = -2, Msg = "未知错误" };
  408. throw;
  409. }
  410. return result;
  411. }
  412. /// <summary>
  413. /// OP费用录入填写详情
  414. /// </summary>
  415. /// <param name="dto"></param>
  416. /// <returns></returns>
  417. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  418. {
  419. Result result = new Result() { Code = -2, Msg = "未知错误" };
  420. try
  421. {
  422. BeginTran();
  423. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = new List<Grp_CarTouristGuideGroundReservationsContent>();
  424. foreach (var item in dto.OPContentList)
  425. {
  426. Grp_CarTouristGuideGroundReservationsContent s = new Grp_CarTouristGuideGroundReservationsContent();
  427. s.Id= item.Id;
  428. s.DiId = dto.DiId;
  429. s.CTGGRId = dto.CTGGRId;
  430. s.SId = item.SId;
  431. s.Price=item.Price;
  432. s.PriceContent = item.priceContent;
  433. s.Currency = dto.Currency;
  434. //s.Remark=item.Remark;
  435. s.CreateUserId = dto.CreateUserId;
  436. carTouristList.Add(s);
  437. }
  438. foreach (var item in carTouristList)
  439. {
  440. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  441. if (QueryData==null)
  442. {
  443. if (item.Price!=0)
  444. {
  445. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  446. if (id == 0)
  447. {
  448. RollbackTran();
  449. return result = new Result() { Code = -2, Msg = "添加失败" };
  450. }
  451. }
  452. }
  453. else
  454. {
  455. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  456. {
  457. Price = item.Price,
  458. PriceContent = item.PriceContent,
  459. Currency = dto.Currency,
  460. Remark = item.Remark,
  461. }).ExecuteCommandAsync();
  462. if (CTable==0)
  463. {
  464. RollbackTran();
  465. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  466. }
  467. }
  468. }
  469. //修改C表数据
  470. List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  471. Grp_CreditCardPayment c=new Grp_CreditCardPayment();
  472. c.PaymentCurrency = dto.Currency;
  473. foreach (var item in carTouristListEnd)
  474. {
  475. c.PayMoney += item.Price;
  476. }
  477. c.PayPercentage = dto.PayPercentage;
  478. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  479. c.CTable = 79;
  480. c.CId = dto.CTGGRId;
  481. c.IsAuditGM = 0;
  482. c.PayDId=dto.PayDId;
  483. c.DIId = dto.DiId;
  484. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  485. c.Payee=dto.Payee;
  486. c.CreateUserId=dto.CreateUserId;
  487. if (c.PayDId == 72)
  488. {
  489. c.IsPay = 1;
  490. }
  491. c.RMBPrice = c.PayMoney;
  492. c.DayRate = 1;
  493. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  494. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  495. if (_TeamRate != null)
  496. {
  497. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  498. if (_SetData != null)
  499. {
  500. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  501. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  502. if (CurrencyRate != null)
  503. {
  504. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  505. c.DayRate = CurrencyRate.Rate;
  506. }
  507. }
  508. }
  509. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  510. if (grp_CreditCard!=null)//修改
  511. {
  512. 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
  513. {
  514. PaymentCurrency = c.PaymentCurrency,
  515. PayMoney = c.PayMoney,
  516. PayPercentage = c.PayPercentage,
  517. CTable = c.CTable,
  518. PayDId = c.PayDId,
  519. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  520. Payee = c.Payee,
  521. IsPay = c.IsPay,
  522. RMBPrice = c.RMBPrice,
  523. DayRate = c.DayRate,
  524. }).ExecuteCommandAsync();
  525. if (CTable == 0)
  526. {
  527. RollbackTran();
  528. return result = new Result() { Code = -2, Msg = "修改失败" };
  529. }
  530. }
  531. else//添加
  532. {
  533. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  534. if (id == 0)
  535. {
  536. RollbackTran();
  537. return result = new Result() { Code = -2, Msg = "添加失败" };
  538. }
  539. }
  540. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  541. {
  542. CId=dto.Currency,
  543. ServiceQuotedPrice=c.PayMoney,
  544. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  545. }).ExecuteCommandAsync();
  546. if (CarTouristGuideCTable == 0)
  547. {
  548. RollbackTran();
  549. return result = new Result() { Code = -2, Msg = "修改失败" };
  550. }
  551. result = new Result() { Code =0, Msg = "保存成功" };
  552. CommitTran();
  553. }
  554. catch (Exception)
  555. {
  556. return result = new Result() { Code = -2, Msg = "未知错误" };
  557. throw;
  558. }
  559. return result;
  560. }
  561. public Result GetDifferenceDate(int id,out DateTime start)
  562. {
  563. Result result = new Domain.Result();
  564. Grp_CarTouristGuideGroundReservations grpCarOp = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == id);
  565. DateTime end = new DateTime();
  566. if (!DateTime.TryParse(grpCarOp?.ServiceStartTime, out start))
  567. {
  568. result.Msg = "服务开始时间不存在!";
  569. result.Code = -1;
  570. result.Data = 0;
  571. return result;
  572. }
  573. if (!DateTime.TryParse(grpCarOp?.ServiceEndTime, out end))
  574. {
  575. result.Msg = "服务结束时间不存在!";
  576. result.Code = -1;
  577. result.Data = 0;
  578. return result;
  579. }
  580. TimeSpan ts = end - start; //计算时间差
  581. int day = ts.Days;
  582. result.Msg = "success!";
  583. result.Code = 0;
  584. result.Data = day;
  585. return result;
  586. }
  587. }
  588. }