quanwei
13 hours ago 408c463c5b66bba2aa1c81d8dca23e04c1608e24
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
 
namespace app\supplier\controller\supplier;
 
use app\common\enum\settings\SettingEnum;
use app\supplier\controller\Controller;
use app\supplier\model\supplier\page\Page as PageModel;
use app\supplier\model\settings\Setting as SettingModel;
 
/**
 * 供应商diy页面管理
 */
class Page extends Controller
{
    /**
     * 页面列表
     */
    public function list()
    {
        $model = new PageModel;
        $data = $this->postData();
        $data['shop_supplier_id'] = $this->getSupplierId();
        $list = $model->getList($data, 10);
        //查找默认
        $default = $model::getDefault($this->getSupplierId());
        return $this->renderSuccess('', compact('list', 'default'));
    }
 
    /**
     * 页面列表
     */
    public function index()
    {
        $model = new PageModel;
        $data = $this->postData();
        $data['shop_supplier_id'] = $this->getSupplierId();
        $list = $model->getList($data);
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 新增页面
     */
    public function add()
    {
        $model = new PageModel;
        if ($this->request->isGet()) {
            return $this->renderSuccess('', [
                'defaultData' => $model->getDefaultItems(),
                'jsonData' => ['page' => $model->getDefaultPage(), 'items' => []],
                'opts' => [
                    'catgory' => [],
                ]
            ]);
        }
        // 接收post数据
        $post = $this->postData();
        $params=json_decode($post['params'], true);
        $params['shop_supplier_id'] = $this->getSupplierId();
        if (!$model->add($params)) {
            return $this->renderError($model->getError() ?: '添加失败');
        }
        return $this->renderSuccess('添加成功');
    }
 
    /**
     * 首页编辑
     * @return \think\response\Json
     */
    public function home()
    {
        return $this->edit();
    }
    /**
     * 编辑页面
     */
    public function edit($page_id = null)
    {
        $model = $page_id > 0 ? PageModel::detail($page_id) : PageModel::getHomePage();
        if ($this->request->isGet()) {
            $jsonData = $model['page_data'];
            jsonRecursive($jsonData);
            return $this->renderSuccess('', [
                'defaultData' => $model->getDefaultItems(),
                'jsonData' => $jsonData,
                'opts' => [
                    'catgory' => [],
                ]
            ]);
        }
 
        // 接收post数据
        $post = $this->postData();
        $params=json_decode($post['params'], true);
        $params['shop_supplier_id'] = $this->getSupplierId();
        if (!$model->edit($params)) {
            return $this->renderError($model->getError() ?:'更新失败');
        }
        return $this->renderSuccess('更新成功');
    }
 
    /**
     * 删除页面
     */
    public function delete($page_id)
    {
        // 帮助详情
        $model = PageModel::detail($page_id);
        if (!$model->setDelete()) {
            return $this->renderError($model->getError() ?:'删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
 
    /**
     * 分类模板
     */
    public function category()
    {
        $model = PageCategoryModel::detail();
        if($this->request->isGet()){
            return $this->renderSuccess('', compact('model'));
        }
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
 
    /**
     * 新增页面
     */
    public function addPage()
    {
        $model = new PageModel;
        if ($this->request->isGet()) {
            return $this->renderSuccess('', [
                'defaultData' => $model->getDefaultItems(),
                'jsonData' => ['page' => $model->getDefaultPage(), 'items' => []],
                'opts' => [
                    'catgory' => [],
                ]
            ]);
        }
        // 接收post数据
        $post = $this->postData();
        $params=json_decode($post['params'], true);
        $params['shop_supplier_id'] = $this->getSupplierId();
        if (!$model->add($params, 10)) {
            return $this->renderError($model->getError() ?: '添加失败');
        }
        return $this->renderSuccess('添加成功');
    }
 
    /**
     * 编辑页面
     */
    public function editPage($page_id)
    {
        $model = PageModel::detail($page_id);
        if ($this->request->isGet()) {
            $jsonData = $model['page_data'];
            jsonRecursive($jsonData);
            return $this->renderSuccess('', [
                'defaultData' => $model->getDefaultItems(),
                'jsonData' => $jsonData,
                'opts' => [
                    'catgory' => [],
                ]
            ]);
        }
        // 接收post数据
        $post = $this->postData();
        $params=json_decode($post['params'], true);
        $params['shop_supplier_id'] = $this->getSupplierId();
        if (!$model->edit($params)) {
            return $this->renderError($model->getError() ?: '更新失败');
        }
        return $this->renderSuccess('更新成功');
    }
 
    /**
     * 删除页面
     */
    public function deletePage($page_id)
    {
        // 详情
        $model = PageModel::detail($page_id);
        if (!$model->setDelete()) {
            return $this->renderError($model->getError() ?: '删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
 
    /**
     * 设置默认
     */
    public function setPage($page_id)
    {
        // 页面详情
        $model = PageModel::detail($page_id);
        if (!$model->setDefault()) {
            return $this->renderError($model->getError() ?: '设置失败');
        }
        return $this->renderSuccess('设置成功');
    }
 
    /**
     * 商城设置
     */
    public function nav()
    {
        if($this->request->isGet()){
            $data = SettingModel::getItem('nav');
            return $this->renderSuccess('', compact('data'));
        }
        $model = new SettingModel;
        $data = $this->postData();
        if ($model->edit('nav', $data)) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    /**
     * 底部菜单
     */
    public function bottomnav()
    {
        $vars = SettingModel::getItem(SettingEnum::NAV.'_'.$this->getSupplierId());
        return $this->renderSuccess('', compact('vars'));
    }
 
    /**
     * 底部菜单设置
     */
    public function bottomedit()
    {
        $model = new SettingModel;
        $data = $this->postData();
        if ($model->edit(SettingEnum::NAV.'_'.$this->getSupplierId(), $data)) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    public function setHome($page_id) {
        //取消原来的首页
        PageModel::getHomePage()->setPageType(20);
        $model = PageModel::detail($page_id);
        if (!$model->setPageType(10)) {
            return $this->renderError($model->getError() ?:'设置失败');
        }
        return $this->renderSuccess('设置成功');
    }
}