From 30158ac145749c3e0fa486406be707af0e882d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Thu, 20 Oct 2022 18:11:54 +0800 Subject: [PATCH] =?UTF-8?q?spu=E3=80=81skus=E6=95=B0=E6=8D=AE=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Shop/SkuController.cs | 76 ++++++++++++++++++ .../Controllers/Shop/SpuController.cs | 50 ++++++++++++ .../yi-sqlsugar-dev.db | Bin 221184 -> 221184 bytes .../Yi.Framework.Service/SpuService.cs | 2 +- .../BuilderExtend/JsonExtension.cs | 6 +- Yi.Vue3.x.Vant/src/api/skuApi.ts | 18 +++++ Yi.Vue3.x.Vant/src/api/spuApi.ts | 18 +++++ Yi.Vue3.x.Vant/src/view/shop/shopSearch.vue | 32 +++++++- 8 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 Yi.Vue3.x.Vant/src/api/skuApi.ts create mode 100644 Yi.Vue3.x.Vant/src/api/spuApi.ts diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs index a0e840b5..600874f6 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Yi.Framework.Common.Enum; using Yi.Framework.Common.Models; using Yi.Framework.Interface; using Yi.Framework.Model.Models; @@ -34,5 +35,80 @@ namespace Yi.Framework.ApiMicroservice.Controllers { return Result.Success().SetData(await _iSkuService.SelctPageList(eneity, page)); } + + + + + //数据测试 + [HttpGet] + public async Task Test(OperEnum operEnum) + { + switch (operEnum) + { + case OperEnum.Insert: + List spus = new(); + var sku1 = new SkuEntity() + { + Id = 1, + Stock = 100, + IsDeleted = false, + SpuId = 1, + Price = 1000, + SpecsSkuAllInfo = new List { + new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="1GB" } , + new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "红" } }, + }; + var sku2 = new SkuEntity() + { + Id = 2, + Stock = 100, + IsDeleted = false, + SpuId = 1, + Price = 4000, + SpecsSkuAllInfo = new List { + new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="2GB" } , + new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "绿" } }, + }; + + + var sku3 = new SkuEntity() + { + Id = 3, + Stock = 100, + IsDeleted = false, + SpuId = 2, + Price = 2000, + SpecsSkuAllInfo = new List { + new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="3GB" } , + new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "红" } }, + }; + var sku4 = new SkuEntity() + { + Id = 4, + Stock = 100, + IsDeleted = false, + SpuId = 2, + Price = 1000, + SpecsSkuAllInfo = new List { + new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="2GB" } , + new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "蓝" } }, + }; + spus.Add(sku1); + spus.Add(sku2); + spus.Add(sku3); + spus.Add(sku4); + await _iSkuService._repository.InsertRangeAsync(spus); + break; + + case OperEnum.Delete: + await _iSkuService._repository.DeleteAsync((u)=>true); + break; + default: + break; + } + + + return Result.Success(); + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs index 2ee37fc0..bd4e9dc7 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Yi.Framework.Common.Enum; using Yi.Framework.Common.Models; using Yi.Framework.Interface; using Yi.Framework.Model.Models; @@ -34,5 +35,54 @@ namespace Yi.Framework.ApiMicroservice.Controllers { return Result.Success().SetData(await _iSpuService.SelctPageList(eneity, page)); } + + + + + //数据测试 + [HttpGet] + public async Task Test(OperEnum operEnum) + { + switch (operEnum) + { + case OperEnum.Insert: + List spus = new(); + var spu1 = new SpuEntity() + { + Id = 1, + SpuName = "华为mate40 5G手机", + IsDeleted = false, + Details = "华为手机就是牛", + Price = "1000-2000", + SpecsSpuAllInfo = new List { + new SpecsSpuAllInfoModel { SpecsGroupName="内存",SpecsNames=new List { "1GB","2GB","3GB"} } , + new SpecsSpuAllInfoModel { SpecsGroupName="颜色",SpecsNames=new List { "红","蓝","绿"} } }, + }; + var spu2 = new SpuEntity() + { + Id = 2, + SpuName = "小米888 8G手机", + IsDeleted = false, + Details = "小米手机就是牛", + Price = "2000-3000", + SpecsSpuAllInfo = new List { + new SpecsSpuAllInfoModel { SpecsGroupName="内存",SpecsNames=new List { "1GB","2GB","3GB"} } , + new SpecsSpuAllInfoModel { SpecsGroupName="颜色",SpecsNames=new List { "红","蓝","绿"} } }, + }; + spus.Add(spu1); + spus.Add(spu2); + await _iSpuService._repository.InsertRangeAsync(spus); + break; + + case OperEnum.Delete: + await _iSpuService._repository.DeleteAsync((u) => true); + break; + default: + break; + } + + + return Result.Success(); + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index befd89061e33fea98c32c33a916e60fff227ed92..a80e2499ee6f710d355c5cedcc981368c2ebc717 100644 GIT binary patch delta 1069 zcmZoTz}s+ucY-vd>_i!7M%l)MtqF`v{5hET^%(f4^XqLE6j0)qNM{mY6I7I!RMcj0 zW&i;W(H{ar-iM~Ik7u+KHZo8!G`BJ}urjvLGchwWv9vIrK0Tf>cRR}i#uxk|V3h(4 zOx(Nj$-2rx1-GBH>K z?EzWV=+45F!u-O>z{p6~&_EYror$rPv8A4wxzY4P{Y+~0N>)ln?oLXzI@L3;?6}&NxASG@#-b{^@D`O!F{x SfB(nh;snvXo#g=2pZNgA`6w*_ diff --git a/Yi.Framework.Net6/Yi.Framework.Service/SpuService.cs b/Yi.Framework.Net6/Yi.Framework.Service/SpuService.cs index 1063ce57..c21b2c39 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/SpuService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/SpuService.cs @@ -14,7 +14,7 @@ namespace Yi.Framework.Service { RefAsync total = 0; var data = await _repository._DbQueryable - + .Includes(spu=>spu.Skus) .WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime) .WhereIF(enetity.IsDeleted is not null, u => u.IsDeleted == enetity.IsDeleted) .OrderBy(u => u.CreateTime, OrderByType.Desc) diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs index 55fa9629..cc59de83 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/BuilderExtend/JsonExtension.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace Yi.Framework.WebCore.BuilderExtend @@ -13,11 +14,14 @@ namespace Yi.Framework.WebCore.BuilderExtend { public static void AddJsonFileService(this IMvcBuilder builder) { + builder.AddJsonOptions(options => + options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())); + builder.AddNewtonsoftJson(options => { options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm"; - + //options.SerializerSettings.Converters.Add(new ValueToStringConverter()); }); diff --git a/Yi.Vue3.x.Vant/src/api/skuApi.ts b/Yi.Vue3.x.Vant/src/api/skuApi.ts new file mode 100644 index 00000000..5c268d36 --- /dev/null +++ b/Yi.Vue3.x.Vant/src/api/skuApi.ts @@ -0,0 +1,18 @@ +import myaxios from '@/utils/myaxios' + +export default { + add(data:any) { + return myaxios({ + url: `/sku/add`, + method: 'post', + data: data + }) + }, + pageList(data:any) { + return myaxios({ + url: '/sku/pageList', + method: 'get', + params: data + }) + } +} \ No newline at end of file diff --git a/Yi.Vue3.x.Vant/src/api/spuApi.ts b/Yi.Vue3.x.Vant/src/api/spuApi.ts new file mode 100644 index 00000000..9f52a64f --- /dev/null +++ b/Yi.Vue3.x.Vant/src/api/spuApi.ts @@ -0,0 +1,18 @@ +import myaxios from '@/utils/myaxios' + +export default { + add(data:any) { + return myaxios({ + url: `/spu/add`, + method: 'post', + data: data + }) + }, + pageList(data:any) { + return myaxios({ + url: '/spu/pageList', + method: 'get', + params: data + }) + } +} \ No newline at end of file diff --git a/Yi.Vue3.x.Vant/src/view/shop/shopSearch.vue b/Yi.Vue3.x.Vant/src/view/shop/shopSearch.vue index 904850e1..1bab92f2 100644 --- a/Yi.Vue3.x.Vant/src/view/shop/shopSearch.vue +++ b/Yi.Vue3.x.Vant/src/view/shop/shopSearch.vue @@ -4,4 +4,34 @@ 点击进入商品详情
返回商品首页 - \ No newline at end of file +这个是spu: +
商品名称:{{item.spuName}} +
规格组: {{spec.specsGroupName}} +
规格值: {{name}} + +
+ +
+
+
+ + + + \ No newline at end of file