field('count(1) as count,gid')->group('gid')->limit(50)->order('id desc')->select(); $room_type_log_data = []; foreach ($room_type_log_list as $k => $v) { $room_type_log_data[$v['gid']] = $v['count']; } $map = []; $map[] = ['is_show', '=', 1]; $map[] = ['is_delete', '=', 1]; $list = db::name('game')->field('gid,game_name,game_ico,game_ico1,sort')->where($map)->order('sort desc')->select(); foreach ($list as $k => &$v) { $v['game_ico'] = localpath_to_netpath($v['game_ico']); $v['game_ico1'] = localpath_to_netpath($v['game_ico1']); $v['click_num'] = 0; if (!empty($room_type_log_data[$v['gid']])) { $v['click_num'] = $room_type_log_data[$v['gid']]; } } if (!empty($room_type_log_data)) { array_multisort(array_column($list, 'click_num'), SORT_DESC, $list); } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } public function add_game_click_log($uid, $gid) { $map = []; $map[] = ['gid', '=', $gid]; $map[] = ['is_show', '=', 1]; $map[] = ['is_delete', '=', 1]; $info = db::name('game')->field('gid,game_name,cover_image,skill_image,game_ico,sort')->cache(10)->where($map)->find(); if (empty($info)) { return ['code' => 201, 'msg' => '信息不存在', 'data' => null]; } //记录用户访问日志 $data = []; $data['uid'] = $uid; $data['gid'] = $gid; $data['add_time'] = time(); $data['update_time'] = time(); db::name('game_click_log')->insert($data); return ['code' => 200, 'msg' => '添加成功', 'data' => null]; } //获取游戏详情 public function get_game_info($gid) { $map = []; $map[] = ['gid', '=', $gid]; $map[] = ['is_show', '=', 1]; $map[] = ['is_delete', '=', 1]; $info = db::name('game')->field('gid,game_name,cover_image,skill_image,game_ico,sort')->cache(10)->where($map)->find(); if (empty($info)) { return ['code' => 201, 'msg' => '信息不存在', 'data' => null]; } $info['game_ico'] = localpath_to_netpath($info['game_ico']); $info['cover_image'] = localpath_to_netpath($info['cover_image']); $info['skill_image'] = localpath_to_netpath($info['skill_image']); $skill_level_list = $this->get_game_skill_level_list($gid); $info['skill_level_list'] = $skill_level_list['data']; if (empty($info)) { return ['code' => 201, 'msg' => '信息不存在', 'data' => null]; } else { return ['code' => 200, 'msg' => '获取成功', 'data' => $info]; } } public function get_game_skill_level_list($gid) { $map = []; $map[] = ['gid', '=', $gid]; $map[] = ['is_delete', '=', 1]; $list = db::name('game_skill_level')->field('lid,gid,game_level_name')->where($map)->order('lid asc')->select(); if (empty($list)) { return ['code' => 201, 'msg' => '信息不存在', 'data' => null]; } else { return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } } public function get_game_skill_level_info($gid) { $map = []; $map[] = ['gid', '=', $gid]; $map[] = ['is_delete', '=', 1]; $info = db::name('game_skill_level')->field('gid,game_level_name')->where($map)->order('lid asc')->select(); if (empty($info)) { return ['code' => 201, 'msg' => '信息不存在', 'data' => null]; } else { return ['code' => 200, 'msg' => '获取成功', 'data' => $info]; } } }