初始化-安装依赖

This commit is contained in:
2026-03-03 10:06:12 +08:00
parent 3f349a35a4
commit ec8cac4221
187 changed files with 26292 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace {{namespace_start}}controller{{namespace_end}};
use plugin\saiadmin\basic\BaseController;
use {{namespace_start}}logic{{namespace_end}}\{{class_name}}Logic;
use {{namespace_start}}validate{{namespace_end}}\{{class_name}}Validate;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
/**
* {{menu_name}}控制器
*/
class {{class_name}}Controller extends BaseController
{
/**
* 构造函数
*/
public function __construct()
{
$this->logic = new {{class_name}}Logic();
$this->validate = new {{class_name}}Validate;
parent::__construct();
}
/**
* 数据列表
* @param Request $request
* @return Response
*/
#[Permission('{{menu_name}}列表', '{{namespace}}:{{package_name}}:{{business_name}}:index')]
public function index(Request $request): Response
{
$where = $request->more([
{% for column in columns %}
{% if column.is_query == '2' %}
['{{column.column_name}}', ''],
{% endif %}
{% endfor %}
]);
{% if tpl_category == 'single' %}
$query = $this->logic->search($where);
{% if options.relations != null %}
$query->with([
{% for item in options.relations %}
'{{item.name}}',
{% endfor %}
]);
{% endif %}
$data = $this->logic->getList($query);
{% endif %}
{% if tpl_category == 'tree' %}
$data = $this->logic->tree($where);
{% endif %}
return $this->success($data);
}
/**
* 读取数据
* @param Request $request
* @return Response
*/
#[Permission('{{menu_name}}读取', '{{namespace}}:{{package_name}}:{{business_name}}:read')]
public function read(Request $request): Response
{
$id = $request->input('id', '');
$model = $this->logic->read($id);
if ($model) {
$data = is_array($model) ? $model : $model->toArray();
return $this->success($data);
} else {
return $this->fail('未查找到信息');
}
}
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('{{menu_name}}添加', '{{namespace}}:{{package_name}}:{{business_name}}:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('添加成功');
} else {
return $this->fail('添加失败');
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('{{menu_name}}修改', '{{namespace}}:{{package_name}}:{{business_name}}:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('修改成功');
} else {
return $this->fail('修改失败');
}
}
/**
* 删除数据
* @param Request $request
* @return Response
*/
#[Permission('{{menu_name}}删除', '{{namespace}}:{{package_name}}:{{business_name}}:destroy')]
public function destroy(Request $request): Response
{
$ids = $request->post('ids', '');
if (empty($ids)) {
return $this->fail('请选择要删除的数据');
}
$result = $this->logic->destroy($ids);
if ($result) {
return $this->success('删除成功');
} else {
return $this->fail('删除失败');
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace {{namespace_start}}logic{{namespace_end}};
{% if stub == 'eloquent' %}
use plugin\saiadmin\basic\eloquent\BaseLogic;
{% else %}
use plugin\saiadmin\basic\think\BaseLogic;
{% endif %}
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use {{namespace_start_model}}model{{namespace_end}}\{{class_name}};
/**
* {{menu_name}}逻辑层
*/
class {{class_name}}Logic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new {{class_name}}();
}
{% if tpl_category == 'tree' %}
/**
* 修改数据
* @param $id
* @param $data
* @return mixed
*/
public function edit($id, $data): mixed
{
if (!isset($data['{{options.tree_parent_id}}'])) {
$data['{{options.tree_parent_id}}'] = 0;
}
if ($data['{{options.tree_parent_id}}'] == $data['{{options.tree_id}}']) {
throw new ApiException('不能设置父级为自身');
}
return parent::edit($id, $data);
}
/**
* 删除数据
* @param $ids
*/
public function destroy($ids): bool
{
$num = $this->model->whereIn('{{options.tree_parent_id}}', $ids)->count();
if ($num > 0) {
throw new ApiException('该分类下存在子分类,请先删除子分类');
} else {
return parent::destroy($ids);
}
}
/**
* 树形数据
*/
public function tree($where)
{
$query = $this->search($where);
$request = request();
if ($request && $request->input('tree', 'false') === 'true') {
{% if stub == 'eloquent' %}
$query->select('{{options.tree_id}}', '{{options.tree_id}} as value', '{{options.tree_name}} as label', '{{options.tree_parent_id}}');
{% else %}
$query->field('{{options.tree_id}}, {{options.tree_id}} as value, {{options.tree_name}} as label, {{options.tree_parent_id}}');
{% endif %}
}
{% if options.relations != null %}
$query->with([
{% for item in options.relations %}
'{{item.name}}',
{% endfor %}
]);
{% endif %}
$data = $this->getAll($query);
return Helper::makeTree($data);
}
{% endif %}
}

View File

@@ -0,0 +1,304 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace {{namespace_start_model}}model{{namespace_end}};
{% if stub == 'eloquent' %}
use plugin\saiadmin\basic\eloquent\BaseModel;
{% else %}
use plugin\saiadmin\basic\think\BaseModel;
{% endif %}
/**
* {{menu_name}}模型
*
* {{table_name}} {{table_comment}}
*
{% for column in columns %}
* @property {{column.php_type}} ${{column.column_name}} {{column.column_comment}}
{% endfor %}
*/
class {{class_name}} extends BaseModel
{
/**
* 数据表主键
* @var string
*/
{% if stub == 'eloquent' %}
protected $primaryKey = '{{pk}}';
{% else %}
protected $pk = '{{pk}}';
{% endif %}
/**
* 数据库表名称
* @var string
*/
protected $table = '{{table_name}}';
{% if source != db_source and source != '' %}
/**
* 数据库连接
* @var string
*/
protected $connection = '{{source}}';
{% endif %}
{% if stub == 'eloquent' %}
/**
* 属性转换
*/
protected function casts(): array
{
return array_merge(parent::casts(), [
{% for column in columns %}
{% if column.view_type == 'inputTag' or column.view_type == 'checkbox' %}
'{{column.column_name}}' => 'array',
{% endif %}
{% if column.view_type == 'uploadImage' and column.options.limit > 1 %}
'{{column.column_name}}' => 'array',
{% endif %}
{% if column.view_type == 'imagePicker' and column.options.limit > 1 %}
'{{column.column_name}}' => 'array',
{% endif %}
{% if column.view_type == 'uploadFile' and column.options.limit > 1 %}
'{{column.column_name}}' => 'array',
{% endif %}
{% if column.view_type == 'chunkUpload' and column.options.limit > 1 %}
'{{column.column_name}}' => 'array',
{% endif %}
{% endfor %}
]);
}
{% else %}
{% for column in columns %}
{% if column.view_type == 'inputTag' or column.view_type == 'checkbox' %}
/**
* {{column.column_comment}} 保存数组转换
*/
public function set{{column.column_name | camel}}Attr($value)
{
return json_encode($value, JSON_UNESCAPED_UNICODE);
}
/**
* {{column.column_comment}} 读取数组转换
*/
public function get{{column.column_name | camel}}Attr($value)
{
return json_decode($value ?? '', true);
}
{% endif %}
{% if column.view_type == 'uploadImage' and column.options.limit > 1 %}
/**
* {{column.column_comment}} 保存数组转换
*/
public function set{{column.column_name | camel}}Attr($value)
{
return json_encode($value, JSON_UNESCAPED_UNICODE);
}
/**
* {{column.column_comment}} 读取数组转换
*/
public function get{{column.column_name | camel}}Attr($value)
{
return json_decode($value ?? '', true);
}
{% endif %}
{% if column.view_type == 'imagePicker' and column.options.limit > 1 %}
/**
* {{column.column_comment}} 保存数组转换
*/
public function set{{column.column_name | camel}}Attr($value)
{
return json_encode($value, JSON_UNESCAPED_UNICODE);
}
/**
* {{column.column_comment}} 读取数组转换
*/
public function get{{column.column_name | camel}}Attr($value)
{
return json_decode($value ?? '', true);
}
{% endif %}
{% if column.view_type == 'uploadFile' and column.options.limit > 1 %}
/**
* {{column.column_comment}} 保存数组转换
*/
public function set{{column.column_name | camel}}Attr($value)
{
return json_encode($value, JSON_UNESCAPED_UNICODE);
}
/**
* {{column.column_comment}} 读取数组转换
*/
public function get{{column.column_name | camel}}Attr($value)
{
return json_decode($value ?? '', true);
}
{% endif %}
{% if column.view_type == 'chunkUpload' and column.options.limit > 1 %}
/**
* {{column.column_comment}} 保存数组转换
*/
public function set{{column.column_name | camel}}Attr($value)
{
return json_encode($value, JSON_UNESCAPED_UNICODE);
}
/**
* {{column.column_comment}} 读取数组转换
*/
public function get{{column.column_name | camel}}Attr($value)
{
return json_decode($value ?? '', true);
}
{% endif %}
{% endfor %}
{% endif %}
{% for column in columns %}
{% if column.is_query == 2 and column.query_type == 'neq' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->where('{{column.column_name}}', '<>', $value);
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'gt' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->where('{{column.column_name}}', '>', $value);
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'gte' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->where('{{column.column_name}}', '>=', $value);
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'lt' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->where('{{column.column_name}}', '<', $value);
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'lte' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->where('{{column.column_name}}', '<=', $value);
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'like' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->where('{{column.column_name}}', 'like', '%'.$value.'%');
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'in' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->whereIn('{{column.column_name}}', $value);
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'notin' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->whereNotIn('{{column.column_name}}', $value);
}
{% endif %}
{% if column.is_query == 2 and column.query_type == 'between' %}
/**
* {{column.column_comment}} 搜索
*/
public function search{{column.column_name | camel}}Attr($query, $value)
{
$query->whereBetween('{{column.column_name}}', $value);
}
{% endif %}
{% endfor %}
{% for item in options.relations %}
{% if item.type == 'belongsTo' %}
/**
* 关联模型 {{item.name}}
*/
public function {{item.name}}()
{
return $this->{{item.type}}({{item.model}}::class, '{{item.localKey}}', '{{item.foreignKey}}');
}
{% endif %}
{% if item.type == 'hasOne' or item.type == 'hasMany' %}
/**
* 关联模型 {{item.name}}
*/
public function {{item.name}}()
{
return $this->{{item.type}}({{item.model}}::class, '{{item.localKey}}', '{{item.foreignKey}}');
}
{% endif %}
{% if item.type == 'belongsToMany' and stub == 'think' %}
/**
* 关联模型 {{item.name}}
*/
public function {{item.name}}()
{
return $this->{{item.type}}({{item.model}}::class, {{item.table}}::class, '{{item.localKey}}', '{{item.foreignKey}}');
}
{% endif %}
{% if item.type == 'belongsToMany' and stub == 'eloquent' %}
/**
* 关联模型 {{item.name}}
*/
public function {{item.name}}()
{
return $this->{{item.type}}({{item.model}}::class, {{item.table}}::class, '{{item.foreignKey}}', '{{item.localKey}}');
}
{% endif %}
{% endfor %}
}

View File

@@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace {{namespace_start}}validate{{namespace_end}};
use plugin\saiadmin\basic\BaseValidate;
/**
* {{menu_name}}验证器
*/
class {{class_name}}Validate extends BaseValidate
{
/**
* 定义验证规则
*/
protected $rule = [
{% for column in columns %}
{% if column.is_required == 2 and column.is_pk != 2 %}
'{{column.column_name}}' => 'require',
{% endif %}
{% endfor %}
];
/**
* 定义错误信息
*/
protected $message = [
{% for column in columns %}
{% if column.is_required == 2 and column.is_pk != 2 %}
'{{column.column_name}}' => '{{column.column_comment}}必须填写',
{% endif %}
{% endfor %}
];
/**
* 定义场景
*/
protected $scene = [
'save' => [
{% for column in columns %}
{% if column.is_required == 2 and column.is_pk != 2 %}
'{{column.column_name}}',
{% endif %}
{% endfor %}
],
'update' => [
{% for column in columns %}
{% if column.is_required == 2 and column.is_pk != 2 %}
'{{column.column_name}}',
{% endif %}
{% endfor %}
],
];
}