| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- declare (strict_types = 1);
- namespace app\model\api;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class StoreCategory extends Model
- {
- protected $name = 'store_category';
- /**
- * 获取分类列表
- * @param array $where
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getList($where = [], $page = 1, $pageSize = 20)
- {
- $query = $this->where($where);
- $totalCount = $query->count();
- $list = $query
- ->order('sort', 'desc')
- ->order('id', 'desc')
- ->page($page, $pageSize)
- ->select()
- ->toArray();
- return [
- 'list' => $list,
- 'totalCount' => $totalCount,
- 'pageSize' => $pageSize,
- 'page' => $page
- ];
- }
- /**
- * 获取树形分类
- * @param int $pid
- * @return array
- */
- public function getTree($pid = 0)
- {
- $list = $this->where('pid', $pid)->order('sort', 'desc')->select()->toArray();
- foreach ($list as &$item) {
- $children = $this->getTree($item['id']);
- if (!empty($children)) {
- $item['children'] = $children;
- }
- }
- return $list;
- }
- }
|