Browse Source

fix bug

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

15
class/Api.php

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

5
controller/api.php

@ -54,7 +54,8 @@ function add_category($api){
function edit_category($api){ function edit_category($api){
//获取ID //获取ID
$id = intval($_POST['id']); $id = intval($_POST['id']);
//获取父级ID
$fid = intval($_POST['fid']);
//获取token //获取token
$token = $_POST['token']; $token = $_POST['token'];
//获取分类名称 //获取分类名称
@ -69,7 +70,7 @@ function edit_category($api){
$description = htmlspecialchars($description); $description = htmlspecialchars($description);
//字体图标 //字体图标
$font_icon = htmlspecialchars($_POST['font_icon'],ENT_QUOTES); $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