71 lines
2.5 KiB
Twig
71 lines
2.5 KiB
Twig
<?php
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
*/
|
|
|
|
namespace {{ module_name }};
|
|
|
|
use App\Annotation\Auth;
|
|
use App\Model\{{ controller_name }} as {{ name1 }}Model;
|
|
use App\Request\{{ controller_name }} as {{ name1 }}Request;
|
|
use App\Utils\Param;
|
|
use Hyperf\HttpServer\Annotation\Controller;
|
|
use Hyperf\HttpServer\Annotation\DeleteMapping;
|
|
use Hyperf\HttpServer\Annotation\GetMapping;
|
|
use Hyperf\HttpServer\Annotation\PostMapping;
|
|
use Hyperf\HttpServer\Annotation\PutMapping;
|
|
|
|
#[Controller(prefix: "admin")]
|
|
class {{ controller_name }} extends Base
|
|
{
|
|
#[GetMapping(path: "{{ table_name }}/list")]
|
|
#[Auth(auth: "{{ table_name }}:list")]
|
|
public function {{ name2 }}List()
|
|
{
|
|
$param = Param::only([{% for field in query_fields %}"{{ field.column_name }}"{% if not loop.last %}, {% endif %}{% endfor %}, "limit"=>10]);
|
|
return $this->success("列表接口", {{ name1 }}Model::list($param));
|
|
}
|
|
|
|
#[GetMapping(path: "{{ table_name }}/option")]
|
|
#[Auth(needAuth: false)]
|
|
public function {{ name2 }}Option()
|
|
{
|
|
return $this->success({{ name1 }}Model::options());
|
|
}
|
|
|
|
#[GetMapping(path: "{{ table_name }}/info")]
|
|
#[Auth(auth: "{{ table_name }}:info")]
|
|
public function {{ name2 }}Info()
|
|
{
|
|
$id = $this->request->input("id");
|
|
return $this->success({{ name1 }}Model::getById($id));
|
|
}
|
|
|
|
#[PostMapping(path: "{{ table_name }}/add")]
|
|
#[Auth(auth: "{{ table_name }}:add")]
|
|
public function {{ name2 }}Add()
|
|
{
|
|
$request = $this->container->get({{ name1 }}Request::class);
|
|
$request->scene('add')->validateResolved();
|
|
$data = Param::only([{% for field in insert_fields %}"{{ field.column_name }}"{% if not loop.last %}, {% endif %}{% endfor %}]);
|
|
return $this->toAjax({{ name1 }}Model::add($data));
|
|
}
|
|
|
|
#[PutMapping(path: "{{ table_name }}/edit")]
|
|
#[Auth(auth: "{{ table_name }}:edit")]
|
|
public function {{ name2 }}Edit()
|
|
{
|
|
$request = $this->container->get({{ name1 }}Request::class);
|
|
$request->scene('edit')->validateResolved();
|
|
$data = Param::only([{% for field in edit_fields %}"{{ field.column_name }}"{% if not loop.last %}, {% endif %}{% endfor %}]);
|
|
return $this->toAjax({{ name1 }}Model::edit($data));
|
|
}
|
|
|
|
#[DeleteMapping(path: "{{ table_name }}/del")]
|
|
#[Auth(auth: "{{ table_name }}:del")]
|
|
public function {{ name2 }}Del()
|
|
{
|
|
$ids = $this->request->input("ids");
|
|
return $this->toAjax({{ name1 }}Model::del($ids));
|
|
}
|
|
} |