CarTouristGuideGroundRepository.cs 33 KB

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