Kaynağa Gözat

师傅端接口

lizhen_gitee 8 ay önce
ebeveyn
işleme
1f2572ed89

+ 9 - 8
application/api/controller/worker/Jishuguifan.php

@@ -47,12 +47,12 @@ class Jishuguifan extends Api
         $tree->nbsp = ' ';
         $treedata = $tree->getTreeList($tree->getTreeArray($tid), 'name');
 
-        /*$result = [];
-        foreach ($treedata as $k => $v) {
-            $result[$v['id']] = $v;
-        }*/
-
-        $this->success(1, $treedata);
+        $rs = [
+            'tree' => $treedata,
+            'is_collect' => $this->is_collect($tid,$this->auth->id),
+            'collect_id' => $tid
+        ];
+        $this->success(1, $rs);
     }
 
     //详情
@@ -61,8 +61,7 @@ class Jishuguifan extends Api
         $info = Db::name('jishuguifan')
             ->where('id',$id)
             ->find();
-        //收藏
-        $info['is_collect'] = $this->is_collect($info['id'],$this->auth->id);
+
 
         //上一篇
         $up_id = 0;
@@ -80,6 +79,8 @@ class Jishuguifan extends Api
 
         $rs = [
             'info' => $info,
+            'is_collect' => $this->is_collect($info['tid'],$this->auth->id),
+            'collect_id' => $info['tid'],
             'up_id' => $up_id,
             'down_id' => $down_id,
         ];

+ 72 - 0
application/api/controller/worker/Usercenter.php

@@ -0,0 +1,72 @@
+<?php
+
+namespace app\api\controller\worker;
+
+use app\common\controller\Api;
+use think\Db;
+use fast\Tree;
+/**
+ * 我的
+ */
+class Usercenter extends Api
+{
+    protected $noNeedLogin = ['collect_list','download_list'];
+    protected $noNeedRight = ['*'];
+
+    public function collect_list(){
+        $table = input('type','jishuguifan');
+
+        //验证表名
+        $table_name = [
+            'jishuguifan',
+            'news',
+            'caozuoguifan',
+        ];
+        if(!in_array($table,$table_name)){
+            $this->error();
+        }
+
+        //拿收藏的ids
+        $where = [
+            'worker_id'  => $this->auth->id,
+            'table'    => $table,
+        ];
+        $table_ids = Db::name('worker_collect')->where($where)->group('table_id')->column('table_id');
+
+        if(!empty($table_ids)){
+        $ids_str = implode(',',$table_ids);
+        //字段
+        $table_field = [
+            'jishuguifan' => 'id,name,ismenu',
+            'news' => 'id,title,image,createtime',
+            'caozuoguifan' => 'id,title,image,createtime',
+        ];
+
+        $list = Db::name($table)->field($table_field[$table])
+            ->where('id','IN',$table_ids)
+            ->orderRaw('field(id,'.$ids_str.')')
+            ->autopage()
+            ->select();
+        }else{
+            $list = [];
+        }
+
+        $this->success(1, $list);
+    }
+
+
+    //下载功能
+    public function download_list(){
+        $list = Db::name('worker_download')->alias('down')
+            ->join('jishuguifan j','down.table_id = j.id','LEFT')
+            ->field('j.id,j.name,j.ismenu,down.updatetime')
+            ->where('down.worker_id',$this->auth->id)
+            ->autopage()
+            ->group('down.table_id')
+            ->select();
+
+        $this->success(1,$list);
+
+    }
+
+}