master
cody 6 months ago
parent 1aafa7dacd
commit 5b052aa00f

@ -0,0 +1,52 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use App\Repositories\MeetRepository;
use Illuminate\Console\Command;
class UpdateUserNo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update_user_no';
/**
* The console command description.
*
* @var string
*/
protected $description = '批量更新学号';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$users = User::get();
foreach ($users as $user) {
$no = User::updateNo($user->id);
$this->info($no . '更新成功');
}
return $this->info('更新完成');
}
}

@ -72,6 +72,8 @@ class UserController extends CommonController
$score = Config::getValueByKey('share_score');
ScoreLog::add($pid, $score, '分享获得');
}
// 更新编号
User::updateNo($user->id);
}
$token = $user->createToken("mobile-token")->plainTextToken;
return $this->success(compact('token'));

@ -124,4 +124,16 @@ class User extends Authenticatable implements Auditable
return $user->appointment_total - $useTotal >= 0 ? $user->appointment_total - $useTotal : 0;
}
/**
* 更新用户编号
*/
public static function updateNo($userId)
{
$user = self::find($userId);
$no = date('Ymd', strtotime($user->created_at)) . str_pad($userId, 6, '0', STR_PAD_LEFT);
$user->no = $no;
$user->save();
return $user->no;
}
}

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('no')->nullable()->comment('学号');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
};
Loading…
Cancel
Save