feat: 添加用户生日、地址和个人简介

This commit is contained in:
kuaifan 2025-10-12 15:05:09 +00:00
parent d58dd25dbb
commit 40f04d9860
3 changed files with 75 additions and 1 deletions

View File

@ -415,6 +415,9 @@ class UsersController extends AbstractController
* @apiParam {String} [tel] 电话
* @apiParam {String} [nickname] 昵称
* @apiParam {String} [profession] 职位/职称
* @apiParam {String} [birthday] 生日格式YYYY-MM-DD
* @apiParam {String} [address] 地址
* @apiParam {String} [introduction] 个人简介
* @apiParam {String} [lang] 语言比如zh/en
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
@ -478,6 +481,40 @@ class UsersController extends AbstractController
$upLdap['employeeType'] = $profession;
}
}
// 生日
if (Arr::exists($data, 'birthday')) {
$birthday = trim((string) Request::input('birthday'));
if ($birthday === '') {
$user->birthday = null;
} else {
try {
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $birthday)) {
$birthdayDate = Carbon::createFromFormat('Y-m-d', $birthday);
} else {
$birthdayDate = Carbon::parse($birthday);
}
} catch (\Exception $e) {
return Base::retError('生日格式错误');
}
$user->birthday = $birthdayDate->format('Y-m-d');
}
}
// 地址
if (Arr::exists($data, 'address')) {
$address = trim((string) Request::input('address'));
if (mb_strlen($address) > 100) {
return Base::retError('地址最多只能设置100个字');
}
$user->address = $address ?: null;
}
// 个人简介
if (Arr::exists($data, 'introduction')) {
$introduction = trim((string) Request::input('introduction'));
if (mb_strlen($introduction) > 500) {
return Base::retError('个人简介最多只能设置500个字');
}
$user->introduction = $introduction ?: null;
}
// 语言
if (Arr::exists($data, 'lang')) {
$lang = trim(Request::input('lang'));

View File

@ -22,6 +22,9 @@ use Carbon\Carbon;
* @property string|null $tel 联系电话
* @property string $nickname 昵称
* @property string|null $profession 职位/职称
* @property \Illuminate\Support\Carbon|null $birthday 生日
* @property string|null $address 地址
* @property string|null $introduction 个人简介
* @property string $userimg 头像
* @property string|null $encrypt
* @property string|null $password 登录密码
@ -89,7 +92,7 @@ class User extends AbstractModel
public static $defaultAvatarMode = 'auto';
// 基本信息的字段
public static $basicField = ['userid', 'email', 'nickname', 'profession', 'department', 'userimg', 'bot', 'az', 'pinyin', 'line_at', 'disable_at'];
public static $basicField = ['userid', 'email', 'nickname', 'profession', 'birthday', 'address', 'introduction', 'department', 'userimg', 'bot', 'az', 'pinyin', 'line_at', 'disable_at'];
/**
* 昵称

View File

@ -0,0 +1,34 @@
<?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->date('birthday')->nullable()->after('profession');
$table->string('address', 255)->nullable()->after('birthday');
$table->text('introduction')->nullable()->after('address');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['birthday', 'address', 'introduction']);
});
}
};