WIN-2308041133\Administrator пре 1 дан
родитељ
комит
09df162f0d
3 измењених фајлова са 59 додато и 2 уклоњено
  1. 19 1
      app/api/controller/Pub.php
  2. 2 1
      app/api/route/pub.php
  3. 38 0
      app/model/api/ContractComment.php

+ 19 - 1
app/api/controller/Pub.php

@@ -13,6 +13,7 @@ declare (strict_types=1);
 namespace app\api\controller;
 
 use app\model\api\ArticleModel;
+use app\model\api\ContractComment;
 use app\model\api\LikeBookmark;
 use app\model\api\UserClock;
 use think\db\exception\DataNotFoundException;
@@ -362,7 +363,24 @@ class Pub extends BaseController
         $data = empty($data) ? [] : $data;
         return app("json")->success($data);
     }
-
+    /**
+     * 评论列表
+     * @param Request $request
+     */
+    public function getCommentList(Request $request)
+    {
+        $post = UtilService::getMore([
+            ['uid', 0],
+            ['to_uid', 0],
+            ['page', 1],
+            ['pageSize', 50],
+        ], $request);
+        $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
+        $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
+        $list = (new ContractComment())->getCommentList($post);
+        $data = empty($data) ? [] : $data;
+        return app("json")->success($data);
+    }
     /**
      * 获取其他用户名片信息
      * @param Request $request

+ 2 - 1
app/api/route/pub.php

@@ -44,7 +44,8 @@ Route::group('pub', function () {
     Route::rule('getArtDetail', 'pub/getArtDetail');
     //课程列表页面
     Route::rule('index', 'Pub/index');
-
+    //获取用户的评论
+    Route::rule('getCommentList', 'Pub/getCommentList');
 
     //bug提交
     Route::rule('appBugSub', 'Pub/appBugSub');

+ 38 - 0
app/model/api/ContractComment.php

@@ -11,4 +11,42 @@ use think\Model;
 class ContractComment extends Model
 {
     //
+    /**
+     * 评论列表
+     * @return type
+     */
+    public function getCommentList($post)
+    {
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
+        $where=[];
+//        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
+//            $where[]=["status","=",(int)$post["status"]];
+//        }
+        if(!empty($post["uid"])&&$post["uid"]>0){
+            $where[]=["uid","=",$post["uid"]];
+        }
+        if(!empty($post["to_uid"])&&$post["to_uid"]>0){
+            $where[]=["to_uid","=",$post["to_uid"]];
+        }
+        $totalCount = $this->where($where)->count();
+        $data=null;
+        if($totalCount>0){
+            $data = $this
+//                ->field($field)
+                ->where($where)
+                ->order("create_time", "desc")
+                ->page($post["page"], $post["pageSize"])
+                ->select();
+            if(!empty($data)){
+                $data = $data->toArray();
+                foreach ($data as $k => $v){
+                    $data[$k]["uid_nickname"] = (new User())->where("id", $v["uid"])->value("nickname");
+                    $data[$k]["avatar"] = (new User())->where("id", $v["uid"])->value("avatar");
+                }
+            }
+        }
+        $data = empty($data)?[]:$data;
+        return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
+    }
 }