HotelPriceRepository.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. using AutoMapper;
  2. using MathNet.Numerics.Statistics.Mcmc;
  3. using MySqlX.XDevAPI.Common;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos.Financial;
  6. using OASystem.Domain.Dtos.Groups;
  7. using OASystem.Domain.Entities.Financial;
  8. using OASystem.Domain.Entities.Groups;
  9. using OASystem.Domain.ViewModels.Financial;
  10. using OASystem.Domain.ViewModels.Groups;
  11. using OASystem.Infrastructure.Tools;
  12. using SqlSugar;
  13. using StackExchange.Redis;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using Result = OASystem.Domain.Result;
  20. namespace OASystem.Infrastructure.Repositories.Groups
  21. {
  22. public class HotelPriceRepository : BaseRepository<Grp_HotelReservations, Grp_HotelReservations>
  23. {
  24. private readonly IMapper _mapper;
  25. private readonly Result _result;
  26. private readonly TeamRateRepository _teamRateRep;
  27. public HotelPriceRepository(SqlSugarClient sqlSugar, IMapper mapper, TeamRateRepository teamRateRep) :
  28. base(sqlSugar)
  29. {
  30. this._mapper = mapper;
  31. _result = new Result() { Code = -1, Msg = "操作失败!" };
  32. _teamRateRep = teamRateRep;
  33. }
  34. #region 保留
  35. /// <summary>
  36. /// 付款金额计算
  37. /// </summary>
  38. /// <param name="dto"></param>
  39. /// <returns></returns>
  40. public async Task<Result> HotelConversionAmounts(HotelReservationsCNYDto dto)
  41. {
  42. Result result = new Result() { Code = -2, Msg = "未知错误" };
  43. try
  44. {
  45. HotelReservationsView reservationsView=new HotelReservationsView();
  46. if ((dto.CardPriceCurrency == dto.GovernmentRentCurrency || dto.GovernmentRent == 0)
  47. && (dto.CardPriceCurrency == dto.CityTaxCurrency || dto.CityTax== 0))
  48. {
  49. reservationsView.CurrencyId = dto.CardPriceCurrency;
  50. reservationsView.Price=Convert.ToDecimal((dto.CardPrice+dto.GovernmentRent+dto.CityTax).ToString("F2"));
  51. reservationsView.CurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == dto.CardPriceCurrency).Name;
  52. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  53. }
  54. else
  55. {
  56. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  57. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  58. decimal CardPrice = 0.00M;
  59. decimal GovernmentRent = 0.00M;
  60. decimal CityTax = 0.00M;
  61. if (_TeamRate != null)
  62. {
  63. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CardPriceCurrency);
  64. if (_SetData != null)
  65. {
  66. if (_SetData.Name=="CNY")
  67. {
  68. CardPrice = dto.CardPrice;
  69. }
  70. else
  71. {
  72. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  73. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  74. if (CurrencyRate != null) CardPrice = dto.CardPrice * Convert.ToDecimal(CurrencyRate.Rate);
  75. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  76. }
  77. }
  78. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  79. Sys_SetData _SetData1 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.GovernmentRentCurrency);
  80. if (_SetData1 != null)
  81. {
  82. if (_SetData1.Name == "CNY")
  83. {
  84. GovernmentRent = dto.GovernmentRent;
  85. }
  86. else {
  87. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  88. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData1.Name);
  89. if (CurrencyRate != null) GovernmentRent = dto.GovernmentRent * Convert.ToDecimal(CurrencyRate.Rate);
  90. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  91. }
  92. }
  93. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  94. Sys_SetData _SetData2 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CityTaxCurrency);
  95. if (_SetData2 != null)
  96. {
  97. if (_SetData2.Name == "CNY")
  98. {
  99. CityTax = dto.CityTax;
  100. }
  101. else
  102. {
  103. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  104. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData2.Name);
  105. if (CurrencyRate != null) CityTax = dto.CityTax * Convert.ToDecimal(CurrencyRate.Rate);
  106. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  107. }
  108. }
  109. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  110. reservationsView.CurrencyId = 836;
  111. reservationsView.Price = Convert.ToDecimal((CardPrice + GovernmentRent + CityTax).ToString("F2"));
  112. reservationsView.CurrencyName ="CNY";
  113. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  114. }
  115. else
  116. {
  117. return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data= reservationsView };
  118. }
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. return result = new Result() { Code = -2, Msg = "未知错误" };
  124. throw;
  125. }
  126. }
  127. /// <summary>
  128. /// 根据团组id查询酒店数据
  129. /// </summary>
  130. /// <param name="dto"></param>
  131. /// <returns></returns>
  132. public async Task<Result> HotelReservationsByDiId(HotelReservationsByDiIdDto dto)
  133. {
  134. Result result = new Result() { Code = -2, Msg = "未知错误" };
  135. try
  136. {
  137. string UserId = "";
  138. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 76).ToList();
  139. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  140. UserId += gta.UId + ",";
  141. if (!string.IsNullOrWhiteSpace(UserId))
  142. {
  143. UserId = UserId.Substring(0, UserId.Length - 1);
  144. }
  145. else
  146. {
  147. UserId = "0";
  148. }
  149. string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0,UserId);
  150. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  151. int endIndex = startIndex + dto.PageSize - 1;
  152. if (dto.PortType == 1)
  153. {
  154. string sql = string.Format(@"select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  155. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  156. From Grp_HotelReservations h
  157. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  158. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  159. left Join Sys_SetData s1 on h.GTId=s1.Id
  160. left Join Sys_Users u on u.Id=h.CreateUserId {0} order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  161. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  162. foreach (var item in hotelDataList)
  163. {
  164. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  165. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  166. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  167. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  168. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  169. {
  170. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  171. }
  172. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  173. {
  174. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  175. }
  176. }
  177. return result = new Result() { Code = 0, Msg = "查询成功!", Data = hotelDataList };
  178. }
  179. else if (dto.PortType == 2 || dto.PortType == 3)
  180. {
  181. string sql = string.Format(@"Select * From (
  182. 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,
  183. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  184. From Grp_HotelReservations h
  185. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  186. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  187. left Join Sys_SetData s1 on h.GTId=s1.Id
  188. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  189. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  190. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  191. foreach (var item in hotelDataList)
  192. {
  193. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  194. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  195. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  196. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  197. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  198. {
  199. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  200. }
  201. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  202. {
  203. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  204. }
  205. }
  206. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  207. Select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  208. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  209. From Grp_HotelReservations h
  210. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  211. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  212. left Join Sys_SetData s1 on h.GTId=s1.Id
  213. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  214. ) temp", sqlWhere);
  215. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  216. int count = dataCount.Count;
  217. float totalPage = (float)count / dto.PageSize;//总页数
  218. if (totalPage == 0) totalPage = 1;
  219. else totalPage = (int)Math.Ceiling((double)totalPage);
  220. ListViewBase<HotelReservationsByDiIdView> rst = new ListViewBase<HotelReservationsByDiIdView>();
  221. rst.DataList = hotelDataList;
  222. rst.DataCount = count;
  223. rst.CurrPageIndex = dto.PageIndex;
  224. rst.CurrPageSize = dto.PageSize;
  225. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  226. }
  227. else
  228. {
  229. return result = new Result() { Code = -2, Msg = "请传入PortType参数,1 Web 2 Android 3 IOS" };
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. return result = new Result() { Code = -2, Msg = "未知错误" };
  235. throw;
  236. }
  237. }
  238. /// <summary>
  239. /// 根据酒店费用Id查询详细数据
  240. /// </summary>
  241. /// <param name="dto"></param>
  242. /// <returns></returns>
  243. public async Task<Result> HotelReservationsById(HotelReservationsByIdDto dto)
  244. {
  245. Result result = new Result() { Code = -2, Msg = "未知错误" };
  246. try
  247. {
  248. Grp_HotelReservations hotelReservationsById = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  249. HotelReservationsByIdView _hotelReservations = _mapper.Map<HotelReservationsByIdView>(hotelReservationsById);
  250. if (_hotelReservations!=null)
  251. {
  252. Sys_SetData GTId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GTId);
  253. if (GTId != null) _hotelReservations.GtIdStr = GTId.Name;
  254. if (!string.IsNullOrWhiteSpace(_hotelReservations.CheckInDate))
  255. {
  256. _hotelReservations.CheckInDate = Convert.ToDateTime(hotelReservationsById.CheckInDate).ToString("yyyy-MM-dd");
  257. }
  258. if (!string.IsNullOrWhiteSpace(_hotelReservations.CheckOutDate))
  259. {
  260. _hotelReservations.CheckOutDate = Convert.ToDateTime(hotelReservationsById.CheckOutDate).ToString("yyyy-MM-dd");
  261. }
  262. Sys_SetData GovernmentRentCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GovernmentRentCurrency);
  263. if (GovernmentRentCurrencyStr != null) _hotelReservations.GovernmentRentCurrencyStr = GovernmentRentCurrencyStr.Name;
  264. Sys_SetData CityTaxCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.CityTaxCurrency);
  265. if (CityTaxCurrencyStr != null) _hotelReservations.CityTaxCurrencyStr = CityTaxCurrencyStr.Name;
  266. if (_hotelReservations.CheckType == "") _hotelReservations.CheckTypeStr = "客人房";
  267. else if (_hotelReservations.CheckType == "D") _hotelReservations.CheckTypeStr = "司机房";
  268. else if (_hotelReservations.CheckType == "G") _hotelReservations.CheckTypeStr = "导游房";
  269. else if (_hotelReservations.CheckType == "D&G") _hotelReservations.CheckTypeStr = "司机导游房";
  270. }
  271. string Sql = string.Format(@"select c.PayDId, s.Name asPayDIdStr,c.ConsumptionPatterns,c.ConsumptionDate,c.CTDId,
  272. s1.Name as CTDIdStr,c.BankNo,c.CardholderName,c.PayMoney,c.PaymentCurrency,s2.Name
  273. as PaymentCurrencyStr,c.DayRate,c.CompanyBankNo,c.OtherBankName,c.OtherSideNo,c.OtherSideName,
  274. c.IsAuditGM,c.Payee,c.RMBPrice,c.OrbitalPrivateTransfer,c.Remark from Grp_CreditCardPayment c
  275. left join Sys_SetData s on c.PayDId=s.Id
  276. left join Sys_SetData s1 on c.CTDId=s1.Id
  277. left join Sys_SetData s2 on c.PaymentCurrency=s2.Id
  278. where c.CId ={0} and c.IsDel = 0 and c.CTable = 76", dto.Id);
  279. Grp_CreditCardView _CreditCardPayment = _sqlSugar.SqlQueryable<Grp_CreditCardView>(Sql).First();
  280. if (_CreditCardPayment!=null)
  281. {
  282. if(!string.IsNullOrWhiteSpace(_CreditCardPayment.ConsumptionDate)) _CreditCardPayment.ConsumptionDate=Convert.ToDateTime(_CreditCardPayment.ConsumptionDate).ToString("yyyy-MM-dd");
  283. }
  284. var data = new
  285. {
  286. hotelReservations = _hotelReservations,
  287. creditCardPayment = _CreditCardPayment,
  288. };
  289. return result = new Result() { Code = 0, Msg = "查询成功",Data= data };
  290. }
  291. catch (Exception ex)
  292. {
  293. return result = new Result() { Code = -2, Msg = "未知错误" };
  294. throw;
  295. }
  296. }
  297. /// <summary>
  298. /// 酒店页面下拉框等初始化
  299. /// </summary>
  300. /// <param name="dto"></param>
  301. /// <returns></returns>
  302. public async Task<Result> HotelReservationsInitialize(HotelReservationsDto dto)
  303. {
  304. Result result = new Result() { Code = -2, Msg = "未知错误" };
  305. try
  306. {
  307. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 76).ToList();
  308. string DiId = "0";
  309. foreach (var item in grp_GroupsTaskAssignment)
  310. {
  311. DiId += item.DIId + ",";
  312. }
  313. if (DiId != "0")
  314. {
  315. DiId = DiId.Substring(0, DiId.Length - 1);
  316. }
  317. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  318. //团组下拉框
  319. List<Grp_DelegationInfo> Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  320. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(Delegations);
  321. for (int i = 0;i< grp_Delegations.Count; i++)
  322. {
  323. grp_Delegations[i].VisitDate = Delegations[i].VisitStartDate.ToString("yyyy-MM-dd")+"至"+ Delegations[i].VisitEndDate.ToString("yyyy-MM-dd");
  324. }
  325. //客人类型
  326. List<Sys_SetData> GuestType = _sqlSugar.Queryable<Sys_SetData>().Where(a=>a.IsDel==0 && a.STid==11).ToList();
  327. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  328. //支付方式
  329. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  330. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  331. //币种
  332. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  333. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  334. //卡类型
  335. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  336. List<SetDataCurrencyInfoView> _BankCard = _mapper.Map<List<SetDataCurrencyInfoView>>(BankCard);
  337. //预订网站
  338. List<Sys_SetData> BookingWebsite = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 12 && a.IsDel == 0).ToList();
  339. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  340. if (dto.PortType==2 || dto.PortType==3)
  341. {
  342. GeneralTeamRateInfoDto PostGroupTeamRatedto = new GeneralTeamRateInfoDto();
  343. PostGroupTeamRatedto.DiId= dto.DiId;
  344. PostGroupTeamRatedto.CTable = 76;
  345. PostGroupTeamRatedto.PortType= dto.PortType;
  346. Result teamRateDescAddCurrencyIdViews = PostGroupTeamRateByDiIdAndCTableId(PostGroupTeamRatedto);
  347. List<TeamRateDescAddCurrencyIdView> Currency=new List<TeamRateDescAddCurrencyIdView>();
  348. if (teamRateDescAddCurrencyIdViews.Code==0)
  349. {
  350. Currency = teamRateDescAddCurrencyIdViews.Data;
  351. }
  352. var data = new
  353. {
  354. GuestType = _GuestType,
  355. Payment = _Payment,
  356. CurrencyList = Currency,
  357. BankCard = _BankCard,
  358. BookingWebsite = _BookingWebsite,
  359. };
  360. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  361. }
  362. else
  363. {
  364. var data = new
  365. {
  366. Delegations = grp_Delegations,
  367. GuestType = _GuestType,
  368. Payment = _Payment,
  369. CurrencyList = _CurrencyList,
  370. BankCard = _BankCard,
  371. BookingWebsite = _BookingWebsite,
  372. };
  373. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  374. }
  375. }
  376. catch (Exception ex)
  377. {
  378. return result = new Result() { Code = -2, Msg = "未知错误" };
  379. throw;
  380. }
  381. }
  382. /// <summary>
  383. /// 酒店操作
  384. /// </summary>
  385. /// <param name="dto"></param>
  386. /// <returns></returns>
  387. /// <exception cref="NotImplementedException"></exception>
  388. public async Task<Result> OpHotelReservations(OpHotelReservationsData dto)
  389. {
  390. Result result = new Result() { Code = -2, Msg = "未知错误" };
  391. try
  392. {
  393. BeginTran();
  394. int id = dto.Id;
  395. Grp_HotelReservations hotelPrice = _mapper.Map<Grp_HotelReservations>(dto);
  396. hotelPrice.IsCardPrice = hotelPrice.CardPrice!=0 ? 1:0;
  397. hotelPrice.CboOne=hotelPrice.SingleRoomCount !=0 ? 1 : 0;
  398. hotelPrice.CboTwo = hotelPrice.DoubleRoomCount != 0 ? 1 : 0;
  399. hotelPrice.CboThree = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  400. hotelPrice.CboFour = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  401. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  402. c.Remark = dto.CRemark;
  403. c.PayPercentage = 100;
  404. c.CTable = 76;
  405. c.CId = id;
  406. c.IsAuditGM = 0;
  407. if (c.PayDId == 72)
  408. {
  409. c.IsPay = 1;
  410. }
  411. c.RMBPrice = c.PayMoney;
  412. c.DayRate = 1;
  413. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  414. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  415. if (_TeamRate != null)
  416. {
  417. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  418. if (_SetData != null)
  419. {
  420. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  421. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  422. if (CurrencyRate != null)
  423. {
  424. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  425. c.DayRate = CurrencyRate.Rate;
  426. }
  427. }
  428. }
  429. if (dto.Status == 1)//添加
  430. {
  431. Grp_HotelReservations grp_Hotel = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.HotelName == dto.HotelName && a.GuestName == dto.GuestName &&
  432. a.CheckInDate == dto.CheckInDate && a.CheckOutDate==dto.CheckOutDate && a.City==dto.City);
  433. if (grp_Hotel != null)
  434. {
  435. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  436. }
  437. else
  438. {
  439. id = await AddAsyncReturnId(hotelPrice);
  440. if (id != 0)
  441. {
  442. c.CId = id;
  443. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  444. if (cId != 0)
  445. {
  446. result = new Result() { Code = 0, Msg = "添加成功!" };
  447. }
  448. else
  449. {
  450. RollbackTran();
  451. result = new Result() { Code = -1, Msg = "添加失败!" };
  452. }
  453. }
  454. else
  455. {
  456. RollbackTran();
  457. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  458. }
  459. }
  460. }
  461. else if (dto.Status == 2)//修改
  462. {
  463. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_HotelReservations
  464. {
  465. GTId=hotelPrice.GTId,
  466. CheckNumber=hotelPrice.CheckNumber,
  467. ReservationsWebsite=hotelPrice.ReservationsWebsite,
  468. ReservationsNo=hotelPrice.ReservationsNo,
  469. DetermineNo=hotelPrice.DetermineNo,
  470. City=hotelPrice.City,
  471. HotelName=hotelPrice.HotelName,
  472. HotelAddress=hotelPrice.HotelAddress,
  473. HotelTel=hotelPrice.HotelTel,
  474. GuestName=hotelPrice.GuestName,
  475. CheckInDate=hotelPrice.CheckInDate,
  476. BudgetCurrency=hotelPrice.BudgetCurrency,
  477. CheckOutDate=hotelPrice.CheckOutDate,
  478. SingleRoomCount=hotelPrice.SingleRoomCount,
  479. SingleRoomPrice=hotelPrice.SingleRoomPrice,
  480. DoubleRoomCount=hotelPrice.DoubleRoomCount,
  481. DoubleRoomPrice=hotelPrice.DoubleRoomPrice,
  482. SuiteRoomCount=hotelPrice.SuiteRoomCount,
  483. SuiteRoomPrice=hotelPrice.SuiteRoomPrice,
  484. OtherRoomCount=hotelPrice.OtherRoomCount,
  485. OtherRoomPrice=hotelPrice.OtherRoomPrice,
  486. RoomExplanation=hotelPrice.RoomExplanation,
  487. Attachment=hotelPrice.Attachment,
  488. CardPrice=hotelPrice.CardPrice,
  489. CardPriceCurrency=hotelPrice.CardPriceCurrency,
  490. IsCardPrice =hotelPrice.IsCardPrice,
  491. PredictSingleRoom=hotelPrice.PredictSingleRoom,
  492. PredictDoubleRoom=hotelPrice.PredictDoubleRoom,
  493. PredictSuiteRoom=hotelPrice.PredictSuiteRoom,
  494. PredictOtherRoom=hotelPrice.PredictOtherRoom,
  495. GovernmentRent=hotelPrice.GovernmentRent,
  496. GovernmentRentCurrency=hotelPrice.GovernmentRentCurrency,
  497. CityTax=hotelPrice.CityTax,
  498. CityTaxCurrency=hotelPrice.CityTaxCurrency,
  499. CheckType=hotelPrice.CheckType,
  500. CboOne=hotelPrice.SingleRoomCount,
  501. CboTwo=hotelPrice.DoubleRoomCount,
  502. CboThree=hotelPrice.SuiteRoomCount,
  503. CboFour=hotelPrice.SuiteRoomCount,
  504. CreateUserId=hotelPrice.CreateUserId,
  505. Remark=hotelPrice.Remark
  506. });
  507. if (res)
  508. {
  509. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == hotelPrice.Id && a.CTable == 76).SetColumns(a => new Grp_CreditCardPayment
  510. {
  511. PayDId = dto.PayDId,
  512. PayMoney = c.PayMoney,
  513. PaymentCurrency = c.PaymentCurrency,
  514. Payee = c.Payee,
  515. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  516. DayRate = c.DayRate,
  517. RMBPrice = c.RMBPrice,
  518. ConsumptionPatterns = c.ConsumptionPatterns,
  519. ConsumptionDate = c.ConsumptionDate,
  520. CTDId = c.CTDId,
  521. CompanyBankNo = c.CompanyBankNo,
  522. OtherBankName = c.OtherBankName,
  523. OtherSideNo = c.OtherSideNo,
  524. OtherSideName = c.OtherSideName,
  525. BankNo = c.BankNo,
  526. CardholderName = c.CardholderName,
  527. Remark = c.Remark,
  528. }).ExecuteCommandAsync();
  529. if (CTable==0)
  530. {
  531. result = new Result() { Code = -1, Msg = "修改失败!" };
  532. RollbackTran();
  533. }
  534. else
  535. {
  536. result = new Result() { Code = 0, Msg = "修改成功!" };
  537. }
  538. }
  539. else
  540. {
  541. RollbackTran();
  542. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  543. }
  544. }
  545. CommitTran();
  546. }
  547. catch (Exception ex)
  548. {
  549. return result = new Result() { Code = -2, Msg = "未知错误" };
  550. throw;
  551. }
  552. return result;
  553. }
  554. public Result PostGroupTeamRateByDiIdAndCTableId(GeneralTeamRateInfoDto dto)
  555. {
  556. Result result = new Result() { Code = -2, Msg = "未知错误" };
  557. try
  558. {
  559. if (dto == null)
  560. {
  561. return result = new Result() { Code = -2, Msg = "请输入参数" };
  562. }
  563. if (dto.DiId == 0)
  564. {
  565. return result = new Result() { Code = -2, Msg = "请输入正确的团组Id!" };
  566. }
  567. if (dto.CTable == 0)
  568. {
  569. return result = new Result() { Code = -2, Msg = "请输入正确的业务类型(CTable)Id!" };
  570. }
  571. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  572. {
  573. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  574. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  575. Where tr.IsDel = 0 And tr.DiId = {0} And tr.CTable = {1}", dto.DiId, dto.CTable);
  576. var teamRateInfo = _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToList();
  577. #region 团组汇率
  578. TeamRateModelGeneralView teamRateModels = new TeamRateModelGeneralView();
  579. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  580. #region 获取所有币种
  581. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  582. List<SetDataInfoView> DBdata = _sqlSugar.SqlQueryable<SetDataInfoView>(sql).ToList();
  583. if (DBdata == null || DBdata.Count == 0)
  584. {
  585. return result = new Result() { Code = -2, Msg = "所有币种获取失败!" };
  586. }
  587. currencyDatas = DBdata.Select(x => new SetDataInfoView
  588. {
  589. Name = x.Name,
  590. Id = x.Id,
  591. Remark = x.Remark,
  592. }).ToList();
  593. #endregion
  594. List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
  595. foreach (TeamRateInfoView item in teamRateInfo)
  596. {
  597. #region 拆分remark里的汇率
  598. if (item.Remark.Contains("|"))
  599. {
  600. string[] currencyArr = item.Remark.Split("|");
  601. foreach (string currency in currencyArr)
  602. {
  603. string[] currency1 = currency.Split(":");
  604. string[] currency2 = currency1[0].Split("(");
  605. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  606. SetDataInfoView dataInfoView = new SetDataInfoView();
  607. dataInfoView = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault();
  608. int currencyId = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault().Id;
  609. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  610. {
  611. CurrencyId = dataInfoView.Id,
  612. CurrencyCode = currencyCode,
  613. CurrencyName = currency2[0],
  614. Rate = decimal.Parse(currency1[1]),
  615. };
  616. teamRateDescViews.Add(rateDescView);
  617. }
  618. }
  619. #endregion
  620. if (teamRateDescViews.Count > 0)
  621. {
  622. teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
  623. }
  624. }
  625. #endregion
  626. return result = new Result() { Code = 0, Msg = "操作成功!",Data= teamRateDescViews };
  627. }
  628. else
  629. {
  630. return result = new Result() { Code = -2, Msg = "请输入正确的端口号! 1 Web 2 Android 3 Ios;" };
  631. }
  632. }
  633. catch (Exception ex)
  634. {
  635. return result = new Result() { Code = -2, Msg = "未知错误" };
  636. }
  637. }
  638. #endregion
  639. /// <summary>
  640. /// 酒店预定
  641. /// Items By DiId
  642. /// </summary>
  643. /// <param name="dto"></param>
  644. /// <returns></returns>
  645. public async Task<Result> _ItemsByDiId(int portType,int diId)
  646. {
  647. string sql = string.Format(@"Select row_number() over(order by hr.CreateTime Desc) as Row_Number,
  648. hr.Id,hr.DiId,sd1.Name As GuestType,hr.ReservationsNo,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  649. ccp.PayMoney, ccp.PaymentCurrency,sd2.Name PayCurrency,hr.CreateUserId,u.CnName As CreateUserName,
  650. hr.CreateTime,ccp.IsAuditGM
  651. From Grp_HotelReservations hr
  652. Inner Join Grp_CreditCardPayment ccp On hr.DiId = ccp.DIId And hr.Id = ccp.CId
  653. And ccp.CTable = 76
  654. Left Join Sys_SetData sd1 On hr.GTId = sd1.Id
  655. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  656. Left Join Sys_Users u On hr.CreateUserId = u.Id
  657. Where hr.IsDel = 0 And ccp.IsDel = 0 And hr.DiId = {0} ", diId);
  658. if (portType == 1 || portType == 2 || portType == 3)
  659. {
  660. var hotelFeeData = await _sqlSugar.SqlQueryable<HotelReservationsItemsView>(sql).ToListAsync();
  661. _result.Code = 0;
  662. _result.Data = hotelFeeData;
  663. _result.Msg = "操作成功!";
  664. }
  665. else
  666. {
  667. _result.Msg = "请传入正确的PortType参数,1 Web 2 Android 3 IOS";
  668. }
  669. return _result;
  670. }
  671. /// <summary>
  672. /// 酒店预定
  673. /// basicsData Init
  674. /// </summary>
  675. /// <param name="dto"></param>
  676. /// <returns></returns>
  677. public async Task<Result> _BasicsDataInit(int portType, int diId)
  678. {
  679. List<Sys_SetData> _dataSouruce = await _sqlSugar.Queryable<Sys_SetData>().Where(a => a.IsDel == 0).ToListAsync();
  680. if (portType == 1 || portType == 2 || portType == 3)
  681. {
  682. //客人类型
  683. List<Sys_SetData> GuestType = _dataSouruce.Where(a => a.STid == 11).ToList();
  684. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  685. //预订网站
  686. List<Sys_SetData> BookingWebsite = _dataSouruce.Where(a => a.STid == 12).ToList();
  687. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  688. //支付方式
  689. List<Sys_SetData> Payment = _dataSouruce.Where(a => a.STid == 14).ToList();
  690. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  691. //卡类型
  692. List<Sys_SetData> BankCard = _dataSouruce.Where(a => a.STid == 15).ToList();
  693. List<SetDataCurrencyInfoView> _BankCard = _mapper.Map<List<SetDataCurrencyInfoView>>(BankCard);
  694. //房间入住人类型
  695. List<Sys_SetData> CheckPerson = _dataSouruce.Where(a => a.STid == 71).ToList();
  696. List<SetDataInfoView> _CheckPerson = _mapper.Map<List<SetDataInfoView>>(CheckPerson);
  697. GeneralTeamRateInfoDto postGroupTeamRatedto = new GeneralTeamRateInfoDto()
  698. {
  699. DiId = diId,
  700. CTable = 76, //酒店预定
  701. PortType = portType
  702. };
  703. Result teamRateDescAddCurrencyIdViews = PostGroupTeamRateByDiIdAndCTableId(postGroupTeamRatedto);
  704. List<TeamRateDescAddCurrencyIdView> TeamCurrencyRate = new List<TeamRateDescAddCurrencyIdView>();
  705. if (teamRateDescAddCurrencyIdViews.Code == 0)
  706. {
  707. TeamCurrencyRate = teamRateDescAddCurrencyIdViews.Data;
  708. }
  709. string _CheckVolumeNo = string.Empty;
  710. var checkVoumeNoData = _CreateCheckVolumeNo(diId);
  711. if (checkVoumeNoData.Result.Code == 0)
  712. {
  713. _CheckVolumeNo = checkVoumeNoData.Result.Data;
  714. }
  715. var data = new
  716. {
  717. GuestType = _GuestType, //客人分类
  718. Payment = _Payment,
  719. CurrencyList = TeamCurrencyRate,
  720. BankCard = _BankCard,
  721. BookingWebsite = _BookingWebsite,
  722. CheckPerson = _CheckPerson,
  723. CheckVolumeNo = _CheckVolumeNo
  724. };
  725. _result.Code = 0;
  726. _result.Data = data;
  727. _result.Msg = "操作成功!";
  728. }
  729. else
  730. {
  731. _result.Msg = "请传入正确的PortType参数,1 Web 2 Android 3 IOS!";
  732. }
  733. return _result;
  734. }
  735. /// <summary>
  736. /// 酒店预定
  737. /// 创建 入住卷号码
  738. /// </summary>
  739. /// <param name="DiId"></param>
  740. /// <returns></returns>
  741. public async Task<Result> _CreateCheckVolumeNo(int DiId)
  742. {
  743. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == DiId && it.IsDel == 0).FirstAsync();
  744. if (groupInfo != null)
  745. {
  746. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  747. {
  748. string no = string.Empty;
  749. string[] countrys = new string[] { };
  750. countrys = groupInfo.VisitCountry.Split('|');
  751. foreach (string country in countrys)
  752. {
  753. //国家城市三字码 未挪数据 暂时用随机数代替
  754. }
  755. no = CommonFun.GetRandomLetter(countrys.Length).ToUpper();
  756. no += CommonFun.GetRandomNumber(2);
  757. _result.Code = 0;
  758. _result.Data = no;
  759. _result.Msg = "入住卷号码 获取成功!";
  760. }
  761. }
  762. return _result;
  763. }
  764. /// <summary>
  765. /// 酒店预定-
  766. /// details
  767. /// </summary>
  768. /// <param name="dto"></param>
  769. /// <returns></returns>
  770. public async Task<Result> _Details(int portType, int id)
  771. {
  772. if (id < 0 )
  773. {
  774. _result.Msg = string.Format(@"请输入正确的Id!");
  775. return _result;
  776. }
  777. string sql = string.Format(@"Select hr.Id,hr.DiId,hr.GTId,ccp.CTDId,hr.CheckNumber,hr.ReservationsWebsite,hr.ReservationsNo,
  778. hr.DetermineNo,hr.City,hr.HotelName,hr.HotelTel,hr.HotelAddress,hr.GuestName,hr.CheckInDate,hr.CheckOutDate,
  779. hr.CheckType,hr.RoomExplanation,hr.Remark As HotelRemark,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  780. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,hr.CardPrice,
  781. hr.Isoppay,hr.BreakfastPrice,hr.BreakfastCurrency,hr.GovernmentRent,hr.GovernmentRentCurrency,hr.CityTax,
  782. hr.CityTaxCurrency,ccp.PayDId,ccp.ConsumptionPatterns,ccp.ConsumptionDate,ccp.PayMoney,ccp.PaymentCurrency,
  783. ccp.BankNo,ccp.CardholderName,ccp.CompanyBankNo,ccp.OtherBankName,ccp.OtherSideNo,ccp.OtherSideName,ccp.Payee,
  784. ccp.OrbitalPrivateTransfer,ccp.Remark As CcpRemark
  785. From Grp_HotelReservations hr
  786. Inner Join Grp_CreditCardPayment ccp On hr.DiId = ccp.DIId And hr.Id = ccp.CId
  787. And ccp.CTable = 76
  788. Where hr.IsDel = 0 And ccp.IsDel = 0 And hr.Id = {0}", id);
  789. if (portType == 1 || portType == 2 || portType == 3)
  790. {
  791. var info = await _sqlSugar.SqlQueryable<HotelReservationsDetailsView>(sql).FirstAsync();
  792. if (info != null) _result.Msg = "操作成功!";
  793. else _result.Msg = "暂无数据";
  794. _result.Code = 0;
  795. _result.Data = info;
  796. return _result;
  797. }
  798. else
  799. {
  800. _result.Msg = "请传入正确的PortType参数,1 Web 2 Android 3 IOS";
  801. return _result;
  802. }
  803. }
  804. /// <summary>
  805. /// 酒店预定
  806. /// Add Or Edit
  807. /// </summary>
  808. /// <returns></returns>
  809. public async Task<Result> _AddOrEdit(HotelReservationsAddOrEditDto _dto)
  810. {
  811. int portType = _dto.PortType;
  812. if (portType == 1 || portType == 2 || portType == 3)
  813. {
  814. Grp_HotelReservations _HotelReservations = new Grp_HotelReservations();
  815. Grp_CreditCardPayment _CreditCardPayment = new Grp_CreditCardPayment();
  816. #region 参数处理
  817. _HotelReservations = _mapper.Map<Grp_HotelReservations>(_dto);
  818. _CreditCardPayment = _mapper.Map<Grp_CreditCardPayment>(_dto);
  819. _HotelReservations.DiId = _dto.DiId;
  820. _HotelReservations.CardPriceCurrency = _dto.CTDId;
  821. _HotelReservations.CreateUserId = _dto.UserId;
  822. _HotelReservations.Remark = _dto.HotelRemark;
  823. if (portType == 2 || portType == 3)
  824. {
  825. string checkNo = string.Empty;
  826. Result checkNoRes = await _CreateCheckVolumeNo(_dto.DiId);
  827. if (checkNoRes.Code == 0)
  828. {
  829. checkNo = checkNoRes.Data;
  830. }
  831. }
  832. #region CCP 表参数
  833. _CreditCardPayment.CreateUserId = _dto.UserId;
  834. _CreditCardPayment.DIId = _dto.DiId;
  835. _CreditCardPayment.CTable = 76;
  836. _CreditCardPayment.CTDId = _dto.CTDId;
  837. _CreditCardPayment.PayPercentage = 100.00M;
  838. _CreditCardPayment.PayThenMoney = _CreditCardPayment.PayMoney;
  839. string paymentCurrencyCode = string.Empty;
  840. List<Sys_SetData> currencySouruce = await _sqlSugar.Queryable<Sys_SetData>().Where(a => a.IsDel == 0 && a.STid == 66).ToListAsync();
  841. if (currencySouruce.Count > 0)
  842. {
  843. Sys_SetData currency = new Sys_SetData();
  844. currency = currencySouruce.Where(it => it.Id == _CreditCardPayment.PaymentCurrency).FirstOrDefault();
  845. if (currency != null)
  846. {
  847. paymentCurrencyCode = currency.Name;
  848. }
  849. }
  850. decimal currencyRate = 0.00M;
  851. if (_CreditCardPayment.PayMoney != 0)
  852. {
  853. if(_CreditCardPayment.PaymentCurrency <= 0)
  854. {
  855. _result.Msg = "请选择付款币种!";
  856. return _result;
  857. }
  858. List<TeamRateModelView> teamRateModelViews = new List<TeamRateModelView>();
  859. teamRateModelViews = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
  860. if (teamRateModelViews.Count < 0)
  861. {
  862. _result.Msg = "该团未设置酒店预订模块相关币种汇率!";
  863. return _result;
  864. }
  865. TeamRateModelView teamRateModels_hotel = new TeamRateModelView();
  866. teamRateModels_hotel = teamRateModelViews.Where(it => it.CTableId == 76).FirstOrDefault();
  867. if (teamRateModels_hotel == null)
  868. {
  869. _result.Msg = "该团未设置酒店预订模块相关币种汇率!";
  870. return _result;
  871. }
  872. List<TeamRateDescView> teamRateDescViews = new List<TeamRateDescView>();
  873. teamRateDescViews = teamRateModels_hotel.TeamRates;
  874. if (teamRateDescViews.Count < 0)
  875. {
  876. _result.Msg = "该团未设置酒店预订模块相关币种汇率!";
  877. return _result;
  878. }
  879. TeamRateDescView teamRateDescView = new TeamRateDescView();
  880. teamRateDescView = teamRateDescViews.Where(it => it.CurrencyCode == paymentCurrencyCode).FirstOrDefault();
  881. if (teamRateDescView == null)
  882. {
  883. _result.Msg = "该团未设置酒店预订模块相关币种汇率!";
  884. return _result;
  885. }
  886. currencyRate = teamRateDescView.Rate;
  887. }
  888. _CreditCardPayment.DayRate = currencyRate;
  889. _CreditCardPayment.RMBPrice = (_CreditCardPayment.DayRate * _CreditCardPayment.PayMoney).DecimalsKeepTwo();
  890. //if (_CreditCardPayment.PayDId == 72) //刷卡
  891. //{
  892. // _CreditCardPayment.BankNo = "6222 **** **** 7990";
  893. // _CreditCardPayment.CardholderName = "Zhang Hailin";
  894. //}
  895. _CreditCardPayment.Remark = _dto.CcpRemark;
  896. #endregion
  897. #endregion
  898. if (_dto.Id == 0) // Add
  899. {
  900. _sqlSugar.BeginTran();
  901. int hotelId = await _sqlSugar.Insertable<Grp_HotelReservations>(_HotelReservations).ExecuteReturnIdentityAsync();
  902. if (hotelId < 0)
  903. {
  904. _result.Msg = "酒店预定信息添加失败!";
  905. _sqlSugar.RollbackTran(); //回滚
  906. return _result;
  907. }
  908. _CreditCardPayment.CId = hotelId;
  909. _CreditCardPayment.CTable = 76; //酒店预定模块
  910. int ccpId = await _sqlSugar.Insertable<Grp_CreditCardPayment>(_CreditCardPayment).ExecuteReturnIdentityAsync();
  911. if (ccpId < 0)
  912. {
  913. _result.Msg = "付款信息添加失败!";
  914. _sqlSugar.RollbackTran(); //回滚
  915. return _result;
  916. }
  917. _result.Msg = "操作成功!";
  918. _result.Code = 0;
  919. _sqlSugar.CommitTran(); // 提交
  920. }
  921. else if (_dto.Id > 0) //Edit
  922. {
  923. _sqlSugar.BeginTran();
  924. int hotelStatus = await _sqlSugar.Updateable<Grp_HotelReservations>(_HotelReservations)
  925. .UpdateColumns(it => new
  926. {
  927. it.GTId,
  928. it.CheckNumber,
  929. it.ReservationsWebsite,
  930. it.ReservationsNo,
  931. it.DetermineNo,
  932. it.City,
  933. it.HotelName,
  934. it.HotelTel,
  935. it.HotelAddress,
  936. it.GuestName,
  937. it.CheckInDate,
  938. it.CheckOutDate,
  939. it.CheckType,
  940. it.RoomExplanation,
  941. it.SingleRoomPrice,
  942. it.SingleRoomCount,
  943. it.DoubleRoomPrice,
  944. it.DoubleRoomCount,
  945. it.SuiteRoomPrice,
  946. it.SuiteRoomCount,
  947. it.OtherRoomPrice,
  948. it.OtherRoomCount,
  949. it.CardPrice,
  950. it.CardPriceCurrency,
  951. it.Isoppay,
  952. it.BreakfastPrice,
  953. it.BreakfastCurrency,
  954. it.GovernmentRent,
  955. it.GovernmentRentCurrency,
  956. it.CityTax,
  957. it.CityTaxCurrency,
  958. it.Remark,
  959. })
  960. .WhereColumns(it => it.Id)
  961. .ExecuteCommandAsync();
  962. if (hotelStatus < 0)
  963. {
  964. _result.Msg = "酒店预定信息修改失败!";
  965. _sqlSugar.RollbackTran(); //回滚
  966. return _result;
  967. }
  968. var hotelInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  969. .Where(it => it.DIId == _dto.DiId && it.CId == _dto.Id && it.CTable == 76 && it.IsDel == 0)
  970. .FirstAsync();
  971. if (hotelInfo == null) //ccp表 Add
  972. {
  973. }
  974. else //ccp表 Edit
  975. {
  976. _CreditCardPayment.Id = hotelInfo.Id;
  977. int creditCardStatus = await _sqlSugar.Updateable<Grp_CreditCardPayment>(_CreditCardPayment)
  978. .UpdateColumns(it => new
  979. {
  980. it.CTDId,
  981. it.PayDId,
  982. it.ConsumptionPatterns,
  983. it.ConsumptionDate,
  984. it.PayMoney,
  985. it.PaymentCurrency,
  986. it.PayThenMoney,
  987. it.DayRate,
  988. it.RMBPrice,
  989. it.BankNo,
  990. it.CardholderName,
  991. it.CompanyBankNo,
  992. it.OtherBankName,
  993. it.OtherSideNo,
  994. it.OtherSideName,
  995. it.Payee,
  996. it.OrbitalPrivateTransfer,
  997. it.Remark,
  998. })
  999. .WhereColumns(it => it.Id)
  1000. .ExecuteCommandAsync();
  1001. if (creditCardStatus < 0)
  1002. {
  1003. _result.Msg = "付款信息表修改失败!";
  1004. _sqlSugar.RollbackTran(); //回滚
  1005. return _result;
  1006. }
  1007. }
  1008. _result.Msg = "操作成功!";
  1009. _result.Code = 0;
  1010. _sqlSugar.CommitTran(); // 提交
  1011. }
  1012. else if (_dto.Id < 0) //不正确的Id
  1013. {
  1014. _result.Msg = "请输入正确的数据Id!";
  1015. }
  1016. }
  1017. else
  1018. {
  1019. _result.Msg = "请传入正确的PortType参数,1 Web 2 Android 3 IOS";
  1020. }
  1021. return _result;
  1022. }
  1023. /// <summary>
  1024. /// 酒店预定
  1025. /// Del
  1026. /// </summary>
  1027. /// <returns></returns>
  1028. public async Task<Result> _Del(int id,int userId)
  1029. {
  1030. Grp_HotelReservations _HotelReservations = new Grp_HotelReservations()
  1031. {
  1032. Id = id,
  1033. IsDel = 1,
  1034. DeleteUserId = userId,
  1035. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  1036. };
  1037. int hrStatus = await _sqlSugar.Updateable<Grp_HotelReservations>(_HotelReservations)
  1038. .UpdateColumns(it => new
  1039. {
  1040. it.IsDel,
  1041. it.DeleteUserId,
  1042. it.DeleteTime,
  1043. })
  1044. .WhereColumns(it => it.Id)
  1045. .ExecuteCommandAsync();
  1046. if (hrStatus < 0)
  1047. {
  1048. _result.Msg = "操作失败!";
  1049. return _result;
  1050. }
  1051. _result.Msg = "操作成功!";
  1052. _result.Code = 0;
  1053. return _result;
  1054. }
  1055. }
  1056. }