CarTouristGuideGroundRepository.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. var checkedItem = new List<string>();
  231. if (checkTopArr.Count > 0)
  232. {
  233. var FindTop = checkTopArr.Find(x => x.CbType == "Top");
  234. if (FindTop != null)
  235. {
  236. var selectName = FindTop.CbValues.Split(',').ToList<string>();
  237. foreach (var soureKey in soureDic.Keys)
  238. {
  239. var find = selectName.Find(x => x == soureDic[soureKey]);
  240. if (find == null)
  241. {
  242. var Lindex = carTouristGuides.FindIndex(x=>x.SidName == soureKey);
  243. //carTouristGuides.RemoveRange(Lindex, day + 1);
  244. } else
  245. {
  246. checkedItem.Add(soureKey);
  247. }
  248. }
  249. }
  250. }
  251. var data = new
  252. {
  253. Payment = _Payment,
  254. Delegations = grp_Delegations,
  255. carTouristGuides = carTouristGuides,
  256. CreditCardPayment = _CreditCardPayment,
  257. start,
  258. end,
  259. ssdv,
  260. checkedItem
  261. };
  262. return result = new Result() { Code = 0, Msg = "查询成功",Data=data };
  263. }
  264. catch (Exception ex)
  265. {
  266. return result = new Result() { Code = -2, Msg = "未知错误" };
  267. }
  268. }
  269. /// <summary>
  270. /// web弃用
  271. /// </summary>
  272. /// <param name="dto"></param>
  273. /// <returns></returns>
  274. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  275. {
  276. Result result = new Result() { Code = -2, Msg = "未知错误" };
  277. try
  278. {
  279. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  280. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  281. foreach (var item in carTouristGuides)
  282. {
  283. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  284. }
  285. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  286. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  287. if (_CreditCardPayment!=null)
  288. {
  289. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  290. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  291. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  292. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  293. }
  294. var data = new
  295. {
  296. CarTouristsContent = carTouristGuides,
  297. CreditCardPayment = _CreditCardPayment,
  298. };
  299. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  300. }
  301. catch (Exception ex)
  302. {
  303. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  304. }
  305. }
  306. /// <summary>
  307. /// 根据diid查询op费用列表
  308. /// </summary>
  309. /// <param name="dto"></param>
  310. /// <returns></returns>
  311. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  312. {
  313. Result result = new Result() { Code = -2, Msg = "未知错误" };
  314. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  315. {
  316. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  317. }
  318. try
  319. {
  320. #region SQL条件拼接
  321. string sqlWhere = string.Empty;
  322. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  323. string UserId = "";
  324. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  325. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  326. UserId += gta.UId + ",";
  327. if (!string.IsNullOrWhiteSpace(UserId))
  328. {
  329. UserId = UserId.Substring(0, UserId.Length - 1);
  330. }
  331. else
  332. {
  333. UserId = "0";
  334. }
  335. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  336. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  337. {
  338. Regex r = new Regex("And");
  339. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  340. }
  341. #endregion
  342. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  343. int endIndex = startIndex + dto.PageSize - 1;
  344. if (dto.PortType == 1)
  345. {
  346. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid from
  347. Grp_CarTouristGuideGroundReservations t
  348. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  349. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  350. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  351. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  352. foreach (var item in infoViews)
  353. {
  354. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  355. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  356. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  357. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  358. item.ServiceQuotedPrice = item.PayMoney;
  359. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  360. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
  361. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  362. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  363. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  364. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  365. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  366. if (s!=null)
  367. {
  368. item.PayStrd = s.Name;
  369. }else item.PayStrd ="未选择";
  370. }
  371. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  372. }
  373. else if (dto.PortType == 2 || dto.PortType == 3)
  374. {
  375. string sql = string.Format(@"Select * From (
  376. 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
  377. from
  378. Grp_CarTouristGuideGroundReservations t
  379. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  380. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  381. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  382. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  383. foreach (var item in grp_CarTourists)
  384. {
  385. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  386. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  387. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  388. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  389. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  390. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  391. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  392. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  393. item.ServiceQuotedPrice = item.PayMoney;
  394. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  395. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
  396. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  397. if (s != null)
  398. {
  399. item.PayStrd = s.Name;
  400. }
  401. else item.PayStrd = "未选择";
  402. }
  403. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  404. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  405. Grp_CarTouristGuideGroundReservations t
  406. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  407. left Join Sys_SetData s on s.Id=t.CId {0}
  408. ) temp ", sqlWhere);
  409. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  410. if (dataCount != null)
  411. {
  412. int count = dataCount.Count;
  413. float totalPage = (float)count / dto.PageSize;//总页数
  414. if (totalPage == 0) totalPage = 1;
  415. else totalPage = (int)Math.Ceiling((double)totalPage);
  416. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  417. rst.DataList = grp_CarTourists;
  418. rst.DataCount = count;
  419. rst.CurrPageIndex = dto.PageIndex;
  420. rst.CurrPageSize = dto.PageSize;
  421. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  422. }
  423. }
  424. }
  425. catch (Exception)
  426. {
  427. return result = new Result() { Code = -2, Msg = "未知错误" };
  428. }
  429. return result;
  430. }
  431. /// <summary>
  432. /// OP费用录入填写详情
  433. /// </summary>
  434. /// <param name="dto"></param>
  435. /// <returns></returns>
  436. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  437. {
  438. Result result = new Result() { Code = -2, Msg = "未知错误" };
  439. try
  440. {
  441. BeginTran();
  442. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  443. {
  444. Id = item.Id,
  445. DiId = dto.DiId,
  446. CTGGRId = dto.CTGGRId,
  447. SId = item.SId,
  448. Price = item.Price,
  449. PriceContent = item.priceContent,
  450. Currency = dto.Currency,
  451. CreateUserId = dto.CreateUserId,
  452. Units = item.Units,
  453. DatePrice = item.DatePrice,
  454. Count = item.Count,
  455. }).ToList();
  456. foreach (var item in carTouristList)
  457. {
  458. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  459. if (QueryData==null)
  460. {
  461. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  462. if (id == 0)
  463. {
  464. RollbackTran();
  465. return result = new Result() { Code = -2, Msg = "添加失败" };
  466. }
  467. }
  468. else
  469. {
  470. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  471. {
  472. Price = item.Price,
  473. PriceContent = item.PriceContent,
  474. Currency = dto.Currency,
  475. Remark = item.Remark,
  476. DatePrice = item.DatePrice,
  477. Count = item.Count,
  478. Units = item.Units,
  479. }).ExecuteCommandAsync();
  480. if (CTable==0)
  481. {
  482. RollbackTran();
  483. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  484. }
  485. }
  486. }
  487. //修改C表数据
  488. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  489. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  490. c.PaymentCurrency = dto.Currency;
  491. c.PayMoney = carTouristList.Sum(x => x.Price);
  492. c.PayPercentage = dto.PayPercentage;
  493. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  494. c.CTable = 79;
  495. c.CId = dto.CTGGRId;
  496. c.IsAuditGM = 0;
  497. c.PayDId=dto.PayDId;
  498. c.DIId = dto.DiId;
  499. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  500. c.Payee=dto.Payee;
  501. c.CreateUserId=dto.CreateUserId;
  502. if (c.PayDId == 72)
  503. {
  504. c.IsPay = 1;
  505. }
  506. c.RMBPrice = c.PayMoney;
  507. c.DayRate = 1;
  508. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  509. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  510. if (_TeamRate != null)
  511. {
  512. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  513. if (_SetData != null)
  514. {
  515. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  516. CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  517. if (CurrencyRate != null)
  518. {
  519. c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  520. c.DayRate = CurrencyRate.Rate;
  521. }
  522. }
  523. }
  524. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  525. if (grp_CreditCard!=null)//修改
  526. {
  527. 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
  528. {
  529. PaymentCurrency = c.PaymentCurrency,
  530. PayMoney = c.PayMoney,
  531. PayPercentage = c.PayPercentage,
  532. CTable = c.CTable,
  533. PayDId = c.PayDId,
  534. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  535. Payee = c.Payee,
  536. IsPay = c.IsPay,
  537. RMBPrice = c.RMBPrice,
  538. DayRate = c.DayRate,
  539. }).ExecuteCommandAsync();
  540. if (CTable == 0)
  541. {
  542. RollbackTran();
  543. return result = new Result() { Code = -2, Msg = "修改失败" };
  544. }
  545. }
  546. else//添加
  547. {
  548. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  549. if (id == 0)
  550. {
  551. RollbackTran();
  552. return result = new Result() { Code = -2, Msg = "添加失败" };
  553. }
  554. }
  555. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  556. {
  557. CId = dto.Currency,
  558. ServiceQuotedPrice = c.PayMoney,
  559. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  560. }).ExecuteCommandAsync();
  561. if (CarTouristGuideCTable == 0)
  562. {
  563. RollbackTran();
  564. return result = new Result() { Code = -2, Msg = "修改失败" };
  565. }
  566. result = new Result() { Code =0, Msg = "保存成功" };
  567. CommitTran();
  568. }
  569. catch (Exception ex)
  570. {
  571. return result = new Result() { Code = -2, Msg = "未知错误" };
  572. }
  573. return result;
  574. }
  575. }
  576. }