|
|
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Schema;
class SetStoreUsers extends Command{ /** * The name and signature of the console command. * * @var string */ protected $signature = 'migrateData:SetStoreUsers';
/** * The console command description. * * @var string */ protected $description = 'Command 店铺的账号表整理';
/** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); }
/** * Execute the console command. * 店铺的登录账号,店长、店员 * 将旧账号表的关联的店铺id和角色洗到新的店铺账号表 * @return int */ public function handle() { $oldAccount = 'ims_cjdc_account'; $oldTable = 'ims_users';
$newTable = 'lanzu_store_users';
$oldData = DB::table($oldTable)->get();
$account = DB::table($oldAccount)->select('uid','role','storeid')->get()->toArray(); $accountArr = array_column($account,null,'uid');
$bar = $this->output->createProgressBar(count($account)); $bar->start(); $accountStr = '已经存在的账号id:'; $newData = []; foreach ($oldData as $k => $v){ $exist = DB::table($newTable)->where('id',$v->uid)->exists(); if($exist){ $accountStr .= ','.$v->uid; }else{ $newData[] =[ 'id' => $v->uid, 'openid' => $v->openid ?? '', 'username' => $v->username ?? '', 'password' => $v->password ?? '', 'salt' => $v->salt ?? '', 'register_type' => 0, 'status' => $v->status ?? 0, 'join_ip' => $v->joinip ?? '',
'last_visit_time' => $v->lastvisit ?? 0, 'last_ip' => $v->lastip ?? '', 'token' => $v->token ?? '', 'token_expire' => $v->token_expire ?? '', 'remark' => $v->remark ?? '', 'created_at' => $v->joindate ?? 0, 'updated_at' => time(),
'user_category'=> isset($accountArr[$v->uid]) ? $accountArr[$v->uid]->role ?? 0 : 0, 'store_id'=> isset($accountArr[$v->uid]) ? $accountArr[$v->uid]->storeid ?? 0 : 0, ]; } }
DB::table($newTable)->insert($newData); $bar->finish(); var_dump($accountStr); return 0; }}
|