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,124 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Category as CategoryModel;
use app\common\model\Content as ContentModel;
use app\common\validate\Content as ContentValidate;
class Content extends _Init
{
/**
* 添加信息
* @param [type] $data 文章数据
*/
public static function create($data)
{
$validate = new ContentValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = ContentModel::create($data);
if ($info) {
return true;
} else {
return '创建文章失败';
}
}
/**
* 编辑文章
* @param [type] $data 更新的数据
* @return [type] 返回 修改的结果
*/
public static function edit($data)
{
$validate = new ContentValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = ContentModel::update($data);
if ($info) {
return true;
} else {
return '编辑文章失败';
}
}
/**
* 修改文章状态
* @param [type] $id 文章id
* @param [type] $status 状态
* @return [type] 返回结果
*/
public static function status($id, $status)
{
$info = ContentModel::get($id);
if (!$info) {
return '文章不存在';
} elseif ($info->save(['status' => $status])) {
Logs::write('修改状态', ['status' => $status]);
return true;
} else {
return '修改状态失败';
}
}
/**
* 删除文章
* @param [type] $id 要删除的文章id
* @return [type] 返回 结果
*/
public static function del($id)
{
$info = ContentModel::get($id);
if (!$info) {
return '文章不存在';
} elseif ($info->save(['status' => -1])) {
return true;
} else {
return '删除失败';
}
}
/**
* 根据model活动分类id
* @param [type] $name 模型名称
* @return [type] [description]
*/
public static function getCategoryIds($name)
{
$map = [
'status' => 1,
'model' => $name,
];
$list = CategoryModel::where($map)->column('id');
if (!empty($list)) {
return implode(',', $list);
} else {
return '';
}
}
/**
* 获取分类列表
* @return [type] [description]
*/
public static function categoryList($name)
{
$map = [
'status' => 1,
'model' => $name,
];
return CategoryModel::where($map)->order('sort asc')->select();
}
}