CarTouristGuideGroundRepository.cs 23 KB

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