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.
119 lines
3.0 KiB
119 lines
3.0 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
|
|
|
|
/**
|
|
* // swagger response返回数据引用
|
|
* @OA\Schema(
|
|
* schema="ConfigMsgExport",
|
|
* 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="username",
|
|
* type="string",
|
|
* description="管理员名称",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="truename",
|
|
* type="string",
|
|
* description="管理员真实姓名",
|
|
* ),
|
|
* )
|
|
* ),
|
|
*
|
|
* ),
|
|
*/
|
|
|
|
/**
|
|
* @mixin think\Model
|
|
*/
|
|
class Config extends Common
|
|
{
|
|
/**
|
|
* 管理员列表数据模型
|
|
* @return array|\think\Collection
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
$_result = parent::parentLists('', 0);
|
|
$_result = array_column($_result['data'], 'value', 'name');
|
|
//通用逻辑
|
|
return $_result;
|
|
}
|
|
|
|
public function edit(array $_post = [])
|
|
{
|
|
//业务逻辑
|
|
if (empty($_post)) {
|
|
return false;
|
|
}
|
|
$name_arr = array_keys($_post);
|
|
$id_arr = $this->where('name', 'in', $name_arr)->where('site_id', SITE_ID)->column('id');
|
|
if (!empty($id_arr)) {
|
|
$affected = self::destroy($id_arr, true); //TP真删除
|
|
if (!$affected) {
|
|
return false;
|
|
}
|
|
}
|
|
foreach ($_post as $k => $v) {
|
|
$_temp = [
|
|
'name' => $k,
|
|
'value' => $v,
|
|
'site_id' => SITE_ID,
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
];
|
|
$_data[] = $_temp;
|
|
}
|
|
return $this->insertAll($_data);
|
|
}
|
|
|
|
|
|
/**
|
|
* 读取后
|
|
* @param Model $model
|
|
* @return bool|void
|
|
*/
|
|
public static function onAfterRead(Model $model)
|
|
{
|
|
//读取数据前格式化数据
|
|
if (in_array(request()->action(), ['edit', 'delete', 'status'])) {
|
|
return true;
|
|
}
|
|
//业务逻辑
|
|
}
|
|
|
|
}
|
|
|