You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
821 B
PHP
44 lines
821 B
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
use think\Model;
|
|
class Cate extends Model
|
|
{
|
|
protected static function init()
|
|
{
|
|
Cate::event('before_delete',function(){
|
|
dump(111);die;
|
|
return false;
|
|
});
|
|
}
|
|
public function catetree(){
|
|
$cateres=$this->order('sort desc')->select();
|
|
return $this->sort($cateres);
|
|
}
|
|
public function sort($data,$pid=0,$level=0){
|
|
static $arr=array();
|
|
foreach ($data as $k =>$v) {
|
|
if($v['pid']==$pid){
|
|
$v['level']=$level;
|
|
$arr[]=$v;
|
|
$this->sort($data,$v['id'],$level+1);
|
|
}
|
|
}
|
|
return $arr;
|
|
}
|
|
public function getchilrenid($cateid){
|
|
$cateres=$this->select();
|
|
return $this->_getchilrenid($cateres,$cateid);
|
|
}
|
|
public function _getchilrenid($cateres,$cateid){
|
|
static $arr=array();
|
|
foreach ($cateres as $k =>$v) {
|
|
if($v['pid'] == $cateid){
|
|
$arr[]=$v['id'];
|
|
$this->_getchilrenid($cateres,$v['id']);
|
|
}
|
|
}
|
|
return $arr;
|
|
}
|
|
}
|
|
?>
|