DecreasePaymentsRepository.cs 29 KB

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