瀏覽代碼

首页接口增加字段

lizhen_gitee 2 周之前
父節點
當前提交
b1031bcb08
共有 2 個文件被更改,包括 26 次插入1 次删除
  1. 19 1
      app/Models/User/WxUser.php
  2. 7 0
      app/Wen/Utils/StatisticUtils.php

+ 19 - 1
app/Models/User/WxUser.php

@@ -28,7 +28,7 @@ class WxUser extends Model
     use SoftDeletes;
     use Searchable;
 
-    protected $appends = ['follow_count','follow_user_count','like_count','is_online'];
+    protected $appends = ['follow_count','follow_user_count','like_count','is_online','blogger_status'];
 
     protected $table = 'wx_user';
 
@@ -642,6 +642,24 @@ class WxUser extends Model
     }
 
     /**
+     * 是否认证答主
+     * @param $uid
+     * @return mixed
+     */
+    public function getBloggerStatusAttribute()
+    {
+        dump(__LINE__);
+        $uid = $this->id;
+        $status = StatisticUtils::user_blogger_status($uid);
+
+        if($status == 1){
+            return env('APP_URL').'/icon/blogger.png';
+        } else {
+            return '659';
+        }
+    }
+
+    /**
      * 粉丝数量
      * @param $uid
      */

+ 7 - 0
app/Wen/Utils/StatisticUtils.php

@@ -18,6 +18,7 @@ use App\Models\User\WxUserFollow;
 use App\Models\User\WxUserTemp;
 use App\Models\User\WxUserWithdrawal;
 use Illuminate\Support\Facades\Cache;
+use App\Models\Ask\Blogger;
 
 class StatisticUtils{
 
@@ -112,6 +113,12 @@ class StatisticUtils{
         }
     }
 
+    public static function user_blogger_status($uid){
+        return (int)Cache::remember('user:blogger:status:'.$uid, 5, function () use($uid){
+            return Blogger::where('user_id',$uid)->value('status');
+        });
+    }
+
     public static function user_follow_count($uid){
         return (int)Cache::remember('user:follow:count:'.$uid, 3600, function () use($uid){
             return WxUserFollow::where('user_id',$uid)->count();