HotelPriceRepository.cs 59 KB

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