CarTouristGuideGroundRepository.cs 58 KB

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