lizhen_gitee 1 năm trước cách đây
mục cha
commit
c325fd63f0
2 tập tin đã thay đổi với 228 bổ sung7 xóa
  1. 49 7
      application/api/controller/Index.php
  2. 179 0
      application/api/controller/Userfollow.php

+ 49 - 7
application/api/controller/Index.php

@@ -27,19 +27,61 @@ class Index extends Api
         $this->success(1,$list);
     }
 
-    //名医推荐
-    public function index_doctor(){
-        $keshi_id = input('keshi_id',0);
+    //职称列表
+    public function level_list(){
+        $list = Db::name('doctor_level')->select();
+        $this->success(1,$list);
+    }
+
+    //医生列表
+    //首页推荐,搜索
+    public function doctor_list(){
 
         $where = [
-            'status' => 1,
+            'd.status' => 1,
+            'd.doctor_status' => 1,
         ];
 
+        //科室id
+        $keshi_id = input('keshi_id',0);
         if($keshi_id){
-            $where['keshi_id'] = $keshi_id;
+            $where['d.keshi_id'] = $keshi_id;
+        }
+        //职称id
+        $level_id = input('level_id',0);
+        if($level_id){
+            $where['d.level_id'] = $level_id;
+        }
+        //关注
+        $folllow = input('follow',0);
+        if($folllow){
+            $my_follow_ids = controller('Userfollow')->my_follow_uids();
+            $where['d.id'] = ['IN',$my_follow_ids];
+        }
+        //搜索
+        $keyworld = input('keyworld','');
+        if(!empty($keyworld)){
+            $where['d.nickname|d.goodat|keshi.name'] = ['LIKE','%'.$keyworld.'%'];
         }
 
-        $field = ['id,nickname,'];
-        Db::name('doctor')->field($field)->where($where)->autopage()->select();
+        //dump($where);
+
+        $field = [
+            'd.id','d.nickname','d.avatar','d.keshi_id','d.level_id','d.hospital','d.goodat','d.ordernum',
+            'keshi.name as keshi_name',
+            'level.name as level_name',
+        ];
+        $list = Db::name('doctor')->alias('d')
+            ->field($field)
+            ->join('doctor_level level','d.level_id = level.id','LEFT')
+            ->join('keshi','d.keshi_id = keshi.id','LEFT')
+            ->where($where)->order('d.ordernum desc')->autopage()->select();
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success(1,$list);
     }
+
+
+
+
 }

+ 179 - 0
application/api/controller/Userfollow.php

@@ -0,0 +1,179 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 关注
+ */
+class Userfollow extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+
+    //关注某人,取关
+    public function follow_one(){
+        $follow_uid = input('doctor_id',0);
+
+        if(!$follow_uid){
+            $this->error(__('Invalid parameters'));
+        }
+
+        $checkuser = Db::name('doctor')->find($follow_uid);
+        if(empty($checkuser)){
+            $this->error('此医生不存在');
+        }
+
+        $map = [
+            'uid' => $this->auth->id,
+            'follow_uid' => $follow_uid,
+        ];
+
+        $check = Db::name('user_follow')->where($map)->find();
+        if($check){
+            //取关
+            $rs = Db::name('user_follow')->where($map)->delete();
+            $this->success('操作成功');
+        }
+
+        $id = Db::name('user_follow')->insertGetId($map);
+
+        $this->success('操作成功',$id);
+    }
+
+
+    //我的关注uids
+    public function my_follow_uids(){
+        $list = Db::name('user_follow')->where('uid',$this->auth->id)->column('follow_uid');
+
+        $list = array_flip($list);
+        $list = array_flip($list);
+
+        return $list;
+    }
+////////////////////////////////////////////////////////////
+
+    //我的关注列表
+    public function my_follow_list(){
+        $user_id = input('user_id',0);
+        if(empty($user_id)){
+            $user_id = $this->auth->id;
+        }
+
+        //列表
+        $list = Db::name('user_follow')
+            ->alias('follow')
+            ->join('user','follow.follow_uid = user.id','LEFT')
+            ->field('user.id,user.username,user.nickname,user.avatar,user.birthday,user.gender')
+            ->where('follow.uid',$user_id)->order('follow.id desc')->group('follow.follow_uid')->autopage()->select();
+
+        $list = list_domain_image($list,['avatar']);
+        $list = list_birthday_age($list);
+
+        //我的关注uids
+        $my_follow_uids = $this->my_follow_uids();
+
+        if(!empty($list)){
+            foreach($list as $key => &$val){
+
+                //是否关注
+                $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0;
+            }
+        }
+
+        $this->success('success',$list);
+    }
+
+    //我的粉丝列表
+    public function my_fans_list(){
+        $user_id = input('user_id',0);
+        if(empty($user_id)){
+            $user_id = $this->auth->id;
+        }
+
+        //列表
+        $list = Db::name('user_follow')
+            ->alias('follow')
+            ->join('user','follow.uid = user.id','LEFT')
+            ->field('user.id,user.username,user.nickname,user.avatar,user.birthday,user.gender')
+            ->where('follow.follow_uid',$user_id)
+            ->group('follow.uid')
+            ->order('follow.id desc')->autopage()->select();
+
+        $list = list_domain_image($list,['avatar']);
+        $list = list_birthday_age($list);
+
+        //我的关注uids
+        $my_follow_uids = $this->my_follow_uids();
+
+        if(!empty($list)){
+            foreach($list as $key => &$val){
+
+                //是否关注
+                $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0;
+            }
+        }
+
+        $this->success('success',$list);
+    }
+
+    //我的好友,拿粉丝列表改的
+    public function my_friend_list(){
+        //我的关注uids
+        $my_follow_uids = $this->my_follow_uids();
+        //我的粉丝uids
+        $my_fans_uids = $this->my_fans_uids();
+        //合集就是朋友
+        $friend_ids = array_intersect($my_follow_uids,$my_fans_uids);
+        //dump($friend_ids);
+        //好友列表
+        $list = Db::name('user')->alias('user')
+            ->field('user.id,user.nickname,user.avatar,a.requesttime')
+            ->join('user_active a','user.id = a.user_id','LEFT')
+            ->where('user.id','IN',$friend_ids)->autopage()->order('user.id asc')->select();
+        if(empty($list)){
+            $this->success(1,[]);
+        }
+
+        //dump($list);
+
+        $list_ids = implode(',',array_column($list,'id'));
+        //dump($list_ids);
+
+        //亲密度列表
+        $intimacy = Db::name('user_intimacy')->where('(uid = '.$this->auth->id.' and other_uid in ('.$list_ids.')) or (uid in ('.$list_ids.') and other_uid = '.$this->auth->id.')')->select();
+        //dump($intimacy);
+
+        foreach($list as $key => &$val){
+
+            $val['intimacy'] = 0;
+            $val['requesttime_text'] = get_last_time($val['requesttime']);
+
+            foreach($intimacy as $k => $v){
+
+                if($v['uid'] == $this->auth->id && $v['other_uid'] == $val['id']){
+                    $val['intimacy'] = $v['value'];
+                }
+                if($v['uid'] == $val['id'] && $v['other_uid'] == $this->auth->id){
+                    $val['intimacy'] = $v['value'];
+                }
+            }
+        }
+
+        $this->success(1,$list);
+
+    }
+
+    //我的粉丝uids
+    private function my_fans_uids(){
+        $list = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
+        
+        $list = array_flip($list);
+        $list = array_flip($list);
+
+        return $list;
+    }
+
+}