Pārlūkot izejas kodu

话题关注人数转换成字符串

wzq 5 gadi atpakaļ
vecāks
revīzija
4a3fd457cb

+ 13 - 0
app/Helper/helper.php

@@ -161,3 +161,16 @@ function success($data = [], $msg = "成功")
     }
     return $response;
 }
+//转换数字
+function getNumber($num) {
+    if ($num >= 100000000) {
+        $num = sprintf("%.2f", $num / 100000000) . '亿';
+    } elseif ($num >= 100000) {
+        $num = intval($num / 10000) . '万';
+    } elseif ($num >= 10000) {
+        $num = sprintf("%.1f", $num / 10000) . '万';
+    } else {
+        $num = strval($num);
+    }
+    return $num;
+}

+ 1 - 1
app/Repositories/PostRepositories.php

@@ -543,7 +543,7 @@ class PostRepositories
                 'id' => $topic->id,
                 'name' => $topic->name,
                 'img' => $topic->img,
-                'follow_count' => $topic->follow->count() + (int) config('customer.add_topic_follow_count'),
+                'follow_count' => (string) getNumber($topic->follow->count() + config('customer.add_topic_follow_count')),
             ];
         }
         return $data;

+ 1 - 1
app/Transformers/Topic/TopicDetailTransformer.php

@@ -23,7 +23,7 @@ class TopicDetailTransformer extends TransformerAbstract
             'id' => $topic['id'],
             'name' => subtext($topic['name'], 5),
             'img' => $topic['img'],
-            'follow_count' => $topic->follow->count() + (int) config('customer.add_topic_follow_count'),
+            'follow_count' => (string) getNumber($topic->follow->count() + config('customer.add_topic_follow_count')),
             'is_follow' => $topic->follow->where('uid', $this->uid)->count()?1:0,
         ];
     }

+ 1 - 1
app/Transformers/Topic/TopicListTransformer.php

@@ -19,7 +19,7 @@ class TopicListTransformer extends TransformerAbstract
             'id' => $topic['id'],
             'name' => subtext($topic['name'], 5),
             'img' => $topic['img'],
-            'follow_count' => $topic->follow->count() + (int) config('customer.add_topic_follow_count'),
+            'follow_count' => (string) getNumber($topic->follow->count() + config('customer.add_topic_follow_count')),
         ];
     }
 }