🎨 改进
This commit is contained in:
@@ -55,7 +55,7 @@ class Upload extends Controller
|
||||
$this->configs = $this->getConfig();
|
||||
|
||||
// 角色组
|
||||
if ($this->user) $this->group = $this->user->group;
|
||||
if ($this->user) $this->group = $this->user->role;
|
||||
if (!$this->group) $this->group = Group::where('default', 1)->find();
|
||||
|
||||
// 设置当前储存策略
|
||||
|
||||
@@ -48,7 +48,7 @@ class Users extends Model
|
||||
|
||||
public function getUseQuotaAttr()
|
||||
{
|
||||
return sprintf("%.2f", $this->hasMany('Images', 'user_id', 'id')->sum('size'));
|
||||
return sprintf("%.2f", $this->images()->sum('size'));
|
||||
}
|
||||
|
||||
public static function login($account, $password, $field = 'email')
|
||||
@@ -76,16 +76,16 @@ class Users extends Model
|
||||
|
||||
public function images()
|
||||
{
|
||||
return $this->hasMany('Images', 'user_id', 'id');
|
||||
return $this->hasMany(Images::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function folders()
|
||||
{
|
||||
return $this->hasMany('Folders', 'user_id', 'id');
|
||||
return $this->hasMany(Folders::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function group()
|
||||
public function role()
|
||||
{
|
||||
return $this->hasOne('Group', 'id', 'group_id');
|
||||
return $this->hasOne(Group::class, 'id', 'group_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class Auth extends Base
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
try {
|
||||
if ($this->config['close_register']) {
|
||||
if ($this->getConfig('close_register')) {
|
||||
throw new Exception('站点已关闭注册');
|
||||
}
|
||||
$data = $this->request->post();
|
||||
|
||||
@@ -22,6 +22,9 @@ class Base extends Controller
|
||||
{
|
||||
use Core;
|
||||
|
||||
/**
|
||||
* @var Users
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
protected function initialize()
|
||||
@@ -43,16 +46,16 @@ class Base extends Controller
|
||||
try {
|
||||
// $mail->SMTPDebug = 2;
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $this->config['mail_smtp_host'];
|
||||
$mail->Host = $this->getConfig('mail_smtp_host');
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $this->config['mail_smtp_username'];
|
||||
$mail->Password = $this->config['mail_smtp_password'];
|
||||
$mail->SMTPSecure = $this->config['mail_smtp_secure'];
|
||||
$mail->Port = $this->config['mail_smtp_port'];
|
||||
$mail->setFrom($this->config['mail_form_email'], $this->config['site_name']);
|
||||
$mail->Username = $this->getConfig('mail_smtp_username');
|
||||
$mail->Password = $this->getConfig('mail_smtp_password');
|
||||
$mail->SMTPSecure = $this->getConfig('mail_smtp_secure');
|
||||
$mail->Port = $this->getConfig('mail_smtp_port');
|
||||
$mail->setFrom($this->getConfig('mail_form_email'), $this->getConfig('site_name'));
|
||||
$mail->addAddress($email);
|
||||
$mail->addReplyTo($this->config['mail_form_email'], $this->config['site_name']);
|
||||
$mail->addReplyTo($this->getConfig('mail_form_email'), $this->getConfig('site_name'));
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $body;
|
||||
|
||||
@@ -50,7 +50,7 @@ class User extends Base
|
||||
$id = $deleteId ? $deleteId : $this->request->post('id');
|
||||
$deletes = []; // 需要删除的文件
|
||||
if (is_array($id)) {
|
||||
$images = Images::all(['id' => $id, 'user_id' => $this->user->id]);
|
||||
$images = $this->user->images()->where('id', $id)->select();
|
||||
foreach ($images as &$value) {
|
||||
// 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
|
||||
if (!$this->exists($value)) {
|
||||
@@ -60,7 +60,7 @@ class User extends Base
|
||||
unset($value);
|
||||
}
|
||||
} else {
|
||||
$image = Images::get(['id' => $id, 'user_id' => $this->user->id]);
|
||||
$image = $this->user->images()->where('id', $id)->find();
|
||||
if (!$image) {
|
||||
throw new Exception('没有找到该图片数据');
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class User extends Base
|
||||
$image->delete();
|
||||
}
|
||||
// 是否开启软删除(开启了只删除记录,不删除文件)
|
||||
if (!$this->config['soft_delete']) {
|
||||
if (!$this->getConfig('soft_delete')) {
|
||||
$strategy = [];
|
||||
// 实例化所有储存策略驱动
|
||||
$strategyAll = array_keys(Config::pull('strategy'));
|
||||
@@ -156,7 +156,7 @@ class User extends Base
|
||||
}
|
||||
}
|
||||
|
||||
public function moveImages($ids = [], $folderId)
|
||||
public function moveImages($ids, $folderId)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$count = $this->user->folders()->where('id', $folderId)->count();
|
||||
@@ -210,7 +210,7 @@ class User extends Base
|
||||
if (!$validate->check(['name' => $name])) {
|
||||
throw new \Exception($validate->getError());
|
||||
}
|
||||
if (!Images::where('id', $id)->where('user_id', $this->user->id)->update(['alias_name' => $name])) {
|
||||
if (!$this->user->images()->where('id', $id)->update(['alias_name' => $name])) {
|
||||
throw new \Exception('重命名失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -233,8 +233,8 @@ class User extends Base
|
||||
|
||||
private function getDeleteFoldersAndImages($folderId, &$folders, &$images)
|
||||
{
|
||||
$folderList = Folders::where('parent_id', $folderId)->where('user_id', $this->user->id)->column('id');
|
||||
$imagesList = Images::where('folder_id', $folderId)->where('user_id', $this->user->id)->column('id');
|
||||
$folderList = $this->user->folders()->where('parent_id', $folderId)->column('id');
|
||||
$imagesList = $this->user->images()->where('folder_id', $folderId)->column('id');
|
||||
if ($imagesList) {
|
||||
$images = array_merge($images, $imagesList);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class Images extends Base
|
||||
$image->delete();
|
||||
}
|
||||
// 是否开启软删除(开启了只删除记录,不删除文件)
|
||||
if (!$this->config['soft_delete']) {
|
||||
if (!$this->getConfig('soft_delete')) {
|
||||
$strategy = [];
|
||||
// 实例化所有储存策略驱动
|
||||
$strategyAll = array_keys($this->strategyList);
|
||||
|
||||
@@ -96,7 +96,7 @@ class System extends Base
|
||||
$backup = 'backups/' . date('YmdHis') . '.zip';
|
||||
$upgrade = null;
|
||||
try {
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), $this->config['system_version']);
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), $this->getConfig('system_version'));
|
||||
$release = $upgrade->release(); // 获取最新版
|
||||
// 判断是否已经是最新版
|
||||
if ($upgrade->check($release->version)) {
|
||||
@@ -203,7 +203,7 @@ class System extends Base
|
||||
{
|
||||
$release = null;
|
||||
try {
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), $this->config['system_version']);
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), $this->getConfig('system_version'));
|
||||
$release = $upgrade->release(); // 获取安装包列表
|
||||
if (!$release) {
|
||||
throw new \Exception('获取版本时遇到错误');
|
||||
|
||||
Reference in New Issue
Block a user