1
0
Files
helper/application/common/service/Config.php
2020-08-06 14:58:51 +08:00

113 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Config as ConfigModel;
use app\common\validate\Config as ConfigValidate;
class Config extends _Init
{
/**
* 添加配置项
* @param [type] $data 配置数据
*/
public static function add($data)
{
$validate = new ConfigValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
if (ConfigModel::create($data)) {
Logs::write('新增配置', $data);
return true;
} else {
return '新增配置失败';
}
}
/**
* 修改配置
* @param [type] $data 配置数据集合
* @return [type] 返回的信息 true 和 错误信息
*/
public static function edit($data)
{
$validate = new ConfigValidate();
if (!$validate->scene('edit')->check($data)) {
return $validate->getError();
}
if (ConfigModel::update($data)) {
Logs::write('编辑配置', $data);
return true;
} else {
return '编辑配置失败';
}
}
/**
* 删除配置
* @param [type] $id 配置id
* @return [type] 返回的信息 true 和 错误信息
*/
public static function del($id)
{
$info = ConfigModel::get($id);
if (!$info) {
return '数据不存在';
} elseif ($info->save(['status' => -1])) {
Logs::write('删除配置', $info);
return true;
} else {
return '删除配置失败';
}
}
/**
* 设置配置状态
* @param [type] $id 配置id
* @param [type] $status 要设置的状态
* @param [type] $type 要设置的字段
* @return [type] 返回的信息
*/
public static function status($id, $status, $type)
{
$info = ConfigModel::get($id);
if (!$info) {
return '配置不存在';
} elseif ($info->save([$type => $status])) {
Logs::write('修改状态', [$type => $status]);
return true;
} else {
return '状态修改失败';
}
}
/**
* 批量编辑配置
* @param array $config 编辑的信息
* @return
*/
public static function batchEdit($config)
{
if ($config && is_array($config)) {
foreach ($config as $name => $value) {
ConfigModel::update(['value' => $value], ['name' => $name]);
}
}
Logs::write('批量修改配置', $config);
return true;
}
}