LqCardTransferLogService.cs
8.79 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NCC.Common.Core.Manager;
using NCC.Common.Filter;
using NCC.Dependency;
using NCC.DynamicApiController;
using NCC.Extend.Entitys.Dto.LqCardTransferLog;
using NCC.Extend.Entitys.lq_card_transfer_log;
using NCC.Extend.Entitys.lq_hytk_hytk;
using NCC.Extend.Entitys.lq_khxx;
using NCC.Extend.Interfaces;
using NCC.Extend.Interfaces.BusinessOperationLog;
using NCC.FriendlyException;
using NCC.System.Entitys.Permission;
using SqlSugar;
using Yitter.IdGenerator;
namespace NCC.Extend.LqCardTransferLog
{
/// <summary>
/// 转卡日志服务
/// </summary>
[ApiDescriptionSettings(Tag = "绿纤转卡日志服务", Name = "LqCardTransferLog", Order = 200)]
[Route("api/Extend/[controller]")]
public class LqCardTransferLogService : IDynamicApiController, ILqCardTransferLogService, ITransient
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
private readonly ILogger<LqCardTransferLogService> _logger;
private readonly IBusinessOperationLogService _businessOperationLogService;
private const string BizLogModuleTransferCard = "会员转卡";
public LqCardTransferLogService(
ISqlSugarClient db,
IUserManager userManager,
ILogger<LqCardTransferLogService> logger,
IBusinessOperationLogService businessOperationLogService)
{
_db = db;
_userManager = userManager;
_logger = logger;
_businessOperationLogService = businessOperationLogService;
}
#region 添加转卡日志
/// <summary>
/// 添加转卡日志
/// </summary>
/// <param name="input">转卡日志创建输入参数</param>
/// <returns>创建结果</returns>
[HttpPost("add")]
public async Task<dynamic> AddTransferLog([FromBody] LqCardTransferLogCrInput input)
{
try
{
if (input == null)
{
throw NCCException.Oh("输入参数不能为空");
}
var entity = new LqCardTransferLogEntity
{
Id = YitIdHelper.NextId().ToString(),
RefundCardId = input.refundCardId,
BillingCardId = input.billingCardId,
TransferFromMemberId = input.transferFromMemberId,
TransferToMemberId = input.transferToMemberId,
TransferAmount = input.transferAmount,
TransferTime = input.transferTime,
OperatorId = input.operatorId,
Remarks = input.remarks ?? "",
CreateTime = DateTime.Now,
IsEffective = 1
};
var result = await _db.Insertable(entity).ExecuteCommandAsync();
await TryWriteBizLogAsync(
"新增转卡",
"lq_card_transfer_log",
entity.Id,
$"新增转卡记录 {entity.Id},转出 {input.transferFromMemberId} → 转入 {input.transferToMemberId},金额 {input.transferAmount}",
Newtonsoft.Json.JsonConvert.SerializeObject(new
{
after = new
{
entity.Id,
entity.RefundCardId,
entity.BillingCardId,
entity.TransferFromMemberId,
entity.TransferToMemberId,
entity.TransferAmount,
entity.TransferTime,
entity.Remarks
}
}));
return new
{
Success = true,
Message = "转卡日志创建成功",
Data = new { Id = entity.Id }
};
}
catch (Exception ex)
{
throw NCCException.Oh($"创建转卡日志失败: {ex.Message}");
}
}
#endregion
#region 获取转卡日志列表
/// <summary>
/// 获取转卡日志列表
/// </summary>
/// <param name="input">查询输入参数</param>
/// <returns>转卡日志列表</returns>
[HttpGet("")]
public async Task<dynamic> GetList([FromQuery] LqCardTransferLogListQueryInput input)
{
try
{
var result = await _db.Queryable<LqCardTransferLogEntity>()
.WhereIF(input.isEffective != 0, x => x.IsEffective == input.isEffective)
.WhereIF(!string.IsNullOrEmpty(input.transferFromMemberId), x => x.TransferFromMemberId == input.transferFromMemberId)
.WhereIF(!string.IsNullOrEmpty(input.transferToMemberId), x => x.TransferToMemberId == input.transferToMemberId)
.WhereIF(!string.IsNullOrEmpty(input.operatorId), x => x.OperatorId == input.operatorId)
.WhereIF(input.transferStartTime.HasValue, x => x.TransferTime >= input.transferStartTime.Value)
.WhereIF(input.transferEndTime.HasValue, x => x.TransferTime <= input.transferEndTime.Value)
.WhereIF(input.minTransferAmount.HasValue, x => x.TransferAmount >= input.minTransferAmount.Value)
.WhereIF(input.maxTransferAmount.HasValue, x => x.TransferAmount <= input.maxTransferAmount.Value)
.WhereIF(!string.IsNullOrEmpty(input.keyword), x =>
x.Id.Contains(input.keyword)
|| x.RefundCardId.Contains(input.keyword)
|| x.BillingCardId.Contains(input.keyword)
|| x.Remarks.Contains(input.keyword)
|| SqlFunc.Subqueryable<LqKhxxEntity>()
.Where(m => m.Id == x.TransferFromMemberId && m.Khmc.Contains(input.keyword)).Any()
|| SqlFunc.Subqueryable<LqKhxxEntity>()
.Where(m => m.Id == x.TransferToMemberId && m.Khmc.Contains(input.keyword)).Any())
.WhereIF(!string.IsNullOrEmpty(input.storeId), x => SqlFunc.Subqueryable<LqHytkHytkEntity>()
.Where(r => r.Id == x.RefundCardId && r.Md == input.storeId).Any())
.Select(x => new LqCardTransferLogListOutput
{
id = x.Id,
refundCardId = x.RefundCardId,
billingCardId = x.BillingCardId,
transferFromMemberId = x.TransferFromMemberId,
transferFromMemberName = SqlFunc.Subqueryable<LqKhxxEntity>()
.Where(m => m.Id == x.TransferFromMemberId).Select(m => m.Khmc),
transferToMemberId = x.TransferToMemberId,
transferToMemberName = SqlFunc.Subqueryable<LqKhxxEntity>()
.Where(m => m.Id == x.TransferToMemberId).Select(m => m.Khmc),
transferAmount = x.TransferAmount,
transferTime = x.TransferTime,
operatorId = x.OperatorId,
operatorName = SqlFunc.Subqueryable<UserEntity>()
.Where(u => u.Id == x.OperatorId).Select(u => u.RealName),
remarks = x.Remarks,
createTime = x.CreateTime,
updateTime = x.UpdateTime,
isEffective = x.IsEffective
})
.OrderBy(x => x.transferTime, OrderByType.Desc)
.ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<LqCardTransferLogListOutput>.SqlSugarPageResult(result);
}
catch (Exception ex)
{
throw NCCException.Oh($"获取转卡日志列表失败: {ex.Message}");
}
}
#endregion
private async Task TryWriteBizLogAsync(
string actionCode,
string bizType,
string bizId,
string summary,
string detailJson)
{
try
{
await _businessOperationLogService.WriteAsync(
BizLogModuleTransferCard,
actionCode,
bizType,
bizId,
summary,
detailJson);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "写入会员转卡业务操作日志失败 action={Action}", actionCode);
}
}
}
}