修改
This commit is contained in:
parent
8d5ec7966a
commit
ceda3a224a
@ -50,7 +50,7 @@ class User extends CatchController
|
|||||||
*
|
*
|
||||||
* @param CreateRequest $request
|
* @param CreateRequest $request
|
||||||
* @time 2019年12月06日
|
* @time 2019年12月06日
|
||||||
* @return Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function save(CreateRequest $request)
|
public function save(CreateRequest $request)
|
||||||
{
|
{
|
||||||
@ -60,14 +60,14 @@ class User extends CatchController
|
|||||||
$this->user->attach($request->param('roleids'));
|
$this->user->attach($request->param('roleids'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return CatchResponse::success();
|
return CatchResponse::success('', '添加成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2019年12月04日
|
* @time 2019年12月04日
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function read($id)
|
public function read($id)
|
||||||
{
|
{
|
||||||
@ -85,7 +85,7 @@ class User extends CatchController
|
|||||||
* @time 2019年12月04日
|
* @time 2019年12月04日
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param UpdateRequest $request
|
* @param UpdateRequest $request
|
||||||
* @return Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function update($id, UpdateRequest $request)
|
public function update($id, UpdateRequest $request)
|
||||||
{
|
{
|
||||||
@ -106,7 +106,7 @@ class User extends CatchController
|
|||||||
*
|
*
|
||||||
* @time 2019年12月04日
|
* @time 2019年12月04日
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
@ -122,9 +122,9 @@ class User extends CatchController
|
|||||||
*
|
*
|
||||||
* @time 2019年12月07日
|
* @time 2019年12月07日
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function switchStatus($id): Json
|
public function switchStatus($id): \think\response\Json
|
||||||
{
|
{
|
||||||
$user = $this->user->findBy($id);
|
$user = $this->user->findBy($id);
|
||||||
return CatchResponse::success($this->user->updateBy($id, [
|
return CatchResponse::success($this->user->updateBy($id, [
|
||||||
@ -136,12 +136,12 @@ class User extends CatchController
|
|||||||
*
|
*
|
||||||
* @time 2019年12月07日
|
* @time 2019年12月07日
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return Json
|
* @return \think\response\Json
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public function recover($id): Json
|
public function recover($id): \think\response\Json
|
||||||
{
|
{
|
||||||
$trashedUser = $this->user->findBy($id, ['*'], true);
|
$trashedUser = $this->user->findBy($id, ['*'], true);
|
||||||
|
|
||||||
@ -176,4 +176,4 @@ class User extends CatchController
|
|||||||
'hasRoles' => $roleIds,
|
'hasRoles' => $roleIds,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,9 @@ class Users extends CatchModel
|
|||||||
})
|
})
|
||||||
->when($search['status'] ?? false, function ($query) use ($search){
|
->when($search['status'] ?? false, function ($query) use ($search){
|
||||||
$query->where('status', $search['status']);
|
$query->where('status', $search['status']);
|
||||||
})->paginate($search['limit'] ?? $this->limit);
|
})
|
||||||
|
->order('id', 'desc')
|
||||||
|
->paginate($search['limit'] ?? $this->limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,4 +82,4 @@ class Users extends CatchModel
|
|||||||
|
|
||||||
return array_unique($permissionIds);
|
return array_unique($permissionIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +1,63 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace catcher;
|
namespace catcher;
|
||||||
|
|
||||||
use think\facade\View;
|
|
||||||
use think\Paginator;
|
use think\Paginator;
|
||||||
use think\Response;
|
use think\Response;
|
||||||
|
use think\response\Json;
|
||||||
|
|
||||||
class CatchResponse
|
class CatchResponse
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 成功的响应
|
* 成功的响应
|
||||||
*
|
*
|
||||||
* @time 2019年12月02日
|
* @time 2019年12月02日
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param $msg
|
* @param $msg
|
||||||
* @param int $code
|
* @param int $code
|
||||||
* @return \think\response\Json
|
* @return Json
|
||||||
*/
|
*/
|
||||||
public static function success($data = [], $msg = 'success', $code = Code::SUCCESS): \think\response\Json
|
public static function success($data = [], $msg = 'success', $code = Code::SUCCESS): Json
|
||||||
{
|
{
|
||||||
return json([
|
return json([
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
'msg' => $msg,
|
'message' => $msg,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页
|
* 分页
|
||||||
*
|
*
|
||||||
* @time 2019年12月06日
|
* @time 2019年12月06日
|
||||||
* @param Paginator $list
|
* @param Paginator $list
|
||||||
* @return \think\response\Json
|
* @return
|
||||||
*/
|
*/
|
||||||
public static function paginate(Paginator $list): \think\response\Json
|
public static function paginate(Paginator $list)
|
||||||
{
|
{
|
||||||
return json([
|
return json([
|
||||||
'code' => 10000,
|
'code' => 10000,
|
||||||
'msg' => 'success',
|
'msg' => 'success',
|
||||||
'count' => $list->total(),
|
'count' => $list->total(),
|
||||||
'current' => $list->currentPage(),
|
'current' => $list->currentPage(),
|
||||||
'limit' => $list->listRows(),
|
'limit' => $list->listRows(),
|
||||||
'data' => $list->getCollection(),
|
'data' => $list->getCollection(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误的响应
|
* 错误的响应
|
||||||
*
|
*
|
||||||
* @time 2019年12月02日
|
* @time 2019年12月02日
|
||||||
* @param string $msg
|
* @param string $msg
|
||||||
* @param int $code
|
* @param int $code
|
||||||
* @return mixed
|
* @return Json
|
||||||
* @throws \Exception
|
*/
|
||||||
*/
|
public static function fail($msg = '', $code = 10001): Json
|
||||||
public static function fail($msg = '', $code = 10001)
|
{
|
||||||
{
|
return json([
|
||||||
if (request()->isAjax()) {
|
'code' => $code,
|
||||||
return json([
|
'msg' => $msg,
|
||||||
'code' => $code,
|
]);
|
||||||
'msg' => $msg,
|
}
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response::create(config('catch.error'), 'view', $code)->assign(['msg' => $msg, 'code' => $code]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user