You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.1 KiB
95 lines
2.1 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\store\controller\market;
|
|
|
|
use think\response\Json;
|
|
use app\store\controller\Controller;
|
|
use app\store\model\ActiveMain as ActiveMainModal;
|
|
use app\store\model\ActiveCol as ActiveColModal;
|
|
|
|
/**
|
|
* 活动管理
|
|
* Class Active
|
|
* @package app\store\controller\market
|
|
*/
|
|
class Active extends Controller
|
|
{
|
|
/**
|
|
* 列表记录
|
|
* @return Json
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function list(): Json
|
|
{
|
|
$model = new ActiveMainModal;
|
|
$list = $model->getList($this->request->param());
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
/**
|
|
* 添加活动
|
|
* @return Json
|
|
*/
|
|
public function add(): Json
|
|
{
|
|
// 新增记录
|
|
$model = new ActiveMainModal;
|
|
|
|
if ($model->add($this->postForm())) {
|
|
return $this->renderSuccess('添加成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '添加失败');
|
|
}
|
|
|
|
/**
|
|
* 更新活动
|
|
* @param int $activeId
|
|
* @return Json
|
|
*/
|
|
public function edit(int $activeId): Json
|
|
{
|
|
// 协议详情
|
|
$model = ActiveMainModal::detail($activeId);
|
|
// 更新记录
|
|
if ($model->edit($this->postForm())) {
|
|
return $this->renderSuccess('更新成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '更新失败');
|
|
}
|
|
|
|
/**
|
|
* 删除活动
|
|
* @param int $activeId
|
|
* @return Json
|
|
*/
|
|
public function delete(int $activeId): Json
|
|
{
|
|
// 先看是否在副表中有数据
|
|
$model = new ActiveColModal;
|
|
$list = $model->getList($activeId);
|
|
if (count($list) > 0) {
|
|
return $this->renderError('请先删除活动模块');
|
|
}
|
|
|
|
$model = ActiveMainModal::detail($activeId);
|
|
if ($model->setDelete()) {
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '删除失败');
|
|
}
|
|
|
|
|
|
/**
|
|
* 根据活动 id 获取活动的模块列表
|
|
* @param init $activeId
|
|
*/
|
|
public function colList(int $activeId): Json
|
|
{
|
|
$model = new ActiveColModal;
|
|
$list = $model->getList($activeId);
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
}
|
|
|