@ -5,6 +5,8 @@ namespace Home\Controller;
use OT\DataDictionary;
use User\Api\PromoteApi;
use Base\Service\PromoteService;
use Base\Service\PromoteCoinRecordService;
use Base\Service\PromoteCoinTransferLogService;
/**
* 前台首页控制器
@ -38,7 +40,9 @@ class PromoteCoinController extends BaseController
public function myCoin($p = 0)
{
$map['promote_id'] = PID;
$loginPromote = $this->getLoginPromote();
$map = [];
$map['promote_id'] = $loginPromote['id'];
empty(I('game_id')) || $map['game_id'] = I('game_id');
empty(I('status')) || $map['status'] = I('status');
@ -88,179 +92,105 @@ class PromoteCoinController extends BaseController
$this->assign('_page', $page);
}
$this->meta_title = '我的平台币';
$this->assign('data', $data);
$this->assign('count', $count);
$this->meta_title = '我的平台币';
$this->display();
}
public function coinRecord($p = 0 )
public function coinDetails( )
{
$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');
$type = I('type', 0);
$subType = I('sub_type', 0);
$targetType = I('target_type', '');
$startTime = I('start_time', '');
$endTime = I('end_time', '');
$gameId = I('game_id', 0);
$loginPromote = $this->getLoginPromote();
$conditions = [];
$conditions['game_id'] = $gameId;
$conditions['promote_id'] = $loginPromote['id'];
if ($type != 0) {
$conditions['type'] = $type;
}
if ($subType != 0) {
$conditions['sub_type'] = $subType;
}
if ($targetType != '') {
$targetTypeRow = explode('_', $targetType);
$conditions['target_type'] = $targetTypeRow[0];
if (count($targetTypeRow) == 2) {
$conditions['target_level'] = $targetTypeRow[1];
}
}
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;
if ($startTime != '' || $endTime != '') {
if ($startTime != '') {
$conditions['create_time'] = ['egt', strtotime($startTime. ' 00:00:00')];
}
if ($endTime != '') {
$conditions['create_time'] = ['elt', strtotime($endTime. ' 23:59:59')];
}
}
$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');
$service = new PromoteCoinRecordService();
$query = M('promote_coin_record', 'tab_')->where($conditions);
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
list($items, $pagination, $count) = $this->paginate($query);
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'] = '未知';
}
}
$records = [];
foreach ($items as $item) {
$records[] = [
'id' => $item['id'],
'sn' => $item['sn'],
'type_text' => $service->getTypeText($item['type']),
'sub_type_text' => $service->getSubTypeText($item['sub_type']),
'target_type_text' => $service->getTargetTypeText($item['target_type'], $item['target_level']),
'coin' => $item['coin'],
'balance_coin' => $item['balance_coin'],
'remark' => $item['remark'],
'description' => $item['description'],
'create_time' => date('Y-m-d H:i:s', $item['create_time']),
];
}
$this->meta_title = '交易明细';
$this->assign('data', $data);
$this->assign('subTypes', PromoteCoinRecordService::$subTypes);
$this->assign('types', PromoteCoinRecordService::$types);
$this->assign('targetTypeLevels', $service->getTargetTypeLevels());
$this->assign('records', $records);
$this->assign('count', $count);
$this->assign('gameId', I('get.game_id'));
$this->assign('setDate', date("Y-m-d"));
$this->meta_title = '交易明细';
$this->assign('gameId', $gameId);
$this->assign('pagination', $pagination);
$this->display();
}
public function coinRecordDesc ()
public function coinDetail ()
{
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 = '查看明细';
$id = I('id', 0);
$service = new PromoteCoinRecordService();
$loginPromote = $this->getLoginPromote();
$item = M('promote_coin_record', 'tab_')->where(['promote_id' => $loginPromote['id'], 'id' => $id])->find();
$refOrderName = '';
$ref = $service->getRef($item);
$refDetail = $service->getRefDetail($item, $ref);
$record = [
'id' => $item['id'],
'sn' => $item['sn'],
'type_text' => $service->getTypeText($item['type']),
'sub_type_text' => $service->getSubTypeText($item['sub_type']),
'target_type_text' => $service->getTargetTypeText($item['target_type'], $item['target_level']),
'coin_type' => $item['game_id'] > 0 ? '绑定币' : '通用币',
'coin' => $item['coin'],
'balance_coin' => $item['balance_coin'],
'remark' => $item['remark'],
'description' => $item['description'],
'create_time' => date('Y-m-d H:i:s', $item['create_time']),
];
$this->assign('record', $record);
$this->assign('refDetail', $refDetail);
$this->display();
}
@ -326,12 +256,19 @@ class PromoteCoinController extends BaseController
/**
* 转移平台币
*/
public function shift($p = 0 )
public function shift()
{
$data = D('Promote')->find(PID );
$loginPromote = $this->getLoginPromote( );
if (IS_POST) {
$num = I('num');
$password = I('password');
$shiftUserType = I('shift_user_type', 0);
$targetId = I('target_id', 0);
$gameId = I('game_id', 0);
$remark = I('remark', '');
$coinType = I('coin_type', 1);
if (!is_numeric($num)) {
$this->ajaxReturn(['status' => 0, 'msg' => '发送数量必须是数字']);
}
@ -340,42 +277,31 @@ class PromoteCoinController extends BaseController
$this->ajaxReturn(['status' => 0, 'msg' => '发送数量不正确']);
}
$password = I('password' );
if ($data['second_pwd'] !== $this->think_ucenter_md5 ($password, UC_AUTH_KEY)) {
$promoteService = new PromoteService( );
if ($loginPromote['second_pwd'] !== $promoteService->password ($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) {
if ($shiftUserType == 4 & & $gameId == 0) {
$this->ajaxReturn(['status' => 0, 'msg' => '请选择游戏']);
}
$promoteService = new PromoteService();
$params = [
'from_promote_id' => $loginPromote['id'],
'num' => $num,
'remark' => $remark,
'game_id' => $gameId,
'is_use_bind' => $coinType == 1 ? false : true,
];
$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,
];
if ($shiftUserType == 1 || $shiftUserType == 2 || $shiftUserType == 3) {
$params['promote_id'] = $targetId;
$result = $promoteService->shiftPromoteCoin($params);
} elseif ($shiftUserType == 4) {
$params['user_id'] = $targetId;
$result = $promoteService->shiftUserCoin($params);
}
@ -385,10 +311,6 @@ class PromoteCoinController extends BaseController
$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();
}
@ -430,136 +352,103 @@ class PromoteCoinController extends BaseController
$this->ajaxReturn($res);
}
/**
* 转移平台币记录
*/
public function record()
public function transferLogs()
{
$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')];
$this->meta_title = "平台币转移记录";
$gameId = I('game_id', -1);
$account = I('account', '');
$sn = I('sn', '');
$startTime = I('time_end', '');
$endTime = I('time_start', '');
$loginPromote = $this->getLoginPromote();
$conditions = ['promote_id' => $loginPromote['id']];
if ($startTime != '' || $endTime != '') {
if ($startTime != '') {
$conditions['create_time'] = ['egt', strtotime($startTime. ' 00:00:00')];
}
if (!empty($searchUsers) & & !empty($searchPromotes)) {
$map['_string'] = '(source_id in (' . implode(',', array_column($searchUsers, 'id')) . ') or'
. '(source_id in (' . implode(',', array_column($searchPromotes, 'id')) . '))';
if ($endTime != '') {
$conditions['create_time'] = ['elt', strtotime($endTime. ' 23:59:59')];
}
}
$searchHandleType = I('handle_type', 0);
if ($searchHandleType) {
if ($searchHandleType == 2) {
$map['source_type'] = 2;
} else {
$query = M('promote_coin_transfer_log', 'tab_')->where($conditions)->order('create_time desc');
list($logs, $pagination, $count) = $this->paginate($query);
$service = new PromoteCoinTransferLogService();
$gameIds = [];
$promoteIds = [];
$uesrIds = [];
foreach ($logs as $log) {
$gameIds[] = $log['game_id'];
if ($log['target_type'] == 1) {
$promoteIds[] = $log['target_id'];
}
if ($log['target_type'] == 2) {
$uesrIds[] = $log['target_id'];
}
}
$searchGameId = I('game_id', -1);
if ($searchGameId != -1) {
$map['game_id'] = $searchGameId;
$games = [];
$promotes = [];
$users = [];
if (count($gameIds) > 0) {
$games = M('game', 'tab_')->field(['id', 'game_name'])->where(['id' => ['in', $gameIds]])->select();
}
$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'];
}
if (count($promoteIds) > 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', $promoteIds]])->select();
}
$sourceUsers = $this->getRecordsByIds(M('User', 'tab_'), $sourceUserIds, ['indexBy' => 'id']);
$sourcePromotes = $this->getRecordsByIds(M('Promote', 'tab_'), $sourcePromoteIds, ['indexBy' => 'id']);
if (count($uesrIds) > 0) {
$users = M('user', 'tab_')->field(['id', 'account'])->where(['id' => ['in', $uesrIds]])->select();
}
$users = index_by_column('id', $users);
$promotes = index_by_column('id', $promotes);
$games = index_by_column('id', $games);
$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'];
foreach ($logs as $log) {
$targetAccount = '';
if ($log['target_type'] == 1) {
$targetAccount = isset($promotes[$log['target_id']]) ? $promotes[$log['target_id']]['account'] : '未知推广账号';
}
if ($log['target_type'] == 2) {
$targetAccount = isset($promotes[$log['target_id']]) ? $promotes[$log['target_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 ? '成功' : '失败',
'id' => $log['id'],
'sn' => $log['sn'],
'target_account' => $targetAccount,
'game_name' => isset($games[$log['game_id']]) ? $games[$log['game_id']]['game_name'] : '所有游戏',
'target_type_text' => $service->getTargetTypeText($log['target_type'], $log['target_level']),
'num' => $log['num'],
'description' => $log['description'],
'status_text' => '成功',
'create_time' => date('Y-m-d H:i:s', $log['create_time'])
];
}
$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->assign('records', $records);
$this->display();
}
public function detail()
{
$id = I('id', 0);
$record = M('PromoteCoin ', 'tab_')->where(['id' => $id])->find();
$source Name = '';
$record = M('promote_coin_transfer_log', 'tab_')->where(['id' => $id])->find();
$targetName = '';
$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);
if ($record['target_type'] == 2) {
$targetUser = M('user', 'tab_')->where(['id' => $record['target_id']])->find();
$targetName = $targetUser['real_name'];
$targetAccount = $targetUser['account'];
} elseif ($record['target_type'] == 1) {
$targetPromote = M('promote', 'tab_')->where(['id' => $record['target_id']])->find();
$targetName = $targetPromote['real_name'];
$targetAccount = $targetPromote['account'];
}
$service = new PromoteCoinTransferLogService();
$targetTypeText = $service->getTargetTypeText($record['target_type'], $record['target_level']);
$gameName = '所有游戏';
if ($record['game_id'] > 0) {
$game = M('Game', 'tab_')->field('game_name')->where(['id' => $record['game_id']])->find();
@ -571,9 +460,9 @@ class PromoteCoinController extends BaseController
'sn' => $record['sn'],
'game_name' => $gameName,
'create_time' => date('Y-m-d H:i:s', $record['create_time']),
'source_name' => $source Name,
'source_account' => $source Account,
'handle_type' => $handleType ,
'target_name' => $target Name,
'target_account' => $target Account,
'target_type_text' => $targetTypeText ,
'description' => $record['description'],
'remark' => $record['remark'],
'status' => $record['status'] == 1 ? '成功' : '失败',
@ -793,11 +682,6 @@ class PromoteCoinController extends BaseController
$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);