DecreasePaymentsRepository.cs 55 KB

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