DecreasePaymentsRepository.cs 21 KB

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