| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895 | 
							- using AutoMapper;
 
- using NPOI.HPSF;
 
- using NPOI.SS.Formula.Functions;
 
- using OASystem.Domain;
 
- using OASystem.Domain.AesEncryption;
 
- using OASystem.Domain.Dtos.Groups;
 
- using OASystem.Domain.Entities.Financial;
 
- using OASystem.Domain.Entities.Groups;
 
- using OASystem.Domain.Entities.Resource;
 
- using OASystem.Domain.ViewModels.Financial;
 
- using OASystem.Domain.ViewModels.Groups;
 
- using OASystem.Domain.ViewModels.QiYeWeChat;
 
- using OASystem.Domain.ViewModels.Resource;
 
- using OASystem.Infrastructure.Repositories.System;
 
- using OASystem.Infrastructure.Tools;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Runtime.Intrinsics.Arm;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- namespace OASystem.Infrastructure.Repositories.Groups
 
- {
 
-     public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
 
-     {
 
-         private readonly IMapper _mapper;
 
-         private readonly TeamRateRepository _teamRateRep;
 
-         private readonly SetDataRepository _setDataRepository;
 
-         public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper, TeamRateRepository teamRateRep, SetDataRepository setDataRepository)
 
-             : base(sqlSugar)
 
-         {
 
-             this._mapper = mapper;
 
-             _teamRateRep = teamRateRep;
 
-             this._setDataRepository = setDataRepository;
 
-         }
 
-         /// <summary>
 
-         /// 根据团组Id查询数据
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         public async Task<JsonView> DecreasePaymentsList(DecreasePaymentsListDto dto)
 
-         {
 
-             string sqlWhere = "";
 
-             if (dto.IsPaySign != -1)
 
-             {
 
-                 sqlWhere += string.Format(@" And ccp.IsPay = {0} ", dto.IsPaySign);
 
-             }
 
-             //雷怡 2024-5-8 15:14 新增View字段 CreateTime
 
-             string sql = string.Format(@" Select gdp.Id,gdp.DiId,gdp.PriceName,gdp.FeeTotal,sd1.[Name] as Currency,gdp.FilePath,su.CnName as CreateUserName,
 
-                                               ccp.IsAuditGM as isAudit,ccp.IsPay,gdp.CreateTime
 
-                                               From Grp_DecreasePayments as gdp With(Nolock) Left Join Grp_CreditCardPayment as ccp With(Nolock) On gdp.Id = ccp.CId
 
-                                               Left Join Sys_SetData as sd1 On gdp.Currency = sd1.Id
 
-                                               Left Join Sys_Users as su On gdp.CreateUserId = su.Id
 
-                                               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);
 
-             List<DecreasePaymentsView> _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
 
-             return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = _DecreasePayments };
 
-         }
 
-         public async Task<JsonView> DecreasePaymentsSelect(DecreasePaymentsDto dto)
 
