ShareUser.php
6.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
namespace App\Console\Commands\AyrShare;
use App\Helper\AyrShare as AyrShareHelper;
use App\Models\Ai\AiVideo;
use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use App\Models\Project\AiVideoTask;
use App\Services\ProjectServer;
use Carbon\Carbon;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ShareUser extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'share_user';
/**
* The console command description.
*
* @var string
*/
protected $description = '用户一周内无记录清除Ayr_share';
/**
* @name :(定时执行)handle
* @author :lyh
* @method :post
* @time :2023/5/12 14:48
*/
public function handle()
{
$this->output('start');
$this->user_operator_record();
return true;
}
/**
* @name : 检测用户是否无操作记录
* @author :lyh
* @method :post
* @time :2023/5/12 14:55
*/
protected function user_operator_record(){
//获取所有ayr_share用户
$ayr_share_model = new AyrShareModel();
$ayr_release = new AyrReleaseModel();
$ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=','']]);
foreach ($ayr_share_list as $v){
$this->output('执行数据的邮箱--'.$v['title']);
$time = Carbon::now()->modify('-1 days')->toDateString();
//创建时间小于7天前的当前时间
if($v['created_at'] > $time){
$this->output('创建时间小于7天跳过--'.$v['title']);
continue;
}
//查询当前用户是否有未推送的博文
$release_info = $this->release_info($ayr_release,$v);
//有推文时,直接跳出循环
if($release_info !== false){
$this->output('有未推送的推文直接跳过--'.$v['title']);
continue;
}
//查询7天是否发送博文
$release_info = $this->release_seven_info($ayr_release,$v);
//有发送博文,则跳出循环
if($release_info !== false){
$this->output('7天内有推文跳过--'.$v['title']);
continue;
}
$aiVideoInfo = $this->aiVideoInfo($v['project_id'] ?? 0);
if($aiVideoInfo !== false){
$this->output('7天内有ai视频推送跳过--'.$v['title']);
continue;
}
//删除用户第三方配置
if(!empty($v['profile_key'])){
$res = $this->del_profiles($v);
if($res === false){
continue;
}
}
//更新数据库
$this->save_ayr_share($ayr_share_model,$v);
}
return $this->error;
}
/**
* @name :(删除第三方配置)del_profiles
* @author :lyh
* @method :post
* @time :2023/6/14 16:10
*/
public function del_profiles($v){
$ayr_share_helper = new AyrShareHelper();
$data_profiles = [
'title'=>$v['title'],
'profileKey'=>$v['profile_key']
];
$res = $ayr_share_helper->deleted_profiles($data_profiles);
if($res['status'] == 'fail'){
$this->output('第三方删除失败'.json_encode($data_profiles,true));
return false;
}
return true;
}
/**
* @name :(更新数据库)save_ayr_share
* @author :lyh
* @method :post
* @time :2023/6/14 16:14
*/
public function save_ayr_share(&$ayr_share_model,$v){
//更新数据库
$data = [
'title'=>'',
'bind_platforms'=>'',
'profile_key'=>'',
'ref_id'=>'',
];
$res = $ayr_share_model->edit($data,['id'=>$v['id']]);
if($res == false){
echo '更新数据库失败';
return true;
}
return true;
}
/**
* @name :(查询是否有定时发送报文)info
* @author :lyh
* @method :post
* @time :2023/6/14 16:17
*/
public function release_info(&$ayr_release,$v){
//查询当前用户是否有未推送的博文
$release_info = $ayr_release->read(['schedule_date'=>['>',date('Y-m-d H:i:s',time())],'share_id'=>$v['id']]);
return $release_info;
}
/**
* @param $ayr_release
* @name :7天内无发送记录release_seven_info
* @author :lyh
* @method :post
* @time :2023/6/14 16:28
*/
public function release_seven_info(&$ayr_release,$v){
//查看用户是否在一周内有发送博客
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]],'share_id'=>$v['id']]);
return $release_info;
}
/**
* @remark :7天内是否推送了ai视频
* @name :aiVidoe
* @author :lyh
* @method :post
* @time :2025/9/22 17:13
*/
public function aiVideoInfo($project_id)
{
if($project_id == 0){
return false;
}
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$aiVideoModel = new AiVideoTask();
$videoInfo = $aiVideoModel->read(['project_id'=>$project_id,'next_auto_date'=>null,'created_at'=>['between',[$start_at,$end_at]]]);
return $videoInfo;
}
/**
* 输入日志
* @param $message
* @return bool
*/
public function output($message)
{
$message = date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
echo $message;
file_put_contents(storage_path('logs/share_user/') . date('Ymd') . '.log', $message, FILE_APPEND);
return true;
}
}