HotelPriceRepository.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. public HotelPriceRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  27. base(sqlSugar)
  28. {
  29. this._mapper = mapper;
  30. _result = new Result() { Code = -1, Msg = "操作失败!" };
  31. }
  32. #region 保留
  33. /// <summary>
  34. /// 付款金额计算
  35. /// </summary>
  36. /// <param name="dto"></param>
  37. /// <returns></returns>
  38. public async Task<Result> HotelConversionAmounts(HotelReservationsCNYDto dto)
  39. {
  40. Result result = new Result() { Code = -2, Msg = "未知错误" };
  41. try
  42. {
  43. HotelReservationsView reservationsView=new HotelReservationsView();
  44. if ((dto.CardPriceCurrency == dto.GovernmentRentCurrency || dto.GovernmentRent == 0)
  45. && (dto.CardPriceCurrency == dto.CityTaxCurrency || dto.CityTax== 0))
  46. {
  47. reservationsView.CurrencyId = dto.CardPriceCurrency;
  48. reservationsView.Price=Convert.ToDecimal((dto.CardPrice+dto.GovernmentRent+dto.CityTax).ToString("F2"));
  49. reservationsView.CurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == dto.CardPriceCurrency).Name;
  50. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  51. }
  52. else
  53. {
  54. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  55. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  56. decimal CardPrice = 0.00M;
  57. decimal GovernmentRent = 0.00M;
  58. decimal CityTax = 0.00M;
  59. if (_TeamRate != null)
  60. {
  61. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CardPriceCurrency);
  62. if (_SetData != null)
  63. {
  64. if (_SetData.Name=="CNY")
  65. {
  66. CardPrice = dto.CardPrice;
  67. }
  68. else
  69. {
  70. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  71. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  72. if (CurrencyRate != null) CardPrice = dto.CardPrice * Convert.ToDecimal(CurrencyRate.Rate);
  73. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  74. }
  75. }
  76. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  77. Sys_SetData _SetData1 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.GovernmentRentCurrency);
  78. if (_SetData1 != null)
  79. {
  80. if (_SetData1.Name == "CNY")
  81. {
  82. GovernmentRent = dto.GovernmentRent;
  83. }
  84. else {
  85. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  86. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData1.Name);
  87. if (CurrencyRate != null) GovernmentRent = dto.GovernmentRent * Convert.ToDecimal(CurrencyRate.Rate);
  88. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  89. }
  90. }
  91. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  92. Sys_SetData _SetData2 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CityTaxCurrency);
  93. if (_SetData2 != null)
  94. {
  95. if (_SetData2.Name == "CNY")
  96. {
  97. CityTax = dto.CityTax;
  98. }
  99. else
  100. {
  101. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  102. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData2.Name);
  103. if (CurrencyRate != null) CityTax = dto.CityTax * Convert.ToDecimal(CurrencyRate.Rate);
  104. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  105. }
  106. }
  107. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  108. reservationsView.CurrencyId = 836;
  109. reservationsView.Price = Convert.ToDecimal((CardPrice + GovernmentRent + CityTax).ToString("F2"));
  110. reservationsView.CurrencyName ="CNY";
  111. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  112. }
  113. else
  114. {
  115. return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data= reservationsView };
  116. }
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. return result = new Result() { Code = -2, Msg = "未知错误" };
  122. throw;
  123. }
  124. }
  125. /// <summary>
  126. /// 根据团组id查询酒店数据
  127. /// </summary>
  128. /// <param name="dto"></param>
  129. /// <returns></returns>
  130. public async Task<Result> HotelReservationsByDiId(HotelReservationsByDiIdDto dto)
  131. {
  132. Result result = new Result() { Code = -2, Msg = "未知错误" };
  133. try
  134. {
  135. string UserId = "";
  136. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 76).ToList();
  137. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  138. UserId += gta.UId + ",";
  139. if (!string.IsNullOrWhiteSpace(UserId))
  140. {
  141. UserId = UserId.Substring(0, UserId.Length - 1);
  142. }
  143. else
  144. {
  145. UserId = "0";
  146. }
  147. string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0,UserId);
  148. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  149. int endIndex = startIndex + dto.PageSize - 1;
  150. if (dto.PortType == 1)
  151. {
  152. string sql = string.Format(@"select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  153. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  154. From Grp_HotelReservations h
  155. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  156. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  157. left Join Sys_SetData s1 on h.GTId=s1.Id
  158. left Join Sys_Users u on u.Id=h.CreateUserId {0} order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  159. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  160. foreach (var item in hotelDataList)
  161. {
  162. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  163. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  164. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  165. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  166. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  167. {
  168. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  169. }
  170. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  171. {
  172. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  173. }
  174. }
  175. return result = new Result() { Code = 0, Msg = "查询成功!", Data = hotelDataList };
  176. }
  177. else if (dto.PortType == 2 || dto.PortType == 3)
  178. {
  179. string sql = string.Format(@"Select * From (
  180. 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,
  181. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  182. From Grp_HotelReservations h
  183. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  184. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  185. left Join Sys_SetData s1 on h.GTId=s1.Id
  186. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  187. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  188. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  189. foreach (var item in hotelDataList)
  190. {
  191. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  192. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  193. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  194. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  195. if (!string.IsNullOrWhiteSpace(item.CheckInDate))
  196. {
  197. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  198. }
  199. if (!string.IsNullOrWhiteSpace(item.CheckOutDate))
  200. {
  201. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  202. }
  203. }
  204. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  205. Select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  206. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  207. From Grp_HotelReservations h
  208. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  209. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  210. left Join Sys_SetData s1 on h.GTId=s1.Id
  211. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  212. ) temp", sqlWhere);
  213. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  214. int count = dataCount.Count;
  215. float totalPage = (float)count / dto.PageSize;//总页数
  216. if (totalPage == 0) totalPage = 1;
  217. else totalPage = (int)Math.Ceiling((double)totalPage);
  218. ListViewBase<HotelReservationsByDiIdView> rst = new ListViewBase<HotelReservationsByDiIdView>();
  219. rst.DataList = hotelDataList;
  220. rst.DataCount = count;
  221. rst.CurrPageIndex = dto.PageIndex;
  222. rst.CurrPageSize = dto.PageSize;
  223. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  224. }
  225. else
  226. {
  227. return result = new Result() { Code = -2, Msg = "请传入PortType参数,1 Web 2 Android 3 IOS" };
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. return result = new Result() { Code = -2, Msg = "未知错误" };
  233. throw;
  234. }
  235. }
  236. /// <summary>
  237. /// 根据酒店费用Id查询详细数据
  238. /// </summary>
  239. /// <param name="dto"></param>
  240. /// <returns></returns>
  241. public async Task<Result> HotelReservationsById(HotelReservationsByIdDto dto)
  242. {
  243. Result result = new Result() { Code = -2, Msg = "未知错误" };
  244. try
  245. {
  246. Grp_HotelReservations hotelReservationsById = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  247. HotelReservationsByIdView _hotelReservations = _mapper.Map<HotelReservationsByIdView>(hotelReservationsById);
  248. if (_hotelReservations!=null)
  249. {
  250. Sys_SetData GTId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GTId);
  251. if (GTId != null) _hotelReservations.GtIdStr = GTId.Name;
  252. if (!string.IsNullOrWhiteSpace(_hotelReservations.CheckInDate))
  253. {
  254. _hotelReservations.CheckInDate = Convert.ToDateTime(hotelReservationsById.CheckInDate).ToString("yyyy-MM-dd");
  255. }
  256. if (!string.IsNullOrWhiteSpace(_hotelReservations.CheckOutDate))
  257. {
  258. _hotelReservations.CheckOutDate = Convert.ToDateTime(hotelReservationsById.CheckOutDate).ToString("yyyy-MM-dd");
  259. }
  260. Sys_SetData GovernmentRentCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GovernmentRentCurrency);
  261. if (GovernmentRentCurrencyStr != null) _hotelReservations.GovernmentRentCurrencyStr = GovernmentRentCurrencyStr.Name;
  262. Sys_SetData CityTaxCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.CityTaxCurrency);
  263. if (CityTaxCurrencyStr != null) _hotelReservations.CityTaxCurrencyStr = CityTaxCurrencyStr.Name;
  264. if (_hotelReservations.CheckType == "") _hotelReservations.CheckTypeStr = "客人房";
  265. else if (_hotelReservations.CheckType == "D") _hotelReservations.CheckTypeStr = "司机房";
  266. else if (_hotelReservations.CheckType == "G") _hotelReservations.CheckTypeStr = "导游房";
  267. else if (_hotelReservations.CheckType == "D&G") _hotelReservations.CheckTypeStr = "司机导游房";
  268. }
  269. string Sql = string.Format(@"select c.PayDId, s.Name asPayDIdStr,c.ConsumptionPatterns,c.ConsumptionDate,c.CTDId,
  270. s1.Name as CTDIdStr,c.BankNo,c.CardholderName,c.PayMoney,c.PaymentCurrency,s2.Name
  271. as PaymentCurrencyStr,c.DayRate,c.CompanyBankNo,c.OtherBankName,c.OtherSideNo,c.OtherSideName,
  272. c.IsAuditGM,c.Payee,c.RMBPrice,c.OrbitalPrivateTransfer,c.Remark from Grp_CreditCardPayment c
  273. left join Sys_SetData s on c.PayDId=s.Id
  274. left join Sys_SetData s1 on c.CTDId=s1.Id
  275. left join Sys_SetData s2 on c.PaymentCurrency=s2.Id
  276. where c.CId ={0} and c.IsDel = 0 and c.CTable = 76", dto.Id);
  277. Grp_CreditCardView _CreditCardPayment = _sqlSugar.SqlQueryable<Grp_CreditCardView>(Sql).First();
  278. if (_CreditCardPayment!=null)
  279. {
  280. if(!string.IsNullOrWhiteSpace(_CreditCardPayment.ConsumptionDate)) _CreditCardPayment.ConsumptionDate=Convert.ToDateTime(_CreditCardPayment.ConsumptionDate).ToString("yyyy-MM-dd");
  281. }
  282. var data = new
  283. {
  284. hotelReservations = _hotelReservations,
  285. creditCardPayment = _CreditCardPayment,
  286. };
  287. return result = new Result() { Code = 0, Msg = "查询成功",Data= data };
  288. }
  289. catch (Exception ex)
  290. {
  291. return result = new Result() { Code = -2, Msg = "未知错误" };
  292. throw;
  293. }
  294. }
  295. /// <summary>
  296. /// 酒店页面下拉框等初始化
  297. /// </summary>
  298. /// <param name="dto"></param>
  299. /// <returns></returns>
  300. public async Task<Result> HotelReservationsInitialize(HotelReservationsDto dto)
  301. {
  302. Result result = new Result() { Code = -2, Msg = "未知错误" };
  303. try
  304. {
  305. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 76).ToList();
  306. string DiId = "0";
  307. foreach (var item in grp_GroupsTaskAssignment)
  308. {
  309. DiId += item.DIId + ",";
  310. }
  311. if (DiId != "0")
  312. {
  313. DiId = DiId.Substring(0, DiId.Length - 1);
  314. }
  315. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  316. //团组下拉框
  317. List<Grp_DelegationInfo> Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  318. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(Delegations);
  319. for (int i = 0;i< grp_Delegations.Count; i++)
  320. {
  321. grp_Delegations[i].VisitDate = Delegations[i].VisitStartDate.ToString("yyyy-MM-dd")+"至"+ Delegations[i].VisitEndDate.ToString("yyyy-MM-dd");
  322. }
  323. //客人类型
  324. List<Sys_SetData> GuestType = _sqlSugar.Queryable<Sys_SetData>().Where(a=>a.IsDel==0 && a.STid==11).ToList();
  325. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  326. //支付方式
  327. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  328. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  329. //币种
  330. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  331. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  332. //卡类型
  333. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  334. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  335. //预订网站
  336. List<Sys_SetData> BookingWebsite = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 12 && a.IsDel == 0).ToList();
  337. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  338. if (dto.PortType==2 || dto.PortType==3)
  339. {
  340. GeneralTeamRateInfoDto PostGroupTeamRatedto = new GeneralTeamRateInfoDto();
  341. PostGroupTeamRatedto.DiId= dto.DiId;
  342. PostGroupTeamRatedto.CTable = 76;
  343. PostGroupTeamRatedto.PortType= dto.PortType;
  344. Result teamRateDescAddCurrencyIdViews = PostGroupTeamRateByDiIdAndCTableId(PostGroupTeamRatedto);
  345. List<TeamRateDescAddCurrencyIdView> Currency=new List<TeamRateDescAddCurrencyIdView>();
  346. if (teamRateDescAddCurrencyIdViews.Code==0)
  347. {
  348. Currency = teamRateDescAddCurrencyIdViews.Data;
  349. }
  350. var data = new
  351. {
  352. GuestType = _GuestType,
  353. Payment = _Payment,
  354. CurrencyList = Currency,
  355. BankCard = _BankCard,
  356. BookingWebsite = _BookingWebsite,
  357. };
  358. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  359. }
  360. else
  361. {
  362. var data = new
  363. {
  364. Delegations = grp_Delegations,
  365. GuestType = _GuestType,
  366. Payment = _Payment,
  367. CurrencyList = _CurrencyList,
  368. BankCard = _BankCard,
  369. BookingWebsite = _BookingWebsite,
  370. };
  371. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  372. }
  373. }
  374. catch (Exception ex)
  375. {
  376. return result = new Result() { Code = -2, Msg = "未知错误" };
  377. throw;
  378. }
  379. }
  380. /// <summary>
  381. /// 酒店操作
  382. /// </summary>
  383. /// <param name="dto"></param>
  384. /// <returns></returns>
  385. /// <exception cref="NotImplementedException"></exception>
  386. public async Task<Result> OpHotelReservations(OpHotelReservationsData dto)
  387. {
  388. Result result = new Result() { Code = -2, Msg = "未知错误" };
  389. try
  390. {
  391. BeginTran();
  392. int id = dto.Id;
  393. Grp_HotelReservations hotelPrice = _mapper.Map<Grp_HotelReservations>(dto);
  394. hotelPrice.IsCardPrice = hotelPrice.CardPrice!=0 ? 1:0;
  395. hotelPrice.CboOne=hotelPrice.SingleRoomCount !=0 ? 1 : 0;
  396. hotelPrice.CboTwo = hotelPrice.DoubleRoomCount != 0 ? 1 : 0;
  397. hotelPrice.CboThree = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  398. hotelPrice.CboFour = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  399. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  400. c.Remark = dto.CRemark;
  401. c.PayPercentage = 100;
  402. c.CTable = 76;
  403. c.CId = id;
  404. c.IsAuditGM = 0;
  405. if (c.PayDId == 72)
  406. {
  407. c.IsPay = 1;
  408. }
  409. c.RMBPrice = c.PayMoney;
  410. c.DayRate = 1;
  411. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  412. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  413. if (_TeamRate != null)
  414. {
  415. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  416. if (_SetData != null)
  417. {
  418. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  419. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  420. if (CurrencyRate != null)
  421. {
  422. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  423. c.DayRate = CurrencyRate.Rate;
  424. }
  425. }
  426. }
  427. if (dto.Status == 1)//添加
  428. {
  429. Grp_HotelReservations grp_Hotel = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.HotelName == dto.HotelName && a.GuestName == dto.GuestName &&
  430. a.CheckInDate == dto.CheckInDate && a.CheckOutDate==dto.CheckOutDate && a.City==dto.City);
  431. if (grp_Hotel != null)
  432. {
  433. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  434. }
  435. else
  436. {
  437. id = await AddAsyncReturnId(hotelPrice);
  438. if (id != 0)
  439. {
  440. c.CId = id;
  441. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  442. if (cId != 0)
  443. {
  444. result = new Result() { Code = 0, Msg = "添加成功!" };
  445. }
  446. else
  447. {
  448. RollbackTran();
  449. result = new Result() { Code = -1, Msg = "添加失败!" };
  450. }
  451. }
  452. else
  453. {
  454. RollbackTran();
  455. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  456. }
  457. }
  458. }
  459. else if (dto.Status == 2)//修改
  460. {
  461. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_HotelReservations
  462. {
  463. GTId=hotelPrice.GTId,
  464. CheckNumber=hotelPrice.CheckNumber,
  465. ReservationsWebsite=hotelPrice.ReservationsWebsite,
  466. ReservationsNo=hotelPrice.ReservationsNo,
  467. DetermineNo=hotelPrice.DetermineNo,
  468. City=hotelPrice.City,
  469. HotelName=hotelPrice.HotelName,
  470. HotelAddress=hotelPrice.HotelAddress,
  471. HotelTel=hotelPrice.HotelTel,
  472. GuestName=hotelPrice.GuestName,
  473. CheckInDate=hotelPrice.CheckInDate,
  474. BudgetCurrency=hotelPrice.BudgetCurrency,
  475. CheckOutDate=hotelPrice.CheckOutDate,
  476. SingleRoomCount=hotelPrice.SingleRoomCount,
  477. SingleRoomPrice=hotelPrice.SingleRoomPrice,
  478. DoubleRoomCount=hotelPrice.DoubleRoomCount,
  479. DoubleRoomPrice=hotelPrice.DoubleRoomPrice,
  480. SuiteRoomCount=hotelPrice.SuiteRoomCount,
  481. SuiteRoomPrice=hotelPrice.SuiteRoomPrice,
  482. OtherRoomCount=hotelPrice.OtherRoomCount,
  483. OtherRoomPrice=hotelPrice.OtherRoomPrice,
  484. RoomExplanation=hotelPrice.RoomExplanation,
  485. Attachment=hotelPrice.Attachment,
  486. CardPrice=hotelPrice.CardPrice,
  487. CardPriceCurrency=hotelPrice.CardPriceCurrency,
  488. IsCardPrice =hotelPrice.IsCardPrice,
  489. PredictSingleRoom=hotelPrice.PredictSingleRoom,
  490. PredictDoubleRoom=hotelPrice.PredictDoubleRoom,
  491. PredictSuiteRoom=hotelPrice.PredictSuiteRoom,
  492. PredictOtherRoom=hotelPrice.PredictOtherRoom,
  493. GovernmentRent=hotelPrice.GovernmentRent,
  494. GovernmentRentCurrency=hotelPrice.GovernmentRentCurrency,
  495. CityTax=hotelPrice.CityTax,
  496. CityTaxCurrency=hotelPrice.CityTaxCurrency,
  497. CheckType=hotelPrice.CheckType,
  498. CboOne=hotelPrice.SingleRoomCount,
  499. CboTwo=hotelPrice.DoubleRoomCount,
  500. CboThree=hotelPrice.SuiteRoomCount,
  501. CboFour=hotelPrice.SuiteRoomCount,
  502. CreateUserId=hotelPrice.CreateUserId,
  503. Remark=hotelPrice.Remark
  504. });
  505. if (res)
  506. {
  507. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == hotelPrice.Id && a.CTable == 76).SetColumns(a => new Grp_CreditCardPayment
  508. {
  509. PayDId = dto.PayDId,
  510. PayMoney = c.PayMoney,
  511. PaymentCurrency = c.PaymentCurrency,
  512. Payee = c.Payee,
  513. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  514. DayRate = c.DayRate,
  515. RMBPrice = c.RMBPrice,
  516. ConsumptionPatterns = c.ConsumptionPatterns,
  517. ConsumptionDate = c.ConsumptionDate,
  518. CTDId = c.CTDId,
  519. CompanyBankNo = c.CompanyBankNo,
  520. OtherBankName = c.OtherBankName,
  521. OtherSideNo = c.OtherSideNo,
  522. OtherSideName = c.OtherSideName,
  523. BankNo = c.BankNo,
  524. CardholderName = c.CardholderName,
  525. Remark = c.Remark,
  526. }).ExecuteCommandAsync();
  527. if (CTable==0)
  528. {
  529. result = new Result() { Code = -1, Msg = "修改失败!" };
  530. RollbackTran();
  531. }
  532. else
  533. {
  534. result = new Result() { Code = 0, Msg = "修改成功!" };
  535. }
  536. }
  537. else
  538. {
  539. RollbackTran();
  540. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  541. }
  542. }
  543. CommitTran();
  544. }
  545. catch (Exception ex)
  546. {
  547. return result = new Result() { Code = -2, Msg = "未知错误" };
  548. throw;
  549. }
  550. return result;
  551. }
  552. public Result PostGroupTeamRateByDiIdAndCTableId(GeneralTeamRateInfoDto dto)
  553. {
  554. Result result = new Result() { Code = -2, Msg = "未知错误" };
  555. try
  556. {
  557. if (dto == null)
  558. {
  559. return result = new Result() { Code = -2, Msg = "请输入参数" };
  560. }
  561. if (dto.DiId == 0)
  562. {
  563. return result = new Result() { Code = -2, Msg = "请输入正确的团组Id!" };
  564. }
  565. if (dto.CTable == 0)
  566. {
  567. return result = new Result() { Code = -2, Msg = "请输入正确的业务类型(CTable)Id!" };
  568. }
  569. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  570. {
  571. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  572. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  573. Where tr.IsDel = 0 And tr.DiId = {0} And tr.CTable = {1}", dto.DiId, dto.CTable);
  574. var teamRateInfo = _sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToList();
  575. #region 团组汇率
  576. TeamRateModelGeneralView teamRateModels = new TeamRateModelGeneralView();
  577. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  578. #region 获取所有币种
  579. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  580. List<SetDataInfoView> DBdata = _sqlSugar.SqlQueryable<SetDataInfoView>(sql).ToList();
  581. if (DBdata == null || DBdata.Count == 0)
  582. {
  583. return result = new Result() { Code = -2, Msg = "所有币种获取失败!" };
  584. }
  585. currencyDatas = DBdata.Select(x => new SetDataInfoView
  586. {
  587. Name = x.Name,
  588. Id = x.Id,
  589. Remark = x.Remark,
  590. }).ToList();
  591. #endregion
  592. List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
  593. foreach (TeamRateInfoView item in teamRateInfo)
  594. {
  595. #region 拆分remark里的汇率
  596. if (item.Remark.Contains("|"))
  597. {
  598. string[] currencyArr = item.Remark.Split("|");
  599. foreach (string currency in currencyArr)
  600. {
  601. string[] currency1 = currency.Split(":");
  602. string[] currency2 = currency1[0].Split("(");
  603. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  604. SetDataInfoView dataInfoView = new SetDataInfoView();
  605. dataInfoView = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault();
  606. int currencyId = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault().Id;
  607. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  608. {
  609. CurrencyId = dataInfoView.Id,
  610. CurrencyCode = currencyCode,
  611. CurrencyName = currency2[0],
  612. Rate = decimal.Parse(currency1[1]),
  613. };
  614. teamRateDescViews.Add(rateDescView);
  615. }
  616. }
  617. #endregion
  618. if (teamRateDescViews.Count > 0)
  619. {
  620. teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
  621. }
  622. }
  623. #endregion
  624. return result = new Result() { Code = 0, Msg = "操作成功!",Data= teamRateDescViews };
  625. }
  626. else
  627. {
  628. return result = new Result() { Code = -2, Msg = "请输入正确的端口号! 1 Web 2 Android 3 Ios;" };
  629. }
  630. }
  631. catch (Exception ex)
  632. {
  633. return result = new Result() { Code = -2, Msg = "未知错误" };
  634. }
  635. }
  636. #endregion
  637. /// <summary>
  638. /// 酒店预定费用
  639. /// Items By DiId
  640. /// </summary>
  641. /// <param name="dto"></param>
  642. /// <returns></returns>
  643. public async Task<Result> _ItemsByDiId(int portType,int diId)
  644. {
  645. string sql = string.Format(@"Select row_number() over(order by hr.CreateTime Desc) as Row_Number,
  646. hr.Id,hr.DiId,sd1.Name As GuestType,hr.ReservationsNo,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  647. ccp.PayMoney, ccp.PaymentCurrency,sd2.Name PayCurrency,hr.CreateUserId,u.CnName As CreateUserName,
  648. hr.CreateTime,ccp.IsAuditGM
  649. From Grp_HotelReservations hr
  650. Inner Join Grp_CreditCardPayment ccp On hr.DiId = ccp.DIId And hr.Id = ccp.CId
  651. And ccp.CTable = 76
  652. Left Join Sys_SetData sd1 On hr.GTId = sd1.Id
  653. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  654. Left Join Sys_Users u On hr.CreateUserId = u.Id
  655. Where hr.IsDel = 0 And ccp.IsDel = 0 And hr.DiId = {0} ", diId);
  656. if (portType == 1 || portType == 2 || portType == 3)
  657. {
  658. var hotelFeeData = await _sqlSugar.SqlQueryable<HotelReservationsItemsView>(sql).ToListAsync();
  659. _result.Code = 0;
  660. _result.Data = hotelFeeData;
  661. _result.Msg = "操作成功!";
  662. }
  663. else
  664. {
  665. _result.Msg = "请传入正确的PortType参数,1 Web 2 Android 3 IOS";
  666. }
  667. return _result;
  668. }
  669. /// <summary>
  670. /// 酒店预定
  671. /// basicsData Init
  672. /// </summary>
  673. /// <param name="dto"></param>
  674. /// <returns></returns>
  675. public async Task<Result> _BasicsDataInit(int portType, int diId)
  676. {
  677. List<Sys_SetData> _dataSouruce = await _sqlSugar.Queryable<Sys_SetData>().Where(a => a.IsDel == 0).ToListAsync();
  678. if (portType == 1 || portType == 2 || portType == 3)
  679. {
  680. //客人类型
  681. List<Sys_SetData> GuestType = _dataSouruce.Where(a => a.STid == 11).ToList();
  682. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  683. //预订网站
  684. List<Sys_SetData> BookingWebsite = _dataSouruce.Where(a => a.STid == 12).ToList();
  685. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  686. //支付方式
  687. List<Sys_SetData> Payment = _dataSouruce.Where(a => a.STid == 14).ToList();
  688. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  689. //卡类型
  690. List<Sys_SetData> BankCard = _dataSouruce.Where(a => a.STid == 15).ToList();
  691. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  692. GeneralTeamRateInfoDto postGroupTeamRatedto = new GeneralTeamRateInfoDto()
  693. {
  694. DiId = diId,
  695. CTable = 76, //酒店预定
  696. PortType = portType
  697. };
  698. Result teamRateDescAddCurrencyIdViews = PostGroupTeamRateByDiIdAndCTableId(postGroupTeamRatedto);
  699. List<TeamRateDescAddCurrencyIdView> TeamCurrencyRate = new List<TeamRateDescAddCurrencyIdView>();
  700. if (teamRateDescAddCurrencyIdViews.Code == 0)
  701. {
  702. TeamCurrencyRate = teamRateDescAddCurrencyIdViews.Data;
  703. }
  704. var data = new
  705. {
  706. GuestType = _GuestType,
  707. Payment = _Payment,
  708. CurrencyList = TeamCurrencyRate,
  709. BankCard = _BankCard,
  710. BookingWebsite = _BookingWebsite,
  711. };
  712. _result.Code = 0;
  713. _result.Data = data;
  714. _result.Msg = "操作成功!";
  715. }
  716. else
  717. {
  718. _result.Msg = "请传入正确的PortType参数,1 Web 2 Android 3 IOS!";
  719. }
  720. return _result;
  721. }
  722. /// <summary>
  723. /// 酒店预定
  724. /// details
  725. /// </summary>
  726. /// <param name="dto"></param>
  727. /// <returns></returns>
  728. public async Task<Result> _Details(int portType, int id)
  729. {
  730. if (id < 0 )
  731. {
  732. _result.Msg = string.Format(@"请输入正确的Id!");
  733. return _result;
  734. }
  735. string sql = string.Format(@"Select hr.Id,hr.DiId,hr.GTId,hr.CardPriceCurrency,hr.CheckNumber,hr.ReservationsWebsite,hr.ReservationsNo,
  736. hr.City,hr.HotelName,hr.HotelTel,hr.HotelAddress,hr.GuestName,hr.CheckInDate,hr.CheckOutDate,hr.CheckType,
  737. hr.RoomExplanation,hr.Remark As HotelRemark,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  738. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,hr.CardPrice,
  739. hr.Isoppay,hr.BreakfastPrice,hr.BreakfastCurrency,hr.GovernmentRent,hr.GovernmentRentCurrency,hr.CityTax,
  740. hr.CityTaxCurrency,ccp.PayDId,ccp.ConsumptionPatterns,ccp.ConsumptionDate,ccp.PayMoney,ccp.PaymentCurrency,
  741. ccp.OtherBankName,ccp.OtherSideNo,ccp.OtherSideName,ccp.Payee,ccp.OrbitalPrivateTransfer,ccp.Remark As CcpRemark
  742. From Grp_HotelReservations hr
  743. Inner Join Grp_CreditCardPayment ccp On hr.DiId = ccp.DIId And hr.Id = ccp.CId
  744. And ccp.CTable = 76
  745. Where hr.IsDel = 0 And ccp.IsDel = 0 And hr.Id = {0}", id);
  746. if (portType == 1 || portType == 2 || portType == 3)
  747. {
  748. var info = await _sqlSugar.SqlQueryable<HotelReservationsDetailsView>(sql).FirstAsync();
  749. if (info != null) _result.Msg = "操作成功!";
  750. else _result.Msg = "暂无数据";
  751. _result.Code = 0;
  752. _result.Data = info;
  753. return _result;
  754. }
  755. else
  756. {
  757. _result.Msg = "请传入正确的PortType参数,1 Web 2 Android 3 IOS";
  758. return _result;
  759. }
  760. }
  761. }
  762. }