liyaozhi
2025-10-28 1320688354fd168c51cf2e05f29a2253f4ed9c00
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
<?php
 
namespace app\admin\controller;
 
use app\admin\model\Application_category as ModelApplication_category;
use app\admin\model\Application as ApplicationModel;
use app\admin\model\Access as AccessModel;
class Application extends Controller
{
    /**
     * 获取分类应用
     */
    public function index()
    {
        $accessList = ModelApplication_category::getAll();
        return $this->renderSuccess('', compact('accessList'));
    }
    /**
     * 新增get数据
     */
    public function addInfo()
    {
        $menu = (new AccessModel())->getList();
        return $this->renderSuccess('', compact('menu'));
    }
    /**
     * 添加到分类
     */
    public function add()
    {
        if($this->request->isGet()){
            //查找所有插件
            $accessList = ApplicationModel::getAllPlus();
            return $this->renderSuccess('', compact('accessList'));
        }
        $model = new ApplicationModel;
        // 新增记录
        if ($model->addApplication($this->postData())) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError('添加失败');
    }
 
    /**
     * 添加类别
     */
    public function addcategory()
    {
        $data = $this->postData();
        $model = new ModelApplication_category;
         
        if(isset($data['id'])){
            $model = $model->detail($data['id']);
            // 编辑记录
            if ($model->edit(['category_name'=>$data['category_name']])) {
                return $this->renderSuccess('编辑成功');
            }
        }else{
            // 新增记录
            if ($model->add($data)) {
                return $this->renderSuccess('添加成功');
            }
        }
        return $this->renderError('添加失败');
    }
 
    /**
     * 添加应用
     */
    public function addapplication()
    {
        if($this->request->isGet()){
            return $this->addInfo();
        }
        $data = json_decode($this->postData()['params'], true);
        $model = new ApplicationModel;
         
        // 新增记录
        if ($model->add($data)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError('添加失败');
    }
 
    /**
     * 编辑
     */
    public function edit($id)
    {
        if($this->request->isGet()){
            return $this->editInfo($id);
        }
        $data = json_decode($this->postData()['params'], true);
        
        if (isset($data['access_id']) && count($data['access_id']) == 0) {
            return $this->renderError('请选择权限');
        }
        $model = ApplicationModel::detail($data['id']);
 
        // 更新记录
        if ($model->edit($data)) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError('更新失败');
    }
    /**
     * 修改get数据
     */
    public function editInfo($id)
    {
        $menu = (new AccessModel())->getList();
        $model = ApplicationModel::detail($id);
        $select_menu = array_column($model->toArray()['access'], 'access_id');
        $model['access_id']=$select_menu;
        return $this->renderSuccess('', compact('model', 'menu', 'select_menu'));
    }
    /**
     * 删除
     */
    public function delete($id)
    {
        // 删除--软
        $model = ApplicationModel::detail($id);
        if (!$model->setDelete()) {
            return $this->renderError('操作失败');
        }
        return $this->renderSuccess('操作成功');
    }
    
    /**
     * 删除---分类
     */
    public function del_category()
    {
        $data = $this->postData();
        $model = ModelApplication_category::detail($data['id']);
        // 删除--软
        if ($model->setDelete()) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError('删除失败');
    }
    //清空应用分类
    public function deleteplugs_category(){
        $data = $this->postData();
        $model = ApplicationModel::detail($data['id']);
        // 删除--软
        if ($model->delete_category()) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError('删除失败');
    }
}