71 lines
2.6 KiB
Twig
71 lines
2.6 KiB
Twig
<?php
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
*/
|
|
|
|
namespace {{ module_name }};
|
|
|
|
use App\Annotation\Auth;
|
|
use App\Model\{{ controller_name }} as {{ table_name | slice(0, 1) }}Model;
|
|
use App\Request\{{ controller_name }} as {{ table_name | slice(0, 1) }}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 {{ table_name }}List()
|
|
{
|
|
$param = Param::only([{% for field in query_fields %}"{{ field.column_name }}"{% if not loop.last %}, {% endif %}{% endfor %}]);
|
|
return $this->success({{ table_name | slice(0, 1) }}Model::list($param));
|
|
}
|
|
|
|
#[GetMapping(path: "{{ table_name }}/option")]
|
|
#[Auth(needAuth: false)]
|
|
public function {{ table_name }}Option()
|
|
{
|
|
return $this->success({{ table_name | slice(0, 1) }}Model::options());
|
|
}
|
|
|
|
#[GetMapping(path: "{{ table_name }}/info")]
|
|
#[Auth(auth: "{{ table_name }}:info")]
|
|
public function {{ table_name }}Info()
|
|
{
|
|
$id = $this->request->input("id");
|
|
return $this->success({{ table_name | slice(0, 1) }}Model::getById());
|
|
}
|
|
|
|
#[PostMapping(path: "{{ table_name }}/add")]
|
|
#[Auth(auth: "{{ table_name }}:add")]
|
|
public function {{ table_name }}Add()
|
|
{
|
|
$request = $this->container->get({{ table_name | slice(0, 1)}}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({{ table_name | slice(0, 1) }}Model::add($data));
|
|
}
|
|
|
|
#[PutMapping(path: "{{ table_name }}/edit")]
|
|
#[Auth(auth: "{{ table_name }}:edit")]
|
|
public function {{ table_name }}Edit()
|
|
{
|
|
$request = $this->container->get({{ table_name | slice(0, 1)}}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({{ table_name | slice(0, 1) }}Model::edit($data));
|
|
}
|
|
|
|
#[DeleteMapping(path: "{{ table_name }}/del")]
|
|
#[Auth(auth: "{{ table_name }}:del")]
|
|
public function {{ table_name }}Del()
|
|
{
|
|
$ids = $this->request->input("ids");
|
|
return $this->toAjax({{ table_name | slice(0, 1) }}Model::del($ids));
|
|
}
|
|
} |