HotelPriceRepository.cs 42 KB

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