-         {
 
-             #region 团组下拉框
 
-             var isGm = AppSettingsHelper
 
-                         .Get<int>("DecreasePaymentsSelectIsGm")
 
-                         .Contains(dto.UserId);
 
-             List<DecreasePaymentGroupView> _Delegations = new List<DecreasePaymentGroupView>();
 
-             if (isGm && dto.CTId != 81)
 
-             {
 
-                 isGm = false;
 
-             }
 
-             if (!isGm)
 
-             {
 
-                 List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
 
-                 string DiId = "";
 
-                 if (grp_GroupsTaskAssignment.Count > 0)
 
-                 {
 
-                     foreach (var item in grp_GroupsTaskAssignment)
 
-                     {
 
-                         DiId += item.DIId + ",";
 
-                     }
 
-                     if (DiId != "0")
 
-                     {
 
-                         DiId = DiId.Substring(0, DiId.Length - 1);
 
-                     }
 
-                     string sql = string.Format($@"Select 
 
-                                         (select ssd.name from Sys_SetData ssd  WHERE  ssd.id  = di.TeamLevSId) as TeamLevSId,
 
-                                         di.Id,
 
- 										di.TeamName,
 
- 										di.ClientUnit,
 
- 										di.ClientName,
 
- 										di.TourCode,
 
- 										di.TeamDid,
 
- 										sd.[Name] As TeamTypeName,
 
- 										di.VisitCountry,
 
- 										di.VisitStartDate,
 
- 										di.VisitEndDate,
 
- 										di.VisitDays,
 
- 										di.VisitPNumber,
 
- 										di.CreateTime
 
- 										From Grp_DelegationInfo di With(NoLock)
 
- 										Left Join Sys_SetData sd On di.TeamDid = sd.Id
 
-                                         Where di.Id in({DiId}) and di.IsDel=0 
 
- 										Order By di.VisitStartDate Desc");
 
-                     _Delegations = _sqlSugar.SqlQueryable<DecreasePaymentGroupView>(sql).ToList();
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 string sql = string.Format($@"Select 
 
-                                         (select ssd.name from Sys_SetData ssd  WHERE  ssd.id  = di.TeamLevSId) as TeamLevSId,
 
-                                         di.Id,
 
- 										di.TeamName,
 
- 										di.ClientUnit,
 
- 										di.ClientName,
 
- 										di.TourCode,
 
- 										di.TeamDid,
 
- 										sd.[Name] As TeamTypeName,
 
- 										di.VisitCountry,
 
- 										di.VisitStartDate,
 
- 										di.VisitEndDate,
 
- 										di.VisitDays,
 
- 										di.VisitPNumber,
 
- 										di.CreateTime
 
- 										From Grp_DelegationInfo di With(NoLock)
 
- 										Left Join Sys_SetData sd On di.TeamDid = sd.Id
 
-                                         Where di.IsDel=0 
 
- 										Order By di.VisitStartDate Desc");
 
-                 _Delegations = _sqlSugar.SqlQueryable<DecreasePaymentGroupView>(sql).ToList();
 
-             }
 
-             #endregion
 
-             #region 其他下拉框查询
 
-             //支付方式
 
-             List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
 
-             List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
 
-             //供应商 supplier
 
-             List<Sys_SetData> supplier = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 21 && a.IsDel == 0).ToList();
 
-             List<SetDataInfoView> _supplier = _mapper.Map<List<SetDataInfoView>>(supplier);
 
-             if (_supplier.Count > 0)
 
-             {
 
-                 var d1 = _supplier.Find(it => it.Name.Equals("策划 公司"));
 
-                 if (d1 != null) _supplier.Remove(d1);
 
-                 var d2 = _supplier.Find(it => it.Name.Equals("礼仪"));
 
-                 if (d2 != null) _supplier.Remove(d2);
 
-                 var d3 = _supplier.Find(it => it.Name.Equals("日常办公用品"));
 
-                 if (d3 != null) _supplier.Remove(d3);
 
-                 var d4 = _supplier.Find(it => it.Name.Equals("其他"));
 
-                 if (d4 != null)
 
-                 {
 
-                     _supplier.Remove(d4);
 
-                     _supplier.Add(d4);
 
-                 }
 
-             }
 
-             List<dynamic> _supplierArea = new List<dynamic>() {
 
-                 new { id=1,name = "国内" },
 
-                 new { id=2,name = "国外" },
 
-             };
 
-             #endregion
 
-             var data = new
 
-             {
 
-                 payment = _Payment,
 
-                 groupName = _Delegations,
 
-                 supplier = _supplier,
 
-                 supplierArea = _supplierArea
 
-             };
 
-             return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = data };
 
-         }
 
-         public async Task<JsonView> OpDecreasePayments(DecreasePaymentsOpDto dto)
 
-         {
 
-             BeginTran();
 
-             int id = 0;
 
-             var grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
 
-             var recheck = true;
 
-             //处理费用总计
 
-             if (grp_Decrease.FeeTotal == 0.00M)
 
-             {
 
-                 grp_Decrease.FeeTotal = grp_Decrease.Price * grp_Decrease.Price;
 
-             }
 
-             List<TeamRateDescAddCurrencyIdView> teamRates = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, dto.DiId, 98);
 
-             var teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
 
-             if (teamRate == null)
 
-             {
 
-                 return new JsonView() { Code = 400, Msg = $"添加失败!团组汇率未设置{_sqlSugar.Queryable<Sys_SetData>().First(it => it.IsDel == 0 && it.Id == grp_Decrease.Currency)?.Name ?? ""}该币种汇率!" };
 
-             }
 
-             if (dto.Status == 1)//添加
 
-             {
 
-                 id = await AddAsyncReturnId(grp_Decrease);
 
-                 grp_Decrease.Id = id;
 
-                 #region C表赋值
 
-                 Grp_CreditCardPayment C = new Grp_CreditCardPayment();
 
-                 C.PayDId = dto.PayDId;
 
-                 C.ConsumptionPatterns = "";
 
-                 C.ConsumptionDate = "";
 
-                 C.CTDId = 0;
 
-                 C.BankNo = "";
 
-                 C.CardholderName = "";
 
-                 C.PayMoney = grp_Decrease.FeeTotal;
 
-                 C.PaymentCurrency = grp_Decrease.Currency;
 
-                 C.CompanyBankNo = "";
 
-                 C.OtherBankName = dto.OtherBankName;
 
-                 C.OtherSideNo = dto.OtherSideNo;
 
-                 C.OtherSideName = dto.OtherSideName;
 
-                 C.Remark = "";
 
-                 C.CreateUserId = grp_Decrease.CreateUserId;
 
-                 C.MFOperator = 0;
 
-                 C.MFOperatorDate = "";
 
-                 C.IsAuditDM = 0;
 
-                 C.AuditDMOperate = 0;
 
-                 C.AuditDMDate = "";
 
-                 C.IsAuditMF = 0;
 
-                 C.AuditMFOperate = 0;
 
-                 C.AuditMFDate = "";
 
-                 C.IsAuditGM = 0;
 
-                 C.AuditGMOperate = 21;
 
-                 C.AuditGMDate = "";
 
-                 //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
 
-                 if (C.PayDId == 72) C.IsPay = 1;
 
-                 else C.IsPay = 0;
 
-                 C.DIId = grp_Decrease.DiId;
 
-                 C.CId = id;
 
-                 C.CTable = 98;
 
-                 C.PayPercentage = 100;
 
-                 C.PayThenMoney = 0;
 
-                 C.PayPercentageOld = 0;
 
-                 C.PayThenMoneyOld = 0;
 
-                 C.UpdateDate = "";
 
-                 C.Payee = dto.SupplierName;
 
-                 C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
 
-                 C.ExceedBudget = 0;
 
-                 //C.RMBPrice = 0.00f;
 
-                 if (teamRate.CurrencyCode.Equals("CNY"))
 
-                 {
 
-                     C.DayRate = 1.0000M;
 
-                     C.RMBPrice = C.PayMoney;
 
-                 }
 
-                 else
 
-                 {
 
-                     C.DayRate = teamRate.Rate;
 
-                     C.RMBPrice = C.PayMoney * C.DayRate;
 
-                 }
 
-                 #endregion 
 
-                 int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
 
-                 if (cId > 1)
 
-                 {
 
-                     #region 策划部内容同步添加至资料库
 
-                     //var userInfo = _sqlSugar.Queryable<Sys_Users>()
 
-                     //    .LeftJoin<Sys_Department>((u,d)=> d.IsDel == 0 && u.DepId == d.Id )
 
-                     //    .Where((u, d) => u.Id == dto.CreateUserId && d.DepName == "策划部" && u.IsDel == 0)
 
-                     //    .First();
 
-                     //if (userInfo != null)
 
-                     //{
 
-                     //    Res_MediaSuppliers mediaSuppliersData = new Res_MediaSuppliers
 
-                     //    {
 
-                     //        CreateTime = DateTime.Now,
 
-                     //        CreateUserId = dto.CreateUserId,
 
-                     //        UnitName = dto.SupplierName,
 
-                     //        TypeId = dto.SupplierTypeId,
 
-                     //        UnitAddress = dto.SupplierAddress,
 
-                     //        Contact = dto.SupplierContact,
 
-                     //        Tel = dto.SupplierContactNumber,
 
-                     //        Email = dto.SupplierEmail,
 
-                     //        Privince = dto.SupplierArea == 1 ? "国内" :"国外",
 
-                     //    };
 
-                     //    EncryptionProcessor.EncryptProperties(mediaSuppliersData);
 
-                     //    _sqlSugar.Insertable(mediaSuppliersData).ExecuteCommand();
 
-                     //}
 
-                     #endregion
 
-                     #region 世运会自动审核处理
 
-                     if (dto.DiId == 2590)
 
-                     {
 
-                         bool isAuto = false;
 
-                         var spPriceName = dto.PriceName.Split('-').ToArray();
 
-                         var expression = Expressionable.Create<Grp_GamesBudgetMaster>()
 
-                                                         .And(x => x.IsDel == 0);
 
-                         if (spPriceName.Length >= 2)
 
-                         {
 
-                             expression.And(x => x.T0 == spPriceName[0])
 
-                                       .And(x => x.CalculationContent == spPriceName[1]);
 
-                             var setting = _sqlSugar.Queryable<Grp_GamesBudgetMaster>()
 
-                                                     .First(expression.ToExpression());
 
-                             if (setting != null)
 
-                             {
 
-                                 var dbList = _sqlSugar.Queryable<Grp_DecreasePayments>()
 
-                                             .LeftJoin<Grp_CreditCardPayment>((x, a) => x.Id == a.CId && a.IsDel == 0 && a.CTable == 98 && a.DIId == dto.DiId)
 
-                                             .Where((x, a) => x.IsDel == 0 && x.PriceName.Contains(spPriceName[0]) && x.PriceName.Contains(spPriceName[1]) && x.Id != id)
 
-                                             .Select((x, a) => new
 
-                                             {
 
-                                                 x,
 
-                                                 a.RMBPrice,
 
-                                             })
 
-                                             .ToList();
 
-                                 //币种问题 (836 CNY)
 
-                                 if (dto.Currency != 836)
 
-                                 {
 
-                                     var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
 
-                                     if (rate != null)
 
-                                     {
 
-                                         //dto.Price *= rate.Rate;
 
-                                         dto.FeeTotal *= rate.Rate;
 
-                                     }
 
-                                 }
 
-                                 //现有金额
 
-                                 var sumPrice = dbList.Sum(x => x.RMBPrice);
 
-                                 //现有数量
 
-                                 //var sumCount = dbList.Sum(x => x.Quantity);
 
-                                 var availableAmount = setting.ItemTotal - sumPrice;
 
-                                 //var availableQuantity = setting.Quantity - sumCount;
 
-                                 if (availableAmount > 0)  // && availableQuantity > 0
 
-                                 {
 
-                                     //单价计算
 
-                                     //var settingPrice = setting.UnitPrice;
 
-                                     //if (int.TryParse(setting.CycleUnit, out int cycleUnit))
 
-                                     //{
 
-                                     //    settingPrice *= cycleUnit;
 
-                                     //}
 
-                                     if (dto.FeeTotal <= availableAmount) //dto.Price <= settingPrice &&  && dto.Quantity <= setting.Quantity
 
-                                     {
 
-                                         isAuto = true;
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                         if (isAuto)
 
-                         {
 
-                             var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
 
-                                 .SetColumns(a => new Grp_CreditCardPayment
 
-                                 {
 
-                                     IsAuditGM = 3, //自动审核通过
 
-                                     AuditGMOperate = 4,
 
-                                     AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 
-                                 })
 
-                                 .Where(a => a.CId == id && a.CTable == 98 && a.DIId == 2590)
 
-                                 .ExecuteCommand();
 
-                             recheck = false;
 
-                         }
 
-                     }
 
-                     #endregion
 
-                     #region 会务成本自动审核处理
 
-                     var hwids = _sqlSugar.Queryable<Sys_SetData>()
 
-                         .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
 
-                         .Select(x => x.Id)
 
-                         .ToList();
 
-                     var groupTypeIsTrue = _sqlSugar.Queryable<Grp_DelegationInfo>()
 
-                         .Where(x => x.Id == dto.DiId && x.IsDel == 0)
 
-                         .Any(x => hwids.Contains(x.TeamDid));
 
-                     if (groupTypeIsTrue)
 
-                     {
 
-                         var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
 
-                                             .First(x => x.Diid == dto.DiId && x.IsDel == 0);
 
-                         if (main != null)
 
-                         {
 
-                             var chiArr = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
 
-                                 .Where(x => x.Diid == dto.DiId && x.ConferenceAffairsCostId == main.Id && x.IsDel == 0)
 
-                                 .ToList();
 
-                             var find = chiArr.FirstOrDefault(x => x.PriceName == dto.PriceName && x.ReviewStatus == 1);
 
-                             var isAuto = false;
 
-                             //存在已审的会务成本
 
-                             if (find != null)
 
-                             {
 
-                                 //检索历史金额
 
-                                 var histyPrice = _sqlSugar.Queryable<Grp_DecreasePayments>()
 
-                                     .LeftJoin<Grp_CreditCardPayment>((x, a) => a.IsDel == 0 && a.CTable == 98 && a.CId == x.Id)
 
-                                     .Where((x, a) => x.IsDel == 0 && x.PriceName == dto.PriceName && x.Id != grp_Decrease.Id)
 
-                                     .Select((x, a) => new
 
-                                     {
 
-                                         x.FeeTotal,
 
-                                         x.Currency,
 
-                                         a.DayRate,
 
-                                         a.RMBPrice,
 
-                                         x.DiId,
 
-                                         x.PriceName,
 
-                                         x.Price,
 
-                                         x.Quantity,
 
-                                     })
 
-                                     .ToList();
 
-                                 //币种不同情况
 
-                                 if (true)
 
-                                 {
 
-                                     //币种全转换为人民币
 
-                                     var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
 
-                                     if (rate != null)
 
-                                     {
 
-                                         grp_Decrease.FeeTotal *= rate.Rate;
 
-                                     }
 
-                                     var ConferenceAffairsCostFeeTotal = 0.00M;
 
-                                     ConferenceAffairsCostFeeTotal = find.Count * find.CostPrice * find.Rate;
 
-                                     var histyPriceValue = histyPrice.Sum(x => x.FeeTotal * x.DayRate);
 
-                                     if (ConferenceAffairsCostFeeTotal > histyPriceValue)
 
-                                     {
 
-                                         isAuto = ConferenceAffairsCostFeeTotal - histyPriceValue >= grp_Decrease.FeeTotal;
 
-                                     }
 
-                                 }
 
-                             }
 
-                             if (isAuto)
 
-                             {
 
-                                 var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
 
-                                       .SetColumns(a => new Grp_CreditCardPayment
 
-                                       {
 
-                                           IsAuditGM = 3, //自动审核通过
 
-                                           AuditGMOperate = 4,
 
-                                           AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 
-                                       })
 
-                                       .Where(a => a.CId == grp_Decrease.Id && a.CTable == 98 && a.DIId == grp_Decrease.DiId)
 
-                                       .ExecuteCommand();
 
-                                 recheck = false;
 
-                             }
 
-                         }
 
-                     }
 
-                     #endregion
 
-                     CommitTran();
 
-                     var data = new { ccpId = cId, sign = 1, dataId = id, recheck };
 
-                     return new JsonView() { Code = 200, Msg = "添加成功!", Data = data };
 
-                 }
 
-                 RollbackTran();
 
-                 return new JsonView() { Code = 400, Msg = "添加失败!" };
 
-             }
 
-             else if (dto.Status == 2)
 
-             {
 
-                 //已审核、已支付 不可修改
 
-                 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);
 
-                 if (grp_CreditCardPayment == null) return new JsonView() { Code = 400, Msg = MsgTips.Fail };
 
-                 var isAuditGM = grp_CreditCardPayment.IsAuditGM;
 
-                 if (isAuditGM == 1 || isAuditGM == 3) return new JsonView() { Code = 400, Msg = $"该费用已通过审核,不可编辑" };
 
-                 if (grp_CreditCardPayment.IsPay == 1) return new JsonView() { Code = 400, Msg = $"该费用已付款,不可编辑!" };
 
-                 bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
 
-                 {
 
-                     DiId = grp_Decrease.DiId,
 
-                     SupplierArea = grp_Decrease.SupplierArea,
 
-                     SupplierTypeId = grp_Decrease.SupplierTypeId,
 
-                     SupplierName = grp_Decrease.SupplierName,
 
-                     SupplierContact = grp_Decrease.SupplierContact,
 
-                     SupplierContactNumber = grp_Decrease.SupplierContactNumber,
 
-                     SupplierSocialAccount = grp_Decrease.SupplierSocialAccount,
 
-                     SupplierEmail = grp_Decrease.SupplierEmail,
 
-                     SupplierAddress = grp_Decrease.SupplierAddress,
 
-                     PriceName = grp_Decrease.PriceName,
 
-                     Price = grp_Decrease.Price,
 
-                     Quantity = grp_Decrease.Quantity,
 
-                     FeeTotal = grp_Decrease.FeeTotal,
 
-                     Currency = grp_Decrease.Currency,
 
-                     FilePath = grp_Decrease.FilePath,
 
-                     OTAOrderNo = grp_Decrease.OTAOrderNo,
 
-                     Remark = grp_Decrease.Remark,
 
-                 });
 
-                 if (res)
 
-                 {
 
-                     if (teamRate != null)
 
-                     {
 
-                         if (teamRate.CurrencyCode.Equals("CNY"))
 
-                         {
 
-                             grp_CreditCardPayment.DayRate = 1.0000M;
 
-                             grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
 
-                         }
 
-                         else
 
-                         {
 
-                             grp_CreditCardPayment.DayRate = teamRate.Rate;
 
-                             grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
 
-                         }
 
-                     }
 
-                     //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
 
-                     int isPay = 0;
 
-                     if (dto.PayDId == 72) isPay = 1;
 
-                     int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
 
-                         .Where(a => a.Id == grp_CreditCardPayment.Id)
 
-                         .SetColumns(a => new Grp_CreditCardPayment
 
-                         {
 
-                             OtherSideName = dto.OtherSideName,
 
-                             OtherSideNo = dto.OtherSideNo,
 
-                             OtherBankName = dto.OtherBankName,
 
-                             PayDId = dto.PayDId,
 
-                             IsPay = isPay,
 
-                             PayMoney = grp_Decrease.FeeTotal,
 
-                             PaymentCurrency = grp_Decrease.Currency,
 
-                             Payee = dto.SupplierName,
 
-                             OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
 
-                             DayRate = grp_CreditCardPayment.DayRate,
 
-                             RMBPrice = grp_CreditCardPayment.RMBPrice,
 
-                             //IsAuditGM = auto ? 3 : grp_CreditCardPayment.IsAuditGM
 
-                         })
 
-                         .ExecuteCommandAsync();
 
-                     if (CTable > 0)
 
-                     {
 
-                         #region 世运会自动审核处理
 
-                         if (dto.DiId == 2590)
 
-                         {
 
-                             bool isAuto = false;
 
-                             string[] spPriceName = dto.PriceName.Split('-').ToArray();
 
-                             var expression = Expressionable.Create<Grp_GamesBudgetMaster>()
 
-                                                             .And(x => x.IsDel == 0);
 
-                             if (spPriceName.Length >= 2)
 
-                             {
 
-                                 expression.And(x => x.T0 == spPriceName[0])
 
-                                           .And(x => x.CalculationContent == spPriceName[1]);
 
-                                 var setting = _sqlSugar.Queryable<Grp_GamesBudgetMaster>()
 
-                                                         .First(expression.ToExpression());
 
-                                 if (setting != null)
 
-                                 {
 
-                                     var dbList = _sqlSugar.Queryable<Grp_DecreasePayments>()
 
-                                                 .LeftJoin<Grp_CreditCardPayment>((x, a) => x.Id == a.CId && a.IsDel == 0 && a.CTable == 98 && a.DIId == dto.DiId)
 
-                                                 .Where((x, a) => x.IsDel == 0 && x.PriceName.Contains(spPriceName[0]) && x.PriceName.Contains(spPriceName[1]) && x.Id != dto.Id)
 
-                                                 .Select((x, a) => new
 
-                                                 {
 
-                                                     x,
 
-                                                     a.RMBPrice,
 
-                                                 })
 
-                                                 .ToList();
 
-                                     //币种问题 (836 CNY)
 
-                                     if (dto.Currency != 836)
 
-                                     {
 
-                                         var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
 
-                                         if (rate != null)
 
-                                         {
 
-                                             //dto.Price *= rate.Rate;
 
-                                             dto.FeeTotal *= rate.Rate;
 
-                                         }
 
-                                     }
 
-                                     //现有金额
 
-                                     var sumPrice = dbList.Sum(x => x.RMBPrice);
 
-                                     //现有数量
 
-                                     //var sumCount = dbList.Sum(x => x.Quantity);
 
-                                     var availableAmount = setting.ItemTotal - sumPrice;
 
-                                     //var availableQuantity = setting.Quantity - sumCount;
 
-                                     if (availableAmount > 0)  // && availableQuantity > 0
 
-                                     {
 
-                                         //单价计算
 
-                                         //var settingPrice = setting.UnitPrice;
 
-                                         //if (int.TryParse(setting.CycleUnit, out int cycleUnit))
 
-                                         //{
 
-                                         //    settingPrice *= cycleUnit;
 
-                                         //}
 
-                                         if (dto.FeeTotal <= availableAmount) //dto.Price <= settingPrice &&  && dto.Quantity <= setting.Quantity
 
-                                         {
 
-                                             isAuto = true;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                             }
 
-                             if (isAuto)
 
-                             {
 
-                                 _sqlSugar.Updateable<Grp_CreditCardPayment>()
 
-                                     .SetColumns(a => new Grp_CreditCardPayment
 
-                                     {
 
-                                         IsAuditGM = 3, //自动审核通过
 
-                                         AuditGMOperate = 4,
 
-                                         AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 
-                                     })
 
-                                     .Where(a => a.CId == dto.Id && a.CTable == 98 && a.DIId == 2590)
 
-                                     .ExecuteCommand();
 
-                                 recheck = false;
 
-                             }
 
-                         }
 
-                         #endregion
 
-                         #region 会务成本自动审核处理
 
-                         var hwids = _sqlSugar.Queryable<Sys_SetData>()
 
-                             .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
 
-                             .Select(x => x.Id)
 
-                             .ToList();
 
-                         var groupTypeIsTrue = _sqlSugar.Queryable<Grp_DelegationInfo>()
 
-                             .Where(x => x.Id == dto.DiId && x.IsDel == 0)
 
-                             .Any(x => hwids.Contains(x.TeamDid));
 
-                         if (groupTypeIsTrue)
 
-                         {
 
-                             var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
 
-                                                 .First(x => x.Diid == dto.DiId && x.IsDel == 0);
 
-                             if (main != null)
 
-                             {
 
-                                 var chiArr = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
 
-                                     .Where(x => x.Diid == dto.DiId && x.ConferenceAffairsCostId == main.Id && x.IsDel == 0)
 
-                                     .ToList();
 
-                                 var find = chiArr.FirstOrDefault(x => x.PriceName == dto.PriceName && x.ReviewStatus == 1);
 
-                                 var isAuto = false;
 
-                                 //存在已审的会务成本
 
-                                 if (find != null)
 
-                                 {
 
-                                     //检索历史金额
 
-                                     var histyPrice = _sqlSugar.Queryable<Grp_DecreasePayments>()
 
-                                         .LeftJoin<Grp_CreditCardPayment>((x, a) => a.IsDel == 0 && a.CTable == 98 && a.CId == x.Id)
 
-                                         .Where((x, a) => x.IsDel == 0 && x.PriceName == dto.PriceName && x.Id != grp_Decrease.Id)
 
-                                         .Select((x, a) => new
 
-                                         {
 
-                                             x.FeeTotal,
 
-                                             x.Currency,
 
-                                             a.DayRate,
 
-                                             a.RMBPrice,
 
-                                             x.DiId,
 
-                                             x.PriceName,
 
-                                             x.Price,
 
-                                             x.Quantity,
 
-                                         })
 
-                                         .ToList();
 
-                                     if (true)
 
-                                     {
 
-                                         //币种全转换为人民币
 
-                                         var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
 
-                                         if (rate != null)
 
-                                         {
 
-                                             grp_Decrease.FeeTotal *= rate.Rate;
 
-                                         }
 
-                                         var ConferenceAffairsCostFeeTotal = 0.00M;
 
-                                         ConferenceAffairsCostFeeTotal = find.Count * find.CostPrice * find.Rate;
 
-                                         var histyPriceValue = histyPrice.Sum(x => x.FeeTotal * x.DayRate);
 
-                                         if (ConferenceAffairsCostFeeTotal > histyPriceValue)
 
-                                         {
 
-                                             isAuto = ConferenceAffairsCostFeeTotal - histyPriceValue >= grp_Decrease.FeeTotal;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                                 if (isAuto)
 
-                                 {
 
-                                     var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
 
-                                     .SetColumns(a => new Grp_CreditCardPayment
 
-                                     {
 
-                                         IsAuditGM = 3, //自动审核通过
 
-                                         AuditGMOperate = 4,
 
-                                         AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 
-                                     })
 
-                                     .Where(a => a.CId == grp_Decrease.Id && a.CTable == 98 && a.DIId == grp_Decrease.DiId)
 
-                                     .ExecuteCommand();
 
-                                     recheck = false;
 
-                                 }
 
-                             }
 
-                         }
 
-                         #endregion
 
-                         CommitTran();
 
-                         var data = new { ccpId = grp_CreditCardPayment.Id, sign = 2, dataId = grp_Decrease.Id, recheck };
 
-                         return new JsonView() { Code = 200, Msg = "修改成功!", Data = data };
 
-                     }
 
-                 }
 
-             }
 
-             RollbackTran();
 
-             return new JsonView() { Code = 400, Msg = MsgTips.Fail };
 
-         }
 
-         public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
 
-         {
 
-             Result result = new Result() { Code = -2, Msg = "未知错误" };
 
-             try
 
-             {
 
-                 #region 团组下拉框
 
-                 List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
 
-                 string DiId = "";
 
-                 foreach (var item in grp_GroupsTaskAssignment)
 
-                 {
 
-                     DiId += item.DIId + ",";
 
-                 }
 
-                 if (!string.IsNullOrWhiteSpace(DiId))
 
-                 {
 
-                     DiId = DiId.Substring(0, DiId.Length - 1);
 
-                 }
 
-                 else
 
-                 {
 
-                     DiId = "0";
 
-                 }
 
-                 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);
 
-                 List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
 
-                 if (grp_Delegations.Count != 0)
 
-                 {
 
-                     int count = grp_Delegations.Count;
 
-                     float totalPage = (float)count / dto.PageSize;//总页数
 
-                     if (totalPage == 0) totalPage = 1;
 
-                     else totalPage = (int)Math.Ceiling((double)totalPage);
 
-                     List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
 
-                     for (int i = 0; i < dto.PageSize; i++)
 
-                     {
 
-                         var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
 
-                         if (RowIndex < grp_Delegations.Count)
 
-                         {
 
-                             delegationEasyViews.Add(grp_Delegations[RowIndex]);
 
-                         }
 
-                         else
 
-                         {
 
-                             break;
 
-                         }
 
-                     }
 
-                     ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
 
-                     rst.DataList = delegationEasyViews;
 
-                     rst.DataCount = count;
 
-                     rst.CurrPageIndex = dto.PageIndex;
 
-                     rst.CurrPageSize = dto.PageSize;
 
-                     return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
 
-                 }
 
-                 else
 
-                 {
 
-                     ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
 
-                     rst.DataList = new List<DelegationEasyView>();
 
-                     return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
 
-                 }
 
-                 #endregion
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 return result = new Result() { Code = -2, Msg = "程序错误" };
 
-                 throw;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 根据团组增减款项表Id查询数据
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         /// <exception cref="NotImplementedException"></exception>
 
-         public async Task<JsonView> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
 
-         {
 
-             string sql = string.Format($@"Select 
 
- 											dp.Id,
 
- 											dp.DiId,
 
- 											dp.SupplierArea,
 
- 											dp.SupplierTypeId,
 
- 											dp.SupplierName,
 
- 											dp.SupplierContact,
 
- 											dp.SupplierContactNumber,
 
- 											dp.SupplierSocialAccount,
 
- 											dp.SupplierEmail,
 
- 											dp.SupplierAddress,
 
- 											dp.PriceName,
 
- 											dp.Price,
 
- 											dp.Quantity,
 
- 											dp.FeeTotal,
 
- 											dp.Currency,
 
- 											dp.FilePath,
 
-                                             dp.OTAOrderNo,
 
- 											dp.Remark,
 
- 											ccp.PayDId,
 
- 											ccp.OrbitalPrivateTransfer,
 
- 											ccp.OtherBankName,
 
- 											ccp.OtherSideName,
 
- 											ccp.OtherSideNo,
 
-                                             ccp.IsAuditGM
 
- 										From Grp_DecreasePayments dp With(NoLock)
 
- 										Left Join Grp_CreditCardPayment ccp With(NoLock) On dp.Id = ccp.CId And dp.DiId = ccp.DIId And ccp.CTable = 98
 
- 										Where dp.IsDel = 0 And dp.Id = {dto.Id}");
 
-             var info = await _sqlSugar.SqlQueryable<DecreasePaymentsInfoView>(sql).FirstAsync();
 
-             return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = info };
 
-         }
 
-         /// <summary>
 
-         /// Del
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         /// <exception cref="NotImplementedException"></exception>
 
-         public async Task<Result> _Del(int id, int userId)
 
-         {
 
-             Result result = new Result() { Code = -2, Msg = "删除失败!" };
 
-             var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
 
-                 .FirstAsync(x => x.CId == id && x.CTable == 98 && x.IsDel == 0);
 
-             if (ccpInfo == null) return new Result(-2, "数据不存在,不可删除!");
 
-             var auditStatus = new List<int>() {
 
-                     1, // 已通过
 
-             };
 
-             if (auditStatus.Any(x => x == ccpInfo.IsAuditGM)) return new Result(-2, "该费用已手动审核,不可删除!");
 
-             if (ccpInfo.IsPay == 1) return new Result(-2, "该费用已付款,不可删除!");
 
-             _sqlSugar.BeginTran();
 
-             var del = await _sqlSugar.Updateable<Grp_DecreasePayments>()
 
-                 .SetColumns(it => new Grp_DecreasePayments()
 
-                 {
 
-                     IsDel = 1,
 
-                     DeleteUserId = userId,
 
-                     DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 
-                 }).Where(it => it.Id == id)
 
-                 .ExecuteCommandAsync();
 
-             if (del > 0)
 
-             {
 
-                 var del1 = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
 
-                     .SetColumns(a => new Grp_CreditCardPayment()
 
-                     {
 
-                         IsDel = 1,
 
-                         DeleteUserId = userId,
 
-                         DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 
-                     })
 
-                     .Where(a => a.CId == id && a.CTable == 98)
 
-                     .ExecuteCommandAsync();
 
-                 if (del1 > 0)
 
-                 {
 
-                     _sqlSugar.CommitTran();
 
-                     result.Code = 0;
 
-                     result.Msg = "删除成功!";
 
-                     return result;
 
-                 }
 
-             }
 
-             _sqlSugar.RollbackTran();
 
-             return result;
 
-         }
 
-     }
 
- }
 
 
  |