GroupCostParameterRepository.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. if (dac1.Count == 0)
  97. {
  98. dac1 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 1 && x.IsDel == 0).ToList(); //酒店费用
  99. }
  100. if (dac2.Count == 0)
  101. {
  102. dac2 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 2 && x.IsDel == 0).ToList(); //酒店费用
  103. }
  104. if (dac2.Count == 0)
  105. {
  106. dac3 = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.DiId == diid && x.Type == 3 && x.IsDel == 0).ToList(); //酒店费用
  107. }
  108. decimal SumHotel = 0;
  109. decimal SumMeals = 0;
  110. decimal SumGongZa = 0;
  111. List<dynamic> hotelList = new List<dynamic>();
  112. List<string> checkString = new List<string>();
  113. //币种
  114. var currArr = _sqlSugar.Queryable<Sys_SetData>().Where(x=>x.IsDel == 0 && x.STid == 66).ToList();
  115. if (dac1.Count != 0)//酒店费用
  116. {
  117. for (int i = 0; i < dac1.Count; i++)
  118. {
  119. if (!string.IsNullOrWhiteSpace(dac1[i].Place))
  120. {
  121. if (!checkString.Contains(dac1[i].Place))
  122. {
  123. var hotelData = new
  124. {
  125. CountryOrCity = dac1[i].Place,
  126. Price = dac1[i].SubTotal,
  127. CurrPrice = dac1[i].Cost,
  128. CurrStr = (currArr.Find(x => x.Id == dac1[i].Currency)?.Remark ?? dac1[i].Currency.ToString()),
  129. };
  130. hotelList.Add(hotelData);
  131. checkString.Add(dac1[i].Place);
  132. }
  133. }
  134. SumHotel += dac1[i].SubTotal;
  135. }
  136. if (hotelList.Count == 0)
  137. {
  138. var group = dac1.GroupBy(x => x.NationalTravelFeeId).ToList();
  139. foreach (var hotel in group)
  140. {
  141. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  142. var hotelData = new
  143. {
  144. CountryOrCity = city?.Country + city?.City,
  145. Price = hotel.ToList()[0].SubTotal,
  146. CurrPrice = hotel.ToList()[0].Cost,
  147. CurrStr = (currArr.Find(x => x.Id == hotel.ToList()[0].Currency)?.Remark ?? hotel.ToList()[0].Currency.ToString()),
  148. };
  149. hotelList.Add(hotelData);
  150. checkString.Add(city?.City ?? "");
  151. }
  152. }
  153. }
  154. hotelList = hotelList.Distinct().ToList();
  155. List<dynamic> MealsList = new List<dynamic>();
  156. if (dac2.Count != 0) //餐费用
  157. {
  158. for (int i = 0; i < dac2.Count; i++)
  159. {
  160. if (checkString.Contains(dac2[i].Place))
  161. {
  162. var mealsData = new
  163. {
  164. CountryOrCity = dac2[i].Place,
  165. Price = dac2[i].SubTotal,
  166. CurrPrice = dac1[i].Cost,
  167. CurrStr = (currArr.Find(x => x.Id == dac1[i].Currency)?.Remark ?? dac1[i].Currency.ToString()),
  168. };
  169. MealsList.Add(mealsData);
  170. }
  171. SumMeals += dac2[i].SubTotal;
  172. }
  173. if (MealsList.Count == 0)
  174. {
  175. var group = dac2.GroupBy(x => x.NationalTravelFeeId).ToList();
  176. foreach (var hotel in group)
  177. {
  178. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  179. var mealsData = new
  180. {
  181. CountryOrCity = city?.Country + city?.City,
  182. Price = hotel.ToList()[0].SubTotal,
  183. CurrPrice = hotel.ToList()[0].Cost,
  184. CurrStr = (currArr.Find(x => x.Id == hotel.ToList()[0].Currency)?.Remark ?? hotel.ToList()[0].Currency.ToString()),
  185. };
  186. MealsList.Add(mealsData);
  187. }
  188. }
  189. }
  190. MealsList = MealsList.Distinct().ToList();
  191. List<dynamic> GongZaList = new List<dynamic>();
  192. if (dac3.Count != 0) //公杂费用
  193. {
  194. for (int i = 0; i < dac3.Count; i++)
  195. {
  196. if (checkString.Contains(dac3[i].Place))
  197. {
  198. var gongZaData = new
  199. {
  200. CountryOrCity = dac3[i].Place,
  201. Price = dac3[i].SubTotal
  202. };
  203. GongZaList.Add(gongZaData);
  204. }
  205. SumGongZa += dac3[i].SubTotal;
  206. }
  207. if (GongZaList.Count == 0)
  208. {
  209. var group = dac3.GroupBy(x => x.NationalTravelFeeId).ToList();
  210. foreach (var hotel in group)
  211. {
  212. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(it => it.IsDel == 0 && it.Id == hotel.Key);
  213. var gongZaData = new
  214. {
  215. CountryOrCity = city?.Country + city?.City,
  216. Price = hotel.ToList()[0].SubTotal,
  217. };
  218. GongZaList.Add(gongZaData);
  219. }
  220. }
  221. }
  222. GongZaList = GongZaList.Distinct().ToList();
  223. //签证
  224. var Visa = new
  225. {
  226. Type = "Visa",
  227. Price = eec.Visa,
  228. Desc = eec.VisaRemark
  229. };
  230. dynamics.Add(Visa);
  231. //核酸检测费
  232. var HeSuan = new
  233. {
  234. Type = "HeSuan",
  235. Price = eec.HeSuan //元/人
  236. };
  237. dynamics.Add(HeSuan);
  238. //保险费
  239. var Insurance = new
  240. {
  241. Type = "Insurance",
  242. Price = eec.Safe //元/人
  243. };
  244. dynamics.Add(Insurance);
  245. // 伙食费
  246. var Meals = new
  247. {
  248. Type = "Meals",
  249. Content = MealsList
  250. };
  251. dynamics.Add(Meals);
  252. // 酒店费用
  253. var Hotel = new
  254. {
  255. Type = "Hotel",
  256. Content = hotelList
  257. };
  258. dynamics.Add(Hotel);
  259. // 公杂费用
  260. var GongZa = new
  261. {
  262. Type = "GongZa",
  263. Content = GongZaList
  264. };
  265. dynamics.Add(GongZa);
  266. decimal AirJJCTotal = 0;
  267. decimal AirGWCTotal = 0;
  268. decimal AirTDCTotal = 0;
  269. //境内费用(其他费用)选择框
  270. if (eec.ChoiceOne == 1)
  271. {
  272. AirJJCTotal += Math.Round((eec.InsidePay), 2);
  273. AirGWCTotal += Math.Round((eec.InsidePay), 2);
  274. AirTDCTotal += Math.Round((eec.InsidePay), 2);
  275. }
  276. //国际旅费合计选择框
  277. if (eec.SumJJC == 1)
  278. {
  279. AirJJCTotal += Math.Round((eec.OutsideJJPay), 2);
  280. }
  281. if (eec.SumGWC == 1)
  282. {
  283. AirGWCTotal += Math.Round((eec.OutsideGWPay), 2);
  284. }
  285. if (eec.SumTDC == 1)
  286. {
  287. AirTDCTotal += Math.Round((eec.OutsideTDPay), 2);
  288. }
  289. //住宿费合计选择框
  290. if (eec.ChoiceThree == 1)
  291. {
  292. AirJJCTotal += Math.Round(SumHotel, 2);
  293. AirGWCTotal += Math.Round(SumHotel, 2);
  294. AirTDCTotal += Math.Round(SumHotel, 2);
  295. }
  296. //伙食费合计选择框
  297. if (eec.ChoiceFour == 1)
  298. {
  299. AirJJCTotal += Math.Round(SumMeals, 2);
  300. AirGWCTotal += Math.Round(SumMeals, 2);
  301. AirTDCTotal += Math.Round(SumMeals, 2);
  302. }
  303. //公杂费合计选择框
  304. if (eec.ChoiceFour == 1)
  305. {
  306. AirJJCTotal += Math.Round(SumGongZa, 2);
  307. AirGWCTotal += Math.Round(SumGongZa, 2);
  308. AirTDCTotal += Math.Round(SumGongZa, 2);
  309. }
  310. // 报批总报价 - 经济舱
  311. if (eec.SumJJC == 0)
  312. {
  313. AirJJCTotal = 0;
  314. }
  315. var SumAirJJC = new
  316. {
  317. Type = "SumAirJJC",
  318. Price = AirJJCTotal
  319. };
  320. dynamics.Add(SumAirJJC);
  321. //报批总报价 - 公务舱
  322. if (eec.SumGWC == 0)
  323. {
  324. AirGWCTotal = 0;
  325. }
  326. var SumAirGWC = new
  327. {
  328. Type = "SumAirGWC",
  329. Price = AirGWCTotal
  330. };
  331. dynamics.Add(SumAirGWC);
  332. //报批总报价 - 头等舱
  333. if (eec.SumTDC == 0)
  334. {
  335. AirTDCTotal = 0;
  336. }
  337. var SumAirTDC = new
  338. {
  339. Type = "SumAirTDC",
  340. Price = AirTDCTotal
  341. };
  342. dynamics.Add(SumAirTDC);
  343. }
  344. }
  345. catch (Exception)
  346. {
  347. dynamics = new List<dynamic>();
  348. }
  349. return dynamics;
  350. }
  351. }
  352. }