From f540d5984146273f24802eedf98bcbe3ce4ddabe Mon Sep 17 00:00:00 2001 From: azizi Date: Thu, 17 Sep 2020 18:15:09 +0430 Subject: [PATCH 01/13] transfar user from temp_businesses to users and more tables --- app/Console/Commands/convertUsers.php | 250 ++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 app/Console/Commands/convertUsers.php diff --git a/app/Console/Commands/convertUsers.php b/app/Console/Commands/convertUsers.php new file mode 100644 index 0000000..2e473c4 --- /dev/null +++ b/app/Console/Commands/convertUsers.php @@ -0,0 +1,250 @@ +get(); + return $data; + } + + /** + * Insert a row in table users + */ + private function insertRowToUsers($data) + { + Database::table('users')->insertOrIgnore($data); + $lastUser = Database::select('SELECT * FROM `users` WHERE id=(SELECT max(id) FROM `users`)'); + + return $lastUser[0]->id; + } + + + /** + * Insert to wmuser_common phone + */ + private function insertPhone($phones,$timestamp,$userId) + { + $phones = json_decode($phones); + + foreach($phones as $phone) + { + + Database::table('wmuser_common.phones')->insertOrIgnore([ + 'phonable_id' => $userId, + 'number' => $phone->tel, + 'label' => $phone->label, + 'phonable_type' => 'user', + 'created_at' => $timestamp['created_at'], + 'updated_at' => $timestamp['updated_at'], + ]); + + } + + } + + + /** + * Insert address + */ + + private function InsertAddress($addressData,$tmp_id, $userId) + { + $userAddress = Database::select( + 'select * from `addresses` where addressable_id=? and addressable_type =?', + [ + $tmp_id, + 'App\TempBusiness' + ] + ); + + foreach ($userAddress as $address) + { + Database::table('wmuser_common.addresses')->insertOrIgnore([ + 'title' => $address->title, + 'city_id' => $addressData['city_id'], + 'district_id' => $addressData['district_id'], + 'postal_code' => $address->postal_code, + 'addressable_id' => $userId, + 'addressable_type' => 'user', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ]); + } + + + } + + + + /** + * Delete from table temp_businesses + */ + private function deleteTempBusiness() + { + Database::table('temp_businesses')->delete(); + } + + + /** + * insert Status to client status + * + */ + private function insertToClientStatuses($clientStatus) + { + + Database::table('wmuser_crm.client_statuses')->insertOrIgnore([ + 'name' => $clientStatus, + 'user_id' => 52, + 'business_id' => 3, + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ]); + + } + + + /** + * Insert categories with Id + */ + private function categoriesConfig($categoryId, $client_id) + { + + $category = Database::select('select * from `categories` where id=? ' , [$categoryId]); + + + Database::table('wmuser_crm.client_categories')->insertOrIgnore([ + 'name_en' => $category[0]->name_en, + 'name' => $category[0]->name_fa, + 'parent_id' => $category[0]->parent_id, + 'business_id' => 3, + 'user_id' => $client_id, + 'level' => 1, + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ]); + + $clientCategories = Database::table('wmuser_crm.client_categories')->latest()->first(); + + + Database::table('wmuser_crm.client_client_category')->insertOrIgnore([ + 'client_category_id' => $clientCategories->id, + 'client_id' => $client_id + + ]); + + + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + + $count = 0; + foreach($this->getBusinessRows() as $userData) + { + + $phones = json_decode($userData->phones); + + $cellPhone = null; + + for( $i=0; $i <= count($phones)-1 ; $i++ ) + { + if($phones[$i]->label == 'Mobile') + { + $cellPhone = $phones[$i]->tel; + } + } + + + $userTableDedails = [ + 'address' => [ + 'latitude' => $userData->latitude, + 'longitude' => $userData->longitude + ], + 'details' => json_decode($userData->details), + ]; + + $timestamp = [ + 'created_at' => $userData->created_at, + 'updated_at' => $userData->updated_at, + 'deleted_at' => $userData->deleted_at + ]; + + $userTableData = [ + 'name' => $userData->brand_fa, + 'business_id' => 3, + 'cell_number' => $cellPhone, + 'detail' => json_encode($userTableDedails), + 'instagram' => json_decode($userData->details)->InstagramID, + 'telegram' => json_decode($userData->details)->TelegramID, + 'email' => json_decode($userData->details)->Email, + 'created_at' => $timestamp['created_at'], + 'updated_at' => $timestamp['updated_at'], + 'deleted_at' => $timestamp['deleted_at'] + ]; + + $userAddress = [ + 'district_id' => $userData->district_id, + 'city_id' => $userData->city_id + ]; + + + $newUserId = $this->insertRowToUsers($userTableData); + $this->categoriesConfig($userData->category_id, $newUserId); + $this->InsertAddress($userAddress, $userData->id,$newUserId); + $this->insertPhone($userData->phones , $timestamp , $newUserId); + $count ++; + $this->info('success transfer user : '. $newUserId . 'count of add :'.$count); + + } + + // $this->deleteTempBusiness(); + + + } + +} From 20a22f1d0c05c81bc5417f7de699913b69fd83ef Mon Sep 17 00:00:00 2001 From: azizi Date: Mon, 21 Sep 2020 19:01:27 +0330 Subject: [PATCH 02/13] change some feature --- app/Console/Commands/{convertUsers.php => ConvertUsers.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app/Console/Commands/{convertUsers.php => ConvertUsers.php} (99%) diff --git a/app/Console/Commands/convertUsers.php b/app/Console/Commands/ConvertUsers.php similarity index 99% rename from app/Console/Commands/convertUsers.php rename to app/Console/Commands/ConvertUsers.php index 2e473c4..da3b856 100644 --- a/app/Console/Commands/convertUsers.php +++ b/app/Console/Commands/ConvertUsers.php @@ -6,7 +6,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\DB as Database; use Illuminate\Support\Carbon; -class convertUsers extends Command +class ConvertUsers extends Command { /** * The name and signature of the console command. From 6ffe337045a50cd8abf2634975d7ac47cc26e03d Mon Sep 17 00:00:00 2001 From: azizi Date: Mon, 21 Sep 2020 20:06:10 +0330 Subject: [PATCH 03/13] add client status --- app/Console/Commands/ConvertUsers.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/ConvertUsers.php b/app/Console/Commands/ConvertUsers.php index da3b856..af1f7aa 100644 --- a/app/Console/Commands/ConvertUsers.php +++ b/app/Console/Commands/ConvertUsers.php @@ -237,8 +237,9 @@ class ConvertUsers extends Command $this->categoriesConfig($userData->category_id, $newUserId); $this->InsertAddress($userAddress, $userData->id,$newUserId); $this->insertPhone($userData->phones , $timestamp , $newUserId); + $this->insertToClientStatuses($userData->status); $count ++; - $this->info('success transfer user : '. $newUserId . 'count of add :'.$count); + $this->info('success transfer user : '. $newUserId . ' count of add :'.$count); } From d2b39f34aa4f6fbfa7e4e3e7bca03a511f547c43 Mon Sep 17 00:00:00 2001 From: azizi Date: Tue, 22 Sep 2020 17:06:02 +0330 Subject: [PATCH 04/13] resolve some bugs --- app/Console/Commands/ConvertUsers.php | 50 +++++++++++++++------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/app/Console/Commands/ConvertUsers.php b/app/Console/Commands/ConvertUsers.php index af1f7aa..3581b95 100644 --- a/app/Console/Commands/ConvertUsers.php +++ b/app/Console/Commands/ConvertUsers.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB as Database; use Illuminate\Support\Carbon; +use Symfony\Component\VarDumper\Cloner\Data; class ConvertUsers extends Command { @@ -62,7 +63,7 @@ class ConvertUsers extends Command /** * Insert to wmuser_common phone */ - private function insertPhone($phones,$timestamp,$userId) + private function insertPhone($phones,$userId) { $phones = json_decode($phones); @@ -74,8 +75,8 @@ class ConvertUsers extends Command 'number' => $phone->tel, 'label' => $phone->label, 'phonable_type' => 'user', - 'created_at' => $timestamp['created_at'], - 'updated_at' => $timestamp['updated_at'], + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), ]); } @@ -116,15 +117,6 @@ class ConvertUsers extends Command - /** - * Delete from table temp_businesses - */ - private function deleteTempBusiness() - { - Database::table('temp_businesses')->delete(); - } - - /** * insert Status to client status * @@ -140,8 +132,23 @@ class ConvertUsers extends Command 'updated_at' => Carbon::now() ]); + $lastStatusid = Database::table('wmuser_crm.client_statuses')->orderBy('id', 'DESC')->first(); + + return $lastStatusid->id; + } + /** + * update user status + **/ + + private function updateToUserStatus($userId,$userStatusId) + { + Database::table('users') + ->where('id', $userId) + ->update(['user_status_id' => $userStatusId]); + + } /** * Insert categories with Id @@ -208,11 +215,6 @@ class ConvertUsers extends Command 'details' => json_decode($userData->details), ]; - $timestamp = [ - 'created_at' => $userData->created_at, - 'updated_at' => $userData->updated_at, - 'deleted_at' => $userData->deleted_at - ]; $userTableData = [ 'name' => $userData->brand_fa, @@ -222,9 +224,10 @@ class ConvertUsers extends Command 'instagram' => json_decode($userData->details)->InstagramID, 'telegram' => json_decode($userData->details)->TelegramID, 'email' => json_decode($userData->details)->Email, - 'created_at' => $timestamp['created_at'], - 'updated_at' => $timestamp['updated_at'], - 'deleted_at' => $timestamp['deleted_at'] + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + 'deleted_at' => Carbon::now(), + 'user_status_id' => null, ]; $userAddress = [ @@ -236,14 +239,15 @@ class ConvertUsers extends Command $newUserId = $this->insertRowToUsers($userTableData); $this->categoriesConfig($userData->category_id, $newUserId); $this->InsertAddress($userAddress, $userData->id,$newUserId); - $this->insertPhone($userData->phones , $timestamp , $newUserId); - $this->insertToClientStatuses($userData->status); + $this->insertPhone($userData->phones , $newUserId); + $lastUserId = $this->insertToClientStatuses($userData->status); + $this->updateToUserStatus($newUserId,$lastUserId); $count ++; $this->info('success transfer user : '. $newUserId . ' count of add :'.$count); } - // $this->deleteTempBusiness(); + } From b8a9682d216cee9cae5ea2f7865792f95524127a Mon Sep 17 00:00:00 2001 From: azizi Date: Tue, 22 Sep 2020 18:29:03 +0330 Subject: [PATCH 05/13] check and test code and optimize some queries --- app/Console/Commands/ConvertUsers.php | 99 +++++++++++++-------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/app/Console/Commands/ConvertUsers.php b/app/Console/Commands/ConvertUsers.php index 3581b95..db222eb 100644 --- a/app/Console/Commands/ConvertUsers.php +++ b/app/Console/Commands/ConvertUsers.php @@ -53,10 +53,9 @@ class ConvertUsers extends Command */ private function insertRowToUsers($data) { - Database::table('users')->insertOrIgnore($data); - $lastUser = Database::select('SELECT * FROM `users` WHERE id=(SELECT max(id) FROM `users`)'); - - return $lastUser[0]->id; + Database::table('users')->insertOrIgnore($data); + $lastUser = Database::table('users')->orderBy('id', 'DESC')->first(); + return $lastUser->id; } @@ -88,32 +87,32 @@ class ConvertUsers extends Command * Insert address */ - private function InsertAddress($addressData,$tmp_id, $userId) - { - $userAddress = Database::select( - 'select * from `addresses` where addressable_id=? and addressable_type =?', - [ - $tmp_id, - 'App\TempBusiness' - ] - ); - - foreach ($userAddress as $address) - { - Database::table('wmuser_common.addresses')->insertOrIgnore([ - 'title' => $address->title, - 'city_id' => $addressData['city_id'], - 'district_id' => $addressData['district_id'], - 'postal_code' => $address->postal_code, - 'addressable_id' => $userId, - 'addressable_type' => 'user', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now() - ]); - } + private function InsertAddress($addressData,$tmp_id, $userId) + { + $userAddress = Database::select( + 'select * from `addresses` where addressable_id=? and addressable_type =?', + [ + $tmp_id, + 'App\TempBusiness' + ] + ); + + foreach ($userAddress as $address) + { + Database::table('wmuser_common.addresses')->insertOrIgnore([ + 'title' => $address->title, + 'city_id' => $addressData['city_id'], + 'district_id' => $addressData['district_id'], + 'postal_code' => $address->postal_code, + 'addressable_id' => $userId, + 'addressable_type' => 'user', + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ]); + } - } + } @@ -145,8 +144,8 @@ class ConvertUsers extends Command private function updateToUserStatus($userId,$userStatusId) { Database::table('users') - ->where('id', $userId) - ->update(['user_status_id' => $userStatusId]); + ->where('id', $userId) + ->update(['user_status_id' => $userStatusId]); } @@ -156,8 +155,7 @@ class ConvertUsers extends Command private function categoriesConfig($categoryId, $client_id) { - $category = Database::select('select * from `categories` where id=? ' , [$categoryId]); - + $category = Database::table('categories')->where('id' , $categoryId)->get(); Database::table('wmuser_crm.client_categories')->insertOrIgnore([ 'name_en' => $category[0]->name_en, @@ -174,8 +172,8 @@ class ConvertUsers extends Command Database::table('wmuser_crm.client_client_category')->insertOrIgnore([ - 'client_category_id' => $clientCategories->id, - 'client_id' => $client_id + 'client_category_id' => $clientCategories->id, + 'client_id' => $client_id ]); @@ -191,29 +189,29 @@ class ConvertUsers extends Command { $count = 0; - foreach($this->getBusinessRows() as $userData) - { + foreach($this->getBusinessRows() as $userData) + { - $phones = json_decode($userData->phones); + $phones = json_decode($userData->phones); - $cellPhone = null; + $cellPhone = null; - for( $i=0; $i <= count($phones)-1 ; $i++ ) - { - if($phones[$i]->label == 'Mobile') - { + for( $i=0; $i <= count($phones)-1 ; $i++ ) + { + if($phones[$i]->label == 'Mobile') + { $cellPhone = $phones[$i]->tel; - } - } + } + } - $userTableDedails = [ + $userTableDedails = [ 'address' => [ 'latitude' => $userData->latitude, 'longitude' => $userData->longitude ], 'details' => json_decode($userData->details), - ]; + ]; $userTableData = [ @@ -240,12 +238,13 @@ class ConvertUsers extends Command $this->categoriesConfig($userData->category_id, $newUserId); $this->InsertAddress($userAddress, $userData->id,$newUserId); $this->insertPhone($userData->phones , $newUserId); - $lastUserId = $this->insertToClientStatuses($userData->status); - $this->updateToUserStatus($newUserId,$lastUserId); + $lastStatusId = $this->insertToClientStatuses($userData->status); + $this->updateToUserStatus($newUserId,$lastStatusId); $count ++; - $this->info('success transfer user : '. $newUserId . ' count of add :'.$count); - } + $this->info('success transfer user : '. $newUserId . ' count of add : '.$count); + dd('success'); + } From 209d443627013aff53547072c874da6b047b1523 Mon Sep 17 00:00:00 2001 From: azizi Date: Tue, 22 Sep 2020 18:40:35 +0330 Subject: [PATCH 06/13] change class name --- app/Console/Commands/ConvertUsers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/ConvertUsers.php b/app/Console/Commands/ConvertUsers.php index db222eb..a4b276e 100644 --- a/app/Console/Commands/ConvertUsers.php +++ b/app/Console/Commands/ConvertUsers.php @@ -5,9 +5,9 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB as Database; use Illuminate\Support\Carbon; -use Symfony\Component\VarDumper\Cloner\Data; -class ConvertUsers extends Command + +class ConvertUser extends Command { /** * The name and signature of the console command. From f176f70ec1ce944ea89f77d8dc47bd0d61805829 Mon Sep 17 00:00:00 2001 From: azizi Date: Tue, 22 Sep 2020 18:42:13 +0330 Subject: [PATCH 07/13] solve problem --- app/Console/Commands/{ConvertUsers.php => ConvertUser.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/Console/Commands/{ConvertUsers.php => ConvertUser.php} (100%) diff --git a/app/Console/Commands/ConvertUsers.php b/app/Console/Commands/ConvertUser.php similarity index 100% rename from app/Console/Commands/ConvertUsers.php rename to app/Console/Commands/ConvertUser.php From bfd8ee60897714bc05353160f0859cb4a7e4bd3c Mon Sep 17 00:00:00 2001 From: azizi Date: Tue, 22 Sep 2020 15:15:22 +0000 Subject: [PATCH 08/13] Update 'app/Console/Commands/ConvertUser.php' --- app/Console/Commands/ConvertUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/ConvertUser.php b/app/Console/Commands/ConvertUser.php index a4b276e..2420262 100644 --- a/app/Console/Commands/ConvertUser.php +++ b/app/Console/Commands/ConvertUser.php @@ -243,7 +243,7 @@ class ConvertUser extends Command $count ++; $this->info('success transfer user : '. $newUserId . ' count of add : '.$count); - dd('success'); + } From 7d8db2927b0882a14c08cf96876438d7b42cb903 Mon Sep 17 00:00:00 2001 From: azizi Date: Wed, 23 Sep 2020 19:41:00 +0330 Subject: [PATCH 09/13] solve some bugs --- app/Console/Commands/ConvertUser.php | 101 ++++++++++++++++++++------- 1 file changed, 74 insertions(+), 27 deletions(-) diff --git a/app/Console/Commands/ConvertUser.php b/app/Console/Commands/ConvertUser.php index 2420262..a89e706 100644 --- a/app/Console/Commands/ConvertUser.php +++ b/app/Console/Commands/ConvertUser.php @@ -45,6 +45,7 @@ class ConvertUser extends Command private function getBusinessRows() { $data = Database::table('temp_businesses')->get(); + return $data; } @@ -54,7 +55,10 @@ class ConvertUser extends Command private function insertRowToUsers($data) { Database::table('users')->insertOrIgnore($data); - $lastUser = Database::table('users')->orderBy('id', 'DESC')->first(); + $lastUser = Database::table('users') + ->orderBy('id', 'DESC') + ->first(); + return $lastUser->id; } @@ -123,17 +127,36 @@ class ConvertUser extends Command private function insertToClientStatuses($clientStatus) { - Database::table('wmuser_crm.client_statuses')->insertOrIgnore([ - 'name' => $clientStatus, - 'user_id' => 52, - 'business_id' => 3, - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now() - ]); - $lastStatusid = Database::table('wmuser_crm.client_statuses')->orderBy('id', 'DESC')->first(); + $check_client_status = DB::table('wmuser_crm.client_statuses') + ->where('name' , $clientStatus) + ->first(); + + + $client_status_id; + + if ($check_client_status === null) { + + Database::table('wmuser_crm.client_statuses')->insertOrIgnore([ + 'name' => $clientStatus, + 'user_id' => 52, + 'business_id' => 3, + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ]); + + $client_status_id = Database::table('wmuser_crm.client_statuses') + ->orderBy('id', 'DESC') + ->first(); + + } else { + + $client_status_id = $check_client_status; + + } + - return $lastStatusid->id; + return $client_status_id->id; } @@ -145,7 +168,7 @@ class ConvertUser extends Command { Database::table('users') ->where('id', $userId) - ->update(['user_status_id' => $userStatusId]); + ->update(['user_status_id' => $userStatusId]); } @@ -155,24 +178,49 @@ class ConvertUser extends Command private function categoriesConfig($categoryId, $client_id) { - $category = Database::table('categories')->where('id' , $categoryId)->get(); - - Database::table('wmuser_crm.client_categories')->insertOrIgnore([ - 'name_en' => $category[0]->name_en, - 'name' => $category[0]->name_fa, - 'parent_id' => $category[0]->parent_id, - 'business_id' => 3, - 'user_id' => $client_id, - 'level' => 1, - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now() - ]); + $category = Database::table('categories') + ->where('id' , $categoryId) + ->first(); + + + + $check_category_exist = Database::table('wmuser_crm.client_categories') + ->where('name_en' , $category->name_en) + ->first(); + + $client_category_id ; + + if ($check_category_exist === null) + { + Database::table('wmuser_crm.client_categories')->insertOrIgnore([ + 'name_en' => $category->name_en, + 'name' => $category->name_fa, + 'parent_id' => $category->parent_id, + 'business_id' => 3, + 'user_id' => $client_id, + 'level' => 1, + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now() + ]); + + $client_category_id = Database::table('wmuser_crm.client_categories') + ->orderBy('id', 'DESC') + ->first(); + + + $client_category_id = $client_category_id->id; + + } else { + + $client_category_id = $check_category_exist->id; + } + + - $clientCategories = Database::table('wmuser_crm.client_categories')->latest()->first(); Database::table('wmuser_crm.client_client_category')->insertOrIgnore([ - 'client_category_id' => $clientCategories->id, + 'client_category_id' => $client_category_id, 'client_id' => $client_id ]); @@ -224,7 +272,6 @@ class ConvertUser extends Command 'email' => json_decode($userData->details)->Email, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), - 'deleted_at' => Carbon::now(), 'user_status_id' => null, ]; @@ -243,7 +290,7 @@ class ConvertUser extends Command $count ++; $this->info('success transfer user : '. $newUserId . ' count of add : '.$count); - + } From 5dd699e1b1ad8aa1d065d6f1d3c0df39e0fa381b Mon Sep 17 00:00:00 2001 From: azizi Date: Wed, 23 Sep 2020 20:37:48 +0330 Subject: [PATCH 10/13] solve bugs --- app/Console/Commands/ConvertUser.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/ConvertUser.php b/app/Console/Commands/ConvertUser.php index a89e706..d85d952 100644 --- a/app/Console/Commands/ConvertUser.php +++ b/app/Console/Commands/ConvertUser.php @@ -127,8 +127,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 +194,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, From 711b28ed56a88bbe845119beb8a6fc30e6f0b4c0 Mon Sep 17 00:00:00 2001 From: azizi Date: Thu, 24 Sep 2020 18:48:00 +0330 Subject: [PATCH 11/13] solve some bugs and improve codes --- app/Console/Commands/ConvertUser.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/ConvertUser.php b/app/Console/Commands/ConvertUser.php index d85d952..6f96fc7 100644 --- a/app/Console/Commands/ConvertUser.php +++ b/app/Console/Commands/ConvertUser.php @@ -243,12 +243,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; + } + } @@ -263,6 +278,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), @@ -283,7 +299,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 ++; From e2289a5b3643e498d321ddb0e45f1d007a4134d0 Mon Sep 17 00:00:00 2001 From: azizi Date: Thu, 24 Sep 2020 18:52:13 +0330 Subject: [PATCH 12/13] solve a bug --- app/Console/Commands/ConvertUser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Console/Commands/ConvertUser.php b/app/Console/Commands/ConvertUser.php index 6f96fc7..bcb2273 100644 --- a/app/Console/Commands/ConvertUser.php +++ b/app/Console/Commands/ConvertUser.php @@ -68,7 +68,6 @@ class ConvertUser extends Command */ private function insertPhone($phones,$userId) { - $phones = json_decode($phones); foreach($phones as $phone) { From 899ece9dc816338ddc985a5ab67789c7ca730a19 Mon Sep 17 00:00:00 2001 From: azizi Date: Thu, 24 Sep 2020 19:01:49 +0330 Subject: [PATCH 13/13] add features --- app/Console/Commands/ConvertUser.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Console/Commands/ConvertUser.php b/app/Console/Commands/ConvertUser.php index bcb2273..d630473 100644 --- a/app/Console/Commands/ConvertUser.php +++ b/app/Console/Commands/ConvertUser.php @@ -72,10 +72,22 @@ class ConvertUser extends Command 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(),