From d5f7b4b01a98d35e0eb9c793695914b0683a0009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sat, 6 Nov 2021 17:53:54 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E6=B7=B1=E5=BA=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 9 ++++++++- Yi.Framework/Yi.Framework.Service/MenuService.cs | 2 +- Yi.Framework/Yi.Framework.Service/RoleService.cs | 3 ++- .../Yi.Framework.WebCore/Utility/CustomAutofacModule.cs | 7 ++++--- Yi.Vue/src/views/register.vue | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index be7c7a07..32d475a2 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -30,7 +30,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers private RabbitMQInvoker _rabbitMQInvoker; private CacheClientDB _cacheClientDB; private IRoleService _roleService; - public AccountController(ILogger logger, IUserService userService, IMenuService menuService,RabbitMQInvoker rabbitMQInvoker,CacheClientDB cacheClientDB, IRoleService roleService) + private IHttpContextAccessor _httpContext; + public AccountController(ILogger logger, IUserService userService, IMenuService menuService,RabbitMQInvoker rabbitMQInvoker,CacheClientDB cacheClientDB, IRoleService roleService, IHttpContextAccessor httpContext) { _logger = logger; _userService = userService; @@ -38,6 +39,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers _rabbitMQInvoker = rabbitMQInvoker; _cacheClientDB = cacheClientDB; _roleService = roleService; + _httpContext = httpContext; } @@ -94,6 +96,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers //设置默认头像 var setting = JsonHelper.StrToObj(_cacheClientDB.Get(RedisConst.key)); _user.icon = setting.InitIcon; + _user.ip = _httpContext.HttpContext.Request.Headers["X-Real-IP"].FirstOrDefault();//通过上下文获取ip //设置默认角色 if (string.IsNullOrEmpty(setting.InitRole)) { @@ -117,6 +120,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task SendSMS(string SMSAddress) { + if (string.IsNullOrEmpty(SMSAddress)) + { + return Result.Error("请输入电话号码"); + } SMSAddress = SMSAddress.Trim(); if (!await _userService.PhoneIsExsit(SMSAddress)) { diff --git a/Yi.Framework/Yi.Framework.Service/MenuService.cs b/Yi.Framework/Yi.Framework.Service/MenuService.cs index 3b05cfb5..7c885c35 100644 --- a/Yi.Framework/Yi.Framework.Service/MenuService.cs +++ b/Yi.Framework/Yi.Framework.Service/MenuService.cs @@ -58,7 +58,7 @@ namespace Yi.Framework.Service public async Task> GetTopMenuByUserId(int userId) { - var user_data = await _DbRead.Set().Include(u => u.roles).ThenInclude(u => u.menus).FirstOrDefaultAsync(); + var user_data = await _DbRead.Set().Include(u => u.roles).ThenInclude(u => u.menus).Where(u=>u.id==userId).FirstOrDefaultAsync(); List menuList = new(); user_data.roles.ForEach(u => { diff --git a/Yi.Framework/Yi.Framework.Service/RoleService.cs b/Yi.Framework/Yi.Framework.Service/RoleService.cs index 2ab3a56c..1461c1af 100644 --- a/Yi.Framework/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework/Yi.Framework.Service/RoleService.cs @@ -16,7 +16,8 @@ namespace Yi.Framework.Service public async Task> GetRolesByUserId(int userId) { var user_data =await _Db.Set().Include(u => u.roles).Where(u => u.id==userId).FirstOrDefaultAsync(); - var roleList = user_data.roles.Where(u=>u.is_delete==Normal).ToList(); + var roleList = user_data.roles.Where(u=>u.is_delete==Normal).ToList(); + roleList.ForEach(u => u.users = null); return roleList; } diff --git a/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs b/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs index 49e6c303..f39b0d8d 100644 --- a/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs +++ b/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs @@ -1,6 +1,7 @@ using Autofac; using Autofac.Extras.DynamicProxy; using Castle.DynamicProxy; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.EntityFrameworkCore; @@ -36,11 +37,11 @@ namespace Yi.Framework.WebCore.Utility containerBuilder.RegisterType().As().InstancePerDependency().EnableInterfaceInterceptors(); - - + containerBuilder.RegisterType< HttpContextAccessor>().As().SingleInstance(); -///反射注入服务层及接口层 + + ///反射注入服务层及接口层 var assemblysServices = GetDll( "Yi.Framework.Service.dll"); containerBuilder.RegisterAssemblyTypes(assemblysServices) .AsImplementedInterfaces() diff --git a/Yi.Vue/src/views/register.vue b/Yi.Vue/src/views/register.vue index 5a7afbc4..b1c159d9 100644 --- a/Yi.Vue/src/views/register.vue +++ b/Yi.Vue/src/views/register.vue @@ -57,7 +57,7 @@ - 验证码 + 验证码 { if (resp.status) { this.$dialog.notify.success(resp.msg, { @@ -171,6 +172,7 @@ export default { ], isPasswordVisible: false, code: "", + is_en:false, form: { phone: "", username: "", From 24cf70da2c2dbf8d50faa21107c64c62d1fa7640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <68722157+ccnetcore@users.noreply.github.com> Date: Sat, 6 Nov 2021 18:27:09 +0800 Subject: [PATCH 2/6] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4dd2f8a3..0d4d8865 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ **Yi.Vue**:Vue2.0配合CC.Yi.Framework使用前端项目(正在更新) +**分支:ec**:基于Yi.Framework微服务电商项目(同步更新) + **** #### 支持: From 5c106a8ab407fd2d5788b2ec7fc7991f304f93ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 9 Nov 2021 16:59:50 +0800 Subject: [PATCH 3/6] esinvoker --- .../Yi.Framework.Core/ElasticSearchInvoker.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Yi.Framework/Yi.Framework.Core/ElasticSearchInvoker.cs diff --git a/Yi.Framework/Yi.Framework.Core/ElasticSearchInvoker.cs b/Yi.Framework/Yi.Framework.Core/ElasticSearchInvoker.cs new file mode 100644 index 00000000..4b4556cc --- /dev/null +++ b/Yi.Framework/Yi.Framework.Core/ElasticSearchInvoker.cs @@ -0,0 +1,53 @@ +using Microsoft.Extensions.Options; +using Nest; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Common.IOCOptions; + +namespace Yi.Framework.Core +{ + public class ElasticSearchInvoker + { + private readonly ElasticSearchOptions _elasticSearchOptions; + + public ElasticSearchInvoker(IOptionsMonitor optionsMonitor) + { + _elasticSearchOptions = optionsMonitor.CurrentValue; + var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(this._elasticSearchOptions.IndexName); + Client = new ElasticClient(settings); + } + private ElasticClient Client; + public ElasticClient GetElasticClient() + { + return Client; + } + public void Send(List model) where T : class + { + Client.IndexMany(model); + } + + public void InsertOrUpdata(T model) where T : class + { + Client.IndexDocument(model); + } + + public bool Delete(string id) where T : class + { + + var response = Client.Delete(id); + return response.IsValid; + } + public bool DropIndex(string indexName) + { + return Client.Indices.Delete(Indices.Parse(indexName)).IsValid; + } + public void CreateIndex(string indexName) + { + var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(indexName); + this.Client = new ElasticClient(settings); + } + } +} From 12dbc64b74f412a8dcf5a6f75affa22f2f25094e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 9 Nov 2021 17:01:26 +0800 Subject: [PATCH 4/6] searchmodel --- .../Yi.Framework.Model/Search/Goods.cs | 31 +++++++++++++++ .../Yi.Framework.Model/Search/PageResult.cs | 20 ++++++++++ .../Search/SearchRequest.cs | 39 +++++++++++++++++++ .../Yi.Framework.Model/Search/SearchResult.cs | 31 +++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 Yi.Framework/Yi.Framework.Model/Search/Goods.cs create mode 100644 Yi.Framework/Yi.Framework.Model/Search/PageResult.cs create mode 100644 Yi.Framework/Yi.Framework.Model/Search/SearchRequest.cs create mode 100644 Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs diff --git a/Yi.Framework/Yi.Framework.Model/Search/Goods.cs b/Yi.Framework/Yi.Framework.Model/Search/Goods.cs new file mode 100644 index 00000000..35a905c7 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Model/Search/Goods.cs @@ -0,0 +1,31 @@ +using Nest; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.Model.Search +{ + [ElasticsearchType(IdProperty = "id")]//主键声明,且主键必须是属性 + public class Goods + { + public long id { get; set; } + + + public spu spu { get; set; } + public string all; //所有需要被搜索的信息,包括品牌,分类,标题 + public string subtitle; //子标题 + public brand brand; + public category cid1; + public category cid2; + public category cid3; + public DateTime? createTime; + + + public HashSet price = new HashSet(); //是所有sku的价格集合。方便根据价格进行筛选过滤 + public List skus; //sku信息的json结构数据 + public Dictionary specs = new Dictionary(); //可搜索的规格参数,key是参数名,值是参数值 + } +} diff --git a/Yi.Framework/Yi.Framework.Model/Search/PageResult.cs b/Yi.Framework/Yi.Framework.Model/Search/PageResult.cs new file mode 100644 index 00000000..52fde5cb --- /dev/null +++ b/Yi.Framework/Yi.Framework.Model/Search/PageResult.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Yi.Framework.Model.Search +{ + public class PageResult + { + public static readonly long serialVersionUID = 4612105649493688532L; + public long total; // 总记录数 + public int totalPages; //总页数 + public List rows; // 每页显示的数据集合 + + public PageResult(long total, List rows) + { + this.total = total; + this.rows = rows; + } + } +} diff --git a/Yi.Framework/Yi.Framework.Model/Search/SearchRequest.cs b/Yi.Framework/Yi.Framework.Model/Search/SearchRequest.cs new file mode 100644 index 00000000..a3853d37 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Model/Search/SearchRequest.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Model.Search +{ + public class SearchRequest + { + public static readonly int DEFAULT_PAGE = 1; + public static readonly int DEFAULT_SIZE = 20; + public string key { get; set; } + public int page { get; set; } + //排序字段 + public string sortBy { get; set; } + //是否降序 + public bool descending { get; set; } + //过滤字段 + public Dictionary filter = new Dictionary(); + + public int getPage() + { + if (page == 0) + { + return DEFAULT_PAGE; + } + // 获取页码时做一些校验,不能小于1 + return Math.Max(DEFAULT_PAGE, page); + } + + public int getSize() + { + return DEFAULT_SIZE; + } + + + } +} diff --git a/Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs b/Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs new file mode 100644 index 00000000..18043165 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.Model.Search +{ + public class SearchResult : PageResult + { + public List brands = new List(); + public List categories = new List(); + //规格参数过滤条件 + public List> specs = new List>(); + public SearchResult(long total, + int totalPage, + List items, + List categories, + List brands, + List> specs) : base + (total, items) + { + + this.categories = categories; + this.brands = brands; + this.specs = specs; + } + + } +} From 71f5ba4656ceadae40ddc31dfa65d82bc96fe72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 9 Nov 2021 17:03:08 +0800 Subject: [PATCH 5/6] searchmodel --- .../Yi.Framework.Model/Search/Goods.cs | 31 ------------------- .../Yi.Framework.Model/Search/SearchResult.cs | 31 ------------------- 2 files changed, 62 deletions(-) delete mode 100644 Yi.Framework/Yi.Framework.Model/Search/Goods.cs delete mode 100644 Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs diff --git a/Yi.Framework/Yi.Framework.Model/Search/Goods.cs b/Yi.Framework/Yi.Framework.Model/Search/Goods.cs deleted file mode 100644 index 35a905c7..00000000 --- a/Yi.Framework/Yi.Framework.Model/Search/Goods.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Nest; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Yi.Framework.Model.Models; - -namespace Yi.Framework.Model.Search -{ - [ElasticsearchType(IdProperty = "id")]//主键声明,且主键必须是属性 - public class Goods - { - public long id { get; set; } - - - public spu spu { get; set; } - public string all; //所有需要被搜索的信息,包括品牌,分类,标题 - public string subtitle; //子标题 - public brand brand; - public category cid1; - public category cid2; - public category cid3; - public DateTime? createTime; - - - public HashSet price = new HashSet(); //是所有sku的价格集合。方便根据价格进行筛选过滤 - public List skus; //sku信息的json结构数据 - public Dictionary specs = new Dictionary(); //可搜索的规格参数,key是参数名,值是参数值 - } -} diff --git a/Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs b/Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs deleted file mode 100644 index 18043165..00000000 --- a/Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Yi.Framework.Model.Models; - -namespace Yi.Framework.Model.Search -{ - public class SearchResult : PageResult - { - public List brands = new List(); - public List categories = new List(); - //规格参数过滤条件 - public List> specs = new List>(); - public SearchResult(long total, - int totalPage, - List items, - List categories, - List brands, - List> specs) : base - (total, items) - { - - this.categories = categories; - this.brands = brands; - this.specs = specs; - } - - } -} From 6d5f2cbae755bb993a70bedc5b2f42ffde5f96bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 9 Nov 2021 17:05:00 +0800 Subject: [PATCH 6/6] searchmodel --- Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj | 1 + Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj index 3f7b4706..50204716 100644 --- a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -12,6 +12,7 @@ + diff --git a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj index 189ba8b7..20c72c23 100644 --- a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj +++ b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj @@ -4,10 +4,6 @@ net5.0 - - - - True