DecreasePaymentsRepository.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 = "0";
  41. //List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 98).ToList();
  42. //UserId = string.Join(",", gtaUIdList.Select(it => it.UId).ToList());
  43. //string sql = string.Format(@"select Id,DiId,PriceName,Price,(select name from Sys_SetData where id=s.Currency) as Currency,FilePath,
  44. // (select CnName from Sys_Users where Id=s.CreateUserId) as 'CreateUserName',CreateTime,(select IsAuditGM from
  45. // Grp_CreditCardPayment where CTable=98 and CId=s.Id and DiId = {0} and IsDel=0) as 'isAudit' from Grp_DecreasePayments s
  46. // where DIID={0} and IsDel=0 and s.CreateUserId in ({1}) ", dto.DiId, dto.UserId);
  47. string sqlWhere = "";
  48. if (dto.IsPaySign != -1) {
  49. sqlWhere += string.Format(@" And ccp.IsPay = {0} ", dto.IsPaySign);
  50. }
  51. //雷怡 2024-5-8 15:14 新增View字段 CreateTime
  52. string sql = string.Format(@" Select gdp.Id,gdp.DiId,gdp.PriceName,gdp.Price,sd1.[Name] as Currency,gdp.FilePath,su.CnName as CreateUserName,
  53. ccp.IsAuditDM as isAudit,ccp.IsPay,gdp.CreateTime
  54. From Grp_DecreasePayments as gdp With(Nolock) Left Join Grp_CreditCardPayment as ccp With(Nolock) On gdp.Id = ccp.CId
  55. Left Join Sys_SetData as sd1 On gdp.Currency = sd1.Id
  56. Left Join Sys_Users as su On gdp.CreateUserId = su.Id
  57. Where gdp.DiId = {0} And ccp.CTable = 98 {2} And ccp.IsDel = 0 And gdp.IsDel = 0 And gdp.CreateUserId in ({1}) ", dto.DiId, dto.UserId, sqlWhere);
  58. List<DecreasePaymentsView> _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
  59. if (_DecreasePayments.Count > 0)
  60. {
  61. result = new Result() { Code = 0, Msg = "查询成功!", Data = _DecreasePayments };
  62. }
  63. else
  64. {
  65. result = new Result() { Code = 0, Msg = "暂无数据!", Data = _DecreasePayments };
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. result = new Result() { Code = -2, Msg = ex.Message };
  71. }
  72. return result;
  73. }
  74. public async Task<Result> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  75. {
  76. Result result = new Result() { Code = -2, Msg = "未知错误" };
  77. try
  78. {
  79. #region 团组下拉框
  80. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  81. string DiId = "0";
  82. foreach (var item in grp_GroupsTaskAssignment)
  83. {
  84. DiId += item.DIId + ",";
  85. }
  86. if (DiId != "0")
  87. {
  88. DiId = DiId.Substring(0, DiId.Length - 1);
  89. }
  90. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1} Order By CreateTime Desc", DiId, 0);
  91. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  92. if (grp_Delegations.Count == 0)
  93. {
  94. return result = new Result() { Code = -1, Msg = "查询失败!" };
  95. }
  96. #endregion
  97. #region 其他下拉框查询
  98. //支付方式
  99. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  100. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  101. #endregion
  102. var data = new
  103. {
  104. Payment = _Payment,
  105. GroupName = grp_Delegations,
  106. };
  107. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  108. }
  109. catch (Exception ex)
  110. {
  111. return result = new Result() { Code = -2, Msg = "程序错误" };
  112. throw;
  113. }
  114. }
  115. public async Task<Result> OpDecreasePayments(DecreasePaymentsOpDto dto)
  116. {
  117. Result result = new Result() { Code = -2, Msg = "未知错误" };
  118. BeginTran();
  119. try
  120. {
  121. int id = 0;
  122. Grp_DecreasePayments grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  123. List<TeamRateDescAddCurrencyIdView> teamRates = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, dto.DiId, 98);
  124. if (dto.Status == 1)//添加
  125. {
  126. string selectSql = string.Format(@"select * from Grp_DecreasePayments where PriceName='{0}' and IsDel={1} and DiId={2}"
  127. , dto.PriceName, 0, dto.DiId);
  128. var DecreasePayments = await _sqlSugar.SqlQueryable<Grp_DecreasePayments>(selectSql).FirstAsync();//查询是否存在
  129. if (DecreasePayments != null)
  130. {
  131. return new Result() { Code = -1, Msg = "该数据已存在,请勿重复添加!" };
  132. }
  133. else//不存在,可添加
  134. {
  135. id = await AddAsyncReturnId(grp_Decrease);
  136. if (id < 1)
  137. {
  138. RollbackTran();
  139. return new Result() { Code = -1, Msg = "添加失败!" };
  140. }
  141. //进行C表添加
  142. Grp_CreditCardPayment C = new Grp_CreditCardPayment();
  143. C.PayDId = dto.PayDId;
  144. C.ConsumptionPatterns = "";
  145. C.ConsumptionDate = "";
  146. C.CTDId = 0;
  147. C.BankNo = "";
  148. C.CardholderName = "";
  149. C.PayMoney = grp_Decrease.Price;
  150. C.PaymentCurrency = grp_Decrease.Currency;
  151. //当天汇率
  152. //if (!string.IsNullOrEmpty(hfRate.Value))
  153. // C.DayRate = hfRate.Value;
  154. //else
  155. //C.DayRate = "";
  156. C.CompanyBankNo = "";
  157. C.OtherBankName = "";
  158. C.OtherSideNo = "";
  159. C.OtherSideName = "";
  160. C.Remark = "";
  161. C.CreateUserId = grp_Decrease.CreateUserId;
  162. C.MFOperator = 0;
  163. C.MFOperatorDate = "";
  164. C.IsAuditDM = 0;
  165. C.AuditDMOperate = 0;
  166. C.AuditDMDate = "";
  167. C.IsAuditMF = 0;
  168. C.AuditMFOperate = 0;
  169. C.AuditMFDate = "";
  170. C.IsAuditGM = 0;
  171. C.AuditGMOperate = 21;
  172. C.AuditGMDate = "";
  173. if (C.PayDId == 72) C.IsPay = 1;
  174. else C.IsPay = 0;
  175. C.DIId = grp_Decrease.DiId;
  176. C.CId = id;
  177. C.CTable = 98;
  178. C.PayPercentage = 100;
  179. C.PayThenMoney = 0;
  180. C.PayPercentageOld = 0;
  181. C.PayThenMoneyOld = 0;
  182. C.UpdateDate = "";
  183. C.Payee = dto.Payee;
  184. C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  185. C.ExceedBudget = 0;
  186. //C.RMBPrice = 0.00f;
  187. //设置该团组的汇率
  188. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  189. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 98);
  190. if (teamRate != null)
  191. {
  192. if (teamRate.CurrencyCode.Equals("CNY"))
  193. {
  194. C.DayRate = 1.0000M;
  195. C.RMBPrice = C.PayMoney;
  196. }
  197. else
  198. {
  199. C.DayRate = teamRate.Rate;
  200. C.RMBPrice = C.PayMoney * C.DayRate;
  201. }
  202. }
  203. else
  204. {
  205. RollbackTran();
  206. return new Result() { Code = -1, Msg = $"添加失败!团组汇率未设置{_sqlSugar.Queryable<Sys_SetData>().First(it => it.IsDel == 0 && it.Id == grp_Decrease.Currency)?.Name ?? ""}该币种汇率!" };
  207. }
  208. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  209. if (cId != 0)
  210. {
  211. CommitTran();
  212. return new Result() { Code = 0, Msg = "添加成功!" };
  213. }
  214. else
  215. {
  216. RollbackTran();
  217. return new Result() { Code = -1, Msg = "添加失败!" };
  218. }
  219. }
  220. }
  221. else if (dto.Status == 2)
  222. {
  223. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  224. {
  225. DiId = grp_Decrease.DiId,
  226. PriceName = grp_Decrease.PriceName,
  227. Price = grp_Decrease.Price,
  228. Currency = grp_Decrease.Currency,
  229. FilePath = grp_Decrease.FilePath,
  230. Remark = grp_Decrease.Remark,
  231. });
  232. if (res)
  233. {
  234. 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);
  235. if (grp_CreditCardPayment != null)
  236. {
  237. //设置该团组的汇率
  238. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  239. if (teamRate != null)
  240. {
  241. if (teamRate.CurrencyCode.Equals("CNY"))
  242. {
  243. grp_CreditCardPayment.DayRate = 1.0000M;
  244. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  245. }
  246. else
  247. {
  248. grp_CreditCardPayment.DayRate = teamRate.Rate;
  249. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  250. }
  251. }
  252. else
  253. {
  254. RollbackTran();
  255. return new Result() { Code = -1, Msg = "修改失败!" };
  256. }
  257. int ispay = 0;
  258. if (dto.PayDId == 72) ispay = 1;
  259. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  260. .Where(a => a.Id == grp_CreditCardPayment.Id)
  261. .SetColumns(a => new Grp_CreditCardPayment
  262. {
  263. PayDId = dto.PayDId,
  264. IsPay = ispay,
  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. CommitTran();
  275. return new Result() { Code = 0, Msg = "修改成功!" };
  276. }
  277. else
  278. {
  279. RollbackTran();
  280. return new Result() { Code = -1, Msg = "修改失败!" };
  281. }
  282. }
  283. else
  284. {
  285. RollbackTran();
  286. return new Result() { Code = -1, Msg = "修改失败!" };
  287. }
  288. }
  289. else
  290. {
  291. RollbackTran();
  292. return new Result() { Code = -1, Msg = "修改失败!" };
  293. }
  294. }
  295. }
  296. catch (Exception ex)
  297. {
  298. RollbackTran();
  299. return new Result() { Code = -2, Msg = ex.Message };
  300. }
  301. return result;
  302. }
  303. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  304. {
  305. Result result = new Result() { Code = -2, Msg = "未知错误" };
  306. try
  307. {
  308. #region 团组下拉框
  309. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  310. string DiId = "";
  311. foreach (var item in grp_GroupsTaskAssignment)
  312. {
  313. DiId += item.DIId + ",";
  314. }
  315. if (!string.IsNullOrWhiteSpace(DiId))
  316. {
  317. DiId = DiId.Substring(0, DiId.Length - 1);
  318. }
  319. else
  320. {
  321. DiId = "0";
  322. }
  323. 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);
  324. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  325. if (grp_Delegations.Count != 0)
  326. {
  327. int count = grp_Delegations.Count;
  328. float totalPage = (float)count / dto.PageSize;//总页数
  329. if (totalPage == 0) totalPage = 1;
  330. else totalPage = (int)Math.Ceiling((double)totalPage);
  331. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  332. for (int i = 0; i < dto.PageSize; i++)
  333. {
  334. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  335. if (RowIndex < grp_Delegations.Count)
  336. {
  337. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  338. }
  339. else
  340. {
  341. break;
  342. }
  343. }
  344. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  345. rst.DataList = delegationEasyViews;
  346. rst.DataCount = count;
  347. rst.CurrPageIndex = dto.PageIndex;
  348. rst.CurrPageSize = dto.PageSize;
  349. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  350. }
  351. else
  352. {
  353. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  354. rst.DataList = new List<DelegationEasyView>();
  355. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  356. }
  357. #endregion
  358. }
  359. catch (Exception ex)
  360. {
  361. return result = new Result() { Code = -2, Msg = "程序错误" };
  362. throw;
  363. }
  364. }
  365. /// <summary>
  366. /// 根据团组增减款项表Id查询数据
  367. /// </summary>
  368. /// <param name="dto"></param>
  369. /// <returns></returns>
  370. /// <exception cref="NotImplementedException"></exception>
  371. public async Task<Result> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  372. {
  373. Result result = new Result() { Code = -2, Msg = "程序错误" };
  374. try
  375. {
  376. Grp_DecreasePayments grp_Decrease = _sqlSugar.Queryable<Grp_DecreasePayments>().First(a => a.Id == dto.Id && a.IsDel == 0);
  377. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 98);
  378. var data = new
  379. {
  380. _Decrease = grp_Decrease,
  381. _CreditCard = grp_CreditCard,
  382. };
  383. result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  384. }
  385. catch (Exception ex)
  386. {
  387. result = new Result() { Code = -2, Msg = "程序错误" };
  388. throw;
  389. }
  390. return result;
  391. }
  392. /// <summary>
  393. /// Del
  394. /// </summary>
  395. /// <param name="dto"></param>
  396. /// <returns></returns>
  397. /// <exception cref="NotImplementedException"></exception>
  398. public async Task<Result> _Del(int id, int userId)
  399. {
  400. Result result = new Result() { Code = -2, Msg = "删除失败!" };
  401. _sqlSugar.BeginTran();
  402. var del = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  403. .SetColumns(it => new Grp_DecreasePayments()
  404. {
  405. IsDel = 1,
  406. DeleteUserId = userId,
  407. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  408. }).Where(it => it.Id == id)
  409. .ExecuteCommandAsync();
  410. if (del > 0)
  411. {
  412. var del1 = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  413. .SetColumns(a => new Grp_CreditCardPayment()
  414. {
  415. IsDel = 1,
  416. DeleteUserId = userId,
  417. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  418. })
  419. .Where(a => a.CId == id && a.CTable == 98)
  420. .ExecuteCommandAsync();
  421. if (del1 > 0)
  422. {
  423. _sqlSugar.CommitTran();
  424. result.Code = 0;
  425. result.Msg = "删除成功!";
  426. return result;
  427. }
  428. }
  429. _sqlSugar.RollbackTran();
  430. return result;
  431. }
  432. }
  433. }