|
@@ -1,8 +1,15 @@
|
|
|
using AutoMapper;
|
|
|
+using NPOI.POIFS.Crypt.Dsig;
|
|
|
using OASystem.Domain;
|
|
|
+using OASystem.Domain.Dtos.Financial;
|
|
|
using OASystem.Domain.Dtos.Groups;
|
|
|
+using OASystem.Domain.Entities.Financial;
|
|
|
using OASystem.Domain.Entities.Groups;
|
|
|
+using OASystem.Domain.ViewModels.Financial;
|
|
|
using OASystem.Domain.ViewModels.Groups;
|
|
|
+using OASystem.Domain.ViewModels.QiYeWeChat;
|
|
|
+using OASystem.Infrastructure.Tools;
|
|
|
+using SqlSugar;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -14,9 +21,11 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
public class CustomersRepository : BaseRepository<Grp_Customers, Grp_Ommission>
|
|
|
{
|
|
|
private readonly IMapper _mapper;
|
|
|
- public CustomersRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
|
|
|
+ private readonly HotelPriceRepository _hotel;
|
|
|
+ public CustomersRepository(SqlSugarClient sqlSugar, IMapper mapper, HotelPriceRepository hotel) : base(sqlSugar)
|
|
|
{
|
|
|
_mapper = mapper;
|
|
|
+ _hotel= hotel;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 根据团组Id查询保险费用列表
|
|
@@ -41,7 +50,16 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
{
|
|
|
UserId = "0";
|
|
|
}
|
|
|
- string sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0, UserId);
|
|
|
+ string sqlWhere = string.Empty;
|
|
|
+ if (!string.IsNullOrWhiteSpace(dto.ClientName))
|
|
|
+ {
|
|
|
+ sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2}) and h.ClientName like '%{3}%'", dto.DiId, 0, UserId,dto.ClientName);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlWhere = string.Format(@"Where h.DiId={0} and h.IsDel={1} And h.CreateUserId in ({2})", dto.DiId, 0, UserId);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
|
|
|
int endIndex = startIndex + dto.PageSize - 1;
|
|
@@ -129,32 +147,247 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
{
|
|
|
Grp_Customers grp_Customers = _sqlSugar.Queryable<Grp_Customers>().First(a=>a.Id==dto.Id && a.IsDel==0);
|
|
|
CustomersByIdView customersById = _mapper.Map<CustomersByIdView>(grp_Customers);
|
|
|
- Grp_CreditCardPayment creditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable==82);
|
|
|
- customersById = _mapper.Map<CustomersByIdView>(creditCardPayment);
|
|
|
+
|
|
|
if (customersById != null)
|
|
|
{
|
|
|
- Sys_SetData Iid = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == customersById.Iid);
|
|
|
- if (Iid != null) customersById.IidStr = Iid.Name;
|
|
|
+ Grp_CreditCardPayment creditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 82);
|
|
|
+ CreditCardView creditCardView = _mapper.Map<CreditCardView>(creditCardPayment);
|
|
|
+ Grp_InsuranceCost Iid = _sqlSugar.Queryable<Grp_InsuranceCost>().First(a => a.IsDel == 0 && a.Id == customersById.Iid);
|
|
|
+ if (Iid != null) customersById.IidStr = Iid.GName;
|
|
|
+
|
|
|
+
|
|
|
+ string CountSql = string.Format(@"select sum(InsuranceCosts) as CountCost from Grp_Customers where isdel=0 and Iid=" + customersById.Iid);
|
|
|
+ DataCountCost dataCount = _sqlSugar.SqlQueryable<DataCountCost>(CountSql).First();
|
|
|
+ customersById.InsuranceBalance = Math.Round(Iid.RechargeCost - dataCount.CountCost, 2);
|
|
|
|
|
|
Sys_SetData Currency = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == customersById.Currency);
|
|
|
if (Currency != null) customersById.CurrencyStr = Currency.Name;
|
|
|
|
|
|
- Sys_SetData PayDId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == customersById.PayDId);
|
|
|
- if (PayDId != null) customersById.PayDIdStr = PayDId.Name;
|
|
|
+ Sys_SetData PayDId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == creditCardView.PayDId);
|
|
|
+ if (PayDId != null) creditCardView.PayDIdStr = PayDId.Name;
|
|
|
+
|
|
|
+ Sys_SetData CTDId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == creditCardView.CTDId);
|
|
|
+ if (CTDId != null) creditCardView.CTDIdStr = CTDId.Name;
|
|
|
+ creditCardView.OrbitalPrivateTransferStr= creditCardView.OrbitalPrivateTransfer== 0 ? "公转" : "私转";
|
|
|
+
|
|
|
+ Sys_SetData PaymentCurrency= _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == creditCardView.PaymentCurrency);
|
|
|
+ if (PaymentCurrency != null) creditCardView.PaymentCurrencyStr = PaymentCurrency.Name;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var data = new
|
|
|
+ {
|
|
|
+ customers = customersById,
|
|
|
+ creditCard = creditCardView
|
|
|
+ };
|
|
|
+ return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
|
|
|
+ }
|
|
|
+ var dataN = new
|
|
|
+ {
|
|
|
+ customers = new CustomersView(),
|
|
|
+ creditCard = new CreditCardView()
|
|
|
+ };
|
|
|
+ return result = new Result() { Code = 0, Msg = "暂无数据!", Data = dataN };
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<Result> CustomersInitialize(CustomersInitializeDto dto)
|
|
|
+ {
|
|
|
+ Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ //卡类型
|
|
|
+ List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
|
|
|
+ List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
|
|
|
+
|
|
|
+ //保险名称
|
|
|
+ List<Grp_InsuranceCost> _InsuranceCosts=_sqlSugar.Queryable<Grp_InsuranceCost>().Where(a=>a.IsDel==0).ToList();
|
|
|
+ List<InsuranceCostView> insuranceCostViews = new List<InsuranceCostView>();
|
|
|
+ foreach (var item in _InsuranceCosts)
|
|
|
+ {
|
|
|
+ InsuranceCostView costView=new InsuranceCostView();
|
|
|
+ costView.Id=item.Id;
|
|
|
+ costView.GName=item.GName;
|
|
|
+ costView.Balance = 0.00M;
|
|
|
+ string CountSql = string.Format(@"select sum(InsuranceCosts) as CountCost from Grp_Customers where isdel=0 and Iid=" + item.Id);
|
|
|
+ DataCountCost dataCount = _sqlSugar.SqlQueryable<DataCountCost>(CountSql).First();
|
|
|
+ costView.Balance = Math.Round(item.RechargeCost - dataCount.CountCost, 2);
|
|
|
+ insuranceCostViews.Add(costView);
|
|
|
+ }
|
|
|
+ //币种
|
|
|
+ GeneralTeamRateInfoDto PostGroupTeamRatedto = new GeneralTeamRateInfoDto();
|
|
|
+ PostGroupTeamRatedto.DiId = dto.DiId;
|
|
|
+ PostGroupTeamRatedto.CTbale = 82;
|
|
|
+ PostGroupTeamRatedto.PortType = dto.PortType;
|
|
|
+ Result teamRateDescAddCurrencyIdViews = _hotel.PostGroupTeamRateByDiIdAndCTableId(PostGroupTeamRatedto);
|
|
|
+ List<TeamRateDescAddCurrencyIdView> Currency = new List<TeamRateDescAddCurrencyIdView>();
|
|
|
+ if (teamRateDescAddCurrencyIdViews.Code == 0)
|
|
|
+ {
|
|
|
+ Currency = teamRateDescAddCurrencyIdViews.Data;
|
|
|
+ }
|
|
|
+
|
|
|
+ var data = new
|
|
|
+ {
|
|
|
+ insuranceCost= insuranceCostViews,
|
|
|
+ Payment = _Payment,
|
|
|
+ CurrencyList = Currency,
|
|
|
+ BankCard = _BankCard,
|
|
|
+ };
|
|
|
+ return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<Result> OpCustomers(OpCustomersDto dto)
|
|
|
+ {
|
|
|
+ Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ BeginTran();
|
|
|
+ int id = dto.Id;
|
|
|
+ Grp_Customers cus = _mapper.Map<Grp_Customers>(dto);
|
|
|
+
|
|
|
+ Grp_CreditCardPayment c = _mapper.Map<Grp_CreditCardPayment>(dto);
|
|
|
+ c.Remark = dto.CRemark;
|
|
|
+ c.PayPercentage = 100;
|
|
|
+ c.CTable = 82;
|
|
|
+ c.CId = id;
|
|
|
+ c.IsAuditGM = 0;
|
|
|
+ c.PayMoney = cus.InsuranceCosts;
|
|
|
+ c.PaymentCurrency = cus.Currency;
|
|
|
+ if (c.PayDId == 72)
|
|
|
+ {
|
|
|
+ c.IsPay = 1;
|
|
|
+ }
|
|
|
+ c.RMBPrice = cus.InsuranceCosts;
|
|
|
+ c.DayRate = 1;
|
|
|
+ Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 82);
|
|
|
+ List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
|
|
|
+ if (_TeamRate != null)
|
|
|
+ {
|
|
|
+ Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == cus.Currency);
|
|
|
+ if (_SetData != null)
|
|
|
+ {
|
|
|
+ currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
|
|
|
+ CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
|
|
|
+ if (CurrencyRate != null)
|
|
|
+ {
|
|
|
+ c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
|
|
|
+ c.DayRate = CurrencyRate.Rate;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dto.Status == 1)//添加
|
|
|
+ {
|
|
|
+ Grp_Customers customers = _sqlSugar.Queryable<Grp_Customers>().First(a => a.IsDel == 0 && a.ClientName == dto.ClientName && a.InsuranceCosts == dto.InsuranceCosts);
|
|
|
+ if (customers != null)
|
|
|
+ {
|
|
|
+ return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ id = await AddAsyncReturnId(cus);
|
|
|
+ if (id != 0)
|
|
|
+ {
|
|
|
+ c.CId = id;
|
|
|
+ int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
|
|
|
+ if (cId != 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = 0, Msg = "添加成功!" };
|
|
|
|
|
|
- Sys_SetData CTDId = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == customersById.CTDId);
|
|
|
- if (CTDId != null) customersById.CTDIdStr = CTDId.Name;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RollbackTran();
|
|
|
+ result = new Result() { Code = -1, Msg = "添加失败!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RollbackTran();
|
|
|
+ result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (dto.Status == 2)//修改
|
|
|
+ {
|
|
|
|
|
|
- customersById.OrbitalPrivateTransferStr=customersById.OrbitalPrivateTransfer== 0 ? "公转" : "私转";
|
|
|
- customersById.CRemark = creditCardPayment.Remark;
|
|
|
+
|
|
|
+ bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_Customers
|
|
|
+ {
|
|
|
+ Iid = cus.Iid,
|
|
|
+ ClientName = cus.ClientName,
|
|
|
+ InsuranceCosts = cus.InsuranceCosts,
|
|
|
+ Currency = cus.Currency,
|
|
|
+ Attachment = cus.Attachment,
|
|
|
+ Remark = cus.Remark
|
|
|
+ });
|
|
|
+ if (res)
|
|
|
+ {
|
|
|
+ int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == cus.Id && a.CTable == 82).SetColumns(a => new Grp_CreditCardPayment
|
|
|
+ {
|
|
|
+ PayDId = dto.PayDId,
|
|
|
+ PayMoney = c.PayMoney,
|
|
|
+ PaymentCurrency = c.PaymentCurrency,
|
|
|
+ Payee = c.Payee,
|
|
|
+ OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
|
|
|
+ DayRate = c.DayRate,
|
|
|
+ RMBPrice = c.RMBPrice,
|
|
|
+ ConsumptionPatterns = c.ConsumptionPatterns,
|
|
|
+ ConsumptionDate = c.ConsumptionDate,
|
|
|
+ CTDId = c.CTDId,
|
|
|
+ CompanyBankNo = c.CompanyBankNo,
|
|
|
+ OtherBankName = c.OtherBankName,
|
|
|
+ OtherSideNo = c.OtherSideNo,
|
|
|
+ OtherSideName = c.OtherSideName,
|
|
|
+ BankNo = c.BankNo,
|
|
|
+ CardholderName = c.CardholderName,
|
|
|
+ Remark = c.Remark,
|
|
|
+
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ if (CTable == 0)
|
|
|
+ {
|
|
|
+ result = new Result() { Code = -1, Msg = "修改失败!" };
|
|
|
+ RollbackTran();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = new Result() { Code = 0, Msg = "修改成功!" };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RollbackTran();
|
|
|
+ result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
|
|
|
+ }
|
|
|
}
|
|
|
- return result = new Result() { Code = 0, Msg = "查询成功!",Data= customersById };
|
|
|
+ CommitTran();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
throw;
|
|
|
}
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
}
|