Ver código fonte

问答系统修改

任敬轩 3 anos atrás
pai
commit
d7eaf6675a

+ 14 - 15
app/Http/Controllers/Account/AuthenticationController.php

@@ -7,9 +7,9 @@ use App\Models\Attention;
 use App\Models\Authentication;
 use App\Models\Tag;
 use Illuminate\Http\Request;
-
 use App\Http\Requests;
 use App\Http\Controllers\Controller;
+use Illuminate\Support\Facades\Storage;
 
 class AuthenticationController extends Controller
 {
@@ -58,7 +58,6 @@ class AuthenticationController extends Controller
      */
     public function postStore(Request $request)
     {
-
         $this->validate($request,$this->validateRules,$this->validateMessages);
 
         $data = $request->all();
@@ -66,23 +65,15 @@ class AuthenticationController extends Controller
         $data['user_id'] = $request->user()->id;
 
         if($request->hasFile('id_card_image')){
-            $savePath = storage_path('app/authentications');
             $file = $request->file('id_card_image');
-            $fileName = uniqid(str_random(8)).'.'.$file->getClientOriginalExtension();
-            $target = $file->move($savePath,$fileName);
-            if($target){
-                $data['id_card_image'] = 'authentications-'.$fileName;
-            }
+            $path = 'avatar/' . date("Ym/d", time());
+            $data['id_card_image'] = $this->upload_image($path, $file);
         }
 
         if($request->hasFile('skill_image')){
-            $savePath = storage_path('app/authentications');
             $file = $request->file('skill_image');
-            $fileName = uniqid(str_random(8)).'.'.$file->getClientOriginalExtension();
-            $target = $file->move($savePath,$fileName);
-            if($target){
-                $data['skill_image'] = 'authentications-'.$fileName;
-            }
+            $path = 'avatar/' . date("Ym/d", time());
+            $data['skill_image'] = $this->upload_image($path, $file);
         }
 
         Authentication::create($data);
@@ -159,6 +150,14 @@ class AuthenticationController extends Controller
         }
     }
 
-
+    function upload_image($path, $file, $drive = 'oss')
+    {
+        $disk = Storage::disk($drive);
+        //将图片上传到OSS中,并返回图片路径信息 值如:avatar/WsH9mBklpAQUBQB4mL.jpeg
+        $path = $disk->put($path, $file);
+        //由于图片不在本地,所以我们应该获取图片的完整路径,
+        //值如:https://test.oss-cn-hongkong.aliyuncs.com/avatar/8GdIcz1NaCZ.jpeg
+        return $disk->url($path);
+    }
 
 }

+ 6 - 6
app/Http/Controllers/Admin/AuthenticationController.php

@@ -9,7 +9,7 @@ use App\Models\Tag;
 use App\Models\User;
 use Carbon\Carbon;
 use Illuminate\Http\Request;
-
+use DB;
 use App\Http\Requests;
 use Illuminate\Support\Facades\Storage;
 
@@ -73,12 +73,11 @@ class AuthenticationController extends AdminController
         if(!$authUser){
             return $this->error(route('admin.authentication.create'),'申请认证的用户不存在,请核实user_id');
         }
-
         $data = $request->all();
+
         if(isset($data['is_recommend']) && $data['is_recommend'] ==1){
             $data['recommend_at'] = Carbon::now();
         }
-
         if($request->hasFile('id_card_image')){
             $file = $request->file('id_card_image');
             $path = 'avatar/' . date("Ym/d", time());
@@ -90,7 +89,10 @@ class AuthenticationController extends AdminController
             $path = 'avatar/' . date("Ym/d", time());
             $data['skill_image'] = $this->upload_image($path, $file);
         }
-
+        if($data['status'] == 1){
+            $res['authentication_status'] = 1;
+            DB::table('user_data')->where('user_id',$data['user_id'])->update($res);
+        }
         $authentication = Authentication::create($data);
         if($authentication){
             Tag::multiSave($request->input('skill'),$request->user());
@@ -163,9 +165,7 @@ class AuthenticationController extends AdminController
             $path = 'avatar/' . date("Ym/d", time());
             $data['skill_image'] = $this->upload_image($path, $file);
         }
-
         $result = $authentication->update($data);
-
         if($result){
             Tag::multiSave($request->input('skill'),$request->user());
         }

+ 18 - 9
app/Http/Controllers/IndexController.php

@@ -99,7 +99,7 @@ class IndexController extends Controller
 
         /*热门专家*/
         $hotExperts = Cache::remember('index_hot_experts',Setting()->get('website_cache_time',1),function(){
-            return  Authentication::hottest(8);
+            return  Authentication::hottest(4);
         });
 
         $hotUsers = Cache::remember('index_hot_users',30,function() {
@@ -117,14 +117,23 @@ class IndexController extends Controller
         });
 
         /*热门文章*/
