| // +------------------------------------------------+ namespace app\common\service; use app\common\model\Advert as AdvertModel; use app\common\validate\Advert as AdvertValidate; class Advert extends _Init { public static function add($data) { $validate = new AdvertValidate(); if (!$validate->check($data)) { return $$validate->getError(); } if (AdvertModel::create($data)) { return true; } else { return '添加失败'; } } public static function edit($data) { $validate = new AdvertValidate(); if (!$validate->check($data)) { return $$validate->getError(); } if (AdvertModel::update($data)) { return true; } else { return '编辑失败'; } } public static function del($id) { $info = AdvertModel::get($id); if (!$info) { return $this->error('数据不存在'); } elseif ($info->save(['status' => -1])) { return true; } else { return '删除失败'; } } /** * [status description] * @param [type] $id [description] * @param [type] $status [description] * @param [type] $type [description] * @return [type] [description] */ public static function status($id, $status, $type) { $info = AdvertModel::get($id); if (!$info) { return $this->error('数据不存在'); } elseif ($info->save([$type => $status])) { Logs::write('修改状态', [$type => $status]); return true; } else { return '设置失败'; } } }