DecreasePaymentsRepository.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Financial;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.Entities.Resource;
  7. using OASystem.Domain.ViewModels.Financial;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using OASystem.Domain.ViewModels.QiYeWeChat;
  10. using OASystem.Domain.ViewModels.Resource;
  11. using OASystem.Infrastructure.Repositories.System;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Runtime.Intrinsics.Arm;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace OASystem.Infrastructure.Repositories.Groups
  19. {
  20. public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly TeamRateRepository _teamRateRep;
  24. public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper, TeamRateRepository teamRateRep)
  25. : base(sqlSugar)
  26. {
  27. this._mapper = mapper;
  28. _teamRateRep = teamRateRep;
  29. }
  30. /// <summary>
  31. /// 根据团组Id查询数据
  32. /// </summary>
  33. /// <param name="dto"></param>
  34. /// <returns></returns>
  35. public async Task<Result> DecreasePaymentsList(DecreasePaymentsListDto dto)
  36. {
  37. Result result = new Result() { Code = -2, Msg = "未知错误" };
  38. try
  39. {
  40. string UserId = "";
  41. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 98).ToList();
  42. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  43. UserId += gta.UId + ",";
  44. if (!string.IsNullOrWhiteSpace(UserId))
  45. {
  46. UserId = UserId.Substring(0, UserId.Length - 1);
  47. }
  48. else
  49. {
  50. UserId = "0";
  51. }
  52. string sql = string.Format(@"select Id,DiId,PriceName,Price,(select name from Sys_SetData where id=s.Currency) as Currency,FilePath,
  53. (select CnName from Sys_Users where Id=s.CreateUserId) as 'CreateUserName',CreateTime,(select IsAuditGM from
  54. Grp_CreditCardPayment where CTable=98 and CId=s.Id and IsDel=0) as 'isAudit' from Grp_DecreasePayments s where DIID={0} and IsDel=0 and s.CreateUserId in ({1}) ", dto.DiId,UserId);
  55. List<DecreasePaymentsView> _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
  56. if (_DecreasePayments.Count != 0)
  57. {
  58. result = new Result() { Code = 0, Msg = "查询成功!", Data = _DecreasePayments };
  59. }
  60. else
  61. {
  62. result = new Result() { Code = 0, Msg = "暂无数据!", Data = _DecreasePayments };
  63. }
  64. }
  65. catch (Exception ex)
  66. {
  67. result = new Result() { Code = -2, Msg = "未知错误" };
  68. }
  69. return result;
  70. }
  71. public async Task<Result> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  72. {
  73. Result result = new Result() { Code = -2, Msg = "未知错误" };
  74. try
  75. {
  76. #region 团组下拉框
  77. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  78. string DiId = "0";
  79. foreach (var item in grp_GroupsTaskAssignment)
  80. {
  81. DiId += item.DIId + ",";
  82. }
  83. if (DiId!="0")
  84. {
  85. DiId = DiId.Substring(0, DiId.Length - 1);
  86. }
  87. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  88. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  89. if (grp_Delegations.Count == 0)
  90. {
  91. return result = new Result() { Code = -1, Msg = "查询失败!" };
  92. }
  93. #endregion
  94. #region 其他下拉框查询
  95. //支付方式
  96. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  97. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  98. #endregion
  99. var data = new
  100. {
  101. Payment = _Payment,
  102. GroupName = grp_Delegations,
  103. };
  104. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  105. }
  106. catch (Exception ex)
  107. {
  108. return result = new Result() { Code = -2, Msg = "程序错误" };
  109. throw;
  110. }
  111. }
  112. public async Task<Result> OpDecreasePayments(DecreasePaymentsOpDto dto)
  113. {
  114. Result result = new Result() { Code = -2, Msg = "未知错误" };
  115. BeginTran();
  116. try
  117. {
  118. int id = 0;
  119. Grp_DecreasePayments grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  120. List<TeamRateDescAddCurrencyIdView> teamRates = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, dto.DiId, 98);
  121. if (dto.Status == 1)//添加
  122. {
  123. string selectSql = string.Format(@"select * from Grp_DecreasePayments where PriceName='{0}' and IsDel={1} and DiId={2}"
  124. , dto.PriceName, 0, dto.DiId);
  125. var DecreasePayments = await _sqlSugar.SqlQueryable<Grp_DecreasePayments>(selectSql).FirstAsync();//查询是否存在
  126. if (DecreasePayments != null)
  127. {
  128. return result = new Result() { Code = -1, Msg = "该数据已存在,请勿重复添加!" };
  129. }
  130. else//不存在,可添加
  131. {
  132. id = await AddAsyncReturnId(grp_Decrease);
  133. if (id > 0)
  134. {
  135. result = new Result() { Code = 0, Msg = "添加成功!" };
  136. }
  137. else
  138. {
  139. result = new Result() { Code = 0, Msg = "添加失败!" };
  140. }
  141. if (result.Code == 0)
  142. {
  143. //进行C表添加
  144. Grp_CreditCardPayment C = new Grp_CreditCardPayment();
  145. C.PayDId = dto.PayDId;
  146. C.ConsumptionPatterns = "";
  147. C.ConsumptionDate = "";
  148. C.CTDId = 0;
  149. C.BankNo = "";
  150. C.CardholderName = "";
  151. C.PayMoney = grp_Decrease.Price;
  152. C.PaymentCurrency = grp_Decrease.Currency;
  153. //当天汇率
  154. //if (!string.IsNullOrEmpty(hfRate.Value))
  155. // C.DayRate = hfRate.Value;
  156. //else
  157. //C.DayRate = "";
  158. C.CompanyBankNo = "";
  159. C.OtherBankName = "";
  160. C.OtherSideNo = "";
  161. C.OtherSideName = "";
  162. C.Remark = "";
  163. C.CreateUserId = grp_Decrease.CreateUserId;
  164. C.MFOperator = 0;
  165. C.MFOperatorDate = "";
  166. C.IsAuditDM = 0;
  167. C.AuditDMOperate = 0;
  168. C.AuditDMDate = "";
  169. C.IsAuditMF = 0;
  170. C.AuditMFOperate = 0;
  171. C.AuditMFDate = "";
  172. C.IsAuditGM = 0;
  173. C.AuditGMOperate = 21;
  174. C.AuditGMDate = "";
  175. C.IsPay = 0;
  176. C.DIId = grp_Decrease.DiId;
  177. C.CId = id;
  178. C.CTable = 98;
  179. C.PayPercentage = 100;
  180. C.PayThenMoney = 0;
  181. C.PayPercentageOld = 0;
  182. C.PayThenMoneyOld = 0;
  183. C.UpdateDate = "";
  184. C.Payee = dto.Payee;
  185. C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  186. C.ExceedBudget = 0;
  187. //C.RMBPrice = 0.00f;
  188. //设置该团组的汇率
  189. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyCode == grp_Decrease.Currency.ToString()).FirstOrDefault();
  190. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 98);
  191. if (teamRate != null)
  192. {
  193. if (teamRate.CurrencyCode.Equals("CNY"))
  194. {
  195. C.DayRate = 1.0000M;
  196. C.RMBPrice = C.PayMoney;
  197. }
  198. else
  199. {
  200. C.DayRate = teamRate.Rate;
  201. C.RMBPrice = C.PayMoney * C.DayRate;
  202. }
  203. }
  204. else
  205. {
  206. C.DayRate = 1.0000M;
  207. C.RMBPrice = C.PayMoney;
  208. }
  209. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  210. if (cId != 0)
  211. {
  212. result = new Result() { Code = 0, Msg = "添加成功!" };
  213. }
  214. else
  215. {
  216. RollbackTran();
  217. result = new Result() { Code = -1, Msg = "添加失败!" };
  218. }
  219. }
  220. else
  221. {
  222. result = new Result() { Code = -1, Msg = "添加失败!" };
  223. }
  224. }
  225. }
  226. else if (dto.Status == 2)
  227. {
  228. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  229. {
  230. DiId = grp_Decrease.DiId,
  231. PriceName = grp_Decrease.PriceName,
  232. Price = grp_Decrease.Price,
  233. Currency = grp_Decrease.Currency,
  234. FilePath = grp_Decrease.FilePath,
  235. Remark = grp_Decrease.Remark,
  236. });
  237. if (res)
  238. {
  239. Grp_CreditCardPayment grp_CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == grp_Decrease.Id && a.CTable==98 && a.CId==grp_Decrease.Id && a.IsDel == 0);
  240. if (grp_CreditCardPayment != null)
  241. {
  242. //设置该团组的汇率
  243. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyCode == grp_Decrease.Currency.ToString()).FirstOrDefault();
  244. if (teamRate != null)
  245. {
  246. if (teamRate.CurrencyCode.Equals("CNY"))
  247. {
  248. grp_CreditCardPayment.DayRate = 1.0000M;
  249. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  250. }
  251. else
  252. {
  253. grp_CreditCardPayment.DayRate = teamRate.Rate;
  254. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  255. }
  256. }
  257. else
  258. {
  259. grp_CreditCardPayment.DayRate = 1M;
  260. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price;
  261. }
  262. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.Id == grp_CreditCardPayment.Id).SetColumns(a => new Grp_CreditCardPayment
  263. {
  264. PayDId = dto.PayDId,
  265. PayMoney = grp_Decrease.Price,
  266. PaymentCurrency = grp_Decrease.Currency,
  267. Payee = dto.Payee,
  268. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  269. DayRate = grp_CreditCardPayment.DayRate,
  270. RMBPrice = grp_CreditCardPayment.RMBPrice,
  271. }).ExecuteCommandAsync();
  272. if (CTable != 0)
  273. {
  274. result = new Result() { Code = 0, Msg = "修改成功!" };
  275. }
  276. else
  277. {
  278. result = new Result() { Code = -1, Msg = "修改失败!" };
  279. RollbackTran();
  280. }
  281. }
  282. else
  283. {
  284. RollbackTran();
  285. result = new Result() { Code = -1, Msg = "修改失败!" };
  286. }
  287. }
  288. else
  289. {
  290. result = new Result() { Code = -1, Msg = "修改失败!" };
  291. }
  292. }
  293. CommitTran();
  294. }
  295. catch (Exception ex)
  296. {
  297. RollbackTran();
  298. result = new Result() { Code = -2, Msg = "未知错误" };
  299. }
  300. return result;
  301. }
  302. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  303. {
  304. Result result = new Result() { Code = -2, Msg = "未知错误" };
  305. try
  306. {
  307. #region 团组下拉框
  308. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  309. string DiId = "";
  310. foreach (var item in grp_GroupsTaskAssignment)
  311. {
  312. DiId += item.DIId + ",";
  313. }
  314. if (!string.IsNullOrWhiteSpace(DiId))
  315. {
  316. DiId = DiId.Substring(0, DiId.Length - 1);
  317. }
  318. else
  319. {
  320. DiId = "0";
  321. }
  322. string sql = string.Format(@"select Id,TourCode,TeamName,ClientName,VisitStartDate,VisitEndDate,VisitCountry,VisitDays,VisitPNumber from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  323. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  324. if (grp_Delegations.Count != 0)
  325. {
  326. int count = grp_Delegations.Count;
  327. float totalPage = (float)count / dto.PageSize;//总页数
  328. if (totalPage == 0) totalPage = 1;
  329. else totalPage = (int)Math.Ceiling((double)totalPage);
  330. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  331. for (int i = 0; i < dto.PageSize; i++)
  332. {
  333. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  334. if (RowIndex < grp_Delegations.Count)
  335. {
  336. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  337. }
  338. else
  339. {
  340. break;
  341. }
  342. }
  343. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  344. rst.DataList = delegationEasyViews;
  345. rst.DataCount = count;
  346. rst.CurrPageIndex = dto.PageIndex;
  347. rst.CurrPageSize = dto.PageSize;
  348. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  349. }
  350. else
  351. {
  352. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  353. rst.DataList=new List<DelegationEasyView>();
  354. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  355. }
  356. #endregion
  357. }
  358. catch (Exception ex)
  359. {
  360. return result = new Result() { Code = -2, Msg = "程序错误" };
  361. throw;
  362. }
  363. }
  364. /// <summary>
  365. /// 根据团组增减款项表Id查询数据
  366. /// </summary>
  367. /// <param name="dto"></param>
  368. /// <returns></returns>
  369. /// <exception cref="NotImplementedException"></exception>
  370. public async Task<Result> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  371. {
  372. Result result = new Result() { Code = -2, Msg = "程序错误" };
  373. try
  374. {
  375. Grp_DecreasePayments grp_Decrease = _sqlSugar.Queryable<Grp_DecreasePayments>().First(a=>a.Id==dto.Id && a.IsDel==0);
  376. Grp_CreditCardPayment grp_CreditCard= _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable==98);
  377. var data = new
  378. {
  379. _Decrease = grp_Decrease,
  380. _CreditCard = grp_CreditCard,
  381. };
  382. result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  383. }
  384. catch (Exception ex)
  385. {
  386. result = new Result() { Code = -2, Msg = "程序错误" };
  387. throw;
  388. }
  389. return result;
  390. }
  391. }
  392. }