|
@@ -1501,15 +1501,83 @@ class Index extends Api
|
|
|
$this->error('您已经有队伍了');
|
|
|
}
|
|
|
|
|
|
- $count = $hu_game_people->where(['game_id' => $id, 'group' => $group_id])->count('id');
|
|
|
- if ($count >= $game_people['num']) {
|
|
|
+ $group_info = $hu_game_people->where(['game_id' => $id, 'group' => $group_id])->find();
|
|
|
+ if (!$group_info) {
|
|
|
+ $this->error('该队伍已经解散');
|
|
|
+ }
|
|
|
+ if ($group_info['now_num'] >= $game_people['num']) {
|
|
|
$this->error('该队伍人数已到上线');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //开启redis
|
|
|
+ $redis = new \Redis();
|
|
|
+ $redis->connect(config('redis_host'), config('redis_port'));
|
|
|
+ if (config('redis_pwd')) {
|
|
|
+ $redis->auth(config('redis_pwd'));
|
|
|
+ }
|
|
|
+ if(config('redis_selectdb') > 0){
|
|
|
+ $redis->select(config('redis_selectdb'));
|
|
|
+ }
|
|
|
+ //是否可以操作: 1可以 其他 不可以
|
|
|
+ $game_people_status = $redis->lPop('game_people' . $id . '_' . $group_id);
|
|
|
+ if ($game_people_status != 1) {
|
|
|
+ $this->error('网络繁忙,请稍后再试');
|
|
|
+ }
|
|
|
|
|
|
+ $data['group'] = $group_id;
|
|
|
+ $data['now_num'] = $group_info['now_num'] + 1;
|
|
|
+ $data['updatetime'] = time();
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+ //修改信息
|
|
|
+ $rs = $hu_game_people->where(['id' => $game_people['id'], 'group' => 0])->setField($data);
|
|
|
+ if (!$rs) {
|
|
|
+ Db::rollback();
|
|
|
+ $redis->rPush('game_people' . $id . '_' . $group_id, 1);
|
|
|
+ $this->error('您的网络开小差了');
|
|
|
+ }
|
|
|
+ //修改队伍其他信息
|
|
|
+ $rt = $hu_game_people->where(['game_id' => $id, 'group' => $group_id, 'now_num' => $group_info['now_num']])->setField('now_num', $group_info['now_num'] + 1);
|
|
|
+ if (!$rt) {
|
|
|
+ Db::rollback();
|
|
|
+ $redis->rPush('game_people' . $id . '_' . $group_id, 1);
|
|
|
+ $this->error('您的网络开小差了');
|
|
|
+ }
|
|
|
|
|
|
+ Db::commit();
|
|
|
+ $this->success('加入成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //排行榜
|
|
|
+ public function rankinglist() {
|
|
|
+ $city_id = input('city_id', 0, 'intval'); //市id
|
|
|
+ $area_id = input('area_id', 0, 'intval'); //区id
|
|
|
+
|
|
|
+ if (!$city_id && !$area_id) {
|
|
|
+ $this->error('请选择查看地区');
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if ($city_id) {
|
|
|
+ $where['city_id'] = $city_id;
|
|
|
+ }
|
|
|
+ if ($area_id) {
|
|
|
+ $where['area_id'] = $area_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = Db::name('user')->field('id, nickname, avatar, win_num, lose_num, power_value, rank_id')->where($where)->page($this->page, $this->pagenum)->order('power_value desc')->select();
|
|
|
+
|
|
|
+ $list = list_domain_image($list, ['avatar']);
|
|
|
+ if ($list) {
|
|
|
+ $hu_rank = Db::name('rank');
|
|
|
+ foreach ($list as &$v) {
|
|
|
+ $rank_name = $hu_rank->where(['id' => $v['rank_id']])->value('name');
|
|
|
+ $v['rank_name'] = $rank_name ? : '';
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ $this->success('排行榜', $list);
|
|
|
}
|
|
|
|
|
|
}
|