DecreasePaymentsRepository.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  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 OASystem.Infrastructure.Tools;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Globalization;
  19. using System.Linq;
  20. using System.Runtime.Intrinsics.Arm;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. namespace OASystem.Infrastructure.Repositories.Groups
  24. {
  25. public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
  26. {
  27. private readonly IMapper _mapper;
  28. private readonly TeamRateRepository _teamRateRep;
  29. private readonly SetDataRepository _setDataRepository;
  30. public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper, TeamRateRepository teamRateRep, SetDataRepository setDataRepository)
  31. : base(sqlSugar)
  32. {
  33. this._mapper = mapper;
  34. _teamRateRep = teamRateRep;
  35. this._setDataRepository = setDataRepository;
  36. }
  37. /// <summary>
  38. /// 根据团组Id查询数据
  39. /// </summary>
  40. /// <param name="dto"></param>
  41. /// <returns></returns>
  42. public async Task<JsonView> DecreasePaymentsList(DecreasePaymentsListDto dto)
  43. {
  44. string sqlWhere = "";
  45. if (dto.IsPaySign != -1)
  46. {
  47. sqlWhere += string.Format(@" And ccp.IsPay = {0} ", dto.IsPaySign);
  48. }
  49. // 其他款项-查看团组全部费用UserIds
  50. var permUserIds = new List<int>() {
  51. 400, // 李允
  52. };
  53. var typeIds = new List<int>() {
  54. 302, // 成都-会务活动
  55. 691, // 四川-会务活动
  56. 762, // 四川-赛事项目收入
  57. 1047,// 成都-赛事项目收入
  58. 1539,// 纽茵-会务活动
  59. 1548 // 重庆-会务活动
  60. };
  61. var isSpecialType = await _sqlSugar.Queryable<Grp_DelegationInfo>().AnyAsync(x => x.IsDel == 0 && x.Id == dto.DiId && typeIds.Contains(x.TeamDid));
  62. if (!isSpecialType || !permUserIds.Contains(dto.UserId))
  63. {
  64. sqlWhere += string.Format(@" AND gdp.CreateUserId IN({0})", dto.UserId);
  65. }
  66. //雷怡 2024-5-8 15:14 新增View字段 CreateTime
  67. string sql = string.Format(@"Select gdp.Id,gdp.DiId,
  68. CASE
  69. WHEN gdp.PaymentPercent <> 100
  70. THEN gdp.PriceName
  71. + '('
  72. + gdp.PaymentType
  73. + ')'
  74. -- + ' '
  75. -- + CAST(CAST(gdp.PaymentPercent AS INT) AS VARCHAR(10))
  76. -- + '%)'
  77. ELSE gdp.PriceName
  78. END AS PriceName,
  79. -- gdp.FeeTotal,
  80. gdp.PaymentType,
  81. gdp.PaymentPercent,
  82. gdp.ActualPaymentAmount FeeTotal,
  83. sd1.[Name] as Currency,gdp.FilePath,su.CnName as CreateUserName,ccp.IsAuditGM as isAudit,ccp.IsPay,gdp.CreateTime
  84. From Grp_DecreasePayments as gdp With(Nolock) Left Join Grp_CreditCardPayment as ccp With(Nolock) On gdp.Id = ccp.CId
  85. Left Join Sys_SetData as sd1 On gdp.Currency = sd1.Id
  86. Left Join Sys_Users as su On gdp.CreateUserId = su.Id
  87. Where gdp.DiId = {0} And ccp.CTable = 98 {1} And ccp.IsDel = 0 And gdp.IsDel = 0 ", dto.DiId, sqlWhere);
  88. var _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
  89. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = _DecreasePayments };
  90. }
  91. /// <summary>
  92. /// 获取付款方式配置(STid = 138)
  93. /// </summary>
  94. public async Task<List<PaymentTypeView>> GetPaymentTypesAsync()
  95. {
  96. const int PaymentSettingStId = 138;
  97. var paymentTypes = await _sqlSugar
  98. .Queryable<Sys_SetData>()
  99. .Where(x => x.STid == PaymentSettingStId && x.IsDel == 0)
  100. .ToListAsync();
  101. return paymentTypes.Select(x =>
  102. {
  103. var y = new PaymentTypeView()
  104. {
  105. PaymentType = x.Name,
  106. PaymentPercent = x.Remark.SafeParseDecimal(),
  107. };
  108. return y;
  109. }).ToList();
  110. }
  111. public async Task<JsonView> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  112. {
  113. #region 团组下拉框
  114. var isGm = AppSettingsHelper
  115. .Get<int>("DecreasePaymentsSelectIsGm")
  116. .Contains(dto.UserId);
  117. var _Delegations = new List<DecreasePaymentGroupView>();
  118. if (isGm && dto.CTId != 81)
  119. {
  120. isGm = false;
  121. }
  122. if (!isGm)
  123. {
  124. var grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  125. string DiId = "";
  126. if (grp_GroupsTaskAssignment.Count > 0)
  127. {
  128. foreach (var item in grp_GroupsTaskAssignment)
  129. {
  130. DiId += item.DIId + ",";
  131. }
  132. if (DiId != "0")
  133. {
  134. DiId = DiId.Substring(0, DiId.Length - 1);
  135. }
  136. string sql = string.Format($@"Select
  137. (select ssd.name from Sys_SetData ssd WHERE ssd.id = di.TeamLevSId) as TeamLevSId,
  138. di.Id,
  139. di.TeamName,
  140. di.ClientUnit,
  141. di.ClientName,
  142. di.TourCode,
  143. di.TeamDid,
  144. sd.[Name] As TeamTypeName,
  145. di.VisitCountry,
  146. di.VisitStartDate,
  147. di.VisitEndDate,
  148. di.VisitDays,
  149. di.VisitPNumber,
  150. di.CreateTime
  151. From Grp_DelegationInfo di With(NoLock)
  152. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  153. Where di.Id in({DiId}) and di.IsDel=0
  154. Order By di.VisitStartDate Desc");
  155. _Delegations = _sqlSugar.SqlQueryable<DecreasePaymentGroupView>(sql).ToList();
  156. }
  157. }
  158. else
  159. {
  160. string sql = string.Format($@"Select
  161. (select ssd.name from Sys_SetData ssd WHERE ssd.id = di.TeamLevSId) as TeamLevSId,
  162. di.Id,
  163. di.TeamName,
  164. di.ClientUnit,
  165. di.ClientName,
  166. di.TourCode,
  167. di.TeamDid,
  168. sd.[Name] As TeamTypeName,
  169. di.VisitCountry,
  170. di.VisitStartDate,
  171. di.VisitEndDate,
  172. di.VisitDays,
  173. di.VisitPNumber,
  174. di.CreateTime
  175. From Grp_DelegationInfo di With(NoLock)
  176. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  177. Where di.IsDel=0
  178. Order By di.VisitStartDate Desc");
  179. _Delegations = _sqlSugar.SqlQueryable<DecreasePaymentGroupView>(sql).ToList();
  180. }
  181. #endregion
  182. #region 其他下拉框查询
  183. var setdata = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.IsDel == 0).ToList();
  184. // 支付方式
  185. var payment = setdata.Where(a => a.STid == 14).ToList();
  186. var _payment = _mapper.Map<List<SetDataInfoView>>(payment);
  187. // 供应商
  188. var supplier = setdata.Where(a => a.STid == 21).ToList();
  189. var _supplier = _mapper.Map<List<SetDataInfoView>>(supplier);
  190. if (_supplier.Count > 0)
  191. {
  192. var d1 = _supplier.Find(it => it.Name.Equals("策划 公司"));
  193. if (d1 != null) _supplier.Remove(d1);
  194. var d2 = _supplier.Find(it => it.Name.Equals("礼仪"));
  195. if (d2 != null) _supplier.Remove(d2);
  196. var d3 = _supplier.Find(it => it.Name.Equals("日常办公用品"));
  197. if (d3 != null) _supplier.Remove(d3);
  198. var d4 = _supplier.Find(it => it.Name.Equals("其他"));
  199. if (d4 != null)
  200. {
  201. _supplier.Remove(d4);
  202. _supplier.Add(d4);
  203. }
  204. }
  205. var _supplierArea = new List<dynamic>() {
  206. new { id=1,name = "国内" },
  207. new { id=2,name = "国外" },
  208. };
  209. // 付款方式
  210. var _paymentOptions = await GetPaymentTypesAsync();
  211. #endregion
  212. var data = new
  213. {
  214. payment = _payment,
  215. groupName = _Delegations,
  216. supplier = _supplier,
  217. supplierArea = _supplierArea,
  218. paymentOptions = _paymentOptions,
  219. };
  220. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = data };
  221. }
  222. public async Task<JsonView> OpDecreasePayments(DecreasePaymentsOpDto dto)
  223. {
  224. // 输入验证
  225. if (dto == null) return new JsonView { Code = 400, Msg = "参数不能为空" };
  226. BeginTran();
  227. int id = 0;
  228. var grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  229. var recheck = true;
  230. //处理费用总计
  231. if (grp_Decrease.FeeTotal == 0.00M)
  232. {
  233. grp_Decrease.FeeTotal = grp_Decrease.Quantity * grp_Decrease.Price;
  234. }
  235. // 处理未选择付款类型
  236. if (string.IsNullOrEmpty(dto.PaymentType))
  237. {
  238. grp_Decrease.PaymentType = "全款";
  239. grp_Decrease.PaymentPercent = 100m;
  240. }
  241. // 处理此次 付款金额
  242. grp_Decrease.ActualPaymentAmount = grp_Decrease.FeeTotal * grp_Decrease.PaymentPercent / 100m;
  243. // 获取汇率(复用查询)
  244. var teamRates = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, dto.DiId, 98);
  245. var teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  246. if (teamRate == null)
  247. {
  248. var currencyName = await _sqlSugar.Queryable<Sys_SetData>()
  249. .Where(it => it.IsDel == 0 && it.Id == grp_Decrease.Currency)
  250. .Select(it => it.Name)
  251. .FirstAsync() ?? "";
  252. return new JsonView { Code = 400, Msg = $"添加失败!团组汇率未设置{currencyName}该币种汇率!" };
  253. }
  254. if (dto.Status == 1)//添加
  255. {
  256. id = await AddAsyncReturnId(grp_Decrease);
  257. grp_Decrease.Id = id;
  258. #region C表赋值
  259. var ccp = new Grp_CreditCardPayment
  260. {
  261. PayDId = dto.PayDId,
  262. ConsumptionPatterns = "",
  263. ConsumptionDate = "",
  264. CTDId = 0,
  265. BankNo = "",
  266. CardholderName = "",
  267. PayMoney = grp_Decrease.ActualPaymentAmount,
  268. PaymentCurrency = grp_Decrease.Currency,
  269. CompanyBankNo = "",
  270. OtherBankName = dto.OtherBankName,
  271. OtherSideNo = dto.OtherSideNo,
  272. OtherSideName = dto.OtherSideName,
  273. Remark = "",
  274. CreateUserId = grp_Decrease.CreateUserId,
  275. MFOperator = 0,
  276. MFOperatorDate = "",
  277. IsAuditDM = 0,
  278. AuditDMOperate = 0,
  279. AuditDMDate = "",
  280. IsAuditMF = 0,
  281. AuditMFOperate = 0,
  282. AuditMFDate = "",
  283. IsAuditGM = 0,
  284. AuditGMOperate = 21,
  285. AuditGMDate = "",
  286. DIId = grp_Decrease.DiId,
  287. CId = id,
  288. CTable = 98,
  289. PayPercentage = 100,
  290. PayThenMoney = 0,
  291. PayPercentageOld = 0,
  292. PayThenMoneyOld = 0,
  293. UpdateDate = "",
  294. Payee = dto.SupplierName,
  295. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  296. ExceedBudget = 0,
  297. };
  298. //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
  299. if (ccp.PayDId == 72) ccp.IsPay = 1;
  300. else ccp.IsPay = 0;
  301. if (teamRate.CurrencyCode.Equals("CNY"))
  302. {
  303. ccp.DayRate = 1.0000M;
  304. ccp.RMBPrice = ccp.PayMoney;
  305. }
  306. else
  307. {
  308. ccp.DayRate = teamRate.Rate;
  309. ccp.RMBPrice = ccp.PayMoney * ccp.DayRate;
  310. }
  311. #endregion
  312. int cId = await _sqlSugar.Insertable(ccp).ExecuteReturnIdentityAsync();
  313. if (cId > 1)
  314. {
  315. #region 付款类型为预付款时,添加尾款信息
  316. if (grp_Decrease.PaymentType.Contains("预付款"))
  317. {
  318. var balancePercent = 100m - grp_Decrease.PaymentPercent;
  319. grp_Decrease.PaymentType = "尾款";
  320. grp_Decrease.PaymentPercent = balancePercent;
  321. grp_Decrease.ActualPaymentAmount = grp_Decrease.FeeTotal * balancePercent / 100m;
  322. var balanceId = await AddAsyncReturnId(grp_Decrease);
  323. if (balanceId < 1)
  324. {
  325. RollbackTran();
  326. return new JsonView() { Code = 200, Msg = $"{grp_Decrease.PriceName}尾款信息添加失败!" };
  327. }
  328. ccp.CId = balanceId;
  329. ccp.PayMoney = grp_Decrease.ActualPaymentAmount;
  330. if (teamRate.CurrencyCode.Equals("CNY"))
  331. {
  332. ccp.DayRate = 1.0000M;
  333. ccp.RMBPrice = ccp.PayMoney;
  334. }
  335. else
  336. {
  337. ccp.DayRate = teamRate.Rate;
  338. ccp.RMBPrice = ccp.PayMoney * ccp.DayRate;
  339. }
  340. var balanceCId = await _sqlSugar.Insertable(ccp).ExecuteReturnIdentityAsync();
  341. if (balanceCId < 1)
  342. {
  343. RollbackTran();
  344. return new JsonView() { Code = 200, Msg = $"{grp_Decrease.PriceName}尾款信息添加失败!" };
  345. }
  346. }
  347. #endregion
  348. #region 策划部内容同步添加至资料库
  349. //var userInfo = _sqlSugar.Queryable<Sys_Users>()
  350. // .LeftJoin<Sys_Department>((u,d)=> d.IsDel == 0 && u.DepId == d.Id )
  351. // .Where((u, d) => u.Id == dto.CreateUserId && d.DepName == "策划部" && u.IsDel == 0)
  352. // .First();
  353. //if (userInfo != null)
  354. //{
  355. // Res_MediaSuppliers mediaSuppliersData = new Res_MediaSuppliers
  356. // {
  357. // CreateTime = DateTime.Now,
  358. // CreateUserId = dto.CreateUserId,
  359. // UnitName = dto.SupplierName,
  360. // TypeId = dto.SupplierTypeId,
  361. // UnitAddress = dto.SupplierAddress,
  362. // Contact = dto.SupplierContact,
  363. // Tel = dto.SupplierContactNumber,
  364. // Email = dto.SupplierEmail,
  365. // Privince = dto.SupplierArea == 1 ? "国内" :"国外",
  366. // };
  367. // EncryptionProcessor.EncryptProperties(mediaSuppliersData);
  368. // _sqlSugar.Insertable(mediaSuppliersData).ExecuteCommand();
  369. //}
  370. #endregion
  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 != 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. var execCount = _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 == id && a.CTable == 98 && a.DIId == 2590)
  436. .ExecuteCommand();
  437. recheck = false;
  438. }
  439. }
  440. #endregion
  441. #region 会务成本自动审核处理
  442. var auditRes = await AutoAuditConferenceCostAsync(grp_Decrease, teamRates);
  443. recheck = auditRes.isRecheck;
  444. #endregion
  445. CommitTran();
  446. var data = new { ccpId = cId, sign = 1, dataId = id, recheck };
  447. return new JsonView() { Code = 200, Msg = "添加成功!", Data = data };
  448. }
  449. RollbackTran();
  450. return new JsonView() { Code = 400, Msg = "添加失败!" };
  451. }
  452. else if (dto.Status == 2)
  453. {
  454. // 已审核、已支付 不可修改
  455. 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);
  456. // 修改 付款类型验证 尾款时不能修改为非尾款
  457. var editValid = _sqlSugar.Queryable<Grp_DecreasePayments>()
  458. .Where(a => a.Id == grp_Decrease.Id && a.IsDel == 0)
  459. .Select(a => new
  460. {
  461. a.PaymentType,
  462. a.PaymentPercent,
  463. a.Price,
  464. a.Quantity,
  465. a.PriceName,
  466. a.FeeTotal,
  467. })
  468. .First();
  469. if (editValid.PaymentType.Contains("尾款"))
  470. {
  471. // 原付款类型为尾款时,修改时必须包含尾款且付款比例、价格信息不变
  472. if (!dto.PaymentType.Contains("尾款"))
  473. {
  474. return new JsonView() { Code = 400, Msg = $"尾款信息不可修改为非尾款选项!" };
  475. }
  476. if (editValid.PriceName != dto.PriceName)
  477. {
  478. return new JsonView() { Code = 400, Msg = $"尾款信息的费用名称不可修改,若要修改请前往预付款修改!" };
  479. }
  480. //if (editValid.PriceName != dto.PriceName || editValid.Price != dto.Price || editValid.Quantity != dto.Quantity ||
  481. // editValid.FeeTotal != dto.FeeTotal || editValid.PaymentPercent != dto.PaymentPercent)
  482. //{
  483. // return new JsonView() { Code = 400, Msg = $"尾款信息的价格、数量、费用总计、付款比例不可修改,若要修改请前往预付款修改对应信息!" };
  484. //}
  485. }
  486. if (grp_CreditCardPayment == null) return new JsonView() { Code = 400, Msg = MsgTips.Fail };
  487. var isAuditGM = grp_CreditCardPayment.IsAuditGM;
  488. if (isAuditGM == 1 || isAuditGM == 3) return new JsonView() { Code = 400, Msg = $"该费用已通过审核,不可编辑" };
  489. if (grp_CreditCardPayment.IsPay == 1) return new JsonView() { Code = 400, Msg = $"该费用已付款,不可编辑!" };
  490. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  491. {
  492. DiId = grp_Decrease.DiId,
  493. SupplierArea = grp_Decrease.SupplierArea,
  494. SupplierTypeId = grp_Decrease.SupplierTypeId,
  495. SupplierName = grp_Decrease.SupplierName,
  496. SupplierContact = grp_Decrease.SupplierContact,
  497. SupplierContactNumber = grp_Decrease.SupplierContactNumber,
  498. SupplierSocialAccount = grp_Decrease.SupplierSocialAccount,
  499. SupplierEmail = grp_Decrease.SupplierEmail,
  500. SupplierAddress = grp_Decrease.SupplierAddress,
  501. PriceName = grp_Decrease.PriceName,
  502. Price = grp_Decrease.Price,
  503. Quantity = grp_Decrease.Quantity,
  504. FeeTotal = grp_Decrease.FeeTotal,
  505. PaymentType = grp_Decrease.PaymentType,
  506. PaymentPercent = grp_Decrease.PaymentPercent,
  507. ActualPaymentAmount = grp_Decrease.ActualPaymentAmount,
  508. Currency = grp_Decrease.Currency,
  509. FilePath = grp_Decrease.FilePath,
  510. OTAOrderNo = grp_Decrease.OTAOrderNo,
  511. Remark = grp_Decrease.Remark,
  512. });
  513. if (res)
  514. {
  515. if (teamRate != null)
  516. {
  517. if (teamRate.CurrencyCode.Equals("CNY"))
  518. {
  519. grp_CreditCardPayment.DayRate = 1.0000M;
  520. grp_CreditCardPayment.RMBPrice = grp_Decrease.ActualPaymentAmount;
  521. }
  522. else
  523. {
  524. grp_CreditCardPayment.DayRate = teamRate.Rate;
  525. grp_CreditCardPayment.RMBPrice = grp_Decrease.ActualPaymentAmount * grp_CreditCardPayment.DayRate;
  526. }
  527. }
  528. //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
  529. int isPay = 0;
  530. if (dto.PayDId == 72) isPay = 1;
  531. int cTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  532. .Where(a => a.Id == grp_CreditCardPayment.Id)
  533. .SetColumns(a => new Grp_CreditCardPayment
  534. {
  535. OtherSideName = dto.OtherSideName,
  536. OtherSideNo = dto.OtherSideNo,
  537. OtherBankName = dto.OtherBankName,
  538. PayDId = dto.PayDId,
  539. IsPay = isPay,
  540. PayMoney = grp_Decrease.ActualPaymentAmount,
  541. PaymentCurrency = grp_Decrease.Currency,
  542. Payee = dto.SupplierName,
  543. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  544. DayRate = grp_CreditCardPayment.DayRate,
  545. RMBPrice = grp_CreditCardPayment.RMBPrice,
  546. //IsAuditGM = auto ? 3 : grp_CreditCardPayment.IsAuditGM
  547. })
  548. .ExecuteCommandAsync();
  549. if (cTable > 0)
  550. {
  551. #region 付款类型为预付款时,添加尾款信息
  552. if (grp_Decrease.PaymentType.Contains("预付款"))
  553. {
  554. // 检查尾款信息是否存在,存在则更新,不存在则添加
  555. var balanceInfo = await _sqlSugar.Queryable<Grp_DecreasePayments>()
  556. .Where(x => x.DiId == grp_Decrease.DiId && x.PriceName == grp_Decrease.PriceName && x.PaymentType.Contains("尾款") && x.IsDel == 0)
  557. .FirstAsync();
  558. var balancePercent = 100m - grp_Decrease.PaymentPercent;
  559. var paymentTypeName = "尾款";
  560. var paymentPercent = balancePercent;
  561. var actualPaymentAmount = grp_Decrease.FeeTotal * balancePercent / 100m;
  562. if (balanceInfo != null) // 更新尾款信息
  563. {
  564. bool balanceRes = await UpdateAsync(a => a.Id == balanceInfo.Id, a => new Grp_DecreasePayments
  565. {
  566. DiId = grp_Decrease.DiId,
  567. SupplierArea = grp_Decrease.SupplierArea,
  568. SupplierTypeId = grp_Decrease.SupplierTypeId,
  569. SupplierName = grp_Decrease.SupplierName,
  570. SupplierContact = grp_Decrease.SupplierContact,
  571. SupplierContactNumber = grp_Decrease.SupplierContactNumber,
  572. SupplierSocialAccount = grp_Decrease.SupplierSocialAccount,
  573. SupplierEmail = grp_Decrease.SupplierEmail,
  574. SupplierAddress = grp_Decrease.SupplierAddress,
  575. PriceName = grp_Decrease.PriceName,
  576. Price = grp_Decrease.Price,
  577. Quantity = grp_Decrease.Quantity,
  578. FeeTotal = grp_Decrease.FeeTotal,
  579. PaymentType = paymentTypeName,
  580. PaymentPercent = paymentPercent,
  581. ActualPaymentAmount = actualPaymentAmount,
  582. Currency = grp_Decrease.Currency,
  583. FilePath = grp_Decrease.FilePath,
  584. OTAOrderNo = grp_Decrease.OTAOrderNo,
  585. Remark = grp_Decrease.Remark,
  586. });
  587. if (!balanceRes)
  588. {
  589. RollbackTran();
  590. return new JsonView() { Code = 200, Msg = $"{grp_Decrease.PriceName}尾款信息更新失败!" };
  591. }
  592. var DayRate = 0.00m;
  593. var RMBPrice = 0.00m;
  594. if (teamRate != null)
  595. {
  596. if (teamRate.CurrencyCode.Equals("CNY"))
  597. {
  598. DayRate = 1.0000M;
  599. RMBPrice = actualPaymentAmount;
  600. }
  601. else
  602. {
  603. DayRate = teamRate.Rate;
  604. RMBPrice = actualPaymentAmount * DayRate;
  605. }
  606. }
  607. int balanceCTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  608. .Where(a => a.DIId == balanceInfo.DiId && a.CTable == 98 && a.CId == balanceInfo.Id)
  609. .SetColumns(a => new Grp_CreditCardPayment
  610. {
  611. OtherSideName = dto.OtherSideName,
  612. OtherSideNo = dto.OtherSideNo,
  613. OtherBankName = dto.OtherBankName,
  614. PayDId = dto.PayDId,
  615. IsPay = isPay,
  616. PayMoney = actualPaymentAmount,
  617. PaymentCurrency = grp_Decrease.Currency,
  618. Payee = dto.SupplierName,
  619. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  620. DayRate = DayRate,
  621. RMBPrice = RMBPrice,
  622. })
  623. .ExecuteCommandAsync();
  624. if (balanceCTable < 1)
  625. {
  626. RollbackTran();
  627. return new JsonView() { Code = 200, Msg = $"{grp_Decrease.PriceName}尾款信息更新失败!" };
  628. }
  629. }
  630. else // 添加尾款信息
  631. {
  632. grp_Decrease.PaymentType = paymentTypeName;
  633. grp_Decrease.PaymentPercent = paymentPercent;
  634. grp_Decrease.ActualPaymentAmount = actualPaymentAmount;
  635. var balanceId = await AddAsyncReturnId(grp_Decrease);
  636. if (balanceId < 1)
  637. {
  638. RollbackTran();
  639. return new JsonView() { Code = 200, Msg = $"{grp_Decrease.PriceName}尾款信息添加失败!" };
  640. }
  641. grp_CreditCardPayment.CId = balanceId;
  642. grp_CreditCardPayment.PayMoney = grp_Decrease.ActualPaymentAmount;
  643. if (teamRate.CurrencyCode.Equals("CNY"))
  644. {
  645. grp_CreditCardPayment.DayRate = 1.0000M;
  646. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  647. }
  648. else
  649. {
  650. grp_CreditCardPayment.DayRate = teamRate.Rate;
  651. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  652. }
  653. var balanceCId = await _sqlSugar.Insertable(grp_CreditCardPayment).ExecuteReturnIdentityAsync();
  654. if (balanceCId < 1)
  655. {
  656. RollbackTran();
  657. return new JsonView() { Code = 200, Msg = $"{grp_Decrease.PriceName}尾款信息添加失败!" };
  658. }
  659. }
  660. }
  661. // 付款类型更改为全款时,删除同名称尾款信息
  662. if (grp_Decrease.PaymentType.Contains("全款"))
  663. {
  664. var balanceInfo = await _sqlSugar.Queryable<Grp_DecreasePayments>()
  665. .Where(x => x.DiId == grp_Decrease.DiId && x.PriceName == grp_Decrease.PriceName && x.PaymentType.Contains("尾款") && x.IsDel == 0)
  666. .FirstAsync();
  667. if (balanceInfo != null) {
  668. bool balanceRes = await UpdateAsync(a => a.Id == balanceInfo.Id,
  669. a => new Grp_DecreasePayments
  670. {
  671. IsDel = 1,
  672. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  673. DeleteUserId = dto.CreateUserId,
  674. Remark = $"{balanceInfo.Remark};由预付款更改为全款时,自动删除:{grp_Decrease.PriceName}尾款信息"
  675. });
  676. int balanceCTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  677. .Where(a => a.DIId == balanceInfo.DiId && a.CTable == 98 && a.CId == balanceInfo.Id)
  678. .SetColumns(a => new Grp_CreditCardPayment
  679. {
  680. IsDel = 1,
  681. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  682. DeleteUserId = dto.CreateUserId,
  683. Remark = $"{balanceInfo.Remark};由预付款更改为全款时,自动删除:{grp_Decrease.PriceName}尾款信息"
  684. })
  685. .ExecuteCommandAsync();
  686. }
  687. }
  688. #endregion
  689. #region 世运会自动审核处理
  690. if (dto.DiId == 2590)
  691. {
  692. bool isAuto = false;
  693. string[] spPriceName = dto.PriceName.Split('-').ToArray();
  694. var expression = Expressionable.Create<Grp_GamesBudgetMaster>()
  695. .And(x => x.IsDel == 0);
  696. if (spPriceName.Length >= 2)
  697. {
  698. expression.And(x => x.T0 == spPriceName[0])
  699. .And(x => x.CalculationContent == spPriceName[1]);
  700. var setting = _sqlSugar.Queryable<Grp_GamesBudgetMaster>()
  701. .First(expression.ToExpression());
  702. if (setting != null)
  703. {
  704. var dbList = _sqlSugar.Queryable<Grp_DecreasePayments>()
  705. .LeftJoin<Grp_CreditCardPayment>((x, a) => x.Id == a.CId && a.IsDel == 0 && a.CTable == 98 && a.DIId == dto.DiId)
  706. .Where((x, a) => x.IsDel == 0 && x.PriceName.Contains(spPriceName[0]) && x.PriceName.Contains(spPriceName[1]) && x.Id != dto.Id)
  707. .Select((x, a) => new
  708. {
  709. x,
  710. a.RMBPrice,
  711. })
  712. .ToList();
  713. //币种问题 (836 CNY)
  714. if (dto.Currency != 836)
  715. {
  716. var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  717. if (rate != null)
  718. {
  719. //dto.Price *= rate.Rate;
  720. dto.FeeTotal *= rate.Rate;
  721. }
  722. }
  723. //现有金额
  724. var sumPrice = dbList.Sum(x => x.RMBPrice);
  725. //现有数量
  726. //var sumCount = dbList.Sum(x => x.Quantity);
  727. var availableAmount = setting.ItemTotal - sumPrice;
  728. //var availableQuantity = setting.Quantity - sumCount;
  729. if (availableAmount > 0) // && availableQuantity > 0
  730. {
  731. //单价计算
  732. //var settingPrice = setting.UnitPrice;
  733. //if (int.TryParse(setting.CycleUnit, out int cycleUnit))
  734. //{
  735. // settingPrice *= cycleUnit;
  736. //}
  737. if (dto.FeeTotal <= availableAmount) //dto.Price <= settingPrice && && dto.Quantity <= setting.Quantity
  738. {
  739. isAuto = true;
  740. }
  741. }
  742. }
  743. }
  744. if (isAuto)
  745. {
  746. _sqlSugar.Updateable<Grp_CreditCardPayment>()
  747. .SetColumns(a => new Grp_CreditCardPayment
  748. {
  749. IsAuditGM = 3, //自动审核通过
  750. AuditGMOperate = 4,
  751. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  752. })
  753. .Where(a => a.CId == dto.Id && a.CTable == 98 && a.DIId == 2590)
  754. .ExecuteCommand();
  755. recheck = false;
  756. }
  757. }
  758. #endregion
  759. #region 会务成本自动审核处理
  760. var auditRes = await AutoAuditConferenceCostAsync(grp_Decrease, teamRates);
  761. recheck = auditRes.isRecheck;
  762. #endregion
  763. CommitTran();
  764. var data = new { ccpId = grp_CreditCardPayment.Id, sign = 2, dataId = grp_Decrease.Id, recheck };
  765. return new JsonView() { Code = 200, Msg = "修改成功!", Data = data };
  766. }
  767. }
  768. }
  769. RollbackTran();
  770. return new JsonView() { Code = 400, Msg = MsgTips.Fail };
  771. }
  772. /// <summary>
  773. /// 会务成本自动审核
  774. /// </summary>
  775. /// <param name="paymentInfo"></param>
  776. /// <param name="teamRates"></param>
  777. /// <returns></returns>
  778. private async Task<(bool isAudit, bool isRecheck)> AutoAuditConferenceCostAsync(Grp_DecreasePayments paymentInfo, List<TeamRateDescAddCurrencyIdView> teamRates)
  779. {
  780. var hwids = _sqlSugar.Queryable<Sys_SetData>()
  781. .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
  782. .Select(x => x.Id)
  783. .ToList();
  784. var groupTypeIsTrue = _sqlSugar.Queryable<Grp_DelegationInfo>()
  785. .Where(x => x.Id == paymentInfo.DiId && x.IsDel == 0)
  786. .Any(x => hwids.Contains(x.TeamDid));
  787. if (groupTypeIsTrue)
  788. {
  789. var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>().First(x => x.Diid == paymentInfo.DiId && x.IsDel == 0);
  790. if (main != null)
  791. {
  792. var chiArr = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  793. .Where(x => x.Diid == paymentInfo.DiId && x.ConferenceAffairsCostId == main.Id && x.IsDel == 0)
  794. .ToList();
  795. var find = chiArr.FirstOrDefault(x => x.PriceName == paymentInfo.PriceName && x.ReviewStatus == 1);
  796. var isAuto = false;
  797. //存在已审的会务成本
  798. if (find != null)
  799. {
  800. //检索历史金额
  801. var histyPrice = _sqlSugar.Queryable<Grp_DecreasePayments>()
  802. .LeftJoin<Grp_CreditCardPayment>((x, a) => a.IsDel == 0 && a.CTable == 98 && a.CId == x.Id)
  803. .Where((x, a) => x.IsDel == 0 && x.DiId == paymentInfo.DiId && x.PriceName == paymentInfo.PriceName &&
  804. !x.PaymentType.Contains("尾款") && x.Id != paymentInfo.Id)
  805. .Select((x, a) => new
  806. {
  807. x.FeeTotal,
  808. x.Currency,
  809. a.DayRate,
  810. a.RMBPrice,
  811. x.DiId,
  812. x.PriceName,
  813. x.Price,
  814. x.Quantity,
  815. })
  816. .ToList();
  817. //币种全转换为人民币
  818. var rate = teamRates.Where(it => it.CurrencyId == paymentInfo.Currency).FirstOrDefault();
  819. if (rate != null)
  820. {
  821. paymentInfo.FeeTotal *= rate.Rate;
  822. }
  823. var ConferenceAffairsCostFeeTotal = 0.00M;
  824. ConferenceAffairsCostFeeTotal = find.Count * find.CostPrice * find.Rate;
  825. var histyPriceValue = histyPrice.Sum(x => x.FeeTotal * x.DayRate);
  826. if (ConferenceAffairsCostFeeTotal > histyPriceValue)
  827. {
  828. isAuto = ConferenceAffairsCostFeeTotal - histyPriceValue >= paymentInfo.FeeTotal;
  829. }
  830. }
  831. if (isAuto)
  832. {
  833. var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  834. .SetColumns(a => new Grp_CreditCardPayment
  835. {
  836. IsAuditGM = 3, //自动审核通过
  837. AuditGMOperate = 4,
  838. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  839. })
  840. .Where(a => a.CId == paymentInfo.Id && a.CTable == 98 && a.DIId == paymentInfo.DiId)
  841. .ExecuteCommand();
  842. // 处理尾款审核
  843. var balanceAuditInfo = _sqlSugar.Queryable<Grp_DecreasePayments>()
  844. .Where(x => x.DiId == paymentInfo.DiId && x.IsDel == 0 && x.PriceName == paymentInfo.PriceName && x.PaymentType.Contains("尾款"))
  845. .First();
  846. if (balanceAuditInfo != null)
  847. {
  848. var balanceAudit = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  849. .SetColumns(a => new Grp_CreditCardPayment
  850. {
  851. IsAuditGM = 3, //自动审核通过
  852. AuditGMOperate = 4,
  853. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  854. })
  855. .Where(a => a.CId == balanceAuditInfo.Id && a.CTable == 98 && a.DIId == balanceAuditInfo.DiId)
  856. .ExecuteCommand();
  857. }
  858. return (true, false);
  859. }
  860. }
  861. }
  862. return (false,true);
  863. }
  864. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  865. {
  866. Result result = new Result() { Code = -2, Msg = "未知错误" };
  867. try
  868. {
  869. #region 团组下拉框
  870. var grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  871. string DiId = "";
  872. foreach (var item in grp_GroupsTaskAssignment)
  873. {
  874. DiId += item.DIId + ",";
  875. }
  876. if (!string.IsNullOrWhiteSpace(DiId))
  877. {
  878. DiId = DiId.Substring(0, DiId.Length - 1);
  879. }
  880. else
  881. {
  882. DiId = "0";
  883. }
  884. 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);
  885. var grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  886. if (grp_Delegations.Count != 0)
  887. {
  888. int count = grp_Delegations.Count;
  889. float totalPage = (float)count / dto.PageSize;//总页数
  890. if (totalPage == 0) totalPage = 1;
  891. else totalPage = (int)Math.Ceiling((double)totalPage);
  892. var delegationEasyViews = new List<DelegationEasyView>();
  893. for (int i = 0; i < dto.PageSize; i++)
  894. {
  895. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  896. if (RowIndex < grp_Delegations.Count)
  897. {
  898. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  899. }
  900. else
  901. {
  902. break;
  903. }
  904. }
  905. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  906. rst.DataList = delegationEasyViews;
  907. rst.DataCount = count;
  908. rst.CurrPageIndex = dto.PageIndex;
  909. rst.CurrPageSize = dto.PageSize;
  910. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  911. }
  912. else
  913. {
  914. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  915. rst.DataList = new List<DelegationEasyView>();
  916. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  917. }
  918. #endregion
  919. }
  920. catch (Exception ex)
  921. {
  922. return result = new Result() { Code = -2, Msg = "程序错误" };
  923. }
  924. }
  925. /// <summary>
  926. /// 根据团组增减款项表Id查询数据
  927. /// </summary>
  928. /// <param name="dto"></param>
  929. /// <returns></returns>
  930. /// <exception cref="NotImplementedException"></exception>
  931. public async Task<JsonView> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  932. {
  933. string sql = string.Format($@"Select
  934. dp.Id,
  935. dp.DiId,
  936. dp.SupplierArea,
  937. dp.SupplierTypeId,
  938. dp.SupplierName,
  939. dp.SupplierContact,
  940. dp.SupplierContactNumber,
  941. dp.SupplierSocialAccount,
  942. dp.SupplierEmail,
  943. dp.SupplierAddress,
  944. dp.PriceName,
  945. dp.Price,
  946. dp.Quantity,
  947. dp.FeeTotal,
  948. dp.PaymentType,
  949. dp.PaymentPercent,
  950. dp.ActualPaymentAmount,
  951. dp.Currency,
  952. dp.FilePath,
  953. dp.OTAOrderNo,
  954. dp.Remark,
  955. ccp.PayDId,
  956. ccp.OrbitalPrivateTransfer,
  957. ccp.OtherBankName,
  958. ccp.OtherSideName,
  959. ccp.OtherSideNo,
  960. ccp.IsAuditGM
  961. From Grp_DecreasePayments dp With(NoLock)
  962. Left Join Grp_CreditCardPayment ccp With(NoLock) On dp.Id = ccp.CId And dp.DiId = ccp.DIId And ccp.CTable = 98
  963. Where dp.IsDel = 0 And dp.Id = {dto.Id}");
  964. var info = await _sqlSugar.SqlQueryable<DecreasePaymentsInfoView>(sql).FirstAsync();
  965. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = info };
  966. }
  967. /// <summary>
  968. /// Del
  969. /// </summary>
  970. /// <param name="dto"></param>
  971. /// <returns></returns>
  972. /// <exception cref="NotImplementedException"></exception>
  973. public async Task<Result> _Del(int id, int userId)
  974. {
  975. Result result = new Result() { Code = -2, Msg = "删除失败!" };
  976. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  977. .FirstAsync(x => x.CId == id && x.CTable == 98 && x.IsDel == 0);
  978. if (ccpInfo == null) return new Result(-2, "数据不存在,不可删除!");
  979. var auditStatus = new List<int>() {
  980. 1, // 已通过
  981. };
  982. if (auditStatus.Any(x => x == ccpInfo.IsAuditGM)) return new Result(-2, "该费用已审核,不可删除!");
  983. if (ccpInfo.IsPay == 1) return new Result(-2, "该费用已付款,不可删除!");
  984. _sqlSugar.BeginTran();
  985. var del = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  986. .SetColumns(it => new Grp_DecreasePayments()
  987. {
  988. IsDel = 1,
  989. DeleteUserId = userId,
  990. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  991. }).Where(it => it.Id == id)
  992. .ExecuteCommandAsync();
  993. if (del > 0)
  994. {
  995. var del1 = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  996. .SetColumns(a => new Grp_CreditCardPayment()
  997. {
  998. IsDel = 1,
  999. DeleteUserId = userId,
  1000. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  1001. })
  1002. .Where(a => a.CId == id && a.CTable == 98)
  1003. .ExecuteCommandAsync();
  1004. if (del1 > 0)
  1005. {
  1006. _sqlSugar.CommitTran();
  1007. result.Code = 0;
  1008. result.Msg = "删除成功!";
  1009. return result;
  1010. }
  1011. }
  1012. _sqlSugar.RollbackTran();
  1013. return result;
  1014. }
  1015. }
  1016. }