feat 添加客户用户名登录功能

This commit is contained in:
Abbh1 2023-11-22 12:17:14 +08:00
parent da5f4be16f
commit 9b8b05bc05
13 changed files with 489 additions and 36 deletions

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using ARW.Model.Models.Business.Custom.CustomerLoginLogs;
namespace ARW.Model.Dto.Business.Custom.CustomerLoginLogs
{
/// <summary>
/// 客户登录日志输入对象
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
public class CustomerLoginLogDto
{
public int CustomerLoginLogId { get; set; }
public long CustomerLoginLogGuid { get; set; }
[Required(ErrorMessage = "客户guid不能为空")]
public long CustomerGuid { get; set; }
}
/// <summary>
/// 客户登录日志查询对象
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
public class CustomerLoginLogQueryDto : PagerInfo
{
[Required(ErrorMessage = "客户guid不能为空")]
public long CustomerGuid { get; set; }
public string ids { get; set; }
}
}

View File

@ -26,8 +26,8 @@ namespace ARW.Model.Dto.Business.Custom.Customers
public long? CustomerMemberLevelGuid { get; set; } public long? CustomerMemberLevelGuid { get; set; }
[Required(ErrorMessage = "小程序openid不能为空")]
public string CustomerXcxOpenid { get; set; } public string CustomerXcxOpenid { get; set; }
public string CustomerPassword { get; set; }
public string CustomerType { get; set; } public string CustomerType { get; set; }
@ -46,19 +46,14 @@ namespace ARW.Model.Dto.Business.Custom.Customers
[Required(ErrorMessage = "性别不能为空")] [Required(ErrorMessage = "性别不能为空")]
public int CustomerGender { get; set; } public int CustomerGender { get; set; }
[Required(ErrorMessage = "可用余额不能为空")]
public decimal CustomerAvailableBalance { get; set; } public decimal CustomerAvailableBalance { get; set; }
[Required(ErrorMessage = "可用积分不能为空")]
public decimal CustomerAvailablePoints { get; set; } public decimal CustomerAvailablePoints { get; set; }
[Required(ErrorMessage = "总支付金额不能为空")]
public decimal CustomerTotalPaymentAmount { get; set; } public decimal CustomerTotalPaymentAmount { get; set; }
[Required(ErrorMessage = "实际消费金额不能为空")]
public decimal CustomerActualConsumptionAmount { get; set; } public decimal CustomerActualConsumptionAmount { get; set; }
[Required(ErrorMessage = "最后登录时间不能为空")]
public DateTime? CustomerLastLoginTime { get; set; } public DateTime? CustomerLastLoginTime { get; set; }
@ -109,6 +104,11 @@ namespace ARW.Model.Dto.Business.Custom.Customers
/// </summary> /// </summary>
public string CustomerXcxOpenid { get; set; } public string CustomerXcxOpenid { get; set; }
public string CustomerNickname { get; set; }
public string CustomerPassword { get; set; }
} }

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using SqlSugar;
using OfficeOpenXml.Attributes;
using Newtonsoft.Json;
namespace ARW.Model.Models.Business.Custom.CustomerLoginLogs
{
/// <summary>
/// 客户登录日志,数据实体对象
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
[SugarTable("tb_customer_login_log")]
public class CustomerLoginLog : BusinessBase
{
/// <summary>
/// 描述 :
/// 空值 : false
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "customer_login_log_id")]
public int CustomerLoginLogId { get; set; }
/// <summary>
/// 描述 :
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "customer_login_log_guid")]
public long CustomerLoginLogGuid { get; set; }
/// <summary>
/// 描述 :客户guid
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "customer_guid")]
public long CustomerGuid { get; set; }
}
}

View File

@ -117,6 +117,15 @@ namespace ARW.Model.Models.Business.Custom.Customers
[SugarColumn(ColumnName = "customer_mobile_phone_number")] [SugarColumn(ColumnName = "customer_mobile_phone_number")]
public string CustomerMobilePhoneNumber { get; set; } public string CustomerMobilePhoneNumber { get; set; }
/// <summary>
/// 描述 :密码
/// 空值 : false
/// </summary>
[EpplusTableColumn(Header = "密码")]
[SugarColumn(ColumnName = "customer_password")]
public string CustomerPassword { get; set; }
/// <summary> /// <summary>
/// 描述 :电子邮箱 /// 描述 :电子邮箱
/// 空值 : false /// 空值 : false

View File

