Commit 8a54e55d authored by liudong1993's avatar liudong1993

自动收货

parent cefd9bc9
......@@ -904,6 +904,19 @@ GROUP BY od.GoodsId,o.OrderId
string sql = $@"SELECT OrderId,UserId,OrderNo,OrderSource,CouponsIds FROM rb_goods_order where TenantId ={t} and MallBaseId ={m} and `Status`=0 and OrderStatus =1 and DATE_ADD(CreateDate,INTERVAL {cancelTime} MINUTE) < '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'";
return Get<RB_Goods_Order_Extend>(sql).ToList();
}
/// <summary>
/// 获取可自动收货的订单列表
/// </summary>
/// <param name="day"></param>
/// <param name="t"></param>
/// <param name="m"></param>
/// <returns></returns>
public List<RB_Goods_Order_Extend> GetCanReceivingOrderList(int day, int t, int m)
{
string sql = $@"SELECT OrderId,UserId,OrderNo,OrderSource,CouponsIds FROM rb_goods_order where TenantId ={t} and MallBaseId ={m} and `Status`=0 and OrderStatus =3 and DATE_ADD(DeliveryTime,INTERVAL {day} DAY) < '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'";
return Get<RB_Goods_Order_Extend>(sql).ToList();
}
#endregion
}
}
......@@ -43,5 +43,24 @@ namespace Mall.WindowsService.Helper
Interlocked.Exchange(ref inTimer, 0);
}
}
/// <summary>
/// 自动收货订单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void AutoReceivingOrder(object sender, System.Timers.ElapsedEventArgs e)
{
if (Interlocked.Exchange(ref inTimer, 1) == 0)
{
if (DateTime.Now.Hour == 1)
{
LogHelper.Write("AutoReceivingOrder=====Start");
Module.FinanceModule.AutoReceivingOrder();
LogHelper.Write("AutoReceivingOrder=====End");
Interlocked.Exchange(ref inTimer, 0);
}
}
}
}
}
......@@ -256,6 +256,8 @@ and DATE_FORMAT(b.CreateDate,'%y-%m-%d')<DATE_FORMAT('{endDate}','%y-%m-%d') an
//查询未付款的所有订单
var olist = goods_OrderRepository.GetCanCancelOrderList(item.CancelTime, item.TenantId, item.MallBaseId);
foreach (var qitem in olist)
{
try
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() { };
keyValues.Add(nameof(RB_Goods_Order_Extend.OrderStatus), OrderStatusEnum.Cancel);
......@@ -434,6 +436,85 @@ and DATE_FORMAT(b.CreateDate,'%y-%m-%d')<DATE_FORMAT('{endDate}','%y-%m-%d') an
});
}
}
catch (Exception ex)
{
Helper.LogHelper.Write("AutoCancelOrder:" + ex.Message);
continue;
}
}
}
}
return true;
}
catch (Exception ex)
{
Helper.LogHelper.Write("AutoCancelOrder:" + ex.Message);
return false;
}
}
#endregion
#region 自动收货
/// <summary>
/// 自动收货
/// </summary>
/// <returns></returns>
public static bool AutoReceivingOrder() {
try
{
var list = mallBaseRepository.GetListRepository(new Mall.Model.Extend.BaseSetUp.RB_MallBase_Extend() { });
foreach (var item in list)
{
if (item.AutoReceiving > 0)
{
//查询未付款的所有订单
var olist = goods_OrderRepository.GetCanReceivingOrderList(item.CancelTime, item.TenantId, item.MallBaseId);
foreach (var qitem in olist)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() { };
keyValues.Add(nameof(RB_Goods_Order_Extend.OrderStatus), OrderStatusEnum.Received);
keyValues.Add(nameof(RB_Goods_Order_Extend.ReceivingTime), DateTime.Now);
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Goods_Order_Extend.OrderId),
FiledValue=qitem.OrderId,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_Goods_Order_Extend.UserId),
FiledValue=qitem.UserId,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_Goods_Order_Extend.TenantId),
FiledValue=item.TenantId,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_Goods_Order_Extend.MallBaseId),
FiledValue=item.MallBaseId,
OperatorEnum=OperatorEnum.Equal
}
};
bool flag = goods_OrderRepository.Update(keyValues, wheres);
if (flag)
{
goods_LogRepository.Insert(new Mall.Model.Entity.Product.RB_Goods_Log()
{
Id = 0,
Type = 1,
SourceId = qitem.OrderId,
Content = "系统自动确认收货",
CreateDate = DateTime.Now,
MallBaseId = item.MallBaseId,
TenantId = item.TenantId
});
}
}
}
}
return true;
......
......@@ -13,6 +13,7 @@ namespace Mall.WindowsService
{
System.Timers.Timer timer1; //计时器
private System.Timers.Timer timer2; //订单取消计时器
private System.Timers.Timer timer3; //订单自动收货计时器
public WindowsService()
{
......@@ -39,6 +40,18 @@ namespace Mall.WindowsService
timer2.Enabled = true;
#endregion
#region 订单自动完成定时器
timer3 = new System.Timers.Timer();
timer2 = new System.Timers.Timer
{
Interval = 1000 * (60 * 60) //60分钟调用一次
};
timer3.Elapsed += new System.Timers.ElapsedEventHandler(helper.AutoReceivingOrder);
timer3.Enabled = true;
#endregion
}
protected override void OnStop()
......@@ -47,6 +60,7 @@ namespace Mall.WindowsService
Helper.LogHelper.Write("主服务停止运行......");
this.timer1.Enabled = false;
this.timer2.Enabled = false;
this.timer3.Enabled = false;
}
}
}
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