📖 File Reader
<?php
namespace app\api\model;
use think\Model;
class ModGoodsAct extends Model
{
protected $name = 'goods_act';//表名
/**
* 获取该分类下所有子分类
* @param $parent_id 分类id
* @param $type 类型:1包含当前id、0不包含
*/
static function sublevel_act_id($parent_id,$type=0)
{
$act_id = '';
if ($type == 1){
$act_id = $parent_id.',';
}
while ($parent_id){
$list = ModGoodsAct::where("parent_id in ($parent_id) and is_show = 1")->order("sort desc")->field("id,name")->select();
$id = '';
foreach ($list as $k => $v){
$id .= $v["id"].',';
}
$id = substr($id,0,strlen($id)-1);
if (!empty($id)){
$act_id .= $id.',';
}
$parent_id = $id;
}
return substr($act_id,0,strlen($act_id)-1);
}
}