data_center/app/adminapi/logic/systems/SystemLogic.php

71 lines
1.9 KiB
PHP

<?php
namespace app\adminapi\logic\systems;
use app\common\logic\BaseLogic;
use app\common\model\systems\System;
class SystemLogic extends BaseLogic
{
//新增
public static function add(array $params): bool
{
try{
System::create([
'name' => $params['name'],
'url' => $params['url'],
'app_id' => create_app_id(),
'app_key' => create_app_key(),
'register_status' => $params['register_status'],
'status' => 0,
]);
return true;
}catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
//删除
public static function delete(array $params): bool
{
try {
System::update([
'id' => $params['id'],
'status' => 2,
'update_time' => time()
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
//修改
public static function edit(array $params) : bool
{
try {
System::update([
'id' => $params['id'],
'name' => $params['name'],
'url' => $params['url'],
'status' => $params['status'],
'register_status' => $params['register_status'],
'update_time' => time()
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
// 查看
public static function detail($params) : array
{
$data = System::field('id,name,app_id,app_key,url,register_status,status,create_time')->findOrEmpty($params['id']);
$data['status_text'] = $data->status_text;
return $data->toArray();
}
}