init: 项目初始代码
This commit is contained in:
196
app/api/controller/v1/Navigator.php
Normal file
196
app/api/controller/v1/Navigator.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Navigator as NavigatorModel;
|
||||
use app\api\validate\Navigator as NavigatorValidate;
|
||||
|
||||
class Navigator extends Base
|
||||
{
|
||||
//管理员模型
|
||||
protected $model = null;
|
||||
//后台管理员控制器
|
||||
protected $validate = null;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new NavigatorValidate();
|
||||
$this->model = new NavigatorModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
if ($result['pid'] != 0) {
|
||||
$pidName = $this->model->where('id',$result['pid'])->find()->toArray();
|
||||
$result['pid_name'] = $pidName['name'];
|
||||
} else {
|
||||
$result['pid_name'] = '';
|
||||
}
|
||||
$result['language_id'] = $result['site_id'];
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表树
|
||||
*/
|
||||
public function tree():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != '' && $inputData['language_id'] != 0) {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
$this->order['sort'] = 'desc';
|
||||
|
||||
$list = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
$tree = list_to_tree($list);
|
||||
return $this->msg(200, '获取列表成功', $tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 顶级列表树
|
||||
*/
|
||||
public function topTree():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != '' && $inputData['language_id'] != 0) {
|
||||
$this->focus['site_id'] = $inputData['language_id'];
|
||||
//$this->focus['pid'] = 0;
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
$list = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
//echo "<pre>=="; print_r($list);
|
||||
//去除自己的顶级
|
||||
if (isset($inputData['id']) && $inputData['id'] != '') {
|
||||
//查找当前分类是否有子类。
|
||||
$nav = $this->model->find($inputData['id']);
|
||||
$hasSon = $this->model->where('pid',$inputData['id'])->find();
|
||||
|
||||
if($hasSon) {
|
||||
$tree = [];
|
||||
}
|
||||
else{
|
||||
foreach ($list as $key => $item) {
|
||||
if ($inputData['id'] == $item['id']){
|
||||
unset($list[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$tree = list_to_tree($list);
|
||||
}
|
||||
|
||||
/*if ($nav) {
|
||||
if (!empty($son)) {
|
||||
$tree = [];
|
||||
} else {
|
||||
foreach ($list as $key => $item) {
|
||||
if ($inputData['id'] == $item['id']){
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
$tree = list_to_tree($list);
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
/*foreach ($list as $key => $item) {
|
||||
if ($inputData['id'] == $item['id']){
|
||||
unset($list[$key]);
|
||||
}
|
||||
}*/
|
||||
|
||||
$tree = list_to_tree($list);
|
||||
|
||||
}
|
||||
//echo "<pre>---"; print_r($tree);
|
||||
return $this->msg(200, '获取列表成功', $tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改是否是顶部状态
|
||||
*/
|
||||
public function changeStatus():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$inputData['site_id'] = $inputData['language_id'];
|
||||
}
|
||||
if (isset($inputData['language_id'])) {
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
if (isset($inputData['is_foot']) && $inputData['is_foot'] == '') {
|
||||
unset($inputData['is_foot']);
|
||||
}
|
||||
|
||||
if (isset($inputData['is_top']) && $inputData['is_top'] == '') {
|
||||
unset($inputData['is_top']);
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//不能都提交为空
|
||||
if (count($inputData) < 3) {
|
||||
return $this->msg(504,"参数错误");
|
||||
}
|
||||
|
||||
$result = $this->model->changeStatus($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"操作成功");
|
||||
} else {
|
||||
return $this->msg(504,"操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//查找是否有子类。
|
||||
$hasData = $this->model->getNavigatorIsInUse($inputData);
|
||||
if (!$hasData) {
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
} else {
|
||||
return $this->msg(504,"该导航下有子分类,不能删除");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user