Skip to content

Commit d14474e

Browse files
committed
处理一些bug
1 parent 3434dd8 commit d14474e

File tree

27 files changed

+300
-62
lines changed

27 files changed

+300
-62
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ php artisan serve --port 9091
5555
```shell script
5656
php artisan queue:work redis --sleep=3
5757
```
58+
59+
#### 更新日志
60+
* 2021-04-17 新增用户评论所属区域显示 新增归档a链接 新增评论删除模型监听

apiblog/.DS_Store

0 Bytes
Binary file not shown.

apiblog/app/Admin/Controllers/TopicController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ protected function detail($id)
7575
*/
7676
protected function form()
7777
{
78-
return Form::make(new Topic(), function (Form $form) {
78+
return Form::make(new Topics(), function (Form $form) {
7979
$form->display('id');
8080
$form->text('article_id');
8181
$form->text('topic_id');
8282
$form->text('user_id');
83-
$form->text('content');
83+
8484
$form->text('address');
8585
$form->text('ip');
8686

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace App\Admin\Controllers;
4+
5+
use App\Admin\Repositories\WebsiteFooter;
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 WebsiteFooterController extends AdminController
12+
{
13+
protected $title ='网址信息';
14+
15+
protected static $status=[
16+
0=>'正常',
17+
1=>'禁用'
18+
];
19+
/**
20+
* Make a grid builder.
21+
*
22+
* @return Grid
23+
*/
24+
protected function grid()
25+
{
26+
return Grid::make(new WebsiteFooter(), function (Grid $grid) {
27+
$grid->column('id')->sortable();
28+
$grid->column('logo')->image();
29+
$grid->column('name','标题');
30+
$grid->column('license');
31+
$grid->column('license_url');
32+
// $grid->column('website');
33+
$grid->column('status')->select(static::$status);
34+
$grid->column('created_at');
35+
$grid->column('updated_at')->sortable();
36+
37+
$grid->filter(function (Grid\Filter $filter) {
38+
$filter->equal('id');
39+
40+
});
41+
});
42+
}
43+
44+
/**
45+
* Make a show builder.
46+
*
47+
* @param mixed $id
48+
*
49+
* @return Show
50+
*/
51+
protected function detail($id)
52+
{
53+
return Show::make($id, new WebsiteFooter(), function (Show $show) {
54+
$show->field('id');
55+
$show->field('name');
56+
$show->field('logo');
57+
$show->field('license');
58+
$show->field('license_url');
59+
$show->field('website');
60+
$show->field('status');
61+
$show->field('created_at');
62+
$show->field('updated_at');
63+
});
64+
}
65+
66+
/**
67+
* Make a form builder.
68+
*
69+
* @return Form
70+
*/
71+
protected function form()
72+
{
73+
return Form::make(new WebsiteFooter(), function (Form $form) {
74+
$form->display('id');
75+
$form->text('name')->required();
76+
$form->image('logo')->disk('public')->required();
77+
$form->text('license','备案/许可证编号')->required();
78+
$form->text('license_url')->required();
79+
80+
//赣ICP备19000975号-1 //https://www.miit.gov.cn/
81+
$form->table('website', function ($table) {
82+
$table->text('title');
83+
$table->image('website_img')->disk('public');
84+
$table->text('website_url');
85+
})->saving(function ($v) {
86+
return json_encode($v);
87+
});
88+
$form->select('status')->options(static::$status)->default(0);
89+
90+
$form->display('created_at');
91+
$form->display('updated_at');
92+
93+
$form->saving(function (Form $form){
94+
if($form->isEditing() && $form->status==1){
95+
//清除缓存
96+
cache()->delete('get_website_info');
97+
}
98+
});
99+
});
100+
}
101+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Admin\Repositories;
4+
5+
use App\Models\WebsiteFooter as Model;
6+
use Dcat\Admin\Repositories\EloquentRepository;
7+
8+
class WebsiteFooter extends EloquentRepository
9+
{
10+
/**
11+
* Model.
12+
*
13+
* @var string
14+
*/
15+
protected $eloquentClass = Model::class;
16+
}

apiblog/app/Admin/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
$router->resource('/users', 'UsersController');
1818
$router->resource('/visitor-registry', 'VisitorRegistryController');
1919
$router->resource('/topics', 'TopicController');
20+
$router->resource('/website', 'WebsiteFooterController');
2021

2122
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Created By PhpStorm.
4+
* User : Latent
5+
* Date : 2021/4/18
6+
* Time : 2:40 下午
7+
**/
8+
9+
namespace App\Http\Controllers;
10+
11+
12+
use App\Models\WebsiteFooter;
13+
use Illuminate\Support\Facades\Redis;
14+
15+
class AppController extends Controller
16+
{
17+
public function getWebsiteInfo()
18+
{
19+
$data = Redis::get('get_website_info');
20+
if(!$data){
21+
$data = WebsiteFooter::query()->where('status',0)
22+
->first(['name','logo','license','license_url','website'])->toArray();
23+
24+
$data['logo'] = env('APP_URL').'/storage/'.$data['logo'];
25+
26+
foreach ($data['website'] as &$val){
27+
28+
$val['website_img'] = env('APP_URL').'/storage/'.$val['website_img'];
29+
}
30+
Redis::set('get_website_info',json_encode($data));
31+
}else{
32+
$data = json_decode($data,true);
33+
}
34+
return $this->success($data);
35+
}
36+
37+
}

apiblog/app/Http/Controllers/OauthController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ public function githubCallBack()
1919
{
2020
$auth = new SocialiteAuth(config('oauth.github'));
2121
$user = $auth->driver('github')->user();
22+
2223
$users = User::query()->where('oauth_id',$user->id)->first();
24+
2325
if(!$users){
2426
$users= User::query()->create([
25-
'name'=>$user->name,
27+
'name'=> empty($user->name) ?? $user->login,
2628
'email'=>$user->email,
2729
'avatar'=>$user->avatar_url,
2830
'oauth_id'=>$user->id,
@@ -36,6 +38,7 @@ public function giteeCallBack()
3638
{
3739
$auth = new SocialiteAuth(config('oauth.gitee'));
3840
$user = $auth->driver('gitee')->user();
41+
3942
$users = User::query()->where('oauth_id',$user->id)->first();
4043

4144
if(!$users){
@@ -54,13 +57,14 @@ public function weiboCallBack()
5457
{
5558
$auth = new SocialiteAuth(config('oauth.weibo'));
5659
$user = $auth->driver('weibo')->user();
60+
5761
$users = User::query()->where('oauth_id',$user->id)->first();
5862

5963
if(!$users){
6064
$users= User::query()->create([
6165
'name'=>$user->name,
62-
'email'=>$user->email,
63-
'avatar'=>$user->avatar_url,
66+
'email'=>'',
67+
'avatar'=>$user->avatar_large,
6468
'oauth_id'=>$user->id,
6569
'bound_oauth'=>2
6670
]);

apiblog/app/Http/Controllers/TopicsController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function index($id)
2626
{
2727
$data = Topics::query()->with('user')
2828
->where('article_id',$id)
29-
->get(['id','content','created_at','user_id']);
29+
->get(['id','content','created_at','user_id','address']);
3030

3131
return $this->success($data);
3232
}
@@ -37,6 +37,7 @@ public function store(Request $request)
3737
'contents' => ['required','min:2'],
3838
'article_id' => ['required','exists:articles,id']
3939
]);
40+
$ipInfo = geoip($request->getClientIp());
4041
if(is_numeric($request->topic_id)){
4142
if( Topics::query()->where('topic_id',$request->topic_id)->exists())
4243
{
@@ -45,18 +46,19 @@ public function store(Request $request)
4546
'content'=> $request->contents,
4647
'article_id'=> $request->article_id,
4748
'user_id'=>Auth::id(),
48-
'ip'=>$request->getClientIp()
49+
'ip'=>$request->getClientIp(),
50+
'address'=>$ipInfo->country.' '.$ipInfo->city
4951
]);
5052
Articles::query()->findOrFail($request->article_id)->increment('browse_count');
5153
}
5254
return $this->fail('当前评论已删除或不存在');
5355
} else{
54-
Log::info('test',[$request->all()]);
5556
Topics::query()->create([
5657
'content'=> $request->contents,
5758
'article_id'=> $request->article_id,
5859
'user_id'=>Auth::id(),
59-
'ip'=>$request->getClientIp()
60+
'ip'=>$request->getClientIp(),
61+
'address'=>$ipInfo->country.' '.$ipInfo->city,
6062
]);
6163
Articles::query()->findOrFail($request->article_id)->increment('browse_count');
6264
}
@@ -65,9 +67,8 @@ public function store(Request $request)
6567

6668
public function delete($id)
6769
{
68-
Log::info('user_id',[Auth::id()]);
6970
if(Topics::query()->where('user_id',Auth::id())->where('id',$id)->exists()) {
70-
Topics::query()->where('user_id',Auth::id())->where('id',$id)->delete();
71+
Topics::destroy($id);
7172
return $this->success();
7273
}else{
7374
return $this->fail('无权限删除该评论或该评论已删除',[],500,200);

apiblog/app/Http/Middleware/AccessRecord.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function handle(Request $request, Closure $next)
2121
if($request->route()->uri == 'api/article/{id}' && env('APP_DEBUG') == false){
2222
VisitorsToRecordJob::dispatch($request->getClientIp(),$request->id);
2323
}
24+
2425
return $next($request);
2526
}
2627
}

0 commit comments

Comments
 (0)