app/Console/Commands/AutoInit.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle()
    {
        $run_date = date('Y-m-d');
        $calc_date = date('Y-m-d', strtotime("-1 days"));
        $res = DB::table('currency')->where('id',1)->get();
        $currency = "";
        $client_id = env('TO_CLIENT_ID');
        $client_secret = env('TO_CLIENT_SECRET');
        if(sizeof($res) > 0 && $res[0]->type == 1) 
        {
            $currency = $res[0]->min_value .':'. $res[0]->max_value;
        } else 
        {
            $currency = Report::getCronJobCurrenciesRate('BRL');
        }
        $token = $this->taboolaAccess($client_id, $client_secret);
        DB::table('cron_init')
        ->updateOrInsert(
            ['date' => $run_date],
            ['currency' => $currency, 'token' => $token] 
        );
        $cmpList = $this->getTaboolaCampaigns($token, $calc_date, $calc_date);
        $index = 0;
        $insertData = [];
        foreach ($cmpList['results'] as $key => $value) {
            if($value['clicks'] == 0 && $value['spent'] == 0)
                continue;
            array_push($insertData, ['cmpid' => $value['campaign'], 'flag' => 0]);
        }
        DB::table('cron_campaign')->truncate();
        DB::table('cron_campaign')->insert($insertData);
        $this->info('CronInit has been send successfully');
    }
public function handle ( ) { $ run_date = date ( 'Y-m-d' ) ; $ calc_date = date ( 'Y-m-d' , strtotime ( " -1 days " ) ) ; $ res = DB :: table ( 'currency' ) -> where ( 'id' , 1 ) -> get ( ) ; $ currency = " " ; $ client_id = env ( 'TO_CLIENT_ID' ) ; $ client_secret = env ( 'TO_CLIENT_SECRET' ) ; if ( sizeof ( $ res ) > 0 && $ res [ 0 ] -> type == 1 ) { $ currency = $ res [ 0 ] -> min_value . ':' . $ res [ 0 ] -> max_value ; } else { $ currency = Report :: getCronJobCurrenciesRate ( 'BRL' ) ; } $ token = $ this -> taboolaAccess ( $ client_id , $ client_secret ) ; DB :: table ( 'cron_init' ) -> updateOrInsert ( [ 'date' => $ run_date ] , [ 'currency' => $ currency , 'token' => $ token ] ) ; $ cmpList = $ this -> getTaboolaCampaigns ( $ token , $ calc_date , $ calc_date ) ; $ index = 0 ; $ insertData = [ ] ; foreach ( $ cmpList [ 'results' ] as $ key => $ value ) { if ( $ value [ 'clicks' ] == 0 && $ value [ 'spent' ] == 0 ) continue ; array_push ( $ insertData , [ 'cmpid' => $ value [ 'campaign' ] , 'flag' => 0 ] ) ; } DB :: table ( 'cron_campaign' ) -> truncate ( ) ; DB :: table ( 'cron_campaign' ) -> insert ( $ insertData ) ; $ this -> info ( 'CronInit has been send successfully' ) ; }
Execute the console command.
Execute the console command .
//currency type manual //currency type auto