HotelPriceRepository.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.ViewModels.Groups;
  6. using SqlSugar;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OASystem.Infrastructure.Repositories.Groups
  13. {
  14. public class HotelPriceRepository : BaseRepository<Grp_HotelReservations, Grp_HotelReservations>
  15. {
  16. private readonly IMapper _mapper;
  17. public HotelPriceRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  18. base(sqlSugar)
  19. {
  20. this._mapper = mapper;
  21. }
  22. public async Task<Result> HotelConversionAmounts(HotelReservationsCNYDto dto)
  23. {
  24. Result result = new Result() { Code = -2, Msg = "未知错误" };
  25. try
  26. {
  27. HotelReservationsView reservationsView=new HotelReservationsView();
  28. if ((dto.CardPriceCurrency == dto.GovernmentRentCurrency || dto.GovernmentRent == 0)
  29. && (dto.CardPriceCurrency == dto.CityTaxCurrency || dto.CityTax== 0))
  30. {
  31. reservationsView.CurrencyId = dto.CardPriceCurrency;
  32. reservationsView.Price=Convert.ToDecimal((dto.CardPrice+dto.GovernmentRent+dto.CityTax).ToString("F2"));
  33. reservationsView.CurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == dto.CardPriceCurrency).Name;
  34. }
  35. return result=new Result() { Code = 0, Msg = "查询成功",Data= reservationsView };
  36. }
  37. catch (Exception ex)
  38. {
  39. return result = new Result() { Code = -2, Msg = "未知错误" };
  40. throw;
  41. }
  42. }
  43. public async Task<Result> HotelReservationsByDiId(HotelReservationsByDiIdDto dto)
  44. {
  45. Result result = new Result() { Code = -2, Msg = "未知错误" };
  46. try
  47. {
  48. string UserId = "";
  49. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 76).ToList();
  50. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  51. UserId += gta.UId + ",";
  52. if (!string.IsNullOrWhiteSpace(UserId))
  53. {
  54. UserId = UserId.Substring(0, UserId.Length - 1);
  55. }
  56. else
  57. {
  58. UserId = "0";
  59. }
  60. string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0,UserId);
  61. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  62. int endIndex = startIndex + dto.PageSize - 1;
  63. if (dto.PortType == 1)
  64. {
  65. string sql = string.Format(@"select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  66. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  67. From Grp_HotelReservations h
  68. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  69. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  70. left Join Sys_SetData s1 on h.GTId=s1.Id
  71. left Join Sys_Users u on u.Id=h.CreateUserId {0} order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  72. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  73. foreach (var item in hotelDataList)
  74. {
  75. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  76. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  77. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  78. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  79. }
  80. return result = new Result() { Code = 0, Msg = "查询成功!", Data = hotelDataList };
  81. }
  82. else if (dto.PortType == 2 || dto.PortType == 3)
  83. {
  84. string sql = string.Format(@"Select * From (
  85. 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,
  86. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  87. From Grp_HotelReservations h
  88. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  89. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  90. left Join Sys_SetData s1 on h.GTId=s1.Id
  91. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  92. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  93. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  94. foreach (var item in hotelDataList)
  95. {
  96. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  97. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  98. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  99. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  100. }
  101. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  102. Select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  103. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  104. From Grp_HotelReservations h
  105. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  106. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  107. left Join Sys_SetData s1 on h.GTId=s1.Id
  108. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  109. ) temp", sqlWhere);
  110. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  111. int count = dataCount.Count;
  112. float totalPage = (float)count / dto.PageSize;//总页数
  113. if (totalPage == 0) totalPage = 1;
  114. else totalPage = (int)Math.Ceiling((double)totalPage);
  115. ListViewBase<HotelReservationsByDiIdView> rst = new ListViewBase<HotelReservationsByDiIdView>();
  116. rst.DataList = hotelDataList;
  117. rst.DataCount = count;
  118. rst.CurrPageIndex = dto.PageIndex;
  119. rst.CurrPageSize = dto.PageSize;
  120. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  121. }
  122. else
  123. {
  124. return result = new Result() { Code = -2, Msg = "请传入PortType参数,1 Web 2 Android 3 IOS" };
  125. }
  126. }
  127. catch (Exception ex)
  128. {
  129. return result = new Result() { Code = -2, Msg = "未知错误" };
  130. throw;
  131. }
  132. }
  133. public async Task<Result> HotelReservationsById(HotelReservationsByIdDto dto)
  134. {
  135. Result result = new Result() { Code = -2, Msg = "未知错误" };
  136. try
  137. {
  138. Grp_HotelReservations hotelReservationsById = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  139. HotelReservationsByIdView _hotelReservations = _mapper.Map<HotelReservationsByIdView>(hotelReservationsById);
  140. if (_hotelReservations!=null)
  141. {
  142. Sys_SetData GTId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GTId);
  143. if (GTId != null) _hotelReservations.GtIdStr = GTId.Name;
  144. _hotelReservations.CheckInDate=Convert.ToDateTime(hotelReservationsById.CheckInDate).ToString("yyyy-MM-dd");
  145. _hotelReservations.CheckOutDate = Convert.ToDateTime(hotelReservationsById.CheckOutDate).ToString("yyyy-MM-dd");
  146. Sys_SetData GovernmentRentCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GovernmentRentCurrency);
  147. if (GovernmentRentCurrencyStr != null) _hotelReservations.GovernmentRentCurrencyStr = GovernmentRentCurrencyStr.Name;
  148. Sys_SetData CityTaxCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.CityTaxCurrency);
  149. if (CityTaxCurrencyStr != null) _hotelReservations.CityTaxCurrencyStr = CityTaxCurrencyStr.Name;
  150. if (_hotelReservations.CheckType == "") _hotelReservations.CheckTypeStr = "客人房";
  151. else if (_hotelReservations.CheckType == "D") _hotelReservations.CheckTypeStr = "司机房";
  152. else if (_hotelReservations.CheckType == "G") _hotelReservations.CheckTypeStr = "导游房";
  153. else if (_hotelReservations.CheckType == "D&G") _hotelReservations.CheckTypeStr = "司机导游房";
  154. }
  155. string Sql = string.Format(@"select c.PayDId, s.Name asPayDIdStr,c.ConsumptionPatterns,c.ConsumptionDate,c.CTDId,
  156. s1.Name as CTDIdStr,c.BankNo,c.CardholderName,c.PayMoney,c.PaymentCurrency,s2.Name
  157. as PaymentCurrencyStr,c.DayRate,c.CompanyBankNo,c.OtherBankName,c.OtherSideNo,c.OtherSideName,
  158. c.IsAuditGM,c.Payee,c.RMBPrice,c.OrbitalPrivateTransfer from Grp_CreditCardPayment c
  159. left join Sys_SetData s on c.PayDId=s.Id
  160. left join Sys_SetData s1 on c.CTDId=s1.Id
  161. left join Sys_SetData s2 on c.PaymentCurrency=s2.Id
  162. where c.CId ={0} and c.IsDel = 0 and c.CTable = 76",dto.Id);
  163. Grp_CreditCardView _CreditCardPayment = _sqlSugar.SqlQueryable<Grp_CreditCardView>(Sql).First();
  164. if (_CreditCardPayment!=null)
  165. {
  166. if(!string.IsNullOrWhiteSpace(_CreditCardPayment.ConsumptionDate)) _CreditCardPayment.ConsumptionDate=Convert.ToDateTime(_CreditCardPayment.ConsumptionDate).ToString("yyyy-MM-dd");
  167. }
  168. var data = new
  169. {
  170. hotelReservations = _hotelReservations,
  171. creditCardPayment = _CreditCardPayment,
  172. };
  173. return result = new Result() { Code = 0, Msg = "查询成功",Data= data };
  174. }
  175. catch (Exception ex)
  176. {
  177. return result = new Result() { Code = -2, Msg = "未知错误" };
  178. throw;
  179. }
  180. }
  181. public async Task<Result> HotelReservationsInitialize(HotelReservationsDto dto)
  182. {
  183. Result result = new Result() { Code = -2, Msg = "未知错误" };
  184. try
  185. {
  186. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 76).ToList();
  187. string DiId = "0";
  188. foreach (var item in grp_GroupsTaskAssignment)
  189. {
  190. DiId += item.DIId + ",";
  191. }
  192. if (DiId != "0")
  193. {
  194. DiId = DiId.Substring(0, DiId.Length - 1);
  195. }
  196. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  197. //团组下拉框
  198. List<Grp_DelegationInfo> Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  199. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(Delegations);
  200. for (int i = 0;i< grp_Delegations.Count; i++)
  201. {
  202. grp_Delegations[i].VisitDate = Delegations[i].VisitStartDate.ToString("yyyy-MM-dd")+"至"+ Delegations[i].VisitEndDate.ToString("yyyy-MM-dd");
  203. }
  204. //客人类型
  205. List<Sys_SetData> GuestType = _sqlSugar.Queryable<Sys_SetData>().Where(a=>a.IsDel==0 && a.STid==11).ToList();
  206. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  207. //支付方式
  208. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  209. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  210. //币种
  211. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  212. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  213. //卡类型
  214. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  215. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  216. //预订网站
  217. List<Sys_SetData> BookingWebsite = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 12 && a.IsDel == 0).ToList();
  218. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  219. var data = new
  220. {
  221. Delegations = grp_Delegations,
  222. GuestType = _GuestType,
  223. Payment = _Payment,
  224. CurrencyList = _CurrencyList,
  225. BankCard = _BankCard,
  226. BookingWebsite = _BookingWebsite,
  227. };
  228. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  229. }
  230. catch (Exception ex)
  231. {
  232. return result = new Result() { Code = -2, Msg = "未知错误" };
  233. throw;
  234. }
  235. }
  236. public async Task<Result> OpHotelReservations(OpHotelReservationsData dto)
  237. {
  238. throw new NotImplementedException();
  239. }
  240. }
  241. }