|
|
|
@ -22,6 +22,8 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
private $gameInfo;
|
|
|
|
|
private $companyInfo;
|
|
|
|
|
private $settleupMarketorderModel;
|
|
|
|
|
private $taxRatio;
|
|
|
|
|
private $oldMarketPerformance;
|
|
|
|
|
/**
|
|
|
|
|
* 更新某月数据
|
|
|
|
|
*/
|
|
|
|
@ -58,18 +60,40 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
*/
|
|
|
|
|
private function setSettleupMarketorder()
|
|
|
|
|
{
|
|
|
|
|
$this->setIsTipData();
|
|
|
|
|
$this->getInsideCompanyid();
|
|
|
|
|
$this->getChannelRatio();
|
|
|
|
|
$this->getTaxRatio();
|
|
|
|
|
$this->getAllDownFlowSpend();
|
|
|
|
|
$this->getAllGameInfo();
|
|
|
|
|
$this->getCompanyOtherInfo();
|
|
|
|
|
$this->getPuStatement();
|
|
|
|
|
$this->getPuSpecialStatement();
|
|
|
|
|
$this->performanceSet();
|
|
|
|
|
dd($this->downFlowData);
|
|
|
|
|
|
|
|
|
|
$this->settleupMarketorderDbSave();
|
|
|
|
|
$this->clearConfigData();
|
|
|
|
|
echo "{$this->year}-{$this->month}生成成功".PHP_EOL;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取是否标红提示数据
|
|
|
|
|
*/
|
|
|
|
|
private function setIsTipData()
|
|
|
|
|
{
|
|
|
|
|
$dbres = $this->settleupMarketorderModel->where(['pay_time'=>$this->date])->select();
|
|
|
|
|
|
|
|
|
|
if($dbres){
|
|
|
|
|
foreach ($dbres as $key => $v) {
|
|
|
|
|
$this->oldMarketPerformance[$v['company_id']][$v['game_name']]['company_profit'] = $v['company_profit'];
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$this->oldMarketPerformance = false;
|
|
|
|
|
}
|
|
|
|
|
//取消所有提示
|
|
|
|
|
$this->settleupMarketorderModel->where("1=1")->save(["is_tip"=>0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取公司内部公司id
|
|
|
|
|
*/
|
|
|
|
@ -86,22 +110,46 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 支付服务商渠道费
|
|
|
|
|
* TODO:当前默认除了绑定币其他渠道都1%
|
|
|
|
|
*/
|
|
|
|
|
private function getChannelRatio()
|
|
|
|
|
{
|
|
|
|
|
$res = M("payment_merchant","tab_")->getField("id,config",true);
|
|
|
|
|
foreach ($res as $k => $v) {
|
|
|
|
|
$config = json_decode($v,true);
|
|
|
|
|
if(array_key_exists("channel_rate",$config) && $config['channel_rate'] > 0){
|
|
|
|
|
$res[$k] = $config['channel_rate'];
|
|
|
|
|
}else{
|
|
|
|
|
$res[$k] = 0;
|
|
|
|
|
}
|
|
|
|
|
$res[$k] = 1;
|
|
|
|
|
//------begin------注释的部分表示按实际配置收取
|
|
|
|
|
// $config = json_decode($v,true);
|
|
|
|
|
// if(array_key_exists("channel_rate",$config) && $config['channel_rate'] > 0){
|
|
|
|
|
// $res[$k] = $config['channel_rate'];
|
|
|
|
|
// }else{
|
|
|
|
|
// $res[$k] = 0;
|
|
|
|
|
// }
|
|
|
|
|
//----------end------
|
|
|
|
|
}
|
|
|
|
|
$res[0] = 0;
|
|
|
|
|
$res[0] = 1;//平台币
|
|
|
|
|
$res[-1] = 0;//绑定币
|
|
|
|
|
$this->channelRatio = $res;
|
|
|
|
|
unset($res);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取公司税率
|
|
|
|
|
*/
|
|
|
|
|
private function getTaxRatio()
|
|
|
|
|
{
|
|
|
|
|
$where = [
|
|
|
|
|
"time"=>['ELT',$this->beginThismonth]
|
|
|
|
|
];
|
|
|
|
|
$tax_data = M("tax_radio","tab_")
|
|
|
|
|
->field("tax_radio")
|
|
|
|
|
->order("time desc")
|
|
|
|
|
->where($where)
|
|
|
|
|
->find();
|
|
|
|
|
if($tax_data){
|
|
|
|
|
$this->taxRatio = $tax_data['tax_radio'];
|
|
|
|
|
}else{
|
|
|
|
|
$this->taxRatio = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取所有下游公司支付信息
|
|
|
|
@ -110,6 +158,7 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
{
|
|
|
|
|
$where = [
|
|
|
|
|
"pay_status"=>1,
|
|
|
|
|
"s.is_check"=>1,
|
|
|
|
|
"payed_time"=>["between",[$this->beginThismonth,$this->endThismonth]],
|
|
|
|
|
"p.company_id"=>["NOT IN",$this->inSideCompanyIds],
|
|
|
|
|
"p.company_belong"=>['GT',0]
|
|
|
|
@ -119,33 +168,31 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
->field("substring_index(game_name, '(', 1) relation_game_name,
|
|
|
|
|
SUM(pay_amount) pay_amount,
|
|
|
|
|
IFNULL(SUM(CASE WHEN is_refund = 1 THEN pay_amount ELSE 0 END),0) as refund_amount,
|
|
|
|
|
IFNULL(SUM(CASE WHEN is_check = 2 THEN pay_amount ELSE 0 END),0) as no_statement_amount,
|
|
|
|
|
p.company_id,p.company_belong,merchant_id")
|
|
|
|
|
->join("tab_promote as p on s.promote_id = p.id")
|
|
|
|
|
->where($where)
|
|
|
|
|
->group("relation_game_name,company_id,merchant_id")
|
|
|
|
|
->order("pay_amount desc")->select();
|
|
|
|
|
foreach ($dbres as $v) {
|
|
|
|
|
if(array_key_exists('cp_pay_amount',$this->downFlowData[$v['company_id']][$v['relation_game_name']])){
|
|
|
|
|
if(!array_key_exists($v['relation_game_name'],$this->downFlowData[$v['company_id']])){
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']] = [
|
|
|
|
|
"cp_pay_amount"=>0,
|
|
|
|
|
"promote_pay_amount"=>0,
|
|
|
|
|
"pay_amount"=>0,
|
|
|
|
|
"channel_amount"=>0,
|
|
|
|
|
"refund_amount"=>0,
|
|
|
|
|
"no_statement_amount"=>0,
|
|
|
|
|
"special_amount"=>0,
|
|
|
|
|
"ratio"=>0
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$channel_amount = round($v['pay_amount']*$this->channelRatio[$v['merchant_id']]/100,2);
|
|
|
|
|
$cp_amount = $v['pay_amount']-$v['refund_amount'];
|
|
|
|
|
$promote_amount = $v['pay_amount']-$v['refund_amount']-$v['no_statement_amount'];
|
|
|
|
|
|
|
|
|
|
$promote_amount = $v['pay_amount']-$v['refund_amount'];
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['channel_amount'] += $channel_amount;
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['cp_pay_amount'] += $cp_amount;
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['promote_pay_amount'] += $promote_amount;
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['refund_amount'] += $refund_amount;
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['no_statement_amount'] += $v['no_statement_amount'];
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['pay_amount'] += $v['pay_amount'];
|
|
|
|
|
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['refund_amount'] += $v['refund_amount'];
|
|
|
|
|
}
|
|
|
|
|
unset($dbres);
|
|
|
|
|
}
|
|
|
|
@ -178,7 +225,7 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
->join("sys_member as m on p.admin_id = m.uid")
|
|
|
|
|
->where(['pc.id'=>['in',$companyIds],'p.level'=>1])
|
|
|
|
|
->group("pc.id")
|
|
|
|
|
->getField("pc.id,pc.company_name,pc.uid,pc.company_belong,pc.develop_type,p.id promote_id,p.account,p.admin_id,m.real_name",TRUE);
|
|
|
|
|
->getField("pc.id company_id,pc.company_name,pc.company_belong,pc.develop_type,p.id promote_id,p.account promote_account,p.admin_id,m.real_name",TRUE);
|
|
|
|
|
$this->companyInfo = $companyRes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -256,7 +303,7 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']])){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(!array_key_exists("ratio",$this->downFlowData[1][$v['company_id']][$val['game_name']])){
|
|
|
|
|
if($this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] == 0){
|
|
|
|
|
$this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] = $val['ratio'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -295,7 +342,7 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']])){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(!array_key_exists("ratio",$this->downFlowData[$v['company_id']][$val['game_name']])){
|
|
|
|
|
if($this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] == 0){
|
|
|
|
|
$this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] = $val['ratio'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -322,12 +369,7 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
if( !array_key_exists($val['game_name'],$this->gameInfo) ){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if( array_key_exists("special_amount",$this->downFlowData[$val['company_id']][$val['game_name']]) ){
|
|
|
|
|
$this->downFlowData[$v['company_id']][$val['game_name']]["special_amount"] += $val['sum_money'];
|
|
|
|
|
}else{
|
|
|
|
|
$this->downFlowData[$v['company_id']][$val['game_name']]["special_amount"] = $val['sum_money'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->downFlowData[$v['company_id']][$val['game_name']]["special_amount"] += $val['sum_money'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -383,8 +425,60 @@ class MarketPerformanceSetController extends Controller {
|
|
|
|
|
*/
|
|
|
|
|
private function performanceSet()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach ($this->downFlowData as $company_id => $games) {
|
|
|
|
|
$baseArr = $this->companyInfo[$company_id];
|
|
|
|
|
$baseArr['pay_time'] = $this->date;
|
|
|
|
|
$baseArr['is_settlement'] = 1;
|
|
|
|
|
foreach ($games as $k => $v) {
|
|
|
|
|
// if($company_id == 452){
|
|
|
|
|
// dd($v);
|
|
|
|
|
// }
|
|
|
|
|
$game = $this->gameInfo[$k];
|
|
|
|
|
$cp_ratio = $game['cp_ratio'];
|
|
|
|
|
$tempArr = $baseArr;
|
|
|
|
|
$tempArr['game_id'] = $game['relation_game_id'];
|
|
|
|
|
$tempArr['relation_game_id'] = $game['relation_game_id'];
|
|
|
|
|
$tempArr['game_name'] = $k;
|
|
|
|
|
$tempArr['pay_amount'] = $v['pay_amount'];
|
|
|
|
|
$tempArr['cp_amount'] = round($v['cp_pay_amount']*$cp_ratio/100,2);
|
|
|
|
|
$tempArr['promote_amount'] = round($v['promote_pay_amount']*$v['ratio']/100+$v['special_amount'],2);
|
|
|
|
|
$tempArr['channel_amount'] = $v['channel_amount'];
|
|
|
|
|
$tempArr['refund_amount'] = $v['refund_amount'];
|
|
|
|
|
$tempArr['company_tax'] = round( ($v['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']) * ($this->taxRatio / 100),2 );
|
|
|
|
|
$tempArr['company_profit'] = $tempArr['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']-$tempArr['channel_amount']-$tempArr['company_tax'];
|
|
|
|
|
$tempArr['is_tip'] = 0;
|
|
|
|
|
if($this->oldMarketPerformance){
|
|
|
|
|
if(!array_key_exists($company_id,$this->oldMarketPerformance) || !array_key_exists($k,$this->oldMarketPerformance[$company_id])){
|
|
|
|
|
$tempArr['is_tip'] = 1;
|
|
|
|
|
}else{
|
|
|
|
|
if($this->oldMarketPerformance[$company_id][$k]['company_profit'] != $tempArr['company_profit'].''){
|
|
|
|
|
$tempArr['is_tip'] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if($tempArr['promote_amount'] != 0){
|
|
|
|
|
$this->adddata[]= $tempArr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 毛利数据库操作
|
|
|
|
|
*/
|
|
|
|
|
private function settleupMarketorderDbSave()
|
|
|
|
|
{
|
|
|
|
|
//删除旧数据
|
|
|
|
|
$this->settleupMarketorderModel->where(['pay_time'=>$this->date])->delete();
|
|
|
|
|
$this->settleupMarketorderModel->addAll($this->adddata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清场退出
|
|
|
|
|
*/
|
|
|
|
|
private function clearConfigData()
|
|
|
|
|
{
|
|
|
|
|
unset($this->beginThismonth,$this->endThismonth,$this->date,$this->nowdata,$this->month,$this->year,$this->adddata,$this->downFlowData,$this->gameInfo,$this->companyInfo,$this->taxRatio,$this->oldMarketPerformance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|