Browse Source

直播整个模块,其他小修改

lizhen_gitee 3 years ago
parent
commit
9410b76966

+ 1 - 0
application/api/controller/Baseconfig.php

@@ -21,6 +21,7 @@ class Baseconfig extends Api
             'android_update_version' => config('site.android_update_version'),
             'ios_update_num' => config('site.ios_update_num'),
             'ios_update_version' => config('site.ios_update_version'),
+            'livebc_type' => Db::name('livebc_type')->order('id asc')->select(),
         ];
 
         $this->success('success',$config);

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

@@ -85,6 +85,7 @@ class Gift extends Api
         $this->success("获取成功!", $list);
     }
 
+    //聊天送礼物
     public function givefift_typing() {
         // 接口防并发
         /*if (!$this->apiLimit(1, 1000)) {
@@ -163,7 +164,7 @@ class Gift extends Api
             $giftmoney = bcdiv($giftinfo['value'],$money_to_gold,2);
 
             $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
-            $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,54,'他人赠送礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,54,'获得礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
             if($wallet_rs['status'] === false){
                 Db::rollback();
                 $this->error($wallet_rs['msg']);

+ 1 - 1
application/api/controller/Index.php

@@ -157,7 +157,7 @@ class Index extends Api
         $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")
+            ->field("p.id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level")
             ->where($where)
             ->join("hx_user u","u.id = a.user_id")
             ->join("hx_party p","p.user_id = a.user_id")

+ 201 - 0
application/api/controller/Livebc.php

@@ -0,0 +1,201 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 视频直播间
+ */
+class Livebc extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    //直播列表
+    public function lists(){
+        $type_id = input('type_id','');
+
+        $map = [
+            'livebc.is_online' => 1,
+        ];
+        if(!empty($type_id)){
+            $map['livebc.type_id'] = $type_id;
+        }
+
+        $list = Db::name('livebc')->alias('livebc')->field('livebc.id,livebc.user_id,livebc.type_id,livebc.title,livebc.cityname,livebc.room_no,user.nickname,user.avatar')
+            ->join('user','livebc.user_id = user.id','LEFT')
+            ->where($map)
+            ->autopage()->select();
+
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success('success',$list);
+    }
+
+    //直播间详情
+    public function info(){
+        $id = input('id',0);
+        if(empty($id)){
+            $this->error();
+        }
+
+        $map = [
+            'livebc.id' => $id,
+        ];
+        $info = Db::name('livebc')->alias('livebc')->field('livebc.id,livebc.user_id,livebc.type_id,livebc.title,livebc.cityname,livebc.room_no,user.nickname,user.avatar')
+            ->join('user','livebc.user_id = user.id','LEFT')
+            ->where($map)
+            ->find();
+
+        if(!empty($info)){
+            $map = [
+                'uid' => $this->auth->id,
+                'follow_uid' => $info['user_id'],
+            ];
+            $is_follow = Db::name('user_follow')->where($map)->find();
+            $info['is_follow'] = $is_follow ? 1 : 0;
+
+            $info = info_domain_image($info,['avatar']);
+        }
+
+        $this->success('success',$info);
+    }
+
+    //开播
+    public function start(){
+        $type_id = input('type_id','');
+        $title   = input('title','');
+        $room_no = input('room_no','');
+        $cityname = input('cityname','');
+
+        if(empty($type_id) || empty($title) || empty($room_no)){
+            $this->error();
+        }
+
+        $data = [
+            'type_id' => $type_id,
+            'title'   => $title,
+            'room_no' => $room_no,
+            'cityname' => $cityname,
+            'is_online' => 1,
+            'updatetime' => time(),
+        ];
+
+        Db::startTrans();
+        $find = Db::name('livebc')->where('user_id',$this->auth->id)->lock(true)->find();
+        if($find){
+            $rs = Db::name('livebc')->where('id',$find['id'])->update($data);
+        }else{
+            $data['user_id'] = $this->auth->id;
+            $data['createtime'] = time();
+            $rs = Db::name('livebc')->insertGetId($data);
+        }
+        if($rs === false){
+            Db::rollback();
+            $this->error('开播失败');
+        }
+        //修改用户表直播状态
+        $rs_user = Db::name('user')->where('id',$this->auth->id)->update(['is_livebc' => 1]);
+        if($rs_user === false){
+            Db::rollback();
+            $this->error('开播失败');
+        }
+
+        Db::commit();
+        $this->success('success');
+    }
+
+    //直播送礼物
+    public function givefift() {
+        // 接口防并发
+        /*if (!$this->apiLimit(1, 1000)) {
+            $this->error(__('Operation frequently'));
+        }*/
+
+        $user_id = input('user_id');// 赠送对象
+        $gift_id = input('gift_id');// 礼物ID
+
+        if (!$user_id || !$gift_id )
+        {
+            $this->error();
+        }
+
+        // 不可以赠送给自己
+        if($this->auth->id == $user_id)
+        {
+            $this->error("不可以赠送给自己");
+        }
+
+        // 获取礼物信息
+        $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
+        if (!$giftinfo)
+        {
+            $this->error("请选择礼物");
+        }
+
+        //被赠送人信息
+        $touserinfo = Db::name('user')->where('id',$user_id)->find();
+        if (!$touserinfo)
+        {
+            $this->error("不存在的用户");
+        }
+
+        // 判断当前用户余额
+        $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
+        if($user_gold < $giftinfo['value'])
+        {
+            $this->error("您的金币余额不足");
+        }
+
+
+        Db::startTrans();
+
+
+        // 添加礼物赠送记录表
+        $data = [
+            'user_id' => $this->auth->id,
+            'user_to_id' => $user_id,
+            'gift_id' => $giftinfo['id'],
+            'gift_name' => $giftinfo['name'],
+            'number' => 1,
+            'price' => $giftinfo['value'],
+            'createtime' => time(),
+        ];
+        $log_id = Db::name('gift_user_livebc')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('赠送失败');
+        }
+
+
+        if($giftinfo['value'] > 0){
+
+            // 扣除当前用户余额
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$giftinfo['value'],55,'赠送礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+
+            // 添加赠送用户声币余额
+            $money_to_gold = config('site.money_to_gold');
+            $gift_plat_scale = config('site.gift_plat_scale');
+
+            $giftmoney = bcdiv($giftinfo['value'],$money_to_gold,2);
+
+            $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,56,'获得礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+        }
+
+
+        Db::commit();
+        $this->success('赠送成功');
+
+    }
+
+}

