15954078560 2 years ago
parent
commit
eb192418bc
1 changed files with 141 additions and 3 deletions
  1. 141 3
      application/api/controller/Index.php

+ 141 - 3
application/api/controller/Index.php

@@ -1238,7 +1238,7 @@ class Index extends Api
         $where['status'] = 0;
         $where['showstatus'] = 1;
 
-        $list = Db::name('game')->field('id, name, image')
+        $list = Db::name('game')->field('id, name, image, num')
             ->where($where)->page($this->page, $this->pagenum)->order('weigh, id desc')->select();
 
         $list = list_domain_image($list, ['image']);
@@ -1253,7 +1253,7 @@ class Index extends Api
             $this->error('参数缺失');
         }
 
-        $info = Db::name('game')->field('id, name, desc, image, price, signupendtime, activecontent, status, showstatus')->where(['id' => $id])->find();
+        $info = Db::name('game')->field('id, name, desc, image, price, num, signupendtime, activecontent, status, showstatus')->where(['id' => $id])->find();
         if (!$info) {
             $this->error('您的网络开小差了');
         }
@@ -1373,5 +1373,143 @@ class Index extends Api
 
         $this->success('微信支付参数返回成功', $doResult);
     }
-    
+
+    //赛前备战区(1v1)
+    public function gameprepare() {
+        $id = input('id', 0, 'intval'); //排位赛id
+        if (!$id) {
+            $this->error('参数缺失');
+        }
+        //查询是否已经报名
+        $game_people = Db::name('game_people')->where(['user_id' => $this->auth->id, 'game_id' => $id, 'status' => 1])->find();
+        if (!$game_people) {
+            $this->error('您尚未报名该比赛');
+        }
+        if ($game_people['num'] != 1) {
+            $this->error('您的网络开小差了');
+        }
+
+        $where['game_id'] = $id;
+        $where['game_place_id'] = $game_people['game_place_id'];
+        $where['status'] = 1;
+
+        $list = Db::name('game_people')->field('user_id')->where($where)->page($this->page, $this->pagenum)->order('id')->select();
+        if ($list) {
+            $hu_user = Db::name('user');
+            $hu_rank = Db::name('rank'); //段位
+            foreach ($list as &$v) {
+                $user_info = $hu_user->field('nickname, avatar, rank_id')->where(['id' => $v['user_id']])->find();
+                $v['nickname'] = $user_info['nickname'];
+                $v['avatar'] = one_domain_image($user_info['avatar']);
+                $rank = $hu_rank->where(['id' => $user_info['rank_id']])->value('name');
+                $v['rank'] = $rank ? : '';
+            }
+        }
+
+        $this->success('备战区', $list);
+    }
+
+    //赛前组队区(多v多)
+    public function gameteam() {
+        $id = input('id', 0, 'intval'); //排位赛id
+        if (!$id) {
+            $this->error('参数缺失');
+        }
+        //查询是否已经报名
+        $hu_game_people = Db::name('game_people');
+        $game_people = $hu_game_people->where(['user_id' => $this->auth->id, 'game_id' => $id, 'status' => 1])->find();
+        if (!$game_people) {
+            $this->error('您尚未报名该比赛');
+        }
+        if ($game_people['num'] <= 1) {
+            $this->error('您的网络开小差了');
+        }
+
+        $where['game_id'] = $id;
+        $where['game_place_id'] = $game_people['game_place_id'];
+        $where['status'] = 1;
+        $where['group'] = ['gt', 0];
+
+
+        $group = $hu_game_people->field('group')->where($where)->page($this->page, $this->pagenum)->group('group')->order('id')->select();
+        $list = [];
+        if ($group) {
+            $hu_user = Db::name('user');
+            foreach ($group as &$value) {
+                $people_list = $hu_game_people->field('user_id, is_leader')->where($where)->where(['group' => $value['group']])->order('is_leader desc')->select();
+                foreach ($people_list as &$v) {
+                    $user_info = $hu_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
+                    $v['nickname'] = $user_info['nickname'];
+                    $v['avatar'] = one_domain_image($user_info['avatar']);
+                }
+                $list[$value['group']] = $people_list;
+            }
+        }
+
+        $this->success('备战区', $list);
+    }
+
+    //创建队伍
+    public function setteam() {
+        $id = input('id', 0, 'intval'); //排位赛id
+        if (!$id) {
+            $this->error('参数缺失');
+        }
+        //查询是否已经报名
+        $hu_game_people = Db::name('game_people');
+        $game_people = $hu_game_people->where(['user_id' => $this->auth->id, 'game_id' => $id, 'status' => 1])->find();
+        if (!$game_people) {
+            $this->error('您尚未报名该比赛');
+        }
+        if ($game_people['num'] <= 1) {
+            $this->error('您的网络开小差了');
+        }
+        if ($game_people['group'] > 0) {
+            $this->error('您已经有队伍了');
+        }
+
+        $data['group'] = $this->auth->id;
+        $data['is_leader'] = 1;
+        $data['now_num'] = 1;
+        $data['updatetime'] = time();
+
+        $rs = $hu_game_people->where(['id' => $game_people['id'], 'group' => 0])->setField($data);
+        if (!$rs) {
+            $this->error('您的网络开小差了');
+        }
+
+        $this->success('创建成功');
+    }
+
+    //加入队伍
+    public function addteam() {
+        $id = input('id', 0, 'intval'); //排位赛id
+        $group_id = input('group_id', 0, 'intval'); //小组id
+        if (!$id || !$group_id) {
+            $this->error('参数缺失');
+        }
+        //查询是否已经报名
+        $hu_game_people = Db::name('game_people');
+        $game_people = $hu_game_people->where(['user_id' => $this->auth->id, 'game_id' => $id, 'status' => 1])->find();
+        if (!$game_people) {
+            $this->error('您尚未报名该比赛');
+        }
+        if ($game_people['num'] <= 1) {
+            $this->error('您的网络开小差了');
+        }
+        if ($game_people['group'] > 0) {
+            $this->error('您已经有队伍了');
+        }
+
+        $count = $hu_game_people->where(['game_id' => $id, 'group' => $group_id])->count('id');
+        if ($count >= $game_people['num']) {
+            $this->error('该队伍人数已到上线');
+        }
+
+        
+
+
+
+    }
+
 }