DecreasePaymentsRepository.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. using AutoMapper;
  2. using NPOI.SS.Formula.Functions;
  3. using OASystem.Domain;
  4. using OASystem.Domain.AesEncryption;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Entities.Financial;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.Entities.Resource;
  9. using OASystem.Domain.ViewModels.Financial;
  10. using OASystem.Domain.ViewModels.Groups;
  11. using OASystem.Domain.ViewModels.QiYeWeChat;
  12. using OASystem.Domain.ViewModels.Resource;
  13. using OASystem.Infrastructure.Repositories.System;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Runtime.Intrinsics.Arm;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. namespace OASystem.Infrastructure.Repositories.Groups
  21. {
  22. public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
  23. {
  24. private readonly IMapper _mapper;
  25. private readonly TeamRateRepository _teamRateRep;
  26. private readonly SetDataRepository _setDataRepository;
  27. public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper, TeamRateRepository teamRateRep, SetDataRepository setDataRepository )
  28. : base(sqlSugar)
  29. {
  30. this._mapper = mapper;
  31. _teamRateRep = teamRateRep;
  32. this._setDataRepository = setDataRepository;
  33. }
  34. /// <summary>
  35. /// 根据团组Id查询数据
  36. /// </summary>
  37. /// <param name="dto"></param>
  38. /// <returns></returns>
  39. public async Task<JsonView> DecreasePaymentsList(DecreasePaymentsListDto dto)
  40. {
  41. string sqlWhere = "";
  42. if (dto.IsPaySign != -1)
  43. {
  44. sqlWhere += string.Format(@" And ccp.IsPay = {0} ", dto.IsPaySign);
  45. }
  46. //雷怡 2024-5-8 15:14 新增View字段 CreateTime
  47. string sql = string.Format(@" Select gdp.Id,gdp.DiId,gdp.PriceName,gdp.FeeTotal,sd1.[Name] as Currency,gdp.FilePath,su.CnName as CreateUserName,
  48. ccp.IsAuditGM as isAudit,ccp.IsPay,gdp.CreateTime
  49. From Grp_DecreasePayments as gdp With(Nolock) Left Join Grp_CreditCardPayment as ccp With(Nolock) On gdp.Id = ccp.CId
  50. Left Join Sys_SetData as sd1 On gdp.Currency = sd1.Id
  51. Left Join Sys_Users as su On gdp.CreateUserId = su.Id
  52. 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);
  53. List<DecreasePaymentsView> _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
  54. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = _DecreasePayments };
  55. }
  56. public async Task<JsonView> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  57. {
  58. #region 团组下拉框
  59. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  60. string DiId = "";
  61. List<DecreasePaymentGroupView> _Delegations = new List<DecreasePaymentGroupView>();
  62. if (grp_GroupsTaskAssignment.Count > 0)
  63. {
  64. foreach (var item in grp_GroupsTaskAssignment)
  65. {
  66. DiId += item.DIId + ",";
  67. }
  68. if (DiId != "0")
  69. {
  70. DiId = DiId.Substring(0, DiId.Length - 1);
  71. }
  72. string sql = string.Format($@"Select
  73. (select ssd.name from Sys_SetData ssd WHERE ssd.id = di.TeamLevSId) as TeamLevSId,
  74. di.Id,
  75. di.TeamName,
  76. di.ClientUnit,
  77. di.ClientName,
  78. di.TourCode,
  79. di.TeamDid,
  80. sd.[Name] As TeamTypeName,
  81. di.VisitCountry,
  82. di.VisitStartDate,
  83. di.VisitEndDate,
  84. di.VisitDays,
  85. di.VisitPNumber,
  86. di.CreateTime
  87. From Grp_DelegationInfo di With(NoLock)
  88. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  89. Where di.Id in({DiId}) and di.IsDel=0
  90. Order By di.VisitStartDate Desc");
  91. //DecreasePaymentGroupView
  92. _Delegations = _sqlSugar.SqlQueryable<DecreasePaymentGroupView>(sql).ToList();
  93. }
  94. #endregion
  95. #region 其他下拉框查询
  96. //支付方式
  97. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  98. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  99. //供应商 supplier
  100. List<Sys_SetData> supplier = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 21 && a.IsDel == 0).ToList();
  101. List<SetDataInfoView> _supplier = _mapper.Map<List<SetDataInfoView>>(supplier);
  102. if (_supplier.Count > 0)
  103. {
  104. var d1 = _supplier.Find(it => it.Name.Equals("策划 公司"));
  105. if (d1 != null) _supplier.Remove(d1);
  106. var d2 = _supplier.Find(it => it.Name.Equals("礼仪"));
  107. if (d2 != null) _supplier.Remove(d2);
  108. var d3 = _supplier.Find(it => it.Name.Equals("日常办公用品"));
  109. if (d3 != null) _supplier.Remove(d3);
  110. var d4 = _supplier.Find(it => it.Name.Equals("其他"));
  111. if (d4 != null)
  112. {
  113. _supplier.Remove(d4);
  114. _supplier.Add(d4);
  115. }
  116. }
  117. List<dynamic> _supplierArea = new List<dynamic>() {
  118. new { id=1,name = "国内" },
  119. new { id=2,name = "国外" },
  120. };
  121. #endregion
  122. var data = new
  123. {
  124. payment = _Payment,
  125. groupName = _Delegations,
  126. supplier = _supplier,
  127. supplierArea = _supplierArea
  128. };
  129. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = data };
  130. }
  131. public async Task<JsonView> OpDecreasePayments(DecreasePaymentsOpDto dto)
  132. {
  133. BeginTran();
  134. int id = 0;
  135. var grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  136. //处理费用总计
  137. if (grp_Decrease.FeeTotal == 0.00M)
  138. {
  139. grp_Decrease.FeeTotal = grp_Decrease.Price * grp_Decrease.Price;
  140. }
  141. List<TeamRateDescAddCurrencyIdView> teamRates = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, dto.DiId, 98);
  142. if (dto.Status == 1)//添加
  143. {
  144. string selectSql = string.Format(@"select * from Grp_DecreasePayments where PriceName='{0}' and IsDel={1} and DiId={2}"
  145. , dto.PriceName, 0, dto.DiId);
  146. var DecreasePayments = await _sqlSugar.SqlQueryable<Grp_DecreasePayments>(selectSql).FirstAsync();//查询是否存在
  147. if (DecreasePayments != null)
  148. {
  149. return new JsonView() { Code = 400, Msg = "该数据已存在,请勿重复添加!" };
  150. }
  151. else//不存在,可添加
  152. {
  153. id = await AddAsyncReturnId(grp_Decrease);
  154. if (id < 1)
  155. {
  156. RollbackTran();
  157. return new JsonView() { Code = 400, Msg = "添加失败!" };
  158. }
  159. //进行C表添加
  160. Grp_CreditCardPayment C = new Grp_CreditCardPayment();
  161. C.PayDId = dto.PayDId;
  162. C.ConsumptionPatterns = "";
  163. C.ConsumptionDate = "";
  164. C.CTDId = 0;
  165. C.BankNo = "";
  166. C.CardholderName = "";
  167. C.PayMoney = grp_Decrease.FeeTotal;
  168. C.PaymentCurrency = grp_Decrease.Currency;
  169. //当天汇率
  170. //if (!string.IsNullOrEmpty(hfRate.Value))
  171. // C.DayRate = hfRate.Value;
  172. //else
  173. //C.DayRate = "";
  174. C.CompanyBankNo = "";
  175. C.OtherBankName = dto.OtherBankName;
  176. C.OtherSideNo = dto.OtherSideNo;
  177. C.OtherSideName = dto.OtherSideName;
  178. C.Remark = "";
  179. C.CreateUserId = grp_Decrease.CreateUserId;
  180. C.MFOperator = 0;
  181. C.MFOperatorDate = "";
  182. C.IsAuditDM = 0;
  183. C.AuditDMOperate = 0;
  184. C.AuditDMDate = "";
  185. C.IsAuditMF = 0;
  186. C.AuditMFOperate = 0;
  187. C.AuditMFDate = "";
  188. C.IsAuditGM = 0;
  189. C.AuditGMOperate = 21;
  190. C.AuditGMDate = "";
  191. //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
  192. if (C.PayDId == 72) C.IsPay = 1;
  193. C.DIId = grp_Decrease.DiId;
  194. C.CId = id;
  195. C.CTable = 98;
  196. C.PayPercentage = 100;
  197. C.PayThenMoney = 0;
  198. C.PayPercentageOld = 0;
  199. C.PayThenMoneyOld = 0;
  200. C.UpdateDate = "";
  201. C.Payee = dto.SupplierName;
  202. C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  203. C.ExceedBudget = 0;
  204. //C.RMBPrice = 0.00f;
  205. //设置该团组的汇率
  206. var teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  207. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 98);
  208. if (teamRate != null)
  209. {
  210. if (teamRate.CurrencyCode.Equals("CNY"))
  211. {
  212. C.DayRate = 1.0000M;
  213. C.RMBPrice = C.PayMoney;
  214. }
  215. else
  216. {
  217. C.DayRate = teamRate.Rate;
  218. C.RMBPrice = C.PayMoney * C.DayRate;
  219. }
  220. }
  221. else
  222. {
  223. RollbackTran();
  224. return new JsonView() { Code = 400, Msg = $"添加失败!团组汇率未设置{_sqlSugar.Queryable<Sys_SetData>().First(it => it.IsDel == 0 && it.Id == grp_Decrease.Currency)?.Name ?? ""}该币种汇率!" };
  225. }
  226. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  227. if (cId > 1)
  228. {
  229. #region 策划部内容同步添加至资料库
  230. //var userInfo = _sqlSugar.Queryable<Sys_Users>()
  231. // .LeftJoin<Sys_Department>((u,d)=> d.IsDel == 0 && u.DepId == d.Id )
  232. // .Where((u, d) => u.Id == dto.CreateUserId && d.DepName == "策划部" && u.IsDel == 0)
  233. // .First();
  234. //if (userInfo != null)
  235. //{
  236. // Res_MediaSuppliers mediaSuppliersData = new Res_MediaSuppliers
  237. // {
  238. // CreateTime = DateTime.Now,
  239. // CreateUserId = dto.CreateUserId,
  240. // UnitName = dto.SupplierName,
  241. // TypeId = dto.SupplierTypeId,
  242. // UnitAddress = dto.SupplierAddress,
  243. // Contact = dto.SupplierContact,
  244. // Tel = dto.SupplierContactNumber,
  245. // Email = dto.SupplierEmail,
  246. // Privince = dto.SupplierArea == 1 ? "国内" :"国外",
  247. // };
  248. // EncryptionProcessor.EncryptProperties(mediaSuppliersData);
  249. // _sqlSugar.Insertable(mediaSuppliersData).ExecuteCommand();
  250. //}
  251. #endregion
  252. CommitTran();
  253. var data = new { ccpId = cId, sign = 1,dataId = id };
  254. return new JsonView() { Code = 200, Msg = "添加成功!", Data = data };
  255. }
  256. RollbackTran();
  257. return new JsonView() { Code = 400, Msg = "添加失败!" };
  258. }
  259. }
  260. else if (dto.Status == 2)
  261. {
  262. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  263. {
  264. DiId = grp_Decrease.DiId,
  265. SupplierArea = grp_Decrease.SupplierArea,
  266. SupplierTypeId = grp_Decrease.SupplierTypeId,
  267. SupplierName = grp_Decrease.SupplierName,
  268. SupplierContact = grp_Decrease.SupplierContact,
  269. SupplierContactNumber = grp_Decrease.SupplierContactNumber,
  270. SupplierSocialAccount = grp_Decrease.SupplierSocialAccount,
  271. SupplierEmail = grp_Decrease.SupplierEmail,
  272. SupplierAddress = grp_Decrease.SupplierAddress,
  273. PriceName = grp_Decrease.PriceName,
  274. Price = grp_Decrease.Price,
  275. Quantity = grp_Decrease.Quantity,
  276. FeeTotal = grp_Decrease.FeeTotal,
  277. Currency = grp_Decrease.Currency,
  278. FilePath = grp_Decrease.FilePath,
  279. OTAOrderNo = grp_Decrease.OTAOrderNo,
  280. Remark = grp_Decrease.Remark,
  281. });
  282. if (res)
  283. {
  284. var grp_CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == grp_Decrease.Id && a.CTable == 98 && a.CId == grp_Decrease.Id && a.IsDel == 0);
  285. if (grp_CreditCardPayment != null)
  286. {
  287. //设置该团组的汇率
  288. var teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  289. if (teamRate != null)
  290. {
  291. if (teamRate.CurrencyCode.Equals("CNY"))
  292. {
  293. grp_CreditCardPayment.DayRate = 1.0000M;
  294. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  295. }
  296. else
  297. {
  298. grp_CreditCardPayment.DayRate = teamRate.Rate;
  299. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  300. }
  301. }
  302. else
  303. {
  304. RollbackTran();
  305. return new JsonView() { Code = 400, Msg = "修改失败!" };
  306. }
  307. //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
  308. int isPay = 0;
  309. if (dto.PayDId == 72) isPay = 1;
  310. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  311. .Where(a => a.Id == grp_CreditCardPayment.Id)
  312. .SetColumns(a => new Grp_CreditCardPayment
  313. {
  314. OtherSideName = dto.OtherSideName,
  315. OtherSideNo = dto.OtherSideNo,
  316. OtherBankName = dto.OtherBankName,
  317. PayDId = dto.PayDId,
  318. IsPay = isPay,
  319. PayMoney = grp_Decrease.FeeTotal,
  320. PaymentCurrency = grp_Decrease.Currency,
  321. Payee = dto.SupplierName,
  322. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  323. DayRate = grp_CreditCardPayment.DayRate,
  324. RMBPrice = grp_CreditCardPayment.RMBPrice,
  325. //IsAuditGM = auto ? 3 : grp_CreditCardPayment.IsAuditGM
  326. })
  327. .ExecuteCommandAsync();
  328. if (CTable > 0)
  329. {
  330. CommitTran();
  331. var data = new { ccpId = grp_CreditCardPayment.Id, sign = 2,dataId = grp_Decrease.Id };
  332. return new JsonView() { Code = 200, Msg = "修改成功!", Data = data };
  333. }
  334. }
  335. }
  336. }
  337. RollbackTran();
  338. return new JsonView() { Code = 400, Msg = MsgTips.Fail }; ;
  339. }
  340. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  341. {
  342. Result result = new Result() { Code = -2, Msg = "未知错误" };
  343. try
  344. {
  345. #region 团组下拉框
  346. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  347. string DiId = "";
  348. foreach (var item in grp_GroupsTaskAssignment)
  349. {
  350. DiId += item.DIId + ",";
  351. }
  352. if (!string.IsNullOrWhiteSpace(DiId))
  353. {
  354. DiId = DiId.Substring(0, DiId.Length - 1);
  355. }
  356. else
  357. {
  358. DiId = "0";
  359. }
  360. 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);
  361. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  362. if (grp_Delegations.Count != 0)
  363. {
  364. int count = grp_Delegations.Count;
  365. float totalPage = (float)count / dto.PageSize;//总页数
  366. if (totalPage == 0) totalPage = 1;
  367. else totalPage = (int)Math.Ceiling((double)totalPage);
  368. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  369. for (int i = 0; i < dto.PageSize; i++)
  370. {
  371. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  372. if (RowIndex < grp_Delegations.Count)
  373. {
  374. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  375. }
  376. else
  377. {
  378. break;
  379. }
  380. }
  381. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  382. rst.DataList = delegationEasyViews;
  383. rst.DataCount = count;
  384. rst.CurrPageIndex = dto.PageIndex;
  385. rst.CurrPageSize = dto.PageSize;
  386. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  387. }
  388. else
  389. {
  390. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  391. rst.DataList = new List<DelegationEasyView>();
  392. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  393. }
  394. #endregion
  395. }
  396. catch (Exception ex)
  397. {
  398. return result = new Result() { Code = -2, Msg = "程序错误" };
  399. throw;
  400. }
  401. }
  402. /// <summary>
  403. /// 根据团组增减款项表Id查询数据
  404. /// </summary>
  405. /// <param name="dto"></param>
  406. /// <returns></returns>
  407. /// <exception cref="NotImplementedException"></exception>
  408. public async Task<JsonView> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  409. {
  410. string sql = string.Format($@"Select
  411. dp.Id,
  412. dp.DiId,
  413. dp.SupplierArea,
  414. dp.SupplierTypeId,
  415. dp.SupplierName,
  416. dp.SupplierContact,
  417. dp.SupplierContactNumber,
  418. dp.SupplierSocialAccount,
  419. dp.SupplierEmail,
  420. dp.SupplierAddress,
  421. dp.PriceName,
  422. dp.Price,
  423. dp.Quantity,
  424. dp.FeeTotal,
  425. dp.Currency,
  426. dp.FilePath,
  427. dp.OTAOrderNo,
  428. dp.Remark,
  429. ccp.PayDId,
  430. ccp.OrbitalPrivateTransfer,
  431. ccp.OtherBankName,
  432. ccp.OtherSideName,
  433. ccp.OtherSideNo,
  434. ccp.IsAuditGM
  435. From Grp_DecreasePayments dp With(NoLock)
  436. Left Join Grp_CreditCardPayment ccp With(NoLock) On dp.Id = ccp.CId And dp.DiId = ccp.DIId And ccp.CTable = 98
  437. Where dp.IsDel = 0 And dp.Id = {dto.Id}");
  438. var info = await _sqlSugar.SqlQueryable<DecreasePaymentsInfoView>(sql).FirstAsync();
  439. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = info };
  440. }
  441. /// <summary>
  442. /// Del
  443. /// </summary>
  444. /// <param name="dto"></param>
  445. /// <returns></returns>
  446. /// <exception cref="NotImplementedException"></exception>
  447. public async Task<Result> _Del(int id, int userId)
  448. {
  449. Result result = new Result() { Code = -2, Msg = "删除失败!" };
  450. _sqlSugar.BeginTran();
  451. var del = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  452. .SetColumns(it => new Grp_DecreasePayments()
  453. {
  454. IsDel = 1,
  455. DeleteUserId = userId,
  456. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  457. }).Where(it => it.Id == id)
  458. .ExecuteCommandAsync();
  459. if (del > 0)
  460. {
  461. var del1 = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  462. .SetColumns(a => new Grp_CreditCardPayment()
  463. {
  464. IsDel = 1,
  465. DeleteUserId = userId,
  466. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  467. })
  468. .Where(a => a.CId == id && a.CTable == 98)
  469. .ExecuteCommandAsync();
  470. if (del1 > 0)
  471. {
  472. _sqlSugar.CommitTran();
  473. result.Code = 0;
  474. result.Msg = "删除成功!";
  475. return result;
  476. }
  477. }
  478. _sqlSugar.RollbackTran();
  479. return result;
  480. }
  481. }
  482. }