@ -0,0 +1,48 @@
using Newtonsoft.Json;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
namespace ARW.Model.Vo.Business.Custom.CustomerLoginLogs
{
/// <summary>
/// 客户登录日志展示对象
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
public class CustomerLoginLogVo
{
/// <summary>
/// 描述 :
/// </summary>
public int CustomerLoginLogId { get; set; }
/// <summary>
/// 描述 :
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long CustomerLoginLogGuid { get; set; }
/// <summary>
/// 描述 :客户guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long CustomerGuid { get; set; }
/// <summary>
/// 用户名称
/// </summary>
public string CustomerNickName { get; set; }
/// <summary>
/// 登录时间
/// </summary>
public DateTime CreateTime { get; set; }
}
}

View File

@ -80,32 +80,39 @@ namespace ARW.Model.Vo.Business.Custom.Customers
[EpplusTableColumn(Header = "性别")] [EpplusTableColumn(Header = "性别")]
public int CustomerGender { get; set; } public int CustomerGender { get; set; }
/// <summary>
/// 描述 :密码
/// </summary>
[EpplusIgnore]
public string CustomerPassword { get; set; }
/// <summary> /// <summary>
/// 描述 :可用余额 /// 描述 :可用余额
/// </summary> /// </summary>
[EpplusTableColumn(Header = "可用余额")] [EpplusIgnore]
public decimal CustomerAvailableBalance { get; set; } public decimal CustomerAvailableBalance { get; set; }
/// <summary> /// <summary>
/// 描述 :可用积分 /// 描述 :可用积分
/// </summary> /// </summary>
[EpplusTableColumn(Header = "可用积分")] [EpplusIgnore]
public decimal CustomerAvailablePoints { get; set; } public decimal CustomerAvailablePoints { get; set; }
/// <summary> /// <summary>
/// 描述 :总支付金额 /// 描述 :总支付金额
/// </summary> /// </summary>
[EpplusTableColumn(Header = "总支付金额")] [EpplusIgnore]
public decimal CustomerTotalPaymentAmount { get; set; } public decimal CustomerTotalPaymentAmount { get; set; }
/// <summary> /// <summary>
/// 描述 :实际消费金额 /// 描述 :实际消费金额
/// </summary> /// </summary>
[EpplusTableColumn(Header = "实际消费金额")] [EpplusIgnore]
public decimal CustomerActualConsumptionAmount { get; set; } public decimal CustomerActualConsumptionAmount { get; set; }

View File

@ -0,0 +1,20 @@
using System;
using Infrastructure.Attribute;
using ARW.Repository.System;
using ARW.Model.Models.Business.Custom.CustomerLoginLogs;
namespace ARW.Repository.Business.Custom.CustomerLoginLogs
{
/// <summary>
/// 客户登录日志仓储
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
[AppService(ServiceLifetime = LifeTime.Transient)]
public class CustomerLoginLogRepository : BaseRepository<CustomerLoginLog>
{
#region
#endregion
}
}

View File

@ -0,0 +1,95 @@
using Infrastructure.Attribute;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Infrastructure;
using ARW.Model;
using ARW.Repository;
using ARW.Repository.Business.Custom.CustomerLoginLogs;
using ARW.Service.Business.IBusinessService.Custom.CustomerLoginLogs;
using ARW.Model.Dto.Business.Custom.CustomerLoginLogs;
using ARW.Model.Models.Business.Custom.CustomerLoginLogs;
using ARW.Model.Vo.Business.Custom.CustomerLoginLogs;
using ARW.Model.Models.Business.Custom.Customers;
namespace ARW.Service.Business.BusinessService.Custom.CustomerLoginLogs
{
/// <summary>
/// 客户登录日志接口实现类
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
[AppService(ServiceType = typeof(ICustomerLoginLogService), ServiceLifetime = LifeTime.Transient)]
public class CustomerLoginLogServiceImpl : BaseService<CustomerLoginLog>, ICustomerLoginLogService
{
private readonly CustomerLoginLogRepository _CustomerLoginLogRepository;
public CustomerLoginLogServiceImpl(CustomerLoginLogRepository CustomerLoginLogRepository)
{
this._CustomerLoginLogRepository = CustomerLoginLogRepository;
}
#region
/// <summary>
/// 查询客户登录日志分页列表
/// </summary>
public async Task<PagedInfo<CustomerLoginLogVo>> GetCustomerLoginLogList(CustomerLoginLogQueryDto parm)
{
//开始拼装查询条件d
var predicate = Expressionable.Create<CustomerLoginLog>();
predicate = predicate.AndIF(parm.CustomerGuid != 0, s => s.CustomerGuid == parm.CustomerGuid);
var query = _CustomerLoginLogRepository
.Queryable()
.LeftJoin<Customer>((s, c) => s.CustomerGuid == c.CustomerGuid)
.Where(predicate.ToExpression())
.OrderBy(s => s.Create_time, OrderByType.Desc)
.Select((s, c) => new CustomerLoginLogVo
{
CustomerLoginLogId = s.CustomerLoginLogId,
CustomerLoginLogGuid = s.CustomerLoginLogGuid,
CustomerGuid = s.CustomerGuid,
CreateTime = s.Create_time,
CustomerNickName = c.CustomerNickname
});
return await query.ToPageAsync(parm);
}
/// <summary>
/// 添加或修改客户登录日志
/// </summary>
public async Task<string> AddOrUpdateCustomerLoginLog(CustomerLoginLog model)
{
if (model.CustomerLoginLogId != 0)
{
var response = await _CustomerLoginLogRepository.UpdateAsync(model);
return "修改成功!";
}
else
{
var response = await _CustomerLoginLogRepository.InsertReturnSnowflakeIdAsync(model);
return "添加成功!";
}
}
#region Excel处理
#endregion
#endregion
}
}

