CarTouristGuideGroundRepository.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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.Entities.Resource;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using OASystem.Infrastructure.Tools;
  9. using System.Collections.Generic;
  10. namespace OASystem.Infrastructure.Repositories.Groups
  11. {
  12. public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  13. {
  14. private readonly IMapper _mapper;
  15. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper)
  16. : base(sqlSugar)
  17. {
  18. _mapper = mapper;
  19. }
  20. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  21. {
  22. Result result = new Result() { Code = -2, Msg = "未知错误" };
  23. BeginTran();
  24. try
  25. {
  26. int id = 0;
  27. Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  28. if (dto.Status == 1)//添加
  29. {
  30. Grp_CarTouristGuideGroundReservations grp_CarTouristGuideGround = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(a => a.IsDel == 0 && a.Area == dto.Area && a.BusName == dto.BusName && a.ServiceGuide == dto.ServiceGuide && a.DiId==dto.DiId && a.BusTel==dto.BusTel && a.ServiceTel==dto.ServiceTel);
  31. if (grp_CarTouristGuideGround != null)
  32. {
  33. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  34. }
  35. else
  36. {
  37. id = await AddAsyncReturnId(grp_CarTouristGuide);
  38. if (id == 0)
  39. {
  40. RollbackTran();
  41. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  42. }
  43. else
  44. {
  45. result = new Result() { Code = 0, Msg = "添加成功!" };
  46. }
  47. }
  48. }
  49. else if (dto.Status == 2)//修改
  50. {
  51. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  52. {
  53. Area = grp_CarTouristGuide.Area,
  54. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  55. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  56. ServiceTel = grp_CarTouristGuide.ServiceTel,
  57. BusName = grp_CarTouristGuide.BusName,
  58. BusDescription = grp_CarTouristGuide.BusDescription,
  59. BusTel = grp_CarTouristGuide.BusTel,
  60. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  61. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  62. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  63. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  64. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  65. Remark = grp_CarTouristGuide.Remark,
  66. });
  67. if (res)
  68. {
  69. id = dto.Id;
  70. result = new Result() { Code = 0, Msg = "修改成功!" };
  71. }
  72. else
  73. {
  74. RollbackTran();
  75. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  76. }
  77. }
  78. if (id!=0)
  79. {
  80. Res_LocalGuideData _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.BusName && a.ContactTel == dto.BusTel && a.IsDel == 0);
  81. if (_LocalGuideDataCar == null)
  82. {
  83. Res_LocalGuideData res_LocalGuideCar = new Res_LocalGuideData();
  84. res_LocalGuideCar.UnitName = dto.BusName;
  85. res_LocalGuideCar.ContactTel = dto.BusTel;
  86. res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  87. int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  88. }
  89. Res_LocalGuideData _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.ServiceCompany && a.ContactTel == dto.ServiceTel && a.IsDel == 0);
  90. if (_LocalGuideDataService == null)
  91. {
  92. Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  93. res_LocalGuideService.UnitName = dto.ServiceCompany;
  94. res_LocalGuideService.ContactTel = dto.ServiceTel;
  95. res_LocalGuideService.Contact = dto.ServiceTel;
  96. res_LocalGuideService.CreateUserId = dto.CreateUserId;
  97. int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  98. }
  99. }
  100. CommitTran();
  101. }
  102. catch (Exception ex)
  103. {
  104. result = new Result() { Code = -2, Msg = "未知错误" };
  105. }
  106. return result;
  107. }
  108. public async Task<Result> CarTouristGuideGroundContent(CarTouristGuideGroundContentDto dto)
  109. {
  110. Result result = new Result() { Code = -2, Msg = "未知错误" };
  111. try
  112. {
  113. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79).ToList();
  114. string DiId = "0";
  115. foreach (var item in grp_GroupsTaskAssignment)
  116. {
  117. DiId += item.DIId + ",";
  118. }
  119. if (DiId != "0")
  120. {
  121. DiId = DiId.Substring(0, DiId.Length - 1);
  122. }
  123. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  124. //团组下拉框
  125. List<Grp_DelegationInfo> _Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  126. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(_Delegations);
  127. //支付方式
  128. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  129. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  130. //币种
  131. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  132. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  133. //列表初始化
  134. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  135. List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  136. _TableInitialization= _TableInitialization.OrderBy(a=>a.Name).ToList();
  137. var data = new
  138. {
  139. Payment = _Payment,
  140. CurrencyList = _CurrencyList,
  141. Delegations = grp_Delegations,
  142. TableInitialization = _TableInitialization
  143. };
  144. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  145. }
  146. catch (Exception)
  147. {
  148. return result = new Result() { Code = -2, Msg = "未知错误" };
  149. throw;
  150. }
  151. }
  152. public async Task<Result> OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  153. {
  154. Result result = new Result() { Code = -2, Msg = "未知错误" };
  155. try
  156. {
  157. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  158. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  159. foreach (var item in carTouristGuides)
  160. {
  161. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  162. }
  163. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  164. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  165. if (_CreditCardPayment!=null)
  166. {
  167. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  168. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  169. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  170. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  171. }
  172. var data = new
  173. {
  174. CarTouristsContent = carTouristGuides,
  175. CreditCardPayment = _CreditCardPayment,
  176. };
  177. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  178. }
  179. catch (Exception)
  180. {
  181. return result = new Result() { Code = -2, Msg = "未知错误" };
  182. throw;
  183. }
  184. }
  185. /// <summary>
  186. /// 根据diid查询op费用列表
  187. /// </summary>
  188. /// <param name="dto"></param>
  189. /// <returns></returns>
  190. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  191. {
  192. Result result = new Result() { Code = -2, Msg = "未知错误" };
  193. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  194. {
  195. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  196. }
  197. try
  198. {
  199. #region SQL条件拼接
  200. string sqlWhere = string.Empty;
  201. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  202. string UserId = "";
  203. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  204. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  205. UserId += gta.UId + ",";
  206. if (!string.IsNullOrWhiteSpace(UserId))
  207. {
  208. UserId = UserId.Substring(0, UserId.Length - 1);
  209. }
  210. else
  211. {
  212. UserId = "0";
  213. }
  214. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  215. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  216. {
  217. Regex r = new Regex("And");
  218. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  219. }
  220. #endregion
  221. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  222. int endIndex = startIndex + dto.PageSize - 1;
  223. if (dto.PortType == 1)
  224. {
  225. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney from
  226. Grp_CarTouristGuideGroundReservations t
  227. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  228. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  229. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  230. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  231. foreach (var item in infoViews)
  232. {
  233. item.ServiceQuotedPrice = item.PayMoney;
  234. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  235. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  236. }
  237. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  238. }
  239. else if (dto.PortType == 2 || dto.PortType == 3)
  240. {
  241. string sql = string.Format(@"Select * From (
  242. Select row_number() over (order by c.IsAuditGM,c.PayPercentage desc) as RowNumber,t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage
  243. from
  244. Grp_CarTouristGuideGroundReservations t
  245. Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  246. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  247. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  248. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  249. foreach (var item in grp_CarTourists)
  250. {
  251. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  252. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  253. }
  254. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  255. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  256. Grp_CarTouristGuideGroundReservations t
  257. Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  258. left Join Sys_SetData s on s.Id=t.CId {0}
  259. ) temp ", sqlWhere);
  260. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  261. if (dataCount != null)
  262. {
  263. int count = dataCount.Count;
  264. float totalPage = (float)count / dto.PageSize;//总页数
  265. if (totalPage == 0) totalPage = 1;
  266. else totalPage = (int)Math.Ceiling((double)totalPage);
  267. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  268. rst.DataList = grp_CarTourists;
  269. rst.DataCount = count;
  270. rst.CurrPageIndex = dto.PageIndex;
  271. rst.CurrPageSize = dto.PageSize;
  272. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  273. }
  274. }
  275. }
  276. catch (Exception)
  277. {
  278. return result = new Result() { Code = -2, Msg = "未知错误" };
  279. throw;
  280. }
  281. return result;
  282. }
  283. /// <summary>
  284. /// OP费用录入填写详情
  285. /// </summary>
  286. /// <param name="dto"></param>
  287. /// <returns></returns>
  288. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  289. {
  290. Result result = new Result() { Code = -2, Msg = "未知错误" };
  291. try
  292. {
  293. BeginTran();
  294. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = new List<Grp_CarTouristGuideGroundReservationsContent>();
  295. foreach (var item in dto.OPContentList)
  296. {
  297. Grp_CarTouristGuideGroundReservationsContent s = new Grp_CarTouristGuideGroundReservationsContent();
  298. s.Id= item.Id;
  299. s.DiId = dto.DiId;
  300. s.CTGGRId = dto.CTGGRId;
  301. s.SId = item.SId;
  302. s.Price=item.Price;
  303. s.PriceContent = item.priceContent;
  304. s.Currency = dto.Currency;
  305. //s.Remark=item.Remark;
  306. s.CreateUserId = dto.CreateUserId;
  307. carTouristList.Add(s);
  308. }
  309. foreach (var item in carTouristList)
  310. {
  311. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  312. if (QueryData==null)
  313. {
  314. if (item.Price!=0)
  315. {
  316. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  317. if (id == 0)
  318. {
  319. RollbackTran();
  320. return result = new Result() { Code = -2, Msg = "添加失败" };
  321. }
  322. }
  323. }
  324. else
  325. {
  326. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  327. {
  328. Price = item.Price,
  329. PriceContent = item.PriceContent,
  330. Currency = dto.Currency,
  331. Remark = item.Remark,
  332. }).ExecuteCommandAsync();
  333. if (CTable==0)
  334. {
  335. RollbackTran();
  336. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  337. }
  338. }
  339. }
  340. //修改C表数据
  341. List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  342. Grp_CreditCardPayment c=new Grp_CreditCardPayment();
  343. c.PaymentCurrency = dto.Currency;
  344. foreach (var item in carTouristListEnd)
  345. {
  346. c.PayMoney += item.Price;
  347. }
  348. c.PayPercentage = dto.PayPercentage;
  349. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  350. c.CTable = 79;
  351. c.CId = dto.CTGGRId;
  352. c.IsAuditGM = 0;
  353. c.PayDId=dto.PayDId;
  354. c.DIId = dto.DiId;
  355. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  356. c.Payee=dto.Payee;
  357. c.CreateUserId=dto.CreateUserId;
  358. if (c.PayDId == 72)
  359. {
  360. c.IsPay = 1;
  361. }
  362. c.RMBPrice = c.PayMoney;
  363. c.DayRate = 1;
  364. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  365. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  366. if (_TeamRate != null)
  367. {
  368. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  369. if (_SetData != null)
  370. {
  371. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  372. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  373. if (CurrencyRate != null)
  374. {
  375. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  376. c.DayRate = CurrencyRate.Rate;
  377. }
  378. }
  379. }
  380. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  381. if (grp_CreditCard!=null)//修改
  382. {
  383. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId==dto.DiId).SetColumns(a => new Grp_CreditCardPayment
  384. {
  385. PaymentCurrency = c.PaymentCurrency,
  386. PayMoney = c.PayMoney,
  387. PayPercentage = c.PayPercentage,
  388. CTable = c.CTable,
  389. PayDId = c.PayDId,
  390. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  391. Payee = c.Payee,
  392. IsPay = c.IsPay,
  393. RMBPrice = c.RMBPrice,
  394. DayRate = c.DayRate,
  395. }).ExecuteCommandAsync();
  396. if (CTable == 0)
  397. {
  398. RollbackTran();
  399. return result = new Result() { Code = -2, Msg = "修改失败" };
  400. }
  401. }
  402. else//添加
  403. {
  404. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  405. if (id == 0)
  406. {
  407. RollbackTran();
  408. return result = new Result() { Code = -2, Msg = "添加失败" };
  409. }
  410. }
  411. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  412. {
  413. CId=dto.Currency,
  414. ServiceQuotedPrice=c.PayMoney,
  415. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  416. }).ExecuteCommandAsync();
  417. if (CarTouristGuideCTable == 0)
  418. {
  419. RollbackTran();
  420. return result = new Result() { Code = -2, Msg = "修改失败" };
  421. }
  422. result = new Result() { Code =0, Msg = "保存成功" };
  423. CommitTran();
  424. }
  425. catch (Exception)
  426. {
  427. return result = new Result() { Code = -2, Msg = "未知错误" };
  428. throw;
  429. }
  430. return result;
  431. }
  432. }
  433. }