李帅

init

<?php
namespace App\Admin\Controllers;
use App\Admin\Repositories\PickPoetryVerse;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
class PickPoetryVerseController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new PickPoetryVerse(), function (Grid $grid) {
$grid->column('id')->sortable();
$grid->column('pick_id');
$grid->column('verse_id');
$grid->column('created_at');
$grid->column('updated_at')->sortable();
$grid->filter(function (Grid\Filter $filter) {
$filter->equal('id');
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new PickPoetryVerse(), function (Show $show) {
$show->field('id');
$show->field('pick_id');
$show->field('verse_id');
$show->field('created_at');
$show->field('updated_at');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new PickPoetryVerse(), function (Form $form) {
$form->display('id');
$form->text('pick_id');
$form->text('verse_id');
$form->display('created_at');
$form->display('updated_at');
});
}
}
<?php
namespace App\Console\Commands;
use App\Models\Author;
use App\Models\Poetry;
use App\Models\Verse;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class ImportPoemDataToMysql extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:poem';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @throws
* @return int
*/
public function handle()
{
Author::query()->truncate();
Poetry::query()->truncate();
Verse::query()->truncate();
// 写入楚辞
$this->createChuCiData();
// 写入诗经
$this->createShiJingData();
// 宋词
$this->createSongCiData();
// 唐诗
$this->createTangShiData();
return 0;
}
public function createChuCiData()
{
try{
$chuci = json_decode(Storage::disk('public')->get('PoemData/chuci.json'),true);
$author = new Author;
$author->name = '屈原';
$author->dynasty = '春秋战国';
$author->introduce = '屈原是属于春秋战国时期楚国的人,芈姓,屈氏,名平,字原,又自云名正则,字灵均,战国时期楚国诗人、政治家,是中国历史上一位伟大的爱国诗人,中国浪漫主义文学的奠基人,“楚辞”的创立者和代表作家,开辟了“香草美人”的传统,被誉为“楚辞之祖”。';
$author->save();
$author = new Author;
$author->name = '宋玉';
$author->dynasty = '战国';
$author->introduce = '宋玉(公元前298年—公元前222年),楚国诗人,宋国公族后裔,生于楚国,曾事楚顷襄王,为楚国士大夫。战国著名辞赋家,宋玉与唐勒,景差齐名,传世作品有《九辩》等。所谓“下里巴人”、“阳春白雪”、“曲高和寡”便说的是他,典故皆他而来。始皇帝二十五年己卯,公元前222年因病去世享年七十六岁。';
$author->save();
$author = new Author;
$author->name = '景差';
$author->dynasty = '战国';
$author->introduce = '景差[cuō](前290年—前223年),芈姓,景氏,名差,战国时期楚国辞赋家。后于屈原,与宋玉、唐勒同时以赋见称,主要作品有楚辞《大招》。';
$author->save();
$author = new Author;
$author->name = '贾谊';
$author->dynasty = '战国';
$author->introduce = '贾谊(公元前200年~公元前168年),汉族,洛阳(今河南省洛阳市)人,西汉初年著名政论家、文学家,世称贾生。贾谊少有才名,十八岁时,以善文为郡人所称。文帝时任博士,迁太中大夫,受大臣周勃、灌婴排挤,谪为长沙王太傅,故后世亦称贾长沙、贾太傅。三年后被召回长安,为梁怀王太傅。梁怀王坠马而死,贾谊深自歉疚,抑郁而亡,时仅三十三岁。司马迁对屈原、贾谊都寄予同情,为二人写了一篇合传,后世因而往往把贾谊与屈原并称为“屈贾”。';
$author->save();
$author = new Author;
$author->name = '淮南小山';
$author->dynasty = '西汉';
$author->introduce = '淮南小山是西汉淮南王刘安的一部分门客的共称。今仅存辞赋《招隐士》 1篇。《汉书·艺文志》著录“淮南王群臣赋四十四篇”,《招隐士》当是其中仅存的1篇。此篇始见于东汉王逸的《楚辞章句》,题为淮南小山作,然而萧统《文选》则题刘安作。关于文章写作的背景,说法也不一。王逸说是小山之徒“闵伤屈原”之作,王夫之《楚辞通释》说是淮南小山“为淮南王召致山谷潜伏之士”而作,而不少研究者则以为是淮南小山思念淮南王的作品。';
$author->save();
$author = new Author;
$author->name = '东方朔';
$author->dynasty = '西汉';
$author->introduce = '东方朔(约前161年—前93年?),字曼倩,平原郡厌次县人,西汉时期著名文学家。';
$author->save();
$author = new Author;
$author->name = '庄忌';
$author->dynasty = '西汉';
$author->introduce = '庄忌(约前188-前105)西汉辞赋家。会稽吴(今苏州吴县)人。因避汉明帝刘庄讳改名严忌,与邹阳、枚乘等唱和,是梁孝王门下著名辞赋家。作品仅存《哀时命》一篇。 此赋感叹屈原生不逢时,空怀壮志而不得伸。是咏屈赋中的佳品。此赋纯属骚体,保持了由贾谊开创的西汉早期骚赋所具有的特点。感情真挚,篇幅短小精悍,是咏屈赋中的佳品。';
$author->save();
$author = new Author;
$author->name = '王褒';
$author->dynasty = '西汉';
$author->introduce = '王褒(前90年—前51年),字子渊,别号桐柏真人,蜀郡资中(今四川省资阳市雁江区昆仑乡墨池坝村)人。西汉时期辞赋家,与扬雄并称“渊云”。';
$author->save();
$author = new Author;
$author->name = '刘向';
$author->dynasty = '西汉';
$author->introduce = '刘向(公元前77年~公元前6年),原名刘更生,字子政,沛郡丰邑(今江苏省徐州市)人。汉朝宗室大臣、文学家,楚元王刘交(汉高祖刘邦异母弟)之玄孙,阳城侯刘德之子,经学家刘歆之父,中国目录学鼻祖。';
$author->save();
$author = new Author;
$author->name = '王逸';
$author->dynasty = '东汉';
$author->introduce = '王逸,字叔师,生卒年不详,南郡宜城(今湖北省襄阳市宜城县)人,东汉著名文学家。官至豫州刺史、豫章太守。所作《楚辞章句》,是《楚辞》中最早的完整注本,颇为后世楚辞学者所重。又作有赋、诔、书、论等21篇,及《汉诗》123篇,今多散佚,仅存《九思》,为哀悼屈原而作。明人辑有《王叔师集》';
$author->save();
foreach ($chuci as $item) {
$author = Author::query()->where('name',$item['author'])->first();
$poetry = new Poetry();
$poetry->name = $item['title'];
$poetry->subname = $item['section'];
$poetry->author_id = $author->id;
$poetry->save();
foreach ($item['content'] as $value) {
$verse = new Verse();
$verse->poetry_id = $poetry->id;
$verse->stanza = $value;
$verse->annotate = '';
$verse->en = '';
$verse->save();
}
}
}catch (\Exception $exception){
dd($exception->getMessage() . 'Line:' . $exception->getLine());
}
return true;
}
public function createShiJingData()
{
try{
DB::beginTransaction();
$author = new Author;
$author->name = '不详';
$author->dynasty = '西周至春秋';
$author->introduce = '《诗经》的作者佚名,绝大部分已经无法考证,传为尹吉甫采集、孔子编订。《诗经》在先秦时期称为《诗》,或取其整数称《诗三百》。';
$author->save();
$shijing = json_decode(Storage::disk('public')->get('PoemData/shijing.json'),true);
foreach ($shijing as $item) {
$poetry = new Poetry();
$poetry->name = $item['title'];
$poetry->subname = $item['section'];
$poetry->alias = $item['chapter'];
$poetry->author_id = $author->id;
$poetry->save();
foreach ($item['content'] as $value) {
$verse = new Verse();
$verse->poetry_id = $poetry->id;
$verse->stanza = $value;
$verse->annotate = '';
$verse->en = '';
$verse->save();
}
}
DB::commit();
}catch (\Exception $exception){
DB::rollBack();
dd($exception->getMessage() . 'Line:' . $exception->getLine());
}
return true;
}
public function createSongCiData()
{
try{
$songauthor = json_decode(Storage::disk('public')->get('PoemData/author.song.json'),true);
foreach ($songauthor as $item) {
$author = new Author();
$author->name = $item['name'];
$author->introduce = $item['description'];
$author->save();
}
$songci = json_decode(Storage::disk('public')->get('PoemData/songci.json'),true);
foreach ($songci as $item) {
$author = Author::query()->where('name',$item['author'])->first();
$poetry = new Poetry();
$poetry->name = $item['rhythmic'];
$poetry->author_id = $author->id;
$poetry->save();
foreach ($item['paragraphs'] as $value) {
$verse = new Verse();
$verse->poetry_id = $poetry->id;
$verse->stanza = $value;
$verse->annotate = '';
$verse->en = '';
$verse->save();
}
}
}catch (\Exception $exception){
dd($exception->getMessage() . ' Line:' . $exception->getLine() . ' name:' . $item['rhythmic']);
}
}
public function createTangShiData()
{
try{
$tangauthor = json_decode(Storage::disk('public')->get('PoemData/authors.tang.json'),true);
foreach ($tangauthor as $item) {
$author = new Author();
$author->name = $item['name'];
$author->introduce = $item['desc'];
$author->save();
}
$tangshi = json_decode(Storage::disk('public')->get('PoemData/tangshi.json'),true);
foreach ($tangshi as $item) {
$author = Author::query()->where('name',$item['author'])->first();
$poetry = new Poetry();
$poetry->name = $item['title'];
$poetry->author_id = $author->id;
$poetry->save();
foreach ($item['paragraphs'] as $value) {
$verse = new Verse();
$verse->poetry_id = $poetry->id;
$verse->stanza = $value;
$verse->annotate = '';
$verse->en = '';
$verse->save();
}
}
}catch (\Exception $exception){
dd($exception->getMessage() . ' Line:' . $exception->getLine() . ' name:' . $item['title']);
}
}
}
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
class PickPoetryVerse extends Model
{
use HasDateTimeFormatter;
protected $table = 'pick_poetry_verse';
}
......@@ -15,7 +15,7 @@ class CreatePoetryTable extends Migration
{
Schema::create('poetry', function (Blueprint $table) {
$table->increments('id');
$table->foreignId('author_id')->constrained('author','id');
$table->unsignedBigInteger('author_id')->index()->comment('作者id');
$table->string('name')->default('')->comment('题目');
$table->string('subname')->default('')->comment('小标题');
$table->string('alias')->default('')->comment('别名');
......
......@@ -15,7 +15,7 @@ class CreateVerseTable extends Migration
{
Schema::create('verse', function (Blueprint $table) {
$table->increments('id');
$table->foreignId('poetry_id')->constrained('poetry','id');
$table->unsignedBigInteger('poetry_id')->index()->comment('诗词id');
$table->string('stanza')->default('')->comment('诗节');
$table->text('annotate')->comment('注解');
$table->string('spelling')->default('')->comment('拼音');
......
......@@ -15,8 +15,8 @@ class CreatePoetryTagTable extends Migration
{
Schema::create('poetry_tag', function (Blueprint $table) {
$table->increments('id');
$table->foreignId('poetry_id')->constrained('poetry','id');
$table->foreignId('tag_id')->constrained('tags','id');
$table->unsignedBigInteger('poetry_id')->index()->comment('诗词id');
$table->unsignedBigInteger('tag_id')->index()->comment('标签id');
});
}
......
......@@ -17,9 +17,9 @@ class CreatePickPoetryTable extends Migration
$table->increments('id');
$table->string('title')->default('')->comment('标题');
$table->string('subtitle')->default('')->comment('副标题');
$table->string('left_tag_id')->default('')->comment('左侧文本');
$table->string('right_tag_id')->default('')->comment('右侧文本');
$table->foreignId('poetry_id')->constrained('poetry','id');
$table->string('left_text')->default('')->comment('左侧文本');
$table->string('right_text')->default('')->comment('右侧文本');
$table->unsignedBigInteger('poetry_id')->index()->comment('诗词id');
$table->unsignedBigInteger('use_num')->comment('使用次数');
$table->unsignedTinyInteger('state')->comment('状态');
$table->timestamps();
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePickPoetryVerseTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pick_poetry_verse', function (Blueprint $table) {
$table->increments('id');
$table->unsignedBigInteger('pick_id')->index()->comment('官方秀id');
$table->unsignedBigInteger('verse_id')->index()->comment('诗句(节)id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pick_poetry_verse');
}
}
......@@ -18,8 +18,7 @@ class CreateUserShowTable extends Migration
$table->unsignedBigInteger('user_id')->comment('用户id');
$table->text('content')->comment('内容描述');
$table->unsignedTinyInteger('type')->comment('1=图文,2=视频');
// $table->unsignedBigInteger('pick_id')->comment('引用的官方秀id');
$table->foreignId('poetry_id')->constrained('pick_poetry','id');
$table->unsignedBigInteger('pick_id')->index()->comment('引用的秀id');
$table->integer('fav_num')->comment('收藏数');
$table->integer('view_num')->comment('观看数');
$table->integer('praise_num')->comment('点赞数');
......
......@@ -48,6 +48,8 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection tokenable_id
* @property Grid\Column|Collection abilities
* @property Grid\Column|Collection last_used_at
* @property Grid\Column|Collection poetry_id
* @property Grid\Column|Collection tag_id
* @property Grid\Column|Collection email_verified_at
*
* @method Grid\Column|Collection id(string $label = null)
......@@ -87,6 +89,8 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection tokenable_id(string $label = null)
* @method Grid\Column|Collection abilities(string $label = null)
* @method Grid\Column|Collection last_used_at(string $label = null)
* @method Grid\Column|Collection poetry_id(string $label = null)
* @method Grid\Column|Collection tag_id(string $label = null)
* @method Grid\Column|Collection email_verified_at(string $label = null)
*/
class Grid {}
......@@ -131,6 +135,8 @@ namespace Dcat\Admin {
* @property Show\Field|Collection tokenable_id
* @property Show\Field|Collection abilities
* @property Show\Field|Collection last_used_at
* @property Show\Field|Collection poetry_id
* @property Show\Field|Collection tag_id
* @property Show\Field|Collection email_verified_at
*
* @method Show\Field|Collection id(string $label = null)
......@@ -170,6 +176,8 @@ namespace Dcat\Admin {
* @method Show\Field|Collection tokenable_id(string $label = null)
* @method Show\Field|Collection abilities(string $label = null)
* @method Show\Field|Collection last_used_at(string $label = null)
* @method Show\Field|Collection poetry_id(string $label = null)
* @method Show\Field|Collection tag_id(string $label = null)
* @method Show\Field|Collection email_verified_at(string $label = null)
*/
class Show {}
......