Przeglądaj źródła

师傅端接口

lizhen_gitee 8 miesięcy temu
rodzic
commit
3bc0f3b81d

+ 101 - 0
application/api/controller/worker/Caozuoguifan.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace app\api\controller\worker;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 操作规范
+ */
+class Caozuoguifan extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    public function index()
+    {
+        //所有分类
+        $typelist = Db::name('caozuoguifan_type')
+            ->where('company_id',$this->auth->company_id)
+            ->order('id' , 'asc')
+            ->select();
+
+        //第一个分类的内容
+        $list = [];
+        if(!empty($typelist)){
+            $list = Db::name('caozuoguifan')->field('content',true)
+                ->where('company_id',$this->auth->company_id)
+                ->where('type_id',$typelist[0]['id'])
+                ->autopage()
+                ->select();
+            $list = list_domain_image($list,['image']);
+        }
+
+        $rs = [
+            'typelist' => $typelist,
+            'list'     => $list,
+        ];
+
+        $this->success(1, $rs);
+    }
+
+    //操作规范
+    public function lists(){
+        $type_id = input('type_id',0);
+
+        $list = Db::name('caozuoguifan')->field('content',true)
+            ->where('company_id',$this->auth->company_id)
+            ->where('type_id',$type_id)
+            ->autopage()
+            ->select();
+        $list = list_domain_image($list,['image']);
+
+        $this->success(1, $list);
+    }
+
+    //详情
+    public function info(){
+        $id = input('id',0);
+        $info = Db::name('caozuoguifan')
+            ->where('id',$id)
+            ->find();
+        $info = info_domain_image($info, ['image']);
+
+        //收藏
+        $info['is_collect'] = $this->is_collect($info['id'],$this->auth->id);
+
+        $this->success(1, $info);
+    }
+
+    //收藏,取消收藏
+    public function collect(){
+        $where = [
+            'worker_id'  => $this->auth->id,
+            'table'    => 'caozuoguifan',
+            'table_id' => input('id',0),
+        ];
+        $check = Db::name('worker_collect')->where($where)->find();
+        if($check){
+            Db::name('worker_collect')->where($where)->delete();
+            $this->success('已取消收藏');
+        }else{
+            Db::name('worker_collect')->insertGetId($where);
+            $this->success('收藏成功');
+        }
+    }
+
+    //动态是否收藏
+    private function is_collect($id,$uid){
+        $where = [
+            'worker_id'  => $uid,
+            'table'    => 'caozuoguifan',
+            'table_id' => $id,
+        ];
+        $check = Db::name('worker_collect')->where($where)->find();
+        if($check){
+            return 1;
+        }else{
+            return 0;
+        }
+    }
+}

+ 47 - 4
application/api/controller/worker/News.php

@@ -40,13 +40,20 @@ class News extends Api
         $this->success(1, $rs);
     }
 
-    //操作规范
+    //
     public function lists(){
         $type_id = input('type_id',0);
+        $keyword = input('keyword','','trim');
+
+        $wheresearch = [];
+        if(!empty($keyword)){
+            $wheresearch['title'] = ['LIKE','%'.$keyword.'%'];
+        }
 
         $list = Db::name('news')->field('content',true)
             ->where('company_id',$this->auth->company_id)
             ->where('type_id',$type_id)
+            ->where($wheresearch)
             ->autopage()
             ->select();
         $list = list_domain_image($list,['image']);
@@ -57,13 +64,49 @@ class News extends Api
     //详情
     public function info(){
         $id = input('id',0);
-        $list = Db::name('news')
+        $info = Db::name('news')
             ->where('id',$id)
             ->find();
-        $list = info_domain_image($list, ['image']);
+        $info = info_domain_image($info, ['image']);
 
-        $this->success(1, $list);
+        //收藏
+        $info['is_collect'] = $this->is_collect($info['id'],$this->auth->id);
+
+        $this->success(1, $info);
     }
 
+    //收藏,取消收藏
+    public function collect(){
+        $where = [
+            'worker_id'  => $this->auth->id,
+            'table'    => 'news',
+            'table_id' => input('id',0),
+        ];
+        $check = Db::name('worker_collect')->where($where)->find();
+        if($check){
+            Db::name('worker_collect')->where($where)->delete();
+            $this->success('已取消收藏');
+        }else{
+            Db::name('worker_collect')->insertGetId($where);
+            $this->success('收藏成功');
+        }
+    }
+
+    //动态是否收藏
+    private function is_collect($id,$uid){
+        $where = [
+            'worker_id'  => $uid,
+            'table'    => 'news',
+            'table_id' => $id,
+        ];
+        $check = Db::name('worker_collect')->where($where)->find();
+        if($check){
+            return 1;
+        }else{
+            return 0;
+        }
+    }
+
+
 
 }