Browse Source

fix bug

pull/61/head
xiaoz 3 years ago
parent
commit
2add44c175
  1. 13
      class/Api.php
  2. 5
      controller/api.php

13
class/Api.php

@ -52,7 +52,7 @@ class Api { @@ -52,7 +52,7 @@ class Api {
* 修改分类目录
*
*/
public function edit_category($token,$id,$name,$property = 0,$weight = 0,$description = '',$font_icon = ''){
public function edit_category($token,$id,$name,$property = 0,$weight = 0,$description = '',$font_icon = '',$fid = 0){
$this->auth($token);
//如果id为空
if( empty($id) ){
@ -62,15 +62,24 @@ class Api { @@ -62,15 +62,24 @@ class Api {
elseif( empty($name ) ){
$this->err_msg(-1004,'The category name cannot be empty!');
}
//更新数据库
else{
//根据分类ID查询改分类下面是否已经存在子分类,如果存在子分类了则不允许设置为子分类,实用情况:一级分类下存在二级分类,无法再将改一级分类修改为二级分类
$count = $this->db->count("on_categorys", [
"fid" => $id
]);
if( $count > 0 ) {
$this->err_msg(-2000,'修改失败,该分类下已存在子分类!');
}
$data = [
'name' => htmlspecialchars($name,ENT_QUOTES),
'up_time' => time(),
'weight' => $weight,
'property' => $property,
'description' => htmlspecialchars($description,ENT_QUOTES),
'font_icon' => $font_icon
'font_icon' => $font_icon,
'fid' => $fid
];
$re = $this->db->update('on_categorys',$data,[ 'id' => $id]);
//var_dump( $this->db->log() );

5
controller/api.php

@ -54,7 +54,8 @@ function add_category($api){ @@ -54,7 +54,8 @@ function add_category($api){
function edit_category($api){
//获取ID
$id = intval($_POST['id']);
//获取父级ID
$fid = intval($_POST['fid']);
//获取token
$token = $_POST['token'];
//获取分类名称
@ -69,7 +70,7 @@ function edit_category($api){ @@ -69,7 +70,7 @@ function edit_category($api){
$description = htmlspecialchars($description);
//字体图标
$font_icon = htmlspecialchars($_POST['font_icon'],ENT_QUOTES);
$api->edit_category($token,$id,$name,$property,$weight,$description,$font_icon);
$api->edit_category($token,$id,$name,$property,$weight,$description,$font_icon,$fid);
}
/**
* 删除分类目录

Loading…
Cancel
Save