3) { return; } if (is_array($where)) { $where = array_merge(['stat' => 0], $where); } if ($where) { $this->where($where); } if ($order) { $this->order($order); } if ($field) { $this->field($field); } if (empty($limit)) { $limit = Config::get('list_rows'); $limit = $limit? : 12; } if ($limit) { $this->limit($limit); } $list = $this->select(); if ($list) { foreach ($list as $k => $row) { $row['level'] = $level; $alldata[] = $row; $where['pid'] = $row['id']; self::getSinglepageLists($where, $order, $field, $limit, $level + 1, $alldata); } } return $alldata; } public function getChildIDArray($id) { $list = $this->where(['pid' => $id])->field('id')->select(); $childIDArray = array((int) $id); if ($list) { foreach ($list as $val) { $childArray = self::getChildIDArray($val['id']); $childIDArray = array_merge($childIDArray, $childArray); } } return $childIDArray; } public function getTopParentID($id, $where = null) { $data = $this::get(function($query)use($id, $where) { $query->where(['id' => $id]); if ($where) { $query->where($where); } $query->field(['id', 'pid']); }); if (isset($data['pid']) && $data['pid']) { $topid = self::getTopParentID($data['pid'], $where); } else { $topid = $id; } return $topid; } public function getBreadCrumb($id, $where = null, array &$catarr = array()) { if (!$id) { return array(); } if (is_array($where)) { $where = array_merge(['stat' => ['eq', '0']], $where); } if ($where) { $this->where($where); } $data = $this->field(['id', 'name', 'pid'])->get($id); $catarr[] = $data; if (isset($data['pid']) && $data['pid']) { self::getBreadCrumb($data['pid'], $where, $catarr); } else { return array_reverse($catarr); } return $catarr; } public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = 20) { $options = ''; if ($where) { $this->where($where); } if ($order) { $this->order($order); } if ($field) { $this->field($field); } if ($limit) { $this->limit($limit); } $list = $this->select(); if ($list) { foreach ($list as $k => $row) { if ($row['id'] == $id) { $options.='' . "\n"; } else { $options.='' . "\n"; } } } return $options; } public function getOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) { $options = ''; if ($where) { $this->where($where); } if ($order) { $this->order($order); } if ($field) { $this->field($field); } if (empty($limit)) { $limit = Config::get('list_rows'); } if ($limit) { $this->limit($limit); } $list = $this->select(); if ($list) { foreach ($list as $k => $row) { if ($row['id'] == $id) { $options.='' . "\n"; } else { $options.='' . "\n"; } $where['pid'] = $row['id']; $options.=self::getOptions($id, $where, $order, $field, $limit, $level + 1); } } return $options; } }