Browse Source

调通接口

lizhen_gitee 3 years ago
parent
commit
e8c647bd97

+ 410 - 2
application/api/controller/Index.php

@@ -3,13 +3,16 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-
+use fast\Random;
+use \think\Log;
+use Redis;
+use app\common\library\Sms as Smslib;
 /**
  * 首页接口
  */
 class Index extends Api
 {
-    protected $noNeedLogin = ['*'];
+    protected $noNeedLogin = ['index','contactus','tcpTest','getAppShare','getWebsiteInfo','getUserCharmRankList','getPartyHotList','searchUsers','getInviteCode','getEdition','getInviteImg','getWebsiteInfoForMini','getBankList','getSwitch','getBootAnimation'];
     protected $noNeedRight = ['*'];
 
     /**
@@ -18,6 +21,411 @@ class Index extends Api
      */
     public function index()
     {
+        // 强制关闭需要退出正在房间的用户
+        $tenim = new \app\api\controller\Tenim();
+        $tenim->outMemberFromRoom(4);
         $this->success('请求成功');
     }
+
+
+//    /**
+//     * 生成不重复的随机数字字母组合
+//     */
+//    function getUinqueNo($length = 8) {
+//        $newid = Random::build("alnum",$length);
+////        if(in_array($newid,$nos)) {
+////            $this->getUinqueNo(8);
+////        }
+//        return $newid;
+//    }
+
+    /**
+     * 获取用户协议等
+     */
+    public function getWebsiteInfo() {
+        $params = $this->request->request("params"); //内容
+        if($params == "boxGiftLogo") {
+            echo $this->success("获取成功!",$this->httpurl(config("site.".$params)));
+            exit;
+        }
+        echo "<html><body>";
+        echo config("site.".$params);
+        echo "</body></html>";exit;
+    }
+
+    /**
+     * 获取用户协议等 小程序
+     */
+    public function getWebsiteInfoForMini() {
+        $params = $this->request->request("params"); //内容
+        $res = config("site.".$params);
+        if($params == "boxGiftLogo") $res = $this->httpurl(config("site.".$params));
+        $this->success("获取成功!",$res);
+    }
+
+    /**
+     * 联系我们
+     */
+    public function contactus() {
+        $list = \app\common\model\Config::where(["group"=>"basic","name"=>["in",["email","mobile"]]])->select();
+        $data = [];
+        foreach($list as $k => $v) {
+            $v["name"] == "email" && $data["email"] = $v["value"];
+            $v["name"] == "mobile" && $data["mobile"] = $v["value"];
+        }
+        $this->success("获取成功!",$data);
+    }
+
+    /*
+     * 获取系统消息列表
+     */
+    public function getMessage() {
+        $page = $this->request->request('page',1); // 分页
+        $pageNum = $this->request->request('pageNum',10); // 分页
+        // 分页搜索构建
+        $pageStart = ($page-1)*$pageNum;
+
+        $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
+        $user_id = $this->auth->id;
+
+        $obj = \app\common\model\Message::where(["user_id"=>$user_id])->order("createtime","desc")->limit($pageStart,$pageNum);
+        if($flag == 1) {
+            $list = $obj->find();
+            $list || $list = [];
+            $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
+        } else {
+            $list = $obj->select();
+            if($list) foreach($list as $k => &$v) {
+                $v["createtime"] = $this->get_last_time($v["createtime"]);
+            }
+        }
+
+        $this->success("获取成功!",$list);
+
+    }
+
+    /**
+     * 删除系统消息
+     */
+    public function delMessage() {
+        $id = $this->request->request("id",0,"intval"); //消息ID
+        if($id <= 0) {
+            $this->error("参数传入错误!");
+        }
+        $res = \app\common\model\Message::where(["id"=>$id,"user_id"=>$this->auth->id])->delete();
+
+        if($res) {
+            $this->success("删除成功!");
+        } else {
+            $this->error("删除失败!");
+        }
+    }
+
+    /**
+     * 获取主播魅力值排行
+     */
+    public function getUserCharmRankList() {
+        $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
+        if(!in_array($time,[1,2,3,4])) {
+            $this->error("参数传入错误!");
+        }
+
+        $hour = strtotime(date("Y-m-d H:00:00"));
+        $today = strtotime(date("Y-m-d 00:00:00"));
+        $weekend = strtotime('monday this week');
+//        $weekend = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
+        $month = strtotime(date("Y-m-01 00:00:00"));
+        // 剩余时间
+        $thistime = time();
+        switch ($time) {
+            case 1:
+                $redtime = 3600-($thistime - $hour);
+                break;
+            case 2:
+                $redtime = 3600*24-($thistime - $today);
+                break;
+            case 3:
+                $redtime = 3600*24*7-($thistime - $weekend);
+                break;
+            case 4:
+                $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
+                $redtime = ($monthend - $month)-($thistime - $month);
+                break;
+        }
+
+        $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
+        $where = [];
+        $where["a.createtime"] = ["gt",$timeArr[$time]];
+        $list = \app\common\model\UserCharmRank::alias("a")
+            ->field("p.id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level,u.is_live")
+            ->where($where)
+            ->join("hx_user u","u.id = a.user_id")
+            ->join("hx_party p","p.user_id = a.user_id")
+            ->group("a.user_id")
+            ->order("charm","desc")
+            ->limit(100)
+            ->select();
+
+        $data = [];
+        $data["redtime"] = $redtime;
+        $data["data"] = $list;
+        $this->success("获取成功!",$data);
+    }
+
+    /**
+     * 获取派对热度排序
+     */
+    public function getPartyHotList() {
+        // 剩余时间
+        $thistime = time();
+        $hour = strtotime(date("Y-m-d H:00:00"));
+        $redtime = 3600-($thistime - $hour);
+
+        $where = [];
+        $where["a.createtime"] = ["gt",$hour];
+        $where["p.room_type"] = 1;
+        $list = \app\common\model\PartyHot::alias("a")
+            ->field("sum(a.hot) as hot,p.id,u.avatar,p.party_name,p.party_logo")
+            ->where($where)
+            ->join("hx_party p","p.id = a.party_id")
+            ->join("hx_user u","u.id = p.user_id")
+            ->group("a.party_id")
+            ->order("hot","desc")
+            ->limit(100)
+            ->select();
+
+        $data = [];
+        $data["redtime"] = $redtime;
+        $data["data"] = $list;
+        $this->success("获取成功!",$data);
+    }
+
+    /**
+     * 首页搜索
+     */
+    public function searchUsers() {
+        $search = $this->request->request("search"); //关键词筛选
+        if(!$search) {
+            $this->error("请输入搜索内容!");
+        }
+        // 搜索派对
+        global $whereOr;
+        $where = [];
+        $whereOr["party_id"] = $search;
+        $whereOr["party_name"] = ["like","%$search%"];
+        $where["room_type"] = 1;
+        $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
+            ->where($where)
+            ->where(function ($query) {
+                global $whereOr;
+                $query->whereOr($whereOr);
+            })->order("party_hot","desc")->select();
+
+
+        // 搜索直播间
+        global $whereOrlive;
+        $where = [];
+        $whereOrlive["party_id"] = $search;
+        $whereOrlive["party_name"] = ["like","%$search%"];
+        $where["room_type"] = 2;
+        $liveList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
+            ->where($where)
+            ->where(function ($query) {
+                global $whereOrlive;
+                $query->whereOr($whereOrlive);
+            })
+            ->order("party_hot","desc")->select();
+        // 相关用户
+        $where = [];
+        $where["a.nickname"] = ["like","%$search%"];
+        $where["a.u_id"] = $search;
+        $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
+            ->join("hx_view_fans f","f.user_id = a.id","left")
+            ->order("a.is_online,a.noble,a.level")
+            ->whereOr($where)->select();
+        $res = [];
+        $res["partylist"] = $partyList;
+        $res["livelist"] = $liveList;
+        $res["userlist"] = $userList;
+
+        $this->success("获取成功!",$res);
+    }
+
+    /**
+     * 获取下载二维码和邀请码
+     */
+    public function getInviteCode() {
+        // 获取二维码
+        $qrcode = $this->httpurl(config("site.qrcode"));
+        $miniqrcode = $this->httpurl(config("site.miniqrcode"));
+        // 获取用户邀请码
+        $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
+        $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
+        $downlowdLink = $host."/index/index/appJump?t=wlt".rand(10,999).Random::alpha(8);
+        $this->success("获取成功!",["qrcode"=>$qrcode,"miniqrcode"=>$miniqrcode,"inviteCode"=>$inviteCode,"downlowdLink"=>$downlowdLink]);
+    }
+
+    /**
+     * 获取app分享海报
+     */
+    public function getAppShare() {
+        $this->success("获取成功!",["url"=>$this->httpurl(config("site.appShare"))]);
+    }
+
+    /**
+     * 获取开机动画(暂时关闭)
+     */
+    private function getBootAnimation() {
+        $this->success("获取成功!",["url"=>$this->httpurl(config("site.bootAnimationUrl")),"time"=>floatval(config("site.bootAnimationTime"))]);
+    }
+
+    /**
+     * 获取版本更新信息
+     */
+    public function getEdition() {
+        // 获取二维码
+        $is_force = config("site.is_force");
+        $apkUrl = config("site.apkUrl");
+        $apkName = config("site.apkName");
+        $desc = config("site.desc");
+        $versionCode = config("site.versionCode");
+        $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
+    }
+
+    /**
+     * 获取邀请图片
+     */
+    public function getInviteImg() {
+        $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
+        if(!in_array($plat,[1,2])) $this->error("参数错误");
+        // 获取用户的邀请码
+        $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
+
+        // 文字图片合成
+        $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
+        $img = imagecreatefromstring(file_get_contents($bigImgPath));
+        //字体文件
+        $font = realpath('./assets/fonts/lato/lato-black.ttf');
+
+        //字体颜色(RGB)
+        $black = imagecolorallocate($img, 217, 76, 41);
+        //字体大小
+        $fontSize = 30;
+        //旋转角度
+        $circleSize = 0;
+        //左边距
+        $left = 275;
+        //上边距
+        $top = 540;
+        imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
+        $filename = date("YmdH").".jpeg";
+        $path = "/uploads/qrcode/".$filename;
+        $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
+        list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
+        switch ($bgType) {
+            case 1://gif
+                header('Content-Type:image/gif');
+                imagegif($img,$file);
+                break;
+            case 2://jpg
+                header('Content-Type:image/jpg');
+                imagejpeg($img,$file);
+                break;
+            case 3://jpg
+                header('Content-Type:image/png');
+                imagepng($img,$file);
+                break;
+            default:
+                break;
+        }
+        //销毁照片
+        imagedestroy($img);
+
+        // 图片和二维码合成
+        $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
+
+
+        $background = $file;
+        $target = $this->httpurl($qrcode);
+
+        $background_iamge = imagecreatefromstring(file_get_contents($background));
+        $target_image = imagecreatefromstring(file_get_contents($target));
+        list($target_width, $target_height, $target_type) = getimagesize($target);
+        imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
+        list($background_width, $background_height, $background_type) = getimagesize($background);
+        switch ($background_type) {
+            case 1://gif
+                header('Content-Type:image/gif');
+                imagegif($background_iamge,$file);
+                break;
+            case 2://jpg
+                header('Content-Type:image/jpg');
+                imagejpeg($background_iamge,$file);
+                break;
+            case 3://jpg
+                header('Content-Type:image/png');
+                imagepng($background_iamge,$file);
+                break;
+            default:
+                break;
+        }
+        $savepath = $this->httpurlLocal($path);
+
+        $this->success("获取成功!",$savepath);
+    }
+
+    /**
+     * 获取银行列表
+     */
+    public function getBankList() {
+        $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
+    }
+
+    /**
+     * 获取开关配置
+     */
+    public function getSwitch() {
+        $this->success("获取成功!",["switch"=>config("site.switch")]);
+    }
+
+    /**
+     * 评论时间转换
+     * @param null $time
+     * @return false|string
+     */
+    private function get_last_time($time = NULL) {
+        $text = '';
+        $time = $time === NULL || $time > time() ? time() : intval($time);
+        $t = time() - $time; //时间差 (秒)
+        $y = date('Y', $time)-date('Y', time());//是否跨年
+        switch($t){
+            case $t == 0:
+                $text = '刚刚';
+                break;
+            case $t < 60:
+                $text = $t . '秒前'; // 一分钟内
+                break;
+            case $t < 60 * 60:
+                $text = floor($t / 60) . '分钟前'; //一小时内
+                break;
+            case $t < 60 * 60 * 24:
+                $text = floor($t / (60 * 60)) . '小时前'; // 一天内
+                break;
+            case $t < 60 * 60 * 24 * 3:
+                $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
+                break;
+            case $t < 60 * 60 * 24 * 30:
+                $text = date('m月d日 H:i', $time); //一个月内
+                break;
+            case $t < 60 * 60 * 24 * 365&&$y==0:
+                $text = date('m月d日', $time); //一年内
+                break;
+            default:
+                $text = date('Y年m月d日', $time); //一年以前
+                break;
+        }
+
+        return $text;
+    }
+
 }

