diff --git a/Application/Admin/Conf/config.php b/Application/Admin/Conf/config.php index 26d141df6..30a1267bb 100644 --- a/Application/Admin/Conf/config.php +++ b/Application/Admin/Conf/config.php @@ -129,5 +129,9 @@ return array( "tab_reward_detail", "tab_reward_record", "tab_new_company_statement_info", + "tab_game", + "tab_spend", + "tab_promote", + "tab_promote_company", ] ); \ No newline at end of file diff --git a/Application/Admin/Controller/CompanyStatementController.class.php b/Application/Admin/Controller/CompanyStatementController.class.php index d6725759f..e4fe83fea 100644 --- a/Application/Admin/Controller/CompanyStatementController.class.php +++ b/Application/Admin/Controller/CompanyStatementController.class.php @@ -229,6 +229,13 @@ class CompanyStatementController extends ThinkController } $this->assign("IS_SUBSITE",IS_SUBSITE); + if(IS_SUBSITE){ + $SubKvModel = M("Kv","sub_",SUBSITE_DB);//指定子库 + $LastSynTime = $SubKvModel->where("`key` = 'sub_spend_syn_time'")->getField("value"); + $LastStatementTime = $SubKvModel->where("`key` = 'sub_company_statement'")->getField("value"); + $this->assign('lastSynTime',date('Y-m-d',$LastSynTime)); + $this->assign('lastStatementTime',date('Y-m-d',$LastStatementTime)); + } $this->assign('data',$data); $this->assign('count',$count); @@ -1769,6 +1776,24 @@ class CompanyStatementController extends ThinkController $this->ajaxReturn(array("success"=>"ok","data"=>[])); } + //子站新增结算 + public function subAddStatement(){ + if(!isset($_REQUEST['statement_time'])) $this->error("参数错误"); + $statement_time = $_REQUEST['statement_time']; + $end = date("Y-m-d",strtotime($statement_time)+ 86400); + $utime = strtotime($statement_time)+86399; + + $LastStatementTime = M("Kv","sub_",SUBSITE_DB)->where("`key` = 'sub_company_statement'")->getField("value"); + $begin = date("Y-m-d",$LastStatementTime-0+1); + + $params = "php ".SUBSITE_INDEX." SubCompanyStatementSet/setFreeDateCount/begin/{$begin}/end/{$end}/utime/{$utime}"; + $r = D("CmdTasks")->addTask("SubCompanyStatementSet",$params); + if($r){ + $this->ajaxReturn(["status"=>1,"info"=>"任务登记成功,请等待五分分钟后查看结果"]); + }else{ + $this->ajaxReturn(["status"=>0,"info"=>"任务登记错误"]); + } + } public function viewSpecialComplement() { @@ -2483,6 +2508,13 @@ class CompanyStatementController extends ThinkController "viewSpecialComplement"=>"特殊补点", "delStatement"=>"批量删除" ]; + if(IS_SUBSITE){ + unset($mentBtn['updateNewStatement']); + $is_can_add = D("CmdTasks")->isCanAddTask("SubCompanyStatementSet"); + if($is_can_add){ + $mentBtn['subAddStatement'] = "新增结算"; + } + } $resarr = []; foreach ($mentBtn as $k => $v) { if(IS_ROOT){ diff --git a/Application/Admin/Controller/ExportController.class.php b/Application/Admin/Controller/ExportController.class.php index da7e1ef3d..f293def63 100644 --- a/Application/Admin/Controller/ExportController.class.php +++ b/Application/Admin/Controller/ExportController.class.php @@ -1087,6 +1087,12 @@ class ExportController extends Controller $startTime = strtotime($startDate); $endTime = strtotime($endDate) + 86399; $map['pay_time'] = array('BETWEEN', array($startTime, $endTime)); + $is_sub_data = I("issubdata",0); + if($is_sub_data == 1){ + $SpendModel = M("spend","tab_",SUBSITE_DB); + }else{ + $SpendModel = M("spend","tab_"); + } unset($_REQUEST['timestart']); unset($_REQUEST['timeend']); @@ -1201,7 +1207,7 @@ class ExportController extends Controller D("Spend")->addSubsiteWhere($map); $map1 = $map; $map1['pay_status'] = 1; - $total = M('Spend','tab_')->where($map1)->sum('pay_amount'); + $total = $SpendModel->where($map1)->sum('pay_amount'); // var_dump($total);die(); $total=$total?$total:0; @@ -1277,7 +1283,7 @@ class ExportController extends Controller mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 - $accessNum = M('Spend',"tab_") + $accessNum = $SpendModel ->where($map) ->count(); @@ -1286,7 +1292,7 @@ class ExportController extends Controller // var_dump($count);die(); for($i = 1; $i <= $pages; $i++) { - $xlsData = M('Spend',"tab_") + $xlsData = $SpendModel ->field($fields) ->where($map) ->limit(($i-1)*$perSize ,$perSize) diff --git a/Application/Admin/Controller/FinancePromoteController.class.php b/Application/Admin/Controller/FinancePromoteController.class.php index 93fb2af19..0c7ab2198 100644 --- a/Application/Admin/Controller/FinancePromoteController.class.php +++ b/Application/Admin/Controller/FinancePromoteController.class.php @@ -294,13 +294,12 @@ class FinancePromoteController extends AdminController } $map['s.pay_status']=1; $map['s.is_check']=2; - D("Spend")->addSubsiteWhere($map,"s"); $field= "SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count, SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count, SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as bind_coin_count, IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id, IFNULL(company_id,0) company_id,company_name,develop_type,IFNULL(promote.company_belong,0) company_belong"; - $query = M() + $query = SM() ->table("tab_spend s use index(promote_time)") ->field($field) ->where($map) @@ -379,13 +378,12 @@ class FinancePromoteController extends AdminController } $map['s.pay_status']=1; // $map['s.is_check']=1; - D("Spend")->addSubsiteWhere($map,"s"); $field= "SUM(CASE WHEN pay_way > 0 and s.is_check=1 THEN pay_amount ELSE 0 END) as cash_count, SUM(CASE WHEN pay_way = 0 and s.is_check=1 THEN pay_amount ELSE 0 END) as balance_coin_count, SUM(CASE WHEN pay_way = -1 and s.is_check=1 THEN pay_amount ELSE 0 END) as bind_coin_count, IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id, IFNULL(company_id,0) company_id,company_name,develop_type,IFNULL(promote.company_belong,0) company_belong"; - $query = M() + $query = SM() ->table("tab_spend s use index(promote_time)") ->field($field) ->where($map) @@ -610,13 +608,12 @@ class FinancePromoteController extends AdminController } $map['s.pay_status']=1; $map['s.is_check']=1; - D("Spend")->addSubsiteWhere($map,"s"); // dd($map); $field= "SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count, SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count, SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as bind_coin_count, IFNULL(company_id,0) company_id,company_name,promote_id,promote.account promote_account,develop_type,IFNULL(promote.company_belong,0) company_belong"; - $query = M() + $query = SM() ->table("tab_spend s use index(promote_time)") ->field($field) ->where($map) @@ -895,9 +892,9 @@ class FinancePromoteController extends AdminController $group = ""; $order = "pay_time DESC"; if(isset($_REQUEST['export'])){ - $data = D('spend')->getSpendData($map,$field,$group,$order); + $data = D('spend')->getSubSpendData($map,$field,$group,$order); }else { - $data = D('spend')->getSpendData($map,$field,$group,$order,$page,$row); + $data = D('spend')->getSubSpendData($map,$field,$group,$order,$page,$row); } $marketAdmins = []; @@ -965,7 +962,7 @@ class FinancePromoteController extends AdminController $this->assign('sumInside', $sumInside); $this->assign('sumAll', null_to_0($sumAll)); - $count = D("spend")->getSpendData($map,$field,$group,$order); + $count = D("spend")->getSubSpendData($map,$field,$group,$order); $count = count($count); $page = set_pagination($count,$row); @@ -996,7 +993,7 @@ class FinancePromoteController extends AdminController $map['s.pay_status']=1; $map['s.is_check']=1; - $query = M("spend","tab_")->alias("s") + $query = SM("spend","tab_")->alias("s") ->field("s.game_id,s.game_name,s.sdk_version,p.partner as partner_name, SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count, SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count, @@ -1039,7 +1036,7 @@ class FinancePromoteController extends AdminController $map['s.market_admin_id'] = $adminId; } - $query = M("spend","tab_")->alias("s") + $query = SM("spend","tab_")->alias("s") ->field("SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count, SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count, SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as inside_cash_count"); @@ -1099,7 +1096,7 @@ class FinancePromoteController extends AdminController $row = 10; } $map['pay_status'] = 1; - $map['is_check'] = 1; + $map['tab_spend.is_check'] = 1; if (!empty(I('user_account'))) { $map['tab_spend.user_account'] = array('like','%'.I("user_account").'%'); @@ -1107,7 +1104,7 @@ class FinancePromoteController extends AdminController if (!empty(I('user_nickname'))) { $map['tab_spend.game_player_name'] = array('like',I("user_nickname").'%'); } - D("Spend")->addSubsiteWhere($map,"s"); + D("Spend")->addSubsiteWhere($map,"tab_spend"); $field = "pay_order_number,FROM_UNIXTIME(payed_time) as pay_time,tab_spend.user_account, tab_spend.user_nickname,tab_spend.game_name,tab_spend.promote_account,spend_ip,tab_spend.server_name,tab_spend.sdk_version, game_player_name,pay_amount,cost,pay_way"; diff --git a/Application/Admin/Controller/FinancialSummaryController.class.php b/Application/Admin/Controller/FinancialSummaryController.class.php index b75b0de48..0998a121f 100644 --- a/Application/Admin/Controller/FinancialSummaryController.class.php +++ b/Application/Admin/Controller/FinancialSummaryController.class.php @@ -29,13 +29,7 @@ class FinancialSummaryController extends AdminController if(!IS_ROOT){ $this->OpAuthList= getModuleControllerAuth(); } - $this->assign('menubtn',$this->menuAuth()); - $lastRecount = D("CmdTasks")->getTypeLastTask("FinancialSummary"); - if(!$lastRecount){ - $lastRecount = "无"; - } - $this->assign('lastRecount',$lastRecount); - + $this->assign('menubtn',$this->menuAuth()); $this->getYearList(); $this->getYearData(); $this->display(); @@ -43,9 +37,10 @@ class FinancialSummaryController extends AdminController } public function updateStatement() { - - $temp = date('Y-m',strtotime(date('Y',time()).'-'.(date('m',time())-1).'-01')); - $params = "php ".SUBSITE_INDEX." FinancialSummarySet/setMonthFinancialSummary/recount/1/count_date/{$temp}"; + if(!isset($_REQUEST['time'])) $this->error("参数错误"); + + $time = $_REQUEST['time']; + $params = "php ".SUBSITE_INDEX." FinancialSummarySet/setMonthFinancialSummary/recount/1/count_date/{$time}"; $r = D("CmdTasks")->addTask("FinancialSummary",$params); if($r){ $this->ajaxReturn(["success"=>"ok"]); diff --git a/Application/Admin/Controller/FinancialSummarySetController.class.php b/Application/Admin/Controller/FinancialSummarySetController.class.php index 3a51e78d4..1e6e34a1b 100644 --- a/Application/Admin/Controller/FinancialSummarySetController.class.php +++ b/Application/Admin/Controller/FinancialSummarySetController.class.php @@ -266,12 +266,13 @@ class FinancialSummarySetController extends \Think\Controller */ public function setPromoteMoney() { + $SpendModel = SM("spend",'tab_'); $map = array( "payed_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), "pay_status"=>1, ); D("Spend")->addSubsiteWhere($map,"s"); - $res = $this->SpendModel + $res = $SpendModel ->alias('s') ->field("IFNULL(SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END),0) as cash_count, IFNULL(SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END),0) as balance_coin_count, @@ -358,7 +359,7 @@ class FinancialSummarySetController extends \Think\Controller $unmap = $map; $unmap['is_check'] = 2; - $unSettlementRes = $this->SpendModel + $unSettlementRes = $SpendModel ->alias('s') ->field("IFNULL(SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END),0) as cash_count, IFNULL(SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END),0) as balance_coin_count, diff --git a/Application/Admin/Controller/GameController.class.php b/Application/Admin/Controller/GameController.class.php index bc31f2aad..9ac6db3fb 100644 --- a/Application/Admin/Controller/GameController.class.php +++ b/Application/Admin/Controller/GameController.class.php @@ -484,7 +484,8 @@ ADD COLUMN `kefu_qq` varchar(255) NULL DEFAULT '' COMMENT 'kefu_qq_type为2 时 $otherData['data_share'] = I('post.data.share'); $otherData['game_belong_id'] = I('post.game_belong_id'); $otherData['game_belong_name'] = $realname; - + $otherData['data_share'] = I('post.data_share'); + M('Game', 'tab_')->data($otherData)->where(array('id' => $another['id']))->save(); //同时修改代充游戏折扣 $set_fidel['status'] = 1; diff --git a/Application/Admin/Controller/PlatformController.class.php b/Application/Admin/Controller/PlatformController.class.php index 4531cf3dd..bacd17353 100644 --- a/Application/Admin/Controller/PlatformController.class.php +++ b/Application/Admin/Controller/PlatformController.class.php @@ -255,8 +255,7 @@ class PlatformController extends ThinkController "pay_time"=>["between",$yearMap], "pay_status"=>1 ]; - D("Spend")->addSubsiteWhere($map); - $Payamount = M("Spend","tab_")->field("sum(IF(is_check=1,pay_amount,0)) pay_amount,IFNULL(sum(IF(is_check=2,pay_amount,0)),0) unpay_amount,FROM_UNIXTIME(`pay_time`, '%Y-%m') paytime")->where($map)->group("paytime")->select(); + $Payamount = SM("Spend","tab_")->field("sum(IF(is_check=1,pay_amount,0)) pay_amount,IFNULL(sum(IF(is_check=2,pay_amount,0)),0) unpay_amount,FROM_UNIXTIME(`pay_time`, '%Y-%m') paytime")->where($map)->group("paytime")->select(); if(empty($Payamount)) return ; foreach ($Payamount as $v) { $list[$v['paytime']]['payamount'] = $v['pay_amount']; @@ -271,7 +270,7 @@ class PlatformController extends ThinkController "pay_time"=>["between",$yearMap], "pay_status"=>1 ]; - $Payamount = M("Spend","tab_")->field("sum(IF(is_check=2,pay_amount,0)) pay_amount,FROM_UNIXTIME(`pay_time`, '%Y-%m') paytime")->where($map)->group("paytime")->select(); + $Payamount = SM("Spend","tab_")->field("sum(IF(is_check=2,pay_amount,0)) pay_amount,FROM_UNIXTIME(`pay_time`, '%Y-%m') paytime")->where($map)->group("paytime")->select(); if(empty($Payamount)) return ; foreach ($Payamount as $v) { $list[$v['paytime']]['unpayamount'] = $v['pay_amount']; @@ -1174,7 +1173,7 @@ class PlatformController extends ThinkController } D("Spend")->addSubsiteWhere($map,"s"); - $data = M('promote', 'tab_')->alias('tp1') + $data = SM('promote', 'tab_')->alias('tp1') ->field('tp1.account as promote_account,tp1.id,g.relation_game_id,g.relation_game_name, floor(sum(IF(is_check=1,pay_amount,0))*100) as count,IFNULL(sum(IF(is_check=2,pay_amount,0)),0) unpay_count') ->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left') @@ -1190,7 +1189,7 @@ class PlatformController extends ThinkController if(isset($map['pay_time'])){ $tmap['pay_time'] = ['between', array($tmin,$tmonth[1][1])]; } - $tdata = M('promote', 'tab_')->alias('tp1') + $tdata = SM('promote', 'tab_')->alias('tp1') ->field('tp1.account as promote_account,tp1.id,g.relation_game_id,g.relation_game_name, floor(sum(IF(s.pay_time ' . $today . ' and is_check=1,pay_amount,0))*100) as today, floor(sum(IF(s.pay_time ' . $week . ' and is_check=1,pay_amount,0))*100) as week, @@ -1248,11 +1247,11 @@ class PlatformController extends ThinkController $user_auth_promote_ids = session('user_auth_promote_ids'); if ($user_auth_promote_ids == 'all' || in_array('0', explode(",", $user_auth_promote_ids))) { //官方渠道数据添加 - $authorityData = M('spend', 'tab_')->alias('s') + $authorityData = SM('spend', 'tab_')->alias('s') ->field('floor(sum(IF(is_check=1,pay_amount,0))*100) as count,IFNULL(sum(IF(is_check=2,pay_amount,0)),0) unpay_count') ->where($map) ->find(); - $tauthorityData = M('spend', 'tab_')->alias('s') + $tauthorityData = SM('spend', 'tab_')->alias('s') ->field(' floor(sum(IF(s.pay_time ' . $today . ' and is_check=1,pay_amount,0))*100) as today, floor(sum(IF(s.pay_time ' . $week . ' and is_check=1,pay_amount,0))*100) as week, diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php index 817319353..d160f6d34 100644 --- a/Application/Admin/Controller/SubCompanyStatementSetController.class.php +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -24,7 +24,16 @@ class SubCompanyStatementSetController extends Controller { echo "请先设置请求接口aggregate_cp_settlement_api的值".PHP_EOL;die; } $this->cpapihost = $cpapihost['value']; + // $this->synGame(); } + + //同步游戏表 + // protected function synGame() + // { + // $mainGame = M("Game","tab_")->select(); + // SM()->execute("truncate table tab_game"); + // M("game","tab_",SUBSITE_DB)->addAll($mainGame); + // } /** * Undocumented function * @@ -33,7 +42,7 @@ class SubCompanyStatementSetController extends Controller { * @param string $company all/pc/cp/pu 全部 下游公司 上游 下游个人 * @return void */ - public function setFreeDateCount($begin,$end='',$company='all') + public function setFreeDateCount($begin,$end='',$utime=false,$company='all') { if($end == '') $end = $begin; //判断日期格式 @@ -58,6 +67,9 @@ class SubCompanyStatementSetController extends Controller { for($i=0;$i<$countdate;$i++){ $this->setDailyCount($datelist[$i],$company); } + if($utime){ + M("Kv","sub_",SUBSITE_DB)->where("`key` = 'sub_company_statement'")->save(["value"=>$utime]); + } } public function setDailyCount($stime="now",$company='all') { @@ -74,14 +86,14 @@ class SubCompanyStatementSetController extends Controller { $w = (int)date("w",$stime); if($w == 1){ if($company == "all"){ - echo $nowdate.":".PHP_EOL; - echo "--周结begin".PHP_EOL; + // echo $nowdate.":".PHP_EOL; + // echo "--周结begin".PHP_EOL; $this->cpStatement(0,$stime); - echo "∟----CP周结统计ok".PHP_EOL; + // echo "∟----CP周结统计ok".PHP_EOL; $this->promoteCompanyStatement(0,$stime); - echo "∟----推广公司周结统计ok".PHP_EOL; + // echo "∟----推广公司周结统计ok".PHP_EOL; } if($company == "cp"){ $this->cpStatement(0,$stime); @@ -94,19 +106,18 @@ class SubCompanyStatementSetController extends Controller { } if($d == 1){ if($company == "all"){ - echo $nowdate.":".PHP_EOL; - echo "--月结&补点begin".PHP_EOL; + // echo $nowdate.":".PHP_EOL; + // echo "--月结&补点begin".PHP_EOL; $this->cpStatement(1,$stime); - echo "∟----CP月结&补点统计ok".PHP_EOL; + // echo "∟----CP月结&补点统计ok".PHP_EOL; $this->promoteCompanyStatement(1,$stime); - $this->officeCompanyStatement($stime); //官方结算 - echo "∟----官方/推广公司月结统计ok".PHP_EOL; + // echo "∟----官方/推广公司月结统计ok".PHP_EOL; $this->promoteUserPool(1,$stime); - echo "∟----推广个人月结统计ok".PHP_EOL; + // echo "∟----推广个人月结统计ok".PHP_EOL; } if($company == "cp"){ $this->cpStatement(1,$stime); @@ -122,9 +133,9 @@ class SubCompanyStatementSetController extends Controller { echo "∟----推广个人月结&补点统计ok".PHP_EOL; } } - if($w != 1 && $d != 1){ - echo $nowdate."非月初,无需任何处理".PHP_EOL; - } + // if($w != 1 && $d != 1){ + // echo $nowdate."非月初,无需任何处理".PHP_EOL; + // } } /** * 上游结算 @@ -247,7 +258,6 @@ class SubCompanyStatementSetController extends Controller { $statement_begin_time = date("Y.m.d",$begintime); $statement_end_time = date("Y.m.d",$endtime); $MainStatementDb = M("CompanyStatement","tab_"); //主站结算单 - // dd($cpList); foreach($cpList as $k=>$v){ // $sub_company_id = ($v['first_company_type'] == 1 ? $v['first_company_id'] : $v['second_company_id']); @@ -266,10 +276,13 @@ class SubCompanyStatementSetController extends Controller { if(isset($v['list'][$igm])){ $add_data['statement_info'][$index]['platform_money'] = $v['list'][$igm]['platform_money']; $add_data['statement_info'][$index]['aggregate_money'] = $v['list'][$igm]['aggregate_money']; - $add_data['statement_info'][$index]['ratio'] = $add_data['statement_info'][$index][$ratio_str]; + $game_pay_amount = $v['list'][$igm]['platform_money']-0+$v['list'][$igm]['aggregate_money']; + $ratio = getGameCpRadio($item['relation_game_id'], $game_pay_amount, true) - 0; + $add_data['statement_info'][$index]['ratio'] = $ratio; }else{ $add_data['statement_info'][$index]['platform_money'] = 0; $add_data['statement_info'][$index]['aggregate_money'] = 0; + $add_data['statement_info'][$index]['ratio'] = 0; } } unset($add_data['id'],$add_data['remark'],$add_data['confirm_status'],$add_data['confirm_log']); @@ -396,7 +409,7 @@ class SubCompanyStatementSetController extends Controller { $Promote = M("Promote","tab_"); - $Spend = M("Spend","tab_"); + $Spend = SM("Spend","tab_"); $spenMap = [ "s.pay_status"=>1, "s.payed_time"=>['between', [$begintime,$endtime]], @@ -614,7 +627,7 @@ class SubCompanyStatementSetController extends Controller { //获取推广员 if(count($idarr) == 0){return $res;} $Promote = M("Promote","tab_"); - $Spend = M("Spend","tab_"); + $Spend = SM("Spend","tab_"); $spenMap = [ "s.pay_status"=>1, "s.payed_time"=>['between', [$begintime,$endtime]], @@ -994,7 +1007,7 @@ class SubCompanyStatementSetController extends Controller { $res = []; //获取推广员 $Promote = M("Promote","tab_"); - $Spend = M("Spend","tab_"); + $Spend = SM("Spend","tab_"); $spenMap = [ "s.pay_status"=>1, "s.payed_time"=>['between', [$begintime,$endtime]], @@ -1021,7 +1034,7 @@ class SubCompanyStatementSetController extends Controller { $res = []; //获取推广员 $Promote = M("Promote","tab_"); - $Spend = M("Spend","tab_"); + $Spend = SM("Spend","tab_"); $spenMap = [ "s.pay_status"=>1, "s.payed_time"=>['between', [$begintime,$endtime]], diff --git a/Application/Admin/Controller/SubSpendController.class.php b/Application/Admin/Controller/SubSpendController.class.php new file mode 100644 index 000000000..0d0d1f8dd --- /dev/null +++ b/Application/Admin/Controller/SubSpendController.class.php @@ -0,0 +1,647 @@ + + */ +class SubSpendController extends ThinkController +{ + const model_name = 'Spend'; + public $OpAuthList; + + public function lists() + { + list($is_sub_data, $startTime, $endTime) = $this->setSelectDate(); + // dump($is_sub_data); + // dump($startTime); + // dump($endTime); + // dd(1); + $map['pay_time'] = array('BETWEEN', array($startTime, $endTime)); + if (isset($_REQUEST['is_check'])) { + $map['is_check'] = (int)($_REQUEST['is_check']); + } + + if (isset($_REQUEST['user_account'])) { + $map['user_account'] = array('like', trim($_REQUEST['user_account'])); + unset($_REQUEST['user_account']); + } + if (isset($_REQUEST['spend_ip'])) { + $map['spend_ip'] = array('like', trim($_REQUEST['spend_ip']) . '%'); + unset($_REQUEST['spend_ip']); + } + if (isset($_REQUEST['game_name'])) { + if ($_REQUEST['game_name'] == '全部') { + unset($_REQUEST['game_name']); + } else { + $map['game_id'] = ['in', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')]; + unset($_REQUEST['game_name']); + } + } + if (isset($_REQUEST['game_type']) && $_REQUEST['game_type']) { + $map['sdk_version'] = $_REQUEST['game_type']; + } + if (isset($_REQUEST['server_id'])) { + $map['server_id'] = $_REQUEST['server_id']; + unset($_REQUEST['server_id']); + } + if (isset($_REQUEST['pay_order_number'])) { + $map['pay_order_number'] = array('like', trim($_REQUEST['pay_order_number'])); + unset($_REQUEST['pay_order_number']); + } + if (isset($_REQUEST['extend'])) { + $map['extend'] = array('like', trim($_REQUEST['extend'])); + unset($_REQUEST['extend']); + } + if (isset($_REQUEST['pay_status'])) { + $map['pay_status'] = $_REQUEST['pay_status']; + unset($_REQUEST['pay_status']); + } + if (isset($_REQUEST['pay_way'])) { + if ($_REQUEST['pay_way'] == 2) { + $map['pay_way'] = ['in', '2,3,4']; + } else { + $map['pay_way'] = $_REQUEST['pay_way']; + } + unset($_REQUEST['pay_way']); + } + if (isset($_REQUEST['pay_game_status'])) { + $map['pay_game_status'] = $_REQUEST['pay_game_status']; + unset($_REQUEST['pay_game_status']); + } + + if ($_REQUEST['merchant_id']) { + $map['merchant_id'] = $_REQUEST['merchant_id']; + unset($_REQUEST['merchant_id']); + } + + if (isset($_REQUEST['promote_id']) || isset($_REQUEST['company_id'])) { + $promoteId = I('promote_id',-1); + $companyId = I('company_id',-1); + if ($promoteId == 0 || $companyId == 0) { + $map['promote_id'] = 0; + } else { + if($companyId != -1){ + $promoteMap['company_id'] = $companyId; + } + if($promoteId != -1){ + $promoteMap['chain'] = ['like', "%/$promoteId/%"]; + } + $promoteIds = M('Promote', 'tab_')->where($promoteMap)->getField('id', true); + $promoteIds[] = $promoteId; + $map['promote_id'] = ['in', $promoteIds]; + } + } + if ($_REQUEST['data_order'] != '') { + $data_order = reset(explode(',', $_REQUEST['data_order'])); + $data_order_type = end(explode(',', $_REQUEST['data_order'])); + $this->assign('userarpu_order', $data_order); + $this->assign('userarpu_order_type', $data_order_type); + $sort = $data_order == 3 ? 'desc' : 'asc'; + $order = $data_order_type . ' ' . $sort; + } else { + $order = ' pay_time desc '; + } + if (I('platform_type', 0) != 0) { + $sy = I('platform_type', 0) == 1 ? '=' : '<>'; + $game_id = M("Game","tab_")->where('unique_code ' . $sy . ' ""')->getField("id",true); + $map['game_id'] = ['in',$game_id]; + } + + D("Spend")->addSubsiteWhere($map); + $this->meta_title = $this->m_title = '游戏充值'; + $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Spend/lists', 'status' => 1])->find()); + + $data = $this->getSpendList($_GET["p"], $map, $order,$is_sub_data); + if (!empty($data['data'])) { + $adminUsernameList = getAdminUsernameList(array_column($data['data'], 'market_admin_id')); + foreach ($data['data'] as $key=>&$value) { + ($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):''; + $value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无'; + $value['is_check_str'] = D(self::model_name)::IsCheckStr[$value['is_check']]; + //拆分游戏名称和设备类型 + $game_arr = explode("(", rtrim($value['game_name'], ")")); + $value['game_name'] = $game_arr[0]; + $value['sdk_version_name'] = $game_arr[1]; + } + } + + $promoteCompany = M('promote_company','tab_')->field('id, company_name as name')->where(['status' => 1])->select(); + array_unshift($promoteCompany,['id'=>0,'name'=>C('OFFICIEL_CHANNEL')]); + $this->assign('promoteCompany', $promoteCompany); + + $this->assign('showMarketAdmin', session('user_auth')['show_market_admin']); + $this->assign('showPromote', session('user_auth')['show_promote']); + $this->assign('isMarketAdmin', $isMarketAdmin); + $this->assign('marketAdmins', getMarketAdmins()); + $this->assign('list_data', $data['data']); + $this->assign('_page', $data['page']); + $show_data_power = (is_administrator()|| session('user_auth')['show_data']); + $this->assign('show_data_power', $show_data_power); + + if(!IS_ROOT){ + $this->OpAuthList= getModuleControllerAuth(); + } + + $this->assign('menubtn',$this->menuAuth($is_sub_data)); + $this->display(); + } + public function exportList() + { + $xlsName = $_REQUEST['xlsname']; + $startDate = empty($_REQUEST['timestart']) ? date('Y-m-d', strtotime('-6 day', time())) : $_REQUEST['timestart']; + $endDate = empty($_REQUEST['timeend']) ? date('Y-m-d') : $_REQUEST['timeend']; + + $startTime = strtotime($startDate); + $endTime = strtotime($endDate) + 86399; + $map['pay_time'] = array('BETWEEN', array($startTime, $endTime)); + $is_sub_data = I("issubdata",0); + if($is_sub_data == 1){ + $SpendModel = M("spend","tab_",SUBSITE_DB); + }else{ + $SpendModel = M("spend","tab_"); + } + unset($_REQUEST['timestart']); + unset($_REQUEST['timeend']); + + if (isset($_REQUEST['user_account'])) { + $map['user_account'] = array('like', trim($_REQUEST['user_account'])); + unset($_REQUEST['user_account']); + } + if (isset($_REQUEST['spend_ip'])) { + $map['spend_ip'] = array('like', trim($_REQUEST['spend_ip']) . '%'); + unset($_REQUEST['spend_ip']); + } + if (isset($_REQUEST['game_name'])) { + if ($_REQUEST['game_name'] == '全部') { + unset($_REQUEST['game_name']); + } else { + $map['game_id'] = ['in', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')]; + unset($_REQUEST['game_name']); + } + } + if (isset($_REQUEST['game_type']) && $_REQUEST['game_type']) { + $map['sdk_version'] = $_REQUEST['game_type']; + } + if (isset($_REQUEST['server_id'])) { + $map['server_id'] = $_REQUEST['server_id']; + unset($_REQUEST['server_id']); + } + if (isset($_REQUEST['pay_order_number'])) { + $map['pay_order_number'] = array('like', trim($_REQUEST['pay_order_number'])); + unset($_REQUEST['pay_order_number']); + } + if (isset($_REQUEST['extend'])) { + $map['extend'] = array('like', trim($_REQUEST['extend'])); + unset($_REQUEST['extend']); + } + if (isset($_REQUEST['pay_status'])) { + $map['pay_status'] = $_REQUEST['pay_status']; + unset($_REQUEST['pay_status']); + } + if (isset($_REQUEST['pay_way'])) { + if ($_REQUEST['pay_way'] == 2) { + $map['pay_way'] = ['in', '2,3,4']; + } else { + $map['pay_way'] = $_REQUEST['pay_way']; + } + unset($_REQUEST['pay_way']); + } + + if (isset($_REQUEST['is_check'])) { + $map['is_check'] = (int)($_REQUEST['is_check']); + unset($_REQUEST['is_check']); + } + + if ($_REQUEST['merchant_id']) { + $map['merchant_id'] = $_REQUEST['merchant_id']; + unset($_REQUEST['merchant_id']); + } + + if (isset($_REQUEST['pay_game_status'])) { + $map['pay_game_status'] = $_REQUEST['pay_game_status']; + unset($_REQUEST['pay_game_status']); + } + + if (isset($_REQUEST['promote_id']) || isset($_REQUEST['company_id'])) { + $promoteId = I('promote_id',-1); + $companyId = I('company_id',-1); + if ($promoteId == 0 || $companyId == 0) { + $map['promote_id'] = 0; + } else { + if($companyId != -1){ + $promoteMap['company_id'] = $companyId; + } + if($promoteId != -1){ + $promoteMap['chain'] = ['like', "%/$promoteId/%"]; + } + $promoteIds = M('Promote', 'tab_')->where($promoteMap)->getField('id', true); + $promoteIds[] = $promoteId; + $map['promote_id'] = ['in', $promoteIds]; + } + } + if ($_REQUEST['data_order'] != '') { + $data_order = reset(explode(',', $_REQUEST['data_order'])); + $data_order_type = end(explode(',', $_REQUEST['data_order'])); + $this->assign('userarpu_order', $data_order); + $this->assign('userarpu_order_type', $data_order_type); + $sort = $data_order == 3 ? 'desc' : 'asc'; + $order = $data_order_type . ' ' . $sort; + } else { + $order = ' pay_time desc '; + } + + if (I('platform_type', 0) != 0) { + $sy = I('platform_type', 0) == 1 ? '=' : '<>'; + $game_id = M("Game","tab_")->where('unique_code ' . $sy . ' ""')->getField("id",true); + $map['game_id'] = ['in',$game_id]; + } + + // if (intval(($endTime + 1) - $startTime) / (24 * 3600) <= 31) { + // $map1 = $map; + // $map1['pay_status'] = 1; + // } else { + // $map = '1 = 2'; + // $map1 = $map; + // } + D("Spend")->addSubsiteWhere($map); + $map1 = $map; + $map1['pay_status'] = 1; + $total = $SpendModel->where($map1)->sum('pay_amount'); +// var_dump($total);die(); + $total=$total?$total:0; + + + $headers = [ + 'pay_order_number' => '支付订单号', + 'extend' => 'CP订单号', + 'pay_time' => '充值时间', + 'payed_time' => '支付时间', + 'user_account' => '玩家账号', + 'game_name' => '游戏名称', + 'sdk_version' => '设备类型', + 'game_id' => '所属CP', + 'promote_account' => L('Subordinate_channel'), + '0 as company_name' => '所属推广公司', + 'market_admin_id' => '所属市场专员', + 'merchant_id' => '所属商户', + 'spend_ip' => '充值ip', + 'server_id' => '区服ID', + 'server_name' => '游戏区服', + 'game_player_id' => '角色ID', + 'game_player_name' => '角色名称', + 'cost' => '订单金额', + 'pay_amount' => '实付金额', + 'pay_way' => '充值方式', + 'pay_status' => L('Order_status'), + 'pay_game_status' => '游戏通知状态', + 'is_check' => '是否参与结算', + 'promote_id' => "消费"."{$total}", + ]; + + + $xlsCell = array_values($headers); + $fields = array_keys($headers); + // ----获取游戏的基本信息begin + //获取游戏公司 + $cpCompanyDb = M("partner","tab_")->field("id,partner")->order("id asc")->select(); + $cpCompany = []; + foreach ($cpCompanyDb as $index => $cp) { + $cpCompany[$cp['id']]=$cp['partner']; + } + unset($cpCompanyDb); + //获取所有游戏 + $gameDb = M("Game","tab_")->field("id,relation_game_name,partner_id")->order("id asc")->select(); + $gameInfo = []; + foreach ($gameDb as $index => $g) { + $partner_name = $cpCompany[$g['partner_id']]; + $g['partner_name'] = $partner_name; + $gameInfo[$g['id']]=$g; + } + unset($cpCompany); + unset($gameDb); + // ----获取游戏的基本信息end + + $csvFileName = $xlsName.'.csv'; + //设置好告诉浏览器要下载excel文件的headers + header('Content-Description: File Transfer'); + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + $fp = fopen('php://output', 'a');//打开output流 + mb_convert_variables('GBK', 'UTF-8', $xlsCell); + fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 + + $accessNum = $SpendModel + ->where($map) + ->count(); + + + $perSize = 10000;//每次查询的条数 + $pages = ceil($accessNum / $perSize); + +// var_dump($count);die(); + for($i = 1; $i <= $pages; $i++) { + $xlsData = $SpendModel + ->field($fields) + ->where($map) + ->limit(($i-1)*$perSize ,$perSize) + ->order($order ? $order : 'pay_time desc') + ->select(); + if ($showMarketAdmin == 1) { + $adminUsernameList = getAdminUsernameList(array_column($xlsData, 'market_admin_id')); + } + $promoters = D('Promote')->where(['id'=>['in', array_unique(array_column($xlsData, 'promote_id'))]])->field('id, company_id')->select(); + $promoters = $promoters ? array_column($promoters, 'company_id', 'id') : []; + $companys = $promoters ? M('promote_company', 'tab_')->where(['id'=>['in', array_unique(array_values($promoters))]])->field('id, company_name')->select() : []; + $companys = $companys ? array_column($companys, 'company_name', 'id') : []; + + foreach($xlsData as $value) { + //游戏信息匹配 + $thisGameInfo = $gameInfo[$value["game_id"]]; + $value['game_name'] =$thisGameInfo['relation_game_name']; + $value['sdk_version'] = $value['sdk_version'] == 1 ? "安卓" : "苹果"; + $value['game_id'] = $thisGameInfo['partner_name']; + + $value['is_check'] = D("Spend")::IsCheckStr[$value['is_check']]; + + $value['company_name'] = $promoters[$value['promote_id']] == 0 ? C('OFFICIEL_CHANNEL') : ($companys[$promoters[$value['promote_id']]] ?? ''); + unset($value['promote_id']); + $value['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']); + if($value['pay_status'] == 1) { + $value['payed_time'] = date('Y-m-d H:i:s',$value['payed_time']); + }else { + $value['payed_time'] = "------"; + } + $value['merchant_id'] = getMerchantName($value['merchant_id']); + checkEncryptionAuth($value['user_account'],'spend_lists'); + ($value['promote_account']=='官方渠道'||$value['promote_account']=='自然注册')?($value['promote_account']=C('OFFICIEL_CHANNEL')):''; + $value['extend'] = $value['extend'].'`'; + $value['pay_way'] = get_pay_way($value['pay_way']); + $value['pay_status'] = get_info_status($value['pay_status'],9); + $value['pay_game_status'] = get_info_status($value['pay_game_status'],14); + $value['market_admin_id'] = $adminUsernameList[$value['market_admin_id']] ?? '无'; + mb_convert_variables('GBK', 'UTF-8', $value); + fputcsv($fp, $value); + } + unset($xlsData);//释放变量的内存 + //刷新输出缓冲到浏览器 + ob_flush(); + flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 + } + fclose($fp); + //操作日志 + $GetData = $_GET; + unset($GetData['xlsname']); + addOperationLog(['op_type'=>3,'key'=>getNowDate(),'url'=>U('Spend/lists',$GetData),'menu'=>'充值-游戏订单-游戏充值-导出']); + } + + protected function menuAuth($is_sub_data = false) + { + $is_can_add = D("CmdTasks")->isCanAddTask("SubSpendSet"); + if($is_can_add){ + $mentBtn = [ + "addSubSpendSet"=>"固定订单", + "updateSubSpend"=>"重固订单" + ]; + }else{ + $mentBtn = []; + } + if($is_sub_data){ + $mentBtn['changeSubSpend'] = "订单换绑"; + $mentBtn['addStatement'] = "参与结算"; + $mentBtn['removeStatement'] = "移出结算"; + } + $resarr = []; + foreach ($mentBtn as $k => $v) { + if(IS_ROOT){ + $resarr[] = $v; + }else{ + if(in_array($k,$this->OpAuthList)){ + $resarr[] = $v; + } + } + } + return $resarr; + } + + + + public function addSubSpendSet(){ + if(!isset($_REQUEST['time'])) $this->error("参数错误"); + $time = $_REQUEST['time']; + $params = "php ".SUBSITE_INDEX." SubSpendSet/setSubSpend/time/{$time}"; + $r = D("CmdTasks")->addTask("SubSpendSet",$params); + if($r){ + $this->ajaxReturn(["status"=>1,"info"=>"固化数据任务登记成功,请等待两三分钟后查看结果"]); + }else{ + $this->ajaxReturn(["status"=>0,"info"=>"固化数据任务登记错误"]); + } + } + public function changeSubSpend(){ + if (IS_POST) { + $this->editSubSpend(); + }else{ + $this->showChooseSubSpendCount(); + } + } + + public function updateSubSpend(){ + if(!isset($_REQUEST['begin']) || !isset($_REQUEST['end'])) $this->error("参数错误"); + $begin = $_REQUEST['begin']; + $end = $_REQUEST['end']; + + $params = "php ".SUBSITE_INDEX." SubSpendSet/recountSubSpend/begin/{$begin}/end/{$end}"; + $r = D("CmdTasks")->addTask("SubSpendSet",$params); + if($r){ + $this->ajaxReturn(["status"=>1,"info"=>"重算任务登记成功,请等待两三分钟后查看结果"]); + }else{ + $this->ajaxReturn(["status"=>0,"info"=>"重算任务登记错误"]); + } + } + + public function addStatement() + { + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + $this->editOrderIscheck($ids,2,1); + $this->ajaxReturn(array( + 'status' => 1, + "info"=>"操作成功" + )); + } + public function removeStatement() + { + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + $this->editOrderIscheck($ids,1,2); + $this->ajaxReturn(array( + 'status' => 1, + "info"=>"操作成功" + )); + + } + protected function editSubSpend(){ + if(!isset($_REQUEST['ids']) || !isset($_REQUEST['company_id']) ) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + $company_id = $_REQUEST['company_id']; + if($company_id == 0){ + $saveData = [ + "promote_id"=>0, + "promote_account"=>'官方渠道', + "market_admin_id"=>0, + ]; + }else{ + //获取会长及adminid + $promote = M("promote","tab_")->field("id,account,admin_id")->where("company_id = '{$company_id}' and level = '1' and status = '1'")->find(); + $saveData = [ + "promote_id"=>$promote['id'], + "promote_account"=>$promote['account'], + "market_admin_id"=>$promote['admin_id'], + ]; + } + $where = [ + "id"=>['in',$ids] + ]; + M("spend","tab_",SUBSITE_DB)->where($where)->save($saveData); + $this->ajaxReturn([ + 'status' => 1, + "info"=>"换绑成功" + ]); + + } + + + protected function showChooseSubSpendCount(){ + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + + $dbres = M("spend","tab_",SUBSITE_DB)->where("id in ({$ids})")->group("promote_id")->getField("promote_id,SUM(pay_amount) pay_amount"); + //获取公司 + $promoteIds = implode(",",array_keys($dbres)); + $company = M("promote","tab_") + ->alias('p') + ->where("p.id in ({$promoteIds})") + ->join("tab_promote_company c on p.company_id = c.id","left") + ->group("p.company_id") + ->getField("company_id,group_concat(p.id) promote_ids,c.company_name"); + $sendData = [ + "count" => 0, + "list"=>[] + ]; + foreach ($company as $k => $v) { + $v['promote_ids'] = explode(",",$v['promote_ids']); + $v['pay_amount'] = 0; + foreach($v['promote_ids'] as $promote_id){ + $v['pay_amount'] += ($dbres[$promote_id]-0); + unset($dbres[$promote_id]); + } + unset($v['promote_ids'],$v['company_id']); + $sendData['count'] += $v['pay_amount']; + $sendData['list'][] = $v; + } + if(count($dbres) > 0){ + $office_pay_amount = 0; + foreach ($dbres as $value) { + $office_pay_amount += ($value-0); + } + $sendData['list'][]= ["company_name"=>C('OFFICIEL_CHANNEL'),"pay_amount"=>$office_pay_amount]; + $sendData['count'] += $office_pay_amount; + } + //获取所有公司 + $promoteCompany = M('promote_company','tab_')->field('id, company_name as name')->where(['status' => 1])->select(); + array_unshift($promoteCompany,['id'=>0,'name'=>C('OFFICIEL_CHANNEL')]); + $this->assign('promoteCompany', $promoteCompany); + $this->assign('data', $sendData); + $this->assign('ids', $ids); + $this->display("showChooseSubSpendCount"); + } + + protected function editOrderIscheck($ids,$oldval,$newval){ + $dbres = M("spend","tab_",SUBSITE_DB)->where("id in ({$ids}) and is_check = '{$oldval}'")->select(); + if(empty($dbres)) return false; + + $changeIds = implode(",",array_column($dbres,"id")); + //执行操作 + $res = D(self::model_name)->where("id in ({$changeIds}) and is_check = '{$oldval}'")->save(['is_check'=>$newval]); + if(empty($res)) return false; + //日志 + if($newval == 1){ + $op_name = "加入结算"; + $key = "addStatement"; + }else{ + $op_name = "移出结算"; + $key = "removeStatement"; + } + addOperationLog(['op_type'=>1,'key'=>$key,"op_name"=>$op_name,"content"=>json_encode(["ids"=>$_REQUEST['ids'],"is_check"=>$newval])]); + return true; + } + protected function setSelectDate() + { + $startDate = empty($_REQUEST['timestart']) ? date('Y-m-d', strtotime('-6 day', time())) : $_REQUEST['timestart']; + $endDate = empty($_REQUEST['timeend']) ? date('Y-m-d') : $_REQUEST['timeend']; + unset($_REQUEST['timestart']); + unset($_REQUEST['timeend']); + $startTime = strtotime($startDate); + $endTime = strtotime($endDate) + 86399; + $is_sub_data = false; + $lastSynTime = M("Kv","sub_",SUBSITE_DB)->where("`key` = 'sub_spend_syn_time'")->getField("value"); + if($lastSynTime >= $startTime && $lastSynTime < $endTime){ + $this->redirect(ACTION_NAME, array('timestart' => $startDate,"timeend"=>date('Y-m-d',$lastSynTime))); + } + if($lastSynTime >= $startTime && $lastSynTime <= $endTime){ + $is_sub_data = true; + $endTime = $lastSynTime; + } + if($lastSynTime > $endTime){ + $is_sub_data = true; + } + + $this->assign('startDate', date('Y-m-d',$startTime)); + $this->assign('endDate', date('Y-m-d',$endTime)); + $this->assign('isSubData', $is_sub_data ? 1 : 0); + $this->assign('lastSynTime', date('Y-m-d',$lastSynTime)); + return [$is_sub_data,$startTime,$endTime]; + } + + protected function getSpendList($p = 1, $map = array(), $order, $is_sub_data) + { + $page = intval($p); + $page = $page ? $page : 1; //默认显示第一页数据 + if (isset($_REQUEST['row'])) { + $row = $_REQUEST['row']; + } else { + $row = 10; + } + if($is_sub_data){ + $SpendModel = M("spend","tab_",SUBSITE_DB); + }else{ + $SpendModel = M("spend","tab_"); + } + + $list = $SpendModel + ->where($map) + ->page($page, $row) + ->order($order ? $order : 'pay_time desc') + ->select(); + $count = $SpendModel->where($map)->count(); + + if($count < 20000){ + $page = set_pagination_all($count, $row); + }else{ + $page = set_pagination($count, $row); + } + $data['data'] = $list; + if ($page) { + $data['page'] = $page; + } + + $total = null_to_0($SpendModel->where($map)->where("pay_status = 1")->sum('pay_amount')); + $this->assign('total', $total); + + return $data; + } + +} diff --git a/Application/Admin/Controller/SubSpendSetController.class.php b/Application/Admin/Controller/SubSpendSetController.class.php new file mode 100644 index 000000000..ea24935e1 --- /dev/null +++ b/Application/Admin/Controller/SubSpendSetController.class.php @@ -0,0 +1,107 @@ +1, + "partner_type"=>["in",[0,PARTNER_TYPE]] + ]; + + public function _initialize() + { + $this->SubSpendModel = M("spend","tab_",SUBSITE_DB);//指定子库 + $this->MainSpendModel = M("spend","tab_");//指定子库 + $this->SubKvModel = M("Kv","sub_",SUBSITE_DB);//指定子库 + $this->LastSynTime = $this->SubKvModel->where("`key` = 'sub_spend_syn_time'")->getField("value"); + } + + public function setSubSpend($time) + { + if($time == '') die("时间不能为空"); + //判断日期格式 + $patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/"; + if (!preg_match($patten, $time)) { + die("时间格式错误"); + } + if(strtotime($time)+86399-24*3600 > time()){ + die("时间不能大于当前"); + } + $this->SynTime = strtotime($time)+86399; + if($this->SynTime <= $this->LastSynTime){ + die("时间不能小于最后同步时间"); + } + $this->SynWhere['payed_time'] = ['between', [$this->LastSynTime-0+1,$this->SynTime]]; + + if($this->pageSetSpend()){ + $this->updateLastSynTime(); + }; + echo "sub_spend syn ok".PHP_EOL; + } + + public function recountSubSpend($begin,$end) + { + $patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/"; + if (!preg_match($patten, $begin)) { + die("开始时间格式错误"); + } + if (!preg_match($patten, $end)) { + die("结束时间格式错误"); + } + if(strtotime($end) < strtotime($begin)){ + die("结束时间不能比开始时间小"); + } + if(strtotime($end)+86399 > $this->LastSynTime){ + die("结束时间不能大于最后同步时间"); + } + $end = strtotime($end)+86399; + $begin = strtotime($begin); + $this->SynWhere['payed_time'] = ['between', [$begin,$end]]; + if($this->delSubSpend() !== false){ + echo "delete sub_spend ok".PHP_EOL; + $this->pageSetSpend(); + } + echo "sub_spend update and syn ok".PHP_EOL; + } + //分页插入同步数据 + protected function pageSetSpend() + { + $count = $this->getSynCount(); + if(empty($count)) return true; + $pageCount = ceil($count/self::LIMIT); + for ($i=1; $i <= $pageCount; $i++) { + $tres = $this->MainSpendModel->where($this->SynWhere)->page($i,self::LIMIT)->select(); + $addRes = $this->SubSpendModel->addAll($tres); + echo "[{$i}/{$pageCount}] {$addRes}".PHP_EOL; + } + return true; + } + //删除本地已同步数据 + protected function delSubSpend() + { + return $this->SubSpendModel->where($this->SynWhere)->delete(); + } + //获取需要同步的数量 + protected function getSynCount() + { + return $this->MainSpendModel->where($this->SynWhere)->count(); + } + //更新最后同步时间 + protected function updateLastSynTime() + { + return $this->SubKvModel->where("`key` = 'sub_spend_syn_time'")->save(['value'=>$this->SynTime]); + } +} diff --git a/Application/Admin/Controller/SubSynTableController.class.php b/Application/Admin/Controller/SubSynTableController.class.php new file mode 100644 index 000000000..abed98117 --- /dev/null +++ b/Application/Admin/Controller/SubSynTableController.class.php @@ -0,0 +1,73 @@ +SubSynTableModel = M("syn_table","sub_",SUBSITE_DB);//指定子库 + } + + public function run(){ + $synList = $this->SubSynTableModel->field("id,table_name,table_prefix,check_sum")->select(); + foreach ($synList as $k => $v) { + $this->doSyn($v); + } + } + + public function synOneTable($table_prefix,$tab_name) + { + $synInfo = $this->SubSynTableModel->where("table_name = '{$tab_name}' and table_prefix = '{$table_prefix}'")->field("id,table_name,table_prefix,check_sum")->find(); + $this->doSyn($synInfo); + } + + protected function doSyn($dbarr) + { + //获取最新check_sum + $table_prefix = $dbarr['table_prefix']; + $table_name = $dbarr['table_name']; + $res = M()->query(self::CHECK_SUM_SQL.$table_prefix.$table_name); + $now = time(); + $check_sum = $res[0]['checksum']; + if($check_sum !== $dbarr['check_sum']){ + $this->clearTable($table_prefix,$table_name); + $this->synTable($table_prefix,$table_name); + $dbarr['syn_time'] = $now; + $dbarr['check_sum'] = $check_sum; + } + $dbarr['update_time'] = $now; + $this->SubSynTableModel->save($dbarr); + echo $table_prefix.$table_name." success".PHP_EOL; + } + protected function clearTable($table_prefix,$table_name) + { + return SM()->query(self::TRUNCATE_SQL.$table_prefix.$table_name); + } + protected function synTable($table_prefix,$table_name) + { + $count = M($table_name,$table_prefix)->count(); + if(empty($count)) return true; + $pageCount = ceil($count/self::LIMIT); + for ($i=1; $i <= $pageCount; $i++) { + $tres = M($table_name,$table_prefix)->page($i,self::LIMIT)->select(); + $addRes = M($table_name,$table_prefix,SUBSITE_DB)->addAll($tres); + echo "[{$i}/{$pageCount}] {$addRes}".PHP_EOL; + } + return true; + } + +} diff --git a/Application/Admin/Controller/TestingResourceController.class.php b/Application/Admin/Controller/TestingResourceController.class.php index 882a80204..6faf72c8c 100644 --- a/Application/Admin/Controller/TestingResourceController.class.php +++ b/Application/Admin/Controller/TestingResourceController.class.php @@ -9,10 +9,11 @@ use Base\Service\TestingResourceService; use Base\Service\PartnerService; use Base\Repository\TestingResourceRepository; use Base\Repository\GameRepository; +use Base\Service\GameService; class TestingResourceController extends ThinkController { - public function index() + public function roles() { $params = I('get.'); $gameId = $params['game_id'] ?? 0; @@ -439,14 +440,25 @@ class TestingResourceController extends ThinkController $bindingRole = null; if ($role) { $servers = M('server', 'tab_')->field('id,server_name,server_id')->where(['game_id' => $role['game_id']])->order('server_id asc')->select(); + $game = M('game', 'tab_')->where(['id' => $role['game_id']])->find(['id', 'data_share']); $binding = M('testing_binding', 'tab_')->where(['game_id' => $role['game_id'], 'role_id' => $role['role_id']])->find(); if ($binding) { + + $gameIds = [$role['game_id']]; + if ($game['data_share'] == 1) { + $gameRepository = new GameRepository(); + $baseGames = $gameRepository->getBaseGames(); + $baseGame = $gameRepository->getBaseGameByGameId($role['game_id'], $baseGames); + $gameIds = $gameRepository->getGameIdsByBaseGame($baseGame); + } + $bindingRole = M('user_play_info', 'tab_') ->field(['id', 'role_id', 'user_id', 'game_id', 'server_id', 'user_account', 'role_name']) - ->where(['game_id' => $binding['game_id'], 'role_id' => $binding['bind_role_id']]) + ->where(['game_id' => ['in', $gameIds], 'role_id' => $binding['bind_role_id']]) ->find(); if ($bindingRole) { $bindingRole['binding_time'] = $binding['create_time']; + $bindingRole['share_game_ids'] = $gameIds; } } @@ -456,7 +468,6 @@ class TestingResourceController extends ThinkController $hasItf = $gameSetting ? $gameSetting['has_itf'] : 0; } - $testingResourceService = new TestingResourceService(); $quota = $testingResourceService->getRemainQuota($role, $bindingRole); @@ -574,34 +585,17 @@ class TestingResourceController extends ThinkController $otherQuota = I('other_quota', 0); $otherQuotaRemark = I('otherQuotaRemark', ''); M('user_play_info', 'tab_')->where(['id' => $id])->save(['testing_other_quota' => $otherQuota,'testing_other_quota_remark' => $otherQuotaRemark]); + $admin_account = $_SESSION['onethink_admin']['user_auth']['username']; + $otherQuotaRemark = !empty($otherQuotaRemark) ? $otherQuotaRemark : '无'; + addOperationLog(array( + "op_type"=>1, + 'op_name'=>'修改额外额度记录', + "key"=>'/'.$admin_account.'修改了额外额度'.$otherQuota.',备注信息为'.$otherQuotaRemark.'/', + "url"=>U("TestingResource/index") + )); return $this->ajaxReturn(['status' => 1, 'message' => '设置成功']); } - public function getUserRoles() - { - $gameId = I('game_id', 0); - $serverId = I('server_id', 0); - $userAccount = I('user_account', ''); - $server = M('server', 'tab_')->field(['id', 'server_name', 'server_id'])->where(['id' => $serverId])->find(); - if (is_null($server)) { - return $this->ajaxReturn(['status' => 0, 'message' => '区服不存在']); - } - - $user = M('user', 'tab_')->field(['id', 'promote_id'])->where(['account' => $userAccount])->find(); - if (is_null($user)) { - return $this->ajaxReturn(['status' => 0, 'message' => '账号不存在']); - } - - $testingUser = M('testing_user', 'tab_')->where(['user_account' => $userAccount])->find(); - $isTestingAccount = is_null($testingUser) ? false : true; - - $roles = M('user_play_info', 'tab_') - ->field(['id', 'role_id', 'role_name']) - ->where(['user_account' => $userAccount, 'game_id' => $gameId, 'server_id' => $server['server_id']]) - ->select(); - return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles, 'is_testing_account' => $isTestingAccount]]); - } - public function getResourceTypes() { $gameId = I('game_id', 0); @@ -759,4 +753,33 @@ class TestingResourceController extends ThinkController return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]); } } + + public function getUserRoles() + { + $gameId = I('game_id', 0); + $roleId = I('role_id', 0); + + $game = M('game', 'tab_')->where(['id' => $gameId])->find(); + if (is_null($game)) { + return $this->ajaxReturn(['status' => 0, 'message' => '游戏不存在']); + } + + $gameIds = [$gameId]; + if ($game['data_share'] == 1) { + $gameRepository = new GameRepository(); + $baseGames = $gameRepository->getBaseGames(); + $baseGame = $gameRepository->getBaseGameByGameId($gameId, $baseGames); + if (is_null($baseGame)) { + return $this->ajaxReturn(['status' => 0, 'message' => '游戏不存在']); + } + $gameIds = $gameRepository->getGameIdsByBaseGame($baseGame); + } + + $roles = M('user_play_info', 'tab_') + ->field(['id', 'role_id', 'role_name']) + ->where(['role_id' => $roleId, 'game_id' => ['in', $gameIds]]) + ->select(); + + return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles]]); + } } \ No newline at end of file diff --git a/Application/Admin/Model/SpendModel.class.php b/Application/Admin/Model/SpendModel.class.php index 0ce2fb602..51fecfd41 100644 --- a/Application/Admin/Model/SpendModel.class.php +++ b/Application/Admin/Model/SpendModel.class.php @@ -843,6 +843,19 @@ class SpendModel extends Model } return $data; } + public function getSubSpendData($map = [], $field = '', $group = '', $order = '', $page = 0, $row = 0, $join = false) + { + $query = SM('spend',"tab_")->field($field)->where($map)->group($group)->order($order); + if ($join) { + $query = $query->join($join); + } + if ($row == 0) { + $data = $query->select(); + } else { + $data = $query->page($page, $row)->select(); + } + return $data; + } public function sumSpend($map = [], $field = '') { @@ -850,6 +863,12 @@ class SpendModel extends Model return $sum; } + public function sumSubSpend($map = [], $field = '') + { + $sum = SM('spend',"tab_")->where($map)->sum($field); + + return $sum; + } private function getGameMapByGameStatMap($map) { diff --git a/Application/Admin/View/CompanyStatement/lists.html b/Application/Admin/View/CompanyStatement/lists.html index 0d913da05..483915996 100644 --- a/Application/Admin/View/CompanyStatement/lists.html +++ b/Application/Admin/View/CompanyStatement/lists.html @@ -289,6 +289,28 @@ + @@ -743,6 +765,74 @@ } }); }) + //子站新增结算单 + $("#subAddStatement").click(function(){ + var html = $("#addSubStatementTpl").html(); + layer.open({ + type: 1, + title: "新增结算单", + maxWidth:720, + closeBtn: 1, + shadeClose: false, + content: html, + success:function(){ + $("#addSubStatementSubmit").off("click"); + $("#addSubStatementTime").datetimepicker({ + format: 'yyyy-mm-dd', + language: "zh-CN", + showMeridian:true, + pickDate:true, + minView: 2, + autoclose: true, + pickTime:true, + todayBtn:true, + }); + $("#addSubStatementSubmit").on("click",function(){ + var subtime= $("#addSubStatementTime").val(); + + if(subtime == '') { + layer.msg('请先选择要结算的时间'); + return false; + } + + var lastSynTime = Date.parse($("#lastSynTime").val())+86400000; + var lastStatementTime = Date.parse($("#lastStatementTime").val()); + + var subtimenum = Date.parse(subtime); + + if(subtimenum > lastSynTime) { + layer.msg('新增结算时间必须小于固定订单时间'); + return false; + } + if(subtimenum <= lastStatementTime) { + layer.msg('所选时间已结算'); + return false; + } + + $.ajax({ + type: "POST", + url: "{:U('subAddStatement')}", + dataType: 'json', + async: true, + data: {statement_time:subtime}, + success:function(data){ + + if(data.status==1){ + layer.msg("" + data.info + ""); + setTimeout(function(){ + window.location.reload(); + },1500); + }else{ + layer.alert(data.info) + } + } + }); + + }) + } + }); + }) + //查看批注 $(".viewRemark").click(function () { var remark = $(this).data("remark"); diff --git a/Application/Admin/View/FinancePromote/index.html b/Application/Admin/View/FinancePromote/index.html index 4094d65e6..c6605e1b5 100644 --- a/Application/Admin/View/FinancePromote/index.html +++ b/Application/Admin/View/FinancePromote/index.html @@ -85,7 +85,7 @@

推广员汇总

-

说明:统计各工会每月注册及充值总额(注册数:以玩家最后归属的公会为准,非去重)

+

说明:统计各工会每月注册及充值总额(注册数:以玩家最后归属的公会为准,非去重)/ 支付信息仅统计已固定的订单数据

diff --git a/Application/Admin/View/Platform/promotepay_statistics.html b/Application/Admin/View/Platform/promotepay_statistics.html index 397b1b053..3dd22b267 100644 --- a/Application/Admin/View/Platform/promotepay_statistics.html +++ b/Application/Admin/View/Platform/promotepay_statistics.html @@ -36,7 +36,7 @@

推广员充值统计

-

说明:针对所有推广员下的充值金额,进行充值排行统计:游戏、平台币、绑币的现金充值总额

+

说明:针对所有推广员下的充值金额,进行充值排行统计:游戏、平台币、绑币的现金充值总额/ 支付信息仅统计已固定的订单数据

diff --git a/Application/Admin/View/SubSpend/lists.html b/Application/Admin/View/SubSpend/lists.html new file mode 100644 index 000000000..f1ab220f9 --- /dev/null +++ b/Application/Admin/View/SubSpend/lists.html @@ -0,0 +1,982 @@ + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+ + - +
+ + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+ +
+ +
+ + - +
+
+ +
+ +
+ +
+ +
+ +
+
+ + +
+ +
+ + + +
+ 搜索 +
+
+ +
+
+
+ + {$vo} + +
+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
支付订单号CP订单号 + + 充值时间 + 支付时间玩家账号游戏名称设备类型所属推广员所属市场专员所属商户充值ip区服ID游戏区服角色ID角色名称订单金额 + + 实付金额 + 充值方式订单状态游戏通知状态是否参与结算操作
aOh! 暂时还没有内容!
+ {$data.pay_order_number} + + + {$data.extend} + {:set_show_time($data['pay_time'])} + + {:set_show_time($data['payed_time'])} + + ------ + + + {$data.user_account} + ({$data.small_account}){$data.game_name}{$data.sdk_version_name} + C('OFFICIEL_CHANNEL') + + {$data['promote_account']} + + + {$data.market_admin_username}{:getMerchantName($data['merchant_id'])}{$data.spend_ip}— —— —{$data.server_id}{$data.server_name}— —— —{$data.game_player_id}{$data.game_player_name}{$data.cost|default=0.00}{$data.pay_amount}{:get_pay_way($data['pay_way'])} + {:get_info_status($data['pay_status'],9)} + + {:get_info_status($data['pay_status'],9)} + + + {:get_info_status($data['pay_game_status'],14)} + + — — + + {:get_info_status($data['pay_game_status'],14)} + + {$data.is_check_str} + + + + 补单 + + + 补单 + + + + +
+ + + 通知到账 + + +
汇总 + 当页充值:{:null_to_0(array_sum(array_column(array_status2value('pay_status','',$list_data),'pay_amount')))} + + 累计充值:{$total}(此处只汇总充值成功的订单) +
+
+
+
+ 导出 + {$_page|default=''} +
+ + + + + + +
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ' + + '; + + + + + + + + + diff --git a/Application/Admin/View/SubSpend/showChooseSubSpendCount.html b/Application/Admin/View/SubSpend/showChooseSubSpendCount.html new file mode 100644 index 000000000..2397374c6 --- /dev/null +++ b/Application/Admin/View/SubSpend/showChooseSubSpendCount.html @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 说明:换绑后的数据将归属到选择的公司 +
+
+ + +
+
+ +
+
+ +
+ + + + +
+ +
+ + +
+
所选订单统计:
+
+ + + + + + + + + + + + + + + + + + + + + +
公司金额
{$vo.company_name}{$vo.pay_amount}
合计:{$data['count']}
+
+
+ + +
+ diff --git a/Application/Admin/View/TestingResource/apply.html b/Application/Admin/View/TestingResource/apply.html index 153a22811..557f12371 100644 --- a/Application/Admin/View/TestingResource/apply.html +++ b/Application/Admin/View/TestingResource/apply.html @@ -264,9 +264,9 @@ body { @@ -273,7 +273,7 @@