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.
137 lines
3.6 KiB
137 lines
3.6 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
|
|
/**
|
|
* swagger response返回数据引用
|
|
* @OA\Schema(
|
|
* schema="DemoMsgExport",
|
|
* required={"code","msg","count","data"},
|
|
* @OA\Property(
|
|
* property="code",
|
|
* type="integer",
|
|
* format="int32",
|
|
* description="状态码"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="msg",
|
|
* type="string",
|
|
* description="提示消息"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="count",
|
|
* type="integer",
|
|
* format="int32",
|
|
* description="记录总数",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="data",
|
|
* type="array",
|
|
* description="请求结果",
|
|
* @OA\Items(
|
|
* @OA\Property(
|
|
* property="id",
|
|
* type="integer",
|
|
* description="ID"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="site_id",
|
|
* type="integer",
|
|
* description="站点ID"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="username",
|
|
* type="string",
|
|
* description="管理员名称",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="sex",
|
|
* type="integer",
|
|
* description="性别"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="delete_time",
|
|
* type="integer",
|
|
* description="是否删除 null:未删除"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="update_time",
|
|
* type="integer",
|
|
* description="更新时间"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="create_time",
|
|
* type="integer",
|
|
* description="创建时间"
|
|
* ),
|
|
* )
|
|
* ),
|
|
*
|
|
* ),
|
|
*/
|
|
|
|
/**
|
|
* @mixin think\Model
|
|
*/
|
|
class Demo extends Common
|
|
{
|
|
|
|
protected $table = 'system_demo'; //如cloud_开头不需要
|
|
|
|
/**
|
|
* 管理员列表数据模型
|
|
* @return array|\think\Collection
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
//自定义处理逻辑
|
|
// $username = $this->request->param('username', '');
|
|
// $_op = $this->whereLike('username', "{$username}%");
|
|
// return parent::parentLists($_op);
|
|
|
|
//通用逻辑
|
|
return parent::parentLists();
|
|
}
|
|
|
|
|
|
/**
|
|
* 读取后
|
|
* @param Model $model
|
|
* @return bool|void
|
|
*/
|
|
public static function onAfterRead(Model $model)
|
|
{
|
|
//读取数据前格式化数据
|
|
if (in_array(request()->action(), ['edit', 'delete', 'status'])) {
|
|
return true;
|
|
}
|
|
//业务逻辑
|
|
}
|
|
|
|
/**
|
|
* 新增或修改前
|
|
* @param Model $model
|
|
* @return mixed|void
|
|
*/
|
|
public static function onBeforeWrite(Model $model)
|
|
{
|
|
parent::onBeforeWrite($model);
|
|
|
|
//写入数据前格式化数据
|
|
if (!in_array(request()->action(), ['add', 'edit'])) {
|
|
return true;
|
|
}
|
|
//业务逻辑
|
|
// code...
|
|
|
|
//以下参数禁止新增或者修改
|
|
$model->offsetUnset('ip');
|
|
}
|
|
|
|
}
|
|
|