Files
2020-08-06 15:26:41 +08:00

97 lines
2.5 KiB
PHP
Raw Permalink 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\Suggest as SuggestModel;
use app\common\validate\Suggest as SuggestValidate;
class Suggest extends _Init
{
/**
* 添加信息
* @param [type] $data 意见数据
*/
public static function create($data)
{
$scene = empty($data['pid']) ? 'add' : 'remark';
$validate = new SuggestValidate();
if (!$validate->scene($scene)->check($data)) {
return $validate->getError();
}
$info = SuggestModel::create($data);
if ($info) {
return true;
} else {
return "添加失败";
}
}
/**
* 编辑意见
* @param [type] $data 更新的数据
* @return [type] 返回 修改的结果
*/
public static function edit($data)
{
$validate = new SuggestValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = SuggestModel::update($data);
if ($info) {
return true;
} else {
return "操作失败";
}
}
/**
* 修改意见状态
* @param [type] $id 意见id
* @param [type] $status 状态
* @return [type] 返回结果
*/
public static function status($id, $status)
{
$info = SuggestModel::get($id);
if (!$info) {
return lang("信息不存在");
} elseif ($info->save(['status' => $status])) {
Logs::write('修改状态', ['status' => $status]);
return true;
} else {
return "设置失败";
}
}
public static function read($id)
{
$info = SuggestModel::get($id);
SuggestModel::where('pid',$id)->update(['read'=>1]);
return $info;
}
/**
* 删除意见
* @param [type] $id 要删除的意见id
* @return [type] 返回 结果
*/
public static function del($id)
{
$model = new SuggestModel();
if ($model->destroy($id)) {
return true;
} else {
return "删除失败";
}
}
}