$store
$store : array
秒杀活动会场管理 Class Active
$view : \think\View
$request : \think\Request
__construct(\think\Request $request = null)
构造方法
\think\Request | $request | Request 对象 |
validate(array $data, string|array $validate, array $message = array(), boolean $batch = false, mixed $callback = null) : array|string|true
验证数据
array | $data | 数据 |
string|array | $validate | 验证器名或者验证规则数组 |
array | $message | 提示信息 |
boolean | $batch | 是否批量验证 |
mixed | $callback | 回调方法(闭包) |
<?php
namespace app\store\controller\apps\sharp;
use app\store\controller\Controller;
use app\store\model\sharp\Active as ActiveModel;
/**
* 秒杀活动会场管理
* Class Active
* @package app\store\controller\apps\sharp
*/
class Active extends Controller
{
/**
* 活动会场列表
* @return mixed
* @throws \think\exception\DbException
*/
public function index()
{
$model = new ActiveModel;
$list = $model->getList();
return $this->fetch('index', compact('list'));
}
/**
* 新增活动会场
* @return array|bool|mixed
* @throws \Exception
*/
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() ?: '添加失败');
}
/**
* 修改活动状态
* @param $active_id
* @param $state
* @return array|bool
* @throws \think\exception\DbException
*/
public function state($active_id, $state)
{
// 活动详情
$model = ActiveModel::detail($active_id);
if (!$model->setStatus($state)) {
return $this->renderError('操作失败');
}
return $this->renderSuccess('操作成功');
}
/**
* 删除活动会场
* @param $active_id
* @return array
* @throws \think\exception\DbException
*/
public function delete($active_id)
{
// 活动会场详情
$model = ActiveModel::detail($active_id);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}