style: optimize ui for login and index pages with modern ios tech style
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace app\adminapi\controller\asset;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\common\model\AssetResource;
|
||||
use app\common\model\AssetUserResource;
|
||||
use think\facade\Db;
|
||||
|
||||
class AssetResourceController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* @notes 资源列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$pageNo = $this->request->get('page_no', 1);
|
||||
$pageSize = $this->request->get('page_size', 15);
|
||||
$type = $this->request->get('type');
|
||||
|
||||
$where = [];
|
||||
if ($type) {
|
||||
$where[] = ['type', '=', $type];
|
||||
}
|
||||
|
||||
$count = AssetResource::where($where)->count();
|
||||
$lists = AssetResource::with('users')
|
||||
->where($where)
|
||||
->order('id', 'desc')
|
||||
->page($pageNo, $pageSize)
|
||||
->select();
|
||||
|
||||
return $this->data([
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
'page_no' => $pageNo,
|
||||
'page_size' => $pageSize,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加资源及分配账号
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
if (empty($params['type']) || empty($params['title']) || empty($params['file_url'])) {
|
||||
return $this->fail('请填写完整的资源信息');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$resource = AssetResource::create([
|
||||
'type' => $params['type'],
|
||||
'title' => $params['title'],
|
||||
'file_url' => $params['file_url'],
|
||||
'cover_url' => $params['cover_url'] ?? '',
|
||||
]);
|
||||
|
||||
// 绑定用户
|
||||
if (!empty($params['user_ids']) && is_array($params['user_ids'])) {
|
||||
$userResources = [];
|
||||
foreach ($params['user_ids'] as $userId) {
|
||||
$userResources[] = [
|
||||
'user_id' => $userId,
|
||||
'resource_id' => $resource->id,
|
||||
'create_time' => time(),
|
||||
];
|
||||
}
|
||||
(new AssetUserResource())->saveAll($userResources);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $this->success('添加并分配成功', ['id' => $resource->id]);
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->fail('操作失败: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除资源
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
if (empty($id)) {
|
||||
return $this->fail('缺少参数');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
AssetResource::destroy($id);
|
||||
AssetUserResource::where('resource_id', $id)->delete();
|
||||
Db::commit();
|
||||
return $this->success('删除成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
namespace app\adminapi\controller\asset;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\common\model\AssetUser;
|
||||
|
||||
class AssetUserController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* @notes 账号列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$pageNo = $this->request->get('page_no', 1);
|
||||
$pageSize = $this->request->get('page_size', 15);
|
||||
|
||||
$count = AssetUser::count();
|
||||
$lists = AssetUser::order('id', 'desc')
|
||||
->page($pageNo, $pageSize)
|
||||
->select();
|
||||
|
||||
return $this->data([
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
'page_no' => $pageNo,
|
||||
'page_size' => $pageSize,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加账号
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
if (empty($params['phone'])) {
|
||||
return $this->fail('手机号不能为空');
|
||||
}
|
||||
|
||||
$exist = AssetUser::where('phone', $params['phone'])->find();
|
||||
if ($exist) {
|
||||
return $this->fail('手机号已存在');
|
||||
}
|
||||
|
||||
// Default password 123456
|
||||
$password = empty($params['password']) ? '123456' : $params['password'];
|
||||
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
$user = AssetUser::create([
|
||||
'phone' => $params['phone'],
|
||||
'password' => $passwordHash,
|
||||
'status' => $params['status'] ?? 1,
|
||||
]);
|
||||
|
||||
return $this->success('添加成功', ['id' => $user->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑账号
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
if (empty($params['id'])) {
|
||||
return $this->fail('缺少参数');
|
||||
}
|
||||
|
||||
$user = AssetUser::find($params['id']);
|
||||
if (!$user) {
|
||||
return $this->fail('账号不存在');
|
||||
}
|
||||
|
||||
if (!empty($params['phone']) && $params['phone'] != $user->phone) {
|
||||
$exist = AssetUser::where('phone', $params['phone'])->find();
|
||||
if ($exist) {
|
||||
return $this->fail('手机号已存在');
|
||||
}
|
||||
$user->phone = $params['phone'];
|
||||
}
|
||||
|
||||
if (!empty($params['password'])) {
|
||||
$user->password = password_hash($params['password'], PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
if (isset($params['status'])) {
|
||||
$user->status = $params['status'];
|
||||
}
|
||||
|
||||
$user->save();
|
||||
return $this->success('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除账号
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
if (empty($id)) {
|
||||
return $this->fail('缺少参数');
|
||||
}
|
||||
|
||||
AssetUser::destroy($id);
|
||||
// 也需要删除关联的资源记录
|
||||
\app\common\model\AssetUserResource::where('user_id', $id)->delete();
|
||||
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user