CarTouristGuideGroundRepository.cs 30 KB

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