| | |
| | | } |
| | | |
| | | /** |
| | | * 所有分类 |
| | | */ |
| | | public static function getCategoryALL() |
| | | { |
| | | $model = new static; |
| | | if (!Cache::get('category_all_' . $model::$app_id)) { |
| | | $data = $model->with(['images'])->order(['sort' => 'asc', 'create_time' => 'asc'])->select(); |
| | | $all = !empty($data) ? $data->toArray() : []; |
| | | $tree = []; |
| | | foreach ($all as $first) { |
| | | if ($first['parent_id'] != 0) continue; |
| | | $twoTree = []; |
| | | foreach ($all as $two) { |
| | | if ($two['parent_id'] != $first['category_id']) continue; |
| | | $threeTree = []; |
| | | foreach ($all as $three) |
| | | $three['parent_id'] == $two['category_id'] |
| | | && $threeTree[$three['category_id']] = $three; |
| | | !empty($threeTree) && $two['child'] = $threeTree; |
| | | array_push($twoTree, $two); |
| | | } |
| | | if (!empty($twoTree)) { |
| | | $temp_two_tree = array_column($twoTree, 'sort'); |
| | | array_multisort($temp_two_tree, SORT_ASC, $twoTree); |
| | | $first['child'] = $twoTree; |
| | | } |
| | | array_push($tree, $first); |
| | | } |
| | | Cache::tag('cache')->set('category_all_' . $model::$app_id, compact('all', 'tree')); |
| | | } |
| | | return Cache::get('category_all_' . $model::$app_id); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有分类 |
| | | */ |
| | | public static function getCacheAll() |