1
0

first commit

This commit is contained in:
2020-08-06 14:58:51 +08:00
commit 17096657dc
780 changed files with 92857 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
<?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;
}
}