Showing
4 changed files
with
56 additions
and
14 deletions
| ... | @@ -233,23 +233,33 @@ class ImportPoemDataToMysql extends Command | ... | @@ -233,23 +233,33 @@ class ImportPoemDataToMysql extends Command |
| 233 | try{ | 233 | try{ |
| 234 | $tangauthor = json_decode(Storage::disk('public')->get('PoemData/authors.tang.json'),true); | 234 | $tangauthor = json_decode(Storage::disk('public')->get('PoemData/authors.tang.json'),true); |
| 235 | 235 | ||
| 236 | - foreach ($tangauthor as $item) { | 236 | +// foreach ($tangauthor as $item) { |
| 237 | - $author = new Author(); | 237 | +// $author = new Author(); |
| 238 | - $author->name = $item['name']; | 238 | +// $author->name = $item['name']; |
| 239 | - $author->introduce = $item['desc']; | 239 | +// $author->introduce = $item['desc']; |
| 240 | - $author->save(); | 240 | +// $author->save(); |
| 241 | - } | 241 | +// } |
| 242 | $tangshi = json_decode(Storage::disk('public')->get('PoemData/tangshi.json'),true); | 242 | $tangshi = json_decode(Storage::disk('public')->get('PoemData/tangshi.json'),true); |
| 243 | 243 | ||
| 244 | foreach ($tangshi as $item) { | 244 | foreach ($tangshi as $item) { |
| 245 | - $author = Author::query()->where('name',$item['author'])->first(); | 245 | + $author = new Author(); |
| 246 | + $author->name = $item['author']; | ||
| 247 | + $author->introduce = ''; | ||
| 248 | + foreach ($tangauthor as $itemauthor) { | ||
| 249 | + if ($item['author'] == $itemauthor['name']){ | ||
| 250 | + $author->introduce = $itemauthor['desc']; | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + $author->save(); | ||
| 246 | 254 | ||
| 247 | $poetry = new Poetry(); | 255 | $poetry = new Poetry(); |
| 248 | $poetry->name = $item['title']; | 256 | $poetry->name = $item['title']; |
| 249 | $poetry->author_id = $author->id; | 257 | $poetry->author_id = $author->id; |
| 250 | $poetry->save(); | 258 | $poetry->save(); |
| 251 | 259 | ||
| 252 | - foreach ($item['paragraphs'] as $value) { | 260 | + $paragraphs = explode("\n", $item['contents']); |
| 261 | + | ||
| 262 | + foreach ($paragraphs as $value) { | ||
| 253 | $verse = new Verse(); | 263 | $verse = new Verse(); |
| 254 | $verse->poetry_id = $poetry->id; | 264 | $verse->poetry_id = $poetry->id; |
| 255 | $verse->stanza = $value; | 265 | $verse->stanza = $value; |
| ... | @@ -263,4 +273,34 @@ class ImportPoemDataToMysql extends Command | ... | @@ -263,4 +273,34 @@ class ImportPoemDataToMysql extends Command |
| 263 | dd($exception->getMessage() . ' Line:' . $exception->getLine() . ' name:' . $item['title']); | 273 | dd($exception->getMessage() . ' Line:' . $exception->getLine() . ' name:' . $item['title']); |
| 264 | } | 274 | } |
| 265 | } | 275 | } |
| 276 | + | ||
| 277 | + public function createDaoDeJingData() | ||
| 278 | + { | ||
| 279 | + try { | ||
| 280 | + $author = new Author(); | ||
| 281 | + $author->name = '老子'; | ||
| 282 | + $author->introduce = '老子,姓李名耳,字聃(dān),春秋末期楚国人,中国古代思想家、哲学家、文学家和史学家,道家学派创始人和主要代表人物。老子出生于楚国苦县,早年跟随常枞(zōnɡ)学习知识。周灵王二十一年,老子入周王室任守藏(zàng)室史,后来受到排挤,被免去官职。'; | ||
| 283 | + $author->save(); | ||
| 284 | + | ||
| 285 | + $collects = DB::table('article')->get(); | ||
| 286 | + foreach ($collects as $collect) { | ||
| 287 | + | ||
| 288 | + $poetry = new Poetry(); | ||
| 289 | + $poetry->name = '道德经 ' . $collect->title; | ||
| 290 | + $poetry->author_id = $author->id; | ||
| 291 | + $poetry->save(); | ||
| 292 | + | ||
| 293 | + | ||
| 294 | + $verse = new Verse(); | ||
| 295 | + $verse->poetry_id = $poetry->id; | ||
| 296 | + $verse->stanza = $collect->body; | ||
| 297 | + $verse->annotate = ''; | ||
| 298 | + $verse->en = ''; | ||
| 299 | + $verse->save(); | ||
| 300 | + } | ||
| 301 | + | ||
| 302 | + }catch (\Exception $exception){ | ||
| 303 | + dd($exception->getMessage() . ' Line:' . $exception->getLine() . ' name:' . $collect->title); | ||
| 304 | + } | ||
| 305 | + } | ||
| 266 | } | 306 | } | ... | ... |
| ... | @@ -15,11 +15,10 @@ class AuthController extends Controller | ... | @@ -15,11 +15,10 @@ class AuthController extends Controller |
| 15 | { | 15 | { |
| 16 | /** | 16 | /** |
| 17 | * web用户先访问这里进行重定向 | 17 | * web用户先访问这里进行重定向 |
| 18 | - * @param Request $request | ||
| 19 | * @param $service | 18 | * @param $service |
| 20 | * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\RedirectResponse | 19 | * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
| 21 | */ | 20 | */ |
| 22 | - public function redirectToProvider(Request $request, $service) | 21 | + public function redirectToProvider($service) |
| 23 | { | 22 | { |
| 24 | return Socialite::driver($service)->redirect(); | 23 | return Socialite::driver($service)->redirect(); |
| 25 | } | 24 | } | ... | ... |
| ... | @@ -16,10 +16,6 @@ use Illuminate\Routing\Router; | ... | @@ -16,10 +16,6 @@ use Illuminate\Routing\Router; |
| 16 | 16 | ||
| 17 | Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Router $api){ | 17 | Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Router $api){ |
| 18 | 18 | ||
| 19 | - /** web用户跳转登录*/ | ||
| 20 | - $api->get('auth/{service}', 'AuthController@redirectToProvider'); | ||
| 21 | - $api->get('auth/{service}/callback', 'AuthController@handleProviderCallback'); | ||
| 22 | - | ||
| 23 | /** 移动端微信用户登录*/ | 19 | /** 移动端微信用户登录*/ |
| 24 | $api->get('login/{service}/callback', 'AuthController@apiHandleProviderCallback'); | 20 | $api->get('login/{service}/callback', 'AuthController@apiHandleProviderCallback'); |
| 25 | }); | 21 | }); | ... | ... |
| ... | @@ -13,6 +13,13 @@ use Illuminate\Support\Facades\Route; | ... | @@ -13,6 +13,13 @@ use Illuminate\Support\Facades\Route; |
| 13 | | | 13 | | |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | +Route::namespace('App\Http\Controllers\V1')->group(function (){ | ||
| 17 | + /** web用户跳转登录*/ | ||
| 18 | + Route::get('auth/{service}', 'AuthController@redirectToProvider'); | ||
| 19 | + Route::get('auth/{service}/callback', 'AuthController@handleProviderCallback'); | ||
| 20 | +}); | ||
| 21 | + | ||
| 22 | + | ||
| 16 | Route::get('/', function () { | 23 | Route::get('/', function () { |
| 17 | return view('welcome'); | 24 | return view('welcome'); |
| 18 | }); | 25 | }); | ... | ... |
-
Please register or login to post a comment