1 line
2.9 KiB
PHP
1 line
2.9 KiB
PHP
<?php
|
|
namespace app\store\controller\food\applet;
|
|
|
|
use app\store\controller\food\Controller;
|
|
use app\store\model\food\Setting as SettingModel;
|
|
use think\facade\View;
|
|
|
|
/**
|
|
* 用户中心控制器
|
|
*/
|
|
class Center extends Controller
|
|
|
|
{
|
|
/**
|
|
* 用户中心
|
|
*/
|
|
public function index()
|
|
{
|
|
$model = SettingModel::getItem('center');
|
|
if (!$this->request->isAjax()) {
|
|
return View::fetch('index', compact('model'));
|
|
}
|
|
$data = $this->postData('data');
|
|
$data['menu'] = $model['menu'];
|
|
$model = new SettingModel;
|
|
if($model->edit('center', $data)) {
|
|
return $this->renderSuccess('更新成功');
|
|
}
|
|
$error = $model->getError() ?: '添加失败';
|
|
return $this->renderError($error);
|
|
}
|
|
|
|
/**
|
|
* 添加
|
|
*/
|
|
public function add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$post_data = $this->postData('data');
|
|
if(!isset($post_data['logo']) or empty($post_data['logo'])){
|
|
return $this->renderError('请选择菜单图标');
|
|
}
|
|
$data = SettingModel::getItem('center');
|
|
array_unshift($data['menu'],$post_data);
|
|
$model = new SettingModel;
|
|
if ($model->edit('center',$data)) {
|
|
return $this->renderSuccess('添加成功', url('food.applet.center/index'));
|
|
}
|
|
$error = $model->getError() ?: '添加失败';
|
|
return $this->renderError($error);
|
|
}
|
|
return redirect(url('food.applet.center/index'));
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
*/
|
|
public function edit($index)
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$post_data = $this->postData('data');
|
|
if(!isset($post_data['logo']) or empty($post_data['logo'])){
|
|
return $this->renderError('请选择菜单图标');
|
|
}
|
|
$data = SettingModel::getItem('center');
|
|
$data['menu'][$index] = $post_data;
|
|
$model = new SettingModel;
|
|
if ($model->edit('center',$data)) {
|
|
return $this->renderSuccess('编辑成功', url('food.applet.center/index'));
|
|
}
|
|
$error = $model->getError() ?: '编辑失败';
|
|
return $this->renderError($error);
|
|
}
|
|
return redirect(url('food.applet.center/index'));
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
public function delete($id)
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$data = SettingModel::getItem('center');
|
|
array_splice($data['menu'],$id,1);
|
|
$model = new SettingModel;
|
|
if ($model->edit('center',$data)) {
|
|
return $this->renderSuccess('删除成功', url('food.applet.center/index'));
|
|
}
|
|
$error = $model->getError() ?: '删除失败';
|
|
return $this->renderError($error);
|
|
}
|
|
return redirect(url('food.applet.center/index'));
|
|
}
|
|
|
|
|
|
|
|
} |