<?php
namespace app\store\controller\apps\bargain;
use app\store\controller\Controller;
use app\store\model\Goods as GoodsModel;
use app\store\model\bargain\Active as ActiveModel;
class Active extends Controller
{
public function index($search = '')
{
$model = new ActiveModel;
$list = $model->getList($search);
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.bargain.active/index'));
}
return $this->renderError($model->getError() ?: '添加失败');
}
public function edit($active_id)
{
$model = ActiveModel::detail($active_id);
if (!$this->request->isAjax()) {
$goods = GoodsModel::detail($model['goods_id']);
return $this->fetch('edit', compact('model', 'goods'));
}
if ($model->edit($this->postData('active'))) {
return $this->renderSuccess('更新成功', url('apps.bargain.active/index'));
}
return $this->renderError($model->getError() ?: '更新失败');
}
public function delete($active_id)
{
$model = ActiveModel::detail($active_id);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}