You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

881 lines
30 KiB
PHP

<?php
namespace Home\Controller;
use OT\DataDictionary;
use User\Api\PromoteApi;
use Base\Service\PromoteService;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class PromoteCoinController extends BaseController
{
const MODEL_NAME = 'PromoteCoin';
public static $type = [
1 => '充值',
2 => '消费',
];
public static $subType = [
1 => '平台充值',
2 => '线下转账',
3 => '转账充值',
4 => '转账消费',
5 => '后台扣除',
6 => '迁移回收',
7 => '迁移扣除',
];
public static $handleType = [
1 => '会长转账',
2 => '组长转账',
3 => '推广员转账',
4 => '玩家转账',
];
public function myCoin($p = 0)
{
$map['promote_id'] = PID;
empty(I('game_id')) || $map['game_id'] = I('game_id');
empty(I('status')) || $map['status'] = I('status');
if (!empty(I('coin_type'))) {
switch (I('coin_type')) {
case 1:
$map['game_id'] = 0;
break;
case 2:
$where['game_id'] = ['gt', 0];
break;
}
}
$where['_string'] = '1 = 1';
$map['_complex'] = $where;
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$data = M('PromoteBalanceCoin', 'tab_')
->field('tab_promote_balance_coin.*,tab_game.game_name')
->join('left join tab_game on tab_promote_balance_coin.game_id = tab_game.id')
->where($map)
->page($page, $row)
->select();
$count = M('PromoteBalanceCoin', 'tab_')
->join('left join tab_game on tab_promote_balance_coin.game_id = tab_game.id')
->where($map)
->count();
//分页
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
empty(I('game_id')) || $parameter['game_id'] = I('game_id');
empty(I('status')) || $parameter['status'] = I('status');
empty(I('coin_type')) || $parameter['coin_type'] = I('coin_type');
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('data', $data);
$this->assign('count', $count);
$this->meta_title = '我的平台币';
$this->display();
}
public function coinRecord($p = 0)
{
$map['tab_promote_coin_record.target_id'] = PID;
empty(I('type')) || $map['tab_promote_coin_record.type'] = I('type');
empty(I('sub_type')) || $map['tab_promote_coin_record.sub_type'] = I('sub_type');
if (!empty(I('start_time')) && empty(I('end_time'))) {
$map['tab_promote_coin_record.create_time'] = ['egt', strtotime(I('start_time'))];
} elseif (empty(I('start_time')) && !empty(I('end_time'))) {
$map['tab_promote_coin_record.create_time'] = ['elt', strtotime(I('end_time')) + 86399];
} elseif (!empty(I('start_time')) && !empty(I('end_time'))) {
$map['tab_promote_coin_record.create_time'] = ['between', [strtotime(I('start_time')), strtotime(I('end_time')) + 86399]];
}
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$having = '';
$where['_string'] = '1 = 1';
if (empty(I('get.game_id'))) {
$where['_logic'] = 'or';
$join = 'left join tab_promote_coin on tab_promote_coin_record.ref_id = tab_promote_coin.id and tab_promote_coin_record.sub_type > 2 and tab_promote_coin.banlan_type = 1';
$having = '(coin_id > 0 or pay_id > 0)';
} else {
$where['tab_promote_coin_record.sub_type'] = ['gt', 2];
$join = 'inner join tab_promote_coin on tab_promote_coin_record.ref_id = tab_promote_coin.id and tab_promote_coin.banlan_type = 2 and tab_promote_coin.game_id = ' . I('get.game_id');
}
if (!empty(I('handle_type'))) {
switch (I('handle_type')) {
case 1:
$where['tab_promote_coin.source_type'] = 1;
$join .= ' inner join tab_promote on tab_promote_coin.source_id = tab_promote.id and tab_promote.parent_id = 0';
break;
case 2:
$where['tab_promote_coin.source_type'] = 1;
$join .= ' inner join tab_promote on tab_promote_coin.source_id = tab_promote.id and tab_promote.parent_id > 0 and tab_promote.grand_id = 0';
break;
case 3:
$where['tab_promote_coin.source_type'] = 1;
$join .= ' inner join tab_promote on tab_promote_coin.source_id = tab_promote.id and tab_promote.grand_id > 0';
break;
case 4:
$where['tab_promote_coin.source_type'] = 2;
break;
}
}
$join .= ' left join tab_coin_pay_order on tab_promote_coin_record.ref_id = tab_coin_pay_order.id and tab_promote_coin_record.sub_type in (1,2)';
$map['_complex'] = $where;
$data = M('PromoteCoinRecord', 'tab_')
->field('tab_promote_coin_record.*,tab_promote_coin.id as coin_id,tab_promote_coin.source_type,tab_promote_coin.source_id,tab_coin_pay_order.id as pay_id')
->join($join)
->where($map)
->having($having)
->order('id desc')
->page($page, $row)
// ->fetchSql(true)
->select();
$count = M('PromoteCoinRecord', 'tab_')
->field('tab_promote_coin.id as coin_id,tab_coin_pay_order.id as pay_id')
->join($join)
->where($map)
->having($having)
->select();
$count = count($count);
//分页
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
empty(I('game_id')) || $parameter['game_id'] = I('get.game_id');
empty(I('type')) || $parameter['type'] = I('type');
empty(I('sub_type')) || $parameter['sub_type'] = I('sub_type');
empty(I('source_type')) || $parameter['source_type'] = I('source_type');
empty(I('start_time')) || $parameter['start_time'] = I('start_time');
empty(I('end_time')) || $parameter['end_time'] = I('end_time');
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
if (!empty($data)) {
foreach ($data as $key => $list) {
if ($list['sub_type'] > 2) {
$promote = D('Promote')->where(array('id' => $list['source_id']))->find();
$data[$key]['handle_type'] = $this->getHandleType($list, $promote);
} else {
$data[$key]['handle_type'] = '未知';
}
}
}
$this->assign('data', $data);
$this->assign('count', $count);
$this->assign('gameId', I('get.game_id'));
$this->assign('setDate', date("Y-m-d"));
$this->meta_title = '交易明细';
$this->display();
}
public function coinRecordDesc()
{
if (empty(I('id'))) {
$this->error('网络异常');
}
$map['promote_id'] = PID;
$map['id'] = I('id');
$data['record'] = M('PromoteCoinRecord', 'tab_')
->where($map)
->find();
$data['desc'] = [];
if (!empty($data['record'])) {
switch ($data['record']['sub_type']) {
case 1:
case 2:
$tableName = 'CoinPayOrder';
break;
default:
$tableName = 'PromoteCoin';
break;
}
$data['desc'] = M($tableName, 'tab_')
->where(array('id' => $data['record']['ref_id']))
->find();
if ($data['record']['sub_type'] > 2) {
switch ($data['desc']['source_type']) {
case 1:
$data['payee'] = D('Promote')
->field('*,mobile_phone as phone')
->where(array('id' => $data['desc']['source_id']))
->find();
break;
case 2:
$data['payee'] = D('User')->where(array('id' => $data['desc']['source_id']))->find();
break;
default:
$data['payee'] = [];
break;
}
}
}
if (!empty($data['record'])) {
if ($data['record']['sub_type'] > 2) {
$promote = D('Promote')->where(array('id' => $data['desc']['source_id']))->find();
$data['record']['handle_type'] = $this->getHandleType($data['desc'], $promote);
} else {
$data['record']['handle_type'] = '未知';
}
}
$this->assign('data', $data);
$this->meta_title = '查看明细';
$this->display();
}
public function index($p = 0)
{
$map['type'] = 1;
$map['promote_id'] = PID;
$end_time = strtotime(I('time_end')) + 24 * 60 * 60 - 1;
$start_time = strtotime(I('time_start'));
if (!empty($_REQUEST['time_start']) && !empty($_REQUEST['time_end'])) {
$map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 24 * 60 * 60 - 1));
} elseif (!empty($_REQUEST['time_start']) && empty($_REQUEST['time_end'])) {
$map['create_time'] = array('egt', strtotime($_REQUEST['time_start']));
} elseif (empty($_REQUEST['time_start']) && !empty($_REQUEST['time_end'])) {
$map['create_time'] = array('elt', strtotime($_REQUEST['time_end']) + 24 * 60 * 60 - 1);
}
$extend['map'] = $map;
$this->meta_title = '平台币入账记录';
$this->data_lists($p, self::MODEL_NAME, $extend);
}
public function data_lists($p, $model, $extend = [])
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$model = D($model);
// 条件搜索
$map = [];
foreach (I('get.') as $name => $val) {
$map[$name] = $val;
}
$map = array_merge($map, $extend['map']);
$lists_data = $model->where($map)->order('create_time desc')->page($page, $row)->select();
$count = $model->where($map)->count();
//分页
$parameter = $_POST;
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('lists_data', $lists_data);
$this->assign('count', $count);
$this->display();
}
/**
* 转移平台币
*/
public function shift($p = 0)
{
$data = D('Promote')->find(PID);
if (IS_POST) {
$num = I('num');
if (!is_numeric($num)) {
$this->ajaxReturn(['status' => 0, 'msg' => '发送数量必须是数字']);
}
if ($num <= 0) {
$this->ajaxReturn(['status' => 0, 'msg' => '发送数量不正确']);
}
$password = I('password');
if ($data['second_pwd'] !== $this->think_ucenter_md5($password, UC_AUTH_KEY)) {
$this->ajaxReturn(['status' => 0, 'msg' => '安全密码错误']);
}
$shiftUserType = I('shift_user_type', 0);
if ($shiftUserType == 0) {
$this->ajaxReturn(['status' => 0, 'msg' => '请选择帐号类型']);
}
$gameId = I('game_id', 0);
if ($shiftUserType == 3 && $gameId == 0) {
$this->ajaxReturn(['status' => 0, 'msg' => '请选择游戏']);
}
$promoteService = new PromoteService();
$result = [];
if ($shiftUserType == 1 || $shiftUserType == 2) {
$params = [
'from_promote_id' => session('promote_auth.pid'),
'to_promote_id' => I('promote_id'),
'num' => $num,
'remark' => I('remark', ''),
'game_id' => I('game_id', 0),
'is_use_bind' => I('coin_type', 1) == 1 ? false : true,
];
$result = $promoteService->shiftCoin($params);
} elseif ($shiftUserType == 3) {
$params = [
'promote_id' => session('promote_auth.pid'),
'user_id' => I('promote_id'),
'num' => $num,
'remark' => I('remark', ''),
'game_id' => I('game_id', 0),
'is_use_bind' => I('coin_type', 1) == 1 ? false : true,
];
$result = $promoteService->shiftUserCoin($params);
}
if ($result['status']) {
$this->ajaxReturn(['status' => 1, 'msg' => '转账成功!']);
} else {
$this->ajaxReturn(['status' => -1, 'msg' => $result['msg']]);
}
} else {
$this->assign('data', $data);//用户信息被覆盖,转移位置获取正确数据
$child = M('Promote', 'tab_')->field('account,balance_coin')->where(['parent_id' => PID])->select();
$this->assign('childData', $child);
$this->assign('childcount', count($child));
$this->meta_title = "平台币转移";
$this->display();
}
}
/**
* 获取渠道平台币
* @param $id
*/
public function getCoin()
{
$gameId = I('game_id', 0);
$map = [
'promote_id' => session('promote_auth.pid'),
'game_id' => ['in', [$gameId, 0]],
];
$records = M('PromoteBalanceCoin', 'tab_')->where($map)->select();
$gameCoin = 0;
$commonCoin = 0;
foreach ($records as $record) {
if ($record['game_id'] == 0) {
$commonCoin = $record['num'];
} elseif ($gameId > 0 && $record['game_id'] == $gameId) {
$gameCoin = $record['num'];
}
}
$data = [
'commonCoin' => $commonCoin,
'gameCoin' => $gameCoin
];
$this->ajaxReturn(['status' => true, 'msg' => '成功', 'data' => $data]);
}
public function get_coin($id)
{
$data = D('promote')->find($id);
$res['coin'] = $data['balance_coin'];
$this->ajaxReturn($res);
}
/**
* 转移平台币记录
*/
public function record()
{
$map['source_id'] = empty(I('promote_id')) ? ['neq', '0'] : I('promote_id');
$map['type'] = 2;
$map['promote_id'] = PID;
$end_time = strtotime(I('time_end'));
$start_time = strtotime(I('time_start'));
if (!empty($end_time) && !empty($start_time)) {
$map['create_time'] = ['between', [$start_time, $end_time + 86400 - 1]];
} elseif (!empty($start_time)) {
$map['create_time'] = array('gt', $start_time);
} elseif (!empty($end_time)) {
$map['create_time'] = array('lt', $end_time + 86400 - 1);
}
$account = I('account');
$sn = I('sn');
if ($sn) {
$map['sn'] = ['like', '%' . $sn . '%'];
}
if ($account) {
$searchUsers = M('User', 'tab_')->field('id')->where(['account' => ['like', '%' . $account . '%']])->select();
$searchPromotes = M('Promote', 'tab_')->field('id')->where(['account' => ['like', '%' . $account . '%']])->select();
if (empty($searchUsers) && empty($searchPromotes)) {
$map['_string'] = '1<>1';
}
if (empty($searchUsers) && !empty($searchPromotes)) {
$map['source_id'] = ['in', array_column($searchPromotes, 'id')];
}
if (!empty($searchUsers) && empty($searchPromotes)) {
$map['source_id'] = ['in', array_column($searchUsers, 'id')];
}
if (!empty($searchUsers) && !empty($searchPromotes)) {
$map['_string'] = '(source_id in (' . implode(',', array_column($searchUsers, 'id')) . ') or'
. '(source_id in (' . implode(',', array_column($searchPromotes, 'id')) . '))';
}
}
$searchHandleType = I('handle_type', 0);
if ($searchHandleType) {
if ($searchHandleType == 2) {
$map['source_type'] = 2;
} else {
}
}
$searchGameId = I('game_id', -1);
if ($searchGameId != -1) {
$map['game_id'] = $searchGameId;
}
$this->meta_title = "平台币转移记录";
$query = M('PromoteCoin', 'tab_')->where($map)->order('create_time desc');
list($items, $pagination, $count) = $this->paginate($query);
$gameIds = array_unique(array_column($items, 'game_id'));
$games = $this->getColumnsByIds(M('Game', 'tab_'), $gameIds, 'game_name', ['indexBy' => 'id']);
$sourcePromoteIds = [];
$sourceUserIds = [];
foreach ($items as $item) {
if ($item['source_type'] == 1) {
$sourcePromoteIds[] = $item['source_id'];
} elseif ($item['source_type'] == 2) {
$sourceUserIds[] = $item['source_id'];
}
}
$sourceUsers = $this->getRecordsByIds(M('User', 'tab_'), $sourceUserIds, ['indexBy' => 'id']);
$sourcePromotes = $this->getRecordsByIds(M('Promote', 'tab_'), $sourcePromoteIds, ['indexBy' => 'id']);
$records = [];
foreach ($items as $item) {
$sourceName = '';
$promote = null;
if ($item['source_type'] == 2) {
$sourceName = $sourceUsers[$item['source_id']]['account'];
} elseif ($item['source_type'] == 1) {
$promote = $sourcePromotes[$item['source_id']];
$sourceName = $sourcePromotes[$item['source_id']]['account'];
}
$handleType = $this->getHandleType($item, $promote);
$records[] = [
'id' => $item['id'],
'sn' => $item['sn'],
'account' => $item['id'],
'game_name' => isset($games[$item['game_id']]) ? $games[$item['game_id']] : '所有游戏',
'create_time' => date('Y-m-d H:i:s', $item['create_time']),
'description' => $item['description'],
'num' => $item['num'],
'source_name' => $sourceName,
'handle_type' => $handleType,
'status' => $item['status'] == 1 ? '成功' : '失败',
];
}
$rows = M('PromoteCoin', 'tab_')->field(['game_id'])->where(['type' => 2, 'promote_id' => PID])->group('game_id')->select();
$gameIds = array_column($rows, 'game_id');
$games = [];
if (count($gameIds) > 0) {
$games = M('Game', 'tab_')->field(['id', 'game_name'])->where(['id' => ['in', $gameIds]])->select();
}
$this->assign('games', $games);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->assign('count', $count);
$this->display();
}
public function detail()
{
$id = I('id', 0);
$record = M('PromoteCoin', 'tab_')->where(['id' => $id])->find();
$sourceName = '';
$sourceAccount = '';
$sourcePromote = null;
if ($record['source_type'] == 2) {
$sourceUser = M('User', 'tab_')->where(['id' => $record['source_id']])->find();
$sourceName = $sourceUser['real_name'];
$sourceAccount = $sourceUser['account'];
} elseif ($record['source_type'] == 1) {
$sourcePromote = M('Promote', 'tab_')->where(['id' => $record['source_id']])->find();
$sourceName = $sourcePromote['real_name'];
$sourceAccount = $sourcePromote['account'];
}
$handleType = $this->getHandleType($record, $sourcePromote);
$gameName = '所有游戏';
if ($record['game_id'] > 0) {
$game = M('Game', 'tab_')->field('game_name')->where(['id' => $record['game_id']])->find();
$gameName = $game['game_name'];
}
$item = [
'id' => $record['id'],
'sn' => $record['sn'],
'game_name' => $gameName,
'create_time' => date('Y-m-d H:i:s', $record['create_time']),
'source_name' => $sourceName,
'source_account' => $sourceAccount,
'handle_type' => $handleType,
'description' => $record['description'],
'remark' => $record['remark'],
'status' => $record['status'] == 1 ? '成功' : '失败',
'num' => $record['num'],
];
$this->assign('item', $item);
$this->display();
}
public function getHandleType($promoteCoin, $promote)
{
if ($promoteCoin['source_type'] == 2) {
return '玩家转账';
} else {
$promoteService = new PromoteService();
$levelName = $promoteService->getLevelName($promote['level']);
return $levelName . '转账';
}
}
/*
* 平台币记录
* @author 鹿文学
*/
public function lists($p = 1)
{
$page = intval($p);
$page = $page ? $page : 1;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
SafeFilter($_REQUEST);
switch ($_REQUEST['source']) {
case 1:
{/* 后台发放 */
$data = D(self::MODEL_NAME)->grant($map, $page, $row);
};
break;
case 2:
case 3:
case 4:
case 5:
{
$data = D('Balance')->recharge($map, $page, $row, $_REQUEST['source'] - 1);
};
break;
default:
{
$data = D(self::MODEL_NAME)->all_coin($page, $row);
}
}
$count = $data['count'];
$parameter = array(
'p' => I('get.p', 1),
'row' => I('get.row'),
'source' => I('request.source'),
'order_number' => I('request.order_number'),
'account' => I('request.account'),
);
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('lists_data', $data['list']);
$this->meta_title = '平台币记录';
$this->display();
}
/*
* 批量删除平台币记录
* @author 鹿文学
*/
public function del_promote_coin()
{
if (empty($_REQUEST['ids'])) {
$this->ajaxReturn(['status' => 0, 'info' => '请选择要删除的数据']);
} else {
$pids = '';
$bids = '';
foreach ($_REQUEST['ids'] as $k => $v) {
$arr = explode(',', $v);
if ($arr[1] && $arr[1] != '--') {
$bids[] = $arr[0];
} else {
$pids[] = $arr[0];
}
}
if (is_array($bids)) {
$res1 = D('Balance')->del($bids);
}
if (is_array($pids)) {
$res2 = D(self::MODEL_NAME)->del($pids);
}
if ($res1 + $res2 > 0) {
$this->ajaxReturn(['status' => 1, 'info' => '删除成功']);
} else {
$this->ajaxReturn(['status' => 1, 'info' => '删除失败']);
}
}
}
/*
* 删除平台币记录
* @author 鹿文学
*/
public function del_promote_coin_id()
{
if ($_REQUEST['order_number'] && $_REQUEST['order_number'] != '--') {
$res = D('Balance')->del($_REQUEST['id']);
} else {
$res = D(self::MODEL_NAME)->del($_REQUEST['id']);
}
if ($res) {
$this->ajaxReturn(['status' => 1, 'info' => '删除成功']);
} else {
$this->ajaxReturn(['status' => 1, 'info' => '删除失败']);
}
}
public function subPromotes()
{
$level = I('level', 0);
$account = I('account', '');
$mobile = I('mobile', '');
$promote = $this->getLoginPromote();
$map = [];
$map['level'] = $level;
$map['chain'] = ['like', $promote['chain'] . $promote['id'] . '/%'];
if ($account) {
$map['account'] = ['like', '%' . $account . '%'];
}
if ($mobile) {
$map['mobile_phone'] = ['like', '%' . $mobile . '%'];
}
$query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'mobile_phone'])->where($map);
list($promotes, $pagination, $count) = $this->paginate($query);
$records = [];
foreach ($promotes as $promote) {
$records[] = [
'account' => $promote['account'],
'mobile' => $promote['mobile_phone'],
'real_name' => $promote['real_name'],
'id' => $promote['id'],
];
}
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->display('sub_promotes');
}
public function promoteUsers()
{
$account = I('account', '');
$mobile = I('mobile', '');
$promote = $this->getLoginPromote();
$map = ['chain' => ['like', $promote['chain'] . $promote['id'] . '/%']];
$promoteIds = D('Promote')->field('id')->where($map)->getField('id', true);
$promoteIds[] = $id;
$rows = D('UserPlay')->field(['id', 'user_id'])->where(['promote_id' => ['in', $promoteIds]])->select();
$map = [];
$userIds = array_column($rows, 'user_id');
if (count($userIds) > 0) {
$map = ['id' => ['in', array_column($rows, 'user_id')]];
} else {
$map = ['_string' => '1<>1'];
}
if ($account) {
$map['account'] = ['like', '%' . $account . '%'];
}
if ($mobile) {
$map['mobile_phone'] = ['like', '%' . $mobile . '%'];
}
$query = M('User', 'tab_')->field(['id', 'phone', 'account', 'real_name'])->where($map);
list($users, $pagination, $count) = $this->paginate($query);
$records = [];
foreach ($users as $user) {
$records[] = [
'account' => $user['account'],
'mobile' => $user['phone'],
'real_name' => $user['real_name'],
'id' => $user['id'],
];
}
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->display('promote_users');
}
public function think_ucenter_md5($str, $key = 'ThinkUCenter')
{
return '' === $str ? '' : md5(sha1($str) . $key);
}
public function promoteGames()
{
$promoteId = I('promote_id', 0);
$rows = M('Apply', 'tab_')->field(['game_id'])->where(['promote_id' => $promoteId, 'status' => 1])->select();
$ids = array_column($rows, 'game_id');
$name = I('name', '');
$map = [];
if ($name) {
$map['game_name'] = ['like', '%' . $name . '%'];
}
$records = [];
$records[] = [
'game_name' => '全部',
'icon' => '',
'sdk_version' => '全平台',
'id' => 0,
];
if (count($ids) > 0) {
$map['id'] = ['in', $ids];
} else {
$map['_string'] = '1<>1';
}
$query = M('Game', 'tab_')->field(['id', 'game_name', 'sdk_version', 'icon'])->where($map);
list($games, $pagination, $count) = $this->paginate($query);
foreach ($games as $game) {
$records[] = [
'game_name' => $game['game_name'],
'icon' => get_cover($game['icon'], 'path'),
'sdk_version' => getSDKTypeName($game['sdk_version']),
'id' => $game['id'],
];
}
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->display('promote_games');
}
public function userGames()
{
$userId = I('user_id', 0);
$rows = D('UserPlay')->field(['game_id'])->where(['user_id' => $userId])->select();
$ids = array_column($rows, 'game_id');
$name = I('name', '');
$map = [];
if ($name) {
$map['game_name'] = ['like', '%' . $name . '%'];
}
$records = [];
if (count($ids) > 0) {
$map['id'] = ['in', $ids];
} else {
$map['_string'] = '1<>1';
}
$query = M('Game', 'tab_')->field(['id', 'game_name', 'sdk_version', 'icon'])->where($map);
list($games, $pagination, $count) = $this->paginate($query);
foreach ($games as $game) {
$records[] = [
'game_name' => $game['game_name'],
'icon' => get_cover($game['icon'], 'path'),
'sdk_version' => getSDKTypeName($game['sdk_version']),
'id' => $game['id'],
];
}
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->display('user_games');
}
}