李帅

init

1 +<?php
2 +
3 +namespace App\Admin\Controllers;
4 +
5 +use App\Admin\Repositories\PickPoetryVerse;
6 +use Dcat\Admin\Form;
7 +use Dcat\Admin\Grid;
8 +use Dcat\Admin\Show;
9 +use Dcat\Admin\Http\Controllers\AdminController;
10 +
11 +class PickPoetryVerseController extends AdminController
12 +{
13 + /**
14 + * Make a grid builder.
15 + *
16 + * @return Grid
17 + */
18 + protected function grid()
19 + {
20 + return Grid::make(new PickPoetryVerse(), function (Grid $grid) {
21 + $grid->column('id')->sortable();
22 + $grid->column('pick_id');
23 + $grid->column('verse_id');
24 + $grid->column('created_at');
25 + $grid->column('updated_at')->sortable();
26 +
27 + $grid->filter(function (Grid\Filter $filter) {
28 + $filter->equal('id');
29 +
30 + });
31 + });
32 + }
33 +
34 + /**
35 + * Make a show builder.
36 + *
37 + * @param mixed $id
38 + *
39 + * @return Show
40 + */
41 + protected function detail($id)
42 + {
43 + return Show::make($id, new PickPoetryVerse(), function (Show $show) {
44 + $show->field('id');
45 + $show->field('pick_id');
46 + $show->field('verse_id');
47 + $show->field('created_at');
48 + $show->field('updated_at');
49 + });
50 + }
51 +
52 + /**
53 + * Make a form builder.
54 + *
55 + * @return Form
56 + */
57 + protected function form()
58 + {
59 + return Form::make(new PickPoetryVerse(), function (Form $form) {
60 + $form->display('id');
61 + $form->text('pick_id');
62 + $form->text('verse_id');
63 +
64 + $form->display('created_at');
65 + $form->display('updated_at');
66 + });
67 + }
68 +}
1 +<?php
2 +
3 +namespace App\Console\Commands;
4 +
5 +use App\Models\Author;
6 +use App\Models\Poetry;
7 +use App\Models\Verse;
8 +use Illuminate\Console\Command;
9 +use Illuminate\Support\Facades\DB;
10 +use Illuminate\Support\Facades\Storage;
11 +
12 +class ImportPoemDataToMysql extends Command
13 +{
14 + /**
15 + * The name and signature of the console command.
16 + *
17 + * @var string
18 + */
19 + protected $signature = 'import:poem';
20 +
21 + /**
22 + * The console command description.
23 + *
24 + * @var string
25 + */
26 + protected $description = 'Command description';
27 +
28 + /**
29 + * Create a new command instance.
30 + *
31 + * @return void
32 + */
33 + public function __construct()
34 + {
35 + parent::__construct();
36 + }
37 +
38 + /**
39 + * Execute the console command.
40 + *
41 + * @throws
42 + * @return int
43 + */
44 + public function handle()
45 + {
46 + Author::query()->truncate();
47 + Poetry::query()->truncate();
48 + Verse::query()->truncate();
49 +
50 + // 写入楚辞
51 + $this->createChuCiData();
52 +
53 + // 写入诗经
54 + $this->createShiJingData();
55 +
56 + // 宋词
57 + $this->createSongCiData();
58 +
59 + // 唐诗
60 + $this->createTangShiData();
61 +
62 + return 0;
63 + }
64 +
65 + public function createChuCiData()
66 + {
67 + try{
68 + $chuci = json_decode(Storage::disk('public')->get('PoemData/chuci.json'),true);
69 +
70 + $author = new Author;
71 + $author->name = '屈原';
72 + $author->dynasty = '春秋战国';
73 + $author->introduce = '屈原是属于春秋战国时期楚国的人,芈姓,屈氏,名平,字原,又自云名正则,字灵均,战国时期楚国诗人、政治家,是中国历史上一位伟大的爱国诗人,中国浪漫主义文学的奠基人,“楚辞”的创立者和代表作家,开辟了“香草美人”的传统,被誉为“楚辞之祖”。';
74 + $author->save();
75 +
76 + $author = new Author;
77 + $author->name = '宋玉';
78 + $author->dynasty = '战国';
79 + $author->introduce = '宋玉(公元前298年—公元前222年),楚国诗人,宋国公族后裔,生于楚国,曾事楚顷襄王,为楚国士大夫。战国著名辞赋家,宋玉与唐勒,景差齐名,传世作品有《九辩》等。所谓“下里巴人”、“阳春白雪”、“曲高和寡”便说的是他,典故皆他而来。始皇帝二十五年己卯,公元前222年因病去世享年七十六岁。';
80 + $author->save();
81 +
82 + $author = new Author;
83 + $author->name = '景差';
84 + $author->dynasty = '战国';
85 + $author->introduce = '景差[cuō](前290年—前223年),芈姓,景氏,名差,战国时期楚国辞赋家。后于屈原,与宋玉、唐勒同时以赋见称,主要作品有楚辞《大招》。';
86 + $author->save();
87 +
88 + $author = new Author;
89 + $author->name = '贾谊';
90 + $author->dynasty = '战国';
91 + $author->introduce = '贾谊(公元前200年~公元前168年),汉族,洛阳(今河南省洛阳市)人,西汉初年著名政论家、文学家,世称贾生。贾谊少有才名,十八岁时,以善文为郡人所称。文帝时任博士,迁太中大夫,受大臣周勃、灌婴排挤,谪为长沙王太傅,故后世亦称贾长沙、贾太傅。三年后被召回长安,为梁怀王太傅。梁怀王坠马而死,贾谊深自歉疚,抑郁而亡,时仅三十三岁。司马迁对屈原、贾谊都寄予同情,为二人写了一篇合传,后世因而往往把贾谊与屈原并称为“屈贾”。';
92 + $author->save();
93 +
94 + $author = new Author;
95 + $author->name = '淮南小山';
96 + $author->dynasty = '西汉';
97 + $author->introduce = '淮南小山是西汉淮南王刘安的一部分门客的共称。今仅存辞赋《招隐士》 1篇。《汉书·艺文志》著录“淮南王群臣赋四十四篇”,《招隐士》当是其中仅存的1篇。此篇始见于东汉王逸的《楚辞章句》,题为淮南小山作,然而萧统《文选》则题刘安作。关于文章写作的背景,说法也不一。王逸说是小山之徒“闵伤屈原”之作,王夫之《楚辞通释》说是淮南小山“为淮南王召致山谷潜伏之士”而作,而不少研究者则以为是淮南小山思念淮南王的作品。';
98 + $author->save();
99 +
100 + $author = new Author;
101 + $author->name = '东方朔';
102 + $author->dynasty = '西汉';
103 + $author->introduce = '东方朔(约前161年—前93年?),字曼倩,平原郡厌次县人,西汉时期著名文学家。';
104 + $author->save();
105 +
106 + $author = new Author;
107 + $author->name = '庄忌';
108 + $author->dynasty = '西汉';
109 + $author->introduce = '庄忌(约前188-前105)西汉辞赋家。会稽吴(今苏州吴县)人。因避汉明帝刘庄讳改名严忌,与邹阳、枚乘等唱和,是梁孝王门下著名辞赋家。作品仅存《哀时命》一篇。 此赋感叹屈原生不逢时,空怀壮志而不得伸。是咏屈赋中的佳品。此赋纯属骚体,保持了由贾谊开创的西汉早期骚赋所具有的特点。感情真挚,篇幅短小精悍,是咏屈赋中的佳品。';
110 + $author->save();
111 +
112 + $author = new Author;
113 + $author->name = '王褒';
114 + $author->dynasty = '西汉';
115 + $author->introduce = '王褒(前90年—前51年),字子渊,别号桐柏真人,蜀郡资中(今四川省资阳市雁江区昆仑乡墨池坝村)人。西汉时期辞赋家,与扬雄并称“渊云”。';
116 + $author->save();
117 +
118 + $author = new Author;
119 + $author->name = '刘向';
120 + $author->dynasty = '西汉';
121 + $author->introduce = '刘向(公元前77年~公元前6年),原名刘更生,字子政,沛郡丰邑(今江苏省徐州市)人。汉朝宗室大臣、文学家,楚元王刘交(汉高祖刘邦异母弟)之玄孙,阳城侯刘德之子,经学家刘歆之父,中国目录学鼻祖。';
122 + $author->save();
123 +
124 + $author = new Author;
125 + $author->name = '王逸';
126 + $author->dynasty = '东汉';
127 + $author->introduce = '王逸,字叔师,生卒年不详,南郡宜城(今湖北省襄阳市宜城县)人,东汉著名文学家。官至豫州刺史、豫章太守。所作《楚辞章句》,是《楚辞》中最早的完整注本,颇为后世楚辞学者所重。又作有赋、诔、书、论等21篇,及《汉诗》123篇,今多散佚,仅存《九思》,为哀悼屈原而作。明人辑有《王叔师集》';
128 + $author->save();
129 +
130 +
131 + foreach ($chuci as $item) {
132 + $author = Author::query()->where('name',$item['author'])->first();
133 +
134 + $poetry = new Poetry();
135 + $poetry->name = $item['title'];
136 + $poetry->subname = $item['section'];
137 + $poetry->author_id = $author->id;
138 + $poetry->save();
139 +
140 + foreach ($item['content'] as $value) {
141 + $verse = new Verse();
142 + $verse->poetry_id = $poetry->id;
143 + $verse->stanza = $value;
144 + $verse->annotate = '';
145 + $verse->en = '';
146 + $verse->save();
147 + }
148 + }
149 + }catch (\Exception $exception){
150 + dd($exception->getMessage() . 'Line:' . $exception->getLine());
151 + }
152 +
153 + return true;
154 + }
155 +
156 + public function createShiJingData()
157 + {
158 + try{
159 + DB::beginTransaction();
160 + $author = new Author;
161 + $author->name = '不详';
162 + $author->dynasty = '西周至春秋';
163 + $author->introduce = '《诗经》的作者佚名,绝大部分已经无法考证,传为尹吉甫采集、孔子编订。《诗经》在先秦时期称为《诗》,或取其整数称《诗三百》。';
164 + $author->save();
165 +
166 + $shijing = json_decode(Storage::disk('public')->get('PoemData/shijing.json'),true);
167 +
168 + foreach ($shijing as $item) {
169 +
170 + $poetry = new Poetry();
171 + $poetry->name = $item['title'];
172 + $poetry->subname = $item['section'];
173 + $poetry->alias = $item['chapter'];
174 + $poetry->author_id = $author->id;
175 + $poetry->save();
176 +
177 + foreach ($item['content'] as $value) {
178 + $verse = new Verse();
179 + $verse->poetry_id = $poetry->id;
180 + $verse->stanza = $value;
181 + $verse->annotate = '';
182 + $verse->en = '';
183 + $verse->save();
184 + }
185 + }
186 + DB::commit();
187 + }catch (\Exception $exception){
188 + DB::rollBack();
189 + dd($exception->getMessage() . 'Line:' . $exception->getLine());
190 + }
191 +
192 + return true;
193 + }
194 +
195 + public function createSongCiData()
196 + {
197 + try{
198 + $songauthor = json_decode(Storage::disk('public')->get('PoemData/author.song.json'),true);
199 +
200 + foreach ($songauthor as $item) {
201 + $author = new Author();
202 + $author->name = $item['name'];
203 + $author->introduce = $item['description'];
204 + $author->save();
205 + }
206 + $songci = json_decode(Storage::disk('public')->get('PoemData/songci.json'),true);
207 +
208 + foreach ($songci as $item) {
209 + $author = Author::query()->where('name',$item['author'])->first();
210 +
211 + $poetry = new Poetry();
212 + $poetry->name = $item['rhythmic'];
213 + $poetry->author_id = $author->id;
214 + $poetry->save();
215 +
216 + foreach ($item['paragraphs'] as $value) {
217 + $verse = new Verse();
218 + $verse->poetry_id = $poetry->id;
219 + $verse->stanza = $value;
220 + $verse->annotate = '';
221 + $verse->en = '';
222 + $verse->save();
223 + }
224 + }
225 +
226 + }catch (\Exception $exception){
227 + dd($exception->getMessage() . ' Line:' . $exception->getLine() . ' name:' . $item['rhythmic']);
228 + }
229 + }
230 +
231 + public function createTangShiData()
232 + {
233 + try{
234 + $tangauthor = json_decode(Storage::disk('public')->get('PoemData/authors.tang.json'),true);
235 +
236 + foreach ($tangauthor as $item) {
237 + $author = new Author();
238 + $author->name = $item['name'];
239 + $author->introduce = $item['desc'];
240 + $author->save();
241 + }
242 + $tangshi = json_decode(Storage::disk('public')->get('PoemData/tangshi.json'),true);
243 +
244 + foreach ($tangshi as $item) {
245 + $author = Author::query()->where('name',$item['author'])->first();
246 +
247 + $poetry = new Poetry();
248 + $poetry->name = $item['title'];
249 + $poetry->author_id = $author->id;
250 + $poetry->save();
251 +
252 + foreach ($item['paragraphs'] as $value) {
253 + $verse = new Verse();
254 + $verse->poetry_id = $poetry->id;
255 + $verse->stanza = $value;
256 + $verse->annotate = '';
257 + $verse->en = '';
258 + $verse->save();
259 + }
260 + }
261 +
262 + }catch (\Exception $exception){
263 + dd($exception->getMessage() . ' Line:' . $exception->getLine() . ' name:' . $item['title']);
264 + }
265 + }
266 +}
1 +<?php
2 +
3 +namespace App\Models;
4 +
5 +use Dcat\Admin\Traits\HasDateTimeFormatter;
6 +
7 +use Illuminate\Database\Eloquent\Model;
8 +
9 +class PickPoetryVerse extends Model
10 +{
11 + use HasDateTimeFormatter;
12 + protected $table = 'pick_poetry_verse';
13 +
14 +}
...@@ -15,7 +15,7 @@ class CreatePoetryTable extends Migration ...@@ -15,7 +15,7 @@ class CreatePoetryTable extends Migration
15 { 15 {
16 Schema::create('poetry', function (Blueprint $table) { 16 Schema::create('poetry', function (Blueprint $table) {
17 $table->increments('id'); 17 $table->increments('id');
18 - $table->foreignId('author_id')->constrained('author','id'); 18 + $table->unsignedBigInteger('author_id')->index()->comment('作者id');
19 $table->string('name')->default('')->comment('题目'); 19 $table->string('name')->default('')->comment('题目');
20 $table->string('subname')->default('')->comment('小标题'); 20 $table->string('subname')->default('')->comment('小标题');
21 $table->string('alias')->default('')->comment('别名'); 21 $table->string('alias')->default('')->comment('别名');
......
...@@ -15,7 +15,7 @@ class CreateVerseTable extends Migration ...@@ -15,7 +15,7 @@ class CreateVerseTable extends Migration
15 { 15 {
16 Schema::create('verse', function (Blueprint $table) { 16 Schema::create('verse', function (Blueprint $table) {
17 $table->increments('id'); 17 $table->increments('id');
18 - $table->foreignId('poetry_id')->constrained('poetry','id'); 18 + $table->unsignedBigInteger('poetry_id')->index()->comment('诗词id');
19 $table->string('stanza')->default('')->comment('诗节'); 19 $table->string('stanza')->default('')->comment('诗节');
20 $table->text('annotate')->comment('注解'); 20 $table->text('annotate')->comment('注解');
21 $table->string('spelling')->default('')->comment('拼音'); 21 $table->string('spelling')->default('')->comment('拼音');
......
...@@ -15,8 +15,8 @@ class CreatePoetryTagTable extends Migration ...@@ -15,8 +15,8 @@ class CreatePoetryTagTable extends Migration
15 { 15 {
16 Schema::create('poetry_tag', function (Blueprint $table) { 16 Schema::create('poetry_tag', function (Blueprint $table) {
17 $table->increments('id'); 17 $table->increments('id');
18 - $table->foreignId('poetry_id')->constrained('poetry','id'); 18 + $table->unsignedBigInteger('poetry_id')->index()->comment('诗词id');
19 - $table->foreignId('tag_id')->constrained('tags','id'); 19 + $table->unsignedBigInteger('tag_id')->index()->comment('标签id');
20 }); 20 });
21 } 21 }
22 22
......
...@@ -17,9 +17,9 @@ class CreatePickPoetryTable extends Migration ...@@ -17,9 +17,9 @@ class CreatePickPoetryTable extends Migration
17 $table->increments('id'); 17 $table->increments('id');
18 $table->string('title')->default('')->comment('标题'); 18 $table->string('title')->default('')->comment('标题');
19 $table->string('subtitle')->default('')->comment('副标题'); 19 $table->string('subtitle')->default('')->comment('副标题');
20 - $table->string('left_tag_id')->default('')->comment('左侧文本'); 20 + $table->string('left_text')->default('')->comment('左侧文本');
21 - $table->string('right_tag_id')->default('')->comment('右侧文本'); 21 + $table->string('right_text')->default('')->comment('右侧文本');
22 - $table->foreignId('poetry_id')->constrained('poetry','id'); 22 + $table->unsignedBigInteger('poetry_id')->index()->comment('诗词id');
23 $table->unsignedBigInteger('use_num')->comment('使用次数'); 23 $table->unsignedBigInteger('use_num')->comment('使用次数');
24 $table->unsignedTinyInteger('state')->comment('状态'); 24 $table->unsignedTinyInteger('state')->comment('状态');
25 $table->timestamps(); 25 $table->timestamps();
......
1 +<?php
2 +
3 +use Illuminate\Support\Facades\Schema;
4 +use Illuminate\Database\Schema\Blueprint;
5 +use Illuminate\Database\Migrations\Migration;
6 +
7 +class CreatePickPoetryVerseTable extends Migration
8 +{
9 + /**
10 + * Run the migrations.
11 + *
12 + * @return void
13 + */
14 + public function up()
15 + {
16 + Schema::create('pick_poetry_verse', function (Blueprint $table) {
17 + $table->increments('id');
18 + $table->unsignedBigInteger('pick_id')->index()->comment('官方秀id');
19 + $table->unsignedBigInteger('verse_id')->index()->comment('诗句(节)id');
20 + });
21 + }
22 +
23 + /**
24 + * Reverse the migrations.
25 + *
26 + * @return void
27 + */
28 + public function down()
29 + {
30 + Schema::dropIfExists('pick_poetry_verse');
31 + }
32 +}
...@@ -18,8 +18,7 @@ class CreateUserShowTable extends Migration ...@@ -18,8 +18,7 @@ class CreateUserShowTable extends Migration
18 $table->unsignedBigInteger('user_id')->comment('用户id'); 18 $table->unsignedBigInteger('user_id')->comment('用户id');
19 $table->text('content')->comment('内容描述'); 19 $table->text('content')->comment('内容描述');
20 $table->unsignedTinyInteger('type')->comment('1=图文,2=视频'); 20 $table->unsignedTinyInteger('type')->comment('1=图文,2=视频');
21 -// $table->unsignedBigInteger('pick_id')->comment('引用的官方秀id'); 21 + $table->unsignedBigInteger('pick_id')->index()->comment('引用的秀id');
22 - $table->foreignId('poetry_id')->constrained('pick_poetry','id');
23 $table->integer('fav_num')->comment('收藏数'); 22 $table->integer('fav_num')->comment('收藏数');
24 $table->integer('view_num')->comment('观看数'); 23 $table->integer('view_num')->comment('观看数');
25 $table->integer('praise_num')->comment('点赞数'); 24 $table->integer('praise_num')->comment('点赞数');
......
...@@ -48,6 +48,8 @@ namespace Dcat\Admin { ...@@ -48,6 +48,8 @@ namespace Dcat\Admin {
48 * @property Grid\Column|Collection tokenable_id 48 * @property Grid\Column|Collection tokenable_id
49 * @property Grid\Column|Collection abilities 49 * @property Grid\Column|Collection abilities
50 * @property Grid\Column|Collection last_used_at 50 * @property Grid\Column|Collection last_used_at
51 + * @property Grid\Column|Collection poetry_id
52 + * @property Grid\Column|Collection tag_id
51 * @property Grid\Column|Collection email_verified_at 53 * @property Grid\Column|Collection email_verified_at
52 * 54 *
53 * @method Grid\Column|Collection id(string $label = null) 55 * @method Grid\Column|Collection id(string $label = null)
...@@ -87,6 +89,8 @@ namespace Dcat\Admin { ...@@ -87,6 +89,8 @@ namespace Dcat\Admin {
87 * @method Grid\Column|Collection tokenable_id(string $label = null) 89 * @method Grid\Column|Collection tokenable_id(string $label = null)
88 * @method Grid\Column|Collection abilities(string $label = null) 90 * @method Grid\Column|Collection abilities(string $label = null)
89 * @method Grid\Column|Collection last_used_at(string $label = null) 91 * @method Grid\Column|Collection last_used_at(string $label = null)
92 + * @method Grid\Column|Collection poetry_id(string $label = null)
93 + * @method Grid\Column|Collection tag_id(string $label = null)
90 * @method Grid\Column|Collection email_verified_at(string $label = null) 94 * @method Grid\Column|Collection email_verified_at(string $label = null)
91 */ 95 */
92 class Grid {} 96 class Grid {}
...@@ -131,6 +135,8 @@ namespace Dcat\Admin { ...@@ -131,6 +135,8 @@ namespace Dcat\Admin {
131 * @property Show\Field|Collection tokenable_id 135 * @property Show\Field|Collection tokenable_id
132 * @property Show\Field|Collection abilities 136 * @property Show\Field|Collection abilities
133 * @property Show\Field|Collection last_used_at 137 * @property Show\Field|Collection last_used_at
138 + * @property Show\Field|Collection poetry_id
139 + * @property Show\Field|Collection tag_id
134 * @property Show\Field|Collection email_verified_at 140 * @property Show\Field|Collection email_verified_at
135 * 141 *
136 * @method Show\Field|Collection id(string $label = null) 142 * @method Show\Field|Collection id(string $label = null)
...@@ -170,6 +176,8 @@ namespace Dcat\Admin { ...@@ -170,6 +176,8 @@ namespace Dcat\Admin {
170 * @method Show\Field|Collection tokenable_id(string $label = null) 176 * @method Show\Field|Collection tokenable_id(string $label = null)
171 * @method Show\Field|Collection abilities(string $label = null) 177 * @method Show\Field|Collection abilities(string $label = null)
172 * @method Show\Field|Collection last_used_at(string $label = null) 178 * @method Show\Field|Collection last_used_at(string $label = null)
179 + * @method Show\Field|Collection poetry_id(string $label = null)
180 + * @method Show\Field|Collection tag_id(string $label = null)
173 * @method Show\Field|Collection email_verified_at(string $label = null) 181 * @method Show\Field|Collection email_verified_at(string $label = null)
174 */ 182 */
175 class Show {} 183 class Show {}
......