|
|
|
@ -0,0 +1,316 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Admin\Controller;
|
|
|
|
|
use Think\Controller;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 游戏月毛利统计
|
|
|
|
|
* @author cz
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class GameMarginSetController extends Controller {
|
|
|
|
|
private $beginThismonth;
|
|
|
|
|
private $endThismonth;
|
|
|
|
|
private $date;
|
|
|
|
|
private $nowdata;
|
|
|
|
|
private $month;//月份
|
|
|
|
|
private $year;//年份
|
|
|
|
|
private $adddata;//要添加的数据
|
|
|
|
|
// public $taskid=false;
|
|
|
|
|
// public $result='';
|
|
|
|
|
/**
|
|
|
|
|
* 更新某月数据
|
|
|
|
|
*/
|
|
|
|
|
public function setFreeMonth($count_date)
|
|
|
|
|
{
|
|
|
|
|
$month = $count_date;
|
|
|
|
|
if(empty($month)) die("参数错误");
|
|
|
|
|
|
|
|
|
|
$this->adddata = [];//置空否者会脚本进来会重复计算
|
|
|
|
|
$this->date = $month;
|
|
|
|
|
$tarry = explode('-',$month);
|
|
|
|
|
$this->year= $tarry[0];
|
|
|
|
|
if(strlen($tarry[1]) < 2) $tarry[1]="0".$tarry[1];
|
|
|
|
|
|
|
|
|
|
$this->month= $tarry[1];
|
|
|
|
|
$this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]);
|
|
|
|
|
$this->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1;
|
|
|
|
|
|
|
|
|
|
$this->reCount();
|
|
|
|
|
$this->setGameMargin();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 强制重新聚合
|
|
|
|
|
*/
|
|
|
|
|
private function reCount()
|
|
|
|
|
{
|
|
|
|
|
// $recount = I("recount");
|
|
|
|
|
// if(empty($recount) || $recount != 1){return ;}
|
|
|
|
|
// # code...
|
|
|
|
|
// //清理之前的聚合
|
|
|
|
|
// $temp =array(
|
|
|
|
|
// "count_year"=>$this->year,
|
|
|
|
|
// "count_month"=>$this->month
|
|
|
|
|
// );
|
|
|
|
|
// $this->FinancialSummaryModel->where($temp)->delete();
|
|
|
|
|
// echo "重置成功执行重新生成:";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function setGameMargin()
|
|
|
|
|
{
|
|
|
|
|
$this->getAllGameSpend();
|
|
|
|
|
$this->getJuheStatement();
|
|
|
|
|
$this->getPuStatement();
|
|
|
|
|
|
|
|
|
|
//上游
|
|
|
|
|
dd($this->adddata);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//获取期间所有有流水的游戏
|
|
|
|
|
private function getAllGameSpend()
|
|
|
|
|
{
|
|
|
|
|
$where = [
|
|
|
|
|
"pay_status"=>1,
|
|
|
|
|
"pay_game_status"=>1,
|
|
|
|
|
"is_refund"=>0,
|
|
|
|
|
"payed_time"=>["between",[$this->beginThismonth,$this->endThismonth]]
|
|
|
|
|
];
|
|
|
|
|
$this->adddata = M("Spend","tab_")->where($where)->group("relation_game_name")->getField("substring_index(game_name, '(', 1) relation_game_name,SUM(pay_amount) pay_amount",true);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取聚合数据
|
|
|
|
|
* 688是官方渠道,需要剔除
|
|
|
|
|
*/
|
|
|
|
|
private function getJuheStatement()
|
|
|
|
|
{
|
|
|
|
|
$where = [
|
|
|
|
|
"begintime"=>["between",[$this->beginThismonth,$this->endThismonth]],
|
|
|
|
|
"channel_id"=>["NOT IN",[688]],
|
|
|
|
|
"pay_money"=>['GT',0]
|
|
|
|
|
];
|
|
|
|
|
$dbres = M("aggregate_statement","tab_")->field('statement_info')->where($where)->select();
|
|
|
|
|
if(!empty($dbres)){
|
|
|
|
|
foreach ($dbres as $k => $v) {
|
|
|
|
|
$statement_info = json_decode($v['statement_info'],true);
|
|
|
|
|
foreach ($statement_info as $key => $val) {
|
|
|
|
|
if(array_key_exists($val['game_name'],$this->adddata)){
|
|
|
|
|
$this->adddata[$val['game_name']]['pay_amount'] += $val['money'];
|
|
|
|
|
if( array_key_exists("jh_pay_amount",$this->adddata[$val['game_name']]) ){
|
|
|
|
|
$this->adddata[$val['game_name']]['jh_pay_amount'] += $val['money'];
|
|
|
|
|
$this->adddata[$val['game_name']]['jh_statement_amount'] += $val['ratio_money'];
|
|
|
|
|
}else{
|
|
|
|
|
$this->adddata[$val['game_name']]['jh_pay_amount'] = $val['money'];
|
|
|
|
|
$this->adddata[$val['game_name']]['jh_statement_amount'] = $val['ratio_money'];
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$this->adddata[$val['game_name']] = [
|
|
|
|
|
"relation_game_name"=>$val['game_name'],
|
|
|
|
|
"pay_amount"=>$val['money'],
|
|
|
|
|
"jh_pay_amount"=>$val['money'],
|
|
|
|
|
"jh_statement_amount"=>$val['ratio_money']
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取下游外团结算数据
|
|
|
|
|
* 当前外团:个人周结结算与少部分对月结算
|
|
|
|
|
* @TODO: 万一内团也周结,这里的逻辑需要更改,目前所有的周结都算外团
|
|
|
|
|
*/
|
|
|
|
|
private function getPuStatement()
|
|
|
|
|
{
|
|
|
|
|
//1.获取下游周结结算单
|
|
|
|
|
$where = [
|
|
|
|
|
"_string"=>"statement_begin_time between {$this->beginThismonth} and {$this->endThismonth} OR statement_end_time between {$this->beginThismonth} and {$this->endThismonth}",
|
|
|
|
|
"company_type"=>2,
|
|
|
|
|
"withdraw_type"=>0
|
|
|
|
|
];
|
|
|
|
|
$statement_pool = M("company_statement_pool","tab_")->where($where)->order("statement_begin_time asc")->select();
|
|
|
|
|
//获取结算分段
|
|
|
|
|
$date_arr = [];
|
|
|
|
|
foreach ($statement_pool as $k => $v) {
|
|
|
|
|
$tem = [
|
|
|
|
|
"statement_begin_time"=>$v['statement_begin_time'],
|
|
|
|
|
"statement_end_time"=>$v['statement_end_time'],
|
|
|
|
|
"begin_time"=>date("Y.m.d",$v['statement_begin_time']),
|
|
|
|
|
"end_time"=>date("Y.m.d",$v['statement_end_time']),
|
|
|
|
|
"recount"=>false,
|
|
|
|
|
"withdraw_type"=>0
|
|
|
|
|
];
|
|
|
|
|
if($v['statement_begin_time'] < $this->beginThismonth){
|
|
|
|
|
$tem['statement_begin_time'] = $this->beginThismonth;
|
|
|
|
|
$tem['begin_time'] = date("Y.m.d",$this->beginThismonth);
|
|
|
|
|
$tem['recount'] = true;
|
|
|
|
|
}
|
|
|
|
|
if($v['statement_end_time'] > $this->endThismonth){
|
|
|
|
|
$tem['statement_end_time'] = $this->endThismonth;
|
|
|
|
|
$tem['end_time'] = date("Y.m.d",$this->endThismonth);
|
|
|
|
|
$tem['recount'] = true;
|
|
|
|
|
}
|
|
|
|
|
$this->getPuAllStatement($tem,$v);
|
|
|
|
|
$this->getPuCompanyStatement($tem);//对公周结
|
|
|
|
|
$date_arr[] = $tem;
|
|
|
|
|
}
|
|
|
|
|
//2.获取对公的下游
|
|
|
|
|
$tem = [
|
|
|
|
|
"statement_begin_time"=>$this->beginThismonth,
|
|
|
|
|
"statement_end_time"=>$this->endThismonth,
|
|
|
|
|
"begin_time"=>date("Y.m.d",$this->beginThismonth),
|
|
|
|
|
"end_time"=>date("Y.m.d",$this->endThismonth),
|
|
|
|
|
"recount"=>false,
|
|
|
|
|
"withdraw_type"=>1
|
|
|
|
|
];
|
|
|
|
|
$this->getPuCompanyStatement($tem);
|
|
|
|
|
//3.特殊补点
|
|
|
|
|
$this->getPuSpecialStatement();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取所有个人周结
|
|
|
|
|
*/
|
|
|
|
|
private function getPuAllStatement($time,$pool){
|
|
|
|
|
$id = $pool['id'];
|
|
|
|
|
//获取基本信息
|
|
|
|
|
$infolist = M("company_statement_info","tab_")->where("pool_id = '{$id}'")->select();
|
|
|
|
|
//获取母单
|
|
|
|
|
if(!empty($pool['create_lack_ids'])){
|
|
|
|
|
$l_ids = $pool['create_lack_ids'];
|
|
|
|
|
$lack_info = M("company_lack_statement_info","tab_")->where("id in ({$l_ids})")->select();
|
|
|
|
|
$infolist =array_merge($infolist,$lack_info);
|
|
|
|
|
}
|
|
|
|
|
foreach ($infolist as $v) {
|
|
|
|
|
$sinfo = json_decode($v['statement_info'],true);
|
|
|
|
|
foreach ($sinfo as $va) {
|
|
|
|
|
foreach ($va["game_list"] as $val) {
|
|
|
|
|
|
|
|
|
|
//奖罚不算
|
|
|
|
|
if( !array_key_exists($val['game_name'],$this->adddata) ){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//其他计算日期不算
|
|
|
|
|
if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if($time['recount']){
|
|
|
|
|
$pay_amount = $this->getPuGameSpend($va['account'],$val['game_name']."(",$time['statement_begin_time'],$time['statement_end_time']);
|
|
|
|
|
$val['sum_money'] = round($pay_amount/$val['pay_amount']*$val['sum_money'],2);
|
|
|
|
|
$val['pay_amount'] = $pay_amount;
|
|
|
|
|
}
|
|
|
|
|
if( array_key_exists("pu_pay_amount",$this->adddata[$val['game_name']]) ){
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_pay_amount'] += $val['pay_amount'];
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_statement_amount'] += $val['sum_money'];
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_pay_amount'] = $val['pay_amount'];
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_statement_amount'] = $val['sum_money'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//按推广员及游戏名称获取支付合计
|
|
|
|
|
private function getPuGameSpend($account,$game_name,$begin,$end){
|
|
|
|
|
//获取全部推广员
|
|
|
|
|
$id = M("promote","tab_")->field("id")->where("account = '{$account}'")->find()['id'];
|
|
|
|
|
//获取全部推广员
|
|
|
|
|
$ids = M("promote","tab_")->field("group_concat(id) ids")->where("level1_id = '{$id}'")->group("level1_id")->find()['ids'];
|
|
|
|
|
$where = [
|
|
|
|
|
"pay_status"=>1,
|
|
|
|
|
"payed_time"=>["between",[$begin,$end]],
|
|
|
|
|
"promote_id"=>["in",$ids],
|
|
|
|
|
"game_name"=>["like",$game_name."%"]
|
|
|
|
|
];
|
|
|
|
|
return M("Spend","tab_")->where($where)->field("SUM(pay_amount) pay_amount")->find()['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
//按公司及游戏名称获取支付合计
|
|
|
|
|
private function getPuCompanyGameSpend($company_id,$game_name,$begin,$end){
|
|
|
|
|
//获取全部推广员
|
|
|
|
|
$ids = M("promote","tab_")->field("group_concat(id) ids")->where("company_id = '{$company_id}'")->group("company_id")->find()['ids'];
|
|
|
|
|
$where = [
|
|
|
|
|
"pay_status"=>1,
|
|
|
|
|
"payed_time"=>["between",[$begin,$end]],
|
|
|
|
|
"promote_id"=>["in",$ids],
|
|
|
|
|
"game_name"=>["like",$game_name."%"]
|
|
|
|
|
];
|
|
|
|
|
return M("Spend","tab_")->where($where)->field("SUM(pay_amount) pay_amount")->find()['pay_amount'];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 对公的下游结算
|
|
|
|
|
*/
|
|
|
|
|
private function getPuCompanyStatement($time)
|
|
|
|
|
{
|
|
|
|
|
$where = [
|
|
|
|
|
"company_belong"=>["NOT IN",[0,9]],
|
|
|
|
|
"withdraw_type"=>$time['withdraw_type']
|
|
|
|
|
];
|
|
|
|
|
if($time['recount']){
|
|
|
|
|
$where['_string'] = "statement_begin_time = {$time['statement_begin_time']} OR statement_end_time = {$time['statement_end_time']}";
|
|
|
|
|
}else{
|
|
|
|
|
$where['statement_begin_time'] = $time['statement_begin_time'];
|
|
|
|
|
$where['statement_end_time'] = $time['statement_end_time'];
|
|
|
|
|
}
|
|
|
|
|
$res = M("company_statement","tab_")->where($where)->select();
|
|
|
|
|
if($res){
|
|
|
|
|
foreach ($res as $v) {
|
|
|
|
|
$sinfo = json_decode($v['statement_info'],true);
|
|
|
|
|
foreach ($sinfo as $val) {
|
|
|
|
|
//奖罚不算
|
|
|
|
|
if( !array_key_exists($val['game_name'],$this->adddata) ){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//其他计算日期不算
|
|
|
|
|
if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if($time['recount']){
|
|
|
|
|
$pay_amount = $this->getPuCompanyGameSpend($v['company_id'],$val['game_name']."(",$time['statement_begin_time'],$time['statement_end_time']);
|
|
|
|
|
$val['sum_money'] = round($pay_amount/$val['pay_amount']*$val['sum_money'],2);
|
|
|
|
|
$val['pay_amount'] = $pay_amount;
|
|
|
|
|
}
|
|
|
|
|
if( array_key_exists("pu_pay_amount",$this->adddata[$val['game_name']]) ){
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_pay_amount'] += $val['pay_amount'];
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_statement_amount'] += $val['sum_money'];
|
|
|
|
|
}else{
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_pay_amount'] = $val['pay_amount'];
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_statement_amount'] = $val['sum_money'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 特殊补点
|
|
|
|
|
*/
|
|
|
|
|
private function getPuSpecialStatement()
|
|
|
|
|
{
|
|
|
|
|
$where = [
|
|
|
|
|
"company_belong"=>["NOT IN",[0,9]],
|
|
|
|
|
"withdraw_type"=>3,
|
|
|
|
|
"_string"=>"statement_begin_time >= {$this->beginThismonth} and statement_end_time <= {$this->endThismonth}"
|
|
|
|
|
];
|
|
|
|
|
$res = M("company_statement","tab_")->where($where)->select();
|
|
|
|
|
if($res){
|
|
|
|
|
foreach ($res as $v) {
|
|
|
|
|
$sinfo = json_decode($v['statement_info'],true);
|
|
|
|
|
foreach ($sinfo as $va) {
|
|
|
|
|
foreach ($va["game_list"] as $val) {
|
|
|
|
|
//奖罚不算
|
|
|
|
|
if( !array_key_exists($val['game_name'],$this->adddata) ){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if( array_key_exists("pu_statement_amount",$this->adddata[$val['game_name']]) ){
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_statement_amount'] += $val['sum_money'];
|
|
|
|
|
}else{
|
|
|
|
|
$this->adddata[$val['game_name']]['pu_statement_amount'] = $val['sum_money'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|