-        $hotArticles = Cache::remember('index_hot_articles',Setting()->get('website_cache_time',1),function() {
-            return  Article::hottest(0,12);
-        });
-
+//        $hotArticles = Cache::remember('index_hot_articles',Setting()->get('website_cache_time',1),function() {
+//            return  Article::hottest(0,5);
+//        });
+        $hotArticles = DB::table('articles')
+            ->where('status','>',0)
+            ->orderBy('views','desc')
+            ->paginate(5)
+            ->all();
         /*最新文章*/
-        $newestArticles = Cache::remember('index_newest_articles',Setting()->get('website_cache_time',1),function() {
-            return  Article::newest(0,12);
-        });
+//        $newestArticles = Cache::remember('index_newest_articles',Setting()->get('website_cache_time',1),function() {
+//            return  Article::newest(0,5);
+//        });
+        $newestArticles = DB::table('articles')
+            ->where('status','>',0)
+            ->orderBy('updated_at','desc')
+            ->paginate(5)
+            ->all();
 
         /*最新公告*/
         $newestNotices = Cache::remember('newest_notices',Setting()->get('website_cache_time',1),function() {
@@ -165,6 +174,7 @@ class IndexController extends Controller
                 $userData['mobile_status'] = 1;
             }
             $this->userData->create($userData);
+
         }
         $user->attachRole(2); //默认注册为普通用户角色
         $this->auth->login($user);
@@ -286,7 +296,6 @@ class IndexController extends Controller
 
     public function topic( $categorySlug='all')
     {
-
         $parentId=$currentCategoryId = 0;
         $query = Tag::query();
         if( $categorySlug != 'all' ){

+ 1 - 1
resources/views/themes/default/home/index.blade.php

@@ -82,7 +82,7 @@
             @if($hotExperts)
                 <div class="widget-box clearfix border-top">
                     <h4 class="widget-box-title">推荐专家 <a href="{{ route('website.experts') }}" title="更多">»</a></h4>
-                    <div class="row row-horizon">
+                    <div class="row row-horizon" style="overflow-x:hidden;">
                         @foreach($hotExperts as $expert)
                             <section class="col-sm-6 col-md-3">
                                 <div class="thumbnail">

+ 2 - 2
resources/views/themes/default/home/topic.blade.php

@@ -34,7 +34,7 @@
                     <section class="topic-list-item col-md-3">
                         <div class="widget-topic">
                             <h2 class="h4">
-                                <a href="{{ route('ask.tag.index',['id'=>$topic->id]) }}" @if($topic->logo) class="tag-logo" style="background-image: url({{ route('website.image.show',['image_name'=>$topic->logo]) }});" @endif>{{ $topic->name }}</a>
+                                <a href="{{ route('ask.tag.index',['id'=>$topic->id]) }}" @if($topic->logo) class="tag-logo" style="background-image: url({{$topic->logo}});" @endif>{{ $topic->name }}</a>
                             </h2>
                             <p>
                                 @if($topic->description)
@@ -59,4 +59,4 @@
                 </div>
             </div>
         </div>
-@endsection
+@endsection

+ 3 - 3
resources/views/themes/default/tag/index.blade.php

@@ -11,7 +11,7 @@
             <section class="tag-header mt-20">
                 <div>
                     @if($tag->logo)
-                    <img class="pull-left avatar-27 mr-10" src="{{ route('website.image.show',['image_name'=>$tag->logo]) }}">
+                    <img class="pull-left avatar-27 mr-10" src="{{ $tag->logo }}">
                     @endif
                     <span class="h4 tag-header-title">{{ $tag->name }}</span>
 
@@ -154,7 +154,7 @@
                     @foreach($followers as $follower)
                         <li class="media  widget-user-item ">
                             <a href="{{ route('auth.space.index',['user_id'=>$follower->user_id]) }}" class="user-card pull-left" target="_blank">
-                                <img class="avatar-50"  src="{{ get_user_avatar($follower->user_id) }}" alt="{{ $follower->user->name }}"></a>
+                                <img class="avatar-50"  src="{{ $follower->user->qrcode }}" alt="{{ $follower->user->name }}"></a>
                             </a>
                             <div class="media-object">
                                 <strong><a href="{{ route('auth.space.index',['user_id'=>$follower->user_id]) }}" target="_blank">{{ $follower->user->name }}</a></strong>
@@ -166,4 +166,4 @@
             </div>
         </div><!-- /.side -->
     </div>
-@endsection
+@endsection