HotelPriceRepository.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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.ViewModels.Groups;
  7. using OASystem.Infrastructure.Tools;
  8. using SqlSugar;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace OASystem.Infrastructure.Repositories.Groups
  15. {
  16. public class HotelPriceRepository : BaseRepository<Grp_HotelReservations, Grp_HotelReservations>
  17. {
  18. private readonly IMapper _mapper;
  19. public HotelPriceRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  20. base(sqlSugar)
  21. {
  22. this._mapper = mapper;
  23. }
  24. /// <summary>
  25. /// 付款金额计算
  26. /// </summary>
  27. /// <param name="dto"></param>
  28. /// <returns></returns>
  29. public async Task<Result> HotelConversionAmounts(HotelReservationsCNYDto dto)
  30. {
  31. Result result = new Result() { Code = -2, Msg = "未知错误" };
  32. try
  33. {
  34. HotelReservationsView reservationsView=new HotelReservationsView();
  35. if ((dto.CardPriceCurrency == dto.GovernmentRentCurrency || dto.GovernmentRent == 0)
  36. && (dto.CardPriceCurrency == dto.CityTaxCurrency || dto.CityTax== 0))
  37. {
  38. reservationsView.CurrencyId = dto.CardPriceCurrency;
  39. reservationsView.Price=Convert.ToDecimal((dto.CardPrice+dto.GovernmentRent+dto.CityTax).ToString("F2"));
  40. reservationsView.CurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == dto.CardPriceCurrency).Name;
  41. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  42. }
  43. else
  44. {
  45. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  46. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  47. decimal CardPrice = 0.00M;
  48. decimal GovernmentRent = 0.00M;
  49. decimal CityTax = 0.00M;
  50. if (_TeamRate != null)
  51. {
  52. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CardPriceCurrency);
  53. if (_SetData != null)
  54. {
  55. if (_SetData.Name=="CNY")
  56. {
  57. CardPrice = dto.CardPrice;
  58. }
  59. else
  60. {
  61. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  62. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  63. if (CurrencyRate != null) CardPrice = dto.CardPrice * Convert.ToDecimal(CurrencyRate.Rate);
  64. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  65. }
  66. }
  67. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  68. Sys_SetData _SetData1 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.GovernmentRentCurrency);
  69. if (_SetData1 != null)
  70. {
  71. if (_SetData1.Name == "CNY")
  72. {
  73. GovernmentRent = dto.GovernmentRent;
  74. }
  75. else {
  76. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  77. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData1.Name);
  78. if (CurrencyRate != null) GovernmentRent = dto.GovernmentRent * Convert.ToDecimal(CurrencyRate.Rate);
  79. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  80. }
  81. }
  82. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  83. Sys_SetData _SetData2 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CityTaxCurrency);
  84. if (_SetData2 != null)
  85. {
  86. if (_SetData2.Name == "CNY")
  87. {
  88. CityTax = dto.CityTax;
  89. }
  90. else
  91. {
  92. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  93. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData2.Name);
  94. if (CurrencyRate != null) CityTax = dto.CityTax * Convert.ToDecimal(CurrencyRate.Rate);
  95. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  96. }
  97. }
  98. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  99. reservationsView.CurrencyId = 836;
  100. reservationsView.Price = Convert.ToDecimal((CardPrice + GovernmentRent + CityTax).ToString("F2"));
  101. reservationsView.CurrencyName ="CNY";
  102. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  103. }
  104. else
  105. {
  106. return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data= reservationsView };
  107. }
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. return result = new Result() { Code = -2, Msg = "未知错误" };
  113. throw;
  114. }
  115. }
  116. /// <summary>
  117. /// 根据团组id查询酒店数据
  118. /// </summary>
  119. /// <param name="dto"></param>
  120. /// <returns></returns>
  121. public async Task<Result> HotelReservationsByDiId(HotelReservationsByDiIdDto dto)
  122. {
  123. Result result = new Result() { Code = -2, Msg = "未知错误" };
  124. try
  125. {
  126. string UserId = "";
  127. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 76).ToList();
  128. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  129. UserId += gta.UId + ",";
  130. if (!string.IsNullOrWhiteSpace(UserId))
  131. {
  132. UserId = UserId.Substring(0, UserId.Length - 1);
  133. }
  134. else
  135. {
  136. UserId = "0";
  137. }
  138. string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0,UserId);
  139. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  140. int endIndex = startIndex + dto.PageSize - 1;
  141. if (dto.PortType == 1)
  142. {
  143. string sql = string.Format(@"select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  144. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  145. From Grp_HotelReservations h
  146. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  147. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  148. left Join Sys_SetData s1 on h.GTId=s1.Id
  149. left Join Sys_Users u on u.Id=h.CreateUserId {0} order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  150. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  151. foreach (var item in hotelDataList)
  152. {
  153. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  154. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  155. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  156. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  157. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  158. {
  159. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  160. }
  161. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  162. {
  163. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  164. }
  165. }
  166. return result = new Result() { Code = 0, Msg = "查询成功!", Data = hotelDataList };
  167. }
  168. else if (dto.PortType == 2 || dto.PortType == 3)
  169. {
  170. string sql = string.Format(@"Select * From (
  171. Select row_number() over (order by c.IsAuditGM,c.PayPercentage desc) as RowNumber,h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  172. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  173. From Grp_HotelReservations h
  174. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  175. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  176. left Join Sys_SetData s1 on h.GTId=s1.Id
  177. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  178. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  179. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  180. foreach (var item in hotelDataList)
  181. {
  182. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  183. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  184. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  185. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  186. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  187. {
  188. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  189. }
  190. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  191. {
  192. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  193. }
  194. }
  195. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  196. Select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  197. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  198. From Grp_HotelReservations h
  199. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  200. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  201. left Join Sys_SetData s1 on h.GTId=s1.Id
  202. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  203. ) temp", sqlWhere);
  204. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  205. int count = dataCount.Count;
  206. float totalPage = (float)count / dto.PageSize;//总页数
  207. if (totalPage == 0) totalPage = 1;
  208. else totalPage = (int)Math.Ceiling((double)totalPage);
  209. ListViewBase<HotelReservationsByDiIdView> rst = new ListViewBase<HotelReservationsByDiIdView>();
  210. rst.DataList = hotelDataList;
  211. rst.DataCount = count;
  212. rst.CurrPageIndex = dto.PageIndex;
  213. rst.CurrPageSize = dto.PageSize;
  214. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  215. }
  216. else
  217. {
  218. return result = new Result() { Code = -2, Msg = "请传入PortType参数,1 Web 2 Android 3 IOS" };
  219. }
  220. }
  221. catch (Exception ex)
  222. {
  223. return result = new Result() { Code = -2, Msg = "未知错误" };
  224. throw;
  225. }
  226. }
  227. /// <summary>
  228. /// 根据酒店费用Id查询详细数据
  229. /// </summary>
  230. /// <param name="dto"></param>
  231. /// <returns></returns>
  232. public async Task<Result> HotelReservationsById(HotelReservationsByIdDto dto)
  233. {
  234. Result result = new Result() { Code = -2, Msg = "未知错误" };
  235. try
  236. {
  237. Grp_HotelReservations hotelReservationsById = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  238. HotelReservationsByIdView _hotelReservations = _mapper.Map<HotelReservationsByIdView>(hotelReservationsById);
  239. if (_hotelReservations!=null)
  240. {
  241. Sys_SetData GTId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GTId);
  242. if (GTId != null) _hotelReservations.GtIdStr = GTId.Name;
  243. if (!string.IsNullOrWhiteSpace(_hotelReservations.CheckInDate))
  244. {
  245. _hotelReservations.CheckInDate = Convert.ToDateTime(hotelReservationsById.CheckInDate).ToString("yyyy-MM-dd");
  246. }
  247. if (!string.IsNullOrWhiteSpace(_hotelReservations.CheckOutDate))
  248. {
  249. _hotelReservations.CheckOutDate = Convert.ToDateTime(hotelReservationsById.CheckOutDate).ToString("yyyy-MM-dd");
  250. }
  251. Sys_SetData GovernmentRentCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GovernmentRentCurrency);
  252. if (GovernmentRentCurrencyStr != null) _hotelReservations.GovernmentRentCurrencyStr = GovernmentRentCurrencyStr.Name;
  253. Sys_SetData CityTaxCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.CityTaxCurrency);
  254. if (CityTaxCurrencyStr != null) _hotelReservations.CityTaxCurrencyStr = CityTaxCurrencyStr.Name;
  255. if (_hotelReservations.CheckType == "") _hotelReservations.CheckTypeStr = "客人房";
  256. else if (_hotelReservations.CheckType == "D") _hotelReservations.CheckTypeStr = "司机房";
  257. else if (_hotelReservations.CheckType == "G") _hotelReservations.CheckTypeStr = "导游房";
  258. else if (_hotelReservations.CheckType == "D&G") _hotelReservations.CheckTypeStr = "司机导游房";
  259. }
  260. string Sql = string.Format(@"select c.PayDId, s.Name asPayDIdStr,c.ConsumptionPatterns,c.ConsumptionDate,c.CTDId,
  261. s1.Name as CTDIdStr,c.BankNo,c.CardholderName,c.PayMoney,c.PaymentCurrency,s2.Name
  262. as PaymentCurrencyStr,c.DayRate,c.CompanyBankNo,c.OtherBankName,c.OtherSideNo,c.OtherSideName,
  263. c.IsAuditGM,c.Payee,c.RMBPrice,c.OrbitalPrivateTransfer,c.Remark from Grp_CreditCardPayment c
  264. left join Sys_SetData s on c.PayDId=s.Id
  265. left join Sys_SetData s1 on c.CTDId=s1.Id
  266. left join Sys_SetData s2 on c.PaymentCurrency=s2.Id
  267. where c.CId ={0} and c.IsDel = 0 and c.CTable = 76", dto.Id);
  268. Grp_CreditCardView _CreditCardPayment = _sqlSugar.SqlQueryable<Grp_CreditCardView>(Sql).First();
  269. if (_CreditCardPayment!=null)
  270. {
  271. if(!string.IsNullOrWhiteSpace(_CreditCardPayment.ConsumptionDate)) _CreditCardPayment.ConsumptionDate=Convert.ToDateTime(_CreditCardPayment.ConsumptionDate).ToString("yyyy-MM-dd");
  272. }
  273. var data = new
  274. {
  275. hotelReservations = _hotelReservations,
  276. creditCardPayment = _CreditCardPayment,
  277. };
  278. return result = new Result() { Code = 0, Msg = "查询成功",Data= data };
  279. }
  280. catch (Exception ex)
  281. {
  282. return result = new Result() { Code = -2, Msg = "未知错误" };
  283. throw;
  284. }
  285. }
  286. /// <summary>
  287. /// 酒店页面下拉框等初始化
  288. /// </summary>
  289. /// <param name="dto"></param>
  290. /// <returns></returns>
  291. public async Task<Result> HotelReservationsInitialize(HotelReservationsDto dto)
  292. {
  293. Result result = new Result() { Code = -2, Msg = "未知错误" };
  294. try
  295. {
  296. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 76).ToList();
  297. string DiId = "0";
  298. foreach (var item in grp_GroupsTaskAssignment)
  299. {
  300. DiId += item.DIId + ",";
  301. }
  302. if (DiId != "0")
  303. {
  304. DiId = DiId.Substring(0, DiId.Length - 1);
  305. }
  306. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  307. //团组下拉框
  308. List<Grp_DelegationInfo> Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  309. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(Delegations);
  310. for (int i = 0;i< grp_Delegations.Count; i++)
  311. {
  312. grp_Delegations[i].VisitDate = Delegations[i].VisitStartDate.ToString("yyyy-MM-dd")+"至"+ Delegations[i].VisitEndDate.ToString("yyyy-MM-dd");
  313. }
  314. //客人类型
  315. List<Sys_SetData> GuestType = _sqlSugar.Queryable<Sys_SetData>().Where(a=>a.IsDel==0 && a.STid==11).ToList();
  316. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  317. //支付方式
  318. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  319. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  320. //币种
  321. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  322. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  323. //卡类型
  324. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  325. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  326. //预订网站
  327. List<Sys_SetData> BookingWebsite = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 12 && a.IsDel == 0).ToList();
  328. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  329. if (dto.PortType==2 || dto.PortType==3)
  330. {
  331. var data = new
  332. {
  333. GuestType = _GuestType,
  334. Payment = _Payment,
  335. CurrencyList = _CurrencyList,
  336. BankCard = _BankCard,
  337. BookingWebsite = _BookingWebsite,
  338. };
  339. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  340. }
  341. else
  342. {
  343. var data = new
  344. {
  345. Delegations = grp_Delegations,
  346. GuestType = _GuestType,
  347. Payment = _Payment,
  348. CurrencyList = _CurrencyList,
  349. BankCard = _BankCard,
  350. BookingWebsite = _BookingWebsite,
  351. };
  352. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  353. }
  354. }
  355. catch (Exception ex)
  356. {
  357. return result = new Result() { Code = -2, Msg = "未知错误" };
  358. throw;
  359. }
  360. }
  361. /// <summary>
  362. /// 酒店操作
  363. /// </summary>
  364. /// <param name="dto"></param>
  365. /// <returns></returns>
  366. /// <exception cref="NotImplementedException"></exception>
  367. public async Task<Result> OpHotelReservations(OpHotelReservationsData dto)
  368. {
  369. Result result = new Result() { Code = -2, Msg = "未知错误" };
  370. try
  371. {
  372. BeginTran();
  373. int id = dto.Id;
  374. Grp_HotelReservations hotelPrice = _mapper.Map<Grp_HotelReservations>(dto);
  375. hotelPrice.IsCardPrice = hotelPrice.CardPrice!=0 ? 1:0;
  376. hotelPrice.CboOne=hotelPrice.SingleRoomCount !=0 ? 1 : 0;
  377. hotelPrice.CboTwo = hotelPrice.DoubleRoomCount != 0 ? 1 : 0;
  378. hotelPrice.CboThree = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  379. hotelPrice.CboFour = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  380. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  381. c.Remark = dto.CRemark;
  382. c.PayPercentage = 100;
  383. c.CTable = 76;
  384. c.CId = id;
  385. c.IsAuditGM = 0;
  386. if (c.PayDId == 72)
  387. {
  388. c.IsPay = 1;
  389. }
  390. c.RMBPrice = c.PayMoney;
  391. c.DayRate = 1;
  392. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  393. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  394. if (_TeamRate != null)
  395. {
  396. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  397. if (_SetData != null)
  398. {
  399. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  400. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  401. if (CurrencyRate != null)
  402. {
  403. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  404. c.DayRate = CurrencyRate.Rate;
  405. }
  406. }
  407. }
  408. if (dto.Status == 1)//添加
  409. {
  410. Grp_HotelReservations grp_Hotel = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.HotelName == dto.HotelName && a.GuestName == dto.GuestName &&
  411. a.CheckInDate == dto.CheckInDate && a.CheckOutDate==dto.CheckOutDate && a.City==dto.City);
  412. if (grp_Hotel != null)
  413. {
  414. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  415. }
  416. else
  417. {
  418. id = await AddAsyncReturnId(hotelPrice);
  419. if (id != 0)
  420. {
  421. c.CId = id;
  422. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  423. if (cId != 0)
  424. {
  425. result = new Result() { Code = 0, Msg = "添加成功!" };
  426. }
  427. else
  428. {
  429. RollbackTran();
  430. result = new Result() { Code = -1, Msg = "添加失败!" };
  431. }
  432. }
  433. else
  434. {
  435. RollbackTran();
  436. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  437. }
  438. }
  439. }
  440. else if (dto.Status == 2)//修改
  441. {
  442. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_HotelReservations
  443. {
  444. GTId=hotelPrice.GTId,
  445. CheckNumber=hotelPrice.CheckNumber,
  446. ReservationsWebsite=hotelPrice.ReservationsWebsite,
  447. ReservationsNo=hotelPrice.ReservationsNo,
  448. DetermineNo=hotelPrice.DetermineNo,
  449. City=hotelPrice.City,
  450. HotelName=hotelPrice.HotelName,
  451. HotelAddress=hotelPrice.HotelAddress,
  452. HotelTel=hotelPrice.HotelTel,
  453. GuestName=hotelPrice.GuestName,
  454. CheckInDate=hotelPrice.CheckInDate,
  455. BudgetCurrency=hotelPrice.BudgetCurrency,
  456. CheckOutDate=hotelPrice.CheckOutDate,
  457. SingleRoomCount=hotelPrice.SingleRoomCount,
  458. SingleRoomPrice=hotelPrice.SingleRoomPrice,
  459. DoubleRoomCount=hotelPrice.DoubleRoomCount,
  460. DoubleRoomPrice=hotelPrice.DoubleRoomPrice,
  461. SuiteRoomCount=hotelPrice.SuiteRoomCount,
  462. SuiteRoomPrice=hotelPrice.SuiteRoomPrice,
  463. OtherRoomCount=hotelPrice.OtherRoomCount,
  464. OtherRoomPrice=hotelPrice.OtherRoomPrice,
  465. RoomExplanation=hotelPrice.RoomExplanation,
  466. Attachment=hotelPrice.Attachment,
  467. CardPrice=hotelPrice.CardPrice,
  468. IsCardPrice=hotelPrice.IsCardPrice,
  469. PredictSingleRoom=hotelPrice.PredictSingleRoom,
  470. PredictDoubleRoom=hotelPrice.PredictDoubleRoom,
  471. PredictSuiteRoom=hotelPrice.PredictSuiteRoom,
  472. PredictOtherRoom=hotelPrice.PredictOtherRoom,
  473. GovernmentRent=hotelPrice.GovernmentRent,
  474. GovernmentRentCurrency=hotelPrice.GovernmentRentCurrency,
  475. CityTax=hotelPrice.CityTax,
  476. CityTaxCurrency=hotelPrice.CityTaxCurrency,
  477. CheckType=hotelPrice.CheckType,
  478. CboOne=hotelPrice.SingleRoomCount,
  479. CboTwo=hotelPrice.DoubleRoomCount,
  480. CboThree=hotelPrice.SuiteRoomCount,
  481. CboFour=hotelPrice.SuiteRoomCount,
  482. CreateUserId=hotelPrice.CreateUserId,
  483. Remark=hotelPrice.Remark
  484. });
  485. if (res)
  486. {
  487. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == hotelPrice.Id && a.CTable == 76).SetColumns(a => new Grp_CreditCardPayment
  488. {
  489. PayDId = dto.PayDId,
  490. PayMoney = c.PayMoney,
  491. PaymentCurrency = c.PaymentCurrency,
  492. Payee = c.Payee,
  493. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  494. DayRate = c.DayRate,
  495. RMBPrice = c.RMBPrice,
  496. ConsumptionPatterns = c.ConsumptionPatterns,
  497. ConsumptionDate = c.ConsumptionDate,
  498. CTDId = c.CTDId,
  499. CompanyBankNo = c.CompanyBankNo,
  500. OtherBankName = c.OtherBankName,
  501. OtherSideNo = c.OtherSideNo,
  502. OtherSideName = c.OtherSideName,
  503. BankNo = c.BankNo,
  504. CardholderName = c.CardholderName,
  505. Remark = c.Remark,
  506. }).ExecuteCommandAsync();
  507. if (CTable==0)
  508. {
  509. result = new Result() { Code = -1, Msg = "修改失败!" };
  510. RollbackTran();
  511. }
  512. else
  513. {
  514. result = new Result() { Code = 0, Msg = "修改成功!" };
  515. }
  516. }
  517. else
  518. {
  519. RollbackTran();
  520. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  521. }
  522. }
  523. CommitTran();
  524. }
  525. catch (Exception ex)
  526. {
  527. return result = new Result() { Code = -2, Msg = "未知错误" };
  528. throw;
  529. }
  530. return result;
  531. }
  532. }
  533. }