ShareConfig.php 1.7 KB
<?php

namespace App\Console\Commands\AyrShare;

use App\Helper\AyrShare as AyrShareHelper;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Console\Command;

class ShareConfig extends Command
{
    public $error = 0;
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'share_config';

    /**
     * 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()
    {
        $ayrShareModel = new AyrShareModel();
        //更新用户配置
        $lists = $ayrShareModel->lists($this->map,$this->page,$this->row,'id',['id','profile_key','bind_plat_from']);
        foreach ($lists['list'] as $k => $v){
            if(empty($v['profile_key'])){
                continue;
            }
            //获取当前用户配置
            $ayrShareHelper = new AyrShareHelper();
            $share_info = $ayrShareHelper->get_profiles_users($v['profile_key']);
            if(!isset($share_info['activeSocialAccounts'])){
                $ayrShareModel->edit(['bind_plat_from'=>''],['id'=>$v['id']]);
                continue;
            }
            $str = json_encode($share_info['activeSocialAccounts']);
            if($str != $v['bind_plat_from']){
                $rs = $ayrShareModel->edit(['bind_plat_from'=>$str],['id'=>$v['id']]);
                if($rs === false){
                    $this->error++;
                }
            }
        }
        echo $this->error;
    }
}