Просмотр исходного кода

Merge pull request #2014 from visuddhinanda/laravel

🚧 支持series参数
visuddhinanda 2 лет назад
Родитель
Сommit
2c8f29098b
2 измененных файлов с 49 добавлено и 29 удалено
  1. 14 7
      app/Console/Commands/UpgradePaliText.php
  2. 35 22
      app/Http/Controllers/PaliTextController.php

+ 14 - 7
app/Console/Commands/UpgradePaliText.php

@@ -15,7 +15,7 @@ class UpgradePaliText extends Command
 {
 {
     /**
     /**
      * The name and signature of the console command.
      * The name and signature of the console command.
-     *
+     * php artisan upgrade:palitext 168
      * @var string
      * @var string
      */
      */
     protected $signature = 'upgrade:palitext {from?} {to?}';
     protected $signature = 'upgrade:palitext {from?} {to?}';
@@ -205,19 +205,26 @@ class UpgradePaliText extends Command
                     $currParent = $title_data[$currParent-1]["parent"];
                     $currParent = $title_data[$currParent-1]["parent"];
                     $iLoop++;
                     $iLoop++;
                 }
                 }
+
+                //插入书名
                 if(count($path)>0){
                 if(count($path)>0){
-                    //插入书名
-                    $pcd_book = BookTitle::where('book',$book)
-                                        ->where('paragraph',end($path)['paragraph'])
-                                        ->first();
+                    $bookPara = end($path)['paragraph'];
+                }else{
+                    $bookPara = $paragraph;
+                }
+
+                $pcd_book = BookTitle::where('book',$book)
+                                    ->where('paragraph',$bookPara)
+                                    ->first();
+                if($pcd_book){
                     if(empty($pcd_book)){
                     if(empty($pcd_book)){
-                        Log::error('no pcd book:'.$book.'-'.end($path)['paragraph']);
+                        Log::error('no pcd book:'.$book.'-'.$bookPara);
                     }
                     }
-                    $path[] = ["book"=>0,"paragraph"=>0,"title"=>$pcd_book->title,"level"=>0];
                     $book_id = $pcd_book->sn;
                     $book_id = $pcd_book->sn;
                     if(!empty($book_id)){
                     if(!empty($book_id)){
                         $newData['pcd_book_id'] = $book_id;
                         $newData['pcd_book_id'] = $book_id;
                     }
                     }
+                    $path[] = ["book"=>$book_id,"paragraph"=>$book_id,"title"=>$pcd_book->title,"level"=>0];
                 }
                 }
 
 
                 # 将路径反向
                 # 将路径反向

+ 35 - 22
app/Http/Controllers/PaliTextController.php

@@ -156,30 +156,43 @@ class PaliTextController extends Controller
                  * 4. 获取全部书的目录
                  * 4. 获取全部书的目录
                  */
                  */
 
 
-                $path = PaliText::where('book',$request->get('book'))
-                                ->where('paragraph',$request->get('para'))
-                                ->select('path')->first();
-                if(!$path){
-                    return $this->error("no data");
-                }
-                $json = \json_decode($path->path);
-                $root = null;
-                foreach ($json as $key => $value) {
-                    # code...
-                    if( $value->level == 1 ){
-                        $root = $value;
-                        break;
+                if($request->has('series')){
+                    $book_title = $request->get('series');
+                    //获取丛书书目列表
+                    $books = BookTitle::where('title',$request->get('series'))->get();
+                }else{
+                    //查询这个目录的顶级目录
+                    $path = PaliText::where('book',$request->get('book'))
+                                    ->where('paragraph',$request->get('para'))
+                                    ->select('path')->first();
+                    if(!$path){
+                        return $this->error("no data");
                     }
                     }
+                    $json = \json_decode($path->path);
+                    $root = null;
+                    foreach ($json as $key => $value) {
+                        # code...
+                        if( $value->level == 1 ){
+                            $root = $value;
+                            break;
+                        }
+                    }
+                    if($root===null){
+                        return $this->error("no data");
+                    }
+                    //查询书起始段落
+                    $rootPara = PaliText::where('book',$root->book)
+                                    ->where('paragraph',$root->paragraph)
+                                    ->first();
+                    //获取丛书书名
+                    $book_title = BookTitle::where('book',$rootPara->book)
+                                            ->where('paragraph',$rootPara->paragraph)
+                                            ->value('title');
+                    //获取丛书书目列表
+                    $books = BookTitle::where('title',$book_title)->get();
                 }
                 }
-                if($root===null){
-                    return $this->error("no data");
-                }
-                //查询书起始段落
-                $rootPara = PaliText::where('book',$root->book)
-                                ->where('paragraph',$root->paragraph)
-                                ->first();
-                $book_title = BookTitle::where('book',$rootPara->book)->where('paragraph',$rootPara->paragraph)->value('title');
-                $books = BookTitle::where('title',$book_title)->get();
+
+
                 $chapters = [];
                 $chapters = [];
                 $chapters[] = ['book'=>0,'paragraph'=>0,'toc'=>$book_title,'level'=>1];
                 $chapters[] = ['book'=>0,'paragraph'=>0,'toc'=>$book_title,'level'=>1];
                 foreach ($books as  $book) {
                 foreach ($books as  $book) {