<?php
|
|
namespace app\operations\controller\plus\groupbuy;
|
|
use app\operations\controller\Controller;
|
use app\operations\model\plus\groupbuy\Active as ActiveModel;
|
|
/**
|
* 商家端团购活动控制器
|
*/
|
class Active extends Controller
|
{
|
/**
|
* 团购活动列表
|
*/
|
public function index()
|
{
|
$model = new ActiveModel();
|
$list = $model->getList($this->postData());
|
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 ($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 detail($groupbuy_active_id)
|
{
|
$detail = ActiveModel::detail($groupbuy_active_id);
|
if (!$detail) {
|
return $this->renderError('活动不存在');
|
}
|
return $this->renderSuccess('', compact('detail'));
|
}
|
/**
|
* 删除团购活动
|
*/
|
public function delete($groupbuy_active_id)
|
{
|
$model = ActiveModel::detail($groupbuy_active_id);
|
if (!$model) {
|
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->updateStatus($status)) {
|
return $this->renderSuccess('状态更新成功');
|
}
|
return $this->renderError('状态更新失败');
|
}
|
}
|