Skip to content

Commit

Permalink
Fix:修复后台无法修改用户options信息的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Jan 16, 2023
1 parent 8686eb2 commit b3e4f16
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
18 changes: 9 additions & 9 deletions app/Plugins/User/resources/views/Admin/Users/edit.blade.php
Expand Up @@ -50,47 +50,47 @@

<div class="mb-3">
<label for="" class="form-label">签名</label>
<textarea rows="4" name="Options[qianming]" class="form-control">{{$user->Options->qianming}}</textarea>
<textarea rows="4" name="options[qianming]" class="form-control">{{$user->options->qianming}}</textarea>
</div>

<div class="mb-3">
<label for="" class="form-label">qq</label>
<input class="form-control" type="text" name="Options[qq]" value="@if($user->Options->qq) {{$user->Options->qq}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[qq]" value="@if($user->options->qq) {{$user->options->qq}} @endif">
</div>
<div class="mb-3">
<label for="" class="form-label">微信</label>
<input class="form-control" type="text" name="Options[wx]" value="@if($user->Options->wx) {{$user->Options->wx}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[wx]" value="@if($user->options->wx) {{$user->options->wx}} @endif">
</div>


<div class="mb-3">
<label for="" class="form-label">网站</label>
<input class="form-control" type="text" name="Options[website]" value="@if($user->Options->website) {{$user->Options->website}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[website]" value="@if($user->options->website) {{$user->options->website}} @endif">
</div>

<div class="mb-3">
<label for="" class="form-label">对外邮箱</label>
<input class="form-control" type="text" name="Options[email]" value="@if($user->Options->email) {{$user->Options->email}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[email]" value="@if($user->options->email) {{$user->options->email}} @endif">
</div>

<div class="mb-3">
<label for="" class="form-label">积分</label>
<input class="form-control" type="text" name="Options[credits]" value="@if($user->Options->credits) {{$user->Options->credits}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[credits]" value="@if($user->options->credits) {{$user->options->credits}} @endif">
</div>

<div class="mb-3">
<label for="" class="form-label">金币</label>
<input class="form-control" type="text" name="Options[golds]" value="@if($user->Options->golds) {{$user->Options->golds}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[golds]" value="@if($user->options->golds) {{$user->options->golds}} @endif">
</div>

<div class="mb-3">
<label for="" class="form-label">经验</label>
<input class="form-control" type="text" name="Options[exp]" value="@if($user->Options->exp) {{$user->Options->exp}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[exp]" value="@if($user->options->exp) {{$user->options->exp}} @endif">
</div>

<div class="mb-3">
<label for="" class="form-label">余额</label>
<input class="form-control" type="text" name="Options[money]" value="@if($user->Options->money) {{$user->Options->money}} @else 暂无 @endif">
<input class="form-control" type="text" name="options[money]" value="@if($user->options->money) {{$user->options->money}} @endif">
</div>

<div class="mb-3">
Expand Down
15 changes: 6 additions & 9 deletions app/Plugins/User/src/Controller/Admin/UserController.php
Expand Up @@ -13,6 +13,7 @@
use App\Plugins\User\src\Lib\UserAuth;
use App\Plugins\User\src\Models\User;
use App\Plugins\User\src\Models\UserClass as Uc;
use App\Plugins\User\src\Models\UsersOption;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;
Expand Down Expand Up @@ -199,18 +200,14 @@ public function edit_submit($id)
if (! User::query()->where('id', $id)->exists()) {
return redirect()->url('/admin/users')->with('danger', '用户不存在')->go();
}
$user = User::query()->with('Options','Class')->find($id);
$user = User::query()->with('options','Class')->find($id);
foreach (request()->all() as $key => $value) {
if ($key !== '_token') {
if (is_array($value)) {
foreach ($value as $_k => $_v) {
$user->{$key}->{$_k} = trim($_v);
}
} elseif (is_string($value)) {
$user->{$key} = trim($value);
}
if ($key !== '_token' && is_string($value)) {
$user->{$key} = trim($value);
}
}
UsersOption::query()->where('id',$user->options->id)->update(request()->input('options',[]));
//$user->users_option=$user->options;
$user->save();
return redirect()->url('/admin/users/' . $id . '/show')->with('success', '修改成功!')->go();
//return view('User::Admin.Users.edit', ['user' => $user]);
Expand Down
5 changes: 5 additions & 0 deletions app/Plugins/User/src/Models/User.php
Expand Up @@ -77,6 +77,11 @@ public function options()
return $this->belongsTo(UsersOption::class, 'options_id', 'id');
}

public function users_option()
{
return $this->belongsTo(UsersOption::class, 'options_id', 'id');
}

/**
* 获取用户的评论.
* @return \Hyperf\Database\Model\Relations\HasMany
Expand Down

0 comments on commit b3e4f16

Please sign in to comment.