Commit b8e18e24 authored by liudong1993's avatar liudong1993

定时器

parent c536b505
......@@ -31,7 +31,7 @@ namespace Mall.Model.Entity.Product
set;
}
/// <summary>
/// 类型 1收款 2退款
/// 类型 1收款 2退款 3余额充值 4会员购买
/// </summary>
public int? Type
{
......
......@@ -3847,6 +3847,18 @@ namespace Mall.Module.Product
return false;
}
/// <summary>
/// 获取小程序配置
/// </summary>
/// <param name="TenantId"></param>
/// <param name="MallBaseId"></param>
/// <returns></returns>
public Model.Extend.BaseSetUp.RB_MallBase_Extend GetMallBaseInfo(int TenantId,int MallBaseId)
{
var mallbaseModel = mallBaseRepository.GetListRepository(new Model.Extend.BaseSetUp.RB_MallBase_Extend() { TenantId = TenantId, MallBaseId = MallBaseId }).FirstOrDefault();
return mallbaseModel;
}
/// <summary>
/// 获取买家发货界面信息
/// </summary>
......
......@@ -560,6 +560,22 @@ namespace Mall.WebApi.Controllers.MallBase
return ApiResult.ParamIsNull("数量不正确");
}
//查询售后时间
//var mallbaseModel = orderModule.GetMallBaseInfo(userInfo.TenantId, userInfo.MallBaseId);
//if (mallbaseModel == null) {
// return ApiResult.ParamIsNull("请联系管理员,未查询到配置信息");
//}
//if (mallbaseModel.AfterTime > 0) {
// //获取订单发货时间
// var detailModel = orderModule.GetOrderDetailInfo(demodel.OrderDetialId ?? 0);
// var omodel = orderModule.GetOrderInfo(detailModel?.OrderId ?? 0);
// if (omodel != null && omodel.OrderStatus > Common.Enum.Goods.OrderStatusEnum.WaitReceiving && omodel.ReceivingTime.HasValue) {
// if (omodel.ReceivingTime.Value.AddDays(mallbaseModel.AfterTime) > DateTime.Now) {
// return ApiResult.ParamIsNull("已超过售后期限(" + mallbaseModel.AfterTime + "天),无法申请售后");
// }
// }
//}
demodel.TenantId = userInfo.TenantId;
demodel.MallBaseId = userInfo.MallBaseId;
demodel.UserId = userInfo.UserId;
......
......@@ -61,7 +61,7 @@ namespace Mall.WebApi
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime)
{
if (env.IsDevelopment())
{
......@@ -88,16 +88,15 @@ namespace Mall.WebApi
//获取前面注入的Quartz调度类
//var quartz = app.ApplicationServices.GetRequiredService<QuartzHelper>();
//appLifetime.ApplicationStarted.Register(() =>
//{
// quartz.Start().Wait(); //网站启动完成执行
//});
//appLifetime.ApplicationStopped.Register(() =>
//{
// quartz.Stop(); //网站停止完成执行
appLifetime.ApplicationStarted.Register(() =>
{
Timers.TimerJobj.RunTimer(); //网站启动完成执行
});
//});
appLifetime.ApplicationStopped.Register(() =>
{
Timers.TimerJobj.RunStop(); //网站停止完成执行
});
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
......
using Mall.Common.Plugin;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Mall.WebApi.Timers
{
public class TimerJobj
{
static System.Timers.Timer timer1; //计时器
public static void RunTimer()
{
LogHelper.Write("进来了 。。。 定时器启动");
timer1 = new System.Timers.Timer();
timer1.Interval = 1000 * (60 * 60); //60分钟
timer1.Elapsed += new System.Timers.ElapsedEventHandler(ClearFile);
timer1.Enabled = true;
}
public static void RunStop() {
LogHelper.Write("定时器停止运行......");
timer1.Enabled = false;
}
/// <summary>
/// 防止重置
/// </summary>
private static int inTimer = 0;
/// <summary>
/// 清理文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void ClearFile(object sender, System.Timers.ElapsedEventArgs e) {
if (Interlocked.Exchange(ref inTimer, 1) == 0)
{
if (DateTime.Now.Hour == 1)
{
LogHelper.Write("开始清理临时文件");
string rootBook = AppDomain.CurrentDomain.BaseDirectory;
try
{
DirectoryInfo dir = new DirectoryInfo(rootBook + "/upfile/temporary");
DirectoryInfo[] dirArr = dir.GetDirectories();
foreach (DirectoryInfo item in dirArr)
{
if (item.CreationTime < DateTime.Now.AddDays(-1))
item.Delete(true);
}
foreach (FileInfo fi in dir.GetFiles())
{
if (fi.CreationTime < DateTime.Now.AddDays(-1))
fi.Delete();
}
}
catch
{
LogHelper.Write("清理临时文件失败");
}
}
Interlocked.Exchange(ref inTimer, 0);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment