Quellcode durchsuchen

1.优化广告筛选;
2.广告可以快速复制
3.图片加载失败自动重试

懒得勤快 vor 4 Jahren
Ursprung
Commit
84628605a6

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/ErrorController.cs

@@ -38,7 +38,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult Index()
         {
             Response.StatusCode = 404;
-            return Request.Method.Equals(HttpMethods.Get) ? (ActionResult)View() : Json(new
+            return Request.Method.Equals(HttpMethods.Get) ? View() : Json(new
             {
                 StatusCode = 404,
                 Success = false,

+ 7 - 0
src/Masuit.MyBlogs.Core/Infrastructure/DataContext.cs

@@ -1,5 +1,6 @@
 using Masuit.MyBlogs.Core.Models.Entity;
 using Microsoft.EntityFrameworkCore;
+using System;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
@@ -28,6 +29,9 @@ namespace Masuit.MyBlogs.Core.Infrastructure
             modelBuilder.Entity<Menu>().HasMany(e => e.Children).WithOne(m => m.Parent).IsRequired(false).OnDelete(DeleteBehavior.Cascade);
             modelBuilder.Entity<Comment>().HasMany(e => e.Children).WithOne(c => c.Parent).HasForeignKey(c => c.ParentId).IsRequired(false).OnDelete(DeleteBehavior.Cascade);
             modelBuilder.Entity<LeaveMessage>().HasMany(e => e.Children).WithOne(c => c.Parent).HasForeignKey(c => c.ParentId).IsRequired(false).OnDelete(DeleteBehavior.Cascade);
+
+            modelBuilder.HasDbFunction(typeof(DataContext).GetMethod(nameof(Random))).HasName("RAND");
+            modelBuilder.HasDbFunction(typeof(Guid).GetMethod(nameof(Guid.NewGuid))).HasName("RAND");
         }
 
         public override int SaveChanges()
@@ -99,5 +103,8 @@ namespace Masuit.MyBlogs.Core.Infrastructure
         public virtual DbSet<PostMergeRequest> PostMergeRequests { get; set; }
         public virtual DbSet<Advertisement> Advertisements { get; set; }
         public virtual DbSet<Variables> Variables { get; set; }
+
+        [DbFunction]
+        public static double Random() => throw new NotSupportedException();
     }
 }

+ 2 - 5
src/Masuit.MyBlogs.Core/Infrastructure/Services/AdvertisementService.cs

@@ -4,9 +4,7 @@ using Masuit.MyBlogs.Core.Infrastructure.Repository.Interface;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
-using Masuit.Tools;
 using Masuit.Tools.Linq;
-using Masuit.Tools.RandomSelector;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -50,11 +48,10 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Services
                     var scid = cid.ToString();
                     if (Any(a => a.CategoryIds.Contains(scid)))
                     {
-                        where = where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds));
+                        @where = @where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds));
                     }
                 }
-
-                var list = GetQuery(where).AsEnumerable().Select(a => new WeightedItem<Advertisement>(a, a.CategoryIds is { Length: > 0 } ? (int)a.Price * 2 : (int)a.Price)).WeightedItems(count);
+                var list = GetQuery(where).OrderBy(a => -Math.Log(DataContext.Random()) / (double)a.Price * (string.IsNullOrEmpty(a.CategoryIds) ? 2 : 1)).Take(count).ToList();
                 var ids = list.Select(a => a.Id).ToArray();
                 GetQuery(a => ids.Contains(a.Id)).UpdateFromQuery(a => new Advertisement()
                 {

+ 6 - 6
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj

@@ -34,7 +34,7 @@
         <PackageReference Include="CacheManager.StackExchange.Redis" Version="1.2.0" />
         <PackageReference Include="CHTCHSConv" Version="1.0.0" />
         <PackageReference Include="CSRedisCore" Version="3.6.6" />
-        <PackageReference Include="EFCoreSecondLevelCacheInterceptor" Version="3.1.0" />
+        <PackageReference Include="EFCoreSecondLevelCacheInterceptor" Version="3.1.1" />
         <PackageReference Include="Hangfire" Version="1.7.23" />
         <PackageReference Include="Hangfire.Autofac" Version="2.3.1" />
         <PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
@@ -42,10 +42,10 @@
         <PackageReference Include="IP2Region" Version="1.2.0" />
         <PackageReference Include="Karambolo.AspNetCore.Bundling.NUglify" Version="3.4.1" />
         <PackageReference Include="MaxMind.GeoIP2" Version="4.0.1" />
-        <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.6" />
-        <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.6" />
-        <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="5.0.6" />
-        <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.6" />
+        <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.7" />
+        <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.7" />
+        <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="5.0.7" />
+        <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.7" />
         <PackageReference Include="Microsoft.Extensions.Http.Polly" Version="5.0.1" />
         <PackageReference Include="Microsoft.Graph" Version="3.33.0" />
         <PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.6" />
@@ -59,7 +59,7 @@
         <PackageReference Include="TimeZoneConverter" Version="3.5.0" />
         <PackageReference Include="WilderMinds.RssSyndication" Version="1.7.0" />
         <PackageReference Include="WinInsider.System.Net.Http.Formatting" Version="1.0.14" />
-        <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="5.1.38" />
+        <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="5.1.39" />
     </ItemGroup>
     <ItemGroup>
         <Content Update="appsettings.json">

+ 13 - 0
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/scripts.js

@@ -177,6 +177,19 @@ $(function() {
             $("#ping").text(new Date().getTime()-timestamp);
         });
     }, 2000);
