quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?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('状态更新失败');
    }
}