1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Context;
using Entity;
using Microsoft.EntityFrameworkCore;
using Model.Dtos;
using Model.Params;
using Repository;
namespace Service
{
/// <summary>
/// 发票相关
/// </summary>
public class BillService : IService
{
private IUnitOfWork _unitOfWork;
private IRepository<TB_SignUp> _signupRepository;
private IRepository<TB_Bill> _billRepository;
private IRepository<TB_BillDetail> _billDetailRepository;
private IRepository<TB_Xq_BatchList> _xqbatchlistRepository;
private IRepository<CPM_SettleDetail> _settledetailRepository;
private IRepository<CPM_SettleContent> _settlecontentRepository;
public BillService(IUnitOfWork unitOfWork, IRepository<TB_Bill> billRepository, IRepository<TB_BillDetail> billDetailRepository,
IRepository<TB_Xq_BatchList> xqbatchlistRepository, IRepository<TB_SignUp> signupRepository,
IRepository<CPM_SettleDetail> settledetailRepository, IRepository<CPM_SettleContent> settlecontentRepository)
{
_unitOfWork = unitOfWork;
_billRepository = billRepository;
_billDetailRepository = billDetailRepository;
_xqbatchlistRepository = xqbatchlistRepository;
_signupRepository = signupRepository;
_settledetailRepository = settledetailRepository;
_settlecontentRepository = settlecontentRepository;
}
public async Task<TB_Bill?> GetBill(string orderid)
{
return await _billRepository.Entities.FirstOrDefaultAsync(p => p.OrderID == orderid);
}
public async Task<TB_Bill?> GetBillBySignId(string signId)
{
return await (from s in _signupRepository.Entities
join b in _billRepository.Entities
on s.SignNo equals b.OrderID
where s.ID == signId
select b).FirstOrDefaultAsync();
}
public IQueryable<SignupInfoDTO> QueryBatchSignupBills(long batchid)
{
var query = from bl in _xqbatchlistRepository.Entities
join s in _signupRepository.Entities on bl.SignupID equals s.ID
join b in _billRepository.Entities on s.SignNo equals b.OrderID
where bl.IsDeleted == false && b.IsDeleted == false
&& bl.BatchID == batchid
select new SignupInfoDTO
{
SignNo = bl.PrmSignNo,
BillPic = b.BillPic,
};
return query;
}
public IQueryable<GetStudioBillsResult> QueryStudioBills(GetStudioBillsParam param)
{
var query = from s in _signupRepository.Entities
join b in _billRepository.Entities on s.SignNo equals b.OrderID
join sd in _settledetailRepository.Entities on s.SettleDetailID equals sd.ID
where s.PCID == param.StudioID && s.IsDeleted == false && s.Status == 3
select new GetStudioBillsResult
{
StudioID = param.StudioID,
StudioName = s.PCName,
BillPic = b.BillPic,
BillStatus = b.MakeStatus ? 2 : 1,
SettleTime = s.PassQualifiedTime,
BillType = b.BillType,
CompanyName = s.CompanyName,
CompanyUserID = s.CompanyId,
////CustomerServiceBillDetail = sd.CustomerServiceBillDetail,
////CustomerServiceMoney = sd.CustomerServiceMoney,
////MarketingExpansionBillDetail = sd.MarketingExpansionBillDetail,
////MarketingExpansionMoney = sd.MarketingExpansionMoney,
////MarketingServiceBillDetail = sd.MarketingServiceBillDetail,
////MarketingServiceMoney = sd.MarketingServiceMoney,
Money = b.Money,
GroupID = sd.GroupID
};
if (param.CompanyUserIDs != null && param.CompanyUserIDs.Any())
{
var companyUserIDs = param.CompanyUserIDs;
query = query.Where(q => companyUserIDs.Contains(q.CompanyUserID));
}
if (param.BeginTime.HasValue)
{
var btv = param.BeginTime.Value;
query = query.Where(q => q.SettleTime >= btv);
}
if (param.EndTime.HasValue)
{
var etv = param.EndTime.Value.AddDays(1);
query = query.Where(q => q.SettleTime < etv);
}
if (param.BeginMoney.HasValue)
{
var btm = param.BeginMoney.Value;
query = query.Where(q => q.Money >= btm);
}
if (param.EndMoney.HasValue)
{
var etm = param.EndMoney.Value;
query = query.Where(q => q.Money <= etm);
}
if (param.BillStatus == 1)
{
query = query.Where(q => q.BillStatus == 1);
}
else if (param.BillStatus == 2)
{
query = query.Where(q => q.BillStatus == 2);
}
return query;
}
/// <summary>
/// 查询服务内容
/// </summary>
/// <param name="groupids"></param>
/// <returns></returns>
public List<CPM_SettleContent> GetContents(List<string> groupids)
{
return _settlecontentRepository.Entities.Where(c => groupids.Contains(c.GroupID)).ToList();
}
}
}