2021-01-30 20:59:12 +08:00
|
|
|
<?php
|
2021-07-26 17:41:59 +08:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2021 勾股工作室
|
2021-11-24 17:17:29 +08:00
|
|
|
* @license https://opensource.org/licenses/Apache-2.0
|
2021-07-26 17:41:59 +08:00
|
|
|
* @link https://www.gougucms.com
|
|
|
|
*/
|
|
|
|
|
2021-01-30 20:59:12 +08:00
|
|
|
declare (strict_types = 1);
|
|
|
|
|
|
|
|
namespace app\home\controller;
|
|
|
|
|
|
|
|
use app\home\BaseController;
|
|
|
|
use think\facade\Db;
|
|
|
|
use think\facade\View;
|
|
|
|
|
|
|
|
class User extends BaseController
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
2021-07-26 17:41:59 +08:00
|
|
|
$uid = get_login_user('id');
|
2021-01-30 20:59:12 +08:00
|
|
|
$userInfo = Db::name('User')->where(['id' => $uid])->find();
|
|
|
|
$userInfo['showname'] = empty($userInfo['nickname']) ? $userInfo['username'] : $userInfo['nickname'];
|
2022-02-16 14:50:12 +08:00
|
|
|
$userInfo['level_title'] = Db::name('UserLevel')->where(['id' => $userInfo['level']])->value('title');
|
2021-01-30 20:59:12 +08:00
|
|
|
$userInfo['sex'] = ($userInfo['sex'] == 1) ? '男' : '女';
|
2021-07-26 17:41:59 +08:00
|
|
|
add_user_log('view', '个人中心');
|
2021-01-30 20:59:12 +08:00
|
|
|
View::assign('userInfo', $userInfo);
|
|
|
|
return view();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function info_edit()
|
|
|
|
{
|
2021-07-26 17:41:59 +08:00
|
|
|
$uid = get_login_user('id');
|
2021-01-30 20:59:12 +08:00
|
|
|
$userInfo = Db::name('User')->where(['id' => $uid])->find();
|
2022-02-16 14:50:12 +08:00
|
|
|
$userInfo['birthday'] = $userInfo['birthday']==0 ? '' : date('Y-m-d', $userInfo['birthday']);
|
2021-07-26 17:41:59 +08:00
|
|
|
add_user_log('view', '个人信息');
|
2021-01-30 20:59:12 +08:00
|
|
|
View::assign('userInfo', $userInfo);
|
|
|
|
return view();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit_submit()
|
|
|
|
{
|
2021-07-26 17:41:59 +08:00
|
|
|
$param = get_params();
|
2021-01-30 20:59:12 +08:00
|
|
|
$param['birthday'] = strtotime($param['birthday']);
|
2022-02-16 18:51:46 +08:00
|
|
|
$param['update_time'] = time();
|
2021-01-30 20:59:12 +08:00
|
|
|
$res = Db::name('User')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
|
2021-07-26 17:41:59 +08:00
|
|
|
if ($res !== false) {
|
|
|
|
add_user_log('edit', '个人信息', $param['id'], $param);
|
2021-09-09 08:33:05 +08:00
|
|
|
to_assign(0, '操作成功');
|
2021-07-26 17:41:59 +08:00
|
|
|
} else {
|
2021-09-09 08:33:05 +08:00
|
|
|
to_assign(1, '操作失败');
|
2021-01-30 20:59:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|