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-11-12 23:50:41 +08:00
|
|
|
|
use Option;
|
2016-12-31 11:38:07 +08:00
|
|
|
|
use Datatables;
|
2016-11-19 22:02:02 +08:00
|
|
|
|
use App\Events;
|
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-12-31 11:38:07 +08:00
|
|
|
|
use Illuminate\Support\Arr;
|
2016-09-04 15:35:12 +08:00
|
|
|
|
use Illuminate\Http\Request;
|
2016-08-29 19:47:30 +08:00
|
|
|
|
use App\Exceptions\PrettyPageException;
|
2016-10-23 11:41:52 +08:00
|
|
|
|
use App\Services\Repositories\UserRepository;
|
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-12-27 23:05:09 +08:00
|
|
|
|
$homepage = Option::form('homepage', '首页配置', function($form)
|
|
|
|
|
{
|
|
|
|
|
$form->text('home_pic_url', '首页图片地址')->hint('相对于首页的路径或者完整的 URL');
|
|
|
|
|
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$form->select('copyright_prefer', '程序版权信息')
|
2016-12-30 20:55:33 +08:00
|
|
|
|
->option('0', 'Powered with ❤ by Blessing Skin Server.')
|
|
|
|
|
->option('1', 'Powered by Blessing Skin Server.')
|
|
|
|
|
->option('2', '由 Blessing Skin Server 强力驱动.')
|
|
|
|
|
->option('3', '自豪地采用 Blessing Skin Server.')
|
|
|
|
|
->description('对于任何恶意修改页面<b>右下角</b>的版权信息(包括不限于删除、修改作者信息、修改链接指向)的用户,作者保留对其追究责任的权力。');
|
2016-12-29 23:14:09 +08:00
|
|
|
|
|
|
|
|
|
$form->textarea('copyright_text', '自定义版权文字')->rows(6)
|
|
|
|
|
->description('自定义版权文字内可使用占位符,<code>{site_name}</code> 将会被自动替换为站点名称,<code>{site_url}</code> 会被替换为站点地址。');
|
2016-12-27 23:05:09 +08:00
|
|
|
|
|
|
|
|
|
})->handle();
|
|
|
|
|
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$customJsCss = Option::form('customJsCss', '自定义 CSS/JavaScript', function($form)
|
|
|
|
|
{
|
|
|
|
|
$form->textarea('custom_css', 'CSS')->rows(6);
|
|
|
|
|
$form->textarea('custom_js', 'JavaScript')->rows(6);
|
|
|
|
|
})->addMessage('
|
|
|
|
|
内容将会被追加至每个页面的 <style> 和 <script> 标签中。<br>
|
|
|
|
|
- 这里有一些有用的示例:<a href="https://github.com/printempw/blessing-skin-server/wiki/%E3%80%8C%E8%87%AA%E5%AE%9A%E4%B9%89-CSS-JavaScript%E3%80%8D%E5%8A%9F%E8%83%BD%E7%9A%84%E4%B8%80%E4%BA%9B%E5%AE%9E%E4%BE%8B">「自定义 CSS JavaScript」功能的一些实例@GitHub WiKi</a>
|
|
|
|
|
')->handle();
|
|
|
|
|
|
|
|
|
|
return view('admin.customize', ['forms' => compact('homepage', 'customJsCss')]);
|
2016-07-23 15:20:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 11:52:45 +08:00
|
|
|
|
public function score()
|
|
|
|
|
{
|
2016-12-21 22:53:53 +08:00
|
|
|
|
$rate = Option::form('rate', '积分换算', function($form)
|
|
|
|
|
{
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$form->group('score_per_storage', '存储')->text('score_per_storage')->addon('积分 = 1 KB');
|
2016-12-21 22:53:53 +08:00
|
|
|
|
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$form->group('private_score_per_storage', '私密材质存储')
|
|
|
|
|
->text('private_score_per_storage')->addon('积分 = 1 KB')
|
|
|
|
|
->hint('上传私密材质将消耗更多积分');
|
2016-12-21 22:53:53 +08:00
|
|
|
|
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$form->group('score_per_closet_item', '收藏消耗积分')
|
|
|
|
|
->text('score_per_closet_item')->addon('积分 = 一个衣柜物品');
|
2016-12-28 13:08:17 +08:00
|
|
|
|
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$form->checkbox('return_score', '积分返还')->label('用户删除角色/材质/收藏时返还积分');
|
2016-12-21 22:53:53 +08:00
|
|
|
|
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$form->group('score_per_player', '角色')->text('score_per_player')->addon('积分 = 一个角色');
|
2016-12-21 22:53:53 +08:00
|
|
|
|
|
|
|
|
|
$form->text('user_initial_score', '新用户默认积分');
|
|
|
|
|
|
|
|
|
|
})->handle();
|
|
|
|
|
|
2016-12-29 23:14:09 +08:00
|
|
|
|
$signIn = Option::form('sign_in', '签到配置', function($form)
|
|
|
|
|
{
|
|
|
|
|
$form->group('sign_score', '签到获得积分')
|
|
|
|
|
->text('sign_score_from')->addon('积分 ~ ')->text('sign_score_to')->addon('积分');
|
|
|
|
|
|
|
|
|
|
$form->group('sign_gap_time', '签到间隔时间')->text('sign_gap_time')->addon('小时');
|
|
|
|
|
|
|
|
|
|
$form->checkbox('sign_after_zero', '签到时间')->label('每天零点后可签到')
|
|
|
|
|
->hint('勾选后将无视上一条,每天零时后均可签到');
|
|
|
|
|
})->handle(function() {
|
|
|
|
|
$sign_score = $_POST['sign_score_from'].','.$_POST['sign_score_to'];
|
|
|
|
|
Option::set('sign_score', $sign_score);
|
|
|
|
|
|
|
|
|
|
unset($_POST['sign_score_from']);
|
|
|
|
|
unset($_POST['sign_score_to']);
|
|
|
|
|
})->with([
|
|
|
|
|
'sign_score_from' => @explode(',', option('sign_score'))[0],
|
|
|
|
|
'sign_score_to' => @explode(',', option('sign_score'))[1]
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return view('admin.score', ['forms' => compact('rate', 'signIn')]);
|
2016-07-29 11:52:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 15:20:10 +08:00
|
|
|
|
public function options()
|
|
|
|
|
{
|
2016-11-12 23:50:41 +08:00
|
|
|
|
$general = Option::form('general', '常规选项', function($form)
|
|
|
|
|
{
|
|
|
|
|
$form->text('site_name', '站点标题');
|
|
|
|
|
$form->text('site_description', '站点描述');
|
|
|
|
|
$form->text('site_url', '站点地址(URL)')->hint('以 http(s):// 开头,不要以 / 结尾');
|
|
|
|
|
|
2016-12-28 23:28:15 +08:00
|
|
|
|
$form->checkbox('user_can_register', '开放注册')->label('任何人都可以注册');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
|
|
|
|
|
$form->text('regs_per_ip', '每个 IP 限制注册数');
|
|
|
|
|
|
2016-12-28 23:28:15 +08:00
|
|
|
|
$form->group('max_upload_file_size', '最大允许上传大小')
|
|
|
|
|
->text('max_upload_file_size')->addon('KB')
|
2016-12-29 13:11:46 +08:00
|
|
|
|
->hint('PHP 限制:'.ini_get('upload_max_filesize').',定义在 php.ini 中。');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
|
2016-12-28 23:28:15 +08:00
|
|
|
|
$form->checkbox('allow_chinese_playername', '角色名')->label('允许中文角色名');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
|
2016-12-28 23:28:15 +08:00
|
|
|
|
$form->select('api_type', '首选 JSON API')
|
|
|
|
|
->option('0', 'CustomSkinLoader API')
|
|
|
|
|
->option('1', 'UniversalSkinAPI');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
|
2016-12-28 23:28:15 +08:00
|
|
|
|
$form->checkbox('auto_del_invalid_texture', '失效材质')->label('自动删除失效材质')->hint('自动从皮肤库中删除文件不存在的材质记录');
|
|
|
|
|
|
|
|
|
|
$form->textarea('comment_script', '评论代码')->rows(6)->description('评论代码内可使用占位符,<code>{tid}</code> 将会被自动替换为材质的 id,<code>{name}</code> 会被替换为材质名称,<code>{url}</code> 会被替换为当前页面地址。');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
|
|
|
|
|
})->handle(function() {
|
|
|
|
|
if (substr($_POST['site_url'], -1) == "/")
|
|
|
|
|
$_POST['site_url'] = substr($_POST['site_url'], 0, -1);
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-29 13:11:46 +08:00
|
|
|
|
$announcement = Option::form('announcement', '站点公告', function($form)
|
|
|
|
|
{
|
|
|
|
|
$form->textarea('announcement')->description('可使用 Markdown 进行排版');
|
|
|
|
|
|
|
|
|
|
})->renderWithOutTable()->handle();
|
|
|
|
|
|
2016-12-16 22:13:41 +08:00
|
|
|
|
$cache = Option::form('cache', '资源文件配置', function($form)
|
2016-11-12 23:50:41 +08:00
|
|
|
|
{
|
2016-12-28 23:28:15 +08:00
|
|
|
|
$form->checkbox('force_ssl', '强制 SSL')->label('强制使用 HTTPS 协议加载资源')->hint('请确认 SSL 可用后再开启');
|
|
|
|
|
$form->checkbox('auto_detect_asset_url', '资源地址')->label('自动判断资源文件地址')->hint('根据当前 URL 自动加载资源文件,如果关闭则将根据「站点地址」填写的内容加载。如果出现 CDN 回源问题请关闭');
|
|
|
|
|
$form->checkbox('return_200_when_notfound', 'HTTP 响应码')->label('请求不存在的角色时返回 200 而不是 404');
|
2016-11-12 23:50:41 +08:00
|
|
|
|
|
|
|
|
|
$form->text('cache_expire_time', '缓存失效时间')->hint('秒数,86400 = 一天,31536000 = 一年');
|
|
|
|
|
|
2016-12-28 23:28:15 +08:00
|
|
|
|
})->type('warning')->hint('如果启用了 CDN 缓存请适当修改这些配置')->handle();
|
2016-11-12 23:50:41 +08:00
|
|
|
|
|
2016-12-29 13:11:46 +08:00
|
|
|
|
return view('admin.options')->with('forms', compact('general', 'cache', 'announcement'));
|
2016-07-23 15:20:10 +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-12-31 11:38:07 +08:00
|
|
|
|
return view('admin.users');
|
|
|
|
|
}
|
2016-07-23 15:20:10 +08:00
|
|
|
|
|
2016-12-31 11:38:07 +08:00
|
|
|
|
public function getUserData()
|
|
|
|
|
{
|
|
|
|
|
$users = User::select(['uid', 'email', 'nickname', 'score', 'permission', 'register_at']);
|
|
|
|
|
|
|
|
|
|
$permissionTextMap = [
|
|
|
|
|
User::BANNED => '封禁',
|
|
|
|
|
User::NORMAL => '正常',
|
|
|
|
|
User::ADMIN => '管理员',
|
|
|
|
|
User::SUPER_ADMIN => '超级管理员'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return Datatables::of($users)->editColumn('email', function ($user) {
|
|
|
|
|
return $user->email ?: '[未填写邮箱]';
|
|
|
|
|
})->editColumn('permission', function ($user) use ($permissionTextMap) {
|
|
|
|
|
return Arr::get($permissionTextMap, $user->permission);
|
|
|
|
|
})
|
|
|
|
|
->setRowId('uid')
|
2016-12-31 13:07:00 +08:00
|
|
|
|
->editColumn('score', 'vendor.admin-operations.users.score')
|
|
|
|
|
->addColumn('operations', 'vendor.admin-operations.users.operations')
|
2016-12-31 11:38:07 +08:00
|
|
|
|
->make(true);
|
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-12-31 13:07:00 +08:00
|
|
|
|
return view('admin.players');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPlayerData()
|
|
|
|
|
{
|
|
|
|
|
$players = Player::select(['pid', 'uid', 'player_name', 'preference', 'tid_steve', 'tid_alex', 'tid_cape', 'last_modified']);
|
|
|
|
|
|
|
|
|
|
return Datatables::of($players)->editColumn('preference', 'vendor.admin-operations.players.preference')
|
|
|
|
|
->setRowId('pid')
|
|
|
|
|
->addColumn('previews', 'vendor.admin-operations.players.previews')
|
|
|
|
|
->addColumn('operations', 'vendor.admin-operations.players.operations')
|
|
|
|
|
->make(true);
|
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-10-23 11:41:52 +08:00
|
|
|
|
public function userAjaxHandler(Request $request, UserRepository $users)
|
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-10-23 11:41:52 +08:00
|
|
|
|
$user = $users->get($request->input('uid'));
|
2016-08-16 22:52:00 +08:00
|
|
|
|
// current user
|
2016-10-23 11:41:52 +08:00
|
|
|
|
$cur_user = $users->get(session('uid'));
|
2016-07-29 15:31:05 +08:00
|
|
|
|
|
2016-10-23 11:41:52 +08:00
|
|
|
|
if (!$user)
|
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-10-23 11:41:52 +08:00
|
|
|
|
if ($user->getPermission() == User::ADMIN) {
|
|
|
|
|
if ($cur_user->getPermission() != User::SUPER_ADMIN)
|
2016-09-10 21:39:45 +08:00
|
|
|
|
return json('非超级管理员无法封禁普通管理员');
|
2016-10-23 11:41:52 +08:00
|
|
|
|
} elseif ($user->getPermission() == User::SUPER_ADMIN) {
|
2016-09-10 21:39:45 +08:00
|
|
|
|
return json('超级管理员无法被封禁');
|
2016-07-29 15:31:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-23 11:41:52 +08:00
|
|
|
|
$permission = $user->getPermission() == User::BANNED ? User::NORMAL : User::BANNED;
|
2016-07-29 15:31:05 +08:00
|
|
|
|
|
|
|
|
|
if ($user->setPermission($permission)) {
|
2016-09-10 21:39:45 +08:00
|
|
|
|
return json([
|
2016-07-29 15:31:05 +08:00
|
|
|
|
'errno' => 0,
|
2016-10-23 11:41:52 +08:00
|
|
|
|
'msg' => '账号已被' . ($permission == User::BANNED ? '封禁' : '解封'),
|
2016-07-29 15:31:05 +08:00
|
|
|
|
'permission' => $user->getPermission()
|
|
|
|
|
]);
|
|
|
|
|
}
|
2016-07-23 15:20:10 +08:00
|
|
|
|
|
2016-08-16 22:52:00 +08:00
|
|
|
|
} elseif ($action == "admin") {
|
2016-10-23 11:41:52 +08:00
|
|
|
|
if ($cur_user->getPermission() != User::SUPER_ADMIN)
|
2016-09-10 21:39:45 +08:00
|
|
|
|
return json('非超级管理员无法进行此操作');
|
2016-07-29 15:31:05 +08:00
|
|
|
|
|
2016-10-23 11:41:52 +08:00
|
|
|
|
if ($user->getPermission() == User::SUPER_ADMIN)
|
2016-09-10 21:39:45 +08:00
|
|
|
|
return json('超级管理员无法被解除');
|
2016-07-29 15:31:05 +08:00
|
|
|
|
|
2016-10-23 11:41:52 +08:00
|
|
|
|
$permission = $user->getPermission() == User::ADMIN ? User::NORMAL : User::ADMIN;
|
2016-07-29 15:31:05 +08:00
|
|
|
|
|
|
|
|
|
if ($user->setPermission($permission)) {
|
2016-09-10 21:39:45 +08:00
|
|
|
|
return json([
|
2016-07-29 15:31:05 +08:00
|
|
|
|
'errno' => 0,
|
2016-10-23 11:41:52 +08:00
|
|
|
|
'msg' => '账号已被' . ($permission == User::ADMIN ? '设为' : '解除') . '管理员',
|
2016-07-29 15:31:05 +08:00
|
|
|
|
'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-10-23 11:41:52 +08:00
|
|
|
|
public function playerAjaxHandler(Request $request, UserRepository $users)
|
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-10-23 11:41:52 +08:00
|
|
|
|
$user = $users->get($request->input('uid'));
|
2016-07-23 15:20:10 +08:00
|
|
|
|
|
2016-10-23 11:41:52 +08:00
|
|
|
|
if (!$user)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|