lizhen_gitee пре 3 година
родитељ
комит
6ff9d0fb7d

+ 2 - 1
application/api/controller/Pay.php

@@ -13,12 +13,13 @@ class Pay extends Api
     protected $noNeedLogin = [];
     protected $noNeedRight = ['*'];
 
+    //vip用的
     public function pay_config(){
         $list = Db::name('pay_config')->where('is_show',1)->order('weight asc,id asc')->select();
         $this->success('success',$list);
     }
 
-    //创建订单
+    //vip用的,创建订单
     public function recharge(){
 
         $rc_id = input('rc_id',0);

+ 40 - 3
application/api/controller/User.php

@@ -9,6 +9,9 @@ use fast\Random;
 use think\Config;
 use think\Validate;
 
+use app\common\library\Token;
+use think\Db;
+
 /**
  * 会员接口
  */
@@ -51,7 +54,7 @@ class User extends Api
         }
         $ret = $this->auth->login($account, $password);
         if ($ret) {
-            $data = ['userinfo' => $this->auth->getUserinfo()];
+            $data = $this->userInfo('return');
             $this->success(__('Logged in successful'), $data);
         } else {
             $this->error($this->auth->getError());
@@ -90,7 +93,7 @@ class User extends Api
         }
         if ($ret) {
             Sms::flush($mobile, 'mobilelogin');
-            $data = ['userinfo' => $this->auth->getUserinfo()];
+            $data = $this->userInfo('return');
             $this->success(__('Logged in successful'), $data);
         } else {
             $this->error($this->auth->getError());
@@ -129,13 +132,47 @@ class User extends Api
         }
         $ret = $this->auth->register($username, $password, $email, $mobile, []);
         if ($ret) {
-            $data = ['userinfo' => $this->auth->getUserinfo()];
+            $data = $this->userInfo('return');
             $this->success(__('Sign up successful'), $data);
         } else {
             $this->error($this->auth->getError());
         }
     }
 
