HotelPriceRepository.cs 37 KB

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