CarTouristGuideGroundRepository.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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. };
  352. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  353. } else if(dto.PortType == 2)
  354. {
  355. var data = new
  356. {
  357. Payment = _Payment,
  358. TableInitialization = _TableInitialization,
  359. carTouristGuides = carTouristGuides,
  360. CreditCardPayment = _CreditCardPayment ??= new CarTouristCreditCardPaymentView(),
  361. ssdv,
  362. checkedItemId
  363. };
  364. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  365. }
  366. return result = new Result() { Code = -1, Msg = "请传入有效portType" };
  367. }
  368. catch (Exception ex)
  369. {
  370. return result = new Result() { Code = -2, Msg = "未知错误" };
  371. }
  372. }
  373. /// <summary>
  374. /// web弃用
  375. /// </summary>
  376. /// <param name="dto"></param>
  377. /// <returns></returns>
  378. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  379. {
  380. Result result = new Result() { Code = -2, Msg = "未知错误" };
  381. try
  382. {
  383. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.IsDel==0 && a.CTGGRId==dto.Id).ToList();
  384. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  385. foreach (var item in carTouristGuides)
  386. {
  387. item.SidName= _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  388. }
  389. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  390. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  391. if (_CreditCardPayment!=null)
  392. {
  393. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  394. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  395. if (_CreditCardPayment.OrbitalPrivateTransfer==0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  396. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  397. }
  398. var data = new
  399. {
  400. CarTouristsContent = carTouristGuides,
  401. CreditCardPayment = _CreditCardPayment,
  402. };
  403. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  404. }
  405. catch (Exception ex)
  406. {
  407. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message+")" };
  408. }
  409. }
  410. /// <summary>
  411. /// 根据diid查询op费用列表
  412. /// </summary>
  413. /// <param name="dto"></param>
  414. /// <returns></returns>
  415. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  416. {
  417. Result result = new Result() { Code = -2, Msg = "未知错误" };
  418. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  419. {
  420. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  421. }
  422. try
  423. {
  424. #region SQL条件拼接
  425. string sqlWhere = string.Empty;
  426. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  427. string UserId = "";
  428. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  429. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  430. UserId += gta.UId + ",";
  431. if (!string.IsNullOrWhiteSpace(UserId))
  432. {
  433. UserId = UserId.Substring(0, UserId.Length - 1);
  434. }
  435. else
  436. {
  437. UserId = "0";
  438. }
  439. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  440. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  441. {
  442. Regex r = new Regex("And");
  443. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  444. }
  445. #endregion
  446. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  447. int endIndex = startIndex + dto.PageSize - 1;
  448. Regex regex = new Regex("^[\u4e00-\u9fa5]*$");
  449. //城市列表
  450. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => new
  451. {
  452. x.Id,
  453. x.Country,
  454. x.City,
  455. }).ToList();
  456. if (dto.PortType == 1)
  457. {
  458. 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
  459. Grp_CarTouristGuideGroundReservations t
  460. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  461. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  462. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  463. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  464. foreach (var item in infoViews)
  465. {
  466. if(!regex.IsMatch(item.Area))
  467. {
  468. for(int i = 0; i < data.Count; i++)
  469. {
  470. if (item.Area.Equals(data[i].Id.ToString()))
  471. {
  472. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  473. }
  474. }
  475. }
  476. if (string.IsNullOrWhiteSpace(item.priceTypeStr))
  477. {
  478. item.priceTypeStr = "未选择!";
  479. }
  480. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  481. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  482. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  483. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  484. item.ServiceQuotedPrice = item.PayMoney;
  485. item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
  486. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice,2);
  487. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  488. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  489. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  490. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  491. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a=>a.IsDel==0 && a.Id==item.PayDid);
  492. if (s!=null)
  493. {
  494. item.PayStrd = s.Name;
  495. }else item.PayStrd ="未选择";
  496. }
  497. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  498. }
  499. else if (dto.PortType == 2 || dto.PortType == 3)
  500. {
  501. string sql = string.Format(@"Select * From (
  502. 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
  503. from
  504. Grp_CarTouristGuideGroundReservations t
  505. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  506. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  507. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  508. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  509. foreach (var item in grp_CarTourists)
  510. {
  511. if (!regex.IsMatch(item.Area))
  512. {
  513. for (int i = 0; i < data.Count; i++)
  514. {
  515. if (item.Area.Equals(data[i].Id.ToString()))
  516. {
  517. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  518. }
  519. }
  520. }
  521. if (string.IsNullOrWhiteSpace(item.priceTypeStr))
  522. {
  523. item.priceTypeStr = "未选择!";
  524. }
  525. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  526. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  527. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  528. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  529. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  530. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  531. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  532. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  533. item.ServiceQuotedPrice = item.PayMoney;
  534. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  535. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice,2);
  536. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  537. if (s != null)
  538. {
  539. item.PayStrd = s.Name;
  540. }
  541. else item.PayStrd = "未选择";
  542. }
  543. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  544. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  545. Grp_CarTouristGuideGroundReservations t
  546. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  547. left Join Sys_SetData s on s.Id=t.CId {0}
  548. ) temp ", sqlWhere);
  549. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  550. if (dataCount != null)
  551. {
  552. int count = dataCount.Count;
  553. float totalPage = (float)count / dto.PageSize;//总页数
  554. if (totalPage == 0) totalPage = 1;
  555. else totalPage = (int)Math.Ceiling((double)totalPage);
  556. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  557. rst.DataList = grp_CarTourists;
  558. rst.DataCount = count;
  559. rst.CurrPageIndex = dto.PageIndex;
  560. rst.CurrPageSize = dto.PageSize;
  561. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  562. }
  563. }
  564. }
  565. catch (Exception)
  566. {
  567. return result = new Result() { Code = -2, Msg = "未知错误" };
  568. }
  569. return result;
  570. }
  571. /// <summary>
  572. /// OP费用录入填写详情
  573. /// </summary>
  574. /// <param name="dto"></param>
  575. /// <returns></returns>
  576. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  577. {
  578. Result result = new Result() { Code = -2, Msg = "未知错误" };
  579. try
  580. {
  581. BeginTran();
  582. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  583. {
  584. Id = item.Id,
  585. DiId = dto.DiId,
  586. CTGGRId = dto.CTGGRId,
  587. SId = item.SId,
  588. Price = item.Price,
  589. PriceContent = item.priceContent,
  590. Currency = dto.Currency,
  591. CreateUserId = dto.CreateUserId,
  592. Units = item.Units,
  593. DatePrice = item.DatePrice,
  594. Count = item.Count,
  595. }).ToList();
  596. if (carTouristList.Count > 0)
  597. {
  598. #region load
  599. //车超时费
  600. //餐费和三公经费那个表做完匹配后也放进超支表里
  601. DataTable tb = new DataTable();
  602. tb.Columns.Add("日期", typeof(DateTime));
  603. tb.Columns.Add("费用", typeof(decimal));
  604. tb.Columns.Add("币种", typeof(string));
  605. var addsTourClientList = new List<Grp_TourClientList>();
  606. var carExtraList = carTouristList.Where(x => x.SId == 982 && x.Price != 0).ToList();
  607. var mealPriceList = carTouristList.Where(x => (x.SId == 93 || x.SId == 988 || x.SId == 989) && x.Price != 0).GroupBy(x => x.DatePrice).ToList();
  608. mealPriceList.ForEach(x =>
  609. {
  610. var row = tb.NewRow();
  611. row["日期"] = x.Key;
  612. row["费用"] = x.Sum(x => x.Price * x.Count);
  613. row["币种"] = x.FirstOrDefault()?.Currency;
  614. tb.Rows.Add(row);
  615. });
  616. //限制只能选择地区
  617. var opSingle = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x=>x.Id == dto.CTGGRId);
  618. var opSingleCityId = 0;
  619. Grp_NationalTravelFee cityPrice = null;
  620. //三公费用
  621. if (int.TryParse(opSingle.Area,out opSingleCityId))
  622. {
  623. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  624. x.Id == opSingleCityId
  625. ).First();
  626. }
  627. else
  628. {
  629. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  630. !string.IsNullOrEmpty(x.City) && x.City.Contains(opSingle.Area)
  631. ).First();
  632. }
  633. //超支费用表(数据添加) Fin_GroupExtraCost
  634. List<Fin_GroupExtraCost> groupExtraCostsArr = new List<Fin_GroupExtraCost>();
  635. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId);
  636. if (di == null)
  637. {
  638. result.Code = -1;
  639. result.Msg = "无该团组信息!";
  640. return result;
  641. }
  642. if (carExtraList.Count > 0)
  643. {
  644. foreach (var item in carExtraList)
  645. {
  646. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  647. {
  648. Price = item.Price,
  649. CreateTime = DateTime.Now,
  650. CreateUserId = dto.CreateUserId,
  651. Coefficient = 1,
  652. DiId = dto.DiId,
  653. PriceCurrency = item.Currency,
  654. PriceName = di.TeamName + "车超时费(地接导入)",
  655. PriceType = 1028,
  656. PriceDt = item.DatePrice.ObjToDate(),
  657. PriceSum = item.Price * item.Count,
  658. PriceCount = item.Count,
  659. FilePath = string.Empty,
  660. PriceDetailType = 1050,
  661. });
  662. }
  663. }
  664. if (cityPrice != null)
  665. {
  666. //币种
  667. var currOpResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, carTouristList[0].Currency);
  668. var currOp = currOpResult.Code == 0 ? (currOpResult.Data as CurrencyInfo) == null ? 1 : (currOpResult.Data as CurrencyInfo)!.Rate : 1;
  669. var cityCurrResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, cityPrice.Currency);
  670. var cityCurr = cityCurrResult.Code == 0 ? (cityCurrResult.Data as CurrencyInfo) == null ? 1 : (cityCurrResult.Data as CurrencyInfo)!.Rate : 1;
  671. if (tb.Rows.Count > 0)
  672. {
  673. foreach (DataRow item in tb.Rows)
  674. {
  675. decimal foodCost = 1;
  676. if (!decimal.TryParse(cityPrice.FoodCost, out foodCost))
  677. {
  678. //三公费用 ( 城市餐费用有问题! )
  679. }
  680. var price = Convert.ToDecimal(item["费用"]);
  681. if (item["币种"].ToString() != cityPrice.Currency.ToString()) //币种不相同
  682. {
  683. //全部转换为rmb;
  684. item["费用"] = price * currOp;
  685. cityPrice.FoodCost = (foodCost * cityCurr).ToString("F2");
  686. item["币种"] = "836";
  687. cityPrice.Currency = 836;
  688. }
  689. if (price > foodCost)
  690. {
  691. //每天费用大于三公费用
  692. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  693. {
  694. Price = price - foodCost,
  695. CreateTime = DateTime.Now,
  696. CreateUserId = dto.CreateUserId,
  697. Coefficient = 1,
  698. DiId = dto.DiId,
  699. PriceCurrency = cityPrice.Currency,
  700. PriceName = di.TeamName + "餐费(地接导入)",
  701. PriceType = 1028,
  702. PriceDt = Convert.ToDateTime(item["日期"]),
  703. PriceSum = price - foodCost,
  704. PriceCount = 1,
  705. FilePath = string.Empty,
  706. PriceDetailType = 1049,
  707. });
  708. }
  709. }
  710. }
  711. }
  712. var isTrue = false;
  713. if (groupExtraCostsArr.Count > 0)
  714. {
  715. foreach (var item in groupExtraCostsArr)
  716. {
  717. 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();
  718. if (QuerySgin == null)
  719. {
  720. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  721. {
  722. coefficient = 1,
  723. createUser = dto.CreateUserId,
  724. currency = item.PriceCurrency,
  725. diId = item.DiId,
  726. editType = 1,
  727. filePath = string.Empty,
  728. payee = dto.Payee,
  729. PortType = 1,
  730. PriceCount = item.PriceCount,
  731. priceName = item.PriceName,
  732. remark = item.Remark,
  733. price = item.Price,
  734. priceDetailType = item.PriceDetailType,
  735. priceType = item.PriceType,
  736. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  737. payType = dto.PayDId,
  738. costSign = dto.OrbitalPrivateTransfer
  739. });
  740. isTrue = resultThis.Code == 0 ? true : false;
  741. }
  742. else
  743. {
  744. item.Id = QuerySgin.Id;
  745. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  746. {
  747. coefficient = 1,
  748. createUser = dto.CreateUserId,
  749. currency = item.PriceCurrency,
  750. diId = item.DiId,
  751. editType = 2,
  752. filePath = string.Empty,
  753. payee = dto.Payee,
  754. PortType = 1,
  755. PriceCount = item.PriceCount,
  756. priceName = item.PriceName,
  757. remark = item.Remark,
  758. price = item.Price,
  759. priceDetailType = item.PriceDetailType,
  760. priceType = item.PriceType,
  761. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  762. payType = dto.PayDId,
  763. costSign = dto.OrbitalPrivateTransfer,
  764. Id = item.Id,
  765. });
  766. isTrue = resultThis.Code == 0 ? true : false;
  767. }
  768. }
  769. }
  770. #endregion
  771. }
  772. foreach (var item in carTouristList)
  773. {
  774. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel==0);
  775. if (QueryData==null)
  776. {
  777. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  778. if (id == 0)
  779. {
  780. RollbackTran();
  781. return result = new Result() { Code = -2, Msg = "添加失败" };
  782. }
  783. }
  784. else
  785. {
  786. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  787. {
  788. Price = item.Price,
  789. PriceContent = item.PriceContent,
  790. Currency = dto.Currency,
  791. Remark = item.Remark,
  792. DatePrice = item.DatePrice,
  793. Count = item.Count,
  794. Units = item.Units,
  795. }).ExecuteCommandAsync();
  796. if (CTable==0)
  797. {
  798. RollbackTran();
  799. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  800. }
  801. }
  802. }
  803. Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");
  804. //修改C表数据
  805. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  806. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  807. c.PaymentCurrency = dto.Currency;
  808. for (int i = 0; i < dto.SelectCheck.Count; i++) {
  809. if (!regex.IsMatch(dto.SelectCheck[i]))
  810. {
  811. for(int j = 0; j < carTouristList.Count; j++)
  812. {
  813. if (int.Parse(dto.SelectCheck[i]) == carTouristList[j].SId)
  814. {
  815. c.PayMoney += carTouristList[j].Price * carTouristList[j].Count;
  816. }
  817. }
  818. } else
  819. {
  820. c.PayMoney = carTouristList.Sum(x => x.Price * x.Count);
  821. break;
  822. }
  823. }
  824. c.PayPercentage = dto.PayPercentage;
  825. c.ConsumptionDate= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  826. c.CTable = 79;
  827. c.CId = dto.CTGGRId;
  828. c.IsAuditGM = 0;
  829. c.PayDId=dto.PayDId;
  830. c.DIId = dto.DiId;
  831. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  832. c.Payee=dto.Payee;
  833. c.CreateUserId=dto.CreateUserId;
  834. if (c.PayDId == 72)
  835. {
  836. c.IsPay = 1;
  837. }
  838. c.RMBPrice = c.PayMoney;
  839. c.DayRate = 1;
  840. #region 老汇率获取
  841. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  842. //List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  843. //if (_TeamRate != null)
  844. //{
  845. // Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  846. // if (_SetData != null)
  847. // {
  848. // currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  849. // CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  850. // if (CurrencyRate != null)
  851. // {
  852. // c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  853. // c.DayRate = CurrencyRate.Rate;
  854. // }
  855. // }
  856. //}
  857. #endregion
  858. var rate = await _setDataRep.PostCurrencyByDiid(dto.DiId, dto.CTGGRId, dto.Currency);
  859. if (rate.Code == 0)
  860. {
  861. var rateData = rate.Data as CurrencyInfo;
  862. if (rateData != null)
  863. {
  864. c.RMBPrice = c.PayMoney * rateData.Rate;
  865. c.DayRate = rateData.Rate;
  866. }
  867. }
  868. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a=>a.CId==dto.CTGGRId && a.IsDel==0 && a.CTable==79 && a.DIId==dto.DiId);
  869. if (grp_CreditCard!=null)//修改
  870. {
  871. 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
  872. {
  873. PaymentCurrency = c.PaymentCurrency,
  874. PayMoney = c.PayMoney,
  875. PayPercentage = c.PayPercentage,
  876. CTable = c.CTable,
  877. PayDId = c.PayDId,
  878. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  879. Payee = c.Payee,
  880. IsPay = c.IsPay,
  881. RMBPrice = c.RMBPrice,
  882. DayRate = c.DayRate,
  883. }).ExecuteCommandAsync();
  884. if (CTable == 0)
  885. {
  886. RollbackTran();
  887. return result = new Result() { Code = -2, Msg = "修改失败" };
  888. }
  889. }
  890. else//添加
  891. {
  892. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  893. if (id == 0)
  894. {
  895. RollbackTran();
  896. return result = new Result() { Code = -2, Msg = "添加失败" };
  897. }
  898. }
  899. 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
  900. {
  901. CId = dto.Currency,
  902. ServiceQuotedPrice = c.PayMoney,
  903. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  904. SelectCheck = string.Join(',', dto.SelectCheck)
  905. }).ExecuteCommandAsync();
  906. if (CarTouristGuideCTable == 0)
  907. {
  908. RollbackTran();
  909. return result = new Result() { Code = -2, Msg = "修改失败" };
  910. }
  911. result = new Result() { Code =0, Msg = "保存成功" };
  912. CommitTran();
  913. }
  914. catch (Exception ex)
  915. {
  916. RollbackTran();
  917. return result = new Result() { Code = -2, Msg = "未知错误" };
  918. }
  919. return result;
  920. }
  921. /// <summary>
  922. /// 超支费用
  923. /// 1增、2改、3删
  924. /// </summary>
  925. /// <param name="dto"></param>
  926. /// <returns></returns>
  927. private async Task<Result> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  928. {
  929. Result rt = new Result();
  930. #region 验证
  931. #endregion
  932. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  933. _entity.DiId = dto.diId;
  934. _entity.PriceName = dto.priceName;
  935. _entity.Price = dto.price;
  936. _entity.PriceCurrency = dto.currency;
  937. _entity.PriceType = dto.priceType;
  938. _entity.Coefficient = dto.coefficient;
  939. _entity.PriceDetailType = dto.priceDetailType;
  940. _entity.FilePath = dto.filePath;
  941. _entity.Remark = dto.remark;
  942. _entity.PriceCount = dto.PriceCount;
  943. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  944. _entity.PriceSum = dto.price * dto.PriceCount;
  945. _daiRep.BeginTran();
  946. if (dto.editType == 1)
  947. {
  948. _entity.CreateUserId = dto.createUser;
  949. _entity.CreateTime = DateTime.Now;
  950. _entity.IsDel = 0;
  951. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  952. if (returnId > 0)
  953. {
  954. dto.Id = returnId;
  955. }
  956. }
  957. else if (dto.editType == 2)
  958. {
  959. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  960. {
  961. PriceName = dto.priceName,
  962. Price = dto.price,
  963. PriceCurrency = dto.currency,
  964. PriceType = dto.priceType,
  965. PriceDetailType = dto.priceDetailType,
  966. Coefficient = dto.coefficient,
  967. FilePath = dto.filePath,
  968. Remark = dto.remark,
  969. PriceCount = dto.PriceCount,
  970. PriceDt = _entity.PriceDt,
  971. PriceSum = _entity.PriceSum
  972. });
  973. if (!res)
  974. {
  975. _daiRep.RollbackTran();
  976. //Ok(JsonView(false, "2操作失败!"))
  977. rt.Msg = "2操作失败!";
  978. return rt;
  979. }
  980. }
  981. else if (dto.editType == 3)
  982. {
  983. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  984. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  985. {
  986. IsDel = 1,
  987. DeleteTime = delTime,
  988. DeleteUserId = dto.createUser
  989. });
  990. if (!res)
  991. {
  992. _daiRep.RollbackTran();
  993. rt.Msg = "3操作失败!";
  994. return rt;
  995. }
  996. }
  997. else
  998. {
  999. _daiRep.RollbackTran();
  1000. rt.Msg = "未知的editType";
  1001. return rt;
  1002. }
  1003. if (!extraCost_editCreditCardPayment(dto))
  1004. {
  1005. rt.Msg = "ccp操作失败";
  1006. return rt;
  1007. }
  1008. _daiRep.CommitTran();
  1009. rt.Code = 0;
  1010. rt.Msg = "操作成功";
  1011. return rt;
  1012. }
  1013. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1014. {
  1015. //设置团组汇率
  1016. decimal dcm_dayrate = 1M;
  1017. decimal dcm_rmbPrice = costDto.price;
  1018. int ispay = costDto.payType == 72 ? 1 : 0;
  1019. if (costDto.costSign != 3)
  1020. {
  1021. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1022. if (tr != null)
  1023. {
  1024. if (costDto.currency == 49)
  1025. {
  1026. dcm_dayrate = tr.RateU;
  1027. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1028. }
  1029. else if (costDto.currency == 51)
  1030. {
  1031. dcm_dayrate = tr.RateE;
  1032. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1033. }
  1034. }
  1035. }
  1036. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1037. if (ccp == null)
  1038. {
  1039. ccp = new Grp_CreditCardPayment();
  1040. ccp.PayDId = costDto.payType;// dto
  1041. ccp.ConsumptionPatterns = "";
  1042. ccp.ConsumptionDate = "";
  1043. ccp.CTDId = costDto.payCardId;// dto
  1044. ccp.BankNo = "";
  1045. ccp.CardholderName = "";
  1046. ccp.PayMoney = costDto.price;// dto
  1047. ccp.PaymentCurrency = costDto.currency;// dto
  1048. ccp.CompanyBankNo = "";
  1049. ccp.OtherBankName = "";
  1050. ccp.OtherSideNo = "";
  1051. ccp.OtherSideName = "";
  1052. ccp.Remark = "";
  1053. ccp.CreateUserId = costDto.createUser;
  1054. ccp.CreateTime = DateTime.Now;
  1055. ccp.MFOperator = 0;
  1056. ccp.MFOperatorDate = "";
  1057. ccp.IsAuditDM = 0;
  1058. ccp.AuditDMOperate = 0;
  1059. ccp.AuditDMDate = "";
  1060. ccp.IsAuditMF = 0;
  1061. ccp.AuditMFOperate = 0;
  1062. ccp.AuditMFDate = "";
  1063. ccp.IsAuditGM = 0;
  1064. ccp.AuditGMOperate = 0;
  1065. ccp.AuditGMDate = "";
  1066. ccp.IsPay = ispay; // upd
  1067. ccp.DIId = costDto.diId;// dto
  1068. ccp.CId = costDto.Id;// dto
  1069. ccp.CTable = 1015; //超支费用指向id
  1070. ccp.IsDel = 0;
  1071. ccp.PayPercentage = 100M;
  1072. ccp.PayThenMoney = 0M;
  1073. ccp.PayPercentageOld = 100M;
  1074. ccp.PayThenMoneyOld = 0M;
  1075. ccp.UpdateDate = "";
  1076. ccp.Payee = costDto.payee;// dto
  1077. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1078. ccp.ExceedBudget = 0;
  1079. ccp.DayRate = dcm_dayrate; //upd
  1080. ccp.RMBPrice = dcm_rmbPrice; //upd
  1081. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1082. if (ccpInsertId > 0)
  1083. {
  1084. return true;
  1085. }
  1086. }
  1087. else
  1088. {
  1089. if (costDto.editType == 2)
  1090. {
  1091. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1092. {
  1093. PayDId = costDto.payType,
  1094. CTDId = costDto.payCardId,
  1095. PayMoney = costDto.price,
  1096. PaymentCurrency = costDto.currency,
  1097. IsPay = ispay,
  1098. Payee = costDto.payee,
  1099. OrbitalPrivateTransfer = costDto.costSign,
  1100. DayRate = dcm_dayrate,
  1101. RMBPrice = dcm_rmbPrice
  1102. });
  1103. return res;
  1104. }
  1105. else if (costDto.editType == 3)
  1106. {
  1107. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1108. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1109. {
  1110. IsDel = 1,
  1111. DeleteTime = delTime,
  1112. DeleteUserId = costDto.createUser
  1113. });
  1114. return res2;
  1115. }
  1116. }
  1117. return false;
  1118. }
  1119. }
  1120. }