<?php
namespace app\store\controller\apps\sharp;
use app\store\controller\Controller;
use app\store\model\sharp\Active as ActiveModel;
class Active extends Controller
{
public function index()
{
$model = new ActiveModel;
$list = $model->getList();
return $this->fetch('index', compact('list'));
}
public function add()
{
if (!$this->request->isAjax()) {
return $this->fetch('add');
}
$model = new ActiveModel;
if ($model->add($this->postData('active'))) {
return $this->renderSuccess('添加成功', url('apps.sharp.active/index'));
}
return $this->renderError($model->getError() ?: '添加失败');
}
public function state($active_id, $state)
{
$model = ActiveModel::detail($active_id);
if (!$model->setStatus($state)) {
return $this->renderError('操作失败');
}
return $this->renderSuccess('操作成功');
}
public function delete($active_id)
{
$model = ActiveModel::detail($active_id);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}