diff --git a/CoreCms.Net.Middlewares/IPLogMildd.cs b/CoreCms.Net.Middlewares/IPLogMildd.cs index 7025ea0..1bf81cd 100644 --- a/CoreCms.Net.Middlewares/IPLogMildd.cs +++ b/CoreCms.Net.Middlewares/IPLogMildd.cs @@ -95,7 +95,10 @@ namespace CoreCms.Net.Middlewares var ip = context.Request.Headers["X-Forwarded-For"].ObjectToString(); if (string.IsNullOrEmpty(ip)) { - ip = context.Connection.RemoteIpAddress.ObjectToString(); + if (context.Connection.RemoteIpAddress != null) + { + ip = context.Connection.RemoteIpAddress.MapToIPv4().ObjectToString(); + } } return ip; } diff --git a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs index d56a01e..2778385 100644 --- a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs +++ b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs @@ -409,7 +409,8 @@ namespace CoreCms.Net.Services billPayments.type = type; billPayments.status = (int)GlobalEnumVars.BillPaymentsStatus.NoPay; billPayments.paymentCode = paymentCode; - billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + billPayments.parameters = @params != null ? JsonConvert.SerializeObject(@params) : ""; billPayments.createTime = DateTime.Now; diff --git a/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs b/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs index 1585c03..b282d86 100644 --- a/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs +++ b/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs @@ -385,7 +385,7 @@ namespace CoreCms.Net.Services formSubmitModel.payStatus = false; formSubmitModel.status = false; formSubmitModel.createTime = DateTime.Now; - formSubmitModel.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); + formSubmitModel.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; var formSubmitId = await _formSubmitServices.InsertReturnIdentityAsync(formSubmitModel); diff --git a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs index 40d51bc..f24fa93 100644 --- a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs +++ b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs @@ -87,7 +87,7 @@ namespace CoreCms.Net.Services oldLog.code = type; oldLog.createTime = DateTime.Now; oldLog.mobile = mobile; - oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; oldLog.isUsed = false; var obj = new { @@ -238,7 +238,8 @@ namespace CoreCms.Net.Services oldLog.parameters = JsonConvert.SerializeObject(parameters); oldLog.contentBody = str; oldLog.createTime = DateTime.Now; - oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; oldLog.isUsed = isUsed; await _dal.InsertAsync(oldLog); diff --git a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs index d854a6d..1d2becb 100644 --- a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs +++ b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs @@ -532,7 +532,7 @@ namespace CoreCms.Net.Services order.orderDiscountAmount = cartDto.orderPromotionMoney > 0 ? cartDto.orderPromotionMoney : 0; order.goodsDiscountAmount = cartDto.goodsPromotionMoney > 0 ? cartDto.goodsPromotionMoney : 0; order.couponDiscountAmount = cartDto.couponPromotionMoney; - order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; //以上保存了订单主体表信息,以下生成订单明细表 var items = FormatOrderItems(cartDto.list, order.orderId); if (!items.Any()) diff --git a/CoreCms.Net.Services/User/CoreCmsUserServices.cs b/CoreCms.Net.Services/User/CoreCmsUserServices.cs index 7d6dc48..dc0e0b9 100644 --- a/CoreCms.Net.Services/User/CoreCmsUserServices.cs +++ b/CoreCms.Net.Services/User/CoreCmsUserServices.cs @@ -630,7 +630,8 @@ namespace CoreCms.Net.Services var log = new CoreCmsUserLog(); log.userId = userInfo.id; log.state = isReg ? (int)GlobalEnumVars.UserLogTypes.注册 : (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = isReg ? GlobalEnumVars.UserLogTypes.注册.ToString() : GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); diff --git a/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs b/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs index ec9e7d6..9474772 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs @@ -137,7 +137,9 @@ namespace CoreCms.Net.Web.Admin.Controllers //插入登录日志 var log = new SysLoginRecord(); log.username = model.userName; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.os = RuntimeInformation.OSDescription; if (_httpContextAccessor.HttpContext != null) log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; @@ -152,7 +154,9 @@ namespace CoreCms.Net.Web.Admin.Controllers //插入登录日志 var log = new SysLoginRecord(); log.username = model.userName; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.os = RuntimeInformation.OSDescription; if (_httpContextAccessor.HttpContext != null) log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; @@ -212,7 +216,9 @@ namespace CoreCms.Net.Web.Admin.Controllers if (_httpContextAccessor.HttpContext != null) { if (_httpContextAccessor.HttpContext.Connection.RemoteIpAddress != null) + { log.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); + } log.os = RuntimeInformation.OSDescription; log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; } diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index 890b86f..a19a88a 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -208,7 +208,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = user.id; log.state = (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); @@ -316,7 +316,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = user.id; log.state = (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); @@ -522,7 +522,9 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = id; log.state = (int)GlobalEnumVars.UserLogTypes.注册; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.注册.ToString(); await _userLogServices.InsertAsync(log); diff --git a/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql b/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql index f21e5a2..9044764 100644 --- a/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql +++ b/数据库/MySql/coreshopmysql20210720带演示数据(骆驼命名与实体名对应) .sql @@ -8190,7 +8190,6 @@ INSERT INTO `SysMenu` (`id`, `parentId`, `identificationCode`, `menuName`, `menu (52, 51, 'goods', '商品列表', '', 'good/goods/index', 'good/goods/list', 0, 1, 'good:goods:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:18:55'), (53, 51, 'goodscategory', '商品分类', '', 'good/goodscategory/index', 'good/goodscategory/list', 0, 10, 'good:goodscategory:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:18:58'), (54, 51, 'goodsbrand', '品牌列表', '', 'good/goodsbrand/index', 'good/goodsbrand/list', 0, 20, 'good:goodsbrand:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:02'), -(55, 51, 'goodstype', '商品类型', '', 'good/goodstype/index', 'good/goodstype/list', 0, 30, 'good:goodstype:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:05'), (56, 51, 'goodscomment', '商品评价', '', 'good/goodscomment/index', 'good/goodscomment/list', 0, 40, 'good:goodscomment:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:16'), (57, 51, 'goodsparams', '参数列表', '', 'good/goodsparams/index', 'good/goodsparams/list', 0, 35, 'good:goodsparams:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:12'), (58, 51, 'goodsTypeSpec', '商品属性', '', 'good/goodsTypeSpec/index', 'good/goodsTypeSpec/list', 0, 32, 'good:goodsTypeSpec:index', NULL, NULL, b'0', b'0', '2020-07-17 01:08:11', '2020-07-17 16:19:09'),