HotelPriceRepository.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Financial;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Infrastructure.Tools;
  8. using SqlSugar;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace OASystem.Infrastructure.Repositories.Groups
  15. {
  16. public class HotelPriceRepository : BaseRepository<Grp_HotelReservations, Grp_HotelReservations>
  17. {
  18. private readonly IMapper _mapper;
  19. public HotelPriceRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  20. base(sqlSugar)
  21. {
  22. this._mapper = mapper;
  23. }
  24. /// <summary>
  25. /// 付款金额计算
  26. /// </summary>
  27. /// <param name="dto"></param>
  28. /// <returns></returns>
  29. public async Task<Result> HotelConversionAmounts(HotelReservationsCNYDto dto)
  30. {
  31. Result result = new Result() { Code = -2, Msg = "未知错误" };
  32. try
  33. {
  34. HotelReservationsView reservationsView=new HotelReservationsView();
  35. if ((dto.CardPriceCurrency == dto.GovernmentRentCurrency || dto.GovernmentRent == 0)
  36. && (dto.CardPriceCurrency == dto.CityTaxCurrency || dto.CityTax== 0))
  37. {
  38. reservationsView.CurrencyId = dto.CardPriceCurrency;
  39. reservationsView.Price=Convert.ToDecimal((dto.CardPrice+dto.GovernmentRent+dto.CityTax).ToString("F2"));
  40. reservationsView.CurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == dto.CardPriceCurrency).Name;
  41. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  42. }
  43. else
  44. {
  45. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  46. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  47. decimal CardPrice = 0.00M;
  48. decimal GovernmentRent = 0.00M;
  49. decimal CityTax = 0.00M;
  50. if (_TeamRate != null)
  51. {
  52. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CardPriceCurrency);
  53. if (_SetData != null)
  54. {
  55. if (_SetData.Name=="CNY")
  56. {
  57. CardPrice = dto.CardPrice;
  58. }
  59. else
  60. {
  61. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  62. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  63. if (CurrencyRate != null) CardPrice = dto.CardPrice * Convert.ToDecimal(CurrencyRate.Rate);
  64. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  65. }
  66. }
  67. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  68. Sys_SetData _SetData1 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.GovernmentRentCurrency);
  69. if (_SetData1 != null)
  70. {
  71. if (_SetData1.Name == "CNY")
  72. {
  73. GovernmentRent = dto.GovernmentRent;
  74. }
  75. else {
  76. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  77. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData1.Name);
  78. if (CurrencyRate != null) GovernmentRent = dto.GovernmentRent * Convert.ToDecimal(CurrencyRate.Rate);
  79. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  80. }
  81. }
  82. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  83. Sys_SetData _SetData2 = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == dto.CityTaxCurrency);
  84. if (_SetData2 != null)
  85. {
  86. if (_SetData2.Name == "CNY")
  87. {
  88. CityTax = dto.CityTax;
  89. }
  90. else
  91. {
  92. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  93. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData2.Name);
  94. if (CurrencyRate != null) CityTax = dto.CityTax * Convert.ToDecimal(CurrencyRate.Rate);
  95. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  96. }
  97. }
  98. else return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data = reservationsView };
  99. reservationsView.CurrencyId = 836;
  100. reservationsView.Price = Convert.ToDecimal((CardPrice + GovernmentRent + CityTax).ToString("F2"));
  101. reservationsView.CurrencyName ="CNY";
  102. return result = new Result() { Code = 0, Msg = "查询成功", Data = reservationsView };
  103. }
  104. else
  105. {
  106. return result = new Result() { Code = -1, Msg = "暂未设置团组汇率,请前往设置!", Data= reservationsView };
  107. }
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. return result = new Result() { Code = -2, Msg = "未知错误" };
  113. throw;
  114. }
  115. }
  116. /// <summary>
  117. /// 根据团组id查询酒店数据
  118. /// </summary>
  119. /// <param name="dto"></param>
  120. /// <returns></returns>
  121. public async Task<Result> HotelReservationsByDiId(HotelReservationsByDiIdDto dto)
  122. {
  123. Result result = new Result() { Code = -2, Msg = "未知错误" };
  124. try
  125. {
  126. string UserId = "";
  127. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 76).ToList();
  128. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  129. UserId += gta.UId + ",";
  130. if (!string.IsNullOrWhiteSpace(UserId))
  131. {
  132. UserId = UserId.Substring(0, UserId.Length - 1);
  133. }
  134. else
  135. {
  136. UserId = "0";
  137. }
  138. string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0,UserId);
  139. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  140. int endIndex = startIndex + dto.PageSize - 1;
  141. if (dto.PortType == 1)
  142. {
  143. string sql = string.Format(@"select h.Id,s1.Name as GuestType,h.ReservationsNo,h.HotelName,h.CheckInDate,
  144. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  145. From Grp_HotelReservations h
  146. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  147. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  148. left Join Sys_SetData s1 on h.GTId=s1.Id
  149. left Join Sys_Users u on u.Id=h.CreateUserId {0} order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  150. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  151. foreach (var item in hotelDataList)
  152. {
  153. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  154. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  155. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  156. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  157. item.CheckInDate=DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  158. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  159. }
  160. return result = new Result() { Code = 0, Msg = "查询成功!", Data = hotelDataList };
  161. }
  162. else if (dto.PortType == 2 || dto.PortType == 3)
  163. {
  164. string sql = string.Format(@"Select * From (
  165. 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,
  166. h.CheckOutDate,c.PayMoney,s.Name as PaymentCurrency,u.CnName as CreateUserName,c.IsAuditGM,h.CreateTime,h.Attachment
  167. From Grp_HotelReservations h
  168. Join Grp_CreditCardPayment c on h.Id=c.CId and c.CTable=76 and c.isdel=0
  169. left Join Sys_SetData s on c.PaymentCurrency=s.Id
  170. left Join Sys_SetData s1 on h.GTId=s1.Id
  171. left Join Sys_Users u on u.Id=h.CreateUserId {0}
  172. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  173. List<HotelReservationsByDiIdView> hotelDataList = _sqlSugar.SqlQueryable<HotelReservationsByDiIdView>(sql).ToList();
  174. foreach (var item in hotelDataList)
  175. {
  176. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  177. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  178. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  179. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  180. item.CheckInDate = DateTime.Parse(item.CheckInDate).ToString("yyyy-MM-dd");
  181. item.CheckOutDate = DateTime.Parse(item.CheckOutDate).ToString("yyyy-MM-dd");
  182. }
  183. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  184. Select 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", sqlWhere);
  192. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  193. int count = dataCount.Count;
  194. float totalPage = (float)count / dto.PageSize;//总页数
  195. if (totalPage == 0) totalPage = 1;
  196. else totalPage = (int)Math.Ceiling((double)totalPage);
  197. ListViewBase<HotelReservationsByDiIdView> rst = new ListViewBase<HotelReservationsByDiIdView>();
  198. rst.DataList = hotelDataList;
  199. rst.DataCount = count;
  200. rst.CurrPageIndex = dto.PageIndex;
  201. rst.CurrPageSize = dto.PageSize;
  202. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  203. }
  204. else
  205. {
  206. return result = new Result() { Code = -2, Msg = "请传入PortType参数,1 Web 2 Android 3 IOS" };
  207. }
  208. }
  209. catch (Exception ex)
  210. {
  211. return result = new Result() { Code = -2, Msg = "未知错误" };
  212. throw;
  213. }
  214. }
  215. /// <summary>
  216. /// 根据酒店费用Id查询详细数据
  217. /// </summary>
  218. /// <param name="dto"></param>
  219. /// <returns></returns>
  220. public async Task<Result> HotelReservationsById(HotelReservationsByIdDto dto)
  221. {
  222. Result result = new Result() { Code = -2, Msg = "未知错误" };
  223. try
  224. {
  225. Grp_HotelReservations hotelReservationsById = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  226. HotelReservationsByIdView _hotelReservations = _mapper.Map<HotelReservationsByIdView>(hotelReservationsById);
  227. if (_hotelReservations!=null)
  228. {
  229. Sys_SetData GTId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GTId);
  230. if (GTId != null) _hotelReservations.GtIdStr = GTId.Name;
  231. _hotelReservations.CheckInDate=Convert.ToDateTime(hotelReservationsById.CheckInDate).ToString("yyyy-MM-dd");
  232. _hotelReservations.CheckOutDate = Convert.ToDateTime(hotelReservationsById.CheckOutDate).ToString("yyyy-MM-dd");
  233. Sys_SetData GovernmentRentCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.GovernmentRentCurrency);
  234. if (GovernmentRentCurrencyStr != null) _hotelReservations.GovernmentRentCurrencyStr = GovernmentRentCurrencyStr.Name;
  235. Sys_SetData CityTaxCurrencyStr = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == hotelReservationsById.CityTaxCurrency);
  236. if (CityTaxCurrencyStr != null) _hotelReservations.CityTaxCurrencyStr = CityTaxCurrencyStr.Name;
  237. if (_hotelReservations.CheckType == "") _hotelReservations.CheckTypeStr = "客人房";
  238. else if (_hotelReservations.CheckType == "D") _hotelReservations.CheckTypeStr = "司机房";
  239. else if (_hotelReservations.CheckType == "G") _hotelReservations.CheckTypeStr = "导游房";
  240. else if (_hotelReservations.CheckType == "D&G") _hotelReservations.CheckTypeStr = "司机导游房";
  241. }
  242. string Sql = string.Format(@"select c.PayDId, s.Name asPayDIdStr,c.ConsumptionPatterns,c.ConsumptionDate,c.CTDId,
  243. s1.Name as CTDIdStr,c.BankNo,c.CardholderName,c.PayMoney,c.PaymentCurrency,s2.Name
  244. as PaymentCurrencyStr,c.DayRate,c.CompanyBankNo,c.OtherBankName,c.OtherSideNo,c.OtherSideName,
  245. c.IsAuditGM,c.Payee,c.RMBPrice,c.OrbitalPrivateTransfer,c.Remark from Grp_CreditCardPayment c
  246. left join Sys_SetData s on c.PayDId=s.Id
  247. left join Sys_SetData s1 on c.CTDId=s1.Id
  248. left join Sys_SetData s2 on c.PaymentCurrency=s2.Id
  249. where c.CId ={0} and c.IsDel = 0 and c.CTable = 76", dto.Id);
  250. Grp_CreditCardView _CreditCardPayment = _sqlSugar.SqlQueryable<Grp_CreditCardView>(Sql).First();
  251. if (_CreditCardPayment!=null)
  252. {
  253. if(!string.IsNullOrWhiteSpace(_CreditCardPayment.ConsumptionDate)) _CreditCardPayment.ConsumptionDate=Convert.ToDateTime(_CreditCardPayment.ConsumptionDate).ToString("yyyy-MM-dd");
  254. }
  255. var data = new
  256. {
  257. hotelReservations = _hotelReservations,
  258. creditCardPayment = _CreditCardPayment,
  259. };
  260. return result = new Result() { Code = 0, Msg = "查询成功",Data= data };
  261. }
  262. catch (Exception ex)
  263. {
  264. return result = new Result() { Code = -2, Msg = "未知错误" };
  265. throw;
  266. }
  267. }
  268. /// <summary>
  269. /// 酒店页面下拉框等初始化
  270. /// </summary>
  271. /// <param name="dto"></param>
  272. /// <returns></returns>
  273. public async Task<Result> HotelReservationsInitialize(HotelReservationsDto dto)
  274. {
  275. Result result = new Result() { Code = -2, Msg = "未知错误" };
  276. try
  277. {
  278. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 76).ToList();
  279. string DiId = "0";
  280. foreach (var item in grp_GroupsTaskAssignment)
  281. {
  282. DiId += item.DIId + ",";
  283. }
  284. if (DiId != "0")
  285. {
  286. DiId = DiId.Substring(0, DiId.Length - 1);
  287. }
  288. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  289. //团组下拉框
  290. List<Grp_DelegationInfo> Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  291. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(Delegations);
  292. for (int i = 0;i< grp_Delegations.Count; i++)
  293. {
  294. grp_Delegations[i].VisitDate = Delegations[i].VisitStartDate.ToString("yyyy-MM-dd")+"至"+ Delegations[i].VisitEndDate.ToString("yyyy-MM-dd");
  295. }
  296. //客人类型
  297. List<Sys_SetData> GuestType = _sqlSugar.Queryable<Sys_SetData>().Where(a=>a.IsDel==0 && a.STid==11).ToList();
  298. List<SetDataInfoView> _GuestType = _mapper.Map<List<SetDataInfoView>>(GuestType);
  299. //支付方式
  300. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  301. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  302. //币种
  303. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  304. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  305. //卡类型
  306. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  307. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  308. //预订网站
  309. List<Sys_SetData> BookingWebsite = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 12 && a.IsDel == 0).ToList();
  310. List<SetDataInfoView> _BookingWebsite = _mapper.Map<List<SetDataInfoView>>(BookingWebsite);
  311. var data = new
  312. {
  313. Delegations = grp_Delegations,
  314. GuestType = _GuestType,
  315. Payment = _Payment,
  316. CurrencyList = _CurrencyList,
  317. BankCard = _BankCard,
  318. BookingWebsite = _BookingWebsite,
  319. };
  320. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  321. }
  322. catch (Exception ex)
  323. {
  324. return result = new Result() { Code = -2, Msg = "未知错误" };
  325. throw;
  326. }
  327. }
  328. /// <summary>
  329. /// 酒店操作
  330. /// </summary>
  331. /// <param name="dto"></param>
  332. /// <returns></returns>
  333. /// <exception cref="NotImplementedException"></exception>
  334. public async Task<Result> OpHotelReservations(OpHotelReservationsData dto)
  335. {
  336. Result result = new Result() { Code = -2, Msg = "未知错误" };
  337. try
  338. {
  339. BeginTran();
  340. int id = dto.Id;
  341. Grp_HotelReservations hotelPrice = _mapper.Map<Grp_HotelReservations>(dto);
  342. hotelPrice.IsCardPrice = hotelPrice.CardPrice!=0 ? 1:0;
  343. hotelPrice.CboOne=hotelPrice.SingleRoomCount !=0 ? 1 : 0;
  344. hotelPrice.CboTwo = hotelPrice.DoubleRoomCount != 0 ? 1 : 0;
  345. hotelPrice.CboThree = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  346. hotelPrice.CboFour = hotelPrice.SuiteRoomCount != 0 ? 1 : 0;
  347. Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
  348. c.Remark = dto.CRemark;
  349. c.PayPercentage = 100;
  350. c.CTable = 76;
  351. c.CId = id;
  352. c.IsAuditGM = 0;
  353. if (c.PayDId == 72)
  354. {
  355. c.IsPay = 1;
  356. }
  357. c.RMBPrice = c.PayMoney;
  358. c.DayRate = 1;
  359. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 76);
  360. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  361. if (_TeamRate != null)
  362. {
  363. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  364. if (_SetData != null)
  365. {
  366. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  367. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  368. if (CurrencyRate != null)
  369. {
  370. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  371. c.DayRate = CurrencyRate.Rate;
  372. }
  373. }
  374. }
  375. if (dto.Status == 1)//添加
  376. {
  377. Grp_HotelReservations grp_Hotel = _sqlSugar.Queryable<Grp_HotelReservations>().First(a => a.IsDel == 0 && a.HotelName == dto.HotelName && a.GuestName == dto.GuestName &&
  378. a.CheckInDate == dto.CheckInDate && a.CheckOutDate==dto.CheckOutDate && a.City==dto.City);
  379. if (grp_Hotel != null)
  380. {
  381. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  382. }
  383. else
  384. {
  385. id = await AddAsyncReturnId(hotelPrice);
  386. if (id != 0)
  387. {
  388. c.CId = id;
  389. int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  390. if (cId != 0)
  391. {
  392. result = new Result() { Code = 0, Msg = "添加成功!" };
  393. }
  394. else
  395. {
  396. RollbackTran();
  397. result = new Result() { Code = -1, Msg = "添加失败!" };
  398. }
  399. }
  400. else
  401. {
  402. RollbackTran();
  403. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  404. }
  405. }
  406. }
  407. else if (dto.Status == 2)//修改
  408. {
  409. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_HotelReservations
  410. {
  411. GTId=hotelPrice.GTId,
  412. CheckNumber=hotelPrice.CheckNumber,
  413. ReservationsWebsite=hotelPrice.ReservationsWebsite,
  414. ReservationsNo=hotelPrice.ReservationsNo,
  415. DetermineNo=hotelPrice.DetermineNo,
  416. City=hotelPrice.City,
  417. HotelName=hotelPrice.HotelName,
  418. HotelAddress=hotelPrice.HotelAddress,
  419. HotelTel=hotelPrice.HotelTel,
  420. GuestName=hotelPrice.GuestName,
  421. CheckInDate=hotelPrice.CheckInDate,
  422. BudgetCurrency=hotelPrice.BudgetCurrency,
  423. CheckOutDate=hotelPrice.CheckOutDate,
  424. SingleRoomCount=hotelPrice.SingleRoomCount,
  425. SingleRoomPrice=hotelPrice.SingleRoomPrice,
  426. DoubleRoomCount=hotelPrice.DoubleRoomCount,
  427. DoubleRoomPrice=hotelPrice.DoubleRoomPrice,
  428. SuiteRoomCount=hotelPrice.SuiteRoomCount,
  429. SuiteRoomPrice=hotelPrice.SuiteRoomPrice,
  430. OtherRoomCount=hotelPrice.OtherRoomCount,
  431. OtherRoomPrice=hotelPrice.OtherRoomPrice,
  432. RoomExplanation=hotelPrice.RoomExplanation,
  433. Attachment=hotelPrice.Attachment,
  434. CardPrice=hotelPrice.CardPrice,
  435. IsCardPrice=hotelPrice.IsCardPrice,
  436. PredictSingleRoom=hotelPrice.PredictSingleRoom,
  437. PredictDoubleRoom=hotelPrice.PredictDoubleRoom,
  438. PredictSuiteRoom=hotelPrice.PredictSuiteRoom,
  439. PredictOtherRoom=hotelPrice.PredictOtherRoom,
  440. GovernmentRent=hotelPrice.GovernmentRent,
  441. GovernmentRentCurrency=hotelPrice.GovernmentRentCurrency,
  442. CityTax=hotelPrice.CityTax,
  443. CityTaxCurrency=hotelPrice.CityTaxCurrency,
  444. CheckType=hotelPrice.CheckType,
  445. CboOne=hotelPrice.SingleRoomCount,
  446. CboTwo=hotelPrice.DoubleRoomCount,
  447. CboThree=hotelPrice.SuiteRoomCount,
  448. CboFour=hotelPrice.SuiteRoomCount,
  449. CreateUserId=hotelPrice.CreateUserId,
  450. Remark=hotelPrice.Remark
  451. });
  452. if (res)
  453. {
  454. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == hotelPrice.Id && a.CTable == 76).SetColumns(a => new Grp_CreditCardPayment
  455. {
  456. PayDId = dto.PayDId,
  457. PayMoney = c.PayMoney,
  458. PaymentCurrency = c.PaymentCurrency,
  459. Payee = c.Payee,
  460. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  461. DayRate = c.DayRate,
  462. RMBPrice = c.RMBPrice,
  463. ConsumptionPatterns = c.ConsumptionPatterns,
  464. ConsumptionDate = c.ConsumptionDate,
  465. CTDId = c.CTDId,
  466. CompanyBankNo = c.CompanyBankNo,
  467. OtherBankName = c.OtherBankName,
  468. OtherSideNo = c.OtherSideNo,
  469. OtherSideName = c.OtherSideName,
  470. BankNo = c.BankNo,
  471. CardholderName = c.CardholderName,
  472. Remark = c.Remark,
  473. }).ExecuteCommandAsync();
  474. if (CTable==0)
  475. {
  476. result = new Result() { Code = -1, Msg = "修改失败!" };
  477. RollbackTran();
  478. }
  479. else
  480. {
  481. result = new Result() { Code = 0, Msg = "修改成功!" };
  482. }
  483. }
  484. else
  485. {
  486. RollbackTran();
  487. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  488. }
  489. }
  490. CommitTran();
  491. }
  492. catch (Exception ex)
  493. {
  494. return result = new Result() { Code = -2, Msg = "未知错误" };
  495. throw;
  496. }
  497. return result;
  498. }
  499. }
  500. }