<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016/12/19
* Time: 13:38
*/
namespace Admin\Controller;
use Admin\Model\PromoteModel;
class AjaxController extends ThinkController{
/**
* 获取配置项
* @param $category
*/
public function getConfigCategory($category){
switch ($category){
case 1:$result = C('PC_CONFIG_GROUP_LIST');break;
case 2:$result = C('CHANNEL_CONFIG_GROUP_LIST');break;
case 3:$result = C('APP_CONFIG_GROUP_LIST');break;
case 5:$result = C('WAP_CONFIG_GROUP_LIST');break;
case 6:$result = C('BA_CONFIG_GROUP_LIST');break;
default:$result = C('CONFIG_GROUP_LIST');
}
$this->AjaxReturn($result);
}
/**
* 获取区服列表
* @param $game_id
*/
public function getServer($game_id=""){
$map = [];
if (!empty($game_id)) {
$map['game_id'] = $game_id;
}
$data = M('server','tab_')->where($map)->select();
$this->AjaxReturn($data);
}
/**
*获取充值游戏区服
* @param game_id
*/
public function getSpendServer($game_id="",$type=1, $game_type='', $game_name=''){
if($type==2){
$game = M('Game','tab_')->field('id')->where(['game_name'=>$game_id])->find();
$game_id = $game['id'];
}
$map['game_id'] = $game_id;
$map['server_name'] = array('neq','');
$data = M('Spend','tab_')->field('server_name')->where($map)->group('server_name')->select();
$this->AjaxReturn($data);
}
/**
* 获取用户注册区服
*/
public function getUserServer($game_id="",$type=1){
if($type==2){
$game = M('Game','tab_')->field('id')->where(['game_name'=>$game_id])->find();
$game_id = $game['id'];
}
$map['game_id'] = $game_id;
$map['server_name'] = array('neq','');
$data = M('UserPlayInfo','tab_')->field('server_name')->where($map)->group('server_name')->select();
$this->AjaxReturn($data);
}
public function getGmeServer($game_name="", $sdk_version="")
{
$game_map = [];
if ($game_name) {
$game_map['relation_game_name'] = $game_name;
}else {
$this->AjaxReturn([]);
}
if ($sdk_version) {
$map['server_version'] = $game_map['sdk_version'] = $sdk_version;
}else {
// $this->AjaxReturn([]);
}
$game = M("Game", 'tab_')->where($game_map)->getField('id', true);
// 获取版本信息
$map = [];
if ($game) {
$map['game_id'] = ['in', $game];
} else {
$map['game_id'] = ['in', [-1]];
}
$data = M('Server', 'tab_')->field('id, server_name, server_id')->where($map)->group('server_name')->select();
$this->AjaxReturn($data);
}
public function getGameVersion($game_name="")
{
if ($game_name) {
$map['relation_game_name'] = $game_name;
}else {
$this->AjaxReturn([]);
}
$data = M('Game','tab_')->field('sdk_version')->where($map)->select();
$this->AjaxReturn($data);
}
/**
* 获取游戏折扣
* @param $game_id
*/
public function getGameDiscount($game_id){
$data = M('Game','tab_')->find($game_id);
$res['discount'] = $data['discount'];
$this->AjaxReturn($res);
}
public function getUserPlayGameName($user_id=0){
$map['user_account'] = $user_id;
$data = M("UserPlay","tab_")->field("game_id,game_name,bind_balance")->where($map)->group('user_id,game_id')->select();
$this->AjaxReturn($data);
}
/**
*修改游戏字段
* @param int game_id
* @param string $fields 要修改的字段名称
* @param string $value 要修改的字段的值
* @author 小纯洁
*/
public function setGameDataField($game_id=0,$fields='',$value=''){
$map['id'] = $game_id;
$result = M('Game','tab_')->where($map)->setField($fields,$value);
if($result !== false){
if($fields != "game_status"){
$game = M('Game','tab_')->where($map)->find();
$map1['relation_game_name'] = $game['relation_game_name'];
M('Game','tab_')->where($map1)->setField($fields,$value);
}
$data = array('status' =>1 ,'data'=>$result );
$this->AjaxReturn($data);
}else{
$data = array('status' =>0 ,'data'=>$result );
$this->AjaxReturn($data);
}
}
/**
*获取推广员申请通过的游戏
*/
public function getPromoteApplyGame($promote_id = 0){
if($promote_id == 0){
$return_msg = array('status'=>0,'info'=>'请选择推广员');
$this->AjaxReturn($return_msg);
}
$fields = "tab_game.id,tab_game.game_name,discount,tab_apply.promote_id,tab_apply.promote_account";
$data = D('Apply')->getPromoteGame($promote_id,$fields);
if(empty($data)){
$return_msg = array('status'=>0,'info'=>'该推广员没有已审核的游戏');
$this->AjaxReturn($return_msg);
} else{
$return_msg = array('status'=>1,'info'=>'成功','data'=>$data);
$this->AjaxReturn($return_msg);
}
}
public function getPromotersByLevel()
{
$level = I('level');
if (!$level) {
return $this->ajaxReturn(['code'=>1, 'msg'=>'获取成功', 'data'=>[]]);
}
$this->ajaxReturn(['code'=>1, 'msg'=>'获取成功', 'data'=>(new PromoteModel)->getPromotersByLevel($level)]);
}
/**
* 根据公司id获取会长
*/
public function getPromotersByCompanyid($company_id = -1)
{
$company_id = I('company_id');
$data = M("Promote","tab_")->field("id,account,nickname,company_id");
if($company_id == -1){
$data = $data->where("level = '1'")->select();
}else{
$data = $data->where("company_id = '{$company_id}' and level = '1'")->select();
}
foreach ($data as & $item) {
$item['nickname'] = $item['account'] . ($item['nickname'] ? "({$item['nickname']})" : "");
}
$this->ajaxReturn(['code'=>1, 'msg'=>'获取成功', 'data'=>$data]);
}
public function getPromotersByLevelOther()
{
$level = I('level');
if (!$level) {
return $this->ajaxReturn(['code'=>1, 'msg'=>'获取成功', 'data'=>[]]);
}
$this->ajaxReturn(['code'=>1, 'msg'=>'获取成功', 'data'=>(new PromoteModel)->getPromotersByLevelOther($level)]);
}
public function getGameList($type=0, $sdk_type=0)
{
$game = M("game","tab_");
if(MODULE_NAME == 'Admin') {
$map['game_status'] = array('in','0,1');
} else {
$map['game_status'] = 1;
}
if(!empty($type)){
/*$map['developers'] = $type == 1? array('EQ',0):array('GT',0);*/
/* $map['game_status'] = $type == 1? 1:array('in','0,1'); */
switch($type) {
case 1:
$map['developers'] = array('EQ',0);
break;
case 2:
$map['developers'] = array('EGT',0);
break;
default:
$map['developers'] = array('GT',0);
}
}else{
$map['apply_status'] = 1;
$map['online_status'] = 1;
}
if (empty($sdk_type)) {
$lists = $game->field('id,game_name,sdk_version,relation_game_name,icon,relation_game_id,game_status,display_site,dow_num')->where($map)->group('relation_game_name')->order("id asc")->select();
} else {
$map['sdk_version'] = $sdk_type;
$lists = $game->field('id,game_name,sdk_version,relation_game_name,icon,relation_game_id,game_status,display_site,dow_num')->where($map)->order("id asc")->select();
}
$this->ajaxReturn(['code'=>1, 'msg'=>'获取成功', 'data'=>$lists]);
}
public function getDownstreamData() {
$withdraw_number = $_REQUEST['withdraw_number'];
if ($withdraw_number) {
$map['widthdraw_number'] = $withdraw_number;
}
if ($_REQUEST['company_id']) {
$map['company_id'] = $_REQUEST['company_id'];
}
$data = M("withdraw","tab_")
->field("widthdraw_number,promote_account,tab_promote_company.id as company_id,company_name,tab_withdraw.settlement_type,mobile_phone,real_name,bank_card,account_openin,address,game_ratio,bank_account")
->join("left join tab_promote on tab_withdraw.promote_id=tab_promote.id")
->join("left join tab_promote_company on tab_promote.company_id=tab_promote_company.id")
->where($map)
->find();
if ($data['settlement_type']==1) {
$data['settlement_type'] = '周结订单';
} else if($data['settlement_type']==2){
$data['settlement_type'] = '月结订单';
} else {
$data['settlement_type'] = '补点订单';
}
$data['game_ratio'] = json_decode($data['game_ratio'],true);
$getStatementData =M('statement','tab_')->where(['ext_field'=>$withdraw_number])->find();
$statementData = json_decode($getStatementData['statement_info'],true);
if ($statementData) {
$data['sum'] = $getStatementData['statement_money'];
$data['pay_amount'] = $getStatementData['pay_amount'];
$handleStatementData = [];
foreach ($statementData as $key=>$sv) {
if ($sv['game_id']) {
$nowVal['selle_ratio'] = $sv['second_ratio'];
$nowVal['sum_amount'] = $sv['pay_amount'];
$nowVal['begin_time'] = $sv['statement_begin_time'];
$nowVal['end_time'] = $sv['statement_end_time'];
$nowVal['game_name'] = $sv['game_name'];
$nowVal['fax_ratio'] = $sv['fax_ratio'];
$nowVal['sum'] = $sv['sum_money'];
$handleStatementData[$sv['game_id']][] = $nowVal;
} else {
$data['forfeit'] = $sv['sum_money'];
}
}
$first_party_info = json_decode($getStatementData['first_party_info'],true);
$second_party_info = json_decode($getStatementData['second_party_info'],true);
$data['game_ratio'] = $handleStatementData;
$data['company_name'] = $second_party_info['partner'];
$data['mobile_phone'] = $second_party_info['link_phone'];
$data['bank_card'] = $second_party_info['bank_account'];
$data['account_openin'] = $second_party_info['opening_bank'];
$data['settlement_type'] = $second_party_info['settlement_type'];
$data['address'] = $second_party_info['address'];
$data['real_name'] = $second_party_info['link_man'];
$data['bank_account_name'] = $second_party_info['bank_account_name'];
$data['settlement_type_value'] = $getStatementData['settlement_type'];
$data['settlement_type_value'] = $getStatementData['settlement_type'];
$data['invoice_item'] = $second_party_info['invoice_item'];
$data['invoice_type'] = $second_party_info['invoice_type'];
$data['jfCompany'] = $first_party_info['jfCompany'];
$data['jfPerson'] = $first_party_info['jfPerson'];
$data['jfTel'] = $first_party_info['jfTel'];
if ($getStatementData['settlement_type']=='周结订单') {
$data['settlement_type_value'] = 1;
} else if ($getStatementData['settlement_type']=='月结订单') {
$data['settlement_type_value'] = 2;
} else {
$data['settlement_type_value'] = 3;
}
// dump($statementData);die();
} else {
$data['address'] = json_decode($data['address'],1);
// dd($data['address']);
$address = '';
if (is_array($data['address'])) {
foreach($data['address'] as $key => $value) {
$address = $address.' '.$value;
}
}
$data['address'] = $address;
if (is_array($data['game_ratio'])) {
foreach ($data['game_ratio'] as $key => & $value) {
foreach ($value as $k => & $v) {
$v['game_name'] = get_gamename($key);
}
}
}
$yfData = M('tool','tab_')->where(['name'=>'company_info'])->find();
$yfData = json_decode($yfData['config'],true);
$data['yfpartner'] = $yfData['partner'];
$data['yflink_man'] = $yfData['link_man'];
$data['yflink_phone'] = $yfData['link_phone'];
}
$this->ajaxReturn(['code'=>1, 'msg'=>'获取成功', 'data'=>$data]);
}
function getPromoteCompanyList() {
$map = [];
if ($_REQUEST['withdraw_number']) {
$map['widthdraw_number'] = $_REQUEST['withdraw_number'];
}
// var_dump($map);die();
if ($_REQUEST['company_id']) {
$map['_string'] = "tab_promote.company_id={$_REQUEST['company_id']} and ext_field is null";
}
// $map['widthdraw_number'] = ['neq',''];
$data = M("withdraw","tab_")
->field("widthdraw_number,promote_account,tab_promote_company.id as company_id,tab_promote_company.company_name,tab_withdraw.settlement_type,mobile_phone,real_name,bank_card,account_openin,address,game_ratio,bank_account")
->join("left join tab_promote on tab_withdraw.promote_id=tab_promote.id")
->join("left join tab_promote_company on tab_promote.company_id=tab_promote_company.id")
->join("left join tab_statement as statement on tab_withdraw.widthdraw_number = statement.ext_field")
->where($map)
// ->where("widthdraw_number is not NULL")
->select();
$this->ajaxReturn(['data'=>$data]);
// return $data;
}
}