<?php
|
|
namespace app\supplier\controller\plus\groupbuy;
|
|
use app\supplier\controller\Controller;
|
use app\supplier\model\plus\groupbuy\Active as ActiveModel;
|
|
/**
|
* 供应商端团购活动控制器
|
*/
|
class Active extends Controller
|
{
|
/**
|
* 团购活动列表
|
*/
|
public function index()
|
{
|
$param = $this->postData();
|
// 添加供应商ID筛选
|
$param['shop_supplier_id'] = $this->getSupplierId();
|
|
$model = new ActiveModel();
|
$list = $model->getList($param);
|
return $this->renderSuccess('', compact('list'));
|
}
|
|
/**
|
* 添加团购活动
|
*/
|
public function add()
|
{
|
$model = new ActiveModel();
|
if ($this->request->isGet()) {
|
return $this->renderSuccess('', []);
|
}
|
|
$data = $this->postData();
|
// 设置供应商ID
|
$data['shop_supplier_id'] = $this->getSupplierId();
|
if ($model->add($data)) {
|
return $this->renderSuccess('添加成功');
|
}
|
return $this->renderError($model->getError() ?: '添加失败');
|
}
|
|
/**
|
* 编辑团购活动
|
*/
|
public function edit($groupbuy_active_id)
|
{
|
$model = ActiveModel::detail($groupbuy_active_id);
|
if (!$model) {
|
return $this->renderError('活动不存在');
|
}
|
|
// 验证权限
|
if ($model['shop_supplier_id'] != $this->getSupplierId()) {
|
return $this->renderError('没有权限操作此活动');
|
}
|
|
if ($this->request->isGet()) {
|
return $this->renderSuccess('', compact('model'));
|
}
|
|
$data = $this->postData();
|
if ($model->edit($data)) {
|
return $this->renderSuccess('更新成功');
|
}
|
return $this->renderError($model->getError() ?: '更新失败');
|
}
|
|
/**
|
* 删除团购活动
|
*/
|
public function delete($groupbuy_active_id)
|
{
|
$model = ActiveModel::detail($groupbuy_active_id);
|
if (!$model) {
|
return $this->renderError('活动不存在');
|
}
|
|
// 验证权限
|
if ($model['shop_supplier_id'] != $this->getSupplierId()) {
|
return $this->renderError('没有权限操作此活动');
|
}
|
|
if ($model->remove()) {
|
return $this->renderSuccess('删除成功');
|
}
|
return $this->renderError('删除失败');
|
}
|
|
/**
|
* 更新活动状态
|
*/
|
public function updateStatus($groupbuy_active_id, $status)
|
{
|
$model = ActiveModel::detail($groupbuy_active_id);
|
if (!$model) {
|
return $this->renderError('活动不存在');
|
}
|
|
// 验证权限
|
if ($model['shop_supplier_id'] != $this->getSupplierId()) {
|
return $this->renderError('没有权限操作此活动');
|
}
|
|
if ($model->updateStatus($status)) {
|
return $this->renderSuccess('状态更新成功');
|
}
|
return $this->renderError('状态更新失败');
|
}
|
}
|