update: add user softdelete api

This commit is contained in:
tokumeikoi 2021-07-01 00:35:22 +09:00
parent 044d1e9b7f
commit de6ff1dca9
5 changed files with 25 additions and 2 deletions

View File

@ -277,4 +277,16 @@ class UserController extends Controller
'data' => true 'data' => true
]); ]);
} }
public function drop(Request $request)
{
$user = User::find($request->input('id'));
if (!$user) abort(500, '用户不存在');
if (!$user->delete()) {
abort(500, '删除失败');
}
return response([
'data' => true
]);
}
} }

View File

@ -75,6 +75,7 @@ class AdminRoute
$router->post('/user/ban', 'Admin\\UserController@ban'); $router->post('/user/ban', 'Admin\\UserController@ban');
$router->post('/user/resetSecret', 'Admin\\UserController@resetSecret'); $router->post('/user/resetSecret', 'Admin\\UserController@resetSecret');
$router->post('/user/setInviteUser', 'Admin\\UserController@setInviteUser'); $router->post('/user/setInviteUser', 'Admin\\UserController@setInviteUser');
$router->post('/user/drop', 'Admin\\UserController@drop');
// StatOrder // StatOrder
$router->get ('/stat/getOverride', 'Admin\\StatController@getOverride'); $router->get ('/stat/getOverride', 'Admin\\StatController@getOverride');
$router->get ('/stat/getServerLastRank', 'Admin\\StatController@getServerLastRank'); $router->get ('/stat/getServerLastRank', 'Admin\\StatController@getServerLastRank');

View File

@ -3,9 +3,11 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model class User extends Model
{ {
use SoftDeletes;
protected $table = 'v2_user'; protected $table = 'v2_user';
protected $dateFormat = 'U'; protected $dateFormat = 'U';
protected $guarded = ['id']; protected $guarded = ['id'];

View File

@ -342,9 +342,10 @@ CREATE TABLE `v2_user` (
`expired_at` bigint(20) DEFAULT '0', `expired_at` bigint(20) DEFAULT '0',
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
`deleted_at` int(11) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`) UNIQUE KEY `email_deleted_at` (`email`,`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2021-05-06 16:14:04 -- 2021-06-30 15:34:40

View File

@ -411,3 +411,10 @@ ALTER TABLE `v2_order`
ALTER TABLE `v2_payment` ALTER TABLE `v2_payment`
ADD `uuid` char(32) NOT NULL AFTER `id`; ADD `uuid` char(32) NOT NULL AFTER `id`;
ALTER TABLE `v2_user`
ADD `deleted_at` int(11) NOT NULL AFTER `updated_at`;
ALTER TABLE `v2_user`
ADD UNIQUE `email_deleted_at` (`email`, `deleted_at`),
DROP INDEX `email`;