+ 1 - 1
application/api/controller/Party.php

@@ -1552,7 +1552,7 @@ class Party extends Common
 
                 // 添加赠送用户声币余额
                 if($getValue > 0){
-                    $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$getValue,52,'他人赠送礼物:'.$giftInfo["name"]);
+                    $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$getValue,52,'获得礼物:'.$giftInfo["name"]);
                     if($wallet_rs['status'] === false){
                         Db::rollback();
                         $this->error($wallet_rs['msg']);

+ 6 - 3
application/api/controller/Piaoliuping.php

@@ -39,16 +39,19 @@ class Piaoliuping extends Api
 
         //不能是自己发的
         $map = [
-            'user_id' => ['NEQ',$this->auth->id],
+            'plp.user_id' => ['NEQ',$this->auth->id],
         ];
 
         //不能重复
         $log_list = Db::name('piaoliuping_log')->where('user_id',$this->auth->id)->column('plp_id');
         if(!empty($log_list)){
-            $map['id'] = ['NOTIN',$log_list];
+            $map['plp.id'] = ['NOTIN',$log_list];
         }
 
-        $rs = Db::name('piaoliuping')->where($map)->orderRaw('rand()')->find();
+        $rs = Db::name('piaoliuping')->alias('plp')
+            ->field('plp.*,user.nickname,user.avatar')
+            ->join('user','plp.user_id = user.id','LEFT')
+            ->where($map)->orderRaw('rand()')->find();
 
         //记录查看记录
         if(!empty($rs)){

+ 1 - 1
application/api/controller/Tenim.php

@@ -608,7 +608,7 @@ exit;
                 } elseif($info["Action"] == "Logout" || $info["Action"] == "Disconnect") { // 用户退出 不需要管什么原因
                     // 更新用户在线状态为离线
                     \app\common\model\User::update(["is_online"=>0],["id"=>$info["To_Account"]]);
-                    \app\common\model\User::update(["is_live"=>0],["id"=>$info["To_Account"]]);
+                    //\app\common\model\User::update(["is_live"=>0],["id"=>$info["To_Account"]]);
 
                     // 获取用户在派对直播间情况信息
                     $redis = new Redis();

+ 1 - 1
application/extra/site.php

@@ -59,5 +59,5 @@ return array (
   'unlock_like_me' => '38',
   'intro_man_money' => '3',
   'intro_woman_money' => '4',
-  'plp_unvip_daysnum' => '2',
+  'plp_unvip_daysnum' => '-1',
 );

+ 5 - 2
application/extra/wallet.php

@@ -21,10 +21,13 @@ return [
         41 => '签到赠送金币',
 
         51 => '语聊间赠送礼物',
-        52 => '语聊间他人赠送礼物',
+        52 => '语聊间获得礼物',
 
         53 => '聊天赠送礼物',
-        54 => '聊天他人赠送礼物',
+        54 => '聊天获得礼物',
+
+        55 => '直播赠送礼物',
+        56 => '直播获得礼物',
 
         61 => '完成个人任务',
         62 => '解锁喜欢我的人',