You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
229 lines
12 KiB
229 lines
12 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Shentun.Peis.Enums;
|
|
using Shentun.Peis.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Dynamic.Core;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Identity;
|
|
|
|
namespace Shentun.Peis.CardBills
|
|
{
|
|
[ApiExplorerSettings(GroupName = "Work")]
|
|
[Authorize]
|
|
public class CardBillAppService : ApplicationService
|
|
{
|
|
private readonly IRepository<CardBill, Guid> _cardBillRepository;
|
|
private readonly IRepository<IdentityUser, Guid> _userRepository;
|
|
private readonly IRepository<Charge, Guid> _chargeRepository;
|
|
private readonly IRepository<ChargeBack, Guid> _chargeBackRepository;
|
|
private readonly IRepository<ChargeBackPay> _chargeBackPayRepository;
|
|
private readonly IRepository<ChargePay> _chargePayRepository;
|
|
|
|
public CardBillAppService(
|
|
IRepository<CardBill, Guid> cardBillRepository,
|
|
IRepository<IdentityUser, Guid> userRepository,
|
|
IRepository<Charge, Guid> chargeRepository,
|
|
IRepository<ChargeBack, Guid> chargeBackRepository,
|
|
IRepository<ChargeBackPay> chargeBackPayRepository,
|
|
IRepository<ChargePay> chargePayRepository
|
|
)
|
|
{
|
|
this._cardBillRepository = cardBillRepository;
|
|
this._userRepository = userRepository;
|
|
this._chargeRepository = chargeRepository;
|
|
this._chargeBackRepository = chargeBackRepository;
|
|
this._chargeBackPayRepository = chargeBackPayRepository;
|
|
this._chargePayRepository = chargePayRepository;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取全部卡记录列表 带联合搜索条件
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
[HttpPost("api/app/cardbill/getcardbilllist")]
|
|
public async Task<List<CardBillDto>> GetCardBillListAsync(GetCardBillListDto input)
|
|
{
|
|
if (input != null)
|
|
{
|
|
var queryable = (await _cardBillRepository.GetDbSetAsync())
|
|
.Include(x => x.CardRegister)
|
|
.Include(x => x.CardRegister.CardType).AsQueryable();
|
|
|
|
if (!string.IsNullOrEmpty(input.CardNo))
|
|
{
|
|
queryable = queryable.Where(m => m.CardRegister.CardNo == input.CardNo);
|
|
}
|
|
if (!string.IsNullOrEmpty(input.IdNo))
|
|
{
|
|
queryable = queryable.Where(m => m.CardRegister.IdNo == input.IdNo);
|
|
}
|
|
if (!string.IsNullOrEmpty(input.CustomerName))
|
|
{
|
|
queryable = queryable.Where(m => !string.IsNullOrEmpty(m.CardRegister.CustomerName) &&
|
|
m.CardRegister.CustomerName.Contains(input.CustomerName));
|
|
}
|
|
if (!string.IsNullOrEmpty(input.Phone))
|
|
{
|
|
queryable = queryable.Where(m => (!string.IsNullOrEmpty(m.CardRegister.Telephone) &&
|
|
m.CardRegister.Telephone.Contains(input.Phone)) || !string.IsNullOrEmpty(m.CardRegister.MobileTelephone) &&
|
|
m.CardRegister.MobileTelephone.Contains(input.Phone));
|
|
}
|
|
//if (!string.IsNullOrEmpty(input.MobileTelephone))
|
|
//{
|
|
// queryable = queryable.Where(m => !string.IsNullOrEmpty(m.CardRegister.MobileTelephone) &&
|
|
// m.CardRegister.MobileTelephone.Contains(input.MobileTelephone));
|
|
//}
|
|
if (input.BillFlag != null)
|
|
{
|
|
queryable = queryable.Where(m => m.BillFlag == input.BillFlag);
|
|
}
|
|
if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate))
|
|
{
|
|
queryable = queryable.Where(m => m.CreationTime >= Convert.ToDateTime(input.StartDate) &&
|
|
m.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
|
|
}
|
|
|
|
var userlist = await _userRepository.GetListAsync();
|
|
|
|
var entlist = queryable.Select(s => new CardBillDto
|
|
{
|
|
BillFlag = s.BillFlag,
|
|
BillMoney = s.BillMoney,
|
|
MobileTelephone = s.CardRegister.MobileTelephone,
|
|
CardBalance = s.CardRegister.CardBalance,
|
|
CardFlag = s.CardRegister.IsActive,
|
|
CardNo = s.CardRegister.CardNo,
|
|
CardPassword = s.CardRegister.CardPassword,
|
|
CardRegisterId = s.CardRegisterId,
|
|
CardTypeId = s.CardRegister.CardTypeId,
|
|
CardTypeName = s.CardRegister.CardType.DisplayName,
|
|
ConcurrencyStamp = s.ConcurrencyStamp,
|
|
CreationTime = s.CreationTime,
|
|
CreatorId = s.CreatorId,
|
|
CustomerName = s.CardRegister.CustomerName,
|
|
Discount = s.CardRegister.Discount,
|
|
ExpiryDate = s.CardRegister.ExpiryDate.ToString(),
|
|
Id = s.Id,
|
|
IdNo = s.CardRegister.IdNo,
|
|
LastModificationTime = s.LastModificationTime,
|
|
LastModifierId = s.LastModifierId,
|
|
OrganizationUnitId = s.CardRegister.OrganizationUnitId,
|
|
PayModeId = s.PayModeId,
|
|
Remark = s.CardRegister.Remark,
|
|
Telephone = s.CardRegister.Telephone,
|
|
CreatorName = EntityHelper.GetUserNameNoSql(userlist, s.CreatorId),
|
|
LastModifierName = EntityHelper.GetUserNameNoSql(userlist, s.LastModifierId)
|
|
}).ToList();
|
|
|
|
return entlist;
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new UserFriendlyException("参数有误");
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取卡记录列表 根据会员卡ID
|
|
/// </summary>
|
|
/// <param name="CardRegisterId"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
[HttpPost("api/app/cardbill/getcardbilllistincardregisterid")]
|
|
public async Task<List<CardBillInChargeDto>> GetCardBillListInCardRegisterIdAsync(Guid CardRegisterId)
|
|
{
|
|
|
|
var chargeQueryable = await _chargeRepository.GetQueryableAsync();
|
|
var chargePayQueryable = await _chargePayRepository.GetQueryableAsync();
|
|
var cardBillQueryable = await _cardBillRepository.GetQueryableAsync();
|
|
var chargeBackQueryable = await _chargeBackRepository.GetQueryableAsync();
|
|
var chargeBackPayQueryable = await _chargeBackPayRepository.GetQueryableAsync();
|
|
var userQueryable = await _userRepository.GetQueryableAsync();
|
|
|
|
var queryCharge = from a in cardBillQueryable.Where(m => m.CardRegisterId == CardRegisterId && m.BillFlag ==CardBillFlag.Deduction)
|
|
join b in chargePayQueryable on a.Id equals b.CardBillId into bb
|
|
from ab in bb.DefaultIfEmpty()
|
|
join c in chargeQueryable on ab.ChargeId equals c.Id into cc
|
|
from ac in cc.DefaultIfEmpty()
|
|
join d in userQueryable on a.CreatorId equals d.Id into dd
|
|
from ad in dd.DefaultIfEmpty()
|
|
join e in userQueryable on a.LastModifierId equals e.Id into ee
|
|
from ae in ee.DefaultIfEmpty()
|
|
select new CardBillInChargeDto
|
|
{
|
|
BillFlag = a.BillFlag,
|
|
CardRegisterId = a.CardRegisterId,
|
|
BillMoney = a.BillMoney,
|
|
ConcurrencyStamp = a.ConcurrencyStamp,
|
|
PayModeId = a.PayModeId,
|
|
InvoiceNo = ac != null ? Convert.ToString(ac.InvoiceNo) : string.Empty,
|
|
CreationTime = a.CreationTime,
|
|
CreatorName = ad != null ? ad.UserName : string.Empty,
|
|
LastModificationTime = a.LastModificationTime,
|
|
LastModifierName = ae != null ? ae.UserName : string.Empty
|
|
};
|
|
|
|
var queryChargeBack = from a in cardBillQueryable.Where(m => m.CardRegisterId == CardRegisterId && m.BillFlag == CardBillFlag.Refund)
|
|
join b in chargeBackPayQueryable on a.Id equals b.CardBillId into bb
|
|
from ab in bb.DefaultIfEmpty()
|
|
join c in chargeBackQueryable on ab.ChargeBackId equals c.Id into cc
|
|
from ac in cc.DefaultIfEmpty()
|
|
join d in chargeQueryable on ac.ChargeId equals d.Id into dd
|
|
from ad in dd.DefaultIfEmpty()
|
|
join e in userQueryable on a.CreatorId equals e.Id into ee
|
|
from ae in ee.DefaultIfEmpty()
|
|
join f in userQueryable on a.LastModifierId equals f.Id into ff
|
|
from af in ff.DefaultIfEmpty()
|
|
select new CardBillInChargeDto
|
|
{
|
|
BillFlag = a.BillFlag,
|
|
CardRegisterId = a.CardRegisterId,
|
|
BillMoney = a.BillMoney,
|
|
ConcurrencyStamp = a.ConcurrencyStamp,
|
|
PayModeId = a.PayModeId,
|
|
InvoiceNo = ad != null ? Convert.ToString(ad.InvoiceNo) : string.Empty,
|
|
CreationTime = a.CreationTime,
|
|
CreatorName = ae != null ? ae.UserName : string.Empty,
|
|
LastModificationTime = a.LastModificationTime,
|
|
LastModifierName = af != null ? af.UserName : string.Empty
|
|
};
|
|
|
|
var queryReCharge = from a in cardBillQueryable.Where(m => m.CardRegisterId == CardRegisterId && m.BillFlag == CardBillFlag.Charge)
|
|
join d in userQueryable on a.CreatorId equals d.Id into dd
|
|
from ad in dd.DefaultIfEmpty()
|
|
join e in userQueryable on a.LastModifierId equals e.Id into ee
|
|
from ae in ee.DefaultIfEmpty()
|
|
select new CardBillInChargeDto
|
|
{
|
|
BillFlag = a.BillFlag,
|
|
CardRegisterId = a.CardRegisterId,
|
|
BillMoney = a.BillMoney,
|
|
ConcurrencyStamp = a.ConcurrencyStamp,
|
|
PayModeId = a.PayModeId,
|
|
InvoiceNo = string.Empty,
|
|
CreationTime = a.CreationTime,
|
|
CreatorName = ad != null ? ad.UserName : string.Empty,
|
|
LastModificationTime = a.LastModificationTime,
|
|
LastModifierName = ae != null ? ae.UserName : string.Empty
|
|
};
|
|
|
|
var queryAll = queryCharge.Union(queryChargeBack).Union(queryReCharge);
|
|
|
|
return queryAll.ToList();
|
|
}
|
|
}
|
|
}
|