111 lines
4.2 KiB
C#
111 lines
4.2 KiB
C#
using CRM.Core.BLL.Application.Order;
|
||
using CRM.Core.BLL.Base;
|
||
using CRM.Core.BLL.Wx;
|
||
using CRM.Core.Common.Layui;
|
||
using Quartz;
|
||
using System;
|
||
using System.Linq;
|
||
using WX.CRM.Common;
|
||
|
||
namespace CRM.Core.CoreService.Order
|
||
{
|
||
/// <summary>
|
||
/// 自动开通订单,对那些已支付,已合规,已到需要开通时间的订单进行自动开通
|
||
/// </summary>
|
||
public class AutomaticOpenOrder
|
||
{
|
||
private Wx_AutoOpenOrder_BL _autoOpenOrder = new Wx_AutoOpenOrder_BL();
|
||
|
||
private OrderService _orderservice = new OrderService();
|
||
private WX_SZZYORDER_BL _order = new WX_SZZYORDER_BL();
|
||
private WX_PRODUCT_BL product_bl = new WX_PRODUCT_BL();
|
||
private BAS_PARAMETER_BL paramter_bl = new BAS_PARAMETER_BL();
|
||
public void Exe()
|
||
{
|
||
LogHelper.Info("订单自动开通服务开始");
|
||
var parameter = paramter_bl.GetModel("Sys_automatic_open");//是否开启自动开通订单功能:1:开启 0和null:没开启
|
||
if (parameter == null || parameter.PARAVALUE != "1")
|
||
{
|
||
LogHelper.Info("订单自动开通服务结束,未开启自动开通订单服务!");
|
||
return;
|
||
}
|
||
var days = paramter_bl.GetModel("Sys_automatic_open_day");//是否开启自动开通订单功能:1:开启 0和null:没开启
|
||
int dayago = 30;
|
||
if (days != null)
|
||
{
|
||
dayago = Convert.ToInt32(days.PARAVALUE);
|
||
}
|
||
//var list = _autoOpenOrder.GetList(p => p.IsExe == 0, p => p.Id, new Laypage() { page = 1, limit = 20 }).ToList();
|
||
//string[] orderstatus = { "200", "201" };
|
||
DateTime now = DateTime.Now;
|
||
DateTime oneMonth = now.AddDays(-dayago);//计算多少天前的订单
|
||
|
||
|
||
//string[] smallproductList = product_bl.GetSmallProduct();
|
||
//var orderList = _order.GetList(m =>
|
||
//(
|
||
// smallproductList.Contains(m.PRODUCTCODE)//必须是小额产品
|
||
// && orderstatus.Contains(m.ORDERSTATUS)//状态达标
|
||
// && (m.estimateotime == null || m.estimateotime <= now)//时间达标
|
||
// && m.ARRIVALPAY == m.NEEDPAY//支付达标
|
||
// && m.CTIME > oneMonth//必须是一个月内的数据
|
||
//)
|
||
//||
|
||
//(
|
||
// orderstatus.Contains(m.ORDERSTATUS)//状态达标
|
||
// && (m.estimateotime == null || m.estimateotime <= now)//必须时间达到标准
|
||
// && m.ARRIVALPAY == m.NEEDPAY //必须是已支付
|
||
// && m.RISKCTRLSTATUS == 2//必须是风控通过
|
||
// && m.CTIME > oneMonth//必须是一个月内的数据
|
||
//),
|
||
//m => m.ORDERID
|
||
//,
|
||
|
||
var page = new Laypage() { page = 1, limit = 20 };//自动开通小额订单
|
||
var orderList = _order.GetNeedOpenOrderIds(ref page, oneMonth);
|
||
if (orderList != null && orderList.Count() > 0)
|
||
{
|
||
foreach (var item in orderList)
|
||
{
|
||
try
|
||
{
|
||
LogHelper.Info("尝试开通的订单:" + item);
|
||
_orderservice.CanIOpen(item, 0, "系统");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
}
|
||
}
|
||
}
|
||
LogHelper.Info("订单自动开通服务结束,尝试开通订单数:" + (orderList != null ? orderList.Count() : 0));
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 自动开通订单,对那些已支付,已合规,已到需要开通时间的订单进行自动开通
|
||
/// </summary>
|
||
|
||
public class AutomaticOpenOrderJob : IJob
|
||
{
|
||
static bool runnding = false;
|
||
public void Execute(JobExecutionContext context)
|
||
{
|
||
if (runnding)
|
||
return;
|
||
runnding = true;
|
||
try
|
||
{
|
||
new AutomaticOpenOrder().Exe();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogHelper.Error(e);
|
||
}
|
||
finally
|
||
{
|
||
runnding = false;
|
||
}
|
||
}
|
||
}
|
||
}
|