commit
ae6ba1c7d0
@ -1,327 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB as Database;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
|
||||
class ConvertUser extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'db:convert';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'This command when work you need transfer a table rows to another table row';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return data from Temp-business
|
||||
*
|
||||
* @return rows
|
||||
*
|
||||
*/
|
||||
private function getBusinessRows()
|
||||
{
|
||||
$data = Database::table('temp_businesses')->get();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a row in table users
|
||||
*/
|
||||
private function insertRowToUsers($data)
|
||||
{
|
||||
Database::table('users')->insertOrIgnore($data);
|
||||
$lastUser = Database::table('users')
|
||||
->orderBy('id', 'DESC')
|
||||
->first();
|
||||
|
||||
return $lastUser->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert to wmuser_common phone
|
||||
*/
|
||||
private function insertPhone($phones,$userId)
|
||||
{
|
||||
|
||||
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(),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* insert Status to client status
|
||||
*
|
||||
*/
|
||||
private function insertToClientStatuses($clientStatus)
|
||||
{
|
||||
|
||||
$check_client_status = Database::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 $client_status_id->id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* update user status
|
||||
**/
|
||||
|
||||
private function updateToUserStatus($userId,$userStatusId)
|
||||
{
|
||||
Database::table('users')
|
||||
->where('id', $userId)
|
||||
->update(['user_status_id' => $userStatusId]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert categories with Id
|
||||
*/
|
||||
private function categoriesConfig($categoryId, $client_id)
|
||||
{
|
||||
|
||||
$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' => null,
|
||||
'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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Database::table('wmuser_crm.client_client_category')->insertOrIgnore([
|
||||
'client_category_id' => $client_category_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;
|
||||
|
||||
foreach ($phones as $phone)
|
||||
{
|
||||
|
||||
$phone->tel = str_replace(' ','',$phone->tel);
|
||||
|
||||
}
|
||||
|
||||
for( $i=0; $i <= count($phones)-1 ; $i++ )
|
||||
{
|
||||
|
||||
$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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$userTableDedails = [
|
||||
'address' => [
|
||||
'latitude' => $userData->latitude,
|
||||
'longitude' => $userData->longitude
|
||||
],
|
||||
'details' => json_decode($userData->details),
|
||||
];
|
||||
|
||||
|
||||
$userTableData = [
|
||||
'name' => $userData->brand_fa,
|
||||
'name_en' => $userData->brand_en,
|
||||
'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' => Carbon::now(),
|
||||
'updated_at' => Carbon::now(),
|
||||
'user_status_id' => null,
|
||||
];
|
||||
|
||||
$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($phones , $newUserId);
|
||||
$lastStatusId = $this->insertToClientStatuses($userData->status);
|
||||
$this->updateToUserStatus($newUserId,$lastStatusId);
|
||||
$count ++;
|
||||
|
||||
$this->info('success transfer user : '. $newUserId . ' count of add : '.$count);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,101 @@
|
||||
<template>
|
||||
<div class="upload-example width-full">
|
||||
<cropper classname="upload-example-cropper" :stencil-props="stencilProps" @change="onChangeCropper" :src="image" />
|
||||
<div class="button-wrapper">
|
||||
<v-btn
|
||||
@click.native="$refs['image_'+uniqueId].click()"
|
||||
large
|
||||
:color="color"
|
||||
dark
|
||||
>
|
||||
<input
|
||||
type="file"
|
||||
:ref="'image_'+uniqueId"
|
||||
:name="'image_' + uniqueId"
|
||||
v-show="false"
|
||||
@change="uploadImage($event)"
|
||||
accept="image/*"
|
||||
/>
|
||||
<v-icon dark>{{icon}}</v-icon>{{name}}
|
||||
</v-btn>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { Cropper } from "vue-advanced-cropper";
|
||||
export default {
|
||||
props: {
|
||||
name: {
|
||||
default: 'آپلود عکس'
|
||||
},
|
||||
icon: {
|
||||
default: 'WMi-upload'
|
||||
},
|
||||
color: {
|
||||
default: 'black'
|
||||
},
|
||||
stencilProps: {
|
||||
default: () => ({aspectRatio: 1, checkImageOrigin: false})
|
||||
},
|
||||
crop_data: {
|
||||
default: () => ([])
|
||||
},
|
||||
value: {
|
||||
default: ''
|
||||
},
|
||||
url: {
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
components: {
|
||||
Cropper
|
||||
},
|
||||
data: () => ({
|
||||
uniqueId: Math.floor(Math.random() * 10000),
|
||||
}),
|
||||
computed: {
|
||||
image: {
|
||||
get() {
|
||||
return this.url;
|
||||
},
|
||||
set(value) {
|
||||
this.$emit('update:url', value);
|
||||
}
|
||||
},
|
||||
file: {
|
||||
get() {
|
||||
return this.value;
|
||||
},
|
||||
set(value) {
|
||||
this.$emit('input', value);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
uploadImage(event) {
|
||||
// Reference to the DOM input element
|
||||
let input = event.target;
|
||||
// Ensure that you have a file before attempting to read it
|
||||
if (input.files && input.files[0])
|
||||
{
|
||||
//set v-model
|
||||
this.file = input.files[0];
|
||||
|
||||
// create a new FileReader to read this image and convert to base64 format
|
||||
let reader = new FileReader();
|
||||
// Define a callback function to run, when FileReader finishes its job
|
||||
reader.onload = e => {
|
||||
// Note: arrow function used here, so that "this.imageData" refers to the imageData of Vue component
|
||||
// Read image as base64 and set to imageData
|
||||
this.image = e.target.result;
|
||||
};
|
||||
// Start the reader job - read file as a data url (base64 format)
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
}
|
||||
},
|
||||
onChangeCropper({coordinates}) {
|
||||
this.$emit('update:crop_data', coordinates);
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
@ -0,0 +1,89 @@
|
||||
const isUndefined = (value) => value === undefined;
|
||||
|
||||
const isNull = (value) => value === null;
|
||||
|
||||
const isBoolean = (value) => typeof value === 'boolean';
|
||||
|
||||
const isObject = (value) => value === Object(value);
|
||||
|
||||
const isArray = (value) => Array.isArray(value);
|
||||
|
||||
const isDate = (value) => value instanceof Date;
|
||||
|
||||
const isBlob = (value) =>
|
||||
value &&
|
||||
typeof value.size === 'number' &&
|
||||
typeof value.type === 'string' &&
|
||||
typeof value.slice === 'function';
|
||||
|
||||
const isFile = (value) =>
|
||||
isBlob(value) &&
|
||||
typeof value.name === 'string' &&
|
||||
(typeof value.lastModifiedDate === 'object' ||
|
||||
typeof value.lastModified === 'number');
|
||||
|
||||
const objectToFormData = (obj, cfg, fd, pre) => {
|
||||
cfg = cfg || {};
|
||||
|
||||
cfg.indices = isUndefined(cfg.indices) ? true : cfg.indices;
|
||||
|
||||
cfg.nullsAsUndefineds = isUndefined(cfg.nullsAsUndefineds)
|
||||
? false
|
||||
: cfg.nullsAsUndefineds;
|
||||
|
||||
cfg.booleansAsIntegers = isUndefined(cfg.booleansAsIntegers)
|
||||
? false
|
||||
: cfg.booleansAsIntegers;
|
||||
|
||||
cfg.allowEmptyArrays = isUndefined(cfg.allowEmptyArrays)
|
||||
? true
|
||||
: cfg.allowEmptyArrays;
|
||||
|
||||
fd = fd || new FormData();
|
||||
|
||||
if (isUndefined(obj)) {
|
||||
return fd;
|
||||
} else if (isNull(obj)) {
|
||||
if (!cfg.nullsAsUndefineds) {
|
||||
fd.append(pre, '');
|
||||
}
|
||||
} else if (isBoolean(obj)) {
|
||||
if (cfg.booleansAsIntegers) {
|
||||
fd.append(pre, obj ? 1 : 0);
|
||||
} else {
|
||||
fd.append(pre, obj);
|
||||
}
|
||||
} else if (isArray(obj)) {
|
||||
if (obj.length) {
|
||||
obj.forEach((value, index) => {
|
||||
const key = pre + '[' + (cfg.indices ? index : '') + ']';
|
||||
|
||||
objectToFormData(value, cfg, fd, key);
|
||||
});
|
||||
} else if (cfg.allowEmptyArrays) {
|
||||
fd.append(pre , []);
|
||||
}
|
||||
} else if (isDate(obj)) {
|
||||
fd.append(pre, obj.toISOString());
|
||||
} else if (isObject(obj) && !isFile(obj) && !isBlob(obj)) {
|
||||
Object.keys(obj).forEach((prop) => {
|
||||
const value = obj[prop];
|
||||
|
||||
if (isArray(value)) {
|
||||
while (prop.length > 2 && prop.lastIndexOf('[]') === prop.length - 2) {
|
||||
prop = prop.substring(0, prop.length - 2);
|
||||
}
|
||||
}
|
||||
|
||||
const key = pre ? pre + '[' + prop + ']' : prop;
|
||||
|
||||
objectToFormData(value, cfg, fd, key);
|
||||
});
|
||||
} else {
|
||||
fd.append(pre, obj);
|
||||
}
|
||||
|
||||
return fd;
|
||||
};
|
||||
|
||||
export { objectToFormData };
|
Loading…
Reference in new issue