作者 lyh

gx

1 <?php 1 <?php
2 2
3 namespace App\Console\Commands\AyrShare; 3 namespace App\Console\Commands\AyrShare;
  4 +use App\Helper\AyrShare as AyrShareHelper;
  5 +use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
  6 +use Carbon\Carbon;
  7 +use App\Models\AyrShare\AyrShare as AyrShareModel;
4 use Illuminate\Console\Command; 8 use Illuminate\Console\Command;
5 9
6 class ShareUser extends Command 10 class ShareUser extends Command
7 { 11 {
  12 + public $error = 0;
  13 + /**
  14 + * The name and signature of the console command.
  15 + *
  16 + * @var string
  17 + */
  18 + protected $signature = 'share_user';
  19 +
  20 + /**
  21 + * The console command description.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $description = '用户一周内无记录清除Ayr_share';
8 /** 26 /**
9 * @name :(定时执行)handle 27 * @name :(定时执行)handle
10 * @author :lyh 28 * @author :lyh
@@ -13,6 +31,54 @@ class ShareUser extends Command @@ -13,6 +31,54 @@ class ShareUser extends Command
13 */ 31 */
14 public function handle() 32 public function handle()
15 { 33 {
  34 + $this->user_operator_record();
  35 + }
16 36
  37 + /**
  38 + * @name : 检测用户是否无操作记录
  39 + * @author :lyh
  40 + * @method :post
  41 + * @time :2023/5/12 14:55
  42 + */
  43 + protected function user_operator_record(){
  44 + //获取所有ayr_share用户
  45 + $ayr_share_model = new AyrShareModel();
  46 + $ayr_share_list = $ayr_share_model->list();
  47 + foreach ($ayr_share_list as $k => $v){
  48 + //查询当前用户是否有未推送的博文
  49 + $ayr_release = new AyrReleaseModel();
  50 + $release_info = $ayr_release->read(['idempotency_key'=>['<',date('Y-m-d H:i:s',time())],'share_id'=>$v['id']]);
  51 + //有推文时,直接跳出循环
  52 + if($release_info !== false){
  53 + continue;
  54 + }
  55 + //查看用户是否在一周内有发送博客
  56 + $start_at = Carbon::now()->modify('-7 days')->toDateString();
  57 + $end_at = Carbon::now()->toDateString();
  58 + $release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]]]);
  59 + //有发送博文,则跳出循环
  60 + if($release_info == false){
  61 + continue;
  62 + }
  63 + //删除用户第三方配置
  64 + $ayr_share_helper = new AyrShareHelper();
  65 + $res = $ayr_share_helper->deleted_profiles();
  66 + if($res['status'] == 'fail'){
  67 + $this->error++;
  68 + continue;
  69 + }
  70 + //更新数据库
  71 + $data = [
  72 + 'title'=>null,
  73 + 'bind_plat_from'=>null,
  74 + 'profile_key'=>null,
  75 + 'ref_id'=>null,
  76 + ];
  77 + $res = $ayr_share_model->edit($data,['id'=>$v['id']]);
  78 + if($res == false){
  79 + $this->error++;
  80 + }
  81 + }
  82 + return $this->error;
17 } 83 }
18 } 84 }
@@ -22,6 +22,7 @@ class Kernel extends ConsoleKernel @@ -22,6 +22,7 @@ class Kernel extends ConsoleKernel
22 $schedule->command('rank_data_indexed_pages')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次 22 $schedule->command('rank_data_indexed_pages')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
23 $schedule->command('rank_data_recomm_domain')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次 23 $schedule->command('rank_data_recomm_domain')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
24 $schedule->command('rank_data_week')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次 24 $schedule->command('rank_data_week')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
  25 + $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
25 } 26 }
26 27
27 /** 28 /**
@@ -68,7 +68,7 @@ zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K @@ -68,7 +68,7 @@ zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
68 public function deleted_profiles($data){ 68 public function deleted_profiles($data){
69 $param = [ 69 $param = [
70 'title'=>$data['title'], 70 'title'=>$data['title'],
71 -// 'profileKey'=>$this->profile_key, 71 + 'profileKey'=>$data['profileKey'],
72 ]; 72 ];
73 $url = $this->path.'/api/profiles/profile'; 73 $url = $this->path.'/api/profiles/profile';
74 return $this->http_click('delete',$url,$param); 74 return $this->http_click('delete',$url,$param);