2016-07-22 19:36:24 +08:00
|
|
|
<?php
|
|
|
|
|
2016-08-28 10:05:21 +08:00
|
|
|
namespace App\Http\Controllers;
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
use View;
|
|
|
|
use Utils;
|
2016-07-22 19:36:24 +08:00
|
|
|
use App\Models\User;
|
2016-07-23 15:20:10 +08:00
|
|
|
use App\Models\Player;
|
|
|
|
use App\Models\Texture;
|
2016-09-04 15:35:12 +08:00
|
|
|
use App\Models\UserModel;
|
|
|
|
use Illuminate\Http\Request;
|
2016-08-29 19:47:30 +08:00
|
|
|
use App\Exceptions\PrettyPageException;
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
class AdminController extends Controller
|
2016-07-22 19:36:24 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2016-08-28 10:05:21 +08:00
|
|
|
return view('admin.index');
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
public function customize()
|
|
|
|
{
|
2016-08-28 10:05:21 +08:00
|
|
|
return view('admin.customize');
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
2016-07-29 11:52:45 +08:00
|
|
|
public function score()
|
|
|
|
{
|
2016-08-28 10:05:21 +08:00
|
|
|
return view('admin.score');
|
2016-07-29 11:52:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
public function options()
|
|
|
|
{
|
2016-08-28 10:05:21 +08:00
|
|
|
return view('admin.options');
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
/**
|
|
|
|
* Handle Upload Checking & Downloading
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function update(Request $request)
|
2016-08-09 13:18:27 +08:00
|
|
|
{
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($request->action == "check") {
|
2016-08-24 22:43:04 +08:00
|
|
|
$updater = new \Updater(\App::version());
|
2016-09-04 15:35:12 +08:00
|
|
|
|
2016-08-09 13:18:27 +08:00
|
|
|
if ($updater->newVersionAvailable()) {
|
2016-09-10 21:39:45 +08:00
|
|
|
return json([
|
2016-08-09 13:18:27 +08:00
|
|
|
'new_version_available' => true,
|
|
|
|
'latest_version' => $updater->latest_version
|
|
|
|
]);
|
2016-08-27 18:11:34 +08:00
|
|
|
} else {
|
2016-09-10 21:39:45 +08:00
|
|
|
return json([
|
2016-08-27 18:11:34 +08:00
|
|
|
'new_version_available' => false,
|
|
|
|
'latest_version' => $updater->current_version
|
|
|
|
]);
|
2016-08-09 13:18:27 +08:00
|
|
|
}
|
2016-09-04 15:35:12 +08:00
|
|
|
} elseif ($request->action == "download") {
|
2016-08-28 10:05:21 +08:00
|
|
|
return view('admin.download');
|
2016-08-26 22:42:49 +08:00
|
|
|
} else {
|
2016-08-28 10:05:21 +08:00
|
|
|
return view('admin.update');
|
2016-08-09 13:18:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
/**
|
|
|
|
* Show Manage Page of Users.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function users(Request $request)
|
2016-07-23 15:20:10 +08:00
|
|
|
{
|
2016-09-04 15:35:12 +08:00
|
|
|
$page = $request->input('page', 1);
|
|
|
|
$filter = $request->input('filter', '');
|
|
|
|
$q = $request->input('q', '');
|
2016-07-23 15:20:10 +08:00
|
|
|
|
|
|
|
if ($filter == "") {
|
|
|
|
$users = UserModel::orderBy('uid');
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($filter == "email") {
|
2016-07-23 15:20:10 +08:00
|
|
|
$users = UserModel::like('email', $q)->orderBy('uid');
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($filter == "nickname") {
|
2016-07-23 15:20:10 +08:00
|
|
|
$users = UserModel::like('nickname', $q)->orderBy('uid');
|
|
|
|
}
|
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
$total_pages = ceil($users->count() / 30);
|
|
|
|
$users = $users->skip(($page - 1) * 30)->take(30)->get();
|
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
return view('admin.users')->with('users', $users)
|
|
|
|
->with('filter', $filter)
|
|
|
|
->with('q', $q)
|
|
|
|
->with('page', $page)
|
|
|
|
->with('total_pages', $total_pages);
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
/**
|
|
|
|
* Show Manage Page of Players.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function players(Request $request)
|
2016-07-23 15:20:10 +08:00
|
|
|
{
|
2016-09-04 15:35:12 +08:00
|
|
|
$page = $request->input('page', 1);
|
|
|
|
$filter = $request->input('filter', '');
|
|
|
|
$q = $request->input('q', '');
|
2016-07-23 15:20:10 +08:00
|
|
|
|
|
|
|
if ($filter == "") {
|
2016-10-16 18:16:15 +08:00
|
|
|
$players = Player::orderBy('uid');
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($filter == "player_name") {
|
2016-10-16 18:16:15 +08:00
|
|
|
$players = Player::like('player_name', $q)->orderBy('uid');
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($filter == "uid") {
|
2016-10-16 18:16:15 +08:00
|
|
|
$players = Player::where('uid', $q)->orderBy('uid');
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
$total_pages = ceil($players->count() / 30);
|
|
|
|
$players = $players->skip(($page - 1) * 30)->take(30)->get();
|
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
return view('admin.players')->with('players', $players)
|
|
|
|
->with('filter', $filter)
|
|
|
|
->with('q', $q)
|
|
|
|
->with('page', $page)
|
|
|
|
->with('total_pages', $total_pages);
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle ajax request from /admin/users
|
2016-09-04 15:35:12 +08:00
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return void
|
2016-07-23 15:20:10 +08:00
|
|
|
*/
|
2016-09-04 15:35:12 +08:00
|
|
|
public function userAjaxHandler(Request $request)
|
2016-07-22 19:36:24 +08:00
|
|
|
{
|
2016-09-04 15:35:12 +08:00
|
|
|
$action = $request->input('action');
|
2016-07-22 19:36:24 +08:00
|
|
|
|
|
|
|
if ($action == "color") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
|
|
|
'color_scheme' => 'required'
|
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
$color_scheme = str_replace('_', '-', $request->input('color_scheme'));
|
2016-07-23 15:20:10 +08:00
|
|
|
\Option::set('color_scheme', $color_scheme);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('修改配色成功', 0);
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
$user = new User($request->input('uid'));
|
2016-08-16 22:52:00 +08:00
|
|
|
// current user
|
2016-08-28 10:05:21 +08:00
|
|
|
$cur_user = new User(session('uid'));
|
2016-07-29 15:31:05 +08:00
|
|
|
|
2016-07-22 19:36:24 +08:00
|
|
|
if (!$user->is_registered)
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('用户不存在', 1);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
|
|
|
if ($action == "email") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
|
|
|
'email' => 'required|email'
|
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($user->setEmail($request->input('email')))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('邮箱修改成功', 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($action == "nickname") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
|
|
|
'nickname' => 'required|nickname'
|
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($user->setNickName($request->input('nickname')))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('昵称已成功设置为 '.$request->input('nickname'), 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($action == "password") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
|
|
|
'password' => 'required|min:8|max:16'
|
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($user->changePasswd($request->input('password')))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('密码修改成功', 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($action == "score") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
|
|
|
'score' => 'required|integer'
|
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($user->setScore($request->input('score')))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('积分修改成功', 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($action == "ban") {
|
2016-07-29 15:31:05 +08:00
|
|
|
if ($user->getPermission() == "1") {
|
2016-08-16 22:52:00 +08:00
|
|
|
if ($cur_user->getPermission() != "2")
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('非超级管理员无法封禁普通管理员');
|
2016-07-29 15:31:05 +08:00
|
|
|
} elseif ($user->getPermission() == "2") {
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('超级管理员无法被封禁');
|
2016-07-29 15:31:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$permission = $user->getPermission() == "-1" ? "0" : "-1";
|
|
|
|
|
|
|
|
if ($user->setPermission($permission)) {
|
2016-09-10 21:39:45 +08:00
|
|
|
return json([
|
2016-07-29 15:31:05 +08:00
|
|
|
'errno' => 0,
|
|
|
|
'msg' => '账号已被' . ($permission == '-1' ? '封禁' : '解封'),
|
|
|
|
'permission' => $user->getPermission()
|
|
|
|
]);
|
|
|
|
}
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($action == "admin") {
|
|
|
|
if ($cur_user->getPermission() != "2")
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('非超级管理员无法进行此操作');
|
2016-07-29 15:31:05 +08:00
|
|
|
|
|
|
|
if ($user->getPermission() == "2")
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('超级管理员无法被解除');
|
2016-07-29 15:31:05 +08:00
|
|
|
|
|
|
|
$permission = $user->getPermission() == "1" ? "0" : "1";
|
|
|
|
|
|
|
|
if ($user->setPermission($permission)) {
|
2016-09-10 21:39:45 +08:00
|
|
|
return json([
|
2016-07-29 15:31:05 +08:00
|
|
|
'errno' => 0,
|
|
|
|
'msg' => '账号已被' . ($permission == '1' ? '设为' : '解除') . '管理员',
|
|
|
|
'permission' => $user->getPermission()
|
|
|
|
]);
|
|
|
|
}
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
} elseif ($action == "delete") {
|
2016-07-22 19:36:24 +08:00
|
|
|
if ($user->delete())
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('账号已被成功删除', 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-07-22 19:36:24 +08:00
|
|
|
} else {
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('非法参数', 1);
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
/**
|
|
|
|
* Handle ajax request from /admin/players
|
|
|
|
*/
|
2016-09-04 15:35:12 +08:00
|
|
|
public function playerAjaxHandler(Request $request)
|
2016-07-22 19:36:24 +08:00
|
|
|
{
|
2016-07-23 15:20:10 +08:00
|
|
|
$action = isset($_GET['action']) ? $_GET['action'] : "";
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-10-16 18:16:15 +08:00
|
|
|
$player = Player::find($request->input('pid'));
|
|
|
|
|
|
|
|
if (!$player)
|
|
|
|
abort(404, trans('general.unexistent-player'));
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
if ($action == "preference") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
|
|
|
'preference' => 'required|preference'
|
|
|
|
]);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($player->setPreference($request->input('preference')))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('角色 '.$player->player_name.' 的优先模型已更改至 '.$request->input('preference'), 0);
|
2016-07-22 19:36:24 +08:00
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
} elseif ($action == "texture") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
|
|
|
'model' => 'required|model',
|
|
|
|
'tid' => 'required|integer'
|
|
|
|
]);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if (!Texture::find($request->tid))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json("材质 tid.{$request->tid} 不存在", 1);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($player->setTexture(['tid_'.$request->model => $request->tid]))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json("角色 {$player->player_name} 的材质修改成功", 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
|
|
|
} elseif ($action == "owner") {
|
2016-09-04 15:35:12 +08:00
|
|
|
$this->validate($request, [
|
2016-09-10 17:52:33 +08:00
|
|
|
'pid' => 'required|integer',
|
|
|
|
'uid' => 'required|integer'
|
2016-09-04 15:35:12 +08:00
|
|
|
]);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
$user = new User($request->input('uid'));
|
2016-07-23 15:20:10 +08:00
|
|
|
|
|
|
|
if (!$user->is_registered)
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('不存在的用户', 1);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
if ($player->setOwner($request->input('uid')))
|
2016-09-10 21:39:45 +08:00
|
|
|
return json("角色 $player->player_name 已成功让渡至 ".$user->getNickName(), 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
2016-07-23 21:46:20 +08:00
|
|
|
} elseif ($action == "delete") {
|
2016-10-16 18:16:15 +08:00
|
|
|
if ($player->delete())
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('角色已被成功删除', 0);
|
2016-07-23 15:20:10 +08:00
|
|
|
} else {
|
2016-09-10 21:39:45 +08:00
|
|
|
return json('非法参数', 1);
|
2016-07-23 15:20:10 +08:00
|
|
|
}
|
2016-07-22 19:36:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|