HotelPriceRepository.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. var data = new
  330. {
  331. Delegations = grp_Delegations,
  332. GuestType = _GuestType,
  333. Payment = _Payment,
  334. CurrencyList = _CurrencyList,
  335. BankCard = _BankCard,
  336. BookingWebsite = _BookingWebsite,
  337. };
  338. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  339. }
  340. catch (Exception ex)
  341. {
  342. return result = new Result() { Code = -2, Msg = "未知错误" };
  343. throw;
  344. }
  345. }
  346. /// <summary>
  347. /// 酒店操作
  348. /// </summary>
  349. /// <param name="dto"></param>
  350. /// <returns></returns>
  351. /// <exception cref="NotImplementedException"></exception>
  352. public async Task<Result> OpHotelReservations(OpHotelReservationsData dto)
  353. {
  354. Result result = new Result() { Code = -2, Msg = "未知错误" };
  355. try
  356. {
  357. BeginTran();
  358. int id = dto.Id;
  359. Grp_HotelReservations hotelPrice = _mapper.Map<Grp_HotelReservations>(dto);
  360. hotelPrice.IsCardPrice = hotelPrice.CardPrice!=0 ? 1:0;
  361. hotelPrice.CboOne=hotelPrice.SingleRoomCount !=0 ? 1 : 0;
  362. hotelPrice.CboTwo = hotelPrice.DoubleRoomCount != 0 ? 1 : 0;
  363. hotelPrice.CboThree = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  364. hotelPrice.CboFour = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  365. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  366. c.Remark = dto.CRemark;
  367. c.PayPercentage = 100;
  368. c.CTable = 76;
  369. c.CId = id;
  370. c.IsAuditGM = 0;
  371. if (c.PayDId == 72)
  372. {
  373. c.IsPay = 1;
  374. }
  375. c.RMBPrice = c.PayMoney;
  376. c.DayRate = 1;
  377. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  378. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  379. if (_TeamRate != null)
  380. {
  381. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  382. if (_SetData != null)
  383. {
  384. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  385. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  386. if (CurrencyRate != null)
  387. {
  388. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  389. c.DayRate = CurrencyRate.Rate;
  390. }
  391. }
  392. }
  393. if (dto.Status == 1)//添加
  394. {
  395. Grp_HotelReservations grp_Hotel = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.HotelName == dto.HotelName && a.GuestName == dto.GuestName &&
  396. a.CheckInDate == dto.CheckInDate && a.CheckOutDate==dto.CheckOutDate && a.City==dto.City);
  397. if (grp_Hotel != null)
  398. {
  399. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  400. }
  401. else
  402. {
  403. id = await AddAsyncReturnId(hotelPrice);
  404. if (id != 0)
  405. {
  406. c.CId = id;
  407. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  408. if (cId != 0)
  409. {
  410. result = new Result() { Code = 0, Msg = "添加成功!" };
  411. }
  412. else
  413. {
  414. RollbackTran();
  415. result = new Result() { Code = -1, Msg = "添加失败!" };
  416. }
  417. }
  418. else
  419. {
  420. RollbackTran();
  421. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  422. }
  423. }
  424. }
  425. else if (dto.Status == 2)//修改
  426. {
  427. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_HotelReservations
  428. {
  429. GTId=hotelPrice.GTId,
  430. CheckNumber=hotelPrice.CheckNumber,
  431. ReservationsWebsite=hotelPrice.ReservationsWebsite,
  432. ReservationsNo=hotelPrice.ReservationsNo,
  433. DetermineNo=hotelPrice.DetermineNo,
  434. City=hotelPrice.City,
  435. HotelName=hotelPrice.HotelName,
  436. HotelAddress=hotelPrice.HotelAddress,
  437. HotelTel=hotelPrice.HotelTel,
  438. GuestName=hotelPrice.GuestName,
  439. CheckInDate=hotelPrice.CheckInDate,
  440. BudgetCurrency=hotelPrice.BudgetCurrency,
  441. CheckOutDate=hotelPrice.CheckOutDate,
  442. SingleRoomCount=hotelPrice.SingleRoomCount,
  443. SingleRoomPrice=hotelPrice.SingleRoomPrice,
  444. DoubleRoomCount=hotelPrice.DoubleRoomCount,
  445. DoubleRoomPrice=hotelPrice.DoubleRoomPrice,
  446. SuiteRoomCount=hotelPrice.SuiteRoomCount,
  447. SuiteRoomPrice=hotelPrice.SuiteRoomPrice,
  448. OtherRoomCount=hotelPrice.OtherRoomCount,
  449. OtherRoomPrice=hotelPrice.OtherRoomPrice,
  450. RoomExplanation=hotelPrice.RoomExplanation,
  451. Attachment=hotelPrice.Attachment,
  452. CardPrice=hotelPrice.CardPrice,
  453. IsCardPrice=hotelPrice.IsCardPrice,
  454. PredictSingleRoom=hotelPrice.PredictSingleRoom,
  455. PredictDoubleRoom=hotelPrice.PredictDoubleRoom,
  456. PredictSuiteRoom=hotelPrice.PredictSuiteRoom,
  457. PredictOtherRoom=hotelPrice.PredictOtherRoom,
  458. GovernmentRent=hotelPrice.GovernmentRent,
  459. GovernmentRentCurrency=hotelPrice.GovernmentRentCurrency,
  460. CityTax=hotelPrice.CityTax,
  461. CityTaxCurrency=hotelPrice.CityTaxCurrency,
  462. CheckType=hotelPrice.CheckType,
  463. CboOne=hotelPrice.SingleRoomCount,
  464. CboTwo=hotelPrice.DoubleRoomCount,
  465. CboThree=hotelPrice.SuiteRoomCount,
  466. CboFour=hotelPrice.SuiteRoomCount,
  467. CreateUserId=hotelPrice.CreateUserId,
  468. Remark=hotelPrice.Remark
  469. });
  470. if (res)
  471. {
  472. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == hotelPrice.Id && a.CTable == 76).SetColumns(a => new Grp_CreditCardPayment
  473. {
  474. PayDId = dto.PayDId,
  475. PayMoney = c.PayMoney,
  476. PaymentCurrency = c.PaymentCurrency,
  477. Payee = c.Payee,
  478. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  479. DayRate = c.DayRate,
  480. RMBPrice = c.RMBPrice,
  481. ConsumptionPatterns = c.ConsumptionPatterns,
  482. ConsumptionDate = c.ConsumptionDate,
  483. CTDId = c.CTDId,
  484. CompanyBankNo = c.CompanyBankNo,
  485. OtherBankName = c.OtherBankName,
  486. OtherSideNo = c.OtherSideNo,
  487. OtherSideName = c.OtherSideName,
  488. BankNo = c.BankNo,
  489. CardholderName = c.CardholderName,
  490. Remark = c.Remark,
  491. }).ExecuteCommandAsync();
  492. if (CTable==0)
  493. {
  494. result = new Result() { Code = -1, Msg = "修改失败!" };
  495. RollbackTran();
  496. }
  497. else
  498. {
  499. result = new Result() { Code = 0, Msg = "修改成功!" };
  500. }
  501. }
  502. else
  503. {
  504. RollbackTran();
  505. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  506. }
  507. }
  508. CommitTran();
  509. }
  510. catch (Exception ex)
  511. {
  512. return result = new Result() { Code = -2, Msg = "未知错误" };
  513. throw;
  514. }
  515. return result;
  516. }
  517. }
  518. }