HotelPriceRepository.cs 58 KB

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