123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Modules\Book\Services;
- use App\Modules\Book\Models\BookCategory;
- use App\Modules\Book\Models\Book;
- class BookCategoryService
- {
- public static function getSecondCategories($id_arr=[]){
- return BookCategory::getSecondCategories($id_arr);
- }
-
- public static function getCategory($all=false){
- if($all){
- $res = BookCategory::getSecondCategories();
- }else{
- $res = BookCategory::getSecondCategories(Book::getCategoryId());
- }
- $male = [];
- $female = [];
- foreach ($res as $v){
- if($v->channel_name == '男频'){
- $male[] = ['id'=>$v->id,'name'=>$v->category_name];
- }
- if($v->channel_name == '女频'){
- $female[] = ['id'=>$v->id,'name'=>$v->category_name];
- }
- }
- $data = [
- ['id'=>1,'name'=>'男频','children'=>$male],
- ['id'=>2,'name'=>'女频','children'=>$female],
- ];
- return $data;
- }
- }
|