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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
  4. using Microsoft.EntityFrameworkCore;
  5. using Shentun.Peis.Enums;
  6. using Shentun.Peis.Models;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Linq.Dynamic.Core;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Volo.Abp;
  14. using Volo.Abp.Application.Services;
  15. using Volo.Abp.Domain.Repositories;
  16. using Volo.Abp.Identity;
  17. namespace Shentun.Peis.CardBills
  18. {
  19. [ApiExplorerSettings(GroupName = "Work")]
  20. [Authorize]
  21. public class CardBillAppService : ApplicationService
  22. {
  23. private readonly IRepository<CardBill, Guid> _cardBillRepository;
  24. private readonly IRepository<IdentityUser, Guid> _userRepository;
  25. private readonly IRepository<Charge, Guid> _chargeRepository;
  26. private readonly IRepository<ChargeBack, Guid> _chargeBackRepository;
  27. private readonly IRepository<ChargeBackPay> _chargeBackPayRepository;
  28. private readonly IRepository<ChargePay> _chargePayRepository;
  29. public CardBillAppService(
  30. IRepository<CardBill, Guid> cardBillRepository,
  31. IRepository<IdentityUser, Guid> userRepository,
  32. IRepository<Charge, Guid> chargeRepository,
  33. IRepository<ChargeBack, Guid> chargeBackRepository,
  34. IRepository<ChargeBackPay> chargeBackPayRepository,
  35. IRepository<ChargePay> chargePayRepository
  36. )
  37. {
  38. this._cardBillRepository = cardBillRepository;
  39. this._userRepository = userRepository;
  40. this._chargeRepository = chargeRepository;
  41. this._chargeBackRepository = chargeBackRepository;
  42. this._chargeBackPayRepository = chargeBackPayRepository;
  43. this._chargePayRepository = chargePayRepository;
  44. }
  45. /// <summary>
  46. /// 获取全部卡记录列表 带联合搜索条件
  47. /// </summary>
  48. /// <param name="input"></param>
  49. /// <returns></returns>
  50. /// <exception cref="UserFriendlyException"></exception>
  51. [HttpPost("api/app/cardbill/getcardbilllist")]
  52. public async Task<List<CardBillDto>> GetCardBillListAsync(GetCardBillListDto input)
  53. {
  54. if (input != null)
  55. {
  56. var queryable = (await _cardBillRepository.GetDbSetAsync())
  57. .Include(x => x.CardRegister)
  58. .Include(x => x.CardRegister.CardType).AsQueryable();
  59. if (!string.IsNullOrEmpty(input.CardNo))
  60. {
  61. queryable = queryable.Where(m => m.CardRegister.CardNo == input.CardNo);
  62. }
  63. if (!string.IsNullOrEmpty(input.IdNo))
  64. {
  65. queryable = queryable.Where(m => m.CardRegister.IdNo == input.IdNo);
  66. }
  67. if (!string.IsNullOrEmpty(input.CustomerName))
  68. {
  69. queryable = queryable.Where(m => !string.IsNullOrEmpty(m.CardRegister.CustomerName) &&
  70. m.CardRegister.CustomerName.Contains(input.CustomerName));
  71. }
  72. if (!string.IsNullOrEmpty(input.Phone))
  73. {
  74. queryable = queryable.Where(m => (!string.IsNullOrEmpty(m.CardRegister.Telephone) &&
  75. m.CardRegister.Telephone.Contains(input.Phone)) || !string.IsNullOrEmpty(m.CardRegister.MobileTelephone) &&
  76. m.CardRegister.MobileTelephone.Contains(input.Phone));
  77. }
  78. //if (!string.IsNullOrEmpty(input.MobileTelephone))
  79. //{
  80. // queryable = queryable.Where(m => !string.IsNullOrEmpty(m.CardRegister.MobileTelephone) &&
  81. // m.CardRegister.MobileTelephone.Contains(input.MobileTelephone));
  82. //}
  83. if (input.BillFlag != null)
  84. {
  85. queryable = queryable.Where(m => m.BillFlag == input.BillFlag);
  86. }
  87. if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate))
  88. {
  89. queryable = queryable.Where(m => m.CreationTime >= Convert.ToDateTime(input.StartDate) &&
  90. m.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
  91. }
  92. var userlist = await _userRepository.GetListAsync();
  93. var entlist = queryable.Select(s => new CardBillDto
  94. {
  95. BillFlag = s.BillFlag,
  96. BillMoney = s.BillMoney,
  97. MobileTelephone = s.CardRegister.MobileTelephone,
  98. CardBalance = s.CardRegister.CardBalance,
  99. CardFlag = s.CardRegister.IsActive,
  100. CardNo = s.CardRegister.CardNo,
  101. CardPassword = s.CardRegister.CardPassword,
  102. CardRegisterId = s.CardRegisterId,
  103. CardTypeId = s.CardRegister.CardTypeId,
  104. CardTypeName = s.CardRegister.CardType.DisplayName,
  105. ConcurrencyStamp = s.ConcurrencyStamp,
  106. CreationTime = s.CreationTime,
  107. CreatorId = s.CreatorId,
  108. CustomerName = s.CardRegister.CustomerName,
  109. Discount = s.CardRegister.Discount,
  110. ExpiryDate = s.CardRegister.ExpiryDate.ToString(),
  111. Id = s.Id,
  112. IdNo = s.CardRegister.IdNo,
  113. LastModificationTime = s.LastModificationTime,
  114. LastModifierId = s.LastModifierId,
  115. OrganizationUnitId = s.CardRegister.OrganizationUnitId,
  116. PayModeId = s.PayModeId,
  117. Remark = s.CardRegister.Remark,
  118. Telephone = s.CardRegister.Telephone,
  119. CreatorName = EntityHelper.GetUserNameNoSql(userlist, s.CreatorId),
  120. LastModifierName = EntityHelper.GetUserNameNoSql(userlist, s.LastModifierId)
  121. }).ToList();
  122. return entlist;
  123. }
  124. else
  125. {
  126. throw new UserFriendlyException("参数有误");
  127. }
  128. }
  129. /// <summary>
  130. /// 获取卡记录列表 根据会员卡ID
  131. /// </summary>
  132. /// <param name="CardRegisterId"></param>
  133. /// <returns></returns>
  134. /// <exception cref="UserFriendlyException"></exception>
  135. [HttpPost("api/app/cardbill/getcardbilllistincardregisterid")]
  136. public async Task<List<CardBillInChargeDto>> GetCardBillListInCardRegisterIdAsync(Guid CardRegisterId)
  137. {
  138. var chargeQueryable = await _chargeRepository.GetQueryableAsync();
  139. var chargePayQueryable = await _chargePayRepository.GetQueryableAsync();
  140. var cardBillQueryable = await _cardBillRepository.GetQueryableAsync();
  141. var chargeBackQueryable = await _chargeBackRepository.GetQueryableAsync();
  142. var chargeBackPayQueryable = await _chargeBackPayRepository.GetQueryableAsync();
  143. var userQueryable = await _userRepository.GetQueryableAsync();
  144. var queryCharge = from a in cardBillQueryable.Where(m => m.CardRegisterId == CardRegisterId && m.BillFlag ==CardBillFlag.Deduction)
  145. join b in chargePayQueryable on a.Id equals b.CardBillId into bb
  146. from ab in bb.DefaultIfEmpty()
  147. join c in chargeQueryable on ab.ChargeId equals c.Id into cc
  148. from ac in cc.DefaultIfEmpty()
  149. join d in userQueryable on a.CreatorId equals d.Id into dd
  150. from ad in dd.DefaultIfEmpty()
  151. join e in userQueryable on a.LastModifierId equals e.Id into ee
  152. from ae in ee.DefaultIfEmpty()
  153. select new CardBillInChargeDto
  154. {
  155. BillFlag = a.BillFlag,
  156. CardRegisterId = a.CardRegisterId,
  157. BillMoney = a.BillMoney,
  158. ConcurrencyStamp = a.ConcurrencyStamp,
  159. PayModeId = a.PayModeId,
  160. InvoiceNo = ac != null ? Convert.ToString(ac.InvoiceNo) : string.Empty,
  161. CreationTime = a.CreationTime,
  162. CreatorName = ad != null ? ad.UserName : string.Empty,
  163. LastModificationTime = a.LastModificationTime,
  164. LastModifierName = ae != null ? ae.UserName : string.Empty
  165. };
  166. var queryChargeBack = from a in cardBillQueryable.Where(m => m.CardRegisterId == CardRegisterId && m.BillFlag == CardBillFlag.Refund)
  167. join b in chargeBackPayQueryable on a.Id equals b.CardBillId into bb
  168. from ab in bb.DefaultIfEmpty()
  169. join c in chargeBackQueryable on ab.ChargeBackId equals c.Id into cc
  170. from ac in cc.DefaultIfEmpty()
  171. join d in chargeQueryable on ac.ChargeId equals d.Id into dd
  172. from ad in dd.DefaultIfEmpty()
  173. join e in userQueryable on a.CreatorId equals e.Id into ee
  174. from ae in ee.DefaultIfEmpty()
  175. join f in userQueryable on a.LastModifierId equals f.Id into ff
  176. from af in ff.DefaultIfEmpty()
  177. select new CardBillInChargeDto
  178. {
  179. BillFlag = a.BillFlag,
  180. CardRegisterId = a.CardRegisterId,
  181. BillMoney = a.BillMoney,
  182. ConcurrencyStamp = a.ConcurrencyStamp,
  183. PayModeId = a.PayModeId,
  184. InvoiceNo = ad != null ? Convert.ToString(ad.InvoiceNo) : string.Empty,
  185. CreationTime = a.CreationTime,
  186. CreatorName = ae != null ? ae.UserName : string.Empty,
  187. LastModificationTime = a.LastModificationTime,
  188. LastModifierName = af != null ? af.UserName : string.Empty
  189. };
  190. var queryReCharge = from a in cardBillQueryable.Where(m => m.CardRegisterId == CardRegisterId && m.BillFlag == CardBillFlag.Charge)
  191. join d in userQueryable on a.CreatorId equals d.Id into dd
  192. from ad in dd.DefaultIfEmpty()
  193. join e in userQueryable on a.LastModifierId equals e.Id into ee
  194. from ae in ee.DefaultIfEmpty()
  195. select new CardBillInChargeDto
  196. {
  197. BillFlag = a.BillFlag,
  198. CardRegisterId = a.CardRegisterId,
  199. BillMoney = a.BillMoney,
  200. ConcurrencyStamp = a.ConcurrencyStamp,
  201. PayModeId = a.PayModeId,
  202. InvoiceNo = string.Empty,
  203. CreationTime = a.CreationTime,
  204. CreatorName = ad != null ? ad.UserName : string.Empty,
  205. LastModificationTime = a.LastModificationTime,
  206. LastModifierName = ae != null ? ae.UserName : string.Empty
  207. };
  208. var queryAll = queryCharge.Union(queryChargeBack).Union(queryReCharge);
  209. return queryAll.ToList();
  210. }
  211. }
  212. }