DecreasePaymentsRepository.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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])
  239. .And(x => x.CalculationContent == spPriceName[1]);
  240. var setting = _sqlSugar.Queryable<Grp_GamesBudgetMaster>()
  241. .First(expression.ToExpression());
  242. if (setting != null)
  243. {
  244. var dbList = _sqlSugar.Queryable<Grp_DecreasePayments>()
  245. .LeftJoin<Grp_CreditCardPayment>((x, a) => x.Id == a.CId && a.IsDel == 0 && a.CTable == 98 && a.DIId == dto.DiId)
  246. .Where((x, a) => x.IsDel == 0 && x.PriceName.Contains(spPriceName[0]) && x.PriceName.Contains(spPriceName[1]) && x.Id != id)
  247. .Select((x, a) => new
  248. {
  249. x,
  250. a.RMBPrice,
  251. })
  252. .ToList();
  253. //币种问题 (836 CNY)
  254. if (dto.Currency != 836)
  255. {
  256. var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  257. if (rate != null)
  258. {
  259. //dto.Price *= rate.Rate;
  260. dto.FeeTotal *= rate.Rate;
  261. }
  262. }
  263. //现有金额
  264. var sumPrice = dbList.Sum(x => x.RMBPrice);
  265. //现有数量
  266. //var sumCount = dbList.Sum(x => x.Quantity);
  267. var availableAmount = setting.ItemTotal - sumPrice;
  268. //var availableQuantity = setting.Quantity - sumCount;
  269. if (availableAmount > 0) // && availableQuantity > 0
  270. {
  271. //单价计算
  272. //var settingPrice = setting.UnitPrice;
  273. //if (int.TryParse(setting.CycleUnit, out int cycleUnit))
  274. //{
  275. // settingPrice *= cycleUnit;
  276. //}
  277. if (dto.FeeTotal <= availableAmount) //dto.Price <= settingPrice && && dto.Quantity <= setting.Quantity
  278. {
  279. isAuto = true;
  280. }
  281. }
  282. }
  283. }
  284. if (isAuto)
  285. {
  286. _sqlSugar.Updateable<Grp_CreditCardPayment>()
  287. .SetColumns(a => new Grp_CreditCardPayment
  288. {
  289. IsAuditGM = 3, //自动审核通过
  290. AuditGMOperate = 4,
  291. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  292. })
  293. .Where(a => a.CId == id && a.CTable == 98 && a.DIId == 2590)
  294. .ExecuteCommand();
  295. }
  296. }
  297. #endregion
  298. CommitTran();
  299. var data = new { ccpId = cId, sign = 1, dataId = id };
  300. return new JsonView() { Code = 200, Msg = "添加成功!", Data = data };
  301. }
  302. RollbackTran();
  303. return new JsonView() { Code = 400, Msg = "添加失败!" };
  304. }
  305. else if (dto.Status == 2)
  306. {
  307. //已审核、已支付 不可修改
  308. 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);
  309. if (grp_CreditCardPayment == null) return new JsonView() { Code = 400, Msg = MsgTips.Fail };
  310. var isAuditGM = grp_CreditCardPayment.IsAuditGM;
  311. if (isAuditGM == 1 || isAuditGM == 3) return new JsonView() { Code = 400, Msg = $"该费用已通过审核,不可编辑" };
  312. if (grp_CreditCardPayment.IsPay == 1) return new JsonView() { Code = 400, Msg = $"该费用已付款,不可编辑!" };
  313. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  314. {
  315. DiId = grp_Decrease.DiId,
  316. SupplierArea = grp_Decrease.SupplierArea,
  317. SupplierTypeId = grp_Decrease.SupplierTypeId,
  318. SupplierName = grp_Decrease.SupplierName,
  319. SupplierContact = grp_Decrease.SupplierContact,
  320. SupplierContactNumber = grp_Decrease.SupplierContactNumber,
  321. SupplierSocialAccount = grp_Decrease.SupplierSocialAccount,
  322. SupplierEmail = grp_Decrease.SupplierEmail,
  323. SupplierAddress = grp_Decrease.SupplierAddress,
  324. PriceName = grp_Decrease.PriceName,
  325. Price = grp_Decrease.Price,
  326. Quantity = grp_Decrease.Quantity,
  327. FeeTotal = grp_Decrease.FeeTotal,
  328. Currency = grp_Decrease.Currency,
  329. FilePath = grp_Decrease.FilePath,
  330. OTAOrderNo = grp_Decrease.OTAOrderNo,
  331. Remark = grp_Decrease.Remark,
  332. });
  333. if (res)
  334. {
  335. if (teamRate != null)
  336. {
  337. if (teamRate.CurrencyCode.Equals("CNY"))
  338. {
  339. grp_CreditCardPayment.DayRate = 1.0000M;
  340. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  341. }
  342. else
  343. {
  344. grp_CreditCardPayment.DayRate = teamRate.Rate;
  345. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  346. }
  347. }
  348. //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
  349. int isPay = 0;
  350. if (dto.PayDId == 72) isPay = 1;
  351. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  352. .Where(a => a.Id == grp_CreditCardPayment.Id)
  353. .SetColumns(a => new Grp_CreditCardPayment
  354. {
  355. OtherSideName = dto.OtherSideName,
  356. OtherSideNo = dto.OtherSideNo,
  357. OtherBankName = dto.OtherBankName,
  358. PayDId = dto.PayDId,
  359. IsPay = isPay,
  360. PayMoney = grp_Decrease.FeeTotal,
  361. PaymentCurrency = grp_Decrease.Currency,
  362. Payee = dto.SupplierName,
  363. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  364. DayRate = grp_CreditCardPayment.DayRate,
  365. RMBPrice = grp_CreditCardPayment.RMBPrice,
  366. //IsAuditGM = auto ? 3 : grp_CreditCardPayment.IsAuditGM
  367. })
  368. .ExecuteCommandAsync();
  369. if (CTable > 0)
  370. {
  371. #region 世运会自动审核处理
  372. if (dto.DiId == 2590)
  373. {
  374. bool isAuto = false;
  375. var spPriceName = dto.PriceName.Split('-').ToArray();
  376. var expression = Expressionable.Create<Grp_GamesBudgetMaster>()
  377. .And(x => x.IsDel == 0);
  378. if (spPriceName.Length >= 2)
  379. {
  380. expression.And(x => x.T0 == spPriceName[0])
  381. .And(x => x.CalculationContent == spPriceName[1]);
  382. var setting = _sqlSugar.Queryable<Grp_GamesBudgetMaster>()
  383. .First(expression.ToExpression());
  384. if (setting != null)
  385. {
  386. var dbList = _sqlSugar.Queryable<Grp_DecreasePayments>()
  387. .LeftJoin<Grp_CreditCardPayment>((x,a) => x.Id == a.CId && a.IsDel == 0 && a.CTable == 98 && a.DIId == dto.DiId )
  388. .Where((x, a) => x.IsDel == 0 && x.PriceName.Contains(spPriceName[0]) && x.PriceName.Contains(spPriceName[1]) && x.Id != dto.Id)
  389. .Select((x, a) => new
  390. {
  391. x,
  392. a.RMBPrice,
  393. })
  394. .ToList();
  395. //币种问题 (836 CNY)
  396. if (dto.Currency != 836)
  397. {
  398. var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  399. if (rate != null)
  400. {
  401. //dto.Price *= rate.Rate;
  402. dto.FeeTotal *= rate.Rate;
  403. }
  404. }
  405. //现有金额
  406. var sumPrice = dbList.Sum(x => x.RMBPrice);
  407. //现有数量
  408. //var sumCount = dbList.Sum(x => x.Quantity);
  409. var availableAmount = setting.ItemTotal - sumPrice;
  410. //var availableQuantity = setting.Quantity - sumCount;
  411. if (availableAmount > 0) // && availableQuantity > 0
  412. {
  413. //单价计算
  414. //var settingPrice = setting.UnitPrice;
  415. //if (int.TryParse(setting.CycleUnit, out int cycleUnit))
  416. //{
  417. // settingPrice *= cycleUnit;
  418. //}
  419. if (dto.FeeTotal <= availableAmount) //dto.Price <= settingPrice && && dto.Quantity <= setting.Quantity
  420. {
  421. isAuto = true;
  422. }
  423. }
  424. }
  425. }
  426. if (isAuto)
  427. {
  428. _sqlSugar.Updateable<Grp_CreditCardPayment>()
  429. .SetColumns(a => new Grp_CreditCardPayment
  430. {
  431. IsAuditGM = 3, //自动审核通过
  432. AuditGMOperate = 4,
  433. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  434. })
  435. .Where(a => a.CId == dto.Id && a.CTable == 98 && a.DIId == 2590)
  436. .ExecuteCommand();
  437. }
  438. }
  439. #endregion
  440. CommitTran();
  441. var data = new { ccpId = grp_CreditCardPayment.Id, sign = 2, dataId = grp_Decrease.Id };
  442. return new JsonView() { Code = 200, Msg = "修改成功!", Data = data };
  443. }
  444. }
  445. }
  446. RollbackTran();
  447. return new JsonView() { Code = 400, Msg = MsgTips.Fail };
  448. }
  449. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  450. {
  451. Result result = new Result() { Code = -2, Msg = "未知错误" };
  452. try
  453. {
  454. #region 团组下拉框
  455. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  456. string DiId = "";
  457. foreach (var item in grp_GroupsTaskAssignment)
  458. {
  459. DiId += item.DIId + ",";
  460. }
  461. if (!string.IsNullOrWhiteSpace(DiId))
  462. {
  463. DiId = DiId.Substring(0, DiId.Length - 1);
  464. }
  465. else
  466. {
  467. DiId = "0";
  468. }
  469. 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);
  470. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  471. if (grp_Delegations.Count != 0)
  472. {
  473. int count = grp_Delegations.Count;
  474. float totalPage = (float)count / dto.PageSize;//总页数
  475. if (totalPage == 0) totalPage = 1;
  476. else totalPage = (int)Math.Ceiling((double)totalPage);
  477. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  478. for (int i = 0; i < dto.PageSize; i++)
  479. {
  480. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  481. if (RowIndex < grp_Delegations.Count)
  482. {
  483. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  484. }
  485. else
  486. {
  487. break;
  488. }
  489. }
  490. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  491. rst.DataList = delegationEasyViews;
  492. rst.DataCount = count;
  493. rst.CurrPageIndex = dto.PageIndex;
  494. rst.CurrPageSize = dto.PageSize;
  495. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  496. }
  497. else
  498. {
  499. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  500. rst.DataList = new List<DelegationEasyView>();
  501. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  502. }
  503. #endregion
  504. }
  505. catch (Exception ex)
  506. {
  507. return result = new Result() { Code = -2, Msg = "程序错误" };
  508. throw;
  509. }
  510. }
  511. /// <summary>
  512. /// 根据团组增减款项表Id查询数据
  513. /// </summary>
  514. /// <param name="dto"></param>
  515. /// <returns></returns>
  516. /// <exception cref="NotImplementedException"></exception>
  517. public async Task<JsonView> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  518. {
  519. string sql = string.Format($@"Select
  520. dp.Id,
  521. dp.DiId,
  522. dp.SupplierArea,
  523. dp.SupplierTypeId,
  524. dp.SupplierName,
  525. dp.SupplierContact,
  526. dp.SupplierContactNumber,
  527. dp.SupplierSocialAccount,
  528. dp.SupplierEmail,
  529. dp.SupplierAddress,
  530. dp.PriceName,
  531. dp.Price,
  532. dp.Quantity,
  533. dp.FeeTotal,
  534. dp.Currency,
  535. dp.FilePath,
  536. dp.OTAOrderNo,
  537. dp.Remark,
  538. ccp.PayDId,
  539. ccp.OrbitalPrivateTransfer,
  540. ccp.OtherBankName,
  541. ccp.OtherSideName,
  542. ccp.OtherSideNo,
  543. ccp.IsAuditGM
  544. From Grp_DecreasePayments dp With(NoLock)
  545. Left Join Grp_CreditCardPayment ccp With(NoLock) On dp.Id = ccp.CId And dp.DiId = ccp.DIId And ccp.CTable = 98
  546. Where dp.IsDel = 0 And dp.Id = {dto.Id}");
  547. var info = await _sqlSugar.SqlQueryable<DecreasePaymentsInfoView>(sql).FirstAsync();
  548. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = info };
  549. }
  550. /// <summary>
  551. /// Del
  552. /// </summary>
  553. /// <param name="dto"></param>
  554. /// <returns></returns>
  555. /// <exception cref="NotImplementedException"></exception>
  556. public async Task<Result> _Del(int id, int userId)
  557. {
  558. Result result = new Result() { Code = -2, Msg = "删除失败!" };
  559. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  560. .FirstAsync(x => x.CId == id && x.CTable == 98 && x.IsDel == 0);
  561. if (ccpInfo == null) return new Result(-2, "数据不存在,不可删除!");
  562. var auditStatus = new List<int>() {
  563. 1, // 已通过
  564. };
  565. if (auditStatus.Any(x => x == ccpInfo.IsAuditGM)) return new Result(-2, "该费用已手动审核,不可删除!");
  566. if (ccpInfo.IsPay == 1) return new Result(-2, "该费用已付款,不可删除!");
  567. _sqlSugar.BeginTran();
  568. var del = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  569. .SetColumns(it => new Grp_DecreasePayments()
  570. {
  571. IsDel = 1,
  572. DeleteUserId = userId,
  573. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  574. }).Where(it => it.Id == id)
  575. .ExecuteCommandAsync();
  576. if (del > 0)
  577. {
  578. var del1 = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  579. .SetColumns(a => new Grp_CreditCardPayment()
  580. {
  581. IsDel = 1,
  582. DeleteUserId = userId,
  583. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  584. })
  585. .Where(a => a.CId == id && a.CTable == 98)
  586. .ExecuteCommandAsync();
  587. if (del1 > 0)
  588. {
  589. _sqlSugar.CommitTran();
  590. result.Code = 0;
  591. result.Msg = "删除成功!";
  592. return result;
  593. }
  594. }
  595. _sqlSugar.RollbackTran();
  596. return result;
  597. }
  598. }
  599. }