CarTouristGuideGroundRepository.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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<Sys_SetData> ssd = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 78).ToList();
  155. List<SetDataInfoView> ssdv = _mapper.Map<List<Sys_SetData>,List<SetDataInfoView>>(ssd);
  156. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  157. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  158. foreach (var itemSt in TableInitialization)
  159. {
  160. var findResult = carTouristGuides.Find(x => x.SId == itemSt.Id);
  161. if (findResult == null)
  162. {
  163. carTouristGuides.Add(new CarTouristGuideGroundReservationsContentView
  164. {
  165. SId = itemSt.Id,
  166. Count = 1,
  167. SidName = itemSt.Name,
  168. });
  169. }
  170. }
  171. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x => x.Key, x => x.ToList());
  172. foreach (var item in groupResult.Keys)
  173. {
  174. while (groupResult[item].Count <= day)
  175. {
  176. groupResult[item] = groupResult[item].OrderByDescending(x => x.DatePrice).ToList();
  177. if (groupResult[item][0]?.DatePrice is not null)
  178. {
  179. groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  180. {
  181. DatePrice = groupResult[item][0].DatePrice.ObjToDate().AddDays(1),
  182. SId = item,
  183. Count = 1,
  184. });
  185. }
  186. else
  187. {
  188. groupResult[item][0].DatePrice = start;
  189. }
  190. }
  191. }
  192. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).OrderBy(x=>x.SId).ThenBy(x=>x.DatePrice).ToList();
  193. foreach (var item in carTouristGuides.Where(x=>string.IsNullOrWhiteSpace(x.SidName)).ToList())
  194. {
  195. item.SidName = TableInitialization.Find(x => x.Id == item.SId)?.Name;
  196. }
  197. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  198. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  199. if (_CreditCardPayment != null)
  200. {
  201. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  202. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  203. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  204. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  205. }
  206. var data = new
  207. {
  208. Payment = _Payment,
  209. Delegations = grp_Delegations,
  210. carTouristGuides = carTouristGuides,
  211. CreditCardPayment = _CreditCardPayment,
  212. start,
  213. end,
  214. ssdv,
  215. };
  216. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  217. }
  218. catch (Exception ex)
  219. {
  220. return result = new Result() { Code = -2, Msg = "未知错误" };
  221. }
  222. }
  223. /// <summary>
  224. /// web弃用
  225. /// </summary>
  226. /// <param name="dto"></param>
  227. /// <returns></returns>
  228. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  229. {
  230. Result result = new Result() { Code = -2, Msg = "未知错误" };
  231. try
  232. {
  233. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  234. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  235. foreach (var item in carTouristGuides)
  236. {
  237. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  238. }
  239. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  240. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  241. if (_CreditCardPayment!=null)
  242. {
  243. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  244. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  245. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  246. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  247. }
  248. var data = new
  249. {
  250. CarTouristsContent = carTouristGuides,
  251. CreditCardPayment = _CreditCardPayment,
  252. };
  253. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  254. }
  255. catch (Exception ex)
  256. {
  257. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  258. }
  259. }
  260. /// <summary>
  261. /// 根据diid查询op费用列表
  262. /// </summary>
  263. /// <param name="dto"></param>
  264. /// <returns></returns>
  265. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  266. {
  267. Result result = new Result() { Code = -2, Msg = "未知错误" };
  268. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  269. {
  270. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  271. }
  272. try
  273. {
  274. #region SQL条件拼接
  275. string sqlWhere = string.Empty;
  276. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  277. string UserId = "";
  278. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  279. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  280. UserId += gta.UId + ",";
  281. if (!string.IsNullOrWhiteSpace(UserId))
  282. {
  283. UserId = UserId.Substring(0, UserId.Length - 1);
  284. }
  285. else
  286. {
  287. UserId = "0";
  288. }
  289. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  290. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  291. {
  292. Regex r = new Regex("And");
  293. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  294. }
  295. #endregion
  296. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  297. int endIndex = startIndex + dto.PageSize - 1;
  298. if (dto.PortType == 1)
  299. {
  300. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid from
  301. Grp_CarTouristGuideGroundReservations t
  302. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  303. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  304. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  305. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  306. foreach (var item in infoViews)
  307. {
  308. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  309. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  310. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  311. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  312. item.ServiceQuotedPrice = item.PayMoney;
  313. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  314. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  315. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  316. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  317. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  318. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  319. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  320. if (s!=null)
  321. {
  322. item.PayStrd = s.Name;
  323. }else item.PayStrd ="未选择";
  324. }
  325. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  326. }
  327. else if (dto.PortType == 2 || dto.PortType == 3)
  328. {
  329. string sql = string.Format(@"Select * From (
  330. 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
  331. from
  332. Grp_CarTouristGuideGroundReservations t
  333. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  334. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  335. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  336. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  337. foreach (var item in grp_CarTourists)
  338. {
  339. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  340. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  341. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  342. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  343. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  344. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  345. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  346. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  347. item.ServiceQuotedPrice = item.PayMoney;
  348. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  349. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  350. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  351. if (s != null)
  352. {
  353. item.PayStrd = s.Name;
  354. }
  355. else item.PayStrd = "未选择";
  356. }
  357. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  358. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  359. Grp_CarTouristGuideGroundReservations t
  360. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  361. left Join Sys_SetData s on s.Id=t.CId {0}
  362. ) temp ", sqlWhere);
  363. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  364. if (dataCount != null)
  365. {
  366. int count = dataCount.Count;
  367. float totalPage = (float)count / dto.PageSize;//总页数
  368. if (totalPage == 0) totalPage = 1;
  369. else totalPage = (int)Math.Ceiling((double)totalPage);
  370. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  371. rst.DataList = grp_CarTourists;
  372. rst.DataCount = count;
  373. rst.CurrPageIndex = dto.PageIndex;
  374. rst.CurrPageSize = dto.PageSize;
  375. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  376. }
  377. }
  378. }
  379. catch (Exception)
  380. {
  381. return result = new Result() { Code = -2, Msg = "未知错误" };
  382. }
  383. return result;
  384. }
  385. /// <summary>
  386. /// OP费用录入填写详情
  387. /// </summary>
  388. /// <param name="dto"></param>
  389. /// <returns></returns>
  390. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  391. {
  392. Result result = new Result() { Code = -2, Msg = "未知错误" };
  393. try
  394. {
  395. BeginTran();
  396. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  397. {
  398. Id = item.Id,
  399. DiId = dto.DiId,
  400. CTGGRId = dto.CTGGRId,
  401. SId = item.SId,
  402. Price = item.Price,
  403. PriceContent = item.priceContent,
  404. Currency = dto.Currency,
  405. CreateUserId = dto.CreateUserId,
  406. Units = item.Units,
  407. DatePrice = item.DatePrice,
  408. Count = item.Count,
  409. }).ToList();
  410. foreach (var item in carTouristList)
  411. {
  412. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  413. if (QueryData==null)
  414. {
  415. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  416. if (id == 0)
  417. {
  418. RollbackTran();
  419. return result = new Result() { Code = -2, Msg = "添加失败" };
  420. }
  421. }
  422. else
  423. {
  424. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  425. {
  426. Price = item.Price,
  427. PriceContent = item.PriceContent,
  428. Currency = dto.Currency,
  429. Remark = item.Remark,
  430. DatePrice = item.DatePrice,
  431. Count = item.Count,
  432. Units = item.Units,
  433. }).ExecuteCommandAsync();
  434. if (CTable==0)
  435. {
  436. RollbackTran();
  437. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  438. }
  439. }
  440. }
  441. //修改C表数据
  442. List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  443. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  444. c.PaymentCurrency = dto.Currency;
  445. c.PayMoney = carTouristListEnd.Sum(x => x.Price);
  446. c.PayPercentage = dto.PayPercentage;
  447. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  448. c.CTable = 79;
  449. c.CId = dto.CTGGRId;
  450. c.IsAuditGM = 0;
  451. c.PayDId=dto.PayDId;
  452. c.DIId = dto.DiId;
  453. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  454. c.Payee=dto.Payee;
  455. c.CreateUserId=dto.CreateUserId;
  456. if (c.PayDId == 72)
  457. {
  458. c.IsPay = 1;
  459. }
  460. c.RMBPrice = c.PayMoney;
  461. c.DayRate = 1;
  462. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  463. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  464. if (_TeamRate != null)
  465. {
  466. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  467. if (_SetData != null)
  468. {
  469. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  470. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  471. if (CurrencyRate != null)
  472. {
  473. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  474. c.DayRate = CurrencyRate.Rate;
  475. }
  476. }
  477. }
  478. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  479. if (grp_CreditCard!=null)//修改
  480. {
  481. 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
  482. {
  483. PaymentCurrency = c.PaymentCurrency,
  484. PayMoney = c.PayMoney,
  485. PayPercentage = c.PayPercentage,
  486. CTable = c.CTable,
  487. PayDId = c.PayDId,
  488. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  489. Payee = c.Payee,
  490. IsPay = c.IsPay,
  491. RMBPrice = c.RMBPrice,
  492. DayRate = c.DayRate,
  493. }).ExecuteCommandAsync();
  494. if (CTable == 0)
  495. {
  496. RollbackTran();
  497. return result = new Result() { Code = -2, Msg = "修改失败" };
  498. }
  499. }
  500. else//添加
  501. {
  502. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  503. if (id == 0)
  504. {
  505. RollbackTran();
  506. return result = new Result() { Code = -2, Msg = "添加失败" };
  507. }
  508. }
  509. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  510. {
  511. CId = dto.Currency,
  512. ServiceQuotedPrice = c.PayMoney,
  513. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  514. }).ExecuteCommandAsync();
  515. if (CarTouristGuideCTable == 0)
  516. {
  517. RollbackTran();
  518. return result = new Result() { Code = -2, Msg = "修改失败" };
  519. }
  520. result = new Result() { Code =0, Msg = "保存成功" };
  521. CommitTran();
  522. }
  523. catch (Exception ex)
  524. {
  525. return result = new Result() { Code = -2, Msg = "未知错误" };
  526. }
  527. return result;
  528. }
  529. }
  530. }