Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
ucenter
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
68766389
authored
Jan 25, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化bug
parent
88ddb501
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
149 additions
and
3 deletions
app/Console/Commands/TransferUser.php
app/Http/Services/DataService.php
app/Providers/EventServiceProvider.php
config/database.php
routes/web.php
app/Console/Commands/TransferUser.php
0 → 100644
View file @
68766389
<?php
namespace
App\Console\Commands
;
use
App\Http\Services\DataService
;
use
Illuminate\Console\Command
;
class
TransferUser
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'transferUser'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Command description'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return int
*/
public
function
handle
()
{
DataService
::
transferIchuntUser
();
}
}
app/Http/Services/DataService.php
0 → 100644
View file @
68766389
<?php
namespace
App\Http\Services
;
use
App\Http\Models\UserModel
;
use
Illuminate\Support\Facades\Redis
;
class
DataService
{
//转移3.0的数据到用户中心
public
static
function
transferIchuntUser
()
{
\DB
::
connection
(
'www'
)
->
table
(
'user_main'
)
->
orderBy
(
'user_id'
)
->
select
([
'mobile'
,
'email'
,
'password'
,
'salt'
,
'user_id'
])
->
chunk
(
100
,
function
(
$users
)
{
$redis
=
Redis
::
connection
(
'user_new'
);
foreach
(
$users
as
$user
)
{
$user
=
(
array
)
$user
;
dump
(
'迁移用户 : '
.
$user
[
'user_id'
]
.
'-----'
.
$user
[
'mobile'
]
.
'----'
.
$user
[
'email'
]);
if
(
empty
(
$user
[
'mobile'
])
&&
empty
(
$user
[
'email'
]))
{
continue
;
}
$userId
=
$user
[
'user_id'
];
//插入到db以后,回写到3.0的db
$user
[
'create_time'
]
=
time
();
unset
(
$user
[
'user_id'
]);
$ucId
=
UserModel
::
insertGetId
(
$user
);
\DB
::
connection
(
'www'
)
->
table
(
'user_main'
)
->
where
(
'user_id'
,
$userId
)
->
update
([
'uc_id'
=>
$ucId
]);
//还要去修改api_user缓存
$cached
=
$redis
->
hget
(
'api_user'
,
$userId
);
if
(
empty
(
$cached
))
{
continue
;
}
$cached
=
json_decode
(
$cached
,
true
);
$cached
[
'uc_id'
]
=
$ucId
;
$cached
=
json_encode
(
$cached
);
$redis
->
hset
(
'api_user'
,
$userId
,
$cached
);
}
});
}
public
static
function
initApiUser
()
{
$redis
=
Redis
::
connection
(
'user_new'
);
\DB
::
connection
(
'www'
)
->
table
(
'user_main'
)
->
orderBy
(
'user_id'
)
->
select
([
'mobile'
,
'email'
,
'password'
,
'salt'
,
'user_id'
,
'uc_id'
])
->
chunk
(
100
,
function
(
$users
)
use
(
$redis
)
{
foreach
(
$users
as
$user
)
{
$user
=
(
array
)
$user
;
if
(
empty
(
$user
[
'uc_id'
]))
{
continue
;
}
$userId
=
$user
[
'user_id'
];
//还要去修改api_user缓存
$cached
=
$redis
->
hget
(
'api_user'
,
$userId
);
if
(
empty
(
$cached
))
{
continue
;
}
$cached
=
json_decode
(
$cached
,
true
);
$cached
[
'uc_id'
]
=
$user
[
'uc_id'
];
$cached
=
json_encode
(
$cached
);
$redis
->
hset
(
'api_user'
,
$userId
,
$cached
);
}
});
}
}
app/Providers/EventServiceProvider.php
View file @
68766389
...
...
@@ -18,9 +18,9 @@ class EventServiceProvider extends ServiceProvider
Registered
::
class
=>
[
SendEmailVerificationNotification
::
class
,
],
'Illuminate\Database\Events\QueryExecuted'
=>
[
'App\Listeners\QueryListener'
,
]
//
'Illuminate\Database\Events\QueryExecuted' => [
//
'App\Listeners\QueryListener',
//
]
];
/**
...
...
config/database.php
View file @
68766389
...
...
@@ -61,6 +61,19 @@ return [
'strict'
=>
false
,
'engine'
=>
null
,
],
'www'
=>
[
'driver'
=>
'mysql'
,
'host'
=>
get_resource_config_section
(
'db'
,
'db_liexin'
)[
'host'
],
'database'
=>
get_resource_config_section
(
'db'
,
'db_liexin'
)[
'db'
],
'username'
=>
get_resource_config_section
(
'db'
,
'db_liexin'
)[
'user'
],
'password'
=>
get_resource_config_section
(
'db'
,
'db_liexin'
)[
'passwd'
],
'port'
=>
3306
,
'charset'
=>
'utf8'
,
'collation'
=>
'utf8_general_ci'
,
'prefix'
=>
'lie_'
,
'strict'
=>
false
,
'engine'
=>
null
,
],
],
/*
...
...
@@ -129,6 +142,13 @@ return [
'database'
=>
0
,
'prefix'
=>
env
(
'PREFIX'
,
''
)
],
'user_new'
=>
[
'host'
=>
get_resource_config_section
(
'redis'
,
'user_new'
)[
'host'
],
'password'
=>
get_resource_config_section
(
'redis'
,
'user_new'
)[
'passwd'
],
'port'
=>
get_resource_config_section
(
'redis'
,
'user_new'
)[
'port'
],
'database'
=>
0
,
'prefix'
=>
env
(
'PREFIX'
,
''
)
],
],
...
...
routes/web.php
View file @
68766389
...
...
@@ -14,6 +14,10 @@ use Illuminate\Support\Facades\Route;
*/
Route
::
get
(
'/'
,
"IndexController@index"
);
// 主菜单
Route
::
get
(
'/dataHandle'
,
function
()
{
\App\Http\Services\DataService
::
transferIchuntUser
();
});
Route
::
prefix
(
'web'
)
->
namespace
(
"Web"
)
->
group
(
function
()
{
Route
::
get
(
'/home'
,
'\App\Http\Controllers\HomeController@home'
);
// 首页
});
...
...
@@ -23,3 +27,4 @@ Route::prefix('web')->namespace("Web")->group(function () {
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment