Created
June 18, 2019 04:49
-
-
Save nutch31/89d305b0fd1a260baed45cb608d20e10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Illuminate\Http\Request; | |
use Carbon\Carbon; | |
use DateTime; | |
use App\Model\Call; | |
use App\Model\Lead; | |
class updateDirectChannelIdCallLeads extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'command:updateDirectChannelIdCallLeads'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Update Direct Channel Id in table leads field phone'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$leads = Lead::where('type', 'phone') | |
->whereNull('direct_channel_id') | |
->orderBy('submitted_date_time', 'asc') | |
->get(); | |
foreach($leads as $lead) | |
{ | |
$call = Call::where([ | |
['date', $lead->submitted_date_time], | |
])->orderBy('date', 'desc')->first(); | |
if(!empty($call)) | |
{ | |
Lead::where('id', $lead->id)->update([ | |
'direct_channel_id' => $call->channel_id | |
]); | |
} | |
} | |
return response(array( | |
'Status' => 'Success' | |
), '200'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment