瀏覽代碼

最新关注

lizhen_gitee 1 年之前
父節點
當前提交
5b8ea001c0

+ 1 - 0
application/api/controller/Dynamic.php

@@ -7,6 +7,7 @@ use app\common\controller\Api;
 use think\Db;
 /**
  * 动态接口
+ * 本文件已作废,topichub 和 topicdongtai 完全替代了动态功能
  */
 class Dynamic extends Api
 {

+ 6 - 46
application/api/controller/Topicdongtai.php

@@ -71,7 +71,7 @@ class Topicdongtai extends Api
                     $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
                 }
 
-                $val['createtime_text'] = $this->get_last_time($val['createtime']);
+                $val['createtime_text'] = get_last_time($val['createtime']);
             }
         }
 
@@ -142,7 +142,7 @@ class Topicdongtai extends Api
                 unset($images_url[count($images_url) - 1]);
                 $info['images_thumb'] = join('.', $images_url) . '_0.jpg';
             }
-            $info['createtime_text'] = $this->get_last_time($info['createtime']);
+            $info['createtime_text'] = get_last_time($info['createtime']);
 
             //评论
             $info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->count();
@@ -340,7 +340,7 @@ class Topicdongtai extends Api
                 }
 
                 //时间处理
-                $val['createtime_text'] = $this->get_last_time($val['createtime']);
+                $val['createtime_text'] = get_last_time($val['createtime']);
 
                 //回复是否已赞
                 $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
@@ -361,7 +361,7 @@ class Topicdongtai extends Api
             ->join('user','a.user_id = user.id','LEFT')
             ->where(['a.id'=>$answer_id])->find();
         $floor_info = info_domain_image($floor_info,['avatar']);
-        $floor_info['createtime_text'] = $this->get_last_time($floor_info['createtime']);
+        $floor_info['createtime_text'] = get_last_time($floor_info['createtime']);
         //回复是否已赞
         $floor_info['is_good'] = $this->answer_is_good($answer_id,$this->auth->id);
         $floor_info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$floor_info['dt_id'],'floor'=>$floor_info['floor'],'level'=>2])->count();
@@ -377,7 +377,7 @@ class Topicdongtai extends Api
         if(!empty($child_lists)){
             foreach($child_lists as $key => &$answer){
                 $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
-                $answer['createtime_text'] = $this->get_last_time($answer['createtime']);
+                $answer['createtime_text'] = get_last_time($answer['createtime']);
             }
         }
 
@@ -435,7 +435,7 @@ class Topicdongtai extends Api
                 $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
 
                 //时间
-                $val['createtime_text'] = $this->get_last_time($val['createtime']);
+                $val['createtime_text'] = get_last_time($val['createtime']);
 
                 //关注
                 $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
@@ -448,45 +448,5 @@ class Topicdongtai extends Api
     }
 
 
-    /**
-     * 评论时间转换
-     * @param null $time
-     * @return false|string
-     */
-    private function get_last_time($time = NULL) {
-        $text = '';
-        $time = $time === NULL || $time > time() ? time() : intval($time);
-        $t = time() - $time; //时间差 (秒)
-        $y = date('Y', $time)-date('Y', time());//是否跨年
-        switch($t){
-            case $t == 0:
-                $text = '刚刚';
-                break;
-            case $t < 60:
-                $text = $t . '秒前'; // 一分钟内
-                break;
-            case $t < 60 * 60:
-                $text = floor($t / 60) . '分钟前'; //一小时内
-                break;
-            case $t < 60 * 60 * 24:
-                $text = floor($t / (60 * 60)) . '小时前'; // 一天内
-                break;
-            case $t < 60 * 60 * 24 * 3:
-                $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
-                break;
-            case $t < 60 * 60 * 24 * 30:
-                $text = date('m月d日 H:i', $time); //一个月内
-                break;
-            case $t < 60 * 60 * 24 * 365&&$y==0:
-                $text = date('m月d日', $time); //一年内
-                break;
-            default:
-                $text = date('Y年m月d日', $time); //一年以前
-                break;
-        }
-
-        return $text;
-    }
-
 
 }

+ 4 - 2
application/api/controller/Usercenter.php

@@ -236,7 +236,7 @@ class UserCenter extends Common
         $where = [];
         $where["a.fans_id"] = $this->auth->id;
         $followlist = $fanfollowModel->alias("a")
-            ->field("a.id,a.user_id,u.avatar,u.nickname,u.level,u.gender")
+            ->field("a.id,a.user_id,a.createtime,u.avatar,u.nickname,u.level,u.gender")
             ->join("hx_user u","u.id = a.user_id")
 //            ->limit($pageStart,$pageNum)
             ->where($where)->select();
@@ -245,7 +245,7 @@ class UserCenter extends Common
         $where = [];
         $where["a.user_id"] = $this->auth->id;
         $fanslist = $fanfollowModel->alias("a")
-            ->field("a.id,a.fans_id,u.avatar,u.nickname,u.level,u.gender")
+            ->field("a.id,a.fans_id,a.createtime,u.avatar,u.nickname,u.level,u.gender")
             ->join("hx_user u","u.id = a.fans_id")
 //            ->limit($pageStart,$pageNum)
             ->where($where)->select();
@@ -260,6 +260,7 @@ class UserCenter extends Common
             }
             if($followlist) {
                 foreach($followlist as $k => $v) {
+                    $followlist[$k]['createtime_text'] = get_last_time($v['createtime']);
                     if(in_array($v["user_id"],$ids)) {
                         $followlist[$k]["is_hu"] = 1;
                     } else {
@@ -277,6 +278,7 @@ class UserCenter extends Common
             }
             if($fanslist) {
                 foreach($fanslist as $k => $v) {
+                    $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
                     if(in_array($v["fans_id"],$ids)) {
                         $fanslist[$k]["is_hu"] = 1;
                     } else {

+ 40 - 0
application/common.php

@@ -509,3 +509,43 @@ function request_post_hub($field_array = [],$required = [],$noempty = []){
 
     return $data;
 }
+
+/**
+ * 时间转换
+ * @param null $time
+ * @return false|string
+ */
+function get_last_time($time = NULL) {
+    $text = '';
+    $time = $time === NULL || $time > time() ? time() : intval($time);
+    $t = time() - $time; //时间差 (秒)
+    $y = date('Y', $time)-date('Y', time());//是否跨年
+    switch($t){
+        case $t == 0:
+            $text = '刚刚';
+            break;
+        case $t < 60:
+            $text = $t . '秒前'; // 一分钟内
+            break;
+        case $t < 60 * 60:
+            $text = floor($t / 60) . '分钟前'; //一小时内
+            break;
+        case $t < 60 * 60 * 24:
+            $text = floor($t / (60 * 60)) . '小时前'; // 一天内
+            break;
+        case $t < 60 * 60 * 24 * 3:
+            $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
+            break;
+        case $t < 60 * 60 * 24 * 30:
+            $text = date('m月d日 H:i', $time); //一个月内
+            break;
+        case $t < 60 * 60 * 24 * 365&&$y==0:
+            $text = date('m月d日', $time); //一年内
+            break;
+        default:
+            $text = date('Y年m月d日', $time); //一年以前
+            break;
+    }
+
+return $text;
+}