43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Client;
|
|
use App\Models\Customers;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Services\GoogleAdsService;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class MigrateClientCustomer extends Command
|
|
{
|
|
protected $signature = 'customer:migrate-client-customers';
|
|
protected $description = 'Migrate client customer data';
|
|
public function handle()
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$clients = Client::where('sql_acc_code', '!=', null)->get();
|
|
|
|
foreach ($clients as $client) {
|
|
$customers = explode(',',$client->sql_acc_code);
|
|
foreach($customers as $customer){
|
|
$client->customers()->create([
|
|
// 'company_name' => $customer,
|
|
'sql_acc_code' => $customer,
|
|
]);
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
Log::error('Error project linkage : '.$e->getMessage(), [
|
|
'trace' => $e->getTraceAsString(),
|
|
]);
|
|
return 1;
|
|
}
|
|
}
|
|
}
|