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.

756 lines
25 KiB
PHTML

5 years ago
<?php
namespace Home\Controller;
use OT\DataDictionary;
use User\Api\PromoteApi;
use Base\Service\PromoteService;
5 years ago
use Base\Service\PromoteCoinRecordService;
use Base\Service\PromoteCoinTransferLogService;
5 years ago
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
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)
{
5 years ago
$loginPromote = $this->getLoginPromote();
$map = [];
$map['promote_id'] = $loginPromote['id'];
5 years ago
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);
}
5 years ago
$this->meta_title = '我的平台币';
5 years ago
$this->assign('data', $data);
$this->assign('count', $count);
$this->display();
}
5 years ago
public function coinDetails()
5 years ago
{
5 years ago
$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];
}
5 years ago
}
5 years ago
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')];
5 years ago
}
}
5 years ago
$service = new PromoteCoinRecordService();
$query = M('promote_coin_record', 'tab_')->where($conditions);
5 years ago
5 years ago
list($items, $pagination, $count) = $this->paginate($query);
5 years ago
5 years ago
$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']),
];
5 years ago
}
5 years ago
$this->meta_title = '交易明细';
5 years ago
5 years ago
$this->assign('subTypes', PromoteCoinRecordService::$subTypes);
$this->assign('types', PromoteCoinRecordService::$types);
$this->assign('targetTypeLevels', $service->getTargetTypeLevels());
$this->assign('records', $records);
5 years ago
$this->assign('count', $count);
5 years ago
$this->assign('gameId', $gameId);
$this->assign('pagination', $pagination);
5 years ago
$this->display();
}
5 years ago
public function coinDetail()
5 years ago
{
5 years ago
$this->meta_title = '查看明细';
5 years ago
$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);
5 years ago
$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();
}
/**
* 转移平台币
*/
5 years ago
public function shift()
5 years ago
{
5 years ago
$loginPromote = $this->getLoginPromote();
5 years ago
if (IS_POST) {
5 years ago
5 years ago
$num = I('num');
5 years ago
$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);
5 years ago
if (!is_numeric($num)) {
$this->ajaxReturn(['status' => 0, 'msg' => '发送数量必须是数字']);
}
if ($num <= 0) {
$this->ajaxReturn(['status' => 0, 'msg' => '发送数量不正确']);
}
5 years ago
$promoteService = new PromoteService();
if ($loginPromote['second_pwd'] !== $promoteService->password($password, UC_AUTH_KEY)) {
5 years ago
$this->ajaxReturn(['status' => 0, 'msg' => '安全密码错误']);
}
if ($shiftUserType == 0) {
$this->ajaxReturn(['status' => 0, 'msg' => '请选择帐号类型']);
}
5 years ago
if ($shiftUserType == 4 && $gameId == 0) {
5 years ago
$this->ajaxReturn(['status' => 0, 'msg' => '请选择游戏']);
}
5 years ago
$params = [
'from_promote_id' => $loginPromote['id'],
'num' => $num,
'remark' => $remark,
'game_id' => $gameId,
'is_use_bind' => $coinType == 1 ? false : true,
];
5 years ago
$result = [];
5 years ago
if ($shiftUserType == 1 || $shiftUserType == 2 || $shiftUserType == 3) {
$params['promote_id'] = $targetId;
$result = $promoteService->shiftPromoteCoin($params);
} elseif ($shiftUserType == 4) {
$params['user_id'] = $targetId;
5 years ago
$result = $promoteService->shiftUserCoin($params);
}
if ($result['status']) {
$this->ajaxReturn(['status' => 1, 'msg' => '转账成功!']);
} else {
$this->ajaxReturn(['status' => -1, 'msg' => $result['msg']]);
}
} else {
$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);
}
5 years ago
public function transferLogs()
5 years ago
{
5 years ago
$this->meta_title = "平台币转移记录";
$gameId = I('game_id', -1);
$account = I('account', '');
$sn = I('sn', '');
$startTime = I('time_end', '');
$endTime = I('time_start', '');
5 years ago
$loginPromote = $this->getLoginPromote();
$conditions = ['promote_id' => $loginPromote['id']];
5 years ago
if ($startTime != '' || $endTime != '') {
if ($startTime != '') {
$conditions['create_time'] = ['egt', strtotime($startTime. ' 00:00:00')];
5 years ago
}
5 years ago
if ($endTime != '') {
$conditions['create_time'] = ['elt', strtotime($endTime. ' 23:59:59')];
5 years ago
}
}
5 years ago
$query = M('promote_coin_transfer_log', 'tab_')->where($conditions)->order('create_time desc');
5 years ago
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'];
5 years ago
}
}
5 years ago
$games = [];
$promotes = [];
$users = [];
if (count($gameIds) > 0) {
$games = M('game', 'tab_')->field(['id', 'game_name'])->where(['id' => ['in', $gameIds]])->select();
5 years ago
}
5 years ago
if (count($promoteIds) > 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', $promoteIds]])->select();
5 years ago
}
5 years ago
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);
5 years ago
$records = [];
5 years ago
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'] : '未知玩家';
5 years ago
}
$records[] = [
5 years ago
'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'])
5 years ago
];
}
$this->assign('pagination', $pagination);
$this->assign('count', $count);
5 years ago
$this->assign('records', $records);
5 years ago
$this->display();
}
public function detail()
{
$id = I('id', 0);
5 years ago
$record = M('promote_coin_transfer_log', 'tab_')->where(['id' => $id])->find();
$targetName = '';
5 years ago
$sourceAccount = '';
$sourcePromote = null;
5 years ago
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']);
5 years ago
$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']),
5 years ago
'target_name' => $targetName,
'target_account' => $targetAccount,
'target_type_text' => $targetTypeText,
5 years ago
'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 {
5 years ago
$promoteService = new PromoteService();
$levelName = $promoteService->getLevelName($promote['level']);
return $levelName . '转账';
5 years ago
}
}
/*
* 平台币记录
* @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()
{
5 years ago
$level = I('level', 0);
5 years ago
$account = I('account', '');
$mobile = I('mobile', '');
5 years ago
$promote = $this->getLoginPromote();
5 years ago
$map = [];
5 years ago
$map['level'] = $level;
$map['chain'] = ['like', $promote['chain'] . $promote['id'] . '/%'];
5 years ago
if ($account) {
$map['account'] = ['like', '%' . $account . '%'];
}
if ($mobile) {
$map['mobile_phone'] = ['like', '%' . $mobile . '%'];
}
5 years ago
$query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'mobile_phone'])->where($map);
5 years ago
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;
5 years ago
if ($account) {
$map['account'] = ['like', '%' . $account . '%'];
}
if ($mobile) {
$map['mobile_phone'] = ['like', '%' . $mobile . '%'];
}
5 years ago
$map['promote_id'] = ['in',$promoteIds];
5 years ago
$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 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');
}
}