xielin 5 anos atrás
pai
commit
77f9bdc029
2 arquivos alterados com 14 adições e 10 exclusões
  1. 1 0
      app/Helper/helper.php
  2. 13 10
      app/Transformers/Topic/TopicPostTransformer.php

+ 1 - 0
app/Helper/helper.php

@@ -22,6 +22,7 @@ if (!function_exists('config_path')) {
  */
 function generateSign(array $params, $secret_key)
 {
+    \Illuminate\Support\Facades\Log::debug($params);
     unset($params['sign']);
     // 将删除参数组中所有等值为FALSE的参数(包括:NULL, 空字符串,0, false)
     // $params = array_filter($params);

+ 13 - 10
app/Transformers/Topic/TopicPostTransformer.php

@@ -5,7 +5,8 @@
  * Date: 2019/6/17
  * Time: 19:26
  */
-namespace  App\Transformers\Topic;
+
+namespace App\Transformers\Topic;
 
 use App\Models\Post;
 use App\Models\PostCollect;
@@ -21,27 +22,29 @@ class TopicPostTransformer extends TransformerAbstract
 {
     use UserTrait;
     use PostTrait;
+
     public function __construct($uid, $invite_code)
     {
         $this->uid = $uid;
         $this->invite_code = $invite_code;
     }
+
     public function transform(Post $post)
     {
         $imgs = [];
-        foreach($post->imgs as $img){
+        foreach ($post->imgs as $img) {
             $imgs[] = $img['img'];
         }
         $isLike = 0;
         $isDislike = 0;
         $isCollect = 0;
         $isFollow = 0;
-        if($this->uid){
-            $isLike = PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
-            $isDislike = PostDislike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
-            $isCollect = PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0;
+        if ($this->uid) {
+            $isLike = PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists() ? 1 : 0;
+            $isDislike = PostDislike::where('post_id', $post['id'])->where('uid', $this->uid)->exists() ? 1 : 0;
+            $isCollect = PostCollect::where('post_id', $post['id'])->where('uid', $this->uid)->exists() ? 1 : 0;
             $followStatus = $this->getFollowStatus($this->uid, $post['uid']);
-            if($followStatus){
+            if ($followStatus) {
                 $isFollow = $followStatus;
             }
         }
@@ -56,7 +59,7 @@ class TopicPostTransformer extends TransformerAbstract
             'topic' => $this->getTopic($post['topic_ids']),
             'is_fine' => $post['is_fine'],
             'title' => $post['title'],
-            'content' => $post['content'],
+            'content' => subtext($post['content'], 100),
             'location' => $post['location'],
             'img' => $post['img'],
             'imgs' => $imgs,
@@ -70,8 +73,8 @@ class TopicPostTransformer extends TransformerAbstract
             'is_collect' => $isCollect,
             'comment' => $this->getNewComment($post['id'], $this->uid),
             'is_follow' => $isFollow,
-            'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",
-            'desc_url' => $post['type'] == 'html'?config('customer.app_service_url').'/community/fragment/detail/'.$post['id']:'',
+            'h5url' => config('customer.share_post_h5url') . "?post_id={$post['id']}&invite_code={$this->invite_code}",
+            'desc_url' => $post['type'] == 'html' ? config('customer.app_service_url') . '/community/fragment/detail/' . $post['id'] : '',
         ];
     }
 }