View File

@ -14,6 +14,9 @@ using ARW.Model.Models.Business.Custom.Customers;
using ARW.Model.Vo.Business.Custom.Customers; using ARW.Model.Vo.Business.Custom.Customers;
using ARW.Repository.Business.Custom.Customers; using ARW.Repository.Business.Custom.Customers;
using ARW.Service.Business.IBusinessService.Custom.Customers; using ARW.Service.Business.IBusinessService.Custom.Customers;
using ARW.Common;
using System.Security.Cryptography;
using ARW.Model.System;
namespace ARW.Service.Business.BusinessService.Custom.Customers namespace ARW.Service.Business.BusinessService.Custom.Customers
{ {
@ -67,6 +70,7 @@ namespace ARW.Service.Business.BusinessService.Custom.Customers
CustomerTotalPaymentAmount = s.CustomerTotalPaymentAmount, CustomerTotalPaymentAmount = s.CustomerTotalPaymentAmount,
CustomerActualConsumptionAmount = s.CustomerActualConsumptionAmount, CustomerActualConsumptionAmount = s.CustomerActualConsumptionAmount,
CustomerLastLoginTime = s.CustomerLastLoginTime, CustomerLastLoginTime = s.CustomerLastLoginTime,
CustomerPassword = s.CustomerPassword
}); });
@ -78,6 +82,8 @@ namespace ARW.Service.Business.BusinessService.Custom.Customers
/// </summary> /// </summary>
public async Task<string> AddOrUpdateCustomer(Customer model) public async Task<string> AddOrUpdateCustomer(Customer model)
{ {
//密码md5
model.CustomerPassword = NETCore.Encrypt.EncryptProvider.Md5(model.CustomerPassword);
if (model.CustomerId != 0) if (model.CustomerId != 0)
{ {
var response = await _CustomerRepository.UpdateAsync(model); var response = await _CustomerRepository.UpdateAsync(model);
@ -85,7 +91,6 @@ namespace ARW.Service.Business.BusinessService.Custom.Customers
} }
else else
{ {
var response = await _CustomerRepository.InsertReturnSnowflakeIdAsync(model); var response = await _CustomerRepository.InsertReturnSnowflakeIdAsync(model);
return "添加成功!"; return "添加成功!";
} }

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ARW.Model;
using ARW.Model.Dto.Business.Custom.CustomerLoginLogs;
using ARW.Model.Models.Business.Custom.CustomerLoginLogs;
using ARW.Model.Vo.Business.Custom.CustomerLoginLogs;
namespace ARW.Service.Business.IBusinessService.Custom.CustomerLoginLogs
{
/// <summary>
/// 客户登录日志接口类
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
public interface ICustomerLoginLogService : IBaseService<CustomerLoginLog>
{
/// <summary>
/// 获取客户登录日志分页列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<PagedInfo<CustomerLoginLogVo>> GetCustomerLoginLogList(CustomerLoginLogQueryDto parm);
/// <summary>
/// 添加或修改客户登录日志
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<string> AddOrUpdateCustomerLoginLog(CustomerLoginLog parm);
}
}

View File

@ -18,6 +18,8 @@ using Infrastructure.Attribute;
using ARW.Service.Business.IBusinessService.Custom.Customers; using ARW.Service.Business.IBusinessService.Custom.Customers;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Aliyun.OSS; using Aliyun.OSS;
using ARW.Service.Business.IBusinessService.Custom.CustomerLoginLogs;
using ARW.Model.Models.Business.Custom.CustomerLoginLogs;
namespace ARW.WebApi.Controllers.Api.Wechat namespace ARW.WebApi.Controllers.Api.Wechat
{ {
@ -31,14 +33,16 @@ namespace ARW.WebApi.Controllers.Api.Wechat
private readonly WeChatLogin _weChat; private readonly WeChatLogin _weChat;
private readonly ICustomerService _customerService; private readonly ICustomerService _customerService;
private readonly ICustomerLoginLogService _CustomerLoginLogService;
private readonly OptionsSetting _jwtSettings; private readonly OptionsSetting _jwtSettings;
public WeChatLoginController(WeChatLogin weChat, ICustomerService customerService, IOptions<OptionsSetting> jwtSettings) public WeChatLoginController(WeChatLogin weChat, ICustomerService customerService, IOptions<OptionsSetting> jwtSettings, ICustomerLoginLogService customerLoginLogService)
{ {
_weChat = weChat; _weChat = weChat;
_customerService = customerService; _customerService = customerService;
_jwtSettings = jwtSettings.Value; _jwtSettings = jwtSettings.Value;
_CustomerLoginLogService = customerLoginLogService;
} }
/// <summary> /// <summary>
@ -55,35 +59,64 @@ namespace ARW.WebApi.Controllers.Api.Wechat
} }
var addModal = parm.Adapt<Customer>().ToCreate(HttpContext); var addModal = parm.Adapt<Customer>().ToCreate(HttpContext);
addModal.CustomerMobilePhoneNumber = await GetUserPhoneNumber(parm.Code); addModal.CustomerPassword = NETCore.Encrypt.EncryptProvider.Md5(addModal.CustomerPassword);
var user = await _customerService.GetFirstAsync(s => s.CustomerMobilePhoneNumber == addModal.CustomerMobilePhoneNumber); var user = new Customer();
if (user == null) /* 用户名密码登录 */
if (!string.IsNullOrEmpty(addModal.CustomerNickname) && !string.IsNullOrEmpty(addModal.CustomerPassword))
{ {
string appId = AppSettings.GetConfig("SenparcWeixinSetting:TenPayV3_AppId"); user = await _customerService.GetFirstAsync(s => s.CustomerNickname == addModal.CustomerNickname && s.CustomerPassword == addModal.CustomerPassword);
string appSecret = AppSettings.GetConfig("SenparcWeixinSetting:TenPayV3_AppSecret"); if (user == null) throw new CustomException("用户名或者密码错误");
//string openid = await GetOpenIDAsync(parm.CustomerXcxOpenidCode, appId, appSecret);
// 客户默认头像
addModal.CustomerAvatar = "https://cdn-we-retail.ym.tencent.com/miniapp/usercenter/icon-user-center-avatar@2x.png";
addModal.CustomerNickname = "用户" + addModal.CustomerMobilePhoneNumber.Substring(addModal.CustomerMobilePhoneNumber.Length - 4); ;
addModal.CustomerGender = 1;
addModal.CustomerType = 1;
addModal.CustomerLastLoginTime = DateTime.Now;
addModal.CustomerXcxOpenid = parm.CustomerXcxOpenid;
var response = await _customerService.InsertReturnSnowflakeIdAsync(addModal);
if (response == 0)
{
throw new CustomException("添加失败!");
}
user = await _customerService.GetFirstAsync(s => s.CustomerGuid == response);
} }
else /* 手机号登录(微信一键登录) */
if (!string.IsNullOrEmpty(parm.Code))
{ {
user.CustomerLastLoginTime = DateTime.Now; addModal.CustomerMobilePhoneNumber = await GetUserPhoneNumber(parm.Code);
user = await _customerService.GetFirstAsync(s => s.CustomerMobilePhoneNumber == addModal.CustomerMobilePhoneNumber);
} }
#region
/* 注册 */
//if (user == null)
//{
// string appId = AppSettings.GetConfig("SenparcWeixinSetting:TenPayV3_AppId");
// string appSecret = AppSettings.GetConfig("SenparcWeixinSetting:TenPayV3_AppSecret");
// //string openid = await GetOpenIDAsync(parm.CustomerXcxOpenidCode, appId, appSecret);
// // 客户默认头像
// addModal.CustomerAvatar = "https://cdn-we-retail.ym.tencent.com/miniapp/usercenter/icon-user-center-avatar@2x.png";
// addModal.CustomerNickname = "用户" + addModal.CustomerMobilePhoneNumber.Substring(addModal.CustomerMobilePhoneNumber.Length - 4); ;
// addModal.CustomerGender = 1;
// addModal.CustomerType = 1;
// addModal.CustomerLastLoginTime = DateTime.Now;
// addModal.CustomerXcxOpenid = parm.CustomerXcxOpenid;
// var response = await _customerService.InsertReturnSnowflakeIdAsync(addModal);
// if (response == 0)
// {
// throw new CustomException("添加失败!");
// }
// user = await _customerService.GetFirstAsync(s => s.CustomerGuid == response);
//}
//else
//{
// user.CustomerLastLoginTime = DateTime.Now;
//}
#endregion
var time = DateTime.Now;
// 记录最后登录时间
user.CustomerLastLoginTime = time;
await _customerService.UpdateAsync(user);
// 添加访问记录
var model = new CustomerLoginLog
{
CustomerGuid = user.CustomerGuid,
Create_time = time,
Create_by = user.CustomerNickname,
};
await _CustomerLoginLogService.AddOrUpdateCustomerLoginLog(model);
LoginUser loginUser = new LoginUser LoginUser loginUser = new LoginUser
{ {
UserId = user.CustomerGuid, UserId = user.CustomerGuid,

View File

@ -0,0 +1,98 @@
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ARW.Admin.WebApi.Extensions;
using ARW.Admin.WebApi.Filters;
using ARW.Common;
using ARW.Model.Dto.Business.Custom.CustomerLoginLogs;
using ARW.Service.Business.IBusinessService.Custom.CustomerLoginLogs;
using ARW.Admin.WebApi.Controllers;
using ARW.Model.Models.Business.Custom.CustomerLoginLogs;
using ARW.Model.Vo.Business.Custom.CustomerLoginLogs;
using Microsoft.AspNetCore.Authorization;
using ARW.Admin.WebApi.Framework;
namespace ARW.WebApi.Controllers.Business.Custom.CustomerLoginLogs
{
/// <summary>
/// 客户登录日志控制器
///
/// @author lwh
/// @date 2023-11-21
/// </summary>
[Verify]
[Route("business/[controller]")]
public class CustomerLoginLogController : BaseController
{
private readonly ICustomerLoginLogService _CustomerLoginLogService;
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="CustomerLoginLogService">客户登录日志服务</param>
public CustomerLoginLogController(ICustomerLoginLogService CustomerLoginLogService)
{
_CustomerLoginLogService = CustomerLoginLogService;
}
/// <summary>
/// 获取客户登录日志列表
/// </summary>
/// <param name="parm">查询参数</param>
/// <returns></returns>
[HttpGet("getCustomerLoginLogList")]
[ActionPermissionFilter(Permission = "business:customerloginlog:list")]
public async Task<IActionResult> GetCustomerLoginLogList([FromQuery] CustomerLoginLogQueryDto parm)
{
var res = await _CustomerLoginLogService.GetCustomerLoginLogList(parm);
return SUCCESS(res);
}
/// <summary>
/// 添加或修改客户登录日志
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpPost("addOrUpdateCustomerLoginLog")]
[ActionPermissionFilter(Permission = "business:customerloginlog:addOrUpdate")]
[Log(Title = "添加或修改客户登录日志", BusinessType = BusinessType.ADDORUPDATE)]
public async Task<IActionResult> AddOrUpdateCustomerLoginLog([FromBody] CustomerLoginLogDto parm)
{
if (parm == null) { throw new CustomException("请求参数错误"); }
var modal = new CustomerLoginLog();
if (parm.CustomerLoginLogId != 0) modal = parm.Adapt<CustomerLoginLog>().ToUpdate(HttpContext);
else modal = parm.Adapt<CustomerLoginLog>().ToCreate(HttpContext);
var res = await _CustomerLoginLogService.AddOrUpdateCustomerLoginLog(modal);
return SUCCESS(res);
}
/// <summary>
/// 删除客户登录日志
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:customerloginlog:delete")]
[Log(Title = "客户登录日志删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(string ids)
{
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _CustomerLoginLogService.Delete(idsArr);
return SUCCESS("删除成功!");
}
}
}

View File

@ -46,7 +46,7 @@
"autoPre": true, // "autoPre": true, //
"author": "admin", "author": "admin",
"tablePrefix": "tb_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)", "tablePrefix": "tb_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "D:\\.Net\\Aerwen\\key1_beacon\\key1_beacon_back" //egD:\Work\ARWAdmin-Vue3 "vuePath": "D:\\.Net\\Projects\\key1_beacon\\key1_beacon_back" //egD:\Work\ARWAdmin-Vue3
}, },
// //
"MailOptions": { "MailOptions": {