From 40f04d986001db853322608e6167fbd029b7908b Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 12 Oct 2025 15:05:09 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=94=9F=E6=97=A5=E3=80=81=E5=9C=B0=E5=9D=80=E5=92=8C=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E7=AE=80=E4=BB=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/UsersController.php | 37 +++++++++++++++++++ app/Models/User.php | 5 ++- ...0000_add_profile_fields_to_users_table.php | 34 +++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2025_10_12_090000_add_profile_fields_to_users_table.php diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 05e2f0629..7e098d6ee 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -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')); diff --git a/app/Models/User.php b/app/Models/User.php index e8394abe6..f02d19206 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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']; /** * 昵称 diff --git a/database/migrations/2025_10_12_090000_add_profile_fields_to_users_table.php b/database/migrations/2025_10_12_090000_add_profile_fields_to_users_table.php new file mode 100644 index 000000000..ca04966cb --- /dev/null +++ b/database/migrations/2025_10_12_090000_add_profile_fields_to_users_table.php @@ -0,0 +1,34 @@ +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']); + }); + } +};