diff --git a/app/Console/Commands/ConvertUser.php b/app/Console/Commands/ConvertUser.php index a89e706..d630473 100644 --- a/app/Console/Commands/ConvertUser.php +++ b/app/Console/Commands/ConvertUser.php @@ -68,15 +68,26 @@ class ConvertUser extends Command */ private function insertPhone($phones,$userId) { - $phones = json_decode($phones); foreach($phones as $phone) { + $number_type ; + $regex = '/^09[0,1,2,3,9]{1}[0-9]{8}$/'; + + if (preg_match($regex,$phone->tel) == 1) + { + $number_type = 'cellphone'; + }else{ + $number_type = 'telephone'; + } + + Database::table('wmuser_common.phones')->insertOrIgnore([ 'phonable_id' => $userId, 'number' => $phone->tel, 'label' => $phone->label, + 'number_type' => $number_type, 'phonable_type' => 'user', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), @@ -127,8 +138,7 @@ class ConvertUser extends Command private function insertToClientStatuses($clientStatus) { - - $check_client_status = DB::table('wmuser_crm.client_statuses') + $check_client_status = Database::table('wmuser_crm.client_statuses') ->where('name' , $clientStatus) ->first(); @@ -195,7 +205,7 @@ class ConvertUser extends Command Database::table('wmuser_crm.client_categories')->insertOrIgnore([ 'name_en' => $category->name_en, 'name' => $category->name_fa, - 'parent_id' => $category->parent_id, + 'parent_id' => null, 'business_id' => 3, 'user_id' => $client_id, 'level' => 1, @@ -244,12 +254,27 @@ class ConvertUser extends Command $cellPhone = null; + foreach ($phones as $phone) + { + + $phone->tel = str_replace(' ','',$phone->tel); + + } + for( $i=0; $i <= count($phones)-1 ; $i++ ) { - if($phones[$i]->label == 'Mobile') + + $regex = '/^09[0,1,2,3,9]{1}[0-9]{8}$/'; + + $match = preg_match($regex,$phones[$i]->tel); + + if ($match == 1) { $cellPhone = $phones[$i]->tel; + break; + } + } @@ -264,6 +289,7 @@ class ConvertUser extends Command $userTableData = [ 'name' => $userData->brand_fa, + 'name_en' => $userData->brand_en, 'business_id' => 3, 'cell_number' => $cellPhone, 'detail' => json_encode($userTableDedails), @@ -284,7 +310,7 @@ class ConvertUser extends Command $newUserId = $this->insertRowToUsers($userTableData); $this->categoriesConfig($userData->category_id, $newUserId); $this->InsertAddress($userAddress, $userData->id,$newUserId); - $this->insertPhone($userData->phones , $newUserId); + $this->insertPhone($phones , $newUserId); $lastStatusId = $this->insertToClientStatuses($userData->status); $this->updateToUserStatus($newUserId,$lastStatusId); $count ++;