|
|
|
<?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;
|
|
|
|
use app\store\model\Goods as GoodsModal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 活动管理
|
|
|
|
* 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'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加活动模块
|
|
|
|
* @return Json
|
|
|
|
*/
|
|
|
|
public function colAdd(): Json
|
|
|
|
{
|
|
|
|
// 新增记录
|
|
|
|
$model = new ActiveColModal;
|
|
|
|
|
|
|
|
if ($model->add($this->postForm())) {
|
|
|
|
return $this->renderSuccess('添加成功');
|
|
|
|
}
|
|
|
|
return $this->renderError($model->getError() ?: '添加失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新活动模块
|
|
|
|
* @param int $activeColId
|
|
|
|
* @return Json
|
|
|
|
*/
|
|
|
|
public function colEdit(int $activeColId): Json
|
|
|
|
{
|
|
|
|
$model = ActiveColModal::detail($activeColId);
|
|
|
|
// 更新记录
|
|
|
|
if ($model->edit($this->postForm())) {
|
|
|
|
return $this->renderSuccess('更新成功');
|
|
|
|
}
|
|
|
|
return $this->renderError($model->getError() ?: '更新失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除活动模块
|
|
|
|
* @param int $activeColId
|
|
|
|
* @return Json
|
|
|
|
*/
|
|
|
|
public function colDelete(int $activeColId): Json
|
|
|
|
{
|
|
|
|
$model = ActiveColModal::detail($activeColId);
|
|
|
|
if ($model->setDelete()) {
|
|
|
|
return $this->renderSuccess('删除成功');
|
|
|
|
}
|
|
|
|
return $this->renderError($model->getError() ?: '删除失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* goodsList 获取商品列表
|
|
|
|
* @return Json
|
|
|
|
*/
|
|
|
|
public function goodsList(string $goodsIds): Json
|
|
|
|
{
|
|
|
|
$goodsIds = explode(',', $goodsIds);
|
|
|
|
|
|
|
|
$model = new GoodsModal;
|
|
|
|
$list = $model->getListByIds($goodsIds);
|
|
|
|
return $this->renderSuccess(compact('list'));
|
|
|
|
}
|
|
|
|
}
|