diff --git a/Application/Admin/Controller/GameMarginController.class.php b/Application/Admin/Controller/GameMarginController.class.php
index 0fb582a6a..9670fa32c 100644
--- a/Application/Admin/Controller/GameMarginController.class.php
+++ b/Application/Admin/Controller/GameMarginController.class.php
@@ -45,17 +45,12 @@ class GameMarginController extends AdminController
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
- $this->export($info);
- $this->assign("percent",'');
+ $this->marginExport($info);
}else{
$is_export= false;
$this->marginCount($info);
- $this->assign("percent",'%');
}
-
- $this->assign("year", $info['count_year']);
- $this->assign("month", $info['count_month']);
$this->assign("id", $id);
$this->assign("is_export",$is_export);
$this->display();
@@ -89,7 +84,7 @@ class GameMarginController extends AdminController
"jh_margin_ratio"=>0,
];
- foreach ($marginInfo as $v) {
+ foreach ($marginInfo as &$v) {
$count['cp_statement_amount'] += $v['cp_statement_amount'];
$count['cp_rebate_amount'] += $v['cp_rebate_amount'];
$count['cp_other_amount'] += $v['cp_other_amount'];
@@ -105,9 +100,13 @@ class GameMarginController extends AdminController
$count['jh_pay_amount'] += $v['jh_pay_amount'];
$count['jh_statement_amount'] += $v['jh_statement_amount'];
$count['jh_margin_amount'] += $v['jh_margin_amount'];
-
+ $v['year'] = $info['count_year'];
+ $v['month'] = $info['count_month'];
+ $this->sprintfCell($v);
}
- $count['cp_ratio'] = round( $count['cp_statement_amount']/$count['pay_amount'] ,4)*100;
+ // $count['cp_ratio'] = round( $count['cp_statement_amount']/$count['pay_amount'] ,4)*100;
+ $count['year'] = $info['count_year'];
+ $count['month'] = $info['count_month'];
$count['pu_ratio'] = round( $count['pu_statement_amount']/$count['pu_pay_amount'] ,4)*100;
$count['pu_margin_ratio'] = round( $count['pu_margin_amount']/$count['pu_pay_amount'] ,4)*100;
@@ -120,16 +119,165 @@ class GameMarginController extends AdminController
$count['jh_ratio'] = round( $count['jh_statement_amount']/$count['jh_pay_amount'] ,4)*100;
$count['jh_margin_ratio'] = round( $count['jh_margin_amount']/$count['jh_pay_amount'] ,4)*100;
// dd($count);
+ $this->sprintfCell($count);
$this->assign("data",$marginInfo);
$this->assign("count",$count);
}
+ private function marginExport($info)
+ {
+ header("Content-type: text/html; charset=utf-8");
+ error_reporting(E_ALL);
+ ini_set('display_errors', TRUE);
+ ini_set('display_startup_errors', TRUE);
+
+ define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
');
+
+ Vendor("PHPExcel.PHPExcel");
+ $objReader = \PHPExcel_IOFactory::createReader('excel2007');
+ //设置模板文件
+ $objPHPExcel = $objReader->load("Public/Admin/excel/gamemargin.xlsx");
+ $marginInfo = json_decode($info['margin_info'],true);
+ $line = 3;
+ $objPHPExcel->getActiveSheet()->insertNewRowBefore($line+1,count($marginInfo)-1);
+
+ foreach ($marginInfo as &$v) {
+ // $v["cp_ratio"] = "=ROUND(G{$line}/D{$line},4)";
+
+ if($v["pc_pay_amount"] > 0){
+ $v["pc_ratio"] ="=ROUND(M{$line}/K{$line},2)";
+ $v["pc_margin_amount"] = "=ROUND((K{$line}*(1-E{$line})*(1-F{$line}-H{$line}-L{$line})),2)";
+ $v["pc_margin_ratio"] ="=ROUND(N{$line}/K{$line},3)";
+ }
+ if ($v["pu_pay_amount"] > 0) {
+ $v["pu_ratio"] ="=ROUND(R{$line}/P{$line},2)";
+ $v["pu_margin_amount"] = "=ROUND((P{$line}-P{$line}*(1-E{$line})*(F{$line}+H{$line})-R{$line}),2)";
+ $v["pu_margin_ratio"] = "=ROUND(S{$line}/P{$line},3)";
+ }
+ $v['platform_margin_ratio'] = "=ROUND((D{$line}-V{$line}-G{$line}-I{$line}-J{$line}-M{$line}-R{$line})/(D{$line}-V{$line}),3)";
+
+ if($v['jh_pay_amount'] > 0){
+ $v["jh_ratio"] ="=ROUND(X{$line}/V{$line},2)";
+ $v["jh_margin_amount"] = "=ROUND((X{$line}-V{$line}*(1-E{$line})*(F{$line}+H{$line})),2)";
+ $v["jh_margin_ratio"] = "=ROUND(Y{$line}/V{$line},3)";
+ }
+
+ $v['margin_amount'] = "=ROUND((D{$line}-G{$line}-I{$line}-J{$line}-M{$line}-R{$line}+X{$line}),2)";
+ $v['margin_ratio'] = "=ROUND(AB{$line}/D{$line},3)";
+
+
+ $objPHPExcel->getActiveSheet()
+ ->setCellValue('A'.$line, $info['count_year'])
+ ->setCellValue('B'.$line, $info['count_month'])
+ ->setCellValue('C'.$line, $v['relation_game_name'])
+ ->setCellValue('D'.$line, $v['pay_amount'])
+ ->setCellValue('E'.$line, $v['cp_promote_ratio']/100)
+ ->setCellValue('F'.$line, $v['cp_ratio']/100)
+ ->setCellValue('G'.$line, $v['cp_statement_amount'])
+ ->setCellValue('H'.$line, $v['cp_rebate_ratio'])
+ ->setCellValue('I'.$line, $v['cp_rebate_amount'])
+ ->setCellValue('J'.$line, $v['cp_other_amount'])
+ ->setCellValue('K'.$line, $v['pc_pay_amount'])
+ ->setCellValue('L'.$line, $v['pc_ratio'])
+ ->setCellValue('M'.$line, $v['pc_statement_amount'])
+ ->setCellValue('N'.$line, $v['pc_margin_amount'])
+ ->setCellValue('O'.$line, $v['pc_margin_ratio'])
+ ->setCellValue('P'.$line, $v['pu_pay_amount'])
+ ->setCellValue('Q'.$line, $v['pu_ratio'])
+ ->setCellValue('R'.$line, $v['pu_statement_amount'])
+ ->setCellValue('S'.$line, $v['pu_margin_amount'])
+ ->setCellValue('T'.$line, $v['pu_margin_ratio'])
+ ->setCellValue('U'.$line, $v['platform_margin_ratio'])
+ ->setCellValue('V'.$line, $v['jh_pay_amount'])
+ ->setCellValue('W'.$line, $v['jh_ratio'])
+ ->setCellValue('X'.$line, $v['jh_statement_amount'])
+ ->setCellValue('Y'.$line, $v['jh_margin_amount'])
+ ->setCellValue('Z'.$line, $v['jh_margin_ratio'])
+ ->setCellValue('AA'.$line, $v['margin_ratio'])
+ ->setCellValue('AB'.$line, $v['margin_amount']);
+ $line ++;
+ }
+
+ $countLine = $line;
+ $line--;
+
+ $count = [
+ "pay_amount"=>"=SUM(D3:D{$line})",
+ // "cp_ratio"=>"=ROUND(G{$countLine}/D{$countLine},4)",
+ "cp_statement_amount"=>"=SUM(G3:G{$line})",
+ "cp_rebate_amount"=>"=SUM(I3:I{$line})",
+ "cp_other_amount"=>"=SUM(J3:J{$line})",
+
+ "pc_pay_amount"=>"=SUM(K3:K{$line})",
+ "pc_ratio"=>"=ROUND(M{$countLine}/K{$countLine},4)",
+ "pc_statement_amount"=>"=SUM(M3:M{$line})",
+ "pc_margin_amount"=>"=SUM(N3:N{$line})",
+ "pc_margin_ratio"=>"=ROUND(N{$countLine}/K{$countLine},4)",
+
+ "pu_pay_amount"=>"=SUM(P3:P{$line})",
+ "pu_statement_amount"=>"=SUM(R3:R{$line})",
+ "pu_ratio"=>"=ROUND(R{$countLine}/P{$countLine},4)",
+ "pu_margin_amount"=>"=SUM(S3:S{$line})",
+ "pu_margin_ratio"=>"=ROUND(S{$countLine}/P{$countLine},4)",
+
+ "platform_margin_ratio"=>"=ROUND((D{$countLine}-V{$countLine}-G{$countLine}-I{$countLine}-J{$countLine}-M{$countLine}-R{$countLine})/(D{$countLine}-V{$countLine}),4)",
+
+ "jh_pay_amount"=>"=SUM(V3:V{$line})",
+ "jh_statement_amount"=>"=SUM(X3:X{$line})",
+ "jh_ratio"=>"=ROUND(X{$countLine}/V{$countLine},4)",
+ "jh_margin_amount"=>"=SUM(Y3:Y{$line})",
+ "jh_margin_ratio"=>"=ROUND(Y{$countLine}/V{$countLine},4)",
+ "margin_ratio"=>"=ROUND(AB{$countLine}/D{$countLine},4)",
+ "margin_amount"=>"=SUM(AB3:AB{$line})",
+
+ ];
+
+ $line ++;
+ $objPHPExcel->getActiveSheet()
+ ->setCellValue('A'.$line, $info['count_year'])
+ ->setCellValue('B'.$line, $info['count_month'])
+ ->setCellValue('D'.$line, $count['pay_amount'])
+ ->setCellValue('G'.$line, $count['cp_statement_amount'])
+ ->setCellValue('I'.$line, $count['cp_rebate_amount'])
+ ->setCellValue('J'.$line, $count['cp_other_amount'])
+ ->setCellValue('K'.$line, $count['pc_pay_amount'])
+ ->setCellValue('L'.$line, $count['pc_ratio'])
+ ->setCellValue('M'.$line, $count['pc_statement_amount'])
+ ->setCellValue('N'.$line, $count['pc_margin_amount'])
+ ->setCellValue('O'.$line, $count['pc_margin_ratio'])
+ ->setCellValue('P'.$line, $count['pu_pay_amount'])
+ ->setCellValue('Q'.$line, $count['pu_ratio'])
+ ->setCellValue('R'.$line, $count['pu_statement_amount'])
+ ->setCellValue('S'.$line, $count['pu_margin_amount'])
+ ->setCellValue('T'.$line, $count['pu_margin_ratio'])
+ ->setCellValue('U'.$line, $count['platform_margin_ratio'])
+ ->setCellValue('V'.$line, $count['jh_pay_amount'])
+ ->setCellValue('W'.$line, $count['jh_ratio'])
+ ->setCellValue('X'.$line, $count['jh_statement_amount'])
+ ->setCellValue('Y'.$line, $count['jh_margin_amount'])
+ ->setCellValue('Z'.$line, $count['jh_margin_ratio'])
+ ->setCellValue('AA'.$line, $count['margin_ratio'])
+ ->setCellValue('AB'.$line, $count['margin_amount']);
+
+ $fileName = "{$info['count_year']}-{$info['count_month']}毛利分析表";
+ ob_end_clean();//清除缓冲区,避免乱码
+ header('pragma:public');
+ header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$fileName.'".xlsx');
+ header("Content-Disposition:attachment;filename={$fileName}.xlsx");//attachment新窗口打印inline本窗口打印
+ $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'excel2007');
+ $objWriter->save('php://output');
+ exit;
+
+
+ }
+
+
private function export($info)
{
$marginInfo = json_decode($info['margin_info'],true);
$line = 3;
foreach ($marginInfo as &$v) {
- $v["cp_ratio"] = "=ROUND(G{$line}/D{$line},4)";
+ // $v["cp_ratio"] = "=ROUND(G{$line}/D{$line},4)";
if($v["pc_pay_amount"] > 0){
$v["pc_ratio"] ="=ROUND(M{$line}/K{$line},4)";
@@ -159,7 +307,7 @@ class GameMarginController extends AdminController
$count = [
"pay_amount"=>"=SUM(D3:D{$line})",
- "cp_ratio"=>"=ROUND(G{$countLine}/D{$countLine},4)",
+ // "cp_ratio"=>"=ROUND(G{$countLine}/D{$countLine},4)",
"cp_statement_amount"=>"=SUM(G3:G{$line})",
"cp_rebate_amount"=>"=SUM(I3:I{$line})",
"cp_other_amount"=>"=SUM(J3:J{$line})",
@@ -274,6 +422,44 @@ class GameMarginController extends AdminController
$this->ajaxReturn(["status"=>"0","msg"=>'任务添加失败']);
}
}
+ /**
+ * 格式化数据
+ */
+ private function sprintfCell(&$item)
+ {
+ $item['pay_amount'] = sprintf("%.2f",$item['pay_amount']);
+ $item['pu_pay_amount'] = sprintf("%.2f",$item['pu_pay_amount']);
+ $item['pc_pay_amount'] = sprintf("%.2f",$item['pc_pay_amount']);
+ $item['jh_pay_amount'] = sprintf("%.2f",$item['jh_pay_amount']);
+
+ $item['cp_statement_amount'] = sprintf("%.2f",$item['cp_statement_amount']);
+ $item['pu_statement_amount'] = sprintf("%.2f",$item['pu_statement_amount']);
+ $item['pc_statement_amount'] = sprintf("%.2f",$item['pc_statement_amount']);
+ $item['jh_statement_amount'] = sprintf("%.2f",$item['jh_statement_amount']);
+
+ $item['margin_amount'] = sprintf("%.2f",$item['margin_amount']);
+ $item['pu_margin_amount'] = sprintf("%.2f",$item['pu_margin_amount']);
+ $item['pc_margin_amount'] = sprintf("%.2f",$item['pc_margin_amount']);
+ $item['jh_margin_amount'] = sprintf("%.2f",$item['jh_margin_amount']);
+
+ $item['cp_other_amount'] = sprintf("%.2f",$item['cp_other_amount']);
+ $item['cp_rebate_amount'] = sprintf("%.2f",$item['cp_rebate_amount']);
+
+ if(array_key_exists('cp_ratio',$item)){
+ $item['cp_ratio'] = sprintf("%.0f%%",$item['cp_ratio']);
+ $item['cp_rebate_ratio'] = sprintf("%.0f%%",$item['cp_rebate_ratio']);
+ }
+
+ $item['pc_ratio'] = sprintf("%.0f%%",$item['pc_ratio']);
+ $item['pu_ratio'] = sprintf("%.0f%%",$item['pu_ratio']);
+ $item['jh_ratio'] = sprintf("%.0f%%",$item['jh_ratio']);
+
+ $item['margin_ratio'] = sprintf("%.1f%%",$item['margin_ratio']);
+ $item['pu_margin_ratio'] = sprintf("%.1f%%",$item['pu_margin_ratio']);
+ $item['pc_margin_ratio'] = sprintf("%.1f%%",$item['pc_margin_ratio']);
+ $item['jh_margin_ratio'] = sprintf("%.1f%%",$item['jh_margin_ratio']);
+ $item['platform_margin_ratio'] = sprintf("%.1f%%",$item['platform_margin_ratio']);
+ }
}
\ No newline at end of file
diff --git a/Application/Admin/Controller/GameMarginSetController.class.php b/Application/Admin/Controller/GameMarginSetController.class.php
index 02729dfa4..4f2d2f8a9 100644
--- a/Application/Admin/Controller/GameMarginSetController.class.php
+++ b/Application/Admin/Controller/GameMarginSetController.class.php
@@ -61,8 +61,8 @@ class GameMarginSetController extends Controller {
{
$this->getInsideCompanyid();
$this->getAllGameSpend();
- $this->getCpStatement();
$this->getJuheStatement();
+ $this->getCpStatement();
$this->getPuStatement();
$this->getPcStatement();
$this->setMarginCount();
@@ -91,7 +91,7 @@ class GameMarginSetController extends Controller {
"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);
+ $this->adddata = M("Spend","tab_")->where($where)->group("relation_game_name")->order("pay_amount desc")->getField("substring_index(game_name, '(', 1) relation_game_name,SUM(pay_amount) pay_amount",true);
}
/**
* 获取聚合数据
@@ -347,13 +347,19 @@ class GameMarginSetController extends Controller {
if( !array_key_exists($game,$this->adddata) ){
continue;
}
- $statement_money = round( $this->adddata[$game]['pay_amount'] / $val['pay_amount'] * $val['sum_money'],2);
+ if($v['pay_type'] == 1){
+ $ratio = $val['first_ratio'];
+ }else{
+ $ratio = $val['second_ratio'];
+ }
+ $statement_money = round( $this->adddata[$game]['pay_amount'] * $ratio / 100,2);
if( array_key_exists("cp_statement_amount",$this->adddata[$game]) ){
$this->adddata[$game]['cp_statement_amount'] += $statement_money;
}else{
$this->adddata[$game]['cp_statement_amount'] = $statement_money;
}
$this->adddata[$game]['cp_promote_ratio'] = $val['promote_ratio'];
+ $this->adddata[$game]['cp_ratio'] = $ratio;
}
}
}
@@ -437,34 +443,34 @@ class GameMarginSetController extends Controller {
$pay_amount = 0;
foreach ($this->adddata as &$v) {
foreach ($baseCell as $bkey=>$bval) array_key_exists($bkey,$v) ?: $v[$bkey] = $bval;
- $v["cp_ratio"] = round($v["cp_statement_amount"]/$v['pay_amount'],4)*100;
+ // $v["cp_ratio"] = round($v["cp_statement_amount"]/$v['pay_amount'],4)*100;
if($v["pc_pay_amount"] > 0){
- $v["pc_ratio"] = round($v["pc_statement_amount"]/$v['pc_pay_amount'],4)*100;
+ $v["pc_ratio"] = round($v["pc_statement_amount"]/$v['pc_pay_amount'],2)*100;
$v["pc_margin_amount"] = round($v["pc_pay_amount"]*(1-$v['cp_promote_ratio']/100)*(100-$v["cp_ratio"]-$v['cp_rebate_ratio']-$v["pc_ratio"])/100,2);
- $v["pc_margin_ratio"] = round($v["pc_margin_amount"]/$v['pc_pay_amount'],4)*100;
+ $v["pc_margin_ratio"] = round($v["pc_margin_amount"]/$v['pc_pay_amount'],3)*100;
}
if ($v["pu_pay_amount"] > 0) {
- $v["pu_ratio"] = round($v["pu_statement_amount"]/$v['pu_pay_amount'],4)*100;
+ $v["pu_ratio"] = round($v["pu_statement_amount"]/$v['pu_pay_amount'],2)*100;
$v["pu_margin_amount"] = round($v["pu_pay_amount"]-$v["pu_pay_amount"]*(1-$v['cp_promote_ratio']/100)*($v["cp_ratio"]+$v['cp_rebate_ratio'])/100-$v["pu_statement_amount"],2);
- $v["pu_margin_ratio"] = round($v["pu_margin_amount"]/$v['pu_pay_amount'],4)*100;
+ $v["pu_margin_ratio"] = round($v["pu_margin_amount"]/$v['pu_pay_amount'],3)*100;
}
- $v['platform_margin_ratio'] = round(($v['pay_amount']-$v['jh_pay_amount']-$v['cp_statement_amount']-$v['cp_rebate_amount']-$v['cp_other_amount']-$v['pc_statement_amount']-$v['pu_statement_amount'])/($v['pay_amount']-$v['jh_pay_amount']),4)*100;
+ $v['platform_margin_ratio'] = round(($v['pay_amount']-$v['jh_pay_amount']-$v['cp_statement_amount']-$v['cp_rebate_amount']-$v['cp_other_amount']-$v['pc_statement_amount']-$v['pu_statement_amount'])/($v['pay_amount']-$v['jh_pay_amount']),3)*100;
if($v['jh_pay_amount'] > 0){
- $v["jh_ratio"] = round($v["jh_statement_amount"]/$v['jh_pay_amount'],4)*100;
+ $v["jh_ratio"] = round($v["jh_statement_amount"]/$v['jh_pay_amount'],2)*100;
$v["jh_margin_amount"] = round( $v["jh_statement_amount"]-$v["jh_pay_amount"]*(1-$v['cp_promote_ratio']/100)*($v["cp_ratio"]+$v['cp_rebate_ratio'])/100 ,2);
- $v["jh_margin_ratio"] = round($v["jh_margin_amount"]/$v['jh_pay_amount'],4)*100;
+ $v["jh_margin_ratio"] = round($v["jh_margin_amount"]/$v['jh_pay_amount'],3)*100;
}
$v['margin_amount'] = round( ($v['pay_amount']-$v['cp_statement_amount']-$v['cp_rebate_amount']-$v['cp_other_amount']-$v['pc_statement_amount']-$v['pu_statement_amount']+$v['jh_statement_amount']),2);
- $v['margin_ratio'] = round($v['margin_amount']/$v['pay_amount'],4)*100;
+ $v['margin_ratio'] = round($v['margin_amount']/$v['pay_amount'],3)*100;
$pay_amount += $v['pay_amount'];
$margin_amount += $v['margin_amount'];
}
- $margin_ratio = round( $margin_amount/$pay_amount ,4)*100;
+ $margin_ratio = round( $margin_amount/$pay_amount ,3)*100;
//保存数据库
$adddata = [
"margin_ratio"=>$margin_ratio,
diff --git a/Application/Admin/View/GameMargin/marginView.html b/Application/Admin/View/GameMargin/marginView.html
index 8ea0d64fa..7bb392f23 100644
--- a/Application/Admin/View/GameMargin/marginView.html
+++ b/Application/Admin/View/GameMargin/marginView.html
@@ -157,33 +157,33 @@
-
{$year}
- {$month}
+ {$margin["year"]}
+ {$margin["month"]}
{$margin["relation_game_name"]}
{$margin["pay_amount"]}
{$margin["cp_promote_ratio"]}%
- {$margin["cp_ratio"]}{$percent}
+ {$margin["cp_ratio"]}
{$margin["cp_statement_amount"]}
- {$margin["cp_rebate_ratio"]}%
+ {$margin["cp_rebate_ratio"]}
{$margin["cp_rebate_amount"]}
{$margin["cp_other_amount"]}
{$margin["pc_pay_amount"]}
- {$margin["pc_ratio"]}{$percent}
+ {$margin["pc_ratio"]}
{$margin["pc_statement_amount"]}
{$margin["pc_margin_amount"]}
- {$margin["pc_margin_ratio"]}{$percent}
+ {$margin["pc_margin_ratio"]}
{$margin["pu_pay_amount"]}
- {$margin["pu_ratio"]}{$percent}
+ {$margin["pu_ratio"]}
{$margin["pu_statement_amount"]}
{$margin["pu_margin_amount"]}
- {$margin["pu_margin_ratio"]}{$percent}
- {$margin["platform_margin_ratio"]}{$percent}
+ {$margin["pu_margin_ratio"]}
+ {$margin["platform_margin_ratio"]}
{$margin["jh_pay_amount"]}
- {$margin["jh_ratio"]}{$percent}
+ {$margin["jh_ratio"]}
{$margin["jh_statement_amount"]}
{$margin["jh_margin_amount"]}
- {$margin["jh_margin_ratio"]}{$percent}
- {$margin["margin_ratio"]}{$percent}
+ {$margin["jh_margin_ratio"]}
+ {$margin["margin_ratio"]}
{$margin["margin_amount"]}
@@ -193,33 +193,33 @@