CarTouristGuideGroundRepository.cs 30 KB

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