Skip to content

Commit 13c23a7

Browse files
committed
1.修正用户中心BUG
2.修正节点订阅功能BUG 3.商品改造 4.定时任务优化
1 parent 599cac3 commit 13c23a7

27 files changed

+554
-109
lines changed

app/Console/Commands/AutoDecGoodsTrafficJob.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class AutoDecGoodsTrafficJob extends Command
1212
{
1313
protected $signature = 'command:autoDecGoodsTrafficJob';
14-
protected $description = '商品到期自动扣购买该商品的账号流量';
14+
protected $description = '自动扣除到期流量包的流量';
1515

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

2121
public function handle()
2222
{
23-
$goodsList = Goods::where('end_time', '<', date('Y-m-d H:i:s'))->get();
24-
foreach ($goodsList as $goods) {
25-
// 所有购买过该商品的用户
26-
$orderGoods = OrderGoods::where('goods_id', $goods->id)->get();
27-
foreach ($orderGoods as $og) {
23+
$orderGoods = OrderGoods::where('is_expire', 0)->get();
24+
foreach ($orderGoods as $og) {
25+
$goods = Goods::where('id', $og->goods_id)->first();
26+
if (empty($goods)) {
27+
continue;
28+
}
29+
30+
// 如果商品已过期,则需要扣流量
31+
if (date("Y-m-d H:i:s", strtotime("-" . $goods->days . " days")) >= $og->created_at) {
2832
$u = User::where('id', $og->user_id)->first();
2933
if (empty($u)) {
3034
continue;
3135
}
3236

33-
if ($u->transfer_enable - $goods->traffic * 1024 * 1024 < 0) {
37+
// 商品到期自动扣总流量
38+
if ($u->transfer_enable - $goods->traffic * 1048576 <= 0) {
3439
User::where('id', $og->user_id)->update(['transfer_enable' => 0]);
3540
} else {
36-
User::where('id', $og->user_id)->decrement('transfer_enable', $goods->traffic * 1024 * 1024);
41+
User::where('id', $og->user_id)->decrement('transfer_enable', $goods->traffic * 1048576);
3742
}
43+
44+
OrderGoods::where('id', $og->id)->update(['is_expire' => 1]);
3845
}
3946
}
4047

app/Console/Commands/DisableExpireUserJob.php renamed to app/Console/Commands/AutoDisableExpireUserJob.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace App\Console\Commands;
44

5-
use App\Http\Models\User;
65
use Illuminate\Console\Command;
6+
use App\Http\Models\User;
77
use Log;
88

9-
class DisableExpireUserJob extends Command
9+
class autoDisableExpireUserJob extends Command
1010
{
11-
protected $signature = 'command:disableExpireUserJob';
12-
protected $description = '禁用到期账号';
11+
protected $signature = 'command:autoDisableExpireUserJob';
12+
protected $description = '到期账号自动禁用';
1313

1414
public function __construct()
1515
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use App\Http\Models\Coupon;
7+
use Log;
8+
9+
class AutoExpireCouponJob extends Command
10+
{
11+
protected $signature = 'command:autoExpireCouponJob';
12+
protected $description = '优惠券到期自动置无效';
13+
14+
public function __construct()
15+
{
16+
parent::__construct();
17+
}
18+
19+
public function handle()
20+
{
21+
$couponList = Coupon::where('status', 0)->where('available_end', '<=', time())->get();
22+
if (!$couponList->isEmpty()) {
23+
foreach ($couponList as $coupon) {
24+
Coupon::where('id', $coupon->id)->update(['status' => 2]);
25+
}
26+
}
27+
28+
Log::info('定时任务:' . $this->description);
29+
}
30+
}

app/Console/Commands/InviteExpire.php renamed to app/Console/Commands/AutoExpireInviteJob.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace App\Console\Commands;
44

5-
use App\Http\Models\Invite;
65
use Illuminate\Console\Command;
6+
use App\Http\Models\Invite;
77
use Log;
88

9-
class InviteExpire extends Command
9+
class AutoExpireInviteJob extends Command
1010
{
11-
protected $signature = 'command:inviteExpire';
12-
protected $description = '邀请码过期废除';
11+
protected $signature = 'command:autoExpireInviteJob';
12+
protected $description = '邀请码过期自动置无效';
1313

1414
public function __construct()
1515
{
@@ -19,7 +19,7 @@ public function __construct()
1919
public function handle()
2020
{
2121
$inviteList = Invite::where('status', 0)->where('dateline', '<=', date('Y-m-d H:i:s'))->get();
22-
if ($inviteList->isEmpty()) {
22+
if (!$inviteList->isEmpty()) {
2323
foreach ($inviteList as $invite) {
2424
Invite::where('id', $invite->id)->update(['status' => 2]);
2525
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use App\Http\Models\Config;
7+
use App\Http\Models\User;
8+
use Log;
9+
10+
class AutoResetUserTrafficJob extends Command
11+
{
12+
protected $signature = 'command:autoResetUserTrafficJob';
13+
protected $description = '自动重置账号的流量';
14+
15+
protected static $config;
16+
17+
public function __construct()
18+
{
19+
parent::__construct();
20+
21+
$config = Config::get();
22+
$data = [];
23+
foreach ($config as $vo) {
24+
$data[$vo->name] = $vo->value;
25+
}
26+
27+
self::$config = $data;
28+
}
29+
30+
public function handle()
31+
{
32+
if (self::$config['reset_traffic']) {
33+
$user_ids = User::where('pay_way', '<>', 0)->select(['id'])->get();
34+
User::whereIn('id', $user_ids)->update(['u' => 0, 'd' => 0]);
35+
}
36+
37+
Log::info('定时任务:' . $this->description);
38+
}
39+
}

app/Console/Commands/UserExpireWarningJob.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
use Illuminate\Console\Command;
66
use App\Http\Models\Config;
77
use App\Http\Models\User;
8+
use App\Http\Models\EmailLog;
89
use App\Mail\userExpireWarning;
910
use Mail;
1011
use Log;
1112

1213
class UserExpireWarningJob extends Command
1314
{
1415
protected $signature = 'command:userExpireWarningJob';
15-
protected $description = '用户到期提醒发邮件';
16+
protected $description = '用户到期自动发邮件提醒';
1617

1718
protected static $config;
1819

@@ -56,4 +57,24 @@ public function handle()
5657

5758
Log::info('定时任务:' . $this->description);
5859
}
60+
61+
/**
62+
* 写入邮件发送日志
63+
* @param int $user_id 用户ID
64+
* @param string $title 投递类型(投递标题)
65+
* @param string $content 投递内容(简要概述)
66+
* @param int $status 投递状态
67+
* @param string $error 投递失败时记录的异常信息
68+
*/
69+
private function sendEmailLog($user_id, $title, $content, $status = 1, $error = '')
70+
{
71+
$emailLogObj = new EmailLog();
72+
$emailLogObj->user_id = $user_id;
73+
$emailLogObj->title = $title;
74+
$emailLogObj->content = $content;
75+
$emailLogObj->status = $status;
76+
$emailLogObj->error = $error;
77+
$emailLogObj->created_at = date('Y-m-d H:i:s');
78+
$emailLogObj->save();
79+
}
5980
}

app/Console/Commands/UserTrafficWarningJob.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
use Illuminate\Console\Command;
66
use App\Http\Models\Config;
77
use App\Http\Models\User;
8+
use App\Http\Models\EmailLog;
89
use App\Mail\userTrafficWarning;
910
use Mail;
1011
use Log;
1112

1213
class UserTrafficWarningJob extends Command
1314
{
1415
protected $signature = 'command:userTrafficWarningJob';
15-
protected $description = '用户流量警告提醒发邮件';
16+
protected $description = '用户流量警告自动发邮件提醒';
1617

1718
protected static $config;
1819

@@ -56,4 +57,24 @@ public function handle()
5657

5758
Log::info('定时任务:' . $this->description);
5859
}
60+
61+
/**
62+
* 写入邮件发送日志
63+
* @param int $user_id 用户ID
64+
* @param string $title 投递类型(投递标题)
65+
* @param string $content 投递内容(简要概述)
66+
* @param int $status 投递状态
67+
* @param string $error 投递失败时记录的异常信息
68+
*/
69+
private function sendEmailLog($user_id, $title, $content, $status = 1, $error = '')
70+
{
71+
$emailLogObj = new EmailLog();
72+
$emailLogObj->user_id = $user_id;
73+
$emailLogObj->title = $title;
74+
$emailLogObj->content = $content;
75+
$emailLogObj->status = $status;
76+
$emailLogObj->error = $error;
77+
$emailLogObj->created_at = date('Y-m-d H:i:s');
78+
$emailLogObj->save();
79+
}
5980
}

app/Console/Kernel.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class Kernel extends ConsoleKernel
1313
* @var array
1414
*/
1515
protected $commands = [
16-
\App\Console\Commands\DisableExpireUserJob::class,
1716
\App\Console\Commands\AutoDecGoodsTrafficJob::class,
18-
\App\Console\Commands\UserTrafficWarningJob::class,
17+
\App\Console\Commands\AutoDisableExpireUserJob::class,
18+
\App\Console\Commands\AutoExpireInviteJob::class,
19+
\App\Console\Commands\AutoExpireCouponJob::class,
20+
\App\Console\Commands\autoResetUserTrafficJob::class,
1921
\App\Console\Commands\UserExpireWarningJob::class,
20-
\App\Console\Commands\InviteExpire::class,
22+
\App\Console\Commands\UserTrafficWarningJob::class,
2123
];
2224

2325
/**
@@ -28,11 +30,13 @@ class Kernel extends ConsoleKernel
2830
*/
2931
protected function schedule(Schedule $schedule)
3032
{
31-
$schedule->command('command:disableExpireUserJob')->everyMinute();
3233
$schedule->command('command:autoDecGoodsTrafficJob')->everyTenMinutes();
33-
$schedule->command('command:userTrafficWarningJob')->daily();
34+
$schedule->command('command:autoDisableExpireUserJob')->everyMinute();
35+
$schedule->command('command:autoExpireCouponJob')->everyThirtyMinutes();
36+
$schedule->command('command:autoExpireInviteJob')->everyThirtyMinutes();
37+
$schedule->command('command:autoResetUserTrafficJob')->monthly();
3438
$schedule->command('command:userExpireWarningJob')->daily();
35-
$schedule->command('command:inviteExpire')->everyThirtyMinutes();
39+
$schedule->command('command:userTrafficWarningJob')->daily();
3640
}
3741

3842
/**

app/Http/Controllers/AdminController.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Models\Article;
66
use App\Http\Models\Config;
77
use App\Http\Models\Invite;
8+
use App\Http\Models\OrderGoods;
89
use App\Http\Models\ReferralApply;
910
use App\Http\Models\ReferralLog;
1011
use App\Http\Models\SsConfig;
@@ -1314,14 +1315,17 @@ public function applyDetail(Request $request)
13141315
{
13151316
$id = $request->get('id');
13161317

1317-
13181318
$list = [];
13191319
$apply = ReferralApply::where('id', $id)->with('user')->first();
1320-
if (!empty($apply) && !empty($apply->link_logs)) {
1320+
if ($apply && $apply->link_logs) {
13211321
$link_logs = explode(',', $apply->link_logs);
13221322
$list = ReferralLog::whereIn('id', $link_logs)->with('user')->paginate(10);
13231323
}
13241324

1325+
foreach ($list as &$vo) {
1326+
$vo->goods = OrderGoods::where('oid', $vo->order_id)->with('goods')->first();
1327+
}
1328+
13251329
$view['info'] = $apply;
13261330
$view['list'] = $list;
13271331

@@ -1348,4 +1352,14 @@ public function setApplyStatus(Request $request)
13481352

13491353
return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
13501354
}
1355+
1356+
// 重置用户流量
1357+
public function resetUserTraffic(Request $request)
1358+
{
1359+
$id = $request->get('id');
1360+
1361+
User::where('id', $id)->update(['u' => 0, 'd' => 0]);
1362+
1363+
return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
1364+
}
13511365
}

app/Http/Controllers/RegisterController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function index(Request $request)
111111
$user->passwd = $this->makeRandStr();
112112
$user->transfer_enable = $transfer_enable;
113113
$user->enable_time = date('Y-m-d H:i:s');
114-
$user->expire_time = date('Y-m-d H:i:s', strtotime("+30 days"));
114+
$user->expire_time = date('Y-m-d H:i:s', strtotime("+1 days"));
115115
$user->reg_ip = $request->getClientIp();
116116
$user->referral_uid = $referral_uid;
117117
$user->save();

0 commit comments

Comments
 (0)