GroupCostParameterRepository.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. using AutoMapper;
  2. using OASystem.Domain.Entities.Groups;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OASystem.Infrastructure.Repositories.Groups
  9. {
  10. public class GroupCostParameterRepository : BaseRepository<Grp_GroupCostParameter, Grp_GroupCostParameterView>
  11. {
  12. public GroupCostParameterRepository(SqlSugarClient sqlSugar) :
  13. base(sqlSugar)
  14. {
  15. }
  16. public List<Grp_GroupCostParameter> GetGroupCostParameterListByDiid(int diid)
  17. {
  18. return Query(x=>x.DiId == diid).ToList();
  19. }
  20. public Grp_GroupCostParameter GetGroupCostParameterMainByDiid(int diid)
  21. {
  22. return Query(x => x.DiId == diid).First(x => x.CostType == "A");
  23. }
  24. public async Task<bool> UpdateIsShareById(int id,int IsShare)
  25. {
  26. return await UpdateAsync(x => x.Id == id, x=>new Grp_GroupCostParameter { IsShare = IsShare });
  27. }
  28. public async Task<bool> DeleteGroupCostParameterListByDiid(int diid, int userid)
  29. {
  30. return await SoftDeleteAsync(x=>x.DiId == diid && x.IsDel == 0, userid);
  31. }
  32. public async Task<bool> SaveAsync(List<Grp_GroupCostParameter> List,int Userid, int diid)
  33. {
  34. bool isTrue = false;
  35. try
  36. {
  37. BeginTran();
  38. var mainCost = GetGroupCostParameterMainByDiid(diid) ?? new Grp_GroupCostParameter
  39. {
  40. IsShare = 0
  41. };
  42. isTrue = await DeleteGroupCostParameterListByDiid(diid, Userid);
  43. if (List.Count > 0)
  44. {
  45. foreach (var item in List)
  46. {
  47. if (item.CostType == "A")
  48. {
  49. item.IsShare = mainCost.IsShare;
  50. break;
  51. }
  52. }
  53. List.ForEach(x => { x.CreateUserId = Userid; x.CreateTime = DateTime.Now; });
  54. isTrue = Adds(List) > 0;
  55. }
  56. CommitTran();
  57. }
  58. catch (Exception ex)
  59. {
  60. RollbackTran();
  61. isTrue = false;
  62. }
  63. return isTrue;
  64. }
  65. public object GetBaoPi(int diid)
  66. {
  67. List<dynamic> dynamics = new List<dynamic>();
  68. try
  69. {
  70. Grp_EnterExitCost eec = _sqlSugar.Queryable<Grp_EnterExitCost>().First(x => x.DiId == diid && x.IsDel == 0);
  71. if (eec != null)
  72. {
  73. var AirJJ = new
  74. {
  75. Type = "JJC",
  76. Price = eec.AirJJ
  77. };
  78. dynamics.Add(AirJJ);
  79. var AirGW = new
  80. {
  81. Type = "GWC",
  82. Price = eec.AirGW
  83. };
  84. dynamics.Add(AirGW);
  85. var AirTDC = new
  86. {
  87. Type = "TDC",
  88. Price = eec.AirTD
  89. };
  90. dynamics.Add(AirTDC);
  91. List<Grp_DayAndCost> dac1 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 1 && x.NationalTravelFeeId > 0 && x.IsDel == 0).ToList(); //酒店费用
  92. List<Grp_DayAndCost> dac2 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 2 && x.NationalTravelFeeId > 0 && x.IsDel == 0).ToList(); //餐费用
  93. List<Grp_DayAndCost> dac3 = (from item in _sqlSugar.Queryable<Grp_DayAndCost>() //公杂费用
  94. where item.DiId == diid && item.Type == 3 && item.NationalTravelFeeId > 0 && item.IsDel == 0
  95. select item).ToList();
  96. var dac4 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  97. .InnerJoin<Sys_SetData>((a,b)=> b.IsDel == 0 && b.Id == a.Currency)
  98. .InnerJoin<Sys_SetData>((a, b, c) => c.IsDel == 0 && c.Id == a.SetDataId)
  99. .Where((a, b, c) => a.Diid == diid && a.IsDel == 0)
  100. .Select((a, b, c) => new
  101. {
  102. a.Cost,
  103. CurrencyStr = b.Remark,
  104. SetDataType = c.Name,
  105. a.SubTotal,
  106. })
  107. .ToList(); //其他费用
  108. if (dac1.Count == 0)
  109. {
  110. dac1 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 1 && x.IsDel == 0).ToList(); //酒店费用
  111. }
  112. if (dac2.Count == 0)
  113. {
  114. dac2 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 2 && x.IsDel == 0).ToList(); //酒店费用
  115. }
  116. if (dac2.Count == 0)
  117. {
  118. dac3 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 3 && x.IsDel == 0).ToList(); //酒店费用
  119. }
  120. decimal SumHotel = 0;
  121. decimal SumMeals = 0;
  122. decimal SumGongZa = 0;
  123. decimal sumOtherPrice = 0;
  124. List<dynamic> hotelList = new List<dynamic>();
  125. List<string> checkString = new List<string>();
  126. //币种
  127. var currArr = _sqlSugar.Queryable<Sys_SetData>().Where(x=>x.IsDel == 0 && x.STid == 66).ToList();
  128. if (dac1.Count != 0)//酒店费用
  129. {
  130. for (int i = 0; i < dac1.Count; i++)
  131. {
  132. if (!string.IsNullOrWhiteSpace(dac1[i].Place))
  133. {
  134. if (!checkString.Contains(dac1[i].Place))
  135. {
  136. var hotelData = new
  137. {
  138. CountryOrCity = dac1[i].Place,
  139. Price = dac1[i].SubTotal,
  140. CurrPrice = dac1[i].Cost,
  141. CurrStr = (currArr.Find(x => x.Id == dac1[i].Currency)?.Remark ?? dac1[i].Currency.ToString()),
  142. };
  143. hotelList.Add(hotelData);
  144. checkString.Add(dac1[i].Place);
  145. }
  146. }
  147. SumHotel += dac1[i].SubTotal;
  148. }
  149. if (hotelList.Count == 0)
  150. {
  151. var group = dac1.GroupBy(x => x.NationalTravelFeeId).ToList();
  152. foreach (var hotel in group)
  153. {
  154. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  155. var hotelData = new
  156. {
  157. CountryOrCity = city?.Country + city?.City,
  158. Price = hotel.ToList()[0].SubTotal,
  159. CurrPrice = hotel.ToList()[0].Cost,
  160. CurrStr = (currArr.Find(x => x.Id == hotel.ToList()[0].Currency)?.Remark ?? hotel.ToList()[0].Currency.ToString()),
  161. };
  162. hotelList.Add(hotelData);
  163. checkString.Add(city?.City ?? "");
  164. }
  165. }
  166. }
  167. hotelList = hotelList.Distinct().ToList();
  168. List<dynamic> MealsList = new List<dynamic>();
  169. if (dac2.Count != 0) //餐费用
  170. {
  171. for (int i = 0; i < dac2.Count; i++)
  172. {
  173. if (checkString.Contains(dac2[i].Place))
  174. {
  175. var mealsData = new
  176. {
  177. CountryOrCity = dac2[i].Place,
  178. Price = dac2[i].SubTotal,
  179. CurrPrice = dac1[i].Cost,
  180. CurrStr = (currArr.Find(x => x.Id == dac1[i].Currency)?.Remark ?? dac1[i].Currency.ToString()),
  181. };
  182. MealsList.Add(mealsData);
  183. }
  184. SumMeals += dac2[i].SubTotal;
  185. }
  186. if (MealsList.Count == 0)
  187. {
  188. var group = dac2.GroupBy(x => x.NationalTravelFeeId).ToList();
  189. foreach (var hotel in group)
  190. {
  191. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  192. var mealsData = new
  193. {
  194. CountryOrCity = city?.Country + city?.City,
  195. Price = hotel.ToList()[0].SubTotal,
  196. CurrPrice = hotel.ToList()[0].Cost,
  197. CurrStr = (currArr.Find(x => x.Id == hotel.ToList()[0].Currency)?.Remark ?? hotel.ToList()[0].Currency.ToString()),
  198. };
  199. MealsList.Add(mealsData);
  200. }
  201. }
  202. }
  203. MealsList = MealsList.Distinct().ToList();
  204. List<dynamic> GongZaList = new List<dynamic>();
  205. if (dac3.Count != 0) //公杂费用
  206. {
  207. for (int i = 0; i < dac3.Count; i++)
  208. {
  209. if (checkString.Contains(dac3[i].Place))
  210. {
  211. var gongZaData = new
  212. {
  213. CountryOrCity = dac3[i].Place,
  214. Price = dac3[i].SubTotal
  215. };
  216. GongZaList.Add(gongZaData);
  217. }
  218. SumGongZa += dac3[i].SubTotal;
  219. }
  220. if (GongZaList.Count == 0)
  221. {
  222. var group = dac3.GroupBy(x => x.NationalTravelFeeId).ToList();
  223. foreach (var hotel in group)
  224. {
  225. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  226. var gongZaData = new
  227. {
  228. CountryOrCity = city?.Country + city?.City,
  229. Price = hotel.ToList()[0].SubTotal,
  230. };
  231. GongZaList.Add(gongZaData);
  232. }
  233. }
  234. }
  235. GongZaList = GongZaList.Distinct().ToList();
  236. List<object> otherList = new List<object>();
  237. if (dac4.Any())
  238. {
  239. foreach (var item in dac4)
  240. {
  241. otherList.Add(item);
  242. sumOtherPrice += item.SubTotal;
  243. }
  244. }
  245. //签证
  246. var Visa = new
  247. {
  248. Type = "Visa",
  249. Price = eec.Visa,
  250. Desc = eec.VisaRemark
  251. };
  252. dynamics.Add(Visa);
  253. //核酸检测费
  254. var HeSuan = new
  255. {
  256. Type = "HeSuan",
  257. Price = eec.HeSuan //元/人
  258. };
  259. dynamics.Add(HeSuan);
  260. //保险费
  261. var Insurance = new
  262. {
  263. Type = "Insurance",
  264. Price = eec.Safe //元/人
  265. };
  266. dynamics.Add(Insurance);
  267. // 伙食费
  268. var Meals = new
  269. {
  270. Type = "Meals",
  271. Content = MealsList
  272. };
  273. dynamics.Add(Meals);
  274. // 酒店费用
  275. var Hotel = new
  276. {
  277. Type = "Hotel",
  278. Content = hotelList
  279. };
  280. dynamics.Add(Hotel);
  281. // 公杂费用
  282. var GongZa = new
  283. {
  284. Type = "GongZa",
  285. Content = GongZaList
  286. };
  287. dynamics.Add(GongZa);
  288. //其他费用
  289. var other = new
  290. {
  291. Type = "Other",
  292. Content = otherList
  293. };
  294. dynamics.Add(other);
  295. decimal AirJJCTotal = 0;
  296. decimal AirGWCTotal = 0;
  297. decimal AirTDCTotal = 0;
  298. //境内费用(其他费用)选择框
  299. if (eec.ChoiceOne == 1)
  300. {
  301. AirJJCTotal += Math.Round((eec.InsidePay), 2);
  302. AirGWCTotal += Math.Round((eec.InsidePay), 2);
  303. AirTDCTotal += Math.Round((eec.InsidePay), 2);
  304. }
  305. //国际旅费合计选择框
  306. if (eec.SumJJC == 1)
  307. {
  308. AirJJCTotal += Math.Round((eec.OutsideJJPay), 2);
  309. }
  310. if (eec.SumGWC == 1)
  311. {
  312. AirGWCTotal += Math.Round((eec.OutsideGWPay), 2);
  313. }
  314. if (eec.SumTDC == 1)
  315. {
  316. AirTDCTotal += Math.Round((eec.OutsideTDPay), 2);
  317. }
  318. //住宿费合计选择框
  319. if (eec.ChoiceThree == 1)
  320. {
  321. AirJJCTotal += Math.Round(SumHotel, 2);
  322. AirGWCTotal += Math.Round(SumHotel, 2);
  323. AirTDCTotal += Math.Round(SumHotel, 2);
  324. }
  325. //伙食费合计选择框
  326. if (eec.ChoiceFour == 1)
  327. {
  328. AirJJCTotal += Math.Round(SumMeals, 2);
  329. AirGWCTotal += Math.Round(SumMeals, 2);
  330. AirTDCTotal += Math.Round(SumMeals, 2);
  331. }
  332. //公杂费合计选择框
  333. if (eec.ChoiceFour == 1)
  334. {
  335. AirJJCTotal += Math.Round(SumGongZa, 2);
  336. AirGWCTotal += Math.Round(SumGongZa, 2);
  337. AirTDCTotal += Math.Round(SumGongZa, 2);
  338. }
  339. //其他费用选择框
  340. if (eec.OtherExpenses_Checked == 1)
  341. {
  342. AirJJCTotal += Math.Round(sumOtherPrice, 2);
  343. AirGWCTotal += Math.Round(sumOtherPrice, 2);
  344. AirTDCTotal += Math.Round(sumOtherPrice, 2);
  345. }
  346. // 报批总报价 - 经济舱
  347. if (eec.SumJJC == 0)
  348. {
  349. AirJJCTotal = 0;
  350. }
  351. var SumAirJJC = new
  352. {
  353. Type = "SumAirJJC",
  354. Price = AirJJCTotal
  355. };
  356. dynamics.Add(SumAirJJC);
  357. //报批总报价 - 公务舱
  358. if (eec.SumGWC == 0)
  359. {
  360. AirGWCTotal = 0;
  361. }
  362. var SumAirGWC = new
  363. {
  364. Type = "SumAirGWC",
  365. Price = AirGWCTotal
  366. };
  367. dynamics.Add(SumAirGWC);
  368. //报批总报价 - 头等舱
  369. if (eec.SumTDC == 0)
  370. {
  371. AirTDCTotal = 0;
  372. }
  373. var SumAirTDC = new
  374. {
  375. Type = "SumAirTDC",
  376. Price = AirTDCTotal
  377. };
  378. dynamics.Add(SumAirTDC);
  379. }
  380. }
  381. catch (Exception)
  382. {
  383. dynamics = new List<dynamic>();
  384. }
  385. return dynamics;
  386. }
  387. }
  388. }