HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/my.esfyn.top/Modules/User/Http/Controllers/Admin/UserController.php
<?php

namespace Modules\User\Http\Controllers\Admin;

use App\Http\Controllers\MyController;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Modules\User\Http\Requests\UserPwdRequest;
use Modules\User\Http\Requests\UserStoreRequest;
use Modules\User\Http\Requests\UserUpdateRequest;
use Modules\User\Models\User;

class UserController extends MyController
{

    /**
     * Display a listing of the resource.
     */
    public function index(Request $request)
    {
        if ($request->ajax() && $request->wantsJson()) {

            $admins = User::with("userRank:id,name")->orderBy('id', 'desc')
                ->where($this->adminFilter($request->input('filter')))
                ->paginate($this->param('limit', 'intval'))->toArray();

            return $this->success($admins);
        }
        return $this->view('admin.user.index');
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        $ranks = app('user')->ranks();
        return $this->view('admin.user.create', compact('ranks'));
    }

    /**
     * Store a newly created resource in storage.
     * @param UserStoreRequest $request
     * @param User $user
     * @return \Illuminate\Http\JsonResponse
     */
    public function store(UserStoreRequest $request, User $user)
    {
        $data = $request->validated();
        $data['password'] = Hash::make($data['password']);

        $result = $user->store($data);

        return $this->result($result);
    }

    /**
     * Show the specified resource.
     * @param int $id
     * @return Renderable
     */
    public function show($id)
    {
        return view('user::show');
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit()
    {
        $ranks = app('user')->ranks();
        $user = User::find($this->param('id', 'intval'));

        return $this->view('admin.user.edit', compact('user', 'ranks'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(UserUpdateRequest $request, User $user)
    {
        $data = $request->validated();
        $result = $user->up($data);

        return $this->result($result);
    }

    /**
     * 密码编辑页面
     */
    public function password()
    {
        $user = User::find($this->param('id', 'intval'));
        return $this->view('admin.user.password', compact('user'));
    }

    /**
     * 设置密码
     */
    public function setPwd(UserPwdRequest $request, User $user)
    {
        $data = $request->validated();
        $result = $user->up(['password' => Hash::make($data['password']), 'id' => $data['id']]);

        return $this->result($result);
    }

    /**
     * 修改字段
     */
    public function modify()
    {
        $user = User::find($this->param('id', 'intval'));
        $user->{$this->param('field')} = $this->param('value');
        $result = $user->save();

        return $this->result($result);
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy()
    {
        $result = User::destroy($this->param('id', 'intval'));
        return $this->result($result);
    }

    /**
     * 变动资金页面
     */
    public function account()
    {
        $user = User::find($this->param('id', 'intval'));
        return $this->view('admin.user.account', compact('user'));
    }

    /**
     * 变动资金
     */
    public function setAccount()
    {

        $balanceRes = $pointRes = true;
        $id = $this->param('id', 'intval');
        $desc = $this->param('description');

        if ($balance = $this->param('balance', 'floatval')) {
            $balanceRes = app('user')->balance($balance, $id, $desc);
        }

        if ($point = $this->param('point', 'floatval')) {
            $pointRes = app('user')->point($point, $id, $desc);
        }

        return $this->result($balanceRes && $pointRes);
    }
}