Commit 68766389 by 杨树贤

优化bug

parent 88ddb501
<?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();
}
}
<?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);
}
});
}
}
......@@ -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',
//]
];
/**
......
......@@ -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', '')
],
],
......
......@@ -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 () {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment