app/Console/Commands/Fans.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle()
    {
        $accountId = $this->argument('account_id');
        $account = $this->getAccount($accountId);
        $fanModel = new FanModel();
        $userService = new User($account->app_id, $account->app_secret);
        $nextOpenId = null;
        $fanModel->where('account_id', $accountId)->delete();
        $fans = $userService->lists();
        $total = $fans['total'];
        $this->info("\n获取粉丝列表...");
        $this->output->progressStart($total);
        while (!empty($fans['data'])) {
            $inserts = [];
            $openId = null;
            foreach ($fans['data']['openid'] as $openId) {
                $input['openid'] = $openId;
                $input['account_id'] = $accountId;
                $input['created_at'] = date('Y-m-d H:i:s');
                $input['updated_at'] = date('Y-m-d H:i:s');
                $input['deleted_at'] = null;
                $inserts[] = $input;
                if (count($inserts) >= 200) {
                    $fanModel->insert($inserts);
                    $inserts = [];
                }
                $this->output->progressAdvance();
            }
            $fanModel->insert($inserts);
            $fans = $userService->lists($openId);
        }
        $this->call('sync:fan_details', array('account_id' => $account->id));
        $this->output->progressFinish();
    }
public function handle ( ) { $ accountId = $ this -> argument ( 'account_id' ) ; $ account = $ this -> getAccount ( $ accountId ) ; $ fanModel = new FanModel ( ) ; $ userService = new User ( $ account -> app_id , $ account -> app_secret ) ; $ nextOpenId = null ; $ fanModel -> where ( 'account_id' , $ accountId ) -> delete ( ) ; $ fans = $ userService -> lists ( ) ; $ total = $ fans [ 'total' ] ; $ this -> info ( " \n 获取粉丝列表..."); $ this -> output -> progressStart ( $ total ) ; while ( ! empty ( $ fans [ 'data' ] ) ) { $ inserts = [ ] ; $ openId = null ; foreach ( $ fans [ 'data' ] [ 'openid' ] as $ openId ) { $ input [ 'openid' ] = $ openId ; $ input [ 'account_id' ] = $ accountId ; $ input [ 'created_at' ] = date ( 'Y-m-d H:i:s' ) ; $ input [ 'updated_at' ] = date ( 'Y-m-d H:i:s' ) ; $ input [ 'deleted_at' ] = null ; $ inserts [ ] = $ input ; if ( count ( $ inserts ) >= 200 ) { $ fanModel -> insert ( $ inserts ) ; $ inserts = [ ] ; } $ this -> output -> progressAdvance ( ) ; } $ fanModel -> insert ( $ inserts ) ; $ fans = $ userService -> lists ( $ openId ) ; } $ this -> call ( 'sync:fan_details' , array ( 'account_id' => $ account -> id ) ) ; $ this -> output -> progressFinish ( ) ; }
Execute the console command.
Execute the console command .
/*
         * 1 获取Account
         */ /*
         * 2 初始化 SDK Config, 构建 SDK 对象
         */ /*
         * 3.1 先取消关注(设置为当前时间)
         */ /*
             * 3.2 插入数据
             */