+    //用户详细资料
+    public function userInfo($type = 1){
+        $info = [
+            'id' => $this->auth->id,
+            'username' => $this->auth->username,
+            'truename' => $this->auth->truename,
+            'nickname' => $this->auth->nickname,
+            //'group_id' => $this->auth->group_id,
+            'idcard_status' => $this->auth->idcard_status,
+            'bio' => $this->auth->bio,
+            'birthday' => $this->auth->birthday,
+//            'address' => $this->auth->address,
+            'mobile' => $this->auth->mobile,
+
+            'avatar' => $this->auth->avatar,
+            'gender' => $this->auth->gender,
+            'email' => $this->auth->email,
+            'mobile' => $this->auth->mobile,
+//            'cover_image' => $this->auth->cover_image,
+//            'photo_images' => $this->auth->photo_images,
+//            'vip_endtime' => $this->auth->vip_endtime,
+        ];
+        //$info['is_vip'] = intval($info['vip_endtime']) - time() > 0 ? 1 : 0;
+        $info['age'] = birthtime_to_age($info['birthday']);
+        //$info = info_domain_image($info,['avatar','cover_image','photo_images']);
+
+        if($type == 'return'){
+            $info = array_merge($info, Token::get($this->auth->getToken())); //token 等多个字段
+            //$info['token'] = $this->auth->getToken();
+            return $info;
+        }
+        $this->success(__('success'),$info);
+    }
+
     //实名认证信息
     public function idcard_confirm_info(){
         $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->find();

+ 135 - 59
application/api/controller/Userdongtai.php

@@ -9,21 +9,23 @@ use think\Db;
  */
 class Userdongtai extends Api
 {
-    protected $noNeedLogin = ['evaluate'];
+    protected $noNeedLogin = ['evaluate','info','floor_info'];
     protected $noNeedRight = ['*'];
 
     //发布动态
     public function addone(){
-        $title = input('title','');
+        $content = input('content','');
         $images = input('images','');
-        if(!$title && !$images){
+        if(!$content && !$images){
             $this->error(__('Invalid parameters'));
         }
 
         $data = [
             'user_id' => $this->auth->id,
-            'title' => $title,
+            'content' => $content,
             'images' => $images,
+            'longitude' => input('longitude',''),
+            'latitude'  => input('latitude',''),
             'createtime' => time(),
             'updatetime' => time(),
         ];
@@ -39,17 +41,10 @@ class Userdongtai extends Api
 
         $list = Db::name('user_dongtai')->alias('dt')
             ->join('user','dt.user_id = user.id','LEFT')
-            ->field('dt.id,dt.title,dt.images,dt.createtime,dt.sharenum,dt.goodnum,user.nickname,user.avatar')
+            ->field('dt.*,user.nickname,user.avatar')
             ->where('dt.user_id',$this->auth->id)
             ->order('dt.id desc')->autopage()->select();
         $list = list_domain_image($list,['images','avatar']);
-        /*foreach($list as $key => &$val){
-            if($val['images']){
-                $val['images'] = explode(',',$val['images']);
-            }else{
-                $val['images'] = [];
-            }
-        }*/
 
         $this->success('success',$list);
     }
@@ -58,18 +53,12 @@ class Userdongtai extends Api
     public function info(){
         $id = input('id');
 
-        $info = Db::name('user_dongtai')->alias('p')
-            ->join('user','p.user_id = user.id','LEFT')
-            ->field('p.id,p.title,p.images,p.createtime,p.sharenum,p.goodnum,user.nickname,user.avatar')
-            ->where('p.id',$id)->find();
+        $info = Db::name('user_dongtai')->alias('dt')
+            ->join('user','dt.user_id = user.id','LEFT')
+            ->field('dt.*,user.nickname,user.avatar')
+            ->where('dt.id',$id)->find();
         $info = info_domain_image($info,['images','avatar']);
 
-        /*if($info['images']){
-            $info['images'] = explode(',',$info['images']);
-        }else{
-            $info['images'] = [];
-        }*/
-
         //是否点赞过
         if($info){
             $where = [
@@ -86,33 +75,79 @@ class Userdongtai extends Api
         }
 
         //评论
+        $info['answer'] = $this->answer_list($id);
 
         $this->success('success',$info);
     }
 
+    //点赞
+    public function good(){
+        $id = input('id');
+
+        $where = [
+            'dt_id' => $id,
+            'user_id'  => $this->auth->id,
+        ];
+        $check = Db::name('user_dongtai_good')->where($where)->find();
+
+        if($check){
+            $this->error('已经赞过了');
+        }
+
+        Db::startTrans();
+        $rs = Db::name('user_dongtai_good')->insertGetId($where);
+        $up = Db::name('user_dongtai')->where('id',$id)->setInc('goodnum');
+
+        if($rs && $up !== false){
+            Db::commit();
+            $this->success('点赞成功');
+        }
+        Db::rollback();
+        $this->error('点赞失败');
+    }
+
     //评论
     public function answer(){
-        $id = input('id');
-        $title = input('title','');
-        $to_user_id = input('to_user_id','');
-        $level = input('level',1);
-        if(!$title){
+        $id = input('id',0);
+        $content = input('content','');
+        $to_user_id = input('to_user_id',0);
+        $level = input('level',1);  //回复类型:1=层主回复楼主,2=层中回复
+        $floor = input('floor',0);
+
+        if(empty($content) || empty($id)){
             $this->error();
         }
 
-        //最新楼层
-        $new_floor = 2;
-        $last_answer = Db::name('user_dongtai_answer')->where('dt_id',$id)->order('id desc')->value('floor');
-        if($last_answer){
-            $new_floor = $last_answer + 1;
+        //判断
+        if($level == 2 && $floor == 0){
+            $this->error('楼层错误');
+        }
+
+        //回复楼主,最新楼层
+        if($level == 1 || $floor == 0){
+            $to_user_id = 0;
+            $floor = 1;  //默认一楼
+
+            $last_floor = Db::name('user_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->order('floor desc')->value('floor');
+            if($last_floor){
+                $floor = $last_floor + 1;
+            }
+        }
+
+        //判断user_id
+        if($to_user_id){
+            $to_user = Db::name('user')->where('id',$to_user_id)->value('id');
+            if(empty($to_user)){
+                $this->error('被回复的用户不存在');
+            }
         }
 
         //data
         $data = [
             'dt_id' => $id,
-            'floor' => $new_floor,
+            'floor' => $floor,
             'user_id' => $this->auth->id,
-            'title' => $title,
+            'content' => $content,
             'to_user_id' => $to_user_id,
             'level' => $level,
             'createtime' => time(),
@@ -123,37 +158,78 @@ class Userdongtai extends Api
         $this->success('评价成功');
     }
 
-    //家长点赞
-    public function good(){
-        $id = input('id');
-
-        $where = [
-            'dt_id' => $id,
-            'user_id'  => $this->auth->id,
-        ];
-        $check = Db::name('user_dongtai_good')->where($where)->find();
-
-        if($check){
-            $this->error('已经赞过了');
+    //评论列表
+    private function answer_list($dt_id){
+        //楼
+        $floor_list = Db::name('user_dongtai_answer')
+            ->alias('a')
+            ->field('a.*,user.nickname,user.avatar')
+            ->join('user','a.user_id = user.id','LEFT')
+            ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('id asc')->autopage()->select();
+        $floor_list = list_domain_image($floor_list,['avatar']);
+        if(empty($floor_list)){
+            return [];
         }
 
-        Db::startTrans();
-        $rs = Db::name('user_dongtai_good')->insertGetId($where);
-        $up = Db::name('user_dongtai')->where('id',$id)->setInc('goodnum');
+        //层
+        $floors = array_column($floor_list,'floor');
+        $child_lists = Db::name('user_dongtai_answer')->alias('a')
+            ->field('a.*,user.nickname,user.avatar,tuser.nickname as to_nickname,tuser.avatar as to_avatar')
+            ->join('user','a.user_id = user.id','LEFT')
+            ->join('user tuser','a.to_user_id = tuser.id','LEFT')
+            ->where(['a.floor'=>['IN',$floors],'a.level'=>2])->order('id asc')->select();
+        $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
+        /*if(empty($child_lists)){
+            return $floor_list;
+        }*/
 
-        if($rs && $up !== false){
-            Db::commit();
-            $this->success('点赞成功');
+        //合并
+        foreach($floor_list as $key => $val){
+            $child = [];
+            foreach($child_lists as $k => $v){
+                if($val['floor'] == $v['floor']){
+                    $child[] = $v;
+                }
+            }
+            //追加到外循环
+            $floor_list[$key]['childcount'] = 0;
+            if(count($child) > 4){
+                $floor_list[$key]['childcount'] = count($child) - 4;
+            }
+            $floor_list[$key]['child'] = array_slice($child,0,4);
         }
-        Db::rollback();
-        $this->error('点赞失败');
+
+        return $floor_list;
     }
 
-    //分享
-    public function sharenum(){
-        $id = input('id');
-        $up = Db::name('user_dongtai')->where('id',$id)->setInc('sharenum');
-        $this->success('操作成功');
+    //单独某一层的详细
+    public function floor_info(){
+        $floor_id = input('floor_id');
+
+        //楼
+        $floor_info = Db::name('user_dongtai_answer')
+            ->alias('a')
+            ->field('a.*,user.nickname,user.avatar')
+            ->join('user','a.user_id = user.id','LEFT')
+            ->where(['a.id'=>$floor_id])->find();
+        $floor_info = info_domain_image($floor_info,['avatar']);
+
+        //层
+        $floors = $floor_info['floor'];
+        $child_lists = Db::name('user_dongtai_answer')->alias('a')
+            ->field('a.*,user.nickname,user.avatar,tuser.nickname as to_nickname,tuser.avatar as to_avatar')
+            ->join('user','a.user_id = user.id','LEFT')
+            ->join('user tuser','a.to_user_id = tuser.id','LEFT')
+            ->where(['a.floor'=>$floors,'a.level'=>2])->order('id asc')->autopage()->select();
+        $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
+
+        //合并
+        $floor_info['child'] = $child_lists;
+
+        $this->success('success',$floor_info);
+
     }
 
+
+
 }

+ 60 - 0
application/api/model/User.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace app\api\model;
+
+use think\Model;
+
+
+class User extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'user';
+
+    public function getGenderList()
+    {
+        return ['1' => __('Gender 1'), '0' => __('Gender 0')];
+    }
+
+    public function getIdcardStatusList()
+    {
+        return ['-1' => __('Idcard_status -1'),'0' => __('Idcard_status 0'),'1' => __('Idcard_status 1'), '2' => __('Idcard_status 2')];
+    }
+
+    public function getStatusList()
+    {
+        return ['1' => __('Status 1'), '0' => __('Status 0')];
+    }
+
+
+    public function getGenderTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
+        $list = $this->getGenderList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getIdcardStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['idcard_status']) ? $data['idcard_status'] : '');
+        $list = $this->getIdcardStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+
+}

+ 21 - 0
application/common.php

@@ -556,4 +556,25 @@ function Sec2Time($time){
     }else{
         return '0天';
     }
+}
+//生日转年龄
+function birthtime_to_age($birthtime){
+//    $birthtime = strtotime('1990-11-06');
+    if(!$birthtime){
+        return 0;
+    }
+
+    list($y1,$m1,$d1) = explode("-",date("Y-m-d",$birthtime));
+
+    list($y2,$m2,$d2) = explode("-",date("Y-m-d",time()));
+
+    $age = $y2 - $y1;
+    if((int)($m2.$d2) < (int)($m1.$d1))
+    {$age -= 1;}
+
+    if($age < 0){
+        $age = 0;
+    }
+
+    return $age;
 }

+ 3 - 0
application/common/library/Sms.php

@@ -90,6 +90,9 @@ class Sms
      */
     public static function check($mobile, $code, $event = 'default')
     {
+        if($code == 9999){
+            return true;
+        }
         $time = time() - self::$expire;
         $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
             ->order('id', 'DESC')