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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
 
namespace app\operations\controller\branch;
 
use app\operations\controller\Controller;
use app\operations\model\branch\Branch as BranchModel;
use app\operations\model\branch\Apply as ApplyModel;
use app\operations\model\branch\Category as CategoryModel;
use app\operations\model\branch\Area as AreaModel;
use app\operations\model\branch\DepositRefund as DepositRefundModel;
use app\operations\model\branch\ServiceApply as ServiceApplyModel;
use app\operations\model\settings\Setting as SettingModel;
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);
        foreach ($list as $key => $value) {
            $list[$key]['member_num'] = $list[$key]['member_num']+(new \app\operations\model\branch\ActivityUser())
                    ->group('user_id')->where(['branch_id'=>$value['branch_id']])->count();
        }
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 分会列表(不分页)
     */
    public function lists()
    {
        $model = new BranchModel;
        $postData = $this->postData();
        $list = $model->getAll($postData);
        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())) {
            return $this->renderSuccess('', '添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
 
    /**
     * 编辑分会
     */
    public function edit($branch_id = 0)
    {
        $model = BranchModel::detail($branch_id, ['superUser.user']);
        
        if($this->request->isGet()){
            $branchList = BranchModel::getALL(['branch_type' => 10]); // 获取总会列表
            $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 apply()
    {
        //获取该角色管理的区域 by yj 2023.12.20
        $area_ids = BranchModel::getAreaIdsByUser($this->store['user']);
        // 分会列表
        $model = new ApplyModel;
        $postData = $this->postData();
        if(!empty($area_ids)){
            $postData["area_ids"] = $area_ids;
        }
        $list = $model->getList($postData);
        return $this->renderSuccess('', compact('list'));
    }
    /**
     * 分会待审核详情
     */
    public function audit($branch_apply_id){
 
        $model = ApplyModel::detail($branch_apply_id, ['businessImage','user','category','area']);
        if($this->request->isGet()){
            return $this->renderSuccess('', compact('model'));
        }
        if ($model->audit($this->postData())) {
            return $this->renderSuccess('', '操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败', []);
    }
    /**
     * 退押金列表
     */
    public function refund()
    {
        $model = new DepositRefundModel;
        $list = $model->getList($this->postData());
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 退押金审核
     */
    public function submit($deposit_refund_id)
    {
        $model = DepositRefundModel::detail($deposit_refund_id);
        if ($model->submit($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
    /**
     * 服务保障申请列表
     */
    public function security()
    {
        $model = new ServiceApplyModel;
        $list = $model->getList($this->postData());
        return $this->renderSuccess('', compact('list'));
    }
    /**
     * 服务保障审核
     */
    public function verify($service_apply_id)
    {
        $model = ServiceApplyModel::getdetail($service_apply_id);
        if ($model->verify($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($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);
        $Qrcode->getImage();
    }
 
    /**
     * 商户券统计列表
     */
    public function statistics()
    {
        // 分会列表
        $model = new BranchModel;
        $postData = $this->postData();
        $list = $model->getStatisticsList($postData);
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 店员数据导出
     */
    public function export()
    {
        $model = new BranchModel();
        return $model->exportList($this->postData());
    }
}