huangsijun
2025-12-11 097a5f9e524acd965fa2abcfd18db30fc3f00ddb
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
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
 
namespace app\branch\controller\branch;
 
use app\common\model\settings\Setting as SettingModel;
use app\branch\model\branch\Branch as BranchModel;
use app\branch\model\activity\Activity as ActivityModel;
use app\branch\controller\Controller;
use app\common\service\qrcode\BranchService;
use app\common\model\settings\Region as RegionModel;
 
/**
 * 分会
 */
class Branch extends Controller
{
    /**
     * 分会列表
     */
    public function index()
    {
        $model = new BranchModel;
        $postData = $this->postData();
        $list = $model->getList($postData, $this->getBranchId());
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 分会列表(不分页)
     */
    public function lists()
    {
        $model = new BranchModel;
        $postData = $this->postData();
        $list = $model->getAll($postData, $this->getBranchId());
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 添加分会
     */
    public function add()
    {
        $model = new BranchModel;
        // $category = CategoryModel::getALL();
        // $region = AreaModel::getALL();
        // if($this->request->isGet()){
        //     return $this->renderSuccess('', compact('category','region'));
        // }
        // 新增记录
        if ($model->add($this->postData(), $this->getBranchId())) {
            return $this->renderSuccess('', '添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
 
    /**
     * 编辑分会
     */
    public function edit($branch_id = 0)
    {
        $model = BranchModel::detail($branch_id, ['superUser.user', 'logo']);
        
        if($this->request->isGet()){
            $branchList = BranchModel::getALL(['branch_type' => 10], $this->getBranchId()); // 获取总会列表
            $areaList = RegionModel::getCacheTree();        
            return $this->renderSuccess('', compact('model', 'branchList', 'areaList'));
        }
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('', '更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
 
    /**
     * 删除分会
     */
    public function delete($branch_id)
    {
        // 分会详情
        $model = BranchModel::detail($branch_id);
        if (!$model->setDelete()) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('', $model->getError() ?: '删除成功');
    }
 
    /**
     * 开启禁止
     */
    public function recycle($branch_id, $is_recycle)
    {
        // 商品详情
        $model = BranchModel::detail($branch_id);
        if (!$model->setRecycle($is_recycle)) {
            return $this->renderError('操作失败');
        }
        return $this->renderSuccess('操作成功');
    }
 
    /**
     * 二维码
     */
    public function qrcode($branch_id, $source)
    {
        $Qrcode = new BranchService($branch_id, $source);
        return $Qrcode->getImage();
    }
 
    /**
     * 排行榜
     */
    public function rank($date = null) {
        $model = new ActivityModel;
        $list = $model->getBranchRankList($date, $this->getBranchId());
        return $this->renderSuccess('', compact('list'));
    }
}