CarTouristGuideGroundRepository.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. using Aspose.Words.Tables;
  2. using AutoMapper;
  3. using NPOI.SS.Formula.Functions;
  4. using NPOI.SS.UserModel;
  5. using NPOI.Util;
  6. using OASystem.Domain;
  7. using OASystem.Domain.Dtos.Financial;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Entities.Financial;
  10. using OASystem.Domain.Entities.Groups;
  11. using OASystem.Domain.Entities.Resource;
  12. using OASystem.Domain.ViewModels.Groups;
  13. using OASystem.Infrastructure.Repositories.Financial;
  14. using OASystem.Infrastructure.Repositories.System;
  15. using OASystem.Infrastructure.Tools;
  16. using SqlSugar.Extensions;
  17. using System.Collections.Generic;
  18. using System.Reflection;
  19. namespace OASystem.Infrastructure.Repositories.Groups
  20. {
  21. public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  22. {
  23. private readonly IMapper _mapper;
  24. private readonly CheckBoxsRepository _checkRep;
  25. private readonly SetDataRepository _setDataRep;
  26. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  27. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper , CheckBoxsRepository checkRep, SetDataRepository setDataRep, DailyFeePaymentRepository daiRep)
  28. : base(sqlSugar)
  29. {
  30. _mapper = mapper;
  31. _checkRep = checkRep;
  32. _setDataRep = setDataRep;
  33. _daiRep = daiRep;
  34. }
  35. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  36. {
  37. Result result = new Result() { Code = -2, Msg = "未知错误" };
  38. BeginTran();
  39. try
  40. {
  41. int id = 0;
  42. Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  43. if (dto.Status == 1)//添加
  44. {
  45. 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);
  46. if (grp_CarTouristGuideGround != null)
  47. {
  48. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  49. }
  50. else
  51. {
  52. id = await AddAsyncReturnId(grp_CarTouristGuide);
  53. if (id == 0)
  54. {
  55. RollbackTran();
  56. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  57. }
  58. else
  59. {
  60. result = new Result() { Code = 0, Msg = "添加成功!" };
  61. }
  62. }
  63. }
  64. else if (dto.Status == 2)//修改
  65. {
  66. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  67. {
  68. Area = grp_CarTouristGuide.Area,
  69. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  70. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  71. ServiceTel = grp_CarTouristGuide.ServiceTel,
  72. BusName = grp_CarTouristGuide.BusName,
  73. BusDescription = grp_CarTouristGuide.BusDescription,
  74. BusTel = grp_CarTouristGuide.BusTel,
  75. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  76. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  77. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  78. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  79. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  80. Remark = grp_CarTouristGuide.Remark,
  81. });
  82. if (res)
  83. {
  84. id = dto.Id;
  85. result = new Result() { Code = 0, Msg = "修改成功!" };
  86. }
  87. else
  88. {
  89. RollbackTran();
  90. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  91. }
  92. }
  93. if (id!=0)
  94. {
  95. Res_LocalGuideData _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.BusName && a.ContactTel == dto.BusTel && a.IsDel == 0);
  96. if (_LocalGuideDataCar == null)
  97. {
  98. Res_LocalGuideData res_LocalGuideCar = new Res_LocalGuideData();
  99. res_LocalGuideCar.UnitName = dto.BusName;
  100. res_LocalGuideCar.ContactTel = dto.BusTel;
  101. res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  102. int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  103. }
  104. Res_LocalGuideData _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>().First(a => a.UnitName == dto.ServiceCompany && a.ContactTel == dto.ServiceTel && a.IsDel == 0);
  105. if (_LocalGuideDataService == null)
  106. {
  107. Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  108. res_LocalGuideService.UnitName = dto.ServiceCompany;
  109. res_LocalGuideService.ContactTel = dto.ServiceTel;
  110. res_LocalGuideService.Contact = dto.ServiceTel;
  111. res_LocalGuideService.CreateUserId = dto.CreateUserId;
  112. int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  113. }
  114. }
  115. CommitTran();
  116. }
  117. catch (Exception ex)
  118. {
  119. result = new Result() { Code = -2, Msg = "未知错误" };
  120. }
  121. return result;
  122. }
  123. public Result CarTouristGuideGroundContent(CarTouristGuideGroundContentDto dto)
  124. {
  125. Result result = new Result() { Code = -2, Msg = "未知错误" };
  126. try
  127. {
  128. DateTime start = new DateTime();
  129. DateTime end = new DateTime();
  130. Grp_CarTouristGuideGroundReservations grpCarOp = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.Id);
  131. if (!DateTime.TryParse(grpCarOp?.ServiceStartTime, out start))
  132. {
  133. result.Msg = "服务开始时间不存在!";
  134. result.Code = -1;
  135. return result;
  136. }
  137. if (!DateTime.TryParse(grpCarOp?.ServiceEndTime, out end))
  138. {
  139. result.Msg = "服务结束时间不存在!";
  140. result.Code = -1;
  141. return result;
  142. }
  143. TimeSpan ts = end - start; //计算时间差
  144. int day = ts.Days;
  145. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79).ToList();
  146. string DiId = "0";
  147. foreach (var item in grp_GroupsTaskAssignment)
  148. {
  149. DiId += item.DIId + ",";
  150. }
  151. if (DiId != "0")
  152. {
  153. DiId = DiId.Substring(0, DiId.Length - 1);
  154. }
  155. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  156. //团组下拉框
  157. List<Grp_DelegationInfo> _Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  158. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(_Delegations);
  159. //支付方式
  160. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  161. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  162. //列表初始化
  163. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  164. List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  165. List<Sys_SetData> ssd = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 78).ToList();
  166. List<SetDataInfoView> ssdv = _mapper.Map<List<Sys_SetData>,List<SetDataInfoView>>(ssd);
  167. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  168. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  169. foreach (var itemSt in TableInitialization)
  170. {
  171. var findResult = carTouristGuides.Find(x => x.SId == itemSt.Id);
  172. if (findResult == null)
  173. {
  174. carTouristGuides.Add(new CarTouristGuideGroundReservationsContentView
  175. {
  176. SId = itemSt.Id,
  177. Count = 1,
  178. SidName = itemSt.Name,
  179. });
  180. }
  181. }
  182. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x => x.Key, x => x.ToList());
  183. foreach (var item in groupResult.Keys)
  184. {
  185. #region 倒推初始化逻辑
  186. //while (groupResult[item].Count <= day)
  187. //{
  188. // groupResult[item] = groupResult[item].OrderByDescending(x => x.DatePrice).ToList();
  189. // if (groupResult[item][0]?.DatePrice is not null)
  190. // {
  191. // groupResult[item].Add(new CarTouristGuideGroundReservationsContentView
  192. // {
  193. // DatePrice = groupResult[item][0].DatePrice.ObjToDate().AddDays(1),
  194. // SId = item,
  195. // Count = 1,
  196. // });
  197. // }
  198. // else
  199. // {
  200. // groupResult[item][0].DatePrice = start;
  201. // }
  202. //}
  203. #endregion
  204. var startForTime = start;
  205. var dayResult = new List<CarTouristGuideGroundReservationsContentView>();
  206. for (var i = 0; i <= day; i++)
  207. {
  208. dayResult.Add(new CarTouristGuideGroundReservationsContentView
  209. {
  210. Count = 1,
  211. DatePrice = startForTime,
  212. SId = item,
  213. });
  214. startForTime = startForTime.AddDays(1);
  215. }
  216. if (groupResult[item].Count != day)
  217. {
  218. for (var m = 0; m< groupResult[item].Count; m++)
  219. {
  220. for (var m1 = 0; m1 < dayResult.Count; m1++)
  221. {
  222. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  223. {
  224. dayResult[m1] = groupResult[item][m];
  225. }
  226. }
  227. }
  228. }
  229. else
  230. {
  231. groupResult[item] = groupResult[item].OrderBy(x => x.DatePrice).ToList();
  232. if (groupResult[item][0].DatePrice == dayResult[0].DatePrice && groupResult[item][day - 1].DatePrice == dayResult[day - 1].DatePrice)
  233. {
  234. dayResult = groupResult[item];
  235. }
  236. else
  237. {
  238. for (var m = 0; m < groupResult[item].Count; m++)
  239. {
  240. for (var m1 = 0; m1 < dayResult.Count; m1++)
  241. {
  242. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  243. {
  244. dayResult[m1] = groupResult[item][m];
  245. }
  246. }
  247. }
  248. }
  249. }
  250. groupResult[item] = dayResult;
  251. }
  252. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).OrderBy(x => x.SId).ThenBy(x => x.DatePrice).ToList();
  253. foreach (var item in carTouristGuides.Where(x => string.IsNullOrWhiteSpace(x.SidName)).ToList())
  254. {
  255. item.SidName = TableInitialization.Find(x => x.Id == item.SId)?.Name;
  256. }
  257. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  258. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  259. if (_CreditCardPayment != null)
  260. {
  261. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  262. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  263. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  264. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  265. }
  266. Dictionary<string, string> soureDic = new Dictionary<string, string>()
  267. {
  268. {"车费", "VF"},
  269. {"导游费", "T/G S"},
  270. {"客户午餐费用" , "L"},
  271. {"导游景点费" , "T/G EF"},
  272. {"导游小费" , "T/G T"},
  273. // --
  274. {"司机小费", "DRV T"},
  275. {"司机餐补", "C/F M"},
  276. {"车超时费", "C/F OF"},
  277. {"导游餐补", "T/G M"},
  278. {"导游房补", "T/G A"},
  279. {"导游交通", "T/G TF"},
  280. {"客户早餐费用", "B"},
  281. {"客户晚餐费用", "D"},
  282. {"景点门票费", "EF"},
  283. {"饮料/零食/水果", "B/R/F"},
  284. {"翻译费", "I/F"},
  285. };
  286. var checkedItem = new List<string>();
  287. var checkedItemId = new List<int>();
  288. if (string.IsNullOrWhiteSpace(grpCarOp.SelectCheck))
  289. {
  290. //获取成本选中
  291. var checkTopArr = _checkRep.GetCheckBoxsByDiid(grpCarOp.DiId);
  292. if (true)
  293. {
  294. var FindTop = checkTopArr.Find(x => x.CbType == "Top");
  295. if (FindTop != null)
  296. {
  297. var selectName = FindTop.CbValues.Split(',').ToList<string>();
  298. foreach (var soureKey in soureDic.Keys)
  299. {
  300. var find = selectName.Find(x => x == soureDic[soureKey]);
  301. if (find == null)
  302. {
  303. var Lindex = carTouristGuides.FindIndex(x => x.SidName == soureKey);
  304. //carTouristGuides.RemoveRange(Lindex, day + 1);
  305. }
  306. else
  307. {
  308. checkedItem.Add(soureKey);
  309. checkedItemId.Add(_TableInitialization.Find(x=>x.Name == soureKey)!.Id);
  310. }
  311. }
  312. }
  313. else
  314. {
  315. checkedItem = new List<string>() { "车费", "导游费", "客户午餐费用", "导游景点费", "导游小费", "接送机费", "其他费用", "司机工资", "司机小费", "司机餐补", "车超时费", "导游餐补", "导游房补", "导游交通", "客户早餐费用", "客户晚餐费用", "景点门票费", "饮料/零食/水果", "住补费用", "翻译费" };
  316. checkedItemId.AddRange(_TableInitialization.Select(x => x.Id).ToList());
  317. }
  318. }
  319. }
  320. else
  321. {
  322. var checkedItemThis = grpCarOp.SelectCheck.Split(",").ToList<string>();
  323. int number = 0;
  324. foreach (var item in checkedItemThis)
  325. {
  326. if (!int.TryParse(item,out number))
  327. {
  328. checkedItemId.Add(_TableInitialization.Find(x => x.Name == item)!.Id);
  329. checkedItem.Add(item);
  330. }
  331. else
  332. {
  333. checkedItemId.Add(number);
  334. checkedItem.Add(_TableInitialization.Find(x => x.Id == int.Parse(item))!.Name);
  335. }
  336. }
  337. }
  338. if(dto.PortType == 1)
  339. {
  340. var data = new
  341. {
  342. Payment = _Payment,
  343. Delegations = grp_Delegations,
  344. carTouristGuides = carTouristGuides,
  345. CreditCardPayment = _CreditCardPayment,
  346. start,
  347. end,
  348. ssdv,
  349. checkedItem
  350. };
  351. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  352. } else if(dto.PortType == 2)
  353. {
  354. var data = new
  355. {
  356. Payment = _Payment,
  357. TableInitialization = _TableInitialization,
  358. carTouristGuides = carTouristGuides,
  359. CreditCardPayment = _CreditCardPayment ??= new CarTouristCreditCardPaymentView(),
  360. ssdv,
  361. checkedItemId
  362. };
  363. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  364. }
  365. return result = new Result() { Code = -1, Msg = "请传入有效portType" };
  366. }
  367. catch (Exception ex)
  368. {
  369. return result = new Result() { Code = -2, Msg = "未知错误" };
  370. }
  371. }
  372. /// <summary>
  373. /// web弃用
  374. /// </summary>
  375. /// <param name="dto"></param>
  376. /// <returns></returns>
  377. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  378. {
  379. Result result = new Result() { Code = -2, Msg = "未知错误" };
  380. try
  381. {
  382. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  383. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  384. foreach (var item in carTouristGuides)
  385. {
  386. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  387. }
  388. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  389. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  390. if (_CreditCardPayment!=null)
  391. {
  392. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  393. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  394. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  395. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  396. }
  397. var data = new
  398. {
  399. CarTouristsContent = carTouristGuides,
  400. CreditCardPayment = _CreditCardPayment,
  401. };
  402. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  403. }
  404. catch (Exception ex)
  405. {
  406. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  407. }
  408. }
  409. /// <summary>
  410. /// 根据diid查询op费用列表
  411. /// </summary>
  412. /// <param name="dto"></param>
  413. /// <returns></returns>
  414. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  415. {
  416. Result result = new Result() { Code = -2, Msg = "未知错误" };
  417. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  418. {
  419. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  420. }
  421. try
  422. {
  423. #region SQL条件拼接
  424. string sqlWhere = string.Empty;
  425. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  426. string UserId = "";
  427. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  428. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  429. UserId += gta.UId + ",";
  430. if (!string.IsNullOrWhiteSpace(UserId))
  431. {
  432. UserId = UserId.Substring(0, UserId.Length - 1);
  433. }
  434. else
  435. {
  436. UserId = "0";
  437. }
  438. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  439. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  440. {
  441. Regex r = new Regex("And");
  442. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  443. }
  444. #endregion
  445. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  446. int endIndex = startIndex + dto.PageSize - 1;
  447. Regex regex = new Regex("^[\u4e00-\u9fa5]*$");
  448. //城市列表
  449. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => new
  450. {
  451. x.Id,
  452. x.Country,
  453. x.City,
  454. }).ToList();
  455. if (dto.PortType == 1)
  456. {
  457. string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid from
  458. Grp_CarTouristGuideGroundReservations t
  459. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  460. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  461. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  462. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  463. foreach (var item in infoViews)
  464. {
  465. if(!regex.IsMatch(item.Area))
  466. {
  467. for(int i = 0; i < data.Count; i++)
  468. {
  469. if (item.Area.Equals(data[i].Id.ToString()))
  470. {
  471. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  472. }
  473. }
  474. }
  475. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  476. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  477. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  478. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  479. item.ServiceQuotedPrice = item.PayMoney;
  480. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  481. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice,2);
  482. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  483. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  484. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  485. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  486. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  487. if (s!=null)
  488. {
  489. item.PayStrd = s.Name;
  490. }else item.PayStrd ="未选择";
  491. }
  492. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  493. }
  494. else if (dto.PortType == 2 || dto.PortType == 3)
  495. {
  496. string sql = string.Format(@"Select * From (
  497. 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
  498. from
  499. Grp_CarTouristGuideGroundReservations t
  500. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  501. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  502. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  503. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  504. foreach (var item in grp_CarTourists)
  505. {
  506. if (!regex.IsMatch(item.Area))
  507. {
  508. for (int i = 0; i < data.Count; i++)
  509. {
  510. if (item.Area.Equals(data[i].Id.ToString()))
  511. {
  512. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  513. }
  514. }
  515. }
  516. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  517. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  518. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  519. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  520. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  521. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  522. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  523. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  524. item.ServiceQuotedPrice = item.PayMoney;
  525. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  526. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice,2);
  527. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  528. if (s != null)
  529. {
  530. item.PayStrd = s.Name;
  531. }
  532. else item.PayStrd = "未选择";
  533. }
  534. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  535. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  536. Grp_CarTouristGuideGroundReservations t
  537. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  538. left Join Sys_SetData s on s.Id=t.CId {0}
  539. ) temp ", sqlWhere);
  540. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  541. if (dataCount != null)
  542. {
  543. int count = dataCount.Count;
  544. float totalPage = (float)count / dto.PageSize;//总页数
  545. if (totalPage == 0) totalPage = 1;
  546. else totalPage = (int)Math.Ceiling((double)totalPage);
  547. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  548. rst.DataList = grp_CarTourists;
  549. rst.DataCount = count;
  550. rst.CurrPageIndex = dto.PageIndex;
  551. rst.CurrPageSize = dto.PageSize;
  552. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  553. }
  554. }
  555. }
  556. catch (Exception)
  557. {
  558. return result = new Result() { Code = -2, Msg = "未知错误" };
  559. }
  560. return result;
  561. }
  562. /// <summary>
  563. /// OP费用录入填写详情
  564. /// </summary>
  565. /// <param name="dto"></param>
  566. /// <returns></returns>
  567. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  568. {
  569. Result result = new Result() { Code = -2, Msg = "未知错误" };
  570. try
  571. {
  572. BeginTran();
  573. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  574. {
  575. Id = item.Id,
  576. DiId = dto.DiId,
  577. CTGGRId = dto.CTGGRId,
  578. SId = item.SId,
  579. Price = item.Price,
  580. PriceContent = item.priceContent,
  581. Currency = dto.Currency,
  582. CreateUserId = dto.CreateUserId,
  583. Units = item.Units,
  584. DatePrice = item.DatePrice,
  585. Count = item.Count,
  586. }).ToList();
  587. if (carTouristList.Count > 0)
  588. {
  589. #region load
  590. //车超时费
  591. //餐费和三公经费那个表做完匹配后也放进超支表里
  592. DataTable tb = new DataTable();
  593. tb.Columns.Add("日期", typeof(DateTime));
  594. tb.Columns.Add("费用", typeof(decimal));
  595. tb.Columns.Add("币种", typeof(string));
  596. var addsTourClientList = new List<Grp_TourClientList>();
  597. var carExtraList = carTouristList.Where(x => x.SId == 982 && x.Price != 0).ToList();
  598. var mealPriceList = carTouristList.Where(x => (x.SId == 93 || x.SId == 988 || x.SId == 989) && x.Price != 0).GroupBy(x => x.DatePrice).ToList();
  599. mealPriceList.ForEach(x =>
  600. {
  601. var row = tb.NewRow();
  602. row["日期"] = x.Key;
  603. row["费用"] = x.Sum(x => x.Price * x.Count);
  604. row["币种"] = x.FirstOrDefault()?.Currency;
  605. tb.Rows.Add(row);
  606. });
  607. //限制只能选择地区
  608. var opSingle = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x=>x.Id == dto.CTGGRId);
  609. var opSingleCityId = 0;
  610. Grp_NationalTravelFee cityPrice = null;
  611. //三公费用
  612. if (int.TryParse(opSingle.Area,out opSingleCityId))
  613. {
  614. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  615. x.Id == opSingleCityId
  616. ).First();
  617. }
  618. else
  619. {
  620. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  621. !string.IsNullOrEmpty(x.City) && x.City.Contains(opSingle.Area)
  622. ).First();
  623. }
  624. //超支费用表(数据添加) Fin_GroupExtraCost
  625. List<Fin_GroupExtraCost> groupExtraCostsArr = new List<Fin_GroupExtraCost>();
  626. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId);
  627. if (di == null)
  628. {
  629. result.Code = -1;
  630. result.Msg = "无该团组信息!";
  631. return result;
  632. }
  633. if (carExtraList.Count > 0)
  634. {
  635. foreach (var item in carExtraList)
  636. {
  637. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  638. {
  639. Price = item.Price,
  640. CreateTime = DateTime.Now,
  641. CreateUserId = dto.CreateUserId,
  642. Coefficient = 1,
  643. DiId = dto.DiId,
  644. PriceCurrency = item.Currency,
  645. PriceName = di.TeamName + "车超时费(地接导入)",
  646. PriceType = 1028,
  647. PriceDt = item.DatePrice.ObjToDate(),
  648. PriceSum = item.Price * item.Count,
  649. PriceCount = item.Count,
  650. FilePath = string.Empty,
  651. PriceDetailType = 1050,
  652. });
  653. }
  654. }
  655. if (cityPrice != null)
  656. {
  657. //币种
  658. var currOpResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, carTouristList[0].Currency);
  659. var currOp = currOpResult.Code == 0 ? (currOpResult.Data as CurrencyInfo) == null ? 1 : (currOpResult.Data as CurrencyInfo)!.Rate : 1;
  660. var cityCurrResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, cityPrice.Currency);
  661. var cityCurr = cityCurrResult.Code == 0 ? (cityCurrResult.Data as CurrencyInfo) == null ? 1 : (cityCurrResult.Data as CurrencyInfo)!.Rate : 1;
  662. if (tb.Rows.Count > 0)
  663. {
  664. foreach (DataRow item in tb.Rows)
  665. {
  666. decimal foodCost = 1;
  667. if (!decimal.TryParse(cityPrice.FoodCost, out foodCost))
  668. {
  669. //三公费用 ( 城市餐费用有问题! )
  670. }
  671. var price = Convert.ToDecimal(item["费用"]);
  672. if (item["币种"].ToString() != cityPrice.Currency.ToString()) //币种不相同
  673. {
  674. //全部转换为rmb;
  675. item["费用"] = price * currOp;
  676. cityPrice.FoodCost = (foodCost * cityCurr).ToString("F2");
  677. item["币种"] = "836";
  678. cityPrice.Currency = 836;
  679. }
  680. if (price > foodCost)
  681. {
  682. //每天费用大于三公费用
  683. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  684. {
  685. Price = price - foodCost,
  686. CreateTime = DateTime.Now,
  687. CreateUserId = dto.CreateUserId,
  688. Coefficient = 1,
  689. DiId = dto.DiId,
  690. PriceCurrency = cityPrice.Currency,
  691. PriceName = di.TeamName + "餐费(地接导入)",
  692. PriceType = 1028,
  693. PriceDt = Convert.ToDateTime(item["日期"]),
  694. PriceSum = price - foodCost,
  695. PriceCount = 1,
  696. FilePath = string.Empty,
  697. PriceDetailType = 1049,
  698. });
  699. }
  700. }
  701. }
  702. }
  703. var isTrue = false;
  704. if (groupExtraCostsArr.Count > 0)
  705. {
  706. foreach (var item in groupExtraCostsArr)
  707. {
  708. var QuerySgin = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(x => x.PriceName == item.PriceName && x.DiId == item.DiId && x.IsDel == 0 && item.PriceDt.ToString("yyyy-MM-dd") == item.PriceDt.ToString("yyyy-MM-dd")).First();
  709. if (QuerySgin == null)
  710. {
  711. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  712. {
  713. coefficient = 1,
  714. createUser = dto.CreateUserId,
  715. currency = item.PriceCurrency,
  716. diId = item.DiId,
  717. editType = 1,
  718. filePath = string.Empty,
  719. payee = dto.Payee,
  720. PortType = 1,
  721. PriceCount = item.PriceCount,
  722. priceName = item.PriceName,
  723. remark = item.Remark,
  724. price = item.Price,
  725. priceDetailType = item.PriceDetailType,
  726. priceType = item.PriceType,
  727. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  728. payType = dto.PayDId,
  729. costSign = dto.OrbitalPrivateTransfer
  730. });
  731. isTrue = resultThis.Code == 0 ? true : false;
  732. }
  733. else
  734. {
  735. item.Id = QuerySgin.Id;
  736. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  737. {
  738. coefficient = 1,
  739. createUser = dto.CreateUserId,
  740. currency = item.PriceCurrency,
  741. diId = item.DiId,
  742. editType = 2,
  743. filePath = string.Empty,
  744. payee = dto.Payee,
  745. PortType = 1,
  746. PriceCount = item.PriceCount,
  747. priceName = item.PriceName,
  748. remark = item.Remark,
  749. price = item.Price,
  750. priceDetailType = item.PriceDetailType,
  751. priceType = item.PriceType,
  752. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  753. payType = dto.PayDId,
  754. costSign = dto.OrbitalPrivateTransfer,
  755. Id = item.Id,
  756. });
  757. isTrue = resultThis.Code == 0 ? true : false;
  758. }
  759. }
  760. }
  761. #endregion
  762. }
  763. foreach (var item in carTouristList)
  764. {
  765. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  766. if (QueryData==null)
  767. {
  768. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  769. if (id == 0)
  770. {
  771. RollbackTran();
  772. return result = new Result() { Code = -2, Msg = "添加失败" };
  773. }
  774. }
  775. else
  776. {
  777. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  778. {
  779. Price = item.Price,
  780. PriceContent = item.PriceContent,
  781. Currency = dto.Currency,
  782. Remark = item.Remark,
  783. DatePrice = item.DatePrice,
  784. Count = item.Count,
  785. Units = item.Units,
  786. }).ExecuteCommandAsync();
  787. if (CTable==0)
  788. {
  789. RollbackTran();
  790. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  791. }
  792. }
  793. }
  794. Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");
  795. //修改C表数据
  796. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  797. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  798. c.PaymentCurrency = dto.Currency;
  799. for (int i = 0; i < dto.SelectCheck.Count; i++) {
  800. if (!regex.IsMatch(dto.SelectCheck[i]))
  801. {
  802. for(int j = 0; j < carTouristList.Count; j++)
  803. {
  804. if (int.Parse(dto.SelectCheck[i]) == carTouristList[j].SId)
  805. {
  806. c.PayMoney += carTouristList[j].Price * carTouristList[j].Count;
  807. }
  808. }
  809. } else
  810. {
  811. c.PayMoney = carTouristList.Sum(x => x.Price * x.Count);
  812. break;
  813. }
  814. }
  815. c.PayPercentage = dto.PayPercentage;
  816. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  817. c.CTable = 79;
  818. c.CId = dto.CTGGRId;
  819. c.IsAuditGM = 0;
  820. c.PayDId=dto.PayDId;
  821. c.DIId = dto.DiId;
  822. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  823. c.Payee=dto.Payee;
  824. c.CreateUserId=dto.CreateUserId;
  825. if (c.PayDId == 72)
  826. {
  827. c.IsPay = 1;
  828. }
  829. c.RMBPrice = c.PayMoney;
  830. c.DayRate = 1;
  831. #region 老汇率获取
  832. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  833. //List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  834. //if (_TeamRate != null)
  835. //{
  836. // Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  837. // if (_SetData != null)
  838. // {
  839. // currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  840. // CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  841. // if (CurrencyRate != null)
  842. // {
  843. // c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  844. // c.DayRate = CurrencyRate.Rate;
  845. // }
  846. // }
  847. //}
  848. #endregion
  849. var rate = await _setDataRep.PostCurrencyByDiid(dto.DiId, dto.CTGGRId, dto.Currency);
  850. if (rate.Code == 0)
  851. {
  852. var rateData = rate.Data as CurrencyInfo;
  853. if (rateData != null)
  854. {
  855. c.RMBPrice = c.PayMoney * rateData.Rate;
  856. c.DayRate = rateData.Rate;
  857. }
  858. }
  859. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  860. if (grp_CreditCard!=null)//修改
  861. {
  862. 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
  863. {
  864. PaymentCurrency = c.PaymentCurrency,
  865. PayMoney = c.PayMoney,
  866. PayPercentage = c.PayPercentage,
  867. CTable = c.CTable,
  868. PayDId = c.PayDId,
  869. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  870. Payee = c.Payee,
  871. IsPay = c.IsPay,
  872. RMBPrice = c.RMBPrice,
  873. DayRate = c.DayRate,
  874. }).ExecuteCommandAsync();
  875. if (CTable == 0)
  876. {
  877. RollbackTran();
  878. return result = new Result() { Code = -2, Msg = "修改失败" };
  879. }
  880. }
  881. else//添加
  882. {
  883. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  884. if (id == 0)
  885. {
  886. RollbackTran();
  887. return result = new Result() { Code = -2, Msg = "添加失败" };
  888. }
  889. }
  890. int CarTouristGuideCTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>().Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId && a.IsDel == 0).SetColumns(a => new Grp_CarTouristGuideGroundReservations
  891. {
  892. CId = dto.Currency,
  893. ServiceQuotedPrice = c.PayMoney,
  894. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  895. SelectCheck = string.Join(',', dto.SelectCheck)
  896. }).ExecuteCommandAsync();
  897. if (CarTouristGuideCTable == 0)
  898. {
  899. RollbackTran();
  900. return result = new Result() { Code = -2, Msg = "修改失败" };
  901. }
  902. result = new Result() { Code =0, Msg = "保存成功" };
  903. CommitTran();
  904. }
  905. catch (Exception ex)
  906. {
  907. RollbackTran();
  908. return result = new Result() { Code = -2, Msg = "未知错误" };
  909. }
  910. return result;
  911. }
  912. /// <summary>
  913. /// 超支费用
  914. /// 1增、2改、3删
  915. /// </summary>
  916. /// <param name="dto"></param>
  917. /// <returns></returns>
  918. private async Task<Result> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  919. {
  920. Result rt = new Result();
  921. #region 验证
  922. #endregion
  923. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  924. _entity.DiId = dto.diId;
  925. _entity.PriceName = dto.priceName;
  926. _entity.Price = dto.price;
  927. _entity.PriceCurrency = dto.currency;
  928. _entity.PriceType = dto.priceType;
  929. _entity.Coefficient = dto.coefficient;
  930. _entity.PriceDetailType = dto.priceDetailType;
  931. _entity.FilePath = dto.filePath;
  932. _entity.Remark = dto.remark;
  933. _entity.PriceCount = dto.PriceCount;
  934. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  935. _entity.PriceSum = dto.price * dto.PriceCount;
  936. _daiRep.BeginTran();
  937. if (dto.editType == 1)
  938. {
  939. _entity.CreateUserId = dto.createUser;
  940. _entity.CreateTime = DateTime.Now;
  941. _entity.IsDel = 0;
  942. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  943. if (returnId > 0)
  944. {
  945. dto.Id = returnId;
  946. }
  947. }
  948. else if (dto.editType == 2)
  949. {
  950. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  951. {
  952. PriceName = dto.priceName,
  953. Price = dto.price,
  954. PriceCurrency = dto.currency,
  955. PriceType = dto.priceType,
  956. PriceDetailType = dto.priceDetailType,
  957. Coefficient = dto.coefficient,
  958. FilePath = dto.filePath,
  959. Remark = dto.remark,
  960. PriceCount = dto.PriceCount,
  961. PriceDt = _entity.PriceDt,
  962. PriceSum = _entity.PriceSum
  963. });
  964. if (!res)
  965. {
  966. _daiRep.RollbackTran();
  967. //Ok(JsonView(false, "2操作失败!"))
  968. rt.Msg = "2操作失败!";
  969. return rt;
  970. }
  971. }
  972. else if (dto.editType == 3)
  973. {
  974. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  975. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  976. {
  977. IsDel = 1,
  978. DeleteTime = delTime,
  979. DeleteUserId = dto.createUser
  980. });
  981. if (!res)
  982. {
  983. _daiRep.RollbackTran();
  984. rt.Msg = "3操作失败!";
  985. return rt;
  986. }
  987. }
  988. else
  989. {
  990. _daiRep.RollbackTran();
  991. rt.Msg = "未知的editType";
  992. return rt;
  993. }
  994. if (!extraCost_editCreditCardPayment(dto))
  995. {
  996. rt.Msg = "ccp操作失败";
  997. return rt;
  998. }
  999. _daiRep.CommitTran();
  1000. rt.Code = 0;
  1001. rt.Msg = "操作成功";
  1002. return rt;
  1003. }
  1004. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1005. {
  1006. //设置团组汇率
  1007. decimal dcm_dayrate = 1M;
  1008. decimal dcm_rmbPrice = costDto.price;
  1009. int ispay = costDto.payType == 72 ? 1 : 0;
  1010. if (costDto.costSign != 3)
  1011. {
  1012. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1013. if (tr != null)
  1014. {
  1015. if (costDto.currency == 49)
  1016. {
  1017. dcm_dayrate = tr.RateU;
  1018. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1019. }
  1020. else if (costDto.currency == 51)
  1021. {
  1022. dcm_dayrate = tr.RateE;
  1023. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1024. }
  1025. }
  1026. }
  1027. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1028. if (ccp == null)
  1029. {
  1030. ccp = new Grp_CreditCardPayment();
  1031. ccp.PayDId = costDto.payType;// dto
  1032. ccp.ConsumptionPatterns = "";
  1033. ccp.ConsumptionDate = "";
  1034. ccp.CTDId = costDto.payCardId;// dto
  1035. ccp.BankNo = "";
  1036. ccp.CardholderName = "";
  1037. ccp.PayMoney = costDto.price;// dto
  1038. ccp.PaymentCurrency = costDto.currency;// dto
  1039. ccp.CompanyBankNo = "";
  1040. ccp.OtherBankName = "";
  1041. ccp.OtherSideNo = "";
  1042. ccp.OtherSideName = "";
  1043. ccp.Remark = "";
  1044. ccp.CreateUserId = costDto.createUser;
  1045. ccp.CreateTime = DateTime.Now;
  1046. ccp.MFOperator = 0;
  1047. ccp.MFOperatorDate = "";
  1048. ccp.IsAuditDM = 0;
  1049. ccp.AuditDMOperate = 0;
  1050. ccp.AuditDMDate = "";
  1051. ccp.IsAuditMF = 0;
  1052. ccp.AuditMFOperate = 0;
  1053. ccp.AuditMFDate = "";
  1054. ccp.IsAuditGM = 0;
  1055. ccp.AuditGMOperate = 0;
  1056. ccp.AuditGMDate = "";
  1057. ccp.IsPay = ispay; // upd
  1058. ccp.DIId = costDto.diId;// dto
  1059. ccp.CId = costDto.Id;// dto
  1060. ccp.CTable = 1015; //超支费用指向id
  1061. ccp.IsDel = 0;
  1062. ccp.PayPercentage = 100M;
  1063. ccp.PayThenMoney = 0M;
  1064. ccp.PayPercentageOld = 100M;
  1065. ccp.PayThenMoneyOld = 0M;
  1066. ccp.UpdateDate = "";
  1067. ccp.Payee = costDto.payee;// dto
  1068. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1069. ccp.ExceedBudget = 0;
  1070. ccp.DayRate = dcm_dayrate; //upd
  1071. ccp.RMBPrice = dcm_rmbPrice; //upd
  1072. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1073. if (ccpInsertId > 0)
  1074. {
  1075. return true;
  1076. }
  1077. }
  1078. else
  1079. {
  1080. if (costDto.editType == 2)
  1081. {
  1082. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1083. {
  1084. PayDId = costDto.payType,
  1085. CTDId = costDto.payCardId,
  1086. PayMoney = costDto.price,
  1087. PaymentCurrency = costDto.currency,
  1088. IsPay = ispay,
  1089. Payee = costDto.payee,
  1090. OrbitalPrivateTransfer = costDto.costSign,
  1091. DayRate = dcm_dayrate,
  1092. RMBPrice = dcm_rmbPrice
  1093. });
  1094. return res;
  1095. }
  1096. else if (costDto.editType == 3)
  1097. {
  1098. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1099. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1100. {
  1101. IsDel = 1,
  1102. DeleteTime = delTime,
  1103. DeleteUserId = costDto.createUser
  1104. });
  1105. return res2;
  1106. }
  1107. }
  1108. return false;
  1109. }
  1110. }
  1111. }