+ 16 - 12
application/api/controller/Party.php

@@ -276,7 +276,7 @@ class Party extends Common
         $thispage = $this->request->request('thispage',1,"intval"); // 当前页数
         $pagenum = $this->request->request('pagenum',10,"intval"); // 每页显示条数0=不做分页
         $type_id = $this->request->request('type_id'); // 派对类型
-        $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
+        $room_type = 1; // 房间类型:1=派对,2=直播
         $is_recommend = $this->request->request('is_recommend'); // 推荐0=否1=是
         $all = $this->request->request('all'); // 全部分类0=否1=是
         $index = $this->request->request('index',0); // 全部分类0=否1=是
@@ -302,8 +302,8 @@ class Party extends Common
             $where["a.is_online"] = 1;
             $where["a.room_type"] = $room_type;
             $sqlPartyList = $partyModel->alias("a")->field("a.*,b.name as type_name")
-                ->join("hx_party_type b","a.party_type = b.id","left")->where($where)->select();
-            $userList = $userModel->field("id,nickname,avatar")->where(["status"=>"normal"])->select();
+                ->join("party_type b","a.party_type = b.id","left")->where($where)->select();
+            $userList = $userModel->field("id,nickname,avatar")->where(["status"=>1])->select();
             $userInfoArr = [];
             if($userList) foreach($userList as $k => $v) $userInfoArr[$v["id"]] = $v;
             if($sqlPartyList) {
@@ -730,7 +730,7 @@ class Party extends Common
      * 派对内搜索用户
      */
     public function searchUserParty() {
-        $u_id = $this->request->request('u_id',0,"intval"); // 用户u_id
+        $username = $this->request->request('username',0,"intval"); // 用户u_id
         $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
 
 //        $redis = new Redis();
@@ -743,8 +743,8 @@ class Party extends Common
 
         $userModel = new \app\common\model\User();
         $where = [];
-        $where["u_id"] = $u_id;
-        $userInfo = $userModel->field("id,u_id,avatar,nickname,level,gender")->where($where)->select();
+        $where["username"] = $username;
+        $userInfo = $userModel->field("id,username,avatar,nickname,level,gender")->where($where)->select();
 
         return $this->success("查询成功!",$userInfo);
     }
@@ -941,7 +941,7 @@ class Party extends Common
         $party_type = $this->request->request('party_type'); // 使用场景
         $is_screen = $this->request->request('is_screen'); // 是否关闭公屏:1=是,0=否
         $on_model = $this->request->request('on_model'); // 上麦模式:1=自由模式,2=麦序模式
-        $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
+        $room_type = 1; // 房间类型:1=派对,2=直播
         $background = $this->request->request('background'); // 派对背景
         if (!$party_id || (!$party_name && !$party_logo && !$party_pass && !$party_type && !$is_screen && !$on_model && !$background)) {
             $this->error(__('Invalid parameters'));
@@ -986,10 +986,12 @@ class Party extends Common
      * 获取派对背景
      */
     public function getDefaultBackground() {
-        $room_type = $this->request->request('room_type',1); // 房间类型
+        /*$room_type = $this->request->request('room_type',1); // 房间类型
         if (!in_array($room_type,[1,2])) {
             $this->error(__('Invalid parameters'));
-        }
+        }*/
+
+        $room_type = 1;
 
         $this->success("获取成功!",\app\common\model\PartyBackground::where(["room_type"=>$room_type])->select());
     }
@@ -1124,7 +1126,8 @@ class Party extends Common
      */
     public function savePartyNotice() {
         $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
-        $room_type = $this->request->request('room_type',1); // 房间类型:1=派对2=直播
+//        $room_type = $this->request->request('room_type',1); // 房间类型:1=派对2=直播
+        $room_type = 1; // 房间类型:1=派对2=直播
         $party_notice = $this->request->request('party_notice'); // 公告标题
         $party_notice_detail = $this->request->request('party_notice_detail'); // 公告内容
         if (!$party_id || !$party_notice || !$party_notice_detail) {
@@ -1251,8 +1254,9 @@ class Party extends Common
      * 获取派对类型
      */
     public function getPatyType() {
-        $room_type = $this->request->request("room_type",1);//
-        if (!in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
+//        $room_type = $this->request->request("room_type",1);//
+        $room_type = 1;
+//        if (!in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
         $partytypeModel = new \app\common\model\PartyType();
         $partytypeList = $partytypeModel->where(["room_type"=>$room_type])->select();
         $this->success("获取成功!",$partytypeList);

+ 61 - 0
application/api/controller/Usercenter.php

@@ -565,6 +565,67 @@ class Usercenter extends Api
         return $all_result;
     }
 
+    /**
+     * 是否关注
+     */
+    public function isFollows() {
+        $user_id = $this->request->request("user_id",0,"intval");
+
+        if (!$user_id || $user_id<=0) {
+            $this->error(__('Invalid parameters'));
+        }
+
+        $map = [
+            'uid' => $this->auth->id,
+            'follow_uid' => $user_id,
+        ];
+        $check = Db::name('user_follow')->where($map)->find();
+
+        $data = [];
+        if($check){
+            $data["is_show_follow"] = 0;
+        }else{
+            $data["is_show_follow"] = 1;
+        }
+
+        $this->success("获取成功!",$data);
+    }
+
+    /**
+     * 获取主播技能分类
+     */
+    public function getAnchorType() {
+        $this->success("获取成功!",\app\common\model\UserAnchorType::select());
+    }
+
+    /**
+     * 主播申请
+     */
+    public function anchorApply() {
+        $this->error('不需要申请');
+        /*$type_id = $this->request->request('type_id'); // 技能分类ID
+        $desc = $this->request->request('desc'); // 申请备注
+        if (!$type_id && !$desc) {
+            $this->error(__('Invalid parameters'));
+        }
+        $useranchorModel = new \app\common\model\UserAnchor();
+        $data = [];
+        $data["user_id"] = $this->auth->id;
+        $data["type_id"] = $type_id;
+        if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
+        $data["desc"] = $desc;
+        $data["createtime"] = time();
+        $res = $useranchorModel->insertGetId($data);
+        if($res) {
+            \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
+            $this->success("申请发送成功!");
+        } else {
+            $this->error("网络错误,请稍后重试");
+        }*/
+    }
+
+
+
 
     /**
      * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离