CarTouristGuideGroundRepository.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. using AutoMapper;
  2. using NPOI.SS.UserModel;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Entities.Financial;
  6. using OASystem.Domain.Entities.Groups;
  7. using OASystem.Domain.Entities.Resource;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using OASystem.Infrastructure.Tools;
  10. using SqlSugar.Extensions;
  11. using System.Collections.Generic;
  12. using System.Reflection;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  16. {
  17. private readonly IMapper _mapper;
  18. private readonly CheckBoxsRepository _checkRep;
  19. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper , CheckBoxsRepository checkRep)
  20. : base(sqlSugar)
  21. {
  22. _mapper = mapper;
  23. _checkRep = checkRep;
  24. }
  25. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  26. {
  27. Result result = new Result() { Code = -2, Msg = "未知错误" };
  28. BeginTran();
  29. try
  30. {
  31. int id = 0;
  32. Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  33. if (dto.Status == 1)//添加
  34. {
  35. 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);
  36. if (grp_CarTouristGuideGround != null)
  37. {
  38. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  39. }
  40. else
  41. {
  42. id = await AddAsyncReturnId(grp_CarTouristGuide);
  43. if (id == 0)
  44. {
  45. RollbackTran();
  46. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  47. }
  48. else
  49. {
  50. result = new Result() { Code = 0, Msg = "添加成功!" };
  51. }
  52. }
  53. }
  54. else if (dto.Status == 2)//修改
  55. {
  56. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  57. {
  58. Area = grp_CarTouristGuide.Area,
  59. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  60. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  61. ServiceTel = grp_CarTouristGuide.ServiceTel,
  62. BusName = grp_CarTouristGuide.BusName,
  63. BusDescription = grp_CarTouristGuide.BusDescription,
  64. BusTel = grp_CarTouristGuide.BusTel,
  65. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  66. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  67. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  68. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  69. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  70. Remark = grp_CarTouristGuide.Remark,
  71. });
  72. if (res)
  73. {
  74. id = dto.Id;
  75. result = new Result() { Code = 0, Msg = "修改成功!" };
  76. }
  77. else
  78. {
  79. RollbackTran();
  80. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  81. }
  82. }
  83. if (id!=0)
  84. {
  85. Res_LocalGuideData _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.BusName && a.ContactTel == dto.BusTel && a.IsDel == 0);
  86. if (_LocalGuideDataCar == null)
  87. {
  88. Res_LocalGuideData res_LocalGuideCar = new Res_LocalGuideData();
  89. res_LocalGuideCar.UnitName = dto.BusName;
  90. res_LocalGuideCar.ContactTel = dto.BusTel;
  91. res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  92. int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  93. }
  94. Res_LocalGuideData _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.ServiceCompany && a.ContactTel == dto.ServiceTel && a.IsDel == 0);
  95. if (_LocalGuideDataService == null)
  96. {
  97. Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  98. res_LocalGuideService.UnitName = dto.ServiceCompany;
  99. res_LocalGuideService.ContactTel = dto.ServiceTel;
  100. res_LocalGuideService.Contact = dto.ServiceTel;
  101. res_LocalGuideService.CreateUserId = dto.CreateUserId;
  102. int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  103. }
  104. }
  105. CommitTran();
  106. }
  107. catch (Exception ex)
  108. {
  109. result = new Result() { Code = -2, Msg = "未知错误" };
  110. }
  111. return result;
  112. }
  113. public Result CarTouristGuideGroundContent(CarTouristGuideGroundContentDto dto)
  114. {
  115. Result result = new Result() { Code = -2, Msg = "未知错误" };
  116. try
  117. {
  118. DateTime start = new DateTime();
  119. DateTime end = new DateTime();
  120. Grp_CarTouristGuideGroundReservations grpCarOp = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.Id);
  121. if (!DateTime.TryParse(grpCarOp?.ServiceStartTime, out start))
  122. {
  123. result.Msg = "服务开始时间不存在!";
  124. result.Code = -1;
  125. return result;
  126. }
  127. if (!DateTime.TryParse(grpCarOp?.ServiceEndTime, out end))
  128. {
  129. result.Msg = "服务结束时间不存在!";
  130. result.Code = -1;
  131. return result;
  132. }
  133. TimeSpan ts = end - start; //计算时间差
  134. int day = ts.Days;
  135. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79).ToList();
  136. string DiId = "0";
  137. foreach (var item in grp_GroupsTaskAssignment)
  138. {
  139. DiId += item.DIId + ",";
  140. }
  141. if (DiId != "0")
  142. {
  143. DiId = DiId.Substring(0, DiId.Length - 1);
  144. }
  145. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  146. //团组下拉框
  147. List<Grp_DelegationInfo> _Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  148. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(_Delegations);
  149. //支付方式
  150. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  151. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  152. //列表初始化
  153. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  154. //List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  155. //_TableInitialization= _TableInitialization.OrderBy(a=>a.Name).ToList();
  156. List<Sys_SetData> ssd = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 78).ToList();
  157. List<SetDataInfoView> ssdv = _mapper.Map<List<Sys_SetData>,List<SetDataInfoView>>(ssd);
  158. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  159. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  160. foreach (var itemSt in TableInitialization)
  161. {
  162. var findResult = carTouristGuides.Find(x => x.SId == itemSt.Id);
  163. if (findResult == null)
  164. {
  165. carTouristGuides.Add(new CarTouristGuideGroundReservationsContentView
  166. {
  167. SId = itemSt.Id,
  168. Count = 1,
  169. SidName = itemSt.Name,
  170. });
  171. }
  172. }
  173. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x => x.Key, x => x.ToList());
  174. foreach (var item in groupResult.Keys)
  175. {
  176. while (groupResult[item].Count <= day)
  177. {
  178. groupResult[item] = groupResult[item].OrderByDescending(x => x.DatePrice).ToList();
  179. if (groupResult[item][0]?.DatePrice is not null)
  180. {
  181. groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  182. {
  183. DatePrice = groupResult[item][0].DatePrice.ObjToDate().AddDays(1),
  184. SId = item,
  185. Count = 1,
  186. });
  187. }
  188. else
  189. {
  190. groupResult[item][0].DatePrice = start;
  191. }
  192. }
  193. }
  194. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).OrderBy(x=>x.SId).ThenBy(x=>x.DatePrice).ToList();
  195. foreach (var item in carTouristGuides.Where(x=>string.IsNullOrWhiteSpace(x.SidName)).ToList())
  196. {
  197. item.SidName = TableInitialization.Find(x => x.Id == item.SId)?.Name;
  198. }
  199. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  200. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  201. if (_CreditCardPayment != null)
  202. {
  203. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  204. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  205. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  206. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  207. }
  208. Dictionary<string, string> soureDic = new Dictionary<string, string>()
  209. {
  210. {"车费", "VF"},
  211. {"导游费", "T/G S"},
  212. {"客户午餐费用" , "L"},
  213. {"导游景点费" , "T/G EF"},
  214. {"导游小费" , "T/G T"},
  215. // --
  216. {"司机小费", "DRV T"},
  217. {"司机餐补", "C/F M"},
  218. {"车超时费", "C/F OF"},
  219. {"导游餐补", "T/G M"},
  220. {"导游房补", "T/G A"},
  221. {"导游交通", "T/G TF"},
  222. {"客户早餐费用", "B"},
  223. {"客户晚餐费用", "D"},
  224. {"景点门票费", "EF"},
  225. {"饮料/零食/水果", "B/R/F"},
  226. {"翻译费", "I/F"},
  227. };
  228. //获取成本选中
  229. var checkTopArr = _checkRep.GetCheckBoxsByDiid(grpCarOp.DiId);
  230. if (checkTopArr.Count > 0)
  231. {
  232. var FindTop = checkTopArr.Find(x => x.CbType == "Top");
  233. if (FindTop != null)
  234. {
  235. var selectName = FindTop.CbValues.Split(',').ToList<string>();
  236. foreach (var soureKey in soureDic.Keys)
  237. {
  238. var find = selectName.Find(x => x == soureDic[soureKey]);
  239. if (find == null)
  240. {
  241. var Lindex = carTouristGuides.FindIndex(x=>x.SidName == soureKey);
  242. carTouristGuides.RemoveRange(Lindex , day + 1);
  243. }
  244. }
  245. }
  246. }
  247. var data = new
  248. {
  249. Payment = _Payment,
  250. Delegations = grp_Delegations,
  251. carTouristGuides = carTouristGuides,
  252. CreditCardPayment = _CreditCardPayment,
  253. start,
  254. end,
  255. ssdv,
  256. };
  257. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  258. }
  259. catch (Exception ex)
  260. {
  261. return result = new Result() { Code = -2, Msg = "未知错误" };
  262. }
  263. }
  264. /// <summary>
  265. /// web弃用
  266. /// </summary>
  267. /// <param name="dto"></param>
  268. /// <returns></returns>
  269. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  270. {
  271. Result result = new Result() { Code = -2, Msg = "未知错误" };
  272. try
  273. {
  274. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  275. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  276. foreach (var item in carTouristGuides)
  277. {
  278. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  279. }
  280. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  281. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  282. if (_CreditCardPayment!=null)
  283. {
  284. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  285. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  286. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  287. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  288. }
  289. var data = new
  290. {
  291. CarTouristsContent = carTouristGuides,
  292. CreditCardPayment = _CreditCardPayment,
  293. };
  294. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  295. }
  296. catch (Exception ex)
  297. {
  298. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  299. }
  300. }
  301. /// <summary>
  302. /// 根据diid查询op费用列表
  303. /// </summary>
  304. /// <param name="dto"></param>
  305. /// <returns></returns>
  306. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  307. {
  308. Result result = new Result() { Code = -2, Msg = "未知错误" };
  309. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  310. {
  311. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  312. }
  313. try
  314. {
  315. #region SQL条件拼接
  316. string sqlWhere = string.Empty;
  317. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  318. string UserId = "";
  319. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  320. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  321. UserId += gta.UId + ",";
  322. if (!string.IsNullOrWhiteSpace(UserId))
  323. {
  324. UserId = UserId.Substring(0, UserId.Length - 1);
  325. }
  326. else
  327. {
  328. UserId = "0";
  329. }
  330. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  331. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  332. {
  333. Regex r = new Regex("And");
  334. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  335. }
  336. #endregion
  337. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  338. int endIndex = startIndex + dto.PageSize - 1;
  339. if (dto.PortType == 1)
  340. {
  341. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid from
  342. Grp_CarTouristGuideGroundReservations t
  343. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  344. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  345. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  346. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  347. foreach (var item in infoViews)
  348. {
  349. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  350. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  351. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  352. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  353. item.ServiceQuotedPrice = item.PayMoney;
  354. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  355. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  356. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  357. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  358. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  359. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  360. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  361. if (s!=null)
  362. {
  363. item.PayStrd = s.Name;
  364. }else item.PayStrd ="未选择";
  365. }
  366. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  367. }
  368. else if (dto.PortType == 2 || dto.PortType == 3)
  369. {
  370. string sql = string.Format(@"Select * From (
  371. Select row_number() over (order by c.IsAuditGM,c.PayPercentage desc) as RowNumber,t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayDid,c.PayMoney
  372. from
  373. Grp_CarTouristGuideGroundReservations t
  374. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  375. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  376. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  377. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  378. foreach (var item in grp_CarTourists)
  379. {
  380. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  381. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  382. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  383. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  384. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  385. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  386. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  387. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  388. item.ServiceQuotedPrice = item.PayMoney;
  389. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  390. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  391. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  392. if (s != null)
  393. {
  394. item.PayStrd = s.Name;
  395. }
  396. else item.PayStrd = "未选择";
  397. }
  398. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  399. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  400. Grp_CarTouristGuideGroundReservations t
  401. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  402. left Join Sys_SetData s on s.Id=t.CId {0}
  403. ) temp ", sqlWhere);
  404. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  405. if (dataCount != null)
  406. {
  407. int count = dataCount.Count;
  408. float totalPage = (float)count / dto.PageSize;//总页数
  409. if (totalPage == 0) totalPage = 1;
  410. else totalPage = (int)Math.Ceiling((double)totalPage);
  411. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  412. rst.DataList = grp_CarTourists;
  413. rst.DataCount = count;
  414. rst.CurrPageIndex = dto.PageIndex;
  415. rst.CurrPageSize = dto.PageSize;
  416. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  417. }
  418. }
  419. }
  420. catch (Exception)
  421. {
  422. return result = new Result() { Code = -2, Msg = "未知错误" };
  423. }
  424. return result;
  425. }
  426. /// <summary>
  427. /// OP费用录入填写详情
  428. /// </summary>
  429. /// <param name="dto"></param>
  430. /// <returns></returns>
  431. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  432. {
  433. Result result = new Result() { Code = -2, Msg = "未知错误" };
  434. try
  435. {
  436. BeginTran();
  437. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  438. {
  439. Id = item.Id,
  440. DiId = dto.DiId,
  441. CTGGRId = dto.CTGGRId,
  442. SId = item.SId,
  443. Price = item.Price,
  444. PriceContent = item.priceContent,
  445. Currency = dto.Currency,
  446. CreateUserId = dto.CreateUserId,
  447. Units = item.Units,
  448. DatePrice = item.DatePrice,
  449. Count = item.Count,
  450. }).ToList();
  451. foreach (var item in carTouristList)
  452. {
  453. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  454. if (QueryData==null)
  455. {
  456. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  457. if (id == 0)
  458. {
  459. RollbackTran();
  460. return result = new Result() { Code = -2, Msg = "添加失败" };
  461. }
  462. }
  463. else
  464. {
  465. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  466. {
  467. Price = item.Price,
  468. PriceContent = item.PriceContent,
  469. Currency = dto.Currency,
  470. Remark = item.Remark,
  471. DatePrice = item.DatePrice,
  472. Count = item.Count,
  473. Units = item.Units,
  474. }).ExecuteCommandAsync();
  475. if (CTable==0)
  476. {
  477. RollbackTran();
  478. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  479. }
  480. }
  481. }
  482. //修改C表数据
  483. List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  484. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  485. c.PaymentCurrency = dto.Currency;
  486. c.PayMoney = carTouristListEnd.Sum(x => x.Price);
  487. c.PayPercentage = dto.PayPercentage;
  488. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  489. c.CTable = 79;
  490. c.CId = dto.CTGGRId;
  491. c.IsAuditGM = 0;
  492. c.PayDId=dto.PayDId;
  493. c.DIId = dto.DiId;
  494. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  495. c.Payee=dto.Payee;
  496. c.CreateUserId=dto.CreateUserId;
  497. if (c.PayDId == 72)
  498. {
  499. c.IsPay = 1;
  500. }
  501. c.RMBPrice = c.PayMoney;
  502. c.DayRate = 1;
  503. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  504. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  505. if (_TeamRate != null)
  506. {
  507. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  508. if (_SetData != null)
  509. {
  510. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  511. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  512. if (CurrencyRate != null)
  513. {
  514. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  515. c.DayRate = CurrencyRate.Rate;
  516. }
  517. }
  518. }
  519. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  520. if (grp_CreditCard!=null)//修改
  521. {
  522. 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
  523. {
  524. PaymentCurrency = c.PaymentCurrency,
  525. PayMoney = c.PayMoney,
  526. PayPercentage = c.PayPercentage,
  527. CTable = c.CTable,
  528. PayDId = c.PayDId,
  529. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  530. Payee = c.Payee,
  531. IsPay = c.IsPay,
  532. RMBPrice = c.RMBPrice,
  533. DayRate = c.DayRate,
  534. }).ExecuteCommandAsync();
  535. if (CTable == 0)
  536. {
  537. RollbackTran();
  538. return result = new Result() { Code = -2, Msg = "修改失败" };
  539. }
  540. }
  541. else//添加
  542. {
  543. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  544. if (id == 0)
  545. {
  546. RollbackTran();
  547. return result = new Result() { Code = -2, Msg = "添加失败" };
  548. }
  549. }
  550. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  551. {
  552. CId = dto.Currency,
  553. ServiceQuotedPrice = c.PayMoney,
  554. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  555. }).ExecuteCommandAsync();
  556. if (CarTouristGuideCTable == 0)
  557. {
  558. RollbackTran();
  559. return result = new Result() { Code = -2, Msg = "修改失败" };
  560. }
  561. result = new Result() { Code =0, Msg = "保存成功" };
  562. CommitTran();
  563. }
  564. catch (Exception ex)
  565. {
  566. return result = new Result() { Code = -2, Msg = "未知错误" };
  567. }
  568. return result;
  569. }
  570. }
  571. }