发票管理apiadmin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

80 lines
2.0 KiB

<?php
declare (strict_types=1);
/**
* 由ApiAdmin自动构建,请处理{$MODEL_NAME}
* @author apiadmin <apiadmin.org>
*/
namespace app\controller\{$MODULE};
use app\model\{$MODEL_NAME};
use app\util\ReturnCode;
use think\Response;
class {$NAME} extends Base {
/**
*
* @return \think\Response
* @throws \think\db\exception\DbException
* @author apiadmin <apiadmin.org>
*/
public function index(): Response {
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
$start = $this->request->get('page', 1);
$obj = new {$MODEL_NAME}();
$listObj = $obj->paginate(['page' => $start, 'list_rows' => $limit])->toArray();
return $this->buildSuccess([
'list' => $listObj['data'],
'count' => $listObj['total']
]);
}
/**
*
* @return Response
* @author apiadmin <apiadmin.org>
*/
public function add(): Response {
$postData = $this->request->post();
$res = {$MODEL_NAME}::create($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
}
return $this->buildSuccess();
}
/**
*
* @return Response
* @author apiadmin <apiadmin.org>
*/
public function edit(): Response {
$postData = $this->request->post();
$res = {$MODEL_NAME}::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
}
return $this->buildSuccess();
}
/**
*
* @return Response
* @author apiadmin <apiadmin.org>
*/
public function del(): Response {
$id = $this->request->get('id');
if (!$id) {
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
}
//
{$MODEL_NAME}::destroy(['id' => $id]);
return $this->buildSuccess();
}
}