GroupCostParameterRepository.cs 14 KB

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