Skip to content

Commit ef821c1

Browse files
authored
Merge branch 'master' into master
2 parents 9559da0 + 481034c commit ef821c1

70 files changed

Lines changed: 1521 additions & 500 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Console/Commands/AutoBanUserJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class AutoBanUserJob extends Command
1313
{
1414
protected $signature = 'command:autoBanUserJob';
15-
protected $description = '自动封禁账号';
15+
protected $description = '自动封禁用户';
1616

1717
protected static $config;
1818

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Http\Models\SsNodeInfo;
6+
use App\Http\Models\SsNodeOnlineLog;
7+
use App\Http\Models\SsNodeTrafficHourly;
8+
use App\Http\Models\UserTrafficLog;
9+
use Illuminate\Console\Command;
10+
use App\Http\Models\Config;
11+
use App\Http\Models\UserTrafficHourly;
12+
use Log;
13+
14+
class AutoClearLogJob extends Command
15+
{
16+
protected $signature = 'command:autoClearLogJob';
17+
protected $description = '自动清除日志';
18+
19+
protected static $config;
20+
21+
public function __construct()
22+
{
23+
parent::__construct();
24+
25+
$config = Config::query()->get();
26+
$data = [];
27+
foreach ($config as $vo) {
28+
$data[$vo->name] = $vo->value;
29+
}
30+
31+
self::$config = $data;
32+
}
33+
34+
public function handle()
35+
{
36+
if (self::$config['is_clear_log']) {
37+
// 自动清除12小时以前的节点负载信息日志
38+
SsNodeInfo::query()->where('log_time', '<=', strtotime(date('Y-m-d H:i:s', strtotime("-12 hours"))))->delete();
39+
40+
// 自动清除1小时以前的节点负载信息日志
41+
SsNodeOnlineLog::query()->where('log_time', '<=', strtotime(date('Y-m-d H:i:s', strtotime("-60 minutes"))))->delete();
42+
43+
// 自动清除30天以前的用户流量日志
44+
UserTrafficLog::query()->where('log_time', '<=', strtotime(date('Y-m-d H:i:s', strtotime("-30 days"))))->delete();
45+
46+
// 自动清除10天以前的用户每小时流量数据日志
47+
UserTrafficHourly::query()->where('created_at', '<=', date('Y-m-d H:i:s', strtotime('-10 days')))->delete();
48+
49+
// 自动清除10天以前的节点每小时流量数据日志
50+
SsNodeTrafficHourly::query()->where('created_at', '<=', date('Y-m-d H:i:s', strtotime('-10 days')))->delete();
51+
}
52+
53+
Log::info('定时任务:' . $this->description);
54+
}
55+
}

app/Console/Commands/AutoDecGoodsTrafficJob.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Console\Commands;
44

55
use Illuminate\Console\Command;
6-
use App\Http\Models\Goods;
76
use App\Http\Models\OrderGoods;
87
use App\Http\Models\User;
98
use Log;
@@ -20,28 +19,20 @@ public function __construct()
2019

2120
public function handle()
2221
{
23-
$orderGoods = OrderGoods::query()->where('is_expire', 0)->get();
22+
$orderGoods = OrderGoods::query()->with(['user', 'goods'])->where('is_expire', 0)->get();
2423
foreach ($orderGoods as $og) {
25-
$goods = Goods::query()->where('id', $og->goods_id)->first();
26-
if (empty($goods)) {
24+
if (empty($og->goods) || $og->goods->is_del || empty($og->user)) {
2725
continue;
2826
}
2927

30-
if (date("Y-m-d H:i:s", strtotime("-" . $goods->days . " days")) >= $og->created_at) {
31-
$u = User::query()->where('id', $og->user_id)->first();
32-
if (empty($u)) {
33-
continue;
28+
// 到期自动处理
29+
if (date("Y-m-d H:i:s", strtotime("-" . $og->goods->days . " days")) >= $og->created_at) {
30+
if ($og->user->transfer_enable - $og->traffic * 1048576 <= 0) {
31+
User::query()->where('id', $og->user_id)->update(['transfer_enable' => 0]);
32+
} else {
33+
User::query()->where('id', $og->user_id)->decrement('transfer_enable', $og->traffic * 1048576);
3434
}
3535

36-
// 流量包到期自动扣总流量
37-
//if ($goods->type == 1) {
38-
if ($u->transfer_enable - $goods->traffic * 1048576 <= 0) {
39-
User::query()->where('id', $og->user_id)->update(['transfer_enable' => 0]);
40-
} else {
41-
User::query()->where('id', $og->user_id)->decrement('transfer_enable', $goods->traffic * 1048576);
42-
}
43-
//}
44-
4536
OrderGoods::query()->where('id', $og->id)->update(['is_expire' => 1]);
4637
}
4738
}

app/Console/Commands/AutoDisableExpireUserJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class autoDisableExpireUserJob extends Command
1010
{
1111
protected $signature = 'command:autoDisableExpireUserJob';
12-
protected $description = '用户到期自动禁用';
12+
protected $description = '自动禁用到期用户';
1313

1414
public function __construct()
1515
{

app/Console/Commands/AutoReopenUserJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class AutoReopenUserJob extends Command
1111
{
1212
protected $signature = 'command:autoReopenUserJob';
13-
protected $description = '自动解封账号';
13+
protected $description = '自动解封用户';
1414

1515
public function __construct()
1616
{

app/Console/Commands/AutoResetUserTrafficJob.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Http\Models\OrderGoods;
56
use Illuminate\Console\Command;
67
use App\Http\Models\Config;
78
use App\Http\Models\User;
@@ -30,8 +31,24 @@ public function __construct()
3031
public function handle()
3132
{
3233
if (self::$config['reset_traffic']) {
33-
$user_ids = User::query()->where('pay_way', '<>', 0)->select(['id'])->get();
34-
User::query()->whereIn('id', $user_ids)->update(['u' => 0, 'd' => 0]);
34+
$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->get();
35+
foreach ($userList as $user) {
36+
if (empty($user->traffic_reset_day)) {
37+
continue;
38+
}
39+
40+
// 取出这个用户最后购买的有效套餐
41+
$orderGoods = OrderGoods::query()->with(['goods' => function($q) { $q->where('type', 2); }])->where('user_id', $user->id)->where('is_expire', 0)->orderBy('id', 'desc')->first();
42+
if (empty($orderGoods) || empty($orderGoods->goods)) {
43+
continue;
44+
}
45+
46+
if ($user->traffic_reset_day == abs(date('d')) && date('m') == date('m', strtotime($orderGoods->created_at))) {
47+
continue;
48+
}
49+
50+
User::query()->where('id', $user->id)->update(['u' => 0, 'd' => 0]);
51+
}
3552
}
3653

3754
Log::info('定时任务:' . $this->description);

app/Console/Commands/AutoStatisticsNodeDailyTrafficJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class AutoStatisticsNodeDailyTrafficJob extends Command
1212
{
1313
protected $signature = 'command:autoStatisticsNodeDailyTrafficJob';
14-
protected $description = '节点每日流量自动统计';
14+
protected $description = '自动统计节点每日流量';
1515

1616
public function __construct()
1717
{
@@ -20,7 +20,7 @@ public function __construct()
2020

2121
public function handle()
2222
{
23-
$nodeList = SsNode::query()->where('status', 1)->get();
23+
$nodeList = SsNode::query()->where('status', 1)->orderBy('id', 'asc')->get();
2424
foreach ($nodeList as $node) {
2525
$this->statisticsByNode($node->id);
2626
}

app/Console/Commands/AutoStatisticsNodeHourlyTrafficJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class AutoStatisticsNodeHourlyTrafficJob extends Command
1212
{
1313
protected $signature = 'command:autoStatisticsNodeHourlyTrafficJob';
14-
protected $description = '节点每小时流量自动统计';
14+
protected $description = '自动统计节点每小时流量';
1515

1616
public function __construct()
1717
{
@@ -20,7 +20,7 @@ public function __construct()
2020

2121
public function handle()
2222
{
23-
$nodeList = SsNode::query()->where('status', 1)->get();
23+
$nodeList = SsNode::query()->where('status', 1)->orderBy('id', 'asc')->get();
2424
foreach ($nodeList as $node) {
2525
$this->statisticsByNode($node->id);
2626
}

app/Console/Commands/AutoStatisticsUserDailyTrafficJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class AutoStatisticsUserDailyTrafficJob extends Command
1313
{
1414
protected $signature = 'command:autoStatisticsUserDailyTrafficJob';
15-
protected $description = '用户每日流量自动统计';
15+
protected $description = '自动统计用户每日流量';
1616

1717
public function __construct()
1818
{
@@ -27,7 +27,7 @@ public function handle()
2727
$this->statisticsByNode($user->id);
2828

2929
// 统计每个节点产生的流量
30-
$nodeList = SsNode::query()->get();
30+
$nodeList = SsNode::query()->where('status', 1)->orderBy('id', 'asc')->get();
3131
foreach ($nodeList as $node) {
3232
$this->statisticsByNode($user->id, $node->id);
3333
}

app/Console/Commands/AutoStatisticsUserHourlyTrafficJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class AutoStatisticsUserHourlyTrafficJob extends Command
1313
{
1414
protected $signature = 'command:autoStatisticsUserHourlyTrafficJob';
15-
protected $description = '用户每小时流量自动统计';
15+
protected $description = '自动统计用户每小时流量';
1616

1717
public function __construct()
1818
{
@@ -27,7 +27,7 @@ public function handle()
2727
$this->statisticsByNode($user->id);
2828

2929
// 统计每个节点产生的流量
30-
$nodeList = SsNode::query()->get();
30+
$nodeList = SsNode::query()->where('status', 1)->orderBy('id', 'asc')->get();
3131
foreach ($nodeList as $node) {
3232
$this->statisticsByNode($user->id, $node->id);
3333
}

0 commit comments

Comments
 (0)