This commit is contained in:
root 2019-10-25 18:18:17 +08:00
parent fcf95e615d
commit 2abdd2b290
2 changed files with 16 additions and 9 deletions

View File

@ -26,22 +26,28 @@ class UserController extends Controller
} }
public function update (UserUpdate $request) { public function update (UserUpdate $request) {
$fetchData = $request->only([
'email',
'password',
'transfer_enable',
'expired_at',
'banned',
'is_admin'
]);
$user = User::find($request->input('id')); $user = User::find($request->input('id'));
if (!$user) { if (!$user) {
abort(500, '用户不存在'); abort(500, '用户不存在');
} }
if (User::where('email', $request->input('email'))->first() && $user->email !== $request->input('email')) { if (User::where('email', $fetchData['email'])->first() && $user->email !== $fetchData['email']) {
abort(500, '邮箱已被使用'); abort(500, '邮箱已被使用');
} }
$user->email = $request->input('email'); if ($fetchData['password']) {
if ($request->input('password')) { $fetchData['password'] = password_hash($fetchData['password'], PASSWORD_DEFAULT);
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT); } else {
unset($fetchData['password']);
} }
$user->transfer_enable = $request->input('transfer_enable') * 1073741824; $fetchData['transfer_enable'] = $fetchData['transfer_enable'] * 1073741824;
$user->expired_at = $request->input('expired_at'); if (!$user->update($fetchData)) {
$user->banned = $request->input('banned');
$user->is_admin = $request->input('is_admin');
if (!$user->save()) {
abort(500, '保存失败'); abort(500, '保存失败');
} }
return response([ return response([

View File

@ -8,4 +8,5 @@ class User extends Model
{ {
protected $table = 'v2_user'; protected $table = 'v2_user';
protected $dateFormat = 'U'; protected $dateFormat = 'U';
protected $guarded = ['id'];
} }