+
+    // 自动重试加载图片
+    $('img').on("error",function() {
+       var that=$(this);
+       var retry=that.attr("retry")||0;
+       if(retry>10){
+          return ;
+       }else{
+          retry++;
+          that.attr("retry", retry);//重试次数+1
+          that.attr('src', that.attr("src"));//继续刷新图片
+       }
+    });
 });
 
 //全局加载动画

+ 31 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/partner.js

@@ -104,6 +104,7 @@
 		    $('.ui.dropdown.types').dropdown('clear');
 		}, 10);
 	}
+
 	$scope.edit = function (item) {
 		$scope.partner = angular.copy(item);
 		$scope.partner.ExpireTime=$scope.partner.ExpireTime == null?"2099-12-31":$scope.partner.ExpireTime;
@@ -130,12 +131,42 @@
 			}
 		});
 	}
+
+	$scope.copy = function (item) {
+		$scope.partner = angular.copy(item);
+		delete $scope.partner.Id;
+		$scope.partner.ExpireTime=$scope.partner.ExpireTime == null?"2099-12-31":$scope.partner.ExpireTime;
+		$scope.isAdd = true;
+		$scope.allowUpload=false;
+		layer.closeAll();
+        $timeout(function () {
+		    $('.ui.dropdown.category').dropdown('clear');
+		    $('.ui.dropdown.types').dropdown('clear');
+			$('.ui.dropdown.category').dropdown('set selected', (item.CategoryIds+"").split(','));
+		    $('.ui.dropdown.types').dropdown('set selected', item.Types.split(','));
+		}, 10);
+		layer.open({
+			type: 1,
+			zIndex: 20,
+			title: '复制广告推广',
+			area: (window.screen.width > 650 ? 650 : window.screen.width) + 'px',// '340px'], //宽高
+			content: $("#edit"),
+			cancel: function(index, layero) {
+				setTimeout(function() {
+					$("#edit").css("display", "none");
+				}, 500);
+				return true;
+			}
+		});
+	}
+
 	$scope.closeAll= function() {
 		layer.closeAll();
 		setTimeout(function() {
 			$("#edit").css("display", "none");
 		}, 500);
 	}
+
 	$scope.submit = function(partner) {
 		if ($scope.isAdd) {
 			partner.Id = 0;

+ 4 - 1
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/partner.html

@@ -76,11 +76,14 @@
                     <span class="el-switch-style" ng-click="changeState(row)"></span>
                 </label>
             </td>
-            <td title="'操作'" style="width: 110px;">
+            <td title="'操作'" style="width: 160px;">
                 <div class="btn-group">
                     <button class="btn btn-info btn-sm waves-effect" ng-click="edit(row)">
                         <i class="icon-pencil"></i>
                     </button>
+                    <a class="btn btn-success btn-sm waves-effect" ng-click="copy(row)">
+                        <i class="zmdi zmdi-copy zmdi-hc-fw"></i>
+                    </a>
                     <button class="btn btn-danger btn-sm waves-effect" ng-click="remove(row)">
                         <i class="icon-bin"></i>
                     </button>