quanwei
2025-10-29 76ed09d116f484b261d44219de300b79eb2013b3
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
<?php
namespace app\api\controller\plus\business;
 
use app\api\controller\Controller;
use app\api\model\plus\business\Grade as GradeModel;
 
class Grade extends Controller
{
    /**
     * 获取等级列表
     */
    public function getList()
    {
        $model = new GradeModel();
        return $this->renderSuccess('',$model->getLists());
    }
    
    /**
     * 获取等级详情
     * @param $grade_id
     * @return array
     */
    public function detail($grade_id)
    {
        $model = new GradeModel();
        $detail = $model->detail($grade_id);
        if (!$detail) {
            return $this->renderError('等级不存在');
        }
        return $this->renderSuccess($detail);
    }
    
    /**
     * 添加等级
     */
    public function add()
    {
        $param = request()->param();
        if ((new GradeModel())->add($param)) {
            return $this->renderSuccess('', '添加成功');
        }
        return $this->renderError('添加失败');
    }
    
    /**
     * 编辑等级
     */
    public function edit()
    {
        $param = request()->param();
        $model = (new GradeModel())->detail($param['grade_id']);
        if (!$model) {
            return $this->renderError('等级不存在');
        }
        unset($param['grade_id']);
        if ($model->edit($param)) {
            return $this->renderSuccess('', '编辑成功');
        }
        return $this->renderError('编辑失败');
    }
    
    /**
     * 删除等级
     */
    public function delete()
    {
        $param = request()->param();
        $model = (new GradeModel())->detail($param['grade_id']);
        if (!$model) {
            return $this->renderError('等级不存在');
        }
        if ($model->setDelete()) {
            return $this->renderSuccess('', '删除成功');
        }
        return $this->renderError('该等级下存在名片,无法删除');
    }
}