quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
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
<?php
 
namespace app\api\controller\branch\admin;
 
use app\api\controller\branch\Admin;
use app\api\model\branch\Activity as ActivityModel;
use app\api\model\branch\Branch as BranchModel;
use app\common\model\settings\Region as RegionModel;
 
/**
 * 分会数据控制器
 */
class Branch extends Admin
{
    /**
     * 分会列表
     */
    public function index()
    {
        $model = new BranchModel;
        $postData = $this->postData();
        $list = $model->getListForAdmin($postData, $this->branch['branch_id']);
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 添加分会
     */
    public function add()
    {
        $model = new BranchModel;
        $data = json_decode($this->request->post('formData', '', null), true);
        // 新增记录
        if ($model->add($data, $this->branch['branch_id'])) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
 
    /**
     * 编辑分会
     */
    public function edit($branch_id)
    {
        $model = BranchModel::detail($branch_id, ['superUser.user']);
        
        if($this->request->isGet()){
            $regionData = RegionModel::getRegionForApi();
            return $this->renderSuccess('', compact('model', 'regionData'));
        }
        $data = json_decode($this->request->post('formData', '', null), true);
        if ($model->edit($data)) {
            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 ranking($date = null) {
        $model = new ActivityModel;
        $list = $model->getBranchRankList($date, $this->branch['branch_id']);
        return $this->renderSuccess('', compact('